iframe-src-aboutblank-navigate-immediately.html (6266B)
1 <!DOCTYPE html> 2 <meta charset="UTF-8"> 3 <title>Navigations immediately after appending iframe with src='about:blank'</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="resources/helpers.js"></script> 7 <body></body> 8 <script> 9 /* 10 When an iframe is created with src="about:blank", it will stay on the initial 11 empty document. These tests verify the behavior of navigations that happen 12 immediately after the iframe is created, which should result in replacement. 13 */ 14 "use strict"; 15 const url1 = "/common/blank.html?1"; 16 17 promise_test(async t => { 18 const startingHistoryLength = history.length; 19 // Create an iframe with src set to about:blank. Per the HTML Standard, this 20 // stays on the "initial about:blank Document" [1], because the "process the 21 // iframe attributes" algorithm [2] catches the "about:blank" navigation and 22 // fires a special synchronous `load` event at the initial about:blank 23 // Document, instead of replacing it with a non-initial, second about:blank 24 // Document. This is documented in the note at the end of [3]. 25 // 26 // [1]: https://html.spec.whatwg.org/#is-initial-about:blank. 27 // [2]: https://html.spec.whatwg.org/#process-the-iframe-attributes 28 // [3]: https://html.spec.whatwg.org/#completely-finish-loading 29 const iframe = insertIframeWithAboutBlankSrc(t); 30 assert_equals(history.length, startingHistoryLength, 31 "Inserting iframe with src='about:blank' must not change history.length"); 32 33 // Trigger a navigation from the initial about:blank Document, to url1 through 34 // the iframe's src attribute. Because we're navigating from the initial 35 // about:blank Document, the navigation should be a replacement. 36 iframe.src = url1; 37 38 // Wait for the latest navigation to finish. 39 await waitForLoad(t, iframe, url1); 40 assert_equals(history.length, startingHistoryLength, 41 "history.length must not change after normal navigation from initial " + 42 "about:blank Document"); 43 }, "Navigating away from the initial about:blank Document to a different " + 44 "one, with src"); 45 46 promise_test(async t => { 47 const startingHistoryLength = history.length; 48 const iframe = insertIframeWithAboutBlankSrc(t); 49 assert_equals(history.length, startingHistoryLength, 50 "Inserting iframe with src='about:blank' must not change history.length"); 51 52 // Trigger a navigation from the initial about:blank Document, to url1 through 53 // location.href. Because we're navigating from the initial about:blank 54 // Document, the navigation should be a replacement. 55 iframe.contentWindow.location.href = url1; 56 await waitForLoad(t, iframe, url1); 57 assert_equals(history.length, startingHistoryLength, 58 "history.length must not change after normal navigation on initial empty document"); 59 }, "Navigating to a different document with location.href"); 60 61 promise_test(async t => { 62 const startingHistoryLength = history.length; 63 const iframe = insertIframeWithAboutBlankSrc(t); 64 assert_equals(history.length, startingHistoryLength, 65 "Inserting iframe with src='about:blank' must not change history.length"); 66 67 // Trigger a navigation from the initial about:blank Document, to url1 through 68 // location.assign(). Because we're navigating from the initial about:blank 69 // Document, the navigation should be a replacement. 70 iframe.contentWindow.location.assign(url1); 71 await waitForLoad(t, iframe, url1); 72 assert_equals(history.length, startingHistoryLength, 73 "history.length must not change after normal navigation on initial empty document"); 74 }, "Navigating to a different document with location.assign"); 75 76 promise_test(async t => { 77 const startingHistoryLength = history.length; 78 const iframe = insertIframeWithAboutBlankSrc(t); 79 assert_equals(history.length, startingHistoryLength, 80 "Inserting iframe with src='about:blank' must not change history.length"); 81 82 // Trigger a navigation from the initial about:blank Document, to url1 through 83 // window.open(). Because we're navigating from the initial about:blank 84 // Document, the navigation should be a replacement. 85 iframe.contentWindow.open(url1, "_self"); 86 await waitForLoad(t, iframe, url1); 87 assert_equals(history.length, startingHistoryLength, 88 "history.length must not change after normal navigation on initial empty document"); 89 }, "Navigating to a different document with window.open"); 90 91 promise_test(async t => { 92 const startingHistoryLength = history.length; 93 const iframe = insertIframeWithAboutBlankSrc(t); 94 assert_equals(history.length, startingHistoryLength, 95 "Inserting iframe with src='about:blank' must not change history.length"); 96 97 // Trigger a navigation from the initial about:blank Document, to url1 through 98 // clicking an `<a>` element. Because we're navigating from the initial 99 // about:blank Document, the navigation should be a replacement. 100 const a = iframe.contentDocument.createElement("a"); 101 a.href = url1; 102 iframe.contentDocument.body.appendChild(a); 103 a.click(); 104 await waitForLoad(t, iframe, url1); 105 assert_equals(history.length, startingHistoryLength, 106 "history.length must not change after normal navigation on initial empty document"); 107 }, "Navigating to a different document with link click"); 108 109 promise_test(async t => { 110 const startingHistoryLength = history.length; 111 const iframe = insertIframeWithAboutBlankSrc(t); 112 assert_equals(history.length, startingHistoryLength, 113 "Inserting iframe with src='about:blank' must not change history.length"); 114 115 // Trigger a navigation from the initial about:blank Document, to url1 through 116 // a form submission. Because we're navigating from the initial about:blank 117 // Document, the navigation should be a replacement. 118 const form = iframe.contentDocument.createElement("form"); 119 form.action = "/common/blank.html"; 120 iframe.contentDocument.body.appendChild(form); 121 const input = iframe.contentDocument.createElement("input"); 122 input.type = "hidden"; 123 input.name = "1"; 124 form.append(input); 125 form.submit(); 126 await waitForLoad(t, iframe, url1 + "="); 127 assert_equals(history.length, startingHistoryLength, 128 "history.length must not change after normal navigation on initial empty document"); 129 }, "Navigating to a different document with form submission"); 130 </script>