pageswap-replace-navigation.html (2056B)
1 <!DOCTYPE html> 2 <title>pageswap navigationactivation for replace navigations</title> 3 <link rel="help" href="https://html.spec.whatwg.org/"> 4 <link rel="author" href="mailto:khushalsagar@chromium.org"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script> 8 const expectedUrl = location.href + '?new'; 9 10 const params = new URLSearchParams(location.search); 11 // The page the popup navigates to. 12 const is_new_page = params.has('new'); 13 // The initial page in the popup. 14 const is_popup_page = params.has('popup'); 15 // The test page itself. 16 const is_test_page = !is_popup_page && !is_new_page; 17 18 const channel = new BroadcastChannel("testchannel"); 19 20 if (is_test_page) { 21 const expectedUrl = location.href.split('?')[0] + "?new"; 22 const expectedEvents = ["pageswap", expectedUrl, "replace","from", "pagehide"]; 23 24 promise_test(async t => { 25 let popup; 26 onload = () => { 27 window.events = []; 28 popup = window.open("?popup"); 29 }; 30 31 await new Promise(resolve => { 32 channel.addEventListener( 33 "message", t.step_func(async (e) => { 34 if (e.data === "nav") { 35 assert_array_equals(window.events, expectedEvents, 'incorrect event order'); 36 popup.close(); 37 resolve(); 38 } 39 })); 40 }); 41 }, `pageswap on replace navigation from script`); 42 } else if (is_popup_page) { 43 onload = () => { 44 requestAnimationFrame(() => requestAnimationFrame(() => { 45 location.replace(location.href.split('?')[0] + '?new'); 46 })); 47 48 onpageswap = (e) => { 49 window.opener.events.push("pageswap"); 50 if (e.viewTransition != null) 51 window.opener.events.push("transition"); 52 window.opener.events.push(e.activation.entry.url); 53 window.opener.events.push(e.activation.navigationType); 54 if (e.activation.from == navigation.currentEntry) 55 window.opener.events.push("from"); 56 }; 57 58 onpagehide = () => { 59 window.opener.events.push("pagehide"); 60 channel.postMessage("nav"); 61 }; 62 }; 63 } 64 </script>