pageswap-push-navigation-hidden-document.html (2242B)
1 <!DOCTYPE html> 2 <title>Tests pageswap dispatch on hidden Documents</title> 3 <link rel="author" title="Khushal Sagar" href="mailto:khushalsagar@chromium.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 = async () => { 29 window.events = []; 30 popup = window.open("?popup"); 31 }; 32 33 await new Promise(resolve => { 34 channel.addEventListener( 35 "message", t.step_func(async (e) => { 36 if (e.data === "nav") { 37 assert_array_equals(window.events, expectedEvents, 'incorrect event order'); 38 popup.close(); 39 resolve(); 40 } 41 })); 42 }); 43 }, `pageswap on navigation from script`); 44 } else if (is_popup_page) { 45 onload = async () => { 46 await test_driver.minimize_window(); 47 assert_equals(document.visibilityState, "hidden"); 48 assert_equals(document.hidden, true); 49 50 location.href = location.href.split('?')[0] + '?new'; 51 }; 52 53 onpageswap = (e) => { 54 window.opener.events.push("pageswap"); 55 if (e.viewTransition != null) 56 window.opener.events.push("transition"); 57 window.opener.events.push(e.activation.entry.url); 58 window.opener.events.push(e.activation.navigationType); 59 if (e.activation.from == navigation.currentEntry) 60 window.opener.events.push("from"); 61 }; 62 63 onpagehide = () => { 64 window.opener.events.push("pagehide"); 65 channel.postMessage("nav"); 66 }; 67 } 68 </script>