-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add promise rejection tracking tests #2388
Merged
+1,126
−0
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bd18b31
Add promise rejection tracking tests
domenic e83b31c
Fixups to onerror test based on review
domenic 7eae2e9
Fix up disallow-crossorigin tests based on issues in OP
domenic 60cb726
Update for modern testharness standards
domenic 5b1cd23
Fix crossorigin case per review
domenic 0755b3b
Avoid "worker collision" lint failure
domenic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...bappapis/scripting/processing-model-2/unhandled-promise-rejections/allow-crossorigin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/cors/support.js?pipe=sub"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/#unhandled-promise-rejections"> | ||
<link rel="help" href="https://html.spec.whatwg.org/#muted-errors"> | ||
|
||
<body> | ||
<script> | ||
'use strict'; | ||
async_test(function(t) { | ||
addEventListener('unhandledrejection', t.step_func(function(e) { | ||
assert_equals(e.reason, 42, 'reason should be the one given by the script'); | ||
t.done(); | ||
})); | ||
}, 'Promise rejection event should be received for the cross-origin CORS script'); | ||
|
||
(function() { | ||
var scriptEl = document.createElement('script'); | ||
scriptEl.src = CROSSDOMAIN + 'support/promise-access-control.py?allow=true'; | ||
document.body.appendChild(scriptEl); | ||
}()); | ||
</script> | ||
</body> |
34 changes: 34 additions & 0 deletions
34
...papis/scripting/processing-model-2/unhandled-promise-rejections/disallow-crossorigin.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/cors/support.js?pipe=sub"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/#unhandled-promise-rejections"> | ||
<link rel="help" href="https://html.spec.whatwg.org/#muted-errors"> | ||
|
||
<body> | ||
<script> | ||
'use strict'; | ||
|
||
(function() { | ||
var resolveLoaded; | ||
var loadedPromise = new Promise(function(resolve) { resolveLoaded = resolve; }); | ||
|
||
async_test(function(t) { | ||
addEventListener('unhandledrejection', t.unreached_func('unhandledrejection event should never be triggered')); | ||
addEventListener('rejectionhandled', t.unreached_func('rejectionhandled event should never be triggered')); | ||
|
||
loadedPromise.then(t.step_func(function() { | ||
t.step_timeout(function() { | ||
t.done(); | ||
}, 1000); | ||
})); | ||
}, 'Promise rejection event should be muted for cross-origin non-CORS script'); | ||
|
||
var scriptEl = document.createElement('script'); | ||
scriptEl.src = CROSSDOMAIN + 'support/promise-access-control.py?allow=false'; | ||
scriptEl.onload = resolveLoaded; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
document.body.appendChild(scriptEl); | ||
}()); | ||
</script> | ||
</body> |
44 changes: 44 additions & 0 deletions
44
.../processing-model-2/unhandled-promise-rejections/promise-rejection-event-constructor.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/#the-promiserejectionevent-interface"> | ||
<script> | ||
'use strict'; | ||
|
||
test(function() { | ||
var p = new Promise(function(resolve, reject) {}); | ||
|
||
// No custom options are passed (besides required promise). | ||
assert_equals(new PromiseRejectionEvent('eventType', { promise: p }).bubbles, false); | ||
assert_equals(new PromiseRejectionEvent('eventType', { promise: p }).cancelable, false); | ||
assert_equals(new PromiseRejectionEvent('eventType', { promise: p }).promise, p); | ||
assert_equals(new PromiseRejectionEvent('eventType', { promise: p }).reason, undefined); | ||
|
||
// No promise is passed. | ||
assert_throws(new TypeError(), | ||
function() { | ||
new PromiseRejectionEvent('eventType', { bubbles: false }); | ||
}, | ||
'Cannot construct PromiseRejectionEventInit without promise'); | ||
|
||
// bubbles is passed. | ||
assert_equals(new PromiseRejectionEvent('eventType', { bubbles: false, promise: p }).bubbles, false); | ||
assert_equals(new PromiseRejectionEvent('eventType', { bubbles: true, promise: p }).bubbles, true); | ||
|
||
// cancelable is passed. | ||
assert_equals(new PromiseRejectionEvent('eventType', { cancelable: false, promise: p }).cancelable, false); | ||
assert_equals(new PromiseRejectionEvent('eventType', { cancelable: true, promise: p }).cancelable, true); | ||
|
||
// reason is passed. | ||
var r = new Error(); | ||
assert_equals(new PromiseRejectionEvent('eventType', { promise: p, reason: r }).reason, r); | ||
|
||
|
||
// All initializers are passed. | ||
assert_equals(new PromiseRejectionEvent('eventType', { bubbles: true, cancelable: true, promise: p, reason: r }).bubbles, true); | ||
assert_equals(new PromiseRejectionEvent('eventType', { bubbles: true, cancelable: true, promise: p, reason: r }).cancelable, true); | ||
assert_equals(new PromiseRejectionEvent('eventType', { bubbles: true, cancelable: true, promise: p, reason: r }).promise, p); | ||
assert_equals(new PromiseRejectionEvent('eventType', { bubbles: true, cancelable: true, promise: p, reason: r }).reason, r); | ||
}, "This tests the constructor for the PromiseRejectionEvent DOM class."); | ||
</script> |
31 changes: 31 additions & 0 deletions
31
...sing-model-2/unhandled-promise-rejections/promise-rejection-events-attached-in-event.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/#unhandled-promise-rejections"> | ||
<script> | ||
'use strict'; | ||
setup({ | ||
allow_uncaught_exception: true | ||
}); | ||
async_test(function(t) { | ||
var e = new Error('e'); | ||
var p = Promise.reject(e); | ||
|
||
window.onunhandledrejection = function(evt) { | ||
t.step(function() { | ||
assert_equals(evt.promise, p); | ||
assert_equals(evt.reason, e); | ||
}); | ||
var unreached = t.unreached_func('promise should not be fulfilled'); | ||
p.then(unreached, function(reason) { | ||
t.step(function() { | ||
assert_equals(reason, e); | ||
}); | ||
t.step_timeout(function() { t.done(); }, 10); | ||
}); | ||
}; | ||
|
||
window.onrejectionhandled = t.unreached_func('rejectionhandled event should not be invoked'); | ||
}, 'Attaching a handler in unhandledrejection should not trigger rejectionhandled.'); | ||
</script> |
35 changes: 35 additions & 0 deletions
35
...ing/processing-model-2/unhandled-promise-rejections/promise-rejection-events-onerror.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/#runtime-script-errors"> | ||
<link rel="help" href="https://html.spec.whatwg.org/#unhandled-promise-rejections"> | ||
<script> | ||
'use strict'; | ||
setup({ | ||
allow_uncaught_exception: true | ||
}); | ||
async_test(function(t) { | ||
var e = new Error('e'); | ||
var e2 = new Error('e2'); | ||
|
||
window.onerror = function (msg, url, line, col, error) { | ||
t.step(function() { | ||
assert_equals(msg, 'Uncaught Error: e2'); | ||
assert_equals(error, e2); | ||
}); | ||
t.done(); | ||
}; | ||
|
||
window.onrejectionhandled = function() { | ||
// This should cause onerror | ||
throw e2; | ||
}; | ||
|
||
var p = Promise.reject(e); | ||
setTimeout(t.step_func(function() { | ||
// This will cause onrejectionhandled | ||
p.catch(function() {}); | ||
}), 1); | ||
}, 'Throwing inside an unhandledrejection handler invokes the error handler.'); | ||
</script> |
8 changes: 8 additions & 0 deletions
8
...s/scripting/processing-model-2/unhandled-promise-rejections/promise-rejection-events.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Promise rejection events tests: in a Window context</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/#unhandled-promise-rejections"> | ||
|
||
<script src="support/promise-rejection-events.js"></script> |
12 changes: 12 additions & 0 deletions
12
...ng-model-2/unhandled-promise-rejections/promise-rejection-events.serviceworker.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Promise rejection events tests: in a service worker context</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/#unhandled-promise-rejections"> | ||
|
||
<script> | ||
'use strict'; | ||
service_worker_test('support/promise-rejection-events.js', 'Service worker setup'); | ||
</script> |
11 changes: 11 additions & 0 deletions
11
...rocessing-model-2/unhandled-promise-rejections/promise-rejection-events.sharedworker.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Promise rejection events tests: in a shared worker context</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/#unhandled-promise-rejections"> | ||
|
||
<script> | ||
'use strict'; | ||
fetch_tests_from_worker(new SharedWorker('support/promise-rejection-events.js')); | ||
</script> |
11 changes: 11 additions & 0 deletions
11
...ting/processing-model-2/unhandled-promise-rejections/promise-rejection-events.worker.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Promise rejection events tests: in a dedicated worker context</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<link rel="help" href="https://html.spec.whatwg.org/#unhandled-promise-rejections"> | ||
|
||
<script> | ||
'use strict'; | ||
fetch_tests_from_worker(new Worker('support/promise-rejection-events.js')); | ||
</script> |
10 changes: 10 additions & 0 deletions
10
...ripting/processing-model-2/unhandled-promise-rejections/support/promise-access-control.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
def main(request, response): | ||
allow = request.GET.first("allow", "false") | ||
|
||
headers = [("Content-Type", "application/javascript")] | ||
if allow != "false": | ||
headers.append(("Access-Control-Allow-Origin", "*")) | ||
|
||
body = "new Promise(function(resolve, reject) { reject(42); })" | ||
|
||
return headers, body |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
scriptEl.crossOrigin = 'anonymous';
- otherwise CORS won't be used.