|
7 | 7 | </head>
|
8 | 8 | <body>
|
9 | 9 | <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> |
13 | 10 | <script>
|
14 | 11 |
|
15 | 12 | 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" }, |
19 | 16 | ];
|
20 | 17 |
|
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); |
24 | 31 | test.obj.step(function () {
|
25 | 32 | assert_equals(target.contentDocument._log, test.expected, "Unexpected _log value");
|
26 | 33 | });
|
27 | 34 | test.obj.done();
|
28 |
| - }); |
29 |
| - }); |
| 35 | + } |
| 36 | + })(); |
30 | 37 |
|
31 | 38 | </script>
|
32 | 39 | </body>
|
|
0 commit comments