|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=574663 |
|
5 --> |
|
6 <head> |
|
7 <title>Test for Bug 574663</title> |
|
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
9 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=574663">Mozilla Bug 574663</a> |
|
14 <p id="display"></p> |
|
15 <div id="content" style="display: none"> |
|
16 |
|
17 </div> |
|
18 <pre id="test"> |
|
19 <script type="application/javascript;version=1.7"> |
|
20 |
|
21 /** Test for Bug 574663 **/ |
|
22 |
|
23 function sendTouchpadScrollMotion(scrollbox, direction, ctrl, momentum) { |
|
24 var win = scrollbox.ownerDocument.defaultView; |
|
25 let event = { |
|
26 deltaMode: WheelEvent.DOM_DELTA_PIXEL, |
|
27 deltaY: direction * 3, |
|
28 lineOrPageDeltaY: direction, |
|
29 ctrlKey: ctrl, |
|
30 isMomentum: momentum |
|
31 }; |
|
32 synthesizeWheel(scrollbox, 10, 10, event, win); |
|
33 // then 5 additional pixel scrolls |
|
34 event.lineOrPageDeltaY = 0; |
|
35 for (let i = 0; i < 5; ++i) { |
|
36 synthesizeWheel(scrollbox, 10, 10, event, win); |
|
37 } |
|
38 } |
|
39 |
|
40 function runTest() { |
|
41 var win = open('data:text/html,<!DOCTYPE html>\n' + |
|
42 '<div id="scrollbox" style="height: 100px; overflow: auto;">' + |
|
43 ' <div style="height: 1000px;"></div>' + |
|
44 '</div>', '_blank', 'width=300,height=300'); |
|
45 SimpleTest.waitForFocus(function () { |
|
46 var scrollbox = win.document.getElementById("scrollbox"); |
|
47 let winUtils = SpecialPowers.getDOMWindowUtils(win); |
|
48 let outstandingTests = [ |
|
49 [false, false], |
|
50 [false, true], |
|
51 [true, false], |
|
52 [true, true], |
|
53 ]; |
|
54 |
|
55 // grab the refresh driver, since we want to make sure |
|
56 // async scrolls happen in deterministic time |
|
57 winUtils.advanceTimeAndRefresh(1000); |
|
58 |
|
59 function nextTest() { |
|
60 if (!outstandingTests.length) { |
|
61 winUtils.restoreNormalRefresh(); |
|
62 win.close(); |
|
63 clearPrefs(); |
|
64 SimpleTest.finish(); |
|
65 return; |
|
66 } |
|
67 |
|
68 let [ctrlKey, isMomentum] = outstandingTests.shift(); |
|
69 let scrollTopBefore = scrollbox.scrollTop; |
|
70 let zoomFactorBefore = winUtils.fullZoom; |
|
71 |
|
72 sendTouchpadScrollMotion(scrollbox, 1, ctrlKey, isMomentum); |
|
73 winUtils.advanceTimeAndRefresh(1000); // force scrolling to happen |
|
74 |
|
75 setTimeout(function () { |
|
76 if (!ctrlKey) { |
|
77 let postfix = isMomentum ? ", even after releasing the touchpad" : ""; |
|
78 // Normal scroll: scroll |
|
79 is(winUtils.fullZoom, zoomFactorBefore, "Normal scrolling shouldn't change zoom" + postfix); |
|
80 isnot(scrollbox.scrollTop, scrollTopBefore, "Normal scrolling should scroll" + postfix); |
|
81 } else { |
|
82 if (!isMomentum) { |
|
83 isnot(winUtils.fullZoom, zoomFactorBefore, "Ctrl-scrolling should zoom while the user is touching the touchpad"); |
|
84 is(scrollbox.scrollTop, scrollTopBefore, "Ctrl-scrolling shouldn't scroll while the user is touching the touchpad"); |
|
85 } else { |
|
86 is(winUtils.fullZoom, zoomFactorBefore, "Momentum scrolling shouldn't zoom, even when pressing Ctrl"); |
|
87 isnot(scrollbox.scrollTop, scrollTopBefore, "Momentum scrolling should scroll, even when pressing Ctrl"); |
|
88 } |
|
89 } |
|
90 // Revert the effect. |
|
91 sendTouchpadScrollMotion(scrollbox, -1, ctrlKey, isMomentum); |
|
92 winUtils.advanceTimeAndRefresh(1000); // force scrolling to happen |
|
93 |
|
94 setTimeout(nextTest, 20); |
|
95 }, 20); |
|
96 } |
|
97 nextTest(); |
|
98 }, win); |
|
99 } |
|
100 |
|
101 function initPrefs() |
|
102 { |
|
103 SpecialPowers.setBoolPref("general.smoothScroll", false); |
|
104 // Disables the app level scroll acceleration |
|
105 SpecialPowers.setIntPref("mousewheel.acceleration.start", -1); |
|
106 SpecialPowers.setBoolPref("mousewheel.system_scroll_override_on_root_content.enabled", false); |
|
107 // Enable zooming for ctrl-scrolling |
|
108 SpecialPowers.setIntPref("mousewheel.with_control.action", 3); |
|
109 } |
|
110 |
|
111 function clearPrefs() |
|
112 { |
|
113 SpecialPowers.clearUserPref("general.smoothScroll"); |
|
114 SpecialPowers.clearUserPref("mousewheel.acceleration.start"); |
|
115 SpecialPowers.clearUserPref("mousewheel.system_scroll_override_on_root_content.enabled"); |
|
116 SpecialPowers.clearUserPref("mousewheel.with_control.action"); |
|
117 } |
|
118 |
|
119 window.onload = function () { |
|
120 initPrefs(); |
|
121 SimpleTest.executeSoon(runTest); |
|
122 } |
|
123 |
|
124 SimpleTest.waitForExplicitFinish(); |
|
125 |
|
126 </script> |
|
127 </pre> |
|
128 |
|
129 </body> |
|
130 </html> |