traverseTo-detach-between-navigate-and-navigatesuccess.html (2180B)
1 <!doctype html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="return-value/resources/helpers.js"></script> 5 6 <iframe id="i" src="/common/blank.html"></iframe> 7 8 <script> 9 async_test(t => { 10 window.onload = t.step_func(() => { 11 const iWindow = i.contentWindow; 12 const iDOMException = iWindow.DOMException; 13 const iNavigationHistoryEntry = iWindow.NavigationHistoryEntry; 14 15 i.contentWindow.navigation.navigate("#1").finished.then(t.step_func(() => { 16 assert_equals(i.contentWindow.navigation.entries().length, 2); 17 let key = i.contentWindow.navigation.entries()[0].key; 18 19 let onnavigateerror_called = false; 20 let result; 21 22 i.contentWindow.navigation.onnavigate = t.step_func(e => { 23 // 1. The intercept handler runs. 24 // 2. "t.step_timeout(handlerRunResolve, 0)" executes handlerRunResolve in a macro task. 25 // 3. In the next microtask, the iframe is removed. 26 // 4. "t.step_timeout(resolve, 5)" executes and the intercept handler promise resolves. 27 let handlerRunResolve; 28 new Promise(r => handlerRunResolve = r).then(() => i.remove()); 29 e.intercept({ handler() { 30 t.step_timeout(handlerRunResolve, 0); 31 return new Promise(resolve => t.step_timeout(resolve, 5)); 32 }}); 33 }); 34 35 i.contentWindow.navigation.onnavigatesuccess = t.unreached_func("navigatesuccess must not fire"); 36 37 i.contentWindow.navigation.onnavigateerror = t.step_func(e => { 38 assert_false(onnavigateerror_called); 39 onnavigateerror_called = true; 40 assert_equals(e.filename, location.href); 41 assert_greater_than(e.lineno, 0); 42 assert_greater_than(e.colno, 0); 43 44 assertCommittedFulfillsFinishedRejectsExactly(t, result, iWindow.navigation.currentEntry, e.error, iWindow, iDOMException, iNavigationHistoryEntry).then( 45 () => t.done(), 46 t.step_func(err => { throw err; }) 47 ); 48 }); 49 50 result = i.contentWindow.navigation.traverseTo(key); 51 })); 52 }); 53 }, "Detach a window between when a traverseTo() fires navigate and navigatesuccess"); 54 </script>