Node-appendChild-script-and-iframe.tentative.html (3226B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Node.appendChild: inserting script and iframe</title> 4 <script src=/resources/testharness.js></script> 5 <script src=/resources/testharnessreport.js></script> 6 <body> 7 <script> 8 9 const kScriptContent = ` 10 state = iframe.contentWindow ? "iframe with content window" : "contentWindow is null"; 11 `; 12 13 // This test ensures that a later-inserted script can observe an 14 // earlier-inserted iframe's contentWindow. 15 test(t => { 16 window.state = "script not run yet"; 17 window.iframe = document.createElement("iframe"); 18 t.add_cleanup(() => window.iframe.remove()); 19 20 const script = document.createElement("script"); 21 script.textContent = kScriptContent; 22 23 const div = document.createElement("div"); 24 div.appendChild(iframe); 25 div.appendChild(script); 26 27 assert_equals(state, "script not run yet"); 28 document.body.appendChild(div); 29 assert_equals(state, "iframe with content window"); 30 }, "Script inserted after an iframe in the same appendChild() call can " + 31 "observe the iframe's non-null contentWindow"); 32 33 // The below tests assert that an earlier-inserted script does not observe a 34 // later-inserted iframe's contentWindow. 35 test(t => { 36 window.state = "script not run yet"; 37 window.iframe = document.createElement("iframe"); 38 t.add_cleanup(() => window.iframe.remove()); 39 40 const script = document.createElement("script"); 41 script.textContent = kScriptContent; 42 43 const div = document.createElement("div"); 44 div.appendChild(script); 45 div.appendChild(iframe); 46 47 assert_equals(state, "script not run yet"); 48 document.body.appendChild(div); 49 assert_equals(state, "contentWindow is null"); 50 }, "A script inserted atomically before an iframe (using a div) does not " + 51 "observe the iframe's contentWindow, since the 'script running' and " + 52 "'iframe setup' both happen in order, after DOM insertion completes"); 53 54 test(t => { 55 window.state = "script not run yet"; 56 window.iframe = document.createElement("iframe"); 57 t.add_cleanup(() => window.iframe.remove()); 58 59 const script = document.createElement("script"); 60 script.textContent = kScriptContent; 61 62 const df = document.createDocumentFragment(); 63 df.appendChild(script); 64 df.appendChild(iframe); 65 66 assert_equals(state, "script not run yet"); 67 document.body.appendChild(df); 68 assert_equals(state, "contentWindow is null"); 69 }, "A script inserted atomically before an iframe (using a DocumentFragment) " + 70 "does not observe the iframe's contentWindow, since the 'script running' " + 71 "and 'iframe setup' both happen in order, after DOM insertion completes"); 72 73 test(t => { 74 window.state = "script not run yet"; 75 window.iframe = document.createElement("iframe"); 76 t.add_cleanup(() => window.iframe.remove()); 77 78 const script = document.createElement("script"); 79 script.textContent = kScriptContent; 80 81 assert_equals(state, "script not run yet"); 82 document.body.append(script, iframe); 83 84 assert_equals(state, "contentWindow is null"); 85 }, "A script inserted atomically before an iframe (using a append() with " + 86 "multiple arguments) does not observe the iframe's contentWindow, since " + 87 "the 'script running' and 'iframe setup' both happen in order, after DOM " + 88 "insertion completes"); 89 </script>