<!DOCTYPE html>
<meta charset="utf-8">
<p>Tests that promise rejection events are received for cross origin CORS scripts</p>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
addEventListener('unhandledrejection', async exception => {
// Ordering in between:
// 1. dispatching the console.error
// 2. dispatching 'unhandledrejection'
// is not guaranteed.
//
// This caused this test to be flaky. See https://crbug.com/1185119
//
// (1) is not observable from here, but part of the expectations. The only
// ways to ensure it will happen consistently before (2) is to use
// setTimeout, unfortunately.
await new Promise(resolve => setTimeout(resolve, 250));
console.log('PASS: received unhandledrejection event');
if (exception.reason == 42)
console.log('PASS: received expected reason');
else
console.log('FAIL: received unexpected reason: ' + e.reason);
if (window.testRunner)
testRunner.notifyDone();
});
</script>
<script src='http://localhost:8000/security/resources/promise-access-control.php?allow=true' crossorigin='anonymous'></script>