file_scrollRestoration_part1_nobfcache.html (2687B)
1 <html> 2 <head> 3 <script> 4 var oldHistoryObject = null; 5 var bc = new BroadcastChannel("bug1155730_part1"); 6 bc.onmessage = (msgEvent) => { 7 var msg = msgEvent.data; 8 var command = msg.command; 9 if (command == "test") { 10 var currentCase = msg.currentCase; 11 test(currentCase); 12 } 13 } 14 15 function test(currentCase) { 16 var assertIs = []; 17 var assertOk = []; 18 var assertIsNot = []; 19 switch (currentCase) { 20 case 1: { 21 assertOk.push([history.scrollRestoration, "History object has scrollRestoration property."]); 22 assertIs.push([history.scrollRestoration, "auto", "history.scrollRestoration's default value should be 'auto'."]); 23 history.scrollRestoration = "foobar"; 24 assertIs.push([history.scrollRestoration, "auto", "Invalid enum value should not change the value of an attribute."]); 25 history.scrollRestoration = "manual"; 26 assertIs.push([history.scrollRestoration, "manual", "Valid enum value should change the value of an attribute."]); 27 history.scrollRestoration = "auto"; 28 assertIs.push([history.scrollRestoration, "auto", "Valid enum value should change the value of an attribute."]); 29 bc.postMessage({command: "asserts", currentCase, assertIs, assertOk}); 30 document.getElementById("bottom").scrollIntoView(); 31 window.location.reload(false); 32 break; 33 } 34 case 2: { 35 assertIsNot.push([Math.round(window.scrollY), 0, "Should have restored scrolling."]); 36 assertIs.push([history.scrollRestoration, "auto", "Should have the same scrollRestoration as before reload."]); 37 history.scrollRestoration = "manual"; 38 bc.postMessage({command: "asserts", currentCase, assertIs, assertIsNot}); 39 window.location.reload(false); 40 break; 41 } 42 case 3: { 43 assertIs.push([window.scrollY, 0, "Should not have restored scrolling."]); 44 assertIs.push([history.scrollRestoration, "manual", "Should have the same scrollRestoration as before reload."]); 45 bc.postMessage({command: "asserts", currentCase, assertIs}); 46 bc.close(); 47 window.close(); 48 break; 49 } 50 } 51 } 52 window.onpageshow = (event) => { 53 bc.postMessage({command: "pageshow", persisted: event.persisted}); 54 } 55 </script> 56 </head> 57 <body> 58 <div style="border: 1px solid black; height: 5000px;"> 59 </div> 60 <div id="bottom">Hello world</div> 61 <a href="#hash" name="hash">hash</a> 62 </body> 63 </html>