pageswap-push-from-click.html (2520B)
1 <!DOCTYPE html> 2 <title>pageswap navigationactivation for push navigations from user click</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 src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 <script> 10 const expectedUrl = location.href + '?new'; 11 12 const params = new URLSearchParams(location.search); 13 // The page the popup navigates to. 14 const is_new_page = params.has('new'); 15 // The initial page in the popup. 16 const is_popup_page = params.has('popup'); 17 // The test page itself. 18 const is_test_page = !is_popup_page && !is_new_page; 19 20 const channel = new BroadcastChannel("testchannel"); 21 22 if (is_test_page) { 23 const expectedUrl = location.href + "?new"; 24 const expectedEvents = ["pageswap", expectedUrl, "push","from", "pagehide"]; 25 26 promise_test(async t => { 27 let popup; 28 onload = () => { 29 document.getElementById('nav_link').remove(); 30 window.events = []; 31 popup = window.open("?popup"); 32 33 popup.addEventListener("load", () => { 34 popup.requestAnimationFrame( 35 () => popup.requestAnimationFrame(() => { 36 let nav_link = popup.document.getElementById('nav_link'); 37 test_driver 38 .click(nav_link) 39 .catch(() => assert_unreached("click failed")); 40 })); 41 }); 42 }; 43 44 await new Promise(resolve => { 45 channel.addEventListener( 46 "message", t.step_func(async (e) => { 47 if (e.data === "nav") { 48 assert_array_equals(window.events, expectedEvents, 'incorrect event order'); 49 popup.close(); 50 resolve(); 51 } 52 })); 53 }); 54 }, `pageswap on navigation from user click`); 55 } else if (is_popup_page) { 56 onpageswap = (e) => { 57 window.opener.events.push("pageswap"); 58 if (e.viewTransition != null) 59 window.opener.events.push("transition"); 60 window.opener.events.push(e.activation.entry.url); 61 window.opener.events.push(e.activation.navigationType); 62 if (e.activation.from == navigation.currentEntry) 63 window.opener.events.push("from"); 64 }; 65 66 onpagehide = () => { 67 window.opener.events.push("pagehide"); 68 channel.postMessage("nav"); 69 }; 70 } 71 </script> 72 <body> 73 <a id="nav_link" href='/html/browsers/browsing-the-web/history-traversal/pageswap/pageswap-push-from-click.html?new'>Click me</a> 74 </body>