Bug 1772588 [wpt PR 34302] - [wpt] Add test for block-in-inline offsetParent., a...
[gecko.git] / editor / libeditor / tests / test_bug915962.html
blob42cf4e3d67b19bb10843e57f02efac399c358924
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">
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});
32 });
35 function waitAndCheckNoScrollEvent(aWindow) {
36 let gotScroll = false;
37 function recordScroll() {
38 gotScroll = true;
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 });
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);
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.
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);
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);
90 oldY = win.scrollY;
91 waitForScrolling = waitForScrollEvent(win);
92 synthesizeKey(" ", {}, win);
94 await waitForScrolling;
96 ok(win.scrollY >= oldY, "Page is scrolled down");
98 win.close();
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");
112 win.close();
114 SimpleTest.finish();
115 }, win);
117 </script>
118 </pre>
119 </body>
120 </html>