after-transition-reload.html (1630B)
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 id="buffer" style="height: 1000px; width: 200vw;"></div> 7 <div id="frag"></div> 8 <div style="height: 200vh; width: 200vw;"></div> 9 <script> 10 promise_test(async t => { 11 // Wait for after the load event so that the navigation doesn't get converted 12 // into a replace navigation. 13 await new Promise(resolve => window.onload = () => t.step_timeout(resolve, 0)); 14 assert_equals(window.scrollY, 0); 15 await navigation.navigate("#frag").finished; 16 // Scroll down 10px from #frag 17 window.scrollBy(0, 10); 18 let scrollY_frag_plus_10 = window.scrollY; 19 20 let intercept_resolve; 21 let navigate_event; 22 navigation.onnavigate = e => { 23 navigate_event = e; 24 e.intercept({ handler: () => new Promise(r => intercept_resolve = r), 25 scroll: "after-transition" }); 26 }; 27 let reload_promises = navigation.reload(); 28 await reload_promises.committed; 29 30 // removing the <div id="buffer"> should scroll up 1000px. 31 assert_equals(window.scrollY, scrollY_frag_plus_10); 32 buffer.remove(); 33 let scrollY_after_buffer_remove = window.scrollY; 34 assert_equals(scrollY_after_buffer_remove, scrollY_frag_plus_10 - 1000); 35 36 // Finishing should scroll to #frag, which is 10px up from the current location 37 intercept_resolve(); 38 await reload_promises.finished; 39 assert_equals(window.scrollY, scrollY_after_buffer_remove - 10); 40 }, "scroll: after-transition should work on a reload navigation"); 41 </script> 42 </body>