test_bug915962.html (3552B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=915962 5 --> 6 <head> 7 <title>Test for Bug 915962</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <script type="text/javascript" src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script> 12 </head> 13 <body> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=915962">Mozilla Bug 915962</a> 15 <p id="display"></p> 16 <div id="content"> 17 </div> 18 <pre id="test"> 19 <script type="application/javascript"> 20 21 /** Test for Bug 915962 */ 22 23 var smoothScrollPref = "general.smoothScroll"; 24 SimpleTest.waitForExplicitFinish(); 25 var win = window.open("file_bug915962.html", "_blank", 26 "width=600,height=600,scrollbars=yes"); 27 28 29 function waitForScrollEvent(aWindow) { 30 return new Promise(resolve => { 31 aWindow.addEventListener("scroll", () => { SimpleTest.executeSoon(resolve); }, {once: true, capture: true}); 32 }); 33 } 34 35 function waitAndCheckNoScrollEvent(aWindow) { 36 let gotScroll = false; 37 function recordScroll() { 38 gotScroll = true; 39 } 40 aWindow.addEventListener("scroll", recordScroll, {capture: true}); 41 return waitToClearOutAnyPotentialScrolls(aWindow).then(function() { 42 aWindow.removeEventListener("scroll", recordScroll, {capture: true}); 43 is(gotScroll, false, "check that we didn't get a scroll"); 44 }); 45 } 46 47 SimpleTest.waitForFocus(function() { 48 SpecialPowers.pushPrefEnv({"set": [[smoothScrollPref, false]]}, startTest); 49 }, win); 50 async function startTest() { 51 // Make sure that pressing Space when a tabindex=-1 element is focused 52 // will scroll the page. 53 var button = win.document.querySelector("button"); 54 var sc = win.document.querySelector("div"); 55 sc.focus(); 56 await waitToClearOutAnyPotentialScrolls(win); 57 is(win.scrollY, 0, "Sanity check"); 58 let waitForScrolling = waitForScrollEvent(win); 59 synthesizeKey(" ", {}, win); 60 61 await waitForScrolling; 62 63 isnot(win.scrollY, 0, "Page is scrolled down"); 64 var oldY = win.scrollY; 65 waitForScrolling = waitForScrollEvent(win); 66 synthesizeKey(" ", {shiftKey: true}, win); 67 68 await waitForScrolling; 69 70 ok(win.scrollY < oldY, "Page is scrolled up"); 71 72 // Make sure that pressing Space when a tabindex=-1 element is focused 73 // will not scroll the page, and will activate the element. 74 button.focus(); 75 await waitToClearOutAnyPotentialScrolls(win); 76 var clicked = false; 77 button.onclick = () => clicked = true; 78 oldY = win.scrollY; 79 let waitForNoScroll = waitAndCheckNoScrollEvent(win); 80 synthesizeKey(" ", {}, win); 81 82 await waitForNoScroll; 83 84 ok(win.scrollY <= oldY, "Page is not scrolled down"); 85 ok(clicked, "The button should be clicked"); 86 synthesizeKey("VK_TAB", {}, win); 87 88 await waitToClearOutAnyPotentialScrolls(win); 89 90 oldY = win.scrollY; 91 waitForScrolling = waitForScrollEvent(win); 92 synthesizeKey(" ", {}, win); 93 94 await waitForScrolling; 95 96 ok(win.scrollY >= oldY, "Page is scrolled down"); 97 98 win.close(); 99 100 win = window.open("file_bug915962.html", "_blank", 101 "width=600,height=600,scrollbars=yes"); 102 103 SimpleTest.waitForFocus(async function() { 104 is(win.scrollY, 0, "Sanity check"); 105 waitForScrolling = waitForScrollEvent(win); 106 synthesizeKey(" ", {}, win); 107 108 await waitForScrolling; 109 110 isnot(win.scrollY, 0, "Page is scrolled down without crashing"); 111 112 win.close(); 113 114 SimpleTest.finish(); 115 }, win); 116 } 117 </script> 118 </pre> 119 </body> 120 </html>