file_scrollRestoration_part2_bfcache.html (2064B)
1 <html> 2 <head> 3 <script> 4 var bc = new BroadcastChannel("bug1155730_part2"); 5 bc.onmessage = (msgEvent) => { 6 var msg = msgEvent.data; 7 var command = msg.command; 8 if (command == "test") { 9 var currentCase = msg.currentCase; 10 test(currentCase); 11 } 12 } 13 14 function test(currentCase) { 15 var assertIs = []; 16 var assertIsNot = []; 17 switch (currentCase) { 18 case 1: { 19 history.scrollRestoration = "manual"; 20 document.getElementById("bottom").scrollIntoView(); 21 window.location.href = "file_scrollRestoration_navigate.html"; 22 break; 23 } 24 case 2: { 25 assertIsNot.push([Math.round(window.scrollY), 0, "Should have kept the old scroll position."]); 26 assertIs.push([history.scrollRestoration, "manual", "Should have the same scrollRestoration as before reload."]); 27 bc.postMessage({command: "asserts", currentCase, assertIs, assertIsNot, assert2: "assert2"}); 28 window.scrollTo(0, 0); 29 window.location.hash = "hash"; 30 bc.postMessage({command: "nextCase"}); 31 requestAnimationFrame(() => { 32 test(currentCase + 1); 33 }); 34 break; 35 } 36 case 3: { 37 assertIsNot.push([Math.round(window.scrollY), 0, "Should have scrolled to #hash."]); 38 assertIs.push([history.scrollRestoration, "manual", "Should have the same scrollRestoration mode as before fragment navigation."]); 39 bc.postMessage({command: "asserts", currentCase, assertIs, assertIsNot}); 40 bc.close(); 41 window.close(); 42 break; 43 } 44 } 45 } 46 window.onpageshow = (event) => { 47 bc.postMessage({command: "pageshow", persisted: event.persisted}); 48 } 49 </script> 50 </head> 51 <body> 52 <div style="border: 1px solid black; height: 5000px;"> 53 </div> 54 <div id="bottom">Hello world</div> 55 <a href="#hash" name="hash">hash</a> 56 </body> 57 </html>