pageswap-traverse-navigation-no-bfcache.https.html (2543B)
1 <!DOCTYPE html> 2 <title>pageswap navigationactivation for traverse 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 src="/resources/common.js"></script> 8 <script src="/html/browsers/browsing-the-web/back-forward-cache/resources/disable_bfcache.js"></script> 9 <style></style> 10 <script> 11 const channel = new BroadcastChannel("testchannel"); 12 13 const params = new URLSearchParams(location.search); 14 const is_initial_page_first_navigation = params.has('popup') && navigation.entries().length == 1; 15 const is_new_page = params.has('new'); 16 const is_test_page = !params.has('popup') && !params.has('new'); 17 18 // The test page which opens a popup for the navigation sequence. 19 if (is_test_page) { 20 const expectedUrl = location.href.split('?')[0] + "?popup"; 21 const expectedEvents = ["pageswap", expectedUrl, "traverse","from", "pagehide"]; 22 23 promise_test(async t => { 24 let popup; 25 onload = () => { 26 window.events = []; 27 popup = window.open("?popup"); 28 }; 29 30 await new Promise(resolve => { 31 channel.addEventListener( 32 "message", t.step_func(async (e) => { 33 if (e.data === "nav") { 34 assert_array_equals(window.events, expectedEvents, 'incorrect event order'); 35 popup.close(); 36 resolve(); 37 } 38 })); 39 }); 40 }, `pageswap on traverse navigation from script`); 41 } else if (is_initial_page_first_navigation) { 42 // The popup page which the user navigates back to. 43 onload = async () => { 44 await disableBFCache(); 45 requestAnimationFrame(() => requestAnimationFrame(() => { 46 location.href = location.href.split('?')[0] + '?new'; 47 })); 48 }; 49 50 onpageshow = (e) => { 51 assert_false(e.persisted, 'the test should run without BFCache'); 52 } 53 } else if (is_new_page) { 54 onload = () => { 55 requestAnimationFrame(() => requestAnimationFrame(() => { 56 navigation.back(); 57 })); 58 }; 59 60 onpageswap = (e) => { 61 window.opener.events.push("pageswap"); 62 if (e.viewTransition != null) 63 window.opener.events.push("transition"); 64 window.opener.events.push(e.activation.entry.url); 65 window.opener.events.push(e.activation.navigationType); 66 if (e.activation.from == navigation.currentEntry) 67 window.opener.events.push("from"); 68 }; 69 70 onpagehide = () => { 71 window.opener.events.push("pagehide"); 72 channel.postMessage("nav"); 73 }; 74 } 75 </script>