after-transition-timing.html (1966B)
1 <!doctype html> 2 <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <body> 6 <div style="height: 200vh; width: 200vw;"></div> 7 <div id="frag"></div> 8 <script> 9 promise_test(async t => { 10 // Wait for after the load event so that the navigation doesn't get converted 11 // into a replace navigation. 12 await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); 13 assert_equals(window.scrollY, 0); 14 await navigation.navigate("#frag").finished; 15 assert_not_equals(window.scrollY, 0); 16 17 window.onpopstate = t.step_func(() => assert_not_equals(window.scrollY, 0)); 18 window.onhashchange = t.step_func(() => assert_not_equals(window.scrollY, 0)); 19 20 // The scroll restore should take place before navigatesuccess fires. 21 let navigatesuccess_called = false; 22 navigation.onnavigatesuccess = t.step_func(() => { 23 navigatesuccess_called = true; 24 assert_equals(window.scrollY, 0); 25 }); 26 27 let back_promises = navigation.back(); 28 navigation.onnavigate = t.step_func(e => { 29 e.intercept({ scroll: "after-transition", 30 handler: async () => { 31 // The ordering here should be: 32 // * intercept() is called 33 // * back_promises.committed is resolved 34 // * this handler runs. 35 // If this handler incorrectly blocks back_promises.committed, 36 // this test will hang. 37 await back_promises.committed; 38 assert_not_equals(window.scrollY, 0); 39 } 40 }); 41 assert_not_equals(window.scrollY, 0); 42 }); 43 44 await back_promises.finished; 45 assert_equals(window.scrollY, 0); 46 assert_true(navigatesuccess_called); 47 }, "scroll: after-transition should scroll when back completes, just before navigatesuccess"); 48 </script> 49 </body>