2 <html style=
"font-size: 32px;">
4 <title>Test for D3E WheelEvent
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <script src=
"/tests/SimpleTest/EventUtils.js"></script>
7 <script src=
"/tests/SimpleTest/paint_listener.js"></script>
8 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
12 <div id=
"scrollable" style=
"font-family: monospace; font-size: 16px; line-height: 1; overflow: auto; width: 200px; height: 200px;">
13 <div id=
"scrolled" style=
"font-size: 64px; width: 5000px; height: 5000px;">
14 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
15 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
16 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
17 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
18 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
19 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
20 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
21 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
22 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
23 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
24 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
25 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
26 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
27 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
28 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
29 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
30 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
31 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
32 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
33 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
34 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
35 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
36 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
37 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
38 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
39 Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text. Tere is a lot of text.
<br>
42 <div id=
"content" style=
"display: none">
46 <script type=
"application/javascript">
48 SimpleTest.waitForExplicitFinish();
49 SimpleTest.waitForFocus(runTest, window);
51 var gScrollableElement = document.getElementById(
"scrollable");
52 var gScrolledElement = document.getElementById(
"scrolled");
55 var gHorizontalLine =
0;
59 function sendWheelAndWait(aX, aY, aEvent)
61 sendWheelAndPaint(gScrollableElement, aX, aY, aEvent, continueTest);
64 function* prepareScrollUnits()
67 function handler(aEvent)
69 result = aEvent.detail;
70 aEvent.preventDefault();
72 window.addEventListener(
"MozMousePixelScroll", handler, { capture: true, passive: false });
74 yield sendWheelAndWait(
10,
10,
75 { deltaMode: WheelEvent.DOM_DELTA_LINE,
76 deltaY:
1.0, lineOrPageDeltaY:
1 });
78 ok(gLineHeight
> 10 && gLineHeight <
25,
"prepareScrollUnits: gLineHeight may be illegal value, got " + gLineHeight);
81 yield sendWheelAndWait(
10,
10,
82 { deltaMode: WheelEvent.DOM_DELTA_LINE,
83 deltaX:
1.0, lineOrPageDeltaX:
1 });
84 gHorizontalLine = result;
85 ok(gHorizontalLine
> 5 && gHorizontalLine <
16,
"prepareScrollUnits: gHorizontalLine may be illegal value, got " + gHorizontalLine);
88 yield sendWheelAndWait(
10,
10,
89 { deltaMode: WheelEvent.DOM_DELTA_PAGE,
90 deltaY:
1.0, lineOrPageDeltaY:
1 });
92 // XXX Cannot we know the actual scroll port size?
93 ok(gPageHeight
>=
150 && gPageHeight <=
200,
94 "prepareScrollUnits: gPageHeight is strange value, got " + gPageHeight);
97 yield sendWheelAndWait(
10,
10,
98 { deltaMode: WheelEvent.DOM_DELTA_PAGE,
99 deltaX:
1.0, lineOrPageDeltaX:
1 });
101 ok(gPageWidth
>=
150 && gPageWidth <=
200,
102 "prepareScrollUnits: gPageWidth is strange value, got " + gPageWidth);
104 window.removeEventListener(
"MozMousePixelScroll", handler, true);
107 function testMakingUntrustedEvent()
109 const kCreateEventArgs = [
110 "WheelEvent",
"wheelevent",
"wheelEvent",
"Wheelevent"
113 for (var i =
0; i < kCreateEventArgs.length; i++) {
115 // We never support WheelEvent construction with document.createEvent().
116 var event = document.createEvent(kCreateEventArgs[i]);
117 ok(false,
"document.createEvent(" + kCreateEventArgs[i] +
") should throw an error");
119 ok(true,
"document.createEvent(" + kCreateEventArgs[i] +
") threw an error");
123 var wheelEvent = new WheelEvent(
"wheel");
124 ok(wheelEvent instanceof WheelEvent,
125 "new WheelEvent() should create an instance of WheelEvent");
126 ok(typeof(wheelEvent.initWheelEvent) !=
"function",
127 "WheelEvent must not have initWheelEvent()");
130 // delta_multiplier prefs should cause changing delta values of trusted events only.
131 // And also legacy events' detail value should be changed too.
132 function* testDeltaMultiplierPrefs()
134 const kModifierAlt =
0x01;
135 const kModifierControl =
0x02;
136 const kModifierMeta =
0x04;
137 const kModifierShift =
0x08;
138 const kModifierWin =
0x10;
142 expected: [
0, kModifierShift | kModifierAlt, kModifierShift | kModifierControl,
143 kModifierShift | kModifierMeta, kModifierShift | kModifierWin,
144 kModifierControl | kModifierAlt, kModifierMeta | kModifierAlt ],
145 unexpected: [ kModifierAlt, kModifierControl, kModifierMeta, kModifierShift, kModifierWin ] },
147 expected: [ kModifierAlt ],
148 unexpected: [
0, kModifierControl, kModifierMeta, kModifierShift, kModifierWin,
149 kModifierShift | kModifierAlt, kModifierControl | kModifierAlt,
150 kModifierMeta | kModifierAlt ] },
151 { name:
"with_control",
152 expected: [ kModifierControl ],
153 unexpected: [
0, kModifierAlt, kModifierMeta, kModifierShift, kModifierWin,
154 kModifierShift | kModifierControl, kModifierControl | kModifierAlt,
155 kModifierMeta | kModifierControl ] },
157 expected: [ kModifierMeta ],
158 unexpected: [
0, kModifierAlt, kModifierControl, kModifierShift, kModifierWin,
159 kModifierShift | kModifierMeta, kModifierControl | kModifierMeta,
160 kModifierMeta | kModifierAlt ] },
161 { name:
"with_shift",
162 expected: [ kModifierShift ],
163 unexpected: [
0, kModifierAlt, kModifierControl, kModifierMeta, kModifierWin,
164 kModifierShift | kModifierAlt, kModifierControl | kModifierShift,
165 kModifierMeta | kModifierShift ] },
167 expected: [ kModifierWin ],
168 unexpected: [
0, kModifierAlt, kModifierControl, kModifierMeta, kModifierShift,
169 kModifierShift | kModifierWin ] },
172 // Note that this test doesn't support complicated lineOrPageDelta values which are computed with
173 // accumulated delta values by the prefs. If you need to test the lineOrPageDelta accumulation,
174 // use test_continuous_dom_wheel_event.html.
176 { deltaMode: WheelEvent.DOM_DELTA_PIXEL,
177 deltaX: gHorizontalLine, deltaY: gLineHeight, deltaZ: gLineHeight, lineOrPageDeltaX:
1, lineOrPageDeltaY:
1 },
178 { deltaMode: WheelEvent.DOM_DELTA_LINE,
179 deltaX:
1.0, deltaY:
1.0, deltaZ:
1.0, lineOrPageDeltaX:
1, lineOrPageDeltaY:
1 },
180 { deltaMode: WheelEvent.DOM_DELTA_PAGE,
181 deltaX:
1.0, deltaY:
1.0, deltaZ:
1.0, lineOrPageDeltaX:
1, lineOrPageDeltaY:
1 },
182 { deltaMode: WheelEvent.DOM_DELTA_PIXEL,
183 deltaX: -gHorizontalLine, deltaY: -gLineHeight, deltaZ: -gLineHeight, lineOrPageDeltaX: -
1, lineOrPageDeltaY: -
1 },
184 { deltaMode: WheelEvent.DOM_DELTA_LINE,
185 deltaX: -
1.0, deltaY: -
1.0, deltaZ: -
1.0, lineOrPageDeltaX: -
1, lineOrPageDeltaY: -
1 },
186 { deltaMode: WheelEvent.DOM_DELTA_LINE, skipDeltaModeCheck: true,
187 deltaX: -
1.0, deltaY: -
1.0, deltaZ: -
1.0, lineOrPageDeltaX: -
1, lineOrPageDeltaY: -
1 },
188 { deltaMode: WheelEvent.DOM_DELTA_PAGE,
189 deltaX: -
1.0, deltaY: -
1.0, deltaZ: -
1.0, lineOrPageDeltaX: -
1, lineOrPageDeltaY: -
1 },
192 const kDeltaMultiplierPrefs = [
193 "delta_multiplier_x",
"delta_multiplier_y",
"delta_multiplier_z"
196 const kPrefValues = [
197 200,
50,
0, -
50, -
150
200 var currentTest, currentModifiers, currentEvent, currentPref, currentMultiplier, testingExpected;
201 var expectedAsyncHandlerCalls;
203 var calledHandlers = { wheel: false,
204 DOMMouseScroll: { horizontal: false, vertical: false },
205 MozMousePixelScroll: { horizontal: false, vertical: false } };
207 function deltaToPixels(mode, delta, horizontal) {
209 case WheelEvent.DOM_DELTA_PIXEL:
211 case WheelEvent.DOM_DELTA_LINE:
212 return delta * (horizontal ? gHorizontalLine : gLineHeight);
213 case WheelEvent.DOM_DELTA_PAGE:
214 return delta * (horizontal ? gPageWidth : gPageHeight);
216 throw new Error(
"Unknown delta mode");
219 function defaultScrollMultiplier(horizontal) {
220 if (!SpecialPowers.getBoolPref(
"mousewheel.system_scroll_override.enabled")) {
223 return SpecialPowers.getIntPref(`mousewheel.system_scroll_override.${horizontal ?
"horizontal" :
"vertical"}.factor`) /
100;
226 function wheelEventHandler(aEvent) {
227 calledHandlers.wheel = true;
229 var expectedDeltaX = currentEvent.deltaX;
230 var expectedDeltaY = currentEvent.deltaY;
231 var expectedDeltaZ = currentEvent.deltaZ;
233 if (testingExpected) {
234 switch (currentPref.charAt(currentPref.length -
1)) {
236 expectedDeltaX *= currentMultiplier;
239 expectedDeltaY *= currentMultiplier;
242 expectedDeltaZ *= currentMultiplier;
245 } else if (aEvent.isTrusted && aEvent.deltaMode == WheelEvent.DOM_DELTA_LINE) {
246 expectedDeltaX *= defaultScrollMultiplier(true);
247 expectedDeltaY *= defaultScrollMultiplier(false);
249 is(aEvent.deltaMode, currentEvent.deltaMode, description +
"deltaMode (" + currentEvent.deltaMode +
") was invalid");
250 is(aEvent.deltaX, expectedDeltaX, description +
"deltaX (" + currentEvent.deltaX +
") was invalid");
251 is(aEvent.deltaY, expectedDeltaY, description +
"deltaY (" + currentEvent.deltaY +
") was invalid");
252 is(aEvent.deltaZ, expectedDeltaZ, description +
"deltaZ (" + currentEvent.deltaZ +
") was invalid");
253 is(aEvent.wheelDeltaX, -Math.round(aEvent.isTrusted ?
3 * deltaToPixels(aEvent.deltaMode, expectedDeltaX, true) : expectedDeltaX), `${description}wheelDeltaX (${aEvent.wheelDeltaX}) was invalid`);
254 is(aEvent.wheelDeltaY, -Math.round(aEvent.isTrusted ?
3 * deltaToPixels(aEvent.deltaMode, expectedDeltaY, false) : expectedDeltaY), `${description}wheelDeltaY (${aEvent.wheelDeltaY}) was invalid`);
255 is(aEvent.wheelDelta, aEvent.wheelDeltaY || aEvent.wheelDeltaX, description +
"wheelDelta was invalid");
257 if (expectedAsyncHandlerCalls
> 0 && --expectedAsyncHandlerCalls ==
0) {
258 setTimeout(continueTest,
0);
262 function legacyEventHandler(aEvent) {
263 var isHorizontal = (aEvent.axis == MouseScrollEvent.HORIZONTAL_AXIS);
264 var isScrollEvent = (aEvent.type ==
"DOMMouseScroll");
267 calledHandlers.DOMMouseScroll.horizontal = true;
269 calledHandlers.DOMMouseScroll.vertical = true;
273 calledHandlers.MozMousePixelScroll.horizontal = true;
275 calledHandlers.MozMousePixelScroll.vertical = true;
278 var eventName = (isHorizontal ?
"Horizontal " :
"Vertical ") + aEvent.type +
" ";
281 expectedDetail = isHorizontal ? currentEvent.lineOrPageDeltaX : currentEvent.lineOrPageDeltaY;
282 if (currentEvent.deltaMode == WheelEvent.DOM_DELTA_PAGE && expectedDetail) {
283 expectedDetail = ((expectedDetail
> 0) ? UIEvent.SCROLL_PAGE_DOWN : UIEvent.SCROLL_PAGE_UP);
286 expectedDetail = isHorizontal ? currentEvent.deltaX : currentEvent.deltaY;
287 if (expectedDetail) {
288 if (currentEvent.deltaMode == WheelEvent.DOM_DELTA_LINE) {
289 expectedDetail *= (isHorizontal ? gHorizontalLine : gLineHeight);
290 } else if (currentEvent.deltaMode == WheelEvent.DOM_DELTA_PAGE) {
291 if (expectedDetail
> 0) {
292 expectedDetail = (isHorizontal ? gPageWidth : gPageHeight);
294 expectedDetail = (isHorizontal ? -gPageWidth : -gPageHeight);
299 if (testingExpected) {
300 if ((isHorizontal && currentPref.charAt(currentPref.length -
1) ==
"x") ||
301 (!isHorizontal && currentPref.charAt(currentPref.length -
1) ==
"y")) {
302 // If it's a page scroll event, the detail value is UIEvent.SCROLL_PAGE_DOWN or
303 // UIEvent.SCROLL_PAGE_UP. If the delta value sign is reverted, we need to
304 // revert the expected detail value too. Otherwise, don't touch it.
305 if (isScrollEvent && currentEvent.deltaMode == WheelEvent.DOM_DELTA_PAGE) {
306 if (currentMultiplier <
0) {
307 expectedDetail = ((expectedDetail == UIEvent.SCROLL_PAGE_UP) ? UIEvent.SCROLL_PAGE_DOWN : UIEvent.SCROLL_PAGE_UP);
310 expectedDetail *= currentMultiplier;
311 expectedDetail = expectedDetail <
0 ? Math.ceil(expectedDetail) : Math.floor(expectedDetail);
315 is(aEvent.detail, expectedDetail, description + eventName +
"detail was invalid");
317 aEvent.preventDefault();
319 if (expectedAsyncHandlerCalls
> 0 && --expectedAsyncHandlerCalls ==
0) {
320 setTimeout(continueTest,
0);
324 window.addEventListener(
"wheel", wheelEventHandler, true);
325 window.addEventListener(
"DOMMouseScroll", legacyEventHandler, true);
326 window.addEventListener(
"MozMousePixelScroll", legacyEventHandler, true);
328 function* dispatchEvent(aIsExpected) {
329 for (var i =
0; i < kEvents.length; i++) {
330 currentEvent = kEvents[i];
331 currentEvent.shiftKey = (currentModifiers & kModifierShift) !=
0;
332 currentEvent.ctrlKey = (currentModifiers & kModifierControl) !=
0;
333 currentEvent.altKey = (currentModifiers & kModifierAlt) !=
0;
334 currentEvent.metaKey = (currentModifiers & kModifierMeta) !=
0;
335 currentEvent.osKey = (currentModifiers & kModifierWin) !=
0;
336 var modifierList =
"";
337 if (currentEvent.shiftKey) {
338 modifierList +=
"Shift ";
340 if (currentEvent.ctrlKey) {
341 modifierList +=
"Control ";
343 if (currentEvent.altKey) {
344 modifierList +=
"Alt ";
346 if (currentEvent.metaKey) {
347 modifierList +=
"Meta ";
349 if (currentEvent.osKey) {
350 modifierList +=
"Win ";
353 for (var j =
0; j < kPrefValues.length; j++) {
354 currentMultiplier = kPrefValues[j] /
100;
355 for (var k =
0; k < kDeltaMultiplierPrefs.length; k++) {
356 currentPref =
"mousewheel." + currentTest.name +
"." + kDeltaMultiplierPrefs[k];
358 yield SpecialPowers.pushPrefEnv({
"set": [[currentPref, kPrefValues[j]]]}, continueTest);
360 gScrollableElement.scrollTop = gScrollableElement.scrollBottom =
1000;
362 // trusted event's delta valuses should be reverted by the pref.
363 testingExpected = aIsExpected;
365 var expectedProps = {
366 deltaX: currentEvent.deltaX * currentMultiplier,
367 deltaY: currentEvent.deltaY * currentMultiplier,
368 dletaZ: currentEvent.deltaZ * currentMultiplier,
369 lineOrPageDeltaX: currentEvent.lineOrPageDeltaX * currentMultiplier,
370 lineOrPageDeltaY: currentEvent.lineOrPageDeltaY * currentMultiplier,
373 var expectedWheel = expectedProps.deltaX !=
0 || expectedProps.deltaY !=
0 || expectedProps.deltaZ !=
0;
374 var expectedDOMMouseX = expectedProps.lineOrPageDeltaX
>=
1 || expectedProps.lineOrPageDeltaX <= -
1;
375 var expectedDOMMouseY = expectedProps.lineOrPageDeltaY
>=
1 || expectedProps.lineOrPageDeltaY <= -
1;
376 var expectedMozMouseX = expectedProps.deltaX
>=
1 || expectedProps.deltaX <= -
1;
377 var expectedMozMouseY = expectedProps.deltaY
>=
1 || expectedProps.deltaY <= -
1;
379 expectedAsyncHandlerCalls =
0;
380 if (expectedWheel) ++expectedAsyncHandlerCalls;
381 if (expectedDOMMouseX) ++expectedAsyncHandlerCalls;
382 if (expectedDOMMouseY) ++expectedAsyncHandlerCalls;
383 if (expectedMozMouseX) ++expectedAsyncHandlerCalls;
384 if (expectedMozMouseY) ++expectedAsyncHandlerCalls;
386 description =
"testDeltaMultiplierPrefs, pref: " + currentPref +
"=" + kPrefValues[j] +
387 ", deltaMode: " + currentEvent.deltaMode +
", modifiers: \"" + modifierList + "\
", (trusted event): ";
388 yield synthesizeWheel(gScrollableElement,
10,
10, currentEvent);
390 is(calledHandlers.wheel,
392 description +
"wheel event was (not) fired");
393 is(calledHandlers.DOMMouseScroll.horizontal,
395 description +
"Horizontal DOMMouseScroll event was (not) fired");
396 is(calledHandlers.DOMMouseScroll.vertical,
398 description +
"Vertical DOMMouseScroll event was (not) fired");
399 is(calledHandlers.MozMousePixelScroll.horizontal,
401 description +
"Horizontal MozMousePixelScroll event was (not) fired");
402 is(calledHandlers.MozMousePixelScroll.vertical,
404 description +
"Vertical MozMousePixelScroll event was (not) fired");
406 calledHandlers = { wheel: false,
407 DOMMouseScroll: { horizontal: false, vertical: false },
408 MozMousePixelScroll: { horizontal: false, vertical: false } };
410 // untrusted event's delta values shouldn't be reverted by the pref.
411 testingExpected = false;
415 shiftKey: currentEvent.shiftKey,
416 ctrlKey: currentEvent.ctrlKey,
417 altKey: currentEvent.altKey,
418 metaKey: currentEvent.metaKey,
419 deltaX: currentEvent.deltaX,
420 deltaY: currentEvent.deltaY,
421 deltaZ: currentEvent.deltaZ,
422 deltaMode: currentEvent.deltaMode,
424 var untrustedEvent = new WheelEvent(
"wheel", props);
426 description =
"testDeltaMultiplierPrefs, pref: " + currentPref +
"=" + kPrefValues[j] +
427 ", deltaMode: " + currentEvent.deltaMode +
", modifiers: \"" + modifierList + "\
", (untrusted event): ";
428 gScrollableElement.dispatchEvent(untrustedEvent);
430 ok(calledHandlers.wheel, description +
"wheel event was not fired for untrusted event");
431 ok(!calledHandlers.DOMMouseScroll.horizontal,
432 description +
"Horizontal DOMMouseScroll event was fired for untrusted event");
433 ok(!calledHandlers.DOMMouseScroll.vertical,
434 description +
"Vertical DOMMouseScroll event was fired for untrusted event");
435 ok(!calledHandlers.MozMousePixelScroll.horizontal,
436 description +
"Horizontal MozMousePixelScroll event was fired for untrusted event");
437 ok(!calledHandlers.MozMousePixelScroll.vertical,
438 description +
"Vertical MozMousePixelScroll event was fired for untrusted event");
440 yield SpecialPowers.pushPrefEnv({
"set": [[currentPref,
100]]}, continueTest);
442 calledHandlers = { wheel: false,
443 DOMMouseScroll: { horizontal: false, vertical: false },
444 MozMousePixelScroll: { horizontal: false, vertical: false } };
447 // We should skip other value tests if testing with modifier key.
448 // If we didn't do so, it would test too many times, but we don't need to do so.
449 if (kTests.name !=
"default") {
456 for (var i =
0; i < kTests.length; i++) {
457 currentTest = kTests[i];
458 for (var j =
0; j < currentTest.expected.length; j++) {
459 currentModifiers = currentTest.expected[j];
460 yield* dispatchEvent(true);
462 for (var k =
0; k < currentTest.unexpected.length; k++) {
463 currentModifiers = currentTest.unexpected[k];
464 yield* dispatchEvent(false);
468 window.removeEventListener(
"wheel", wheelEventHandler, true);
469 window.removeEventListener(
"DOMMouseScroll", legacyEventHandler, true);
470 window.removeEventListener(
"MozMousePixelScroll", legacyEventHandler, true);
473 // Untrusted wheel events shouldn't cause legacy mouse scroll events.
474 function testDispatchingUntrustEvent()
476 var descriptionBase =
"testDispatchingUntrustEvent, ";
477 var description, wheelEventFired;
478 function wheelEventHandler(aEvent)
480 wheelEventFired = true;
483 function legacyEventHandler(aEvent)
485 ok(false, aEvent.type +
" must not be fired");
488 window.addEventListener(
"wheel", wheelEventHandler, true);
489 window.addEventListener(
"DOMMouseScroll", legacyEventHandler, true);
490 window.addEventListener(
"MozMousePixelScroll", legacyEventHandler, true);
492 description = descriptionBase +
"dispatching a pixel wheel event: ";
493 wheelEventFired = false;
494 var untrustedPixelEvent = new WheelEvent(
"wheel", {
495 bubbles: true, cancelable: true,
496 deltaX:
24.0, deltaY:
24.0,
497 deltaMode: WheelEvent.DOM_DELTA_PIXEL,
499 gScrolledElement.dispatchEvent(untrustedPixelEvent);
500 ok(wheelEventFired, description +
"wheel event wasn't fired");
502 description = descriptionBase +
"dispatching a line wheel event: ";
503 wheelEventFired = false;
504 var untrustedLineEvent = new WheelEvent(
"wheel", {
505 bubbles: true, cancelable: true,
506 deltaX:
3.0, deltaY:
3.0,
507 deltaMode: WheelEvent.DOM_DELTA_LINE,
509 gScrolledElement.dispatchEvent(untrustedLineEvent);
510 ok(wheelEventFired, description +
"wheel event wasn't fired");
512 description = descriptionBase +
"dispatching a page wheel event: ";
513 wheelEventFired = false;
514 var untrustedPageEvent = new WheelEvent(
"wheel", {
515 bubbles: true, cancelable: true,
516 deltaX:
1.0, deltaY:
1.0,
517 deltaMode: WheelEvent.DOM_DELTA_PAGE,
519 gScrolledElement.dispatchEvent(untrustedPageEvent);
520 ok(wheelEventFired, description +
"wheel event wasn't fired");
522 window.removeEventListener(
"wheel", wheelEventHandler, true);
523 window.removeEventListener(
"DOMMouseScroll", legacyEventHandler, true);
524 window.removeEventListener(
"MozMousePixelScroll", legacyEventHandler, true);
527 function* testEventOrder()
529 const kWheelEvent =
0x0001;
530 const kDOMMouseScrollEvent =
0x0002;
531 const kMozMousePixelScrollEvent =
0x0004;
532 const kVerticalScrollEvent =
0x0010;
533 const kHorizontalScrollEvent =
0x0020;
534 const kInSystemGroup =
0x0100;
535 const kDefaultPrevented =
0x1000;
541 description:
"Testing the order of the events without preventDefault()",
542 expectedEvents: [ kWheelEvent,
543 kDOMMouseScrollEvent | kVerticalScrollEvent,
544 kDOMMouseScrollEvent | kVerticalScrollEvent | kInSystemGroup,
545 kMozMousePixelScrollEvent | kVerticalScrollEvent,
546 kMozMousePixelScrollEvent | kVerticalScrollEvent | kInSystemGroup,
547 kDOMMouseScrollEvent | kHorizontalScrollEvent,
548 kDOMMouseScrollEvent | kHorizontalScrollEvent | kInSystemGroup,
549 kMozMousePixelScrollEvent | kHorizontalScrollEvent,
550 kMozMousePixelScrollEvent | kHorizontalScrollEvent | kInSystemGroup,
551 kWheelEvent | kInSystemGroup],
553 doPreventDefaultAt:
0,
556 description:
"Testing the order of the events, calling preventDefault() at default group wheel event",
557 expectedEvents: [ kWheelEvent,
558 kWheelEvent | kInSystemGroup | kDefaultPrevented],
560 doPreventDefaultAt: kWheelEvent,
563 description:
"Testing the order of the events, calling preventDefault() at default group DOMMouseScroll event",
564 expectedEvents: [ kWheelEvent,
565 kDOMMouseScrollEvent | kVerticalScrollEvent,
566 kDOMMouseScrollEvent | kVerticalScrollEvent | kInSystemGroup | kDefaultPrevented,
567 kMozMousePixelScrollEvent | kVerticalScrollEvent | kDefaultPrevented,
568 kMozMousePixelScrollEvent | kVerticalScrollEvent | kInSystemGroup | kDefaultPrevented,
569 kDOMMouseScrollEvent | kHorizontalScrollEvent,
570 kDOMMouseScrollEvent | kHorizontalScrollEvent | kInSystemGroup,
571 kMozMousePixelScrollEvent | kHorizontalScrollEvent,
572 kMozMousePixelScrollEvent | kHorizontalScrollEvent | kInSystemGroup,
573 kWheelEvent | kInSystemGroup | kDefaultPrevented],
575 doPreventDefaultAt: kDOMMouseScrollEvent | kVerticalScrollEvent,
578 description:
"Testing the order of the events, calling preventDefault() at default group MozMousePixelScroll event",
579 expectedEvents: [ kWheelEvent,
580 kDOMMouseScrollEvent | kVerticalScrollEvent,
581 kDOMMouseScrollEvent | kVerticalScrollEvent | kInSystemGroup,
582 kMozMousePixelScrollEvent | kVerticalScrollEvent,
583 kMozMousePixelScrollEvent | kVerticalScrollEvent | kInSystemGroup | kDefaultPrevented,
584 kDOMMouseScrollEvent | kHorizontalScrollEvent,
585 kDOMMouseScrollEvent | kHorizontalScrollEvent | kInSystemGroup,
586 kMozMousePixelScrollEvent | kHorizontalScrollEvent,
587 kMozMousePixelScrollEvent | kHorizontalScrollEvent | kInSystemGroup,
588 kWheelEvent | kInSystemGroup | kDefaultPrevented],
590 doPreventDefaultAt: kMozMousePixelScrollEvent | kVerticalScrollEvent,
593 description:
"Testing the order of the events, calling preventDefault() at system group DOMMouseScroll event",
594 expectedEvents: [ kWheelEvent,
595 kDOMMouseScrollEvent | kVerticalScrollEvent,
596 kDOMMouseScrollEvent | kVerticalScrollEvent | kInSystemGroup,
597 kMozMousePixelScrollEvent | kVerticalScrollEvent | kDefaultPrevented,
598 kMozMousePixelScrollEvent | kVerticalScrollEvent | kInSystemGroup | kDefaultPrevented,
599 kDOMMouseScrollEvent | kHorizontalScrollEvent,
600 kDOMMouseScrollEvent | kHorizontalScrollEvent | kInSystemGroup,
601 kMozMousePixelScrollEvent | kHorizontalScrollEvent,
602 kMozMousePixelScrollEvent | kHorizontalScrollEvent | kInSystemGroup,
603 kWheelEvent | kInSystemGroup | kDefaultPrevented],
605 doPreventDefaultAt: kDOMMouseScrollEvent | kVerticalScrollEvent | kInSystemGroup,
608 description:
"Testing the order of the events, calling preventDefault() at system group MozMousePixelScroll event",
609 expectedEvents: [ kWheelEvent,
610 kDOMMouseScrollEvent | kVerticalScrollEvent,
611 kDOMMouseScrollEvent | kVerticalScrollEvent | kInSystemGroup,
612 kMozMousePixelScrollEvent | kVerticalScrollEvent,
613 kMozMousePixelScrollEvent | kVerticalScrollEvent | kInSystemGroup,
614 kDOMMouseScrollEvent | kHorizontalScrollEvent,
615 kDOMMouseScrollEvent | kHorizontalScrollEvent | kInSystemGroup,
616 kMozMousePixelScrollEvent | kHorizontalScrollEvent,
617 kMozMousePixelScrollEvent | kHorizontalScrollEvent | kInSystemGroup,
618 kWheelEvent | kInSystemGroup | kDefaultPrevented],
620 doPreventDefaultAt: kMozMousePixelScrollEvent | kVerticalScrollEvent | kInSystemGroup,
624 function getEventDescription(aEvent)
627 if (aEvent & kWheelEvent) {
630 if (aEvent & kDOMMouseScrollEvent) {
631 result =
"DOMMouseScroll";
632 } else if (aEvent & kMozMousePixelScrollEvent) {
633 result =
"MozMousePixelScroll";
635 if (aEvent & kVerticalScrollEvent) {
636 result +=
", vertical";
638 result +=
", horizontal";
641 if (aEvent & kInSystemGroup) {
642 result +=
", system group";
644 if (aEvent & kDefaultPrevented) {
645 result +=
", defaultPrevented";
650 function pushEvent(aEvent, aIsSystemGroup)
653 if (aEvent.type ==
"wheel") {
656 if (aEvent.type ==
"DOMMouseScroll") {
657 event = kDOMMouseScrollEvent;
658 } else if (aEvent.type ==
"MozMousePixelScroll") {
659 event = kMozMousePixelScrollEvent;
661 if (aEvent.axis == MouseScrollEvent.HORIZONTAL_AXIS) {
662 event |= kHorizontalScrollEvent;
664 event |= kVerticalScrollEvent;
667 if (aIsSystemGroup) {
668 event |= kInSystemGroup;
670 if (aEvent.defaultPrevented) {
671 event |= kDefaultPrevented;
673 currentTest.resultEvents.push(event);
675 if (event == currentTest.doPreventDefaultAt) {
676 aEvent.preventDefault();
679 if (currentTest.resultEvents.length == currentTest.expectedEvents.length) {
680 setTimeout(continueTest,
0);
684 function handler(aEvent)
686 pushEvent(aEvent, false);
689 function systemHandler(aEvent)
691 pushEvent(aEvent, true);
694 window.addEventListener(
"wheel", handler, { capture: true, passive: false });
695 window.addEventListener(
"DOMMouseScroll", handler, { capture: true, passive: false });
696 window.addEventListener(
"MozMousePixelScroll", handler, { capture: true, passive: false });
698 SpecialPowers.addSystemEventListener(window,
"wheel", systemHandler, true);
699 SpecialPowers.addSystemEventListener(window,
"DOMMouseScroll", systemHandler, true);
700 SpecialPowers.addSystemEventListener(window,
"MozMousePixelScroll", systemHandler, true);
702 for (var i =
0; i < kTests.length; i++) {
703 currentTest = kTests[i];
704 yield synthesizeWheel(gScrollableElement,
10,
10,
705 { deltaMode: WheelEvent.DOM_DELTA_LINE, deltaX:
1.0, deltaY:
1.0 });
707 for (var j =
0; j < currentTest.expectedEvents.length; j++) {
708 if (currentTest.resultEvents.length == j) {
709 ok(false, currentTest.description +
": " +
710 getEventDescription(currentTest.expectedEvents[j]) +
" wasn't fired");
713 is(getEventDescription(currentTest.resultEvents[j]),
714 getEventDescription(currentTest.expectedEvents[j]),
715 currentTest.description +
": " + (j +
1) +
"th event is mismatched");
717 if (currentTest.expectedEvents.length < currentTest.resultEvents.length) {
718 ok(false, currentTest.description +
": " +
719 getEventDescription(currentTest.resultEvents[currentTest.expectedEvents.length]) +
720 " was fired unexpectedly");
724 window.removeEventListener(
"wheel", handler, true);
725 window.removeEventListener(
"DOMMouseScroll", handler, true);
726 window.removeEventListener(
"MozMousePixelScroll", handler, true);
728 SpecialPowers.removeSystemEventListener(window,
"wheel", systemHandler, true);
729 SpecialPowers.removeSystemEventListener(window,
"DOMMouseScroll", systemHandler, true);
730 SpecialPowers.removeSystemEventListener(window,
"MozMousePixelScroll", systemHandler, true);
733 var gOnWheelAttrHandled = new Array;
734 var gOnWheelAttrCount =
0;
736 function* testOnWheelAttr()
738 function onWheelHandledString(attr) {
739 return `gOnWheelAttrHandled['${attr}'] = true;
741 if (gOnWheelAttrCount ==
3) {
742 setTimeout(continueTest,
0);
746 document.documentElement.setAttribute(
"onwheel", onWheelHandledString(
"html"));
747 document.body.setAttribute(
"onwheel", onWheelHandledString(
"body"));
748 gScrollableElement.setAttribute(
"onwheel", onWheelHandledString(
"div"));
749 var target = document.getElementById(
"onwheel");
750 yield synthesizeWheel(gScrollableElement,
10,
10,
751 { deltaMode: WheelEvent.DOM_DELTA_LINE,
752 deltaX:
1.0, deltaY:
2.0 });
753 ok(gOnWheelAttrHandled.html,
"html element's onwheel attribute isn't performed");
754 ok(gOnWheelAttrHandled.body,
"body element's onwheel attribute isn't performed");
755 ok(gOnWheelAttrHandled.div,
"div element's onwheel attribute isn't performed");
758 var gOnWheelPropHandled = new Array;
759 var gOnWheelPropCount =
0;
761 function* testOnWheelProperty()
763 const handleOnWheelProp = prop =
> e =
> {
764 gOnWheelPropHandled[prop] = true;
766 if (gOnWheelPropCount ==
5) {
767 setTimeout(continueTest,
0);
771 window.onwheel = handleOnWheelProp('window');
772 document.onwheel = handleOnWheelProp('document');
773 document.documentElement.onwheel = handleOnWheelProp('html');
774 document.body.onwheel = handleOnWheelProp('body');
775 gScrollableElement.onwheel = handleOnWheelProp('div');
777 var target = document.getElementById(
"onwheel");
778 yield synthesizeWheel(gScrollableElement,
10,
10,
779 { deltaMode: WheelEvent.DOM_DELTA_LINE,
780 deltaX:
1.0, deltaY:
2.0 });
782 ok(gOnWheelPropHandled.window,
"window's onwheel property isn't performed");
783 ok(gOnWheelPropHandled.document,
"document's onwheel property isn't performed");
784 ok(gOnWheelPropHandled.html,
"html element's onwheel property isn't performed");
785 ok(gOnWheelPropHandled.body,
"body element's onwheel property isn't performed");
786 ok(gOnWheelPropHandled.div,
"div element's onwheel property isn't performed");
791 yield* prepareScrollUnits();
792 testMakingUntrustedEvent();
793 yield* testDeltaMultiplierPrefs();
794 testDispatchingUntrustEvent();
795 yield* testEventOrder();
796 yield* testOnWheelAttr();
797 yield* testOnWheelProperty();
800 var gTestContinuation = null;
802 function continueTest()
804 if (!gTestContinuation) {
805 gTestContinuation = testBody();
807 var ret = gTestContinuation.next();
815 SpecialPowers.pushPrefEnv({
"set": [
816 // FIXME(emilio): This test is broken in HiDPI, unclear if
817 // MozMousePixelScroll is not properly converting to CSS pixels, or
818 // whether sendWheelAndWait expectes device rather than CSS pixels, or
820 [
"layout.css.devPixelsPerPx",
1.0],
822 [
"dom.event.wheel-deltaMode-lines.disabled", true],
824 [
"mousewheel.default.delta_multiplier_x",
100],
825 [
"mousewheel.default.delta_multiplier_y",
100],
826 [
"mousewheel.default.delta_multiplier_z",
100],
827 [
"mousewheel.with_alt.delta_multiplier_x",
100],
828 [
"mousewheel.with_alt.delta_multiplier_y",
100],
829 [
"mousewheel.with_alt.delta_multiplier_z",
100],
830 [
"mousewheel.with_control.delta_multiplier_x",
100],
831 [
"mousewheel.with_control.delta_multiplier_y",
100],
832 [
"mousewheel.with_control.delta_multiplier_z",
100],
833 [
"mousewheel.with_meta.delta_multiplier_x",
100],
834 [
"mousewheel.with_meta.delta_multiplier_y",
100],
835 [
"mousewheel.with_meta.delta_multiplier_z",
100],
836 [
"mousewheel.with_shift.delta_multiplier_x",
100],
837 [
"mousewheel.with_shift.delta_multiplier_y",
100],
838 [
"mousewheel.with_shift.delta_multiplier_z",
100],
839 [
"mousewheel.with_win.delta_multiplier_x",
100],
840 [
"mousewheel.with_win.delta_multiplier_y",
100],
841 [
"mousewheel.with_win.delta_multiplier_z",
100],
842 // TODO: Need to add passive to SpecialPowers.addSystemEventListener
844 [
"dom.event.default_to_passive_wheel_listeners", false],