popstate-multiple-backs.tentative.html (1690B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <title>Soft navigation with multiple popstate calls.</title> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/resources/testdriver.js"></script> 9 <script src="/resources/testdriver-vendor.js"></script> 10 <script src="resources/soft-navigation-helper.js"></script> 11 </head> 12 <body> 13 <a id="link">Click me!</a> 14 <main id="main"> 15 </main> 16 <script> 17 // Push state 4 times, as history.back() calls will trigger popstate 18 // events. 19 history.pushState({}, "", "three.html"); 20 history.pushState({}, "", "two.html"); 21 history.pushState({}, "", "one.html"); 22 history.pushState({}, "", "zero.html"); 23 24 testSoftNavigation({ 25 testName: 26 "A soft navigation that started from a back() call inside a " + 27 "popstate event is recognized by SoftNavigationHeuristics", 28 eventListenerCb: async () => { 29 history.back(); 30 await waitForUrlToEndWith("one.html"); 31 history.back(); 32 await waitForUrlToEndWith("two.html"); 33 history.back(); 34 await waitForUrlToEndWith("three.html"); 35 }, 36 registerRouteChange: (cb) => addEventListener('popstate', (event) => { 37 // Wait for the final back() nav. 38 if (!location.href.endsWith("three.html")) { 39 return; 40 } 41 cb(event); 42 }), 43 pushState: () => { }, 44 // Although we will own the pushState, we need to set the expected URL 45 pushUrl: "one.html", 46 }); 47 </script> 48 </body> 49 </html>