test_bug851485.html (2443B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=851485 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 851485</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 12 <script type="application/javascript"> 13 14 /** Test for Bug 851485 */ 15 16 SimpleTest.waitForExplicitFinish(); 17 18 var testRunning = false; 19 async function runTest() { 20 if (testRunning) { 21 return; 22 } 23 testRunning = true; 24 25 var e = document.getElementsByTagName('iframe')[0]; 26 var win = e.contentWindow; 27 28 var p = new Promise((r) => { win.addEventListener("hashchange", r, { once: true }); }); 29 win.location.hash = '#anchor'; 30 await p; 31 32 win.scrollTo(0, 500); 33 34 p = new Promise((r) => { e.addEventListener("load", r, { once: true }); }); 35 win.location.reload(); 36 await p; 37 38 is(win.location.hash, "#anchor", "We set the location's hash to 'anchor'"); 39 // Allow a half pixel difference because the scroll position is aligned with 40 // screen pixels instead of CSS pixels (bug 1774315). 41 isfuzzy(win.scrollY, 500, 0.5, "Reloading keeps scroll position"); 42 43 var link = win.document.getElementsByTagName('a')[0]; 44 var anchor = win.document.getElementsByTagName('a')[1]; 45 p = new Promise((r) => { 46 var observer = new IntersectionObserver((entries) => { 47 info("IntersectionObserver: entering callback") 48 if (entries.some((entry) => entry.isIntersecting)) { 49 info("IntersectionObserver: some entry isIntersecting; disconnecting") 50 observer.disconnect(); 51 r(); 52 } 53 }); 54 observer.observe(anchor); 55 }); 56 win.document.body.offsetHeight; 57 synthesizeMouseAtCenter(link, {type: "mousedown"}, win); 58 synthesizeMouseAtCenter(link, {type: "mouseup"}, win); 59 info("Sending click") 60 sendMouseEvent({type: "click"}, link, win); 61 await p; 62 let actualScroll = win.scrollY; 63 info("Promise resolved (for IntersectionObserver). win.scrollY is " + 64 actualScroll); 65 66 ok(actualScroll > 3000, "Scrolling after load works."); 67 68 SimpleTest.finish(); 69 } 70 71 72 </script> 73 </head> 74 <body> 75 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=851485">Mozilla Bug 851485</a> 76 <p id="display"></p> 77 <div id="content" style="display: none"> 78 </div> 79 <pre id="test"> 80 </pre> 81 <iframe src="file_bug842853.html"></iframe> 82 <script> 83 84 </script> 85 </body> 86 </html>