Skip to content

Commit 4980d1b

Browse files
authored
Fix json-module/cors-crossorigin-requests.html so that the output will be deterministic. (#54195)
1 parent c4ab993 commit 4980d1b

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

html/semantics/scripting-1/the-script-element/json-module/cors-crossorigin-requests.html

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,33 @@
77
</head>
88
<body>
99
<h1>json-module-crossorigin</h1>
10-
<iframe id="import-WithCORS" src="crossorigin-import-with-cors.sub.html"></iframe>
11-
<iframe id="import-NoCORS" src="crossorigin-import-without-cors.sub.html"></iframe>
12-
<iframe id="import-parseerror-WithCors" src="crossorigin-import-parse-error-with-cors.sub.html"></iframe>
1310
<script>
1411

1512
var tests = [
16-
{ "obj": async_test("Imported JSON module, cross-origin with CORS"), "id": "import-WithCORS", "expected": "imported JSON: 42" },
17-
{ "obj": async_test("Imported JSON module, cross-origin, missing CORS ACAO header"), "id": "import-NoCORS", "expected": "error" },
18-
{ "obj": async_test("Imported JSON module with parse error, cross-origin, with CORS"), "id": "import-parseerror-WithCors", "expected": "SyntaxError" },
13+
{ "obj": async_test("Imported JSON module, cross-origin with CORS"), "id": "import-WithCORS", "expected": "imported JSON: 42", "url": "crossorigin-import-with-cors.sub.html" },
14+
{ "obj": async_test("Imported JSON module, cross-origin, missing CORS ACAO header"), "id": "import-NoCORS", "expected": "error", "url": "crossorigin-import-without-cors.sub.html" },
15+
{ "obj": async_test("Imported JSON module with parse error, cross-origin, with CORS"), "id": "import-parseerror-WithCors", "expected": "SyntaxError", "url": "crossorigin-import-parse-error-with-cors.sub.html" },
1916
];
2017

21-
window.addEventListener("load", function () {
22-
tests.forEach(function (test) {
23-
var target = document.getElementById(test.id);
18+
async function loadTest(test) {
19+
return new Promise((resolve) => {
20+
const iframe = document.createElement('iframe');
21+
iframe.id = test.id;
22+
iframe.src = test.url;
23+
iframe.onload = () => resolve(iframe);
24+
document.body.appendChild(iframe);
25+
});
26+
}
27+
28+
(async function () {
29+
for (const test of tests) {
30+
const target = await loadTest(test);
2431
test.obj.step(function () {
2532
assert_equals(target.contentDocument._log, test.expected, "Unexpected _log value");
2633
});
2734
test.obj.done();
28-
});
29-
});
35+
}
36+
})();
3037

3138
</script>
3239
</body>

0 commit comments

Comments
 (0)