test_scroll_position_restore_no_bfcache.html (1565B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>Test for Bug 1269539</title> 4 <script src="/tests/SimpleTest/SimpleTest.js"></script> 5 <script src="/tests/SimpleTest/paint_listener.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 7 <script> 8 SimpleTest.waitForExplicitFinish(); 9 10 let loadCount = 0; 11 let childWin; 12 let targetScrollPosition; 13 function handlePageShow(persisted) { 14 ok(typeof persisted == "boolean", "Should get the persisted state from the pageshow event"); 15 ok(!persisted, "Shouldn't have gotten into the bfcache"); 16 is(childWin.getComputedStyle(childWin.document.body).color, "rgb(0, 255, 0)", "Sheet should have been applied"); 17 let scroller = childWin.document.querySelector("#scroll"); 18 if (loadCount == 0) { 19 loadCount++; 20 targetScrollPosition = childWin.innerHeight; 21 isnot(targetScrollPosition, 0, "Should scroll somewhere"); 22 scroller.scrollTo(0, childWin.innerHeight); 23 childWin.requestAnimationFrame(() => childWin.requestAnimationFrame(() => { 24 childWin.location.reload(); 25 })); 26 } else { 27 childWin.requestAnimationFrame(() => childWin.requestAnimationFrame(() => { 28 // Verify that the scroll position was retained 29 is(scroller.scrollTop, targetScrollPosition, "Should have restored the scroll position"); 30 childWin.close(); 31 SimpleTest.finish(); 32 })); 33 } 34 } 35 36 SpecialPowers.pushPrefEnv({ 37 set: [ ["layout.disable-pixel-alignment", true] ] 38 }).then(() => { 39 childWin = window.open('file_scroll_position_restore_no_bfcache.html', '_blank'); 40 }); 41 </script>