5 <title>mousewheel coalescing
</title>
6 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
7 <script src=
"/tests/SimpleTest/EventUtils.js"></script>
8 <script src=
"apz_test_utils.js"></script>
9 <script src=
"apz_test_native_event_utils.js"></script>
10 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css"/>
13 function mousewheel(aWheelEvent
) {
14 // Make mousewheel handling slow
15 var start
= performance
.now();
16 while (performance
.now() < (start
+ 10));
17 wheelEvents
.push(aWheelEvent
);
20 function resolveIfProcessed(resolve
, minamount
) {
21 if (wheelEvents
.length
>= minamount
) {
22 SimpleTest
.requestFlakyTimeout("Make sure we got all events.");
23 setTimeout(function() { resolve(); }, 20);
25 setTimeout(function() { resolveIfProcessed(resolve
, minamount
); });
29 const kLineDeltaFactor
=
30 SpecialPowers
.getBoolPref("mousewheel.system_scroll_override.enabled", false)
31 ? SpecialPowers
.getIntPref("mousewheel.system_scroll_override.vertical.factor", 200) / 100
34 function checkWheelEvents(aExpectedDeltaMode
, aExpectedSumOfDeltaY
, aDescription
) {
35 const lineDeltaFactor
=
36 aExpectedDeltaMode
=== WheelEvent
.DOM_DELTA_LINE
? kLineDeltaFactor
: 1;
39 for (const wheelEvent
of wheelEvents
) {
40 succeeded
&= wheelEvent
.deltaMode
=== aExpectedDeltaMode
;
41 is(wheelEvent
.deltaMode
, aExpectedDeltaMode
,
42 `When ${aDescription}, the deltaMode of all wheel events should be ${aExpectedDeltaMode}`);
43 deltaY
+= wheelEvent
.deltaY
;
45 succeeded
&= deltaY
== aExpectedSumOfDeltaY
* lineDeltaFactor
;
46 is(deltaY
, aExpectedSumOfDeltaY
* lineDeltaFactor
,
47 `When ${aDescription}, sum of the deltaY of all wheel events should be ${aExpectedSumOfDeltaY * lineDeltaFactor}`);
51 async
function testOneSingleWheelEvent() {
52 await
new Promise(function(resolve
) {
54 var element
= document
.getElementById("wheelEventReceiver");
55 element
.addEventListener("wheel", mousewheel
, true);
57 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_LINE
});
59 setTimeout(function() { resolveIfProcessed(resolve
, 1); });
61 is(wheelEvents
.length
, 1,
62 "Synthesizing a wheel event via the parent process should cause 1 wheel event");
63 is(wheelEvents
[0]?.deltaMode
, WheelEvent
.DOM_DELTA_LINE
,
64 "When Synthesizing a wheel event via the parent process, the deltaMode of a wheel event should be WheelEvent.DOM_DELTA_LINE");
65 is(wheelEvents
[0]?.deltaY
, 3 * kLineDeltaFactor
,
66 `When Synthesizing a wheel event via the parent process, the deltaY of a wheel event should be ${3 * kLineDeltaFactor}`);
71 async
function testTwoSingleWheelEvents() {
73 return new Promise(function(resolve
) {
74 info("Synthesizing 2 wheel events via the parent process...");
76 var element
= document
.getElementById("wheelEventReceiver");
77 element
.addEventListener("wheel", mousewheel
, true);
79 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_LINE
});
80 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_LINE
});
82 setTimeout(function() { resolveIfProcessed(resolve
, 1); });
85 for (let i
= 0; i
< kMaxRetry
; i
++) {
87 if (wheelEvents
.length
== 2) {
88 // Even if failed to coalescing, the sum of deltaY values should be same
89 // as sum of the synthesized ones.
90 if (!checkWheelEvents(WheelEvent
.DOM_DELTA_LINE
, 6,
91 "synthesizing 2 wheel events via the parent process")) {
96 is(wheelEvents
.length
, 1,
97 "Synthesizing 2 wheel events via the parent process should cause only 1 wheel event");
98 checkWheelEvents(WheelEvent
.DOM_DELTA_LINE
, 6,
99 "synthesizing 2 wheel events via the parent process");
104 async
function testManySingleWheelEvents() {
106 return new Promise(function(resolve
) {
107 info("Synthesizing 5 wheel events via the parent process...");
109 var element
= document
.getElementById("wheelEventReceiver");
110 element
.addEventListener("wheel", mousewheel
, true);
112 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_LINE
});
113 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_LINE
});
114 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_LINE
});
115 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_LINE
});
116 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_LINE
});
118 setTimeout(function() { resolveIfProcessed(resolve
, 1); });
121 for (let i
= 0; i
< kMaxRetry
; i
++) {
123 if (wheelEvents
.length
> 1 && wheelEvents
.length
<= 5) {
124 // Even if failed to coalescing, the sum of deltaY values should be same
125 // as sum of the synthesized ones.
126 if (!checkWheelEvents(WheelEvent
.DOM_DELTA_LINE
, 15,
127 "synthesizing 5 wheel events via the parent process")) {
132 is(wheelEvents
.length
, 1,
133 "Synthesizing 5 wheel events via the parent process should cause only 1 wheel event");
134 checkWheelEvents(WheelEvent
.DOM_DELTA_LINE
, 15,
135 "synthesizing 5 wheel events via the parent process");
140 async
function testMixedWheelEvents() {
142 return new Promise(function(resolve
) {
143 info("Synthesizing 2 line wheel events, 1 page wheel event and 1 line wheel event...");
145 var element
= document
.getElementById("wheelEventReceiver");
146 element
.addEventListener("wheel", mousewheel
, true);
148 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_LINE
});
149 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_LINE
});
150 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_PAGE
});
151 synthesizeWheel(element
, 10, 10, { deltaY
: 3.0, deltaMode
: WheelEvent
.DOM_DELTA_LINE
});
153 setTimeout(function() { resolveIfProcessed(resolve
, 3); });
156 function checkGroupsOfWheelEvents() {
157 let succeeded
= true;
158 let deltaY
= [0, 0, 0];
160 const description
= "synthesizing 2 line wheel events, 1 page wheel event and 1 line wheel event";
161 for (const wheelEvent
of wheelEvents
) {
164 if (wheelEvent
.deltaMode
=== WheelEvent
.DOM_DELTA_LINE
) {
165 is(wheelEvent
.deltaMode
, WheelEvent
.DOM_DELTA_LINE
,
166 `When ${description}, the deltaMode of the first group should be WheelEvent.DOM_DELTA_LINE`);
172 if (wheelEvent
.deltaMode
=== WheelEvent
.DOM_DELTA_PAGE
) {
173 is(wheelEvent
.deltaMode
, WheelEvent
.DOM_DELTA_PAGE
,
174 `When ${description}, the deltaMode of the seconde group should be WheelEvent.DOM_DELTA_PAGE`);
180 succeeded
&= wheelEvent
.deltaMode
=== WheelEvent
.DOM_DELTA_LINE
;
181 is(wheelEvent
.deltaMode
, WheelEvent
.DOM_DELTA_LINE
,
182 `When ${description}, the deltaMode of the last group should be WheelEvent.DOM_DELTA_LINE`);
185 deltaY
[index
] += wheelEvent
.deltaY
;
187 succeeded
&= deltaY
== [6 * kLineDeltaFactor
, 3, 3 * kLineDeltaFactor
];
188 isDeeply(deltaY
, [6 * kLineDeltaFactor
, 3, 3 * kLineDeltaFactor
],
189 `When ${description}, sum of the deltaY of the each wheel event group should be same as sum of the synthesized ones`);
192 for (let i
= 0; i
< kMaxRetry
; i
++) {
194 if (wheelEvents
.length
!= 3 && wheelEvents
.length
> 1 && wheelEvents
.length
<= 5) {
195 // Even if failed to coalescing, the sum of deltaY values should be same
196 // as sum of the synthesized ones and the wheel events shouldn't be
198 if (!checkGroupsOfWheelEvents()) {
203 is(wheelEvents
.length
, 3,
204 "Synthesizing 2 line wheel events, 1 page wheel event and 1 line wheel event via the parent process should cause only 3 wheel events");
205 checkGroupsOfWheelEvents();
210 async
function runTests() {
211 var enabled
= SpecialPowers
.getDOMWindowUtils(window
).asyncPanZoomEnabled
;
213 // Avoid synthesized mousemove events to be fired at the system cursor.
214 await
promiseNativeMouseEvent({
220 await SpecialPowers
.pushPrefEnv({set: [
221 ["test.events.async.enabled", true],
222 ["dom.event.wheel-coalesced.testing", true],
224 await
promiseElementReadyForUserInput(document
.documentElement
);
225 await SpecialPowers
.pushPrefEnv({clear
: [["test.events.async.enabled"]]});
227 await
testOneSingleWheelEvent();
228 await
testTwoSingleWheelEvents();
229 await
testManySingleWheelEvents();
230 await
testMixedWheelEvents();
232 setTimeout("SimpleTest.finish()");
238 <body onload=
"SimpleTest.waitForFocus(runTests);">
239 <div id=
"wheelEventReceiver" style=
"width:100px;height:100px;"></div>