Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 2bd57e0

Browse files
anforowiczchromium-wpt-export-bot
authored andcommitted
Fix how CORB async_test(s) work.
Some CORB tests run in parallel, because they use `async_test`. See https://web-platform-tests.org/writing-tests/testharness-api.html#asynchronous-tests: "Keep in mind that other tests could start executing before an Asynchronous Test is finished." This CL fixes such tests, to make sure that they either migrate to `promise_test` [1] or avoid using shared/global state. [1] https://web-platform-tests.org/writing-tests/testharness-api.html#promise-tests says "Unlike Asynchronous Tests, Promise Tests don’t start running until after the previous Promise Test finishes. Under rare circumstances, the next test may begin to execute before the returned promise has settled. Use add_cleanup to register any necessary cleanup actions such as resetting global state that need to happen consistently before the next test starts." Bug: 1011410 Change-Id: Ib369e6cd07aed2daaf6347ae5d6f777a2c0835db Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1841898 Commit-Queue: Łukasz Anforowicz <[email protected]> Reviewed-by: Philip Jägenstedt <[email protected]> Cr-Commit-Position: refs/heads/master@{#706131}
1 parent b3f3046 commit 2bd57e0

5 files changed

+20
-18
lines changed

fetch/corb/resources/html-js-polyglot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
// which found out that some script resources are served
55
// with text/html content-type and with a body that is
66
// both a valid html and a valid javascript.
7-
window.polyglot = "html-js-polyglot.js";
7+
window['html-js-polyglot.js'] = true;
88

99
//--></script></body></html>

fetch/corb/resources/html-js-polyglot2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// which found out that some script resources are served
66
// with text/html content-type and with a body that is
77
// both a valid html and a valid javascript.
8-
window.polyglot = "html-js-polyglot2.js";
8+
window['html-js-polyglot2.js'] = true;
99

1010
//]]>--></script>

fetch/corb/script-html-js-polyglot.sub.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
<script>
1010
["html-js-polyglot.js", "html-js-polyglot2.js"].forEach(polyglot_name => {
1111
async_test(function(t) {
12-
window.polyglot = "not yet set by the script";
12+
window[polyglot_name] = false;
1313
var script = document.createElement("script");
1414

1515
script.onload = t.step_func_done(function(){
1616
// Verify that the script response wasn't blocked - that script
17-
// should have set window.polyglot to |polyglot_name|.
18-
assert_equals(window.polyglot, polyglot_name);
17+
// should have set window[polyglot_name] to true.
18+
assert_true(window[polyglot_name]);
1919
})
2020
addEventListener("error",function(e) {
2121
t.step(function() {

fetch/corb/script-resource-with-json-parser-breaker.tentative.sub.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,25 @@
5353
]
5454

5555
function test(mime_type, body) {
56-
async_test(function(t) {
56+
// The test below depends on a global/shared event handler - we need to ensure
57+
// that no tests run in parallel - this is achieved by using `promise_test`
58+
// instead of `async_test`. See also
59+
// https://web-platform-tests.org/writing-tests/testharness-api.html#promise-tests
60+
promise_test(t => new Promise(function(resolve, reject) {
5761
var script = document.createElement("script")
5862

5963
// Without CORB, the JSON parser breaker would cause a syntax error when
6064
// parsed as JavaScript, but with CORB there should be no errors (because
6165
// CORB will replace the response body with an empty body).
62-
script.onload = t.step_func_done(function(){})
63-
addEventListener("error",function(e) {
64-
t.step(function() {
65-
assert_unreached("Empty body of a CORS-blocked response shouldn't trigger syntax errors.");
66-
t.done();
67-
})
68-
});
66+
script.onload = resolve;
67+
addEventListener("error", t.unreached_func(
68+
"Empty body of a CORS-blocked response shouldn't trigger syntax errors."))
6969

7070
// www1 is cross-origin, so the HTTP response is CORB-eligible.
7171
var src_prefix = "http://{{domains[www1]}}:{{ports[http][0]}}/fetch/corb/resources/sniffable-resource.py";
7272
script.src = src_prefix + "?type=" + mime_type + "&body=" + encodeURIComponent(body);
7373
document.body.appendChild(script)
74-
}, "CORB-blocks '" + mime_type + "' that starts with the following JSON parser breaker: " + body);
74+
}), "CORB-blocks '" + mime_type + "' that starts with the following JSON parser breaker: " + body);
7575
}
7676

7777
mime_types.forEach(function(type) {

fetch/corb/script-resource-with-nonsniffable-types.tentative.sub.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@
1111
<meta charset="utf-8">
1212
<script src="/resources/testharness.js"></script>
1313
<script src="/resources/testharnessreport.js"></script>
14+
<script src="/common/utils.js"></script>
1415
<div id=log></div>
1516
<script>
1617
setup({allow_uncaught_exception : true});
1718

1819
function test(mime_type, is_blocking_expected) {
1920
async_test(function(t) {
2021
var script = document.createElement("script")
22+
var script_has_run_token = "script_has_run" + token();
2123

2224
// With and without CORB there should be no error, but without CORB the
2325
// original script body will be preserved and |window.script_has_run| will
2426
// be set.
25-
window.script_has_run = false;
27+
window[script_has_run_token] = false;
2628
script.onload = t.step_func_done(function(){
2729
if (is_blocking_expected) {
28-
assert_false(window.script_has_run);
30+
assert_false(window[script_has_run_token]);
2931
} else {
30-
assert_true(window.script_has_run);
32+
assert_true(window[script_has_run_token]);
3133
}
3234
});
3335
addEventListener("error",function(e) {
@@ -44,7 +46,7 @@
4446
// rather than cross-*site* URL below (e.g. s/hosts[alt]/domains/g).
4547
// See also https://crbug.com/918660 for more context.
4648
var src_prefix = "http://{{hosts[alt][www1]}}:{{ports[http][0]}}/fetch/corb/resources/sniffable-resource.py";
47-
body = "window.script_has_run = true;"
49+
body = `window['${script_has_run_token}'] = true;`
4850
script.src = src_prefix + "?type=" + mime_type + "&body=" + encodeURIComponent(body);
4951
document.body.appendChild(script)
5052
}, "CORB-blocks '" + mime_type + "' that starts with the following JSON parser breaker: " + body);

0 commit comments

Comments
 (0)