window-history.https.sub.html (10038B)
1 <!DOCTYPE html> 2 <!-- 3 This test was procedurally generated. Please do not modify it directly. 4 Sources: 5 - fetch/metadata/tools/fetch-metadata.conf.yml 6 - fetch/metadata/tools/templates/window-history.sub.html 7 --> 8 <html lang="en"> 9 <meta charset="utf-8"> 10 <title>HTTP headers on request for navigation via the HTML History API</title> 11 <script src="/resources/testharness.js"></script> 12 <script src="/resources/testharnessreport.js"></script> 13 <script src="/fetch/metadata/resources/helper.sub.js"></script> 14 <body> 15 <script> 16 'use strict'; 17 18 const whenDone = (win) => { 19 return new Promise((resolve) => { 20 addEventListener('message', function handle(event) { 21 if (event.source === win) { 22 resolve(); 23 removeEventListener('message', handle); 24 } 25 }); 26 }) 27 }; 28 29 /** 30 * Prime the UA's session history such that the location of the request is 31 * immediately behind the current entry. Because the location may not be 32 * same-origin with the current browsing context, this must be done via a 33 * true navigation and not, e.g. the `history.pushState` API. The initial 34 * navigation will alter the WPT server's internal state; in order to avoid 35 * false positives, clear that state prior to initiating the second 36 * navigation via `history.back`. 37 */ 38 function induceBackRequest(url, test, clear) { 39 const win = window.open(url); 40 41 test.add_cleanup(() => win.close()); 42 43 return whenDone(win) 44 .then(clear) 45 .then(() => win.history.back()) 46 .then(() => whenDone(win)); 47 } 48 49 /** 50 * Prime the UA's session history such that the location of the request is 51 * immediately ahead of the current entry. Because the location may not be 52 * same-origin with the current browsing context, this must be done via a 53 * true navigation and not, e.g. the `history.pushState` API. The initial 54 * navigation will alter the WPT server's internal state; in order to avoid 55 * false positives, clear that state prior to initiating the second 56 * navigation via `history.forward`. 57 */ 58 function induceForwardRequest(url, test, clear) { 59 const win = window.open(messageOpenerUrl); 60 61 test.add_cleanup(() => win.close()); 62 63 return whenDone(win) 64 .then(() => win.location = url) 65 .then(() => whenDone(win)) 66 .then(clear) 67 .then(() => win.history.go(-2)) 68 .then(() => whenDone(win)) 69 .then(() => win.history.forward()) 70 .then(() => whenDone(win)); 71 } 72 73 const messageOpenerUrl = new URL( 74 '/fetch/metadata/resources/message-opener.html', location 75 ); 76 // For these tests to function, replacement must *not* be enabled during 77 // navigation. Assignment must therefore take place after the document has 78 // completely loaded [1]. This event is not directly observable, but it is 79 // scheduled as a task immediately following the global object's `load` 80 // event [2]. By queuing a task during the dispatch of the `load` event, 81 // navigation can be consistently triggered without replacement. 82 // 83 // [1] https://html.spec.whatwg.org/multipage/history.html#location-object-setter-navigate 84 // [2] https://html.spec.whatwg.org/multipage/parsing.html#the-end 85 const responseParams = { 86 mime: 'text/html', 87 body: `<script> 88 window.addEventListener('load', () => { 89 set`+`Timeout(() => location.assign('${messageOpenerUrl}')); 90 }); 91 <`+`/script>` 92 }; 93 94 promise_test((t) => { 95 const key = '{{uuid()}}'; 96 const url = makeRequestURL(key, ['httpsOrigin'], responseParams); 97 98 return induceBackRequest(url, t, () => retrieve(key)) 99 .then(() => retrieve(key)) 100 .then((headers) => { 101 assert_own_property(headers, 'sec-fetch-site'); 102 assert_array_equals(headers['sec-fetch-site'], ['same-origin']); 103 }); 104 }, 'sec-fetch-site - Same origin - history.back'); 105 106 promise_test((t) => { 107 const key = '{{uuid()}}'; 108 const url = makeRequestURL(key, ['httpsOrigin'], responseParams); 109 110 return induceForwardRequest(url, t, () => retrieve(key)) 111 .then(() => retrieve(key)) 112 .then((headers) => { 113 assert_own_property(headers, 'sec-fetch-site'); 114 assert_array_equals(headers['sec-fetch-site'], ['same-origin']); 115 }); 116 }, 'sec-fetch-site - Same origin - history.forward'); 117 118 promise_test((t) => { 119 const key = '{{uuid()}}'; 120 const url = makeRequestURL(key, ['httpsCrossSite'], responseParams); 121 122 return induceBackRequest(url, t, () => retrieve(key)) 123 .then(() => retrieve(key)) 124 .then((headers) => { 125 assert_own_property(headers, 'sec-fetch-site'); 126 assert_array_equals(headers['sec-fetch-site'], ['cross-site']); 127 }); 128 }, 'sec-fetch-site - Cross-site - history.back'); 129 130 promise_test((t) => { 131 const key = '{{uuid()}}'; 132 const url = makeRequestURL(key, ['httpsCrossSite'], responseParams); 133 134 return induceForwardRequest(url, t, () => retrieve(key)) 135 .then(() => retrieve(key)) 136 .then((headers) => { 137 assert_own_property(headers, 'sec-fetch-site'); 138 assert_array_equals(headers['sec-fetch-site'], ['cross-site']); 139 }); 140 }, 'sec-fetch-site - Cross-site - history.forward'); 141 142 promise_test((t) => { 143 const key = '{{uuid()}}'; 144 const url = makeRequestURL(key, ['httpsSameSite'], responseParams); 145 146 return induceBackRequest(url, t, () => retrieve(key)) 147 .then(() => retrieve(key)) 148 .then((headers) => { 149 assert_own_property(headers, 'sec-fetch-site'); 150 assert_array_equals(headers['sec-fetch-site'], ['same-site']); 151 }); 152 }, 'sec-fetch-site - Same site - history.back'); 153 154 promise_test((t) => { 155 const key = '{{uuid()}}'; 156 const url = makeRequestURL(key, ['httpsSameSite'], responseParams); 157 158 return induceForwardRequest(url, t, () => retrieve(key)) 159 .then(() => retrieve(key)) 160 .then((headers) => { 161 assert_own_property(headers, 'sec-fetch-site'); 162 assert_array_equals(headers['sec-fetch-site'], ['same-site']); 163 }); 164 }, 'sec-fetch-site - Same site - history.forward'); 165 166 promise_test((t) => { 167 const key = '{{uuid()}}'; 168 const url = makeRequestURL(key, [], responseParams); 169 170 return induceBackRequest(url, t, () => retrieve(key)) 171 .then(() => retrieve(key)) 172 .then((headers) => { 173 assert_own_property(headers, 'sec-fetch-mode'); 174 assert_array_equals(headers['sec-fetch-mode'], ['navigate']); 175 }); 176 }, 'sec-fetch-mode - history.back'); 177 178 promise_test((t) => { 179 const key = '{{uuid()}}'; 180 const url = makeRequestURL(key, [], responseParams); 181 182 return induceForwardRequest(url, t, () => retrieve(key)) 183 .then(() => retrieve(key)) 184 .then((headers) => { 185 assert_own_property(headers, 'sec-fetch-mode'); 186 assert_array_equals(headers['sec-fetch-mode'], ['navigate']); 187 }); 188 }, 'sec-fetch-mode - history.forward'); 189 190 promise_test((t) => { 191 const key = '{{uuid()}}'; 192 const url = makeRequestURL(key, [], responseParams); 193 194 return induceBackRequest(url, t, () => retrieve(key)) 195 .then(() => retrieve(key)) 196 .then((headers) => { 197 assert_own_property(headers, 'sec-fetch-dest'); 198 assert_array_equals(headers['sec-fetch-dest'], ['document']); 199 }); 200 }, 'sec-fetch-dest - history.back'); 201 202 promise_test((t) => { 203 const key = '{{uuid()}}'; 204 const url = makeRequestURL(key, [], responseParams); 205 206 return induceForwardRequest(url, t, () => retrieve(key)) 207 .then(() => retrieve(key)) 208 .then((headers) => { 209 assert_own_property(headers, 'sec-fetch-dest'); 210 assert_array_equals(headers['sec-fetch-dest'], ['document']); 211 }); 212 }, 'sec-fetch-dest - history.forward'); 213 214 promise_test((t) => { 215 const key = '{{uuid()}}'; 216 const url = makeRequestURL(key, [], responseParams); 217 218 return induceBackRequest(url, t, () => retrieve(key)) 219 .then(() => retrieve(key)) 220 .then((headers) => { 221 assert_not_own_property(headers, 'sec-fetch-user'); 222 }); 223 }, 'sec-fetch-user - history.back'); 224 225 promise_test((t) => { 226 const key = '{{uuid()}}'; 227 const url = makeRequestURL(key, [], responseParams); 228 229 return induceForwardRequest(url, t, () => retrieve(key)) 230 .then(() => retrieve(key)) 231 .then((headers) => { 232 assert_not_own_property(headers, 'sec-fetch-user'); 233 }); 234 }, 'sec-fetch-user - history.forward'); 235 236 promise_test((t) => { 237 const key = '{{uuid()}}'; 238 const url = makeRequestURL(key, ['httpsCrossSite'], responseParams); 239 240 return induceBackRequest(url, t, () => retrieve(key)) 241 .then(() => retrieve(key)) 242 .then((headers) => { 243 assert_not_own_property(headers, 'sec-fetch-storage-access'); 244 }); 245 }, 'sec-fetch-storage-access - Cross-site - history.back'); 246 247 promise_test((t) => { 248 const key = '{{uuid()}}'; 249 const url = makeRequestURL(key, ['httpsCrossSite'], responseParams); 250 251 return induceForwardRequest(url, t, () => retrieve(key)) 252 .then(() => retrieve(key)) 253 .then((headers) => { 254 assert_not_own_property(headers, 'sec-fetch-storage-access'); 255 }); 256 }, 'sec-fetch-storage-access - Cross-site - history.forward'); 257 258 promise_test((t) => { 259 const key = '{{uuid()}}'; 260 const url = makeRequestURL(key, ['httpsSameSite'], responseParams); 261 262 return induceBackRequest(url, t, () => retrieve(key)) 263 .then(() => retrieve(key)) 264 .then((headers) => { 265 assert_not_own_property(headers, 'sec-fetch-storage-access'); 266 }); 267 }, 'sec-fetch-storage-access - Same site - history.back'); 268 269 promise_test((t) => { 270 const key = '{{uuid()}}'; 271 const url = makeRequestURL(key, ['httpsSameSite'], responseParams); 272 273 return induceForwardRequest(url, t, () => retrieve(key)) 274 .then(() => retrieve(key)) 275 .then((headers) => { 276 assert_not_own_property(headers, 'sec-fetch-storage-access'); 277 }); 278 }, 'sec-fetch-storage-access - Same site - history.forward'); 279 </script> 280 </body> 281 </html>