window-reuse-in-nested-browsing-contexts.tentative.html (7788B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title></title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <div id=log></div> 7 <script> 8 const setupIframe = (t, attrs) => { 9 const iframe = document.createElement('iframe'); 10 for (const [key, value] of Object.entries(attrs)) 11 iframe[key] = value; 12 const watcher = new EventWatcher(t, iframe, ['load']); 13 document.body.appendChild(iframe); 14 return {iframe, watcher}; 15 }; 16 17 // This test is outdated, see 18 // https://github.com/whatwg/html/issues/3267#issuecomment-2788132131 19 20 promise_test(async t => { 21 const {iframe, watcher} = setupIframe(t, {}); 22 23 // Per https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes, 24 // the task to perform the "iframe load event steps" should still be queued. 25 // If a browser already fired a load event, the test will fail here since 26 // EventWatcher will have received an unexpected load event. 27 28 iframe.contentWindow.persistedString = 'Hello world!'; 29 iframe.src = 'support/same-origin-iframe.html'; 30 await watcher.wait_for(['load']); 31 32 assert_true(iframe.contentWindow.didLoadFrame); 33 // The <iframe>'s session history has only one Document, and that Document is 34 // the initial about:blank Document. The Window object should be reused per 35 // https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes. 36 assert_equals(iframe.contentWindow.persistedString, 'Hello world!'); 37 }, 'synchronously navigate iframe with no initial src.'); 38 39 promise_test(async t => { 40 const {iframe, watcher} = setupIframe(t, {}); 41 42 // Per https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes, 43 // the task to perform the "iframe load event steps" should still be queued. 44 await watcher.wait_for(['load']); 45 46 iframe.contentWindow.persistedString = 'Hello world!'; 47 iframe.src = 'support/same-origin-iframe.html'; 48 await watcher.wait_for(['load']); 49 50 assert_true(iframe.contentWindow.didLoadFrame); 51 // The <iframe>'s session history has only one Document, and that Document is 52 // the initial about:blank Document. The Window object should be reused per 53 // https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes. 54 assert_equals(iframe.contentWindow.persistedString, 'Hello world!'); 55 }, 'after the first iframe load event, navigate iframe with no initial src.'); 56 57 // Per https://whatwg.org/c/iframe-embed-object.html#otherwise-steps-for-iframe-or-frame-elements, 58 // setting the <iframe> src to an empty string before inserting the <iframe> 59 // into the document should begin an attempt to navigate to a resource with 60 // url == "about:blank". 61 promise_test(async t => { 62 const {iframe, watcher} = setupIframe(t, {src: ''}); 63 64 // Per https://whatwg.org/c/browsing-the-web.html#navigate, the "about:blank" 65 // resource should be obtained "in parallel". If a browser performs this step 66 // synchronously, the test will fail here since EventWatcher will have 67 // received an unexpected load event. 68 69 iframe.contentWindow.persistedString = 'Hello world!'; 70 // An attempt to navigate to "about:blank" already exists but should not have 71 // matured yet since the resource should be obtained "in parallel". The new 72 // navigation attempt will cancel the preexisting attempt. 73 iframe.src = 'support/same-origin-iframe.html'; 74 await watcher.wait_for(['load']); 75 76 assert_true(iframe.contentWindow.didLoadFrame); 77 // The navigation attempt to "about:blank" was cancelled, so the <iframe>'s 78 // session history has only one Document, and that Document is the 79 // initial about:blank Document. The Window object should be reused per 80 // https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes. 81 assert_equals(iframe.contentWindow.persistedString, 'Hello world!'); 82 }, 'synchronously navigate iframe with initial src == "".'); 83 84 promise_test(async t => { 85 const {iframe, watcher} = setupIframe(t, {src: ''}); 86 87 // Per https://whatwg.org/c/browsing-the-web.html#navigate, the "about:blank" 88 // resource should be obtained "in parallel". 89 await watcher.wait_for(['load']); 90 91 iframe.contentWindow.persistedString = 'Hello world!'; 92 iframe.src = 'support/same-origin-iframe.html'; 93 await watcher.wait_for(['load']); 94 95 assert_true(iframe.contentWindow.didLoadFrame); 96 // A non-initial navigation to about:blank was committed, so the <iframe> 97 // element is no longer displaying the initial about:blank Document. Per 98 // https://whatwg.org/c/browsing-the-web.html#initialise-the-document-object, 99 // the Window object must not be reused. 100 assert_equals(iframe.contentWindow.persistedString, undefined); 101 }, 'after the first iframe load event, navigate iframe with initial src == "".'); 102 103 promise_test(async t => { 104 const {iframe, watcher} = setupIframe(t, {src: 'about:blank'}); 105 106 // Per https://whatwg.org/c/browsing-the-web.html#navigate, the "about:blank" 107 // resource should be obtained "in parallel". If a browser performs this step 108 // synchronously, the test will fail here since EventWatcher will have 109 // received an unexpected load event. 110 111 iframe.contentWindow.persistedString = 'Hello world!'; 112 // An attempt to navigate to "about:blank" already exists but should not have 113 // matured yet since the resource should be obtained "in parallel". The new 114 // navigation attempt will cancel the preexisting attempt. 115 iframe.src = 'support/same-origin-iframe.html'; 116 await watcher.wait_for(['load']); 117 118 assert_true(iframe.contentWindow.didLoadFrame); 119 // The navigation attempt to "about:blank" was cancelled, so the <iframe>'s 120 // session history has only one Document, and that Document is the 121 // initial about:blank Document. The Window object should be reused per 122 // https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes. 123 assert_equals(iframe.contentWindow.persistedString, 'Hello world!'); 124 }, 'synchronously navigate iframe with initial src == "about:blank".'); 125 126 promise_test(async t => { 127 const {iframe, watcher} = setupIframe(t, {src: 'about:blank'}); 128 129 // Per https://whatwg.org/c/browsing-the-web.html#navigate, the "about:blank" 130 // resource should be obtained "in parallel". 131 await watcher.wait_for(['load']); 132 133 iframe.contentWindow.persistedString = 'Hello world!'; 134 iframe.src = 'support/same-origin-iframe.html'; 135 await watcher.wait_for(['load']); 136 137 assert_true(iframe.contentWindow.didLoadFrame); 138 // A non-initial navigation to about:blank was committed, so the <iframe> 139 // element is no longer displaying the initial about:blank Document. Per 140 // https://whatwg.org/c/browsing-the-web.html#initialise-the-document-object, 141 // the Window object must not be reused. 142 assert_equals(iframe.contentWindow.persistedString, undefined); 143 }, 'after the first iframe load event, navigate iframe with initial src == "about:blank".'); 144 145 // Per https://whatwg.org/c/iframe-embed-object.html#otherwise-steps-for-iframe-or-frame-elements, 146 // setting <iframe> src before inserting the <iframe> into the document should 147 // begin an attempt to navigate to the value of the src attribute. 148 promise_test(async t => { 149 const {iframe, watcher} = setupIframe(t, {src: 'support/same-origin-iframe.html'}); 150 151 iframe.contentWindow.persistedString = 'Hello world!'; 152 // Completion of the attempt to navigate happens "in parallel". 153 await watcher.wait_for(['load']); 154 155 assert_true(iframe.contentWindow.didLoadFrame); 156 // The <iframe>'s session history has only one Document, and that Document is 157 // the initial about:blank Document. The Window object should be reused per 158 // https://whatwg.org/c/iframe-embed-object.html#process-the-iframe-attributes. 159 assert_equals(iframe.contentWindow.persistedString, 'Hello world!'); 160 }, 'iframe with initial src == same-origin resource.'); 161 </script>