Bug 1895153 - Implement "Find in page..." menu functionality r=android-reviewers...
[gecko.git] / testing / web-platform / tests / navigation-api / navigation-methods / traverseTo-detach-between-navigate-and-navigatesuccess.html
blob43bde9a103bc13fd1cb88320da1fb60df0de0fa5
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>
6 <iframe id="i" src="/common/blank.html"></iframe>
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;
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;
19 let onnavigateerror_called = false;
20 let result;
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 });
35 i.contentWindow.navigation.onnavigatesuccess = t.unreached_func("navigatesuccess must not fire");
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);
44 assertCommittedFulfillsFinishedRejectsExactly(t, result, iWindow.navigation.currentEntry, e.error, iWindow, iDOMException, iNavigationHistoryEntry).then(
45 () => t.done(),
46 t.step_func(err => { throw err; })
48 });
50 result = i.contentWindow.navigation.traverseTo(key);
51 }));
52 });
53 }, "Detach a window between when a traverseTo() fires navigate and navigatesuccess");
54 </script>