Node-appendChild-script-and-iframe.tentative.html 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. const kScriptContent = `
  9. state = iframe.contentWindow ? "iframe with content window" : "contentWindow is null";
  10. `;
  11. // This test ensures that a later-inserted script can observe an
  12. // earlier-inserted iframe's contentWindow.
  13. test(t => {
  14. window.state = "script not run yet";
  15. window.iframe = document.createElement("iframe");
  16. t.add_cleanup(() => window.iframe.remove());
  17. const script = document.createElement("script");
  18. script.textContent = kScriptContent;
  19. const div = document.createElement("div");
  20. div.appendChild(iframe);
  21. div.appendChild(script);
  22. assert_equals(state, "script not run yet");
  23. document.body.appendChild(div);
  24. assert_equals(state, "iframe with content window");
  25. }, "Script inserted after an iframe in the same appendChild() call can " +
  26. "observe the iframe's non-null contentWindow");
  27. // The below tests assert that an earlier-inserted script does not observe a
  28. // later-inserted iframe's contentWindow.
  29. test(t => {
  30. window.state = "script not run yet";
  31. window.iframe = document.createElement("iframe");
  32. t.add_cleanup(() => window.iframe.remove());
  33. const script = document.createElement("script");
  34. script.textContent = kScriptContent;
  35. const div = document.createElement("div");
  36. div.appendChild(script);
  37. div.appendChild(iframe);
  38. assert_equals(state, "script not run yet");
  39. document.body.appendChild(div);
  40. assert_equals(state, "contentWindow is null");
  41. }, "A script inserted atomically before an iframe (using a div) does not " +
  42. "observe the iframe's contentWindow, since the 'script running' and " +
  43. "'iframe setup' both happen in order, after DOM insertion completes");
  44. test(t => {
  45. window.state = "script not run yet";
  46. window.iframe = document.createElement("iframe");
  47. t.add_cleanup(() => window.iframe.remove());
  48. const script = document.createElement("script");
  49. script.textContent = kScriptContent;
  50. const df = document.createDocumentFragment();
  51. df.appendChild(script);
  52. df.appendChild(iframe);
  53. assert_equals(state, "script not run yet");
  54. document.body.appendChild(df);
  55. assert_equals(state, "contentWindow is null");
  56. }, "A script inserted atomically before an iframe (using a DocumentFragment) " +
  57. "does not observe the iframe's contentWindow, since the 'script running' " +
  58. "and 'iframe setup' both happen in order, after DOM insertion completes");
  59. test(t => {
  60. window.state = "script not run yet";
  61. window.iframe = document.createElement("iframe");
  62. t.add_cleanup(() => window.iframe.remove());
  63. const script = document.createElement("script");
  64. script.textContent = kScriptContent;
  65. assert_equals(state, "script not run yet");
  66. document.body.append(script, iframe);
  67. assert_equals(state, "contentWindow is null");
  68. }, "A script inserted atomically before an iframe (using a append() with " +
  69. "multiple arguments) does not observe the iframe's contentWindow, since " +
  70. "the 'script running' and 'iframe setup' both happen in order, after DOM " +
  71. "insertion completes");
  72. </script>