test_bug1151421.html (1815B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1151421 5 --> 6 <head> 7 <title>Test for Bug 1151421</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1151421">Mozilla Bug 1151421</a> 13 14 <script type="application/javascript"> 15 16 /** Test for Bug 1151421 */ 17 SimpleTest.waitForExplicitFinish(); 18 19 function childLoad() { 20 // Spin the event loop so we leave the onload handler. 21 SimpleTest.executeSoon(childLoad2); 22 } 23 24 function childLoad2() { 25 let iframe = document.getElementById("iframe"); 26 let cw = iframe.contentWindow; 27 let content = cw.document.getElementById("content"); 28 29 // Create a function to calculate an invariant. 30 let topPlusOffset = function() { 31 return Math.round(content.getBoundingClientRect().top + cw.pageYOffset); 32 }; 33 34 let initialTPO = topPlusOffset(); 35 36 // Scroll the iframe to various positions, and check the TPO. 37 // Scrolling down to the bottom will adjust the page offset by a fractional amount. 38 let positions = [-100, 0.17, 0, 1.5, 10.41, 1e6, 12.1]; 39 40 // Run some tests with scrollTo() and ensure we have the same invariant after scrolling. 41 positions.forEach(function(pos) { 42 cw.scrollTo(0, pos); 43 is(topPlusOffset(), initialTPO, "Top plus offset should remain invariant across scrolling."); 44 }); 45 46 positions.reverse().forEach(function(pos) { 47 cw.scrollTo(0, pos); 48 is(topPlusOffset(), initialTPO, "(reverse) Top plus offset should remain invariant across scrolling."); 49 }); 50 51 SimpleTest.finish(); 52 } 53 54 </script> 55 56 <!-- When the iframe loads, it calls childLoad(). --> 57 <br> 58 <iframe height='100px' id='iframe' src='file_bug1151421.html'></iframe> 59 60 </body> 61 </html>