iframe-nosrc.html (9717B)
1 <!DOCTYPE html> 2 <meta charset="UTF-8"> 3 <title>Navigations on iframe without src attribute</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 and srcdoc attribute is not set, it will stay on the initial empty 12 document. 13 These tests verifies 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 not set, which will stay on the initial empty 24 // document. 25 const iframe = insertIframe(t); 26 assert_equals(history.length, startingHistoryLength, 27 "Inserting iframe with no src 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 }, "src"); 43 44 promise_test(async t => { 45 const startingHistoryLength = history.length; 46 // Create an iframe with src not set, which will stay on the initial empty 47 // document. 48 const iframe = insertIframe(t); 49 assert_equals(history.length, startingHistoryLength, 50 "Inserting iframe with no src 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 }, "location.href"); 66 67 promise_test(async t => { 68 const startingHistoryLength = history.length; 69 // Create an iframe with src not set, which will stay on the initial empty 70 // document. 71 const iframe = insertIframe(t); 72 assert_equals(history.length, startingHistoryLength, 73 "Inserting iframe with no src 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 }, "location.assign"); 89 90 promise_test(async t => { 91 const startingHistoryLength = history.length; 92 // Create an iframe with src not set, which will stay on the initial empty 93 // document. 94 const iframe = insertIframe(t); 95 assert_equals(history.length, startingHistoryLength, 96 "Inserting iframe with no src 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 }, "window.open"); 112 113 promise_test(async t => { 114 const startingHistoryLength = history.length; 115 // Create an iframe with src not set, which will stay on the initial empty 116 // document. 117 const iframe = insertIframe(t); 118 assert_equals(history.length, startingHistoryLength, 119 "Inserting iframe with no src 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 }, "link click"); 141 142 promise_test(async t => { 143 const startingHistoryLength = history.length; 144 // Create an iframe with src not set, which will stay on the initial empty 145 // document. 146 const iframe = insertIframe(t); 147 assert_equals(history.length, startingHistoryLength, 148 "Inserting iframe with no src 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 }, "form submission"); 178 179 // This test is very similar to the `location.href` test a few cases above, but 180 // the difference is that instead of navigating from: 181 // initial about:blank Document => HTTP => HTTP 182 // ... we navigate from: 183 // initial about:blank Document => (non-initial) about:blank Document => HTTP 184 // 185 // We do this to ensure/assert that an explicit navigation to about:blank 186 // *after* the iframe has finished initializing, is counted as a normal 187 // navigation away from the initial about:blank Document, and the "initial-ness" 188 // of the initial about:blank Document is not carried over to the next 189 // about:blank Document. 190 promise_test(async t => { 191 const startingHistoryLength = history.length; 192 // Create an iframe with src not set, which will stay on the initial empty 193 // document. 194 const iframe = insertIframe(t); 195 assert_equals(history.length, startingHistoryLength, 196 "Inserting iframe with no src must not change history.length"); 197 198 // Navigate away from the initial empty document through setting location.href 199 // to `about:blank`. This should do a replacement TO ANOTHER about:blank 200 // Document, which is not the initial about:blank Document. 201 iframe.contentWindow.location.href = 'about:blank'; 202 await waitForLoad(t, iframe, 'about:blank'); 203 assert_equals(history.length, startingHistoryLength, 204 "history.length must not change after normal navigation on document loaded by iframe with no src"); 205 206 // Navigate again using the same method, but this time it shouldn't do a 207 // replacement since it's no longer on the initial empty document. 208 iframe.contentWindow.location.href = url2; 209 await waitForLoad(t, iframe, url2); 210 assert_equals(history.length, startingHistoryLength + 1, 211 "history.length increases after normal navigation from non-initial empty document"); 212 }, "initial about:blank => non-initial about:blank (via location.href) => normal HTTP navigation"); 213 </script>