4 https://bugzilla.mozilla.org/show_bug.cgi?id=915962
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>
14 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=915962">Mozilla Bug
915962</a>
19 <script type=
"application/javascript">
21 /** Test for Bug
915962 **/
23 var smoothScrollPref =
"general.smoothScroll";
24 SimpleTest.waitForExplicitFinish();
25 var win = window.open(
"file_bug915962.html",
"_blank",
26 "width=600,height=600,scrollbars=yes");
29 function waitForScrollEvent(aWindow) {
30 return new Promise(resolve =
> {
31 aWindow.addEventListener(
"scroll", () =
> { SimpleTest.executeSoon(resolve); }, {once: true, capture: true});
35 function waitAndCheckNoScrollEvent(aWindow) {
36 let gotScroll = false;
37 function recordScroll() {
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");
47 SimpleTest.waitForFocus(function() {
48 SpecialPowers.pushPrefEnv({
"set": [[smoothScrollPref, false]]}, startTest);
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");
56 await waitToClearOutAnyPotentialScrolls(win);
57 is(win.scrollY,
0,
"Sanity check");
58 let waitForScrolling = waitForScrollEvent(win);
59 synthesizeKey(
" ", {}, win);
61 await waitForScrolling;
63 isnot(win.scrollY,
0,
"Page is scrolled down");
64 var oldY = win.scrollY;
65 waitForScrolling = waitForScrollEvent(win);
66 synthesizeKey(
" ", {shiftKey: true}, win);
68 await waitForScrolling;
70 ok(win.scrollY < oldY,
"Page is scrolled up");
72 // Make sure that pressing Space when a tabindex=-
1 element is focused
73 // will not scroll the page, and will activate the element.
75 await waitToClearOutAnyPotentialScrolls(win);
77 button.onclick = () =
> clicked = true;
79 let waitForNoScroll = waitAndCheckNoScrollEvent(win);
80 synthesizeKey(
" ", {}, win);
82 await waitForNoScroll;
84 ok(win.scrollY <= oldY,
"Page is not scrolled down");
85 ok(clicked,
"The button should be clicked");
86 synthesizeKey(
"VK_TAB", {}, win);
88 await waitToClearOutAnyPotentialScrolls(win);
91 waitForScrolling = waitForScrollEvent(win);
92 synthesizeKey(
" ", {}, win);
94 await waitForScrolling;
96 ok(win.scrollY
>= oldY,
"Page is scrolled down");
100 win = window.open(
"file_bug915962.html",
"_blank",
101 "width=600,height=600,scrollbars=yes");
103 SimpleTest.waitForFocus(async function() {
104 is(win.scrollY,
0,
"Sanity check");
105 waitForScrolling = waitForScrollEvent(win);
106 synthesizeKey(
" ", {}, win);
108 await waitForScrolling;
110 isnot(win.scrollY,
0,
"Page is scrolled down without crashing");