navigate-204-205-download-then-same-document.html (2381B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 5 <script type="module"> 6 import { Recorder } from "./resources/helpers.mjs"; 7 8 const tests = [ 9 ["204s", "/common/blank.html?pipe=status(204)"], 10 ["205s", "/common/blank.html?pipe=status(205)"], 11 ["Content-Disposition: attachment responses", "/common/blank.html?pipe=header(Content-Disposition,attachment)"] 12 ]; 13 14 for (const [description, url] of tests) { 15 promise_test(async t => { 16 const i = document.createElement("iframe"); 17 i.src = "/common/blank.html"; 18 document.body.append(i); 19 await new Promise(resolve => i.onload = () => t.step_timeout(resolve, 0)); 20 21 const fromStart = i.contentWindow.navigation.currentEntry; 22 23 const recorder = new Recorder({ 24 window: i.contentWindow, 25 finalExpectedEvent: "finished fulfilled 2" 26 }); 27 28 recorder.setUpNavigationAPIListeners(); 29 30 const result1 = i.contentWindow.navigation.navigate(url); 31 recorder.setUpResultListeners(result1, " 1"); 32 33 // Give the server time to send the response. This is not strictly 34 // necessary (the expectations are the same either way) but it's better 35 // coverage if the server is done responding by this time; it guarantees 36 // we're hitting the code path for "got a 204/etc. and ignored it" instead 37 // of "didn't get a response yet". 38 await new Promise(resolve => t.step_timeout(resolve, 50)); 39 40 const result2 = i.contentWindow.navigation.navigate("#1"); 41 recorder.setUpResultListeners(result2, " 2"); 42 43 Promise.resolve().then(() => recorder.record("promise microtask")); 44 45 await recorder.readyToAssert; 46 47 recorder.assert([ 48 /* event name, location.hash value, navigation.transition properties */ 49 ["navigate", "", null], 50 ["AbortSignal abort", "", null], 51 ["navigateerror", "", null], 52 53 ["navigate", "", null], 54 ["currententrychange", "#1", null], 55 ["committed rejected 1", "#1", null], 56 ["finished rejected 1", "#1", null], 57 ["committed fulfilled 2", "#1", null], 58 ["promise microtask", "#1", null], 59 ["navigatesuccess", "#1", null], 60 ["finished fulfilled 2", "#1", null] 61 ]); 62 63 recorder.assertErrorsAreAbortErrors(); 64 }, `event and promise ordering when navigate() is to a ${description} and then to a same-document navigation`); 65 } 66 </script>