iframe-src-204.html (9394B)
1 <!DOCTYPE html> 2 <meta charset="UTF-8"> 3 <title>Navigations on iframe with src set to URL that doesn't load a new document</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 it will contain the initial empty document. If the 11 src is set to a URL that doesn't load a new document (e.g. it results in a 12 HTTP 204 response), it will stay on the initial empty document. 13 These tests verify the behavior of navigations that happen on the initial 14 empty document in that situation. They should all be converted to do a 15 replacement. 16 */ 17 "use strict"; 18 const url1 = "/common/blank.html?1"; 19 const url2 = "/common/blank.html?2"; 20 21 promise_test(async t => { 22 const startingHistoryLength = history.length; 23 // Create an iframe with src set to URL that doesn't load a new document, so 24 // it will stay on the initial empty document. 25 const iframe = insertIframeWith204Src(t); 26 assert_equals(history.length, startingHistoryLength, 27 "Inserting iframe with src set to URL that doesn't load a new document must not change history.length"); 28 29 // Navigate away from the initial empty document through iframe.src. This 30 // should do a replacement. 31 iframe.src = url1; 32 await waitForLoad(t, iframe, url1); 33 assert_equals(history.length, startingHistoryLength, 34 "history.length must not change after normal navigation on document loaded by iframe with no src"); 35 36 // Navigate again using the same method, but this time it shouldn't do a 37 // replacement since it's no longer on the initial empty document. 38 iframe.src = url2; 39 await waitForLoad(t, iframe, url2); 40 assert_equals(history.length, startingHistoryLength + 1, 41 "history.length increases after normal navigation from non-initial empty document"); 42 }, "Navigating to a different document with src"); 43 44 promise_test(async t => { 45 const startingHistoryLength = history.length; 46 // Create an iframe with src set to URL that doesn't load a new document, so 47 // it will stay on the initial empty document. 48 const iframe = insertIframeWith204Src(t); 49 assert_equals(history.length, startingHistoryLength, 50 "Inserting iframe with src set to URL that doesn't load a new document must not change history.length"); 51 52 // Navigate away from the initial empty document through setting 53 // location.href. This should do a replacement. 54 iframe.contentWindow.location.href = url1; 55 await waitForLoad(t, iframe, url1); 56 assert_equals(history.length, startingHistoryLength, 57 "history.length must not change after normal navigation on document loaded by iframe with no src"); 58 59 // Navigate again using the same method, but this time it shouldn't do a 60 // replacement since it's no longer on the initial empty document. 61 iframe.contentWindow.location.href = url2; 62 await waitForLoad(t, iframe, url2); 63 assert_equals(history.length, startingHistoryLength + 1, 64 "history.length increases after normal navigation from non-initial empty document"); 65 }, "Navigating to a different document with location.href"); 66 67 promise_test(async t => { 68 const startingHistoryLength = history.length; 69 // Create an iframe with src set to URL that doesn't load a new document, so 70 // it will stay on the initial empty document. 71 const iframe = insertIframeWith204Src(t); 72 assert_equals(history.length, startingHistoryLength, 73 "Inserting iframe with src set to URL that doesn't load a new document must not change history.length"); 74 75 // Navigate away from the initial empty document through location.assign(). 76 // This should do a replacement. 77 iframe.contentWindow.location.assign(url1); 78 await waitForLoad(t, iframe, url1); 79 assert_equals(history.length, startingHistoryLength, 80 "history.length must not change after normal navigation on document loaded by iframe with no src"); 81 82 // Navigate again using the same method, but this time it shouldn't do a 83 // replacement since it's no longer on the initial empty document. 84 iframe.contentWindow.location.assign(url2); 85 await waitForLoad(t, iframe, url2); 86 assert_equals(history.length, startingHistoryLength + 1, 87 "history.length increases after normal navigation from non-initial empty document"); 88 }, "Navigating to a different document with location.assign"); 89 90 promise_test(async t => { 91 const startingHistoryLength = history.length; 92 // Create an iframe with src set to URL that doesn't load a new document, so 93 // it will stay on the initial empty document. 94 const iframe = insertIframeWith204Src(t); 95 assert_equals(history.length, startingHistoryLength, 96 "Inserting iframe with src set to URL that doesn't load a new document must not change history.length"); 97 98 // Navigate away from the initial empty document through window.open(). 99 // This should do a replacement. 100 iframe.contentWindow.open(url1, "_self"); 101 await waitForLoad(t, iframe, url1); 102 assert_equals(history.length, startingHistoryLength, 103 "history.length must not change after normal navigation on document loaded by iframe with no src"); 104 105 // Navigate again using the same method, but this time it shouldn't do a 106 // replacement since it's no longer on the initial empty document. 107 iframe.contentWindow.open(url2, "_self"); 108 await waitForLoad(t, iframe, url2); 109 assert_equals(history.length, startingHistoryLength + 1, 110 "history.length increases after normal navigation from non-initial empty document"); 111 }, "Navigating to a different document with window.open"); 112 113 promise_test(async t => { 114 const startingHistoryLength = history.length; 115 // Create an iframe with src set to URL that doesn't load a new document, so 116 // it will stay on the initial empty document. 117 const iframe = insertIframeWith204Src(t); 118 assert_equals(history.length, startingHistoryLength, 119 "Inserting iframe with src set to URL that doesn't load a new document must not change history.length"); 120 121 // Navigate away from the initial empty document through clicking an <a> 122 // element. This should do a replacement. 123 const a1 = iframe.contentDocument.createElement("a"); 124 a1.href = url1; 125 iframe.contentDocument.body.appendChild(a1); 126 a1.click(); 127 await waitForLoad(t, iframe, url1); 128 assert_equals(history.length, startingHistoryLength, 129 "history.length must not change after normal navigation on document loaded by iframe with no src"); 130 131 // Navigate again using the same method, but this time it shouldn't do a 132 // replacement since it's no longer on the initial empty document. 133 const a2 = iframe.contentDocument.createElement("a"); 134 a2.href = url2; 135 iframe.contentDocument.body.appendChild(a2); 136 a2.click(); 137 await waitForLoad(t, iframe, url2); 138 assert_equals(history.length, startingHistoryLength + 1, 139 "history.length increases after normal navigation from non-initial empty document"); 140 }, "Navigating to a different document with link click"); 141 142 promise_test(async t => { 143 const startingHistoryLength = history.length; 144 // Create an iframe with src set to URL that doesn't load a new document, so 145 // it will stay on the initial empty document. 146 const iframe = insertIframeWith204Src(t); 147 assert_equals(history.length, startingHistoryLength, 148 "Inserting iframe with src set to URL that doesn't load a new document must not change history.length"); 149 150 // Navigate away from the initial empty document through form submission. 151 // This should do a replacement. 152 const form1 = iframe.contentDocument.createElement("form"); 153 form1.action = "/common/blank.html"; 154 iframe.contentDocument.body.appendChild(form1); 155 const input1 = iframe.contentDocument.createElement("input"); 156 input1.type = "hidden"; 157 input1.name = "1"; 158 form1.append(input1); 159 form1.submit(); 160 await waitForLoad(t, iframe, url1 + "="); 161 assert_equals(history.length, startingHistoryLength, 162 "history.length must not change after normal navigation on document loaded by iframe with no src"); 163 164 // Navigate again using the same method, but this time it shouldn't do a 165 // replacement since it's no longer on the initial empty document. 166 const form2 = iframe.contentDocument.createElement("form"); 167 form2.action = "/common/blank.html"; 168 iframe.contentDocument.body.appendChild(form2); 169 const input2 = iframe.contentDocument.createElement("input"); 170 input2.type = "hidden"; 171 input2.name = "2"; 172 form2.append(input2); 173 form2.submit(); 174 await waitForLoad(t, iframe, url2 + "="); 175 assert_equals(history.length, startingHistoryLength + 1, 176 "history.length increases after normal navigation from non-initial empty document"); 177 }, "Navigating to a different document with form submission"); 178 179 promise_test(async t => { 180 // The ready state is asserted to be what it is currently Blink, Gecko, WebKit 181 const iframe = insertIframeWith204Src(t); 182 assert_equals(iframe.contentDocument.readyState, "complete"); 183 184 let loaded = false; 185 iframe.onload = () => loaded = true; 186 187 iframe.src = "about:blank"; 188 assert_false(loaded, "No sync load event"); 189 assert_equals(iframe.contentDocument.readyState, "complete"); 190 191 await Promise.resolve(); 192 assert_false(loaded, "No load event after microtask checkpoint"); 193 194 await waitForLoad(t, iframe, "about:blank"); 195 assert_true(loaded, "Iframe loaded eventually"); 196 assert_equals(iframe.contentDocument.readyState, "complete"); 197 }, "about:blank on top of 204 loads async"); 198 </script>