Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / tests / window_mouse_scroll_win.html
blob48ccc1fed4b5e71c978e7091a0bddd1c4e44b010
1 <html lang="en-US"
2 style="font-family: Arial; font-size: 10px; line-height: 16px;">
3 <head>
4 <title>Test for mouse scroll handling on Windows</title>
5 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
6 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
7 <link rel="stylesheet" type="text/css"
8 href="chrome://mochikit/content/tests/SimpleTest/test.css" />
9 </head>
10 <body onunload="onUnload();">
11 <div id="display" style="width: 5000px; height: 5000px;">
12 <p id="p1" style="font-size: 16px; width: 100px; height: 100px;">1st &lt;p&gt;.</p>
13 <p id="p2" style="font-size: 32px; width: 100px; height: 100px;">2nd &lt;p&gt;.</p>
14 </div>
15 <script class="testbody" type="application/javascript">
17 window.arguments[0].SimpleTest.waitForFocus(prepareTests, window);
19 const nsIDOMWindowUtils = Ci.nsIDOMWindowUtils;
21 const WHEEL_PAGESCROLL = 4294967295;
23 const WM_VSCROLL = 0x0115;
24 const WM_HSCROLL = 0x0114;
25 const WM_MOUSEWHEEL = 0x020A;
26 const WM_MOUSEHWHEEL = 0x020E;
28 const SB_LINEUP = 0;
29 const SB_LINELEFT = 0;
30 const SB_LINEDOWN = 1;
31 const SB_LINERIGHT = 1;
32 const SB_PAGEUP = 2;
33 const SB_PAGELEFT = 2;
34 const SB_PAGEDOWN = 3;
35 const SB_PAGERIGHT = 3;
37 const SHIFT_L = 0x0100;
38 const SHIFT_R = 0x0200;
39 const CTRL_L = 0x0400;
40 const CTRL_R = 0x0800;
41 const ALT_L = 0x1000;
42 const ALT_R = 0x2000;
44 const DOM_PAGE_SCROLL_DELTA = 32768;
46 const kSystemScrollSpeedOverridePref = "mousewheel.system_scroll_override.enabled";
48 const kAltKeyActionPref = "mousewheel.with_alt.action";
49 const kCtrlKeyActionPref = "mousewheel.with_control.action";
50 const kShiftKeyActionPref = "mousewheel.with_shift.action";
51 const kWinKeyActionPref = "mousewheel.with_meta.action";
53 const kAltKeyDeltaMultiplierXPref = "mousewheel.with_alt.delta_multiplier_x";
54 const kAltKeyDeltaMultiplierYPref = "mousewheel.with_alt.delta_multiplier_y";
55 const kCtrlKeyDeltaMultiplierXPref = "mousewheel.with_control.delta_multiplier_x";
56 const kCtrlKeyDeltaMultiplierYPref = "mousewheel.with_control.delta_multiplier_y";
57 const kShiftKeyDeltaMultiplierXPref = "mousewheel.with_shift.delta_multiplier_x";
58 const kShiftKeyDeltaMultiplierYPref = "mousewheel.with_shift.delta_multiplier_y";
59 const kWinKeyDeltaMultiplierXPref = "mousewheel.with_meta.delta_multiplier_x";
60 const kWinKeyDeltaMultiplierYPref = "mousewheel.with_meta.delta_multiplier_y";
62 const kEmulateWheelByWMSCROLLPref = "mousewheel.emulate_at_wm_scroll";
63 const kVAmountPref = "mousewheel.windows.vertical_amount_override";
64 const kHAmountPref = "mousewheel.windows.horizontal_amount_override";
65 const kTimeoutPref = "mousewheel.windows.transaction.timeout";
67 const kMouseLineScrollEvent = "DOMMouseScroll";
68 const kMousePixelScrollEvent = "MozMousePixelScroll";
70 const kVAxis = MouseScrollEvent.VERTICAL_AXIS;
71 const kHAxis = MouseScrollEvent.HORIZONTAL_AXIS;
73 var gLineHeight = 0;
74 var gCharWidth = 0;
75 var gPageHeight = 0;
76 var gPageWidth = 0;
78 var gP1 = document.getElementById("p1");
79 var gP2 = document.getElementById("p2");
81 var gOtherWindow;
83 function ok(aCondition, aMessage) {
84 window.arguments[0].SimpleTest.ok(aCondition, aMessage);
87 function is(aLeft, aRight, aMessage) {
88 window.arguments[0].SimpleTest.is(aLeft, aRight, aMessage);
91 function isnot(aLeft, aRight, aMessage) {
92 window.arguments[0].SimpleTest.isnot(aLeft, aRight, aMessage);
95 function todo_is(aLeft, aRight, aMessage) {
96 window.arguments[0].SimpleTest.todo_is(aLeft, aRight, aMessage);
99 function onUnload() {
100 SpecialPowers.clearUserPref(kAltKeyActionPref);
101 SpecialPowers.clearUserPref(kCtrlKeyActionPref);
102 SpecialPowers.clearUserPref(kShiftKeyActionPref);
103 SpecialPowers.clearUserPref(kWinKeyActionPref);
105 SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierXPref);
106 SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierYPref);
107 SpecialPowers.clearUserPref(kCtrlKeyDeltaMultiplierXPref);
108 SpecialPowers.clearUserPref(kCtrlKeyDeltaMultiplierYPref);
109 SpecialPowers.clearUserPref(kShiftKeyDeltaMultiplierXPref);
110 SpecialPowers.clearUserPref(kShiftKeyDeltaMultiplierYPref);
111 SpecialPowers.clearUserPref(kWinKeyDeltaMultiplierXPref);
112 SpecialPowers.clearUserPref(kWinKeyDeltaMultiplierYPref);
114 SpecialPowers.clearUserPref(kSystemScrollSpeedOverridePref);
115 SpecialPowers.clearUserPref(kEmulateWheelByWMSCROLLPref);
116 SpecialPowers.clearUserPref(kVAmountPref);
117 SpecialPowers.clearUserPref(kHAmountPref);
118 SpecialPowers.clearUserPref(kTimeoutPref);
119 window.arguments[0].SimpleTest.finish();
122 function getWindowUtils(aWindow) {
123 if (!aWindow) {
124 aWindow = window;
126 return aWindow.windowUtils;
129 function getPointInScreen(aElement, aWindow) {
130 if (!aWindow) {
131 aWindow = window;
133 var bounds = aElement.getBoundingClientRect();
134 return { x: bounds.left + aWindow.mozInnerScreenX,
135 y: bounds.top + aWindow.mozInnerScreenY };
138 function cut(aNum) {
139 return (aNum >= 0) ? Math.floor(aNum) : Math.ceil(aNum);
143 * Make each steps for the tests in following arrays in global scope. Each item
144 * of the arrays will be executed after previous test is finished.
146 * description:
147 * Set the description of the test. This will be used for the message of is()
148 * or the others.
150 * message:
151 * aNativeMessage of nsIDOMWindowUtils.sendNativeMouseScrollEvent().
152 * Must be WM_MOUSEWHEEL, WM_MOUSEHWHEEL, WM_VSCROLL or WM_HSCROLL.
154 * delta:
155 * The native delta value for WM_MOUSEWHEEL or WM_MOUSEHWHEEL.
156 * Or one of the SB_* const value for WM_VSCROLL or WM_HSCROLL.
158 * target:
159 * The target element, under the mouse cursor.
161 * window:
162 * The window which is used for getting nsIDOMWindowUtils.
164 * modifiers:
165 * Pressed modifier keys, 0 means no modifier key is pressed.
166 * Otherwise, one or more values of SHIFT_L, SHIFT_R, CTRL_L, CTRL_R,
167 * ALT_L or ALT_R.
169 * additionalFlags:
170 * aAdditionalFlags of nsIDOMWindowUtils.sendNativeMouseScrollEvent().
171 * See the document of nsIDOMWindowUtils for the detail of the values.
173 * onLineScrollEvent:
174 * Must be a function or null.
175 * If the value is a function, it will be called when DOMMouseScroll event
176 * is received by the synthesized event.
177 * If return true, the common checks are canceled.
179 * onPixelScrollEvent:
180 * Must be a function or null.
181 * If the value is a function, it will be called when MozMousePixelScroll
182 * event is received by the synthesized event.
183 * If return true, the common checks are canceled.
185 * expected:
186 * Must not be null and this must have:
187 * axis:
188 * kVAxis if the synthesized event causes vertical scroll. Otherwise,
189 * it causes horizontal scroll, kHAxis.
190 * lines:
191 * Integer value which is expected detail attribute value of
192 * DOMMouseScroll. If the event shouldn't be fired, must be 0.
193 * pixels:
194 * Integer value or a function which returns double value. The value is
195 * expected detail attribute value of MozMousePixelScroll.
196 * If the event shouldn't be fired, must be 0.
198 * Note that if both lines and pixels are 0, the test framework waits
199 * a few seconds. After that, go to next test.
201 * init:
202 * Must be a function or null. If this value is a function, it's called
203 * before synthesizing the native event.
205 * finish:
206 * Must be a function or null. If this value is a function, it's called
207 * after received all expected events or timeout if no events are expected.
210 // First, get the computed line height, char width, page height and page width.
211 var gPreparingSteps = [
212 { description: "Preparing gLineHeight",
213 message: WM_MOUSEWHEEL, delta: -120,
214 target: gP1, x: 10, y: 10, window,
215 modifiers: 0,
216 additionalFlags: 0,
217 onLineScrollEvent() {
218 return true;
220 onPixelScrollEvent(aEvent) {
221 gLineHeight = aEvent.detail;
222 return true;
224 expected: {
225 axis: kVAxis, lines: 1, pixels: 1,
227 init() {
228 SpecialPowers.setIntPref(kVAmountPref, 1);
229 SpecialPowers.setIntPref(kHAmountPref, 1);
232 { description: "Preparing gCharWidth",
233 message: WM_MOUSEHWHEEL, delta: 120,
234 target: gP1, x: 10, y: 10, window,
235 modifiers: 0,
236 additionalFlags: 0,
237 onLineScrollEvent() {
238 return true;
240 onPixelScrollEvent(aEvent) {
241 gCharWidth = aEvent.detail;
242 return true;
244 expected: {
245 axis: kVAxis, lines: 1, pixels: 1,
248 { description: "Preparing gPageHeight",
249 message: WM_MOUSEWHEEL, delta: -120,
250 target: gP1, x: 10, y: 10, window,
251 modifiers: 0,
252 additionalFlags: 0,
253 onLineScrollEvent() {
254 return true;
256 onPixelScrollEvent(aEvent) {
257 gPageHeight = aEvent.detail;
258 return true;
260 expected: {
261 axis: kHAxis, lines: 1, pixels: 1,
263 init() {
264 SpecialPowers.setIntPref(kVAmountPref, 0xFFFF);
265 SpecialPowers.setIntPref(kHAmountPref, 0xFFFF);
268 { description: "Preparing gPageWidth",
269 message: WM_MOUSEHWHEEL, delta: 120,
270 target: gP1, x: 10, y: 10, window,
271 modifiers: 0,
272 additionalFlags: 0,
273 onLineScrollEvent() {
274 return true;
276 onPixelScrollEvent(aEvent) {
277 gPageWidth = aEvent.detail;
278 return true;
280 expected: {
281 axis: kHAxis, lines: 1, pixels: 1,
283 finish() {
284 ok(gLineHeight > 0, "gLineHeight isn't positive got " + gLineHeight);
285 ok(gCharWidth > 0, "gCharWidth isn't positive got " + gCharWidth);
286 ok(gPageHeight > 0, "gPageHeight isn't positive got " + gPageHeight);
287 ok(gPageWidth > 0, "gPageWidth isn't positive got " + gPageWidth);
289 ok(gPageHeight > gLineHeight,
290 "gPageHeight must be larger than gLineHeight");
291 ok(gPageWidth > gCharWidth,
292 "gPageWidth must be larger than gCharWidth");
293 runNextTest(gBasicTests, 0);
298 var gBasicTests = [
299 // Widget shouldn't dispatch a pixel event if the delta can be devided by
300 // lines to be scrolled. However, pixel events should be fired by ESM.
301 { description: "WM_MOUSEWHEEL, -120, 3 lines",
302 message: WM_MOUSEWHEEL, delta: -120,
303 target: gP1, x: 10, y: 10, window,
304 modifiers: 0,
305 additionalFlags: 0,
306 expected: {
307 axis: kVAxis, lines: 3, pixels() { return gLineHeight * 3; },
309 init() {
310 SpecialPowers.setIntPref(kVAmountPref, 3);
311 SpecialPowers.setIntPref(kHAmountPref, 3);
315 { description: "WM_MOUSEWHEEL, 120, -3 lines",
316 message: WM_MOUSEWHEEL, delta: 120,
317 target: gP1, x: 10, y: 10, window,
318 modifiers: 0,
319 additionalFlags: 0,
320 expected: {
321 axis: kVAxis, lines: -3, pixels() { return gLineHeight * -3; },
325 { description: "WM_MOUSEHWHEEL, 120, 3 chars",
326 message: WM_MOUSEHWHEEL, delta: 120,
327 target: gP1, x: 10, y: 10, window,
328 modifiers: 0,
329 additionalFlags: 0,
330 expected: {
331 axis: kHAxis, lines: 3, pixels() { return gCharWidth * 3; },
335 { description: "WM_MOUSEHWHEEL, -120, -3 chars",
336 message: WM_MOUSEHWHEEL, delta: -120,
337 target: gP1, x: 10, y: 10, window,
338 modifiers: 0,
339 additionalFlags: 0,
340 expected: {
341 axis: kHAxis, lines: -3, pixels() { return gCharWidth * -3; },
345 // Pixel scroll event should be fired always but line scroll event should be
346 // fired only when accumulated delta value is over a line.
347 { description: "WM_MOUSEWHEEL, -20, 0.5 lines",
348 message: WM_MOUSEWHEEL, delta: -20,
349 target: gP1, x: 10, y: 10, window,
350 modifiers: 0,
351 additionalFlags: 0,
352 expected: {
353 axis: kVAxis, lines: 0, pixels() { return gLineHeight / 2; },
356 { description: "WM_MOUSEWHEEL, -20, 0.5 lines (pending: 0.5 lines)",
357 message: WM_MOUSEWHEEL, delta: -20,
358 target: gP1, x: 10, y: 10, window,
359 modifiers: 0,
360 additionalFlags: 0,
361 expected: {
362 axis: kVAxis, lines: 1, pixels() { return gLineHeight / 2; },
365 { description: "WM_MOUSEWHEEL, -20, 0.5 lines",
366 message: WM_MOUSEWHEEL, delta: -20,
367 target: gP1, x: 10, y: 10, window,
368 modifiers: 0,
369 additionalFlags: 0,
370 expected: {
371 axis: kVAxis, lines: 0, pixels() { return gLineHeight / 2; },
375 { description: "WM_MOUSEWHEEL, 20, -0.5 lines (pending: 0.5 lines)",
376 message: WM_MOUSEWHEEL, delta: 20,
377 target: gP1, x: 10, y: 10, window,
378 modifiers: 0,
379 additionalFlags: 0,
380 expected: {
381 axis: kVAxis, lines: 0, pixels() { return gLineHeight / -2; },
384 { description: "WM_MOUSEWHEEL, 20, -0.5 lines (pending: -0.5 lines)",
385 message: WM_MOUSEWHEEL, delta: 20,
386 target: gP1, x: 10, y: 10, window,
387 modifiers: 0,
388 additionalFlags: 0,
389 expected: {
390 axis: kVAxis, lines: -1, pixels() { return -gLineHeight / 2; },
393 { description: "WM_MOUSEWHEEL, 20, -0.5 lines",
394 message: WM_MOUSEWHEEL, delta: 20,
395 target: gP1, x: 10, y: 10, window,
396 modifiers: 0,
397 additionalFlags: 0,
398 expected: {
399 axis: kVAxis, lines: 0, pixels() { return gLineHeight / -2; },
403 { description: "WM_MOUSEHWHEEL, 20, 0.5 chars",
404 message: WM_MOUSEHWHEEL, delta: 20,
405 target: gP1, x: 10, y: 10, window,
406 modifiers: 0,
407 additionalFlags: 0,
408 expected: {
409 axis: kHAxis, lines: 0, pixels() { return gCharWidth / 2; },
412 { description: "WM_MOUSEHWHEEL, 20, 0.5 chars (pending: 0.5 chars)",
413 message: WM_MOUSEHWHEEL, delta: 20,
414 target: gP1, x: 10, y: 10, window,
415 modifiers: 0,
416 additionalFlags: 0,
417 expected: {
418 axis: kHAxis, lines: 1, pixels() { return gCharWidth / 2; },
421 { description: "WM_MOUSEHWHEEL, 20, 0.5 chars",
422 message: WM_MOUSEHWHEEL, delta: 20,
423 target: gP1, x: 10, y: 10, window,
424 modifiers: 0,
425 additionalFlags: 0,
426 expected: {
427 axis: kHAxis, lines: 0, pixels() { return gCharWidth / 2; },
431 { description: "WM_MOUSEHWHEEL, -20, -0.5 chars (pending: 0.5 chars)",
432 message: WM_MOUSEHWHEEL, delta: -20,
433 target: gP1, x: 10, y: 10, window,
434 modifiers: 0,
435 additionalFlags: 0,
436 expected: {
437 axis: kHAxis, lines: 0, pixels() { return gCharWidth / -2; },
440 { description: "WM_MOUSEHWHEEL, -20, -0.5 chars (pending: -0.5 chars)",
441 message: WM_MOUSEHWHEEL, delta: -20,
442 target: gP1, x: 10, y: 10, window,
443 modifiers: 0,
444 additionalFlags: 0,
445 expected: {
446 axis: kHAxis, lines: -1, pixels() { return -gCharWidth / 2; },
449 { description: "WM_MOUSEHWHEEL, -20, -0.5 chars",
450 message: WM_MOUSEHWHEEL, delta: -20,
451 target: gP1, x: 10, y: 10, window,
452 modifiers: 0,
453 additionalFlags: 0,
454 expected: {
455 axis: kHAxis, lines: 0, pixels() { return gCharWidth / -2; },
459 // Even if the mouse cursor is an element whose font-size is different than
460 // the scrollable element, the pixel scroll amount shouldn't be changed.
461 // Widget shouldn't dispatch a pixel event if the delta can be devided by
462 // lines to be scrolled. However, pixel events should be fired by ESM.
463 { description: "WM_MOUSEWHEEL, -120, 3 lines, on the other div whose font-size is larger",
464 message: WM_MOUSEWHEEL, delta: -120,
465 target: gP2, x: 10, y: 10, window,
466 modifiers: 0,
467 additionalFlags: 0,
468 expected: {
469 axis: kVAxis, lines: 3, pixels() { return gLineHeight * 3; },
473 { description: "WM_MOUSEWHEEL, 120, -3 lines, on the other div whose font-size is larger",
474 message: WM_MOUSEWHEEL, delta: 120,
475 target: gP2, x: 10, y: 10, window,
476 modifiers: 0,
477 additionalFlags: 0,
478 expected: {
479 axis: kVAxis, lines: -3, pixels() { return gLineHeight * -3; },
483 { description: "WM_MOUSEHWHEEL, 120, 3 chars, on the other div whose font-size is larger",
484 message: WM_MOUSEHWHEEL, delta: 120,
485 target: gP2, x: 10, y: 10, window,
486 modifiers: 0,
487 additionalFlags: 0,
488 expected: {
489 axis: kHAxis, lines: 3, pixels() { return gCharWidth * 3; },
493 { description: "WM_MOUSEHWHEEL, -120, -3 chars, on the other div whose font-size is larger",
494 message: WM_MOUSEHWHEEL, delta: -120,
495 target: gP2, x: 10, y: 10, window,
496 modifiers: 0,
497 additionalFlags: 0,
498 expected: {
499 axis: kHAxis, lines: -3, pixels() { return gCharWidth * -3; },
503 // Modifier key tests
504 { description: "WM_MOUSEWHEEL, -40, 1 line with left Shift",
505 message: WM_MOUSEWHEEL, delta: -40,
506 target: gP1, x: 10, y: 10, window,
507 modifiers: SHIFT_L,
508 additionalFlags: 0,
509 expected: {
510 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
513 { description: "WM_MOUSEWHEEL, -40, 1 line with right Shift",
514 message: WM_MOUSEWHEEL, delta: -40,
515 target: gP1, x: 10, y: 10, window,
516 modifiers: SHIFT_R,
517 additionalFlags: 0,
518 expected: {
519 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
522 { description: "WM_MOUSEWHEEL, -40, 1 line with left Ctrl",
523 message: WM_MOUSEWHEEL, delta: -40,
524 target: gP1, x: 10, y: 10, window,
525 modifiers: CTRL_L,
526 additionalFlags: 0,
527 expected: {
528 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
531 { description: "WM_MOUSEWHEEL, -40, 1 line with right Ctrl",
532 message: WM_MOUSEWHEEL, delta: -40,
533 target: gP1, x: 10, y: 10, window,
534 modifiers: CTRL_R,
535 additionalFlags: 0,
536 expected: {
537 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
540 { description: "WM_MOUSEWHEEL, -40, 1 line with left Alt",
541 message: WM_MOUSEWHEEL, delta: -40,
542 target: gP1, x: 10, y: 10, window,
543 modifiers: ALT_L,
544 additionalFlags: 0,
545 expected: {
546 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
549 { description: "WM_MOUSEWHEEL, -40, 1 line with right Alt",
550 message: WM_MOUSEWHEEL, delta: -40,
551 target: gP1, x: 10, y: 10, window,
552 modifiers: ALT_R,
553 additionalFlags: 0,
554 expected: {
555 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
559 { description: "WM_MOUSEHWHEEL, 40, 1 character with left Shift",
560 message: WM_MOUSEHWHEEL, delta: 40,
561 target: gP1, x: 10, y: 10, window,
562 modifiers: SHIFT_L,
563 additionalFlags: 0,
564 expected: {
565 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
568 { description: "WM_MOUSEHWHEEL, 40, 1 character with right Shift",
569 message: WM_MOUSEHWHEEL, delta: 40,
570 target: gP1, x: 10, y: 10, window,
571 modifiers: SHIFT_R,
572 additionalFlags: 0,
573 expected: {
574 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
577 { description: "WM_MOUSEHWHEEL, 40, 1 character with left Ctrl",
578 message: WM_MOUSEHWHEEL, delta: 40,
579 target: gP1, x: 10, y: 10, window,
580 modifiers: CTRL_L,
581 additionalFlags: 0,
582 expected: {
583 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
586 { description: "WM_MOUSEHWHEEL, 40, 1 character with right Ctrl",
587 message: WM_MOUSEHWHEEL, delta: 40,
588 target: gP1, x: 10, y: 10, window,
589 modifiers: CTRL_R,
590 additionalFlags: 0,
591 expected: {
592 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
595 { description: "WM_MOUSEHWHEEL, 40, 1 character with left Alt",
596 message: WM_MOUSEHWHEEL, delta: 40,
597 target: gP1, x: 10, y: 10, window,
598 modifiers: ALT_L,
599 additionalFlags: 0,
600 expected: {
601 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
604 { description: "WM_MOUSEHWHEEL, 40, 1 character with right Alt",
605 message: WM_MOUSEHWHEEL, delta: 40,
606 target: gP1, x: 10, y: 10, window,
607 modifiers: ALT_R,
608 additionalFlags: 0,
609 expected: {
610 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
613 finish() {
614 runNextTest(gScrollMessageTests, 0);
619 var gPageScrllTests = [
620 // Pixel scroll event should be fired always but line scroll event should be
621 // fired only when accumulated delta value is over a line.
622 { description: "WM_MOUSEWHEEL, -60, 0.5 pages",
623 message: WM_MOUSEWHEEL, delta: -60,
624 target: gP1, x: 10, y: 10, window,
625 modifiers: 0,
626 additionalFlags: 0,
627 expected: {
628 axis: kVAxis, lines: 0, pixels() { return gPageHeight / 2; },
631 { description: "WM_MOUSEWHEEL, -60, 0.5 pages (pending: 0.5 pages)",
632 message: WM_MOUSEWHEEL, delta: -60,
633 target: gP1, x: 10, y: 10, window,
634 modifiers: 0,
635 additionalFlags: 0,
636 expected: {
637 axis: kVAxis, lines: DOM_PAGE_SCROLL_DELTA,
638 pixels() { return ((gPageHeight / 2) + (gPageHeight % 2)); },
641 { description: "WM_MOUSEWHEEL, -60, 0.5 pages",
642 message: WM_MOUSEWHEEL, delta: -60,
643 target: gP1, x: 10, y: 10, window,
644 modifiers: 0,
645 additionalFlags: 0,
646 expected: {
647 axis: kVAxis, lines: 0, pixels() { return gPageHeight / 2; },
651 { description: "WM_MOUSEWHEEL, 60, -0.5 pages (pending: 0.5 pages)",
652 message: WM_MOUSEWHEEL, delta: 60,
653 target: gP1, x: 10, y: 10, window,
654 modifiers: 0,
655 additionalFlags: 0,
656 expected: {
657 axis: kVAxis, lines: 0, pixels() { return gPageHeight / -2; },
660 { description: "WM_MOUSEWHEEL, 60, -0.5 pages (pending: -0.5 pages)",
661 message: WM_MOUSEWHEEL, delta: 60,
662 target: gP1, x: 10, y: 10, window,
663 modifiers: 0,
664 additionalFlags: 0,
665 expected: {
666 axis: kVAxis, lines: -DOM_PAGE_SCROLL_DELTA,
667 pixels() { return -((gPageHeight / 2) + (gPageHeight % 2)); },
670 { description: "WM_MOUSEWHEEL, 60, -0.5 pages",
671 message: WM_MOUSEWHEEL, delta: 60,
672 target: gP1, x: 10, y: 10, window,
673 modifiers: 0,
674 additionalFlags: 0,
675 expected: {
676 axis: kVAxis, lines: 0, pixels() { return gPageHeight / -2; },
680 { description: "WM_MOUSEHWHEEL, 60, 0.5 pages",
681 message: WM_MOUSEHWHEEL, delta: 60,
682 target: gP1, x: 10, y: 10, window,
683 modifiers: 0,
684 additionalFlags: 0,
685 expected: {
686 axis: kHAxis, lines: 0, pixels() { return gPageWidth / 2; },
689 { description: "WM_MOUSEHWHEEL, 60, 0.5 pages (pending: 0.5 pages)",
690 message: WM_MOUSEHWHEEL, delta: 60,
691 target: gP1, x: 10, y: 10, window,
692 modifiers: 0,
693 additionalFlags: 0,
694 expected: {
695 axis: kHAxis, lines: DOM_PAGE_SCROLL_DELTA,
696 pixels() { return ((gPageWidth / 2) + (gPageWidth % 2)); },
699 { description: "WM_MOUSEHWHEEL, 60, 0.5 pages",
700 message: WM_MOUSEHWHEEL, delta: 60,
701 target: gP1, x: 10, y: 10, window,
702 modifiers: 0,
703 additionalFlags: 0,
704 expected: {
705 axis: kHAxis, lines: 0, pixels() { return gPageWidth / 2; },
709 { description: "WM_MOUSEHWHEEL, -60, -0.5 pages (pending: 0.5 pages)",
710 message: WM_MOUSEHWHEEL, delta: -60,
711 target: gP1, x: 10, y: 10, window,
712 modifiers: 0,
713 additionalFlags: 0,
714 expected: {
715 axis: kHAxis, lines: 0, pixels() { return gCharWidth / -2; },
718 { description: "WM_MOUSEHWHEEL, -60, -0.5 pages (pending: -0.5 pages)",
719 message: WM_MOUSEHWHEEL, delta: -60,
720 target: gP1, x: 10, y: 10, window,
721 modifiers: 0,
722 additionalFlags: 0,
723 expected: {
724 axis: kHAxis, lines: -DOM_PAGE_SCROLL_DELTA,
725 pixels() { return -((gCharWidth / 2) + (gCharWidth % 2)); },
728 { description: "WM_MOUSEHWHEEL, -60, -0.5 pages",
729 message: WM_MOUSEHWHEEL, delta: -60,
730 target: gP1, x: 10, y: 10, window,
731 modifiers: 0,
732 additionalFlags: 0,
733 expected: {
734 axis: kHAxis, lines: 0, pixels() { return gCharWidth / -2; },
739 var gScrollMessageTests = [
740 // Widget should dispatch neither line scroll event nor pixel scroll event if
741 // the WM_*SCROLL's lParam is NULL and mouse wheel emulation is disabled.
742 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation disabled",
743 message: WM_VSCROLL, delta: SB_LINEDOWN,
744 target: gP1, x: 10, y: 10, window,
745 modifiers: 0,
746 additionalFlags: 0,
747 expected: {
748 axis: kVAxis, lines: 0, pixels: 0,
750 init() {
751 SpecialPowers.setIntPref(kVAmountPref, 3);
752 SpecialPowers.setIntPref(kHAmountPref, 3);
753 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
757 { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation disabled",
758 message: WM_VSCROLL, delta: SB_LINEUP,
759 target: gP1, x: 10, y: 10, window,
760 modifiers: 0,
761 additionalFlags: 0,
762 expected: {
763 axis: kVAxis, lines: 0, pixels: 0,
767 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation disabled",
768 message: WM_HSCROLL, delta: SB_LINERIGHT,
769 target: gP1, x: 10, y: 10, window,
770 modifiers: 0,
771 additionalFlags: 0,
772 expected: {
773 axis: kHAxis, lines: 0, pixels: 0,
777 { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation disabled",
778 message: WM_HSCROLL, delta: SB_LINELEFT,
779 target: gP1, x: 10, y: 10, window,
780 modifiers: 0,
781 additionalFlags: 0,
782 expected: {
783 axis: kHAxis, lines: 0, pixels: 0,
787 // Widget should emulate mouse wheel behavior for WM_*SCROLL even if the
788 // kEmulateWheelByWMSCROLLPref is disabled but the message's lParam is not
789 // NULL. Then, widget doesn't dispatch a pixel event for WM_*SCROLL messages,
790 // but ESM dispatches it instead.
791 { description: "WM_VSCROLL, SB_LINEUP, lParam is not NULL, emulation disabled",
792 message: WM_VSCROLL, delta: SB_LINEUP,
793 target: gP1, x: 10, y: 10, window,
794 modifiers: 0,
795 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
796 expected: {
797 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
799 init() {
800 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
804 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled",
805 message: WM_VSCROLL, delta: SB_LINEDOWN,
806 target: gP1, x: 10, y: 10, window,
807 modifiers: 0,
808 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
809 expected: {
810 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
814 { description: "WM_HSCROLL, SB_LINELEFT, lParam is not NULL, emulation disabled",
815 message: WM_HSCROLL, delta: SB_LINELEFT,
816 target: gP1, x: 10, y: 10, window,
817 modifiers: 0,
818 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
819 expected: {
820 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
824 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled",
825 message: WM_HSCROLL, delta: SB_LINERIGHT,
826 target: gP1, x: 10, y: 10, window,
827 modifiers: 0,
828 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
829 expected: {
830 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
834 { description: "WM_VSCROLL, SB_PAGEUP, lParam is not NULL, emulation disabled",
835 message: WM_VSCROLL, delta: SB_PAGEUP,
836 target: gP1, x: 10, y: 10, window,
837 modifiers: 0,
838 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
839 expected: {
840 axis: kVAxis, lines: -DOM_PAGE_SCROLL_DELTA,
841 pixels() { return -gPageHeight; },
845 { description: "WM_VSCROLL, SB_PAGEDOWN, lParam is not NULL, emulation disabled",
846 message: WM_VSCROLL, delta: SB_PAGEDOWN,
847 target: gP1, x: 10, y: 10, window,
848 modifiers: 0,
849 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
850 expected: {
851 axis: kVAxis, lines: DOM_PAGE_SCROLL_DELTA,
852 pixels() { return gPageHeight; },
856 { description: "WM_HSCROLL, SB_PAGELEFT, lParam is not NULL, emulation disabled",
857 message: WM_HSCROLL, delta: SB_PAGELEFT,
858 target: gP1, x: 10, y: 10, window,
859 modifiers: 0,
860 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
861 expected: {
862 axis: kHAxis, lines: -DOM_PAGE_SCROLL_DELTA,
863 pixels() { return -gPageWidth; },
867 { description: "WM_HSCROLL, SB_PAGERIGHT, lParam is not NULL, emulation disabled",
868 message: WM_HSCROLL, delta: SB_PAGERIGHT,
869 target: gP1, x: 10, y: 10, window,
870 modifiers: 0,
871 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
872 expected: {
873 axis: kHAxis, lines: DOM_PAGE_SCROLL_DELTA,
874 pixels() { return gPageWidth; },
878 // Widget should emulate mouse wheel behavior for WM_*SCROLL when the
879 // kEmulateWheelByWMSCROLLPref is enabled even if the message's lParam is
880 // NULL. Then, widget doesn't dispatch a pixel event for WM_*SCROLL messages,
881 // but ESM dispatches it instead.
882 { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation enabled",
883 message: WM_VSCROLL, delta: SB_LINEUP,
884 target: gP1, x: 10, y: 10, window,
885 modifiers: 0,
886 additionalFlags: 0,
887 expected: {
888 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
890 init() {
891 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, true);
895 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation enabled",
896 message: WM_VSCROLL, delta: SB_LINEDOWN,
897 target: gP1, x: 10, y: 10, window,
898 modifiers: 0,
899 additionalFlags: 0,
900 expected: {
901 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
905 { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation enabled",
906 message: WM_HSCROLL, delta: SB_LINELEFT,
907 target: gP1, x: 10, y: 10, window,
908 modifiers: 0,
909 additionalFlags: 0,
910 expected: {
911 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
915 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation enabled",
916 message: WM_HSCROLL, delta: SB_LINERIGHT,
917 target: gP1, x: 10, y: 10, window,
918 modifiers: 0,
919 additionalFlags: 0,
920 expected: {
921 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
925 { description: "WM_VSCROLL, SB_PAGEUP, lParam is NULL, emulation enabled",
926 message: WM_VSCROLL, delta: SB_PAGEUP,
927 target: gP1, x: 10, y: 10, window,
928 modifiers: 0,
929 additionalFlags: 0,
930 expected: {
931 axis: kVAxis, lines: -DOM_PAGE_SCROLL_DELTA,
932 pixels() { return -gPageHeight; },
936 { description: "WM_VSCROLL, SB_PAGEDOWN, lParam is NULL, emulation enabled",
937 message: WM_VSCROLL, delta: SB_PAGEDOWN,
938 target: gP1, x: 10, y: 10, window,
939 modifiers: 0,
940 additionalFlags: 0,
941 expected: {
942 axis: kVAxis, lines: DOM_PAGE_SCROLL_DELTA,
943 pixels() { return gPageHeight; },
947 { description: "WM_HSCROLL, SB_PAGELEFT, lParam is NULL, emulation enabled",
948 message: WM_HSCROLL, delta: SB_PAGELEFT,
949 target: gP1, x: 10, y: 10, window,
950 modifiers: 0,
951 additionalFlags: 0,
952 expected: {
953 axis: kHAxis, lines: -DOM_PAGE_SCROLL_DELTA,
954 pixels() { return -gPageWidth; },
958 { description: "WM_HSCROLL, SB_PAGERIGHT, lParam is NULL, emulation enabled",
959 message: WM_HSCROLL, delta: SB_PAGERIGHT,
960 target: gP1, x: 10, y: 10, window,
961 modifiers: 0,
962 additionalFlags: 0,
963 expected: {
964 axis: kHAxis, lines: DOM_PAGE_SCROLL_DELTA,
965 pixels() { return gPageWidth; },
969 // Modifier key tests for WM_*SCROLL
970 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with left Shift",
971 message: WM_VSCROLL, delta: SB_LINEDOWN,
972 target: gP1, x: 10, y: 10, window,
973 modifiers: SHIFT_L,
974 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
975 expected: {
976 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
978 init() {
979 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
982 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with right Shift",
983 message: WM_VSCROLL, delta: SB_LINEDOWN,
984 target: gP1, x: 10, y: 10, window,
985 modifiers: SHIFT_R,
986 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
987 expected: {
988 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
991 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with left Ctrl",
992 message: WM_VSCROLL, delta: SB_LINEDOWN,
993 target: gP1, x: 10, y: 10, window,
994 modifiers: CTRL_L,
995 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
996 expected: {
997 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1000 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with right Ctrl",
1001 message: WM_VSCROLL, delta: SB_LINEDOWN,
1002 target: gP1, x: 10, y: 10, window,
1003 modifiers: CTRL_L,
1004 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1005 expected: {
1006 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1009 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with left Alt",
1010 message: WM_VSCROLL, delta: SB_LINEDOWN,
1011 target: gP1, x: 10, y: 10, window,
1012 modifiers: ALT_L,
1013 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1014 expected: {
1015 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1018 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with right Alt",
1019 message: WM_VSCROLL, delta: SB_LINEDOWN,
1020 target: gP1, x: 10, y: 10, window,
1021 modifiers: ALT_R,
1022 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1023 expected: {
1024 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1028 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with left Shift",
1029 message: WM_HSCROLL, delta: SB_LINERIGHT,
1030 target: gP1, x: 10, y: 10, window,
1031 modifiers: SHIFT_L,
1032 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1033 expected: {
1034 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1037 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with right Shift",
1038 message: WM_HSCROLL, delta: SB_LINERIGHT,
1039 target: gP1, x: 10, y: 10, window,
1040 modifiers: SHIFT_R,
1041 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1042 expected: {
1043 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1046 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with left Ctrl",
1047 message: WM_HSCROLL, delta: SB_LINERIGHT,
1048 target: gP1, x: 10, y: 10, window,
1049 modifiers: CTRL_L,
1050 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1051 expected: {
1052 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1055 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with right Ctrl",
1056 message: WM_HSCROLL, delta: SB_LINERIGHT,
1057 target: gP1, x: 10, y: 10, window,
1058 modifiers: CTRL_L,
1059 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1060 expected: {
1061 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1064 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with left Alt",
1065 message: WM_HSCROLL, delta: SB_LINERIGHT,
1066 target: gP1, x: 10, y: 10, window,
1067 modifiers: ALT_L,
1068 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1069 expected: {
1070 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1073 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with right Alt",
1074 message: WM_HSCROLL, delta: SB_LINERIGHT,
1075 target: gP1, x: 10, y: 10, window,
1076 modifiers: ALT_R,
1077 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1078 expected: {
1079 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1082 finish() {
1083 runDeactiveWindowTests();
1088 var gDeactiveWindowTests = [
1089 // Typically, mouse drivers send wheel messages to focused window.
1090 // However, we prefer to scroll a scrollable element under the mouse cursor.
1091 { description: "WM_MOUSEWHEEL, -120, 3 lines, window is deactive",
1092 message: WM_MOUSEWHEEL, delta: -120,
1093 target: gP1, x: 10, y: 10, window,
1094 modifiers: 0,
1095 additionalFlags: 0,
1096 expected: {
1097 axis: kVAxis, lines: 3, pixels() { return gLineHeight * 3; },
1099 init() {
1100 SpecialPowers.setIntPref(kVAmountPref, 3);
1101 SpecialPowers.setIntPref(kHAmountPref, 3);
1103 onLineScrollEvent() {
1104 var fm = Services.focus;
1105 is(fm.activeWindow, gOtherWindow, "The other window isn't activated");
1109 { description: "WM_MOUSEWHEEL, 120, -3 lines, window is deactive",
1110 message: WM_MOUSEWHEEL, delta: 120,
1111 target: gP1, x: 10, y: 10, window,
1112 modifiers: 0,
1113 additionalFlags: 0,
1114 expected: {
1115 axis: kVAxis, lines: -3, pixels() { return gLineHeight * -3; },
1119 { description: "WM_MOUSEHWHEEL, 120, 3 chars, window is deactive",
1120 message: WM_MOUSEHWHEEL, delta: 120,
1121 target: gP1, x: 10, y: 10, window,
1122 modifiers: 0,
1123 additionalFlags: 0,
1124 expected: {
1125 axis: kHAxis, lines: 3, pixels() { return gCharWidth * 3; },
1129 { description: "WM_MOUSEHWHEEL, -120, -3 chars, window is deactive",
1130 message: WM_MOUSEHWHEEL, delta: -120,
1131 target: gP1, x: 10, y: 10, window,
1132 modifiers: 0,
1133 additionalFlags: 0,
1134 expected: {
1135 axis: kHAxis, lines: -3, pixels() { return gCharWidth * -3; },
1139 // Of course, even if some drivers prefer the cursor position, we don't need
1140 // to change anything.
1141 { description: "WM_MOUSEWHEEL, -120, 3 lines, window is deactive (receive the message directly)",
1142 message: WM_MOUSEWHEEL, delta: -120,
1143 target: gP1, x: 10, y: 10, window,
1144 modifiers: 0,
1145 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1146 expected: {
1147 axis: kVAxis, lines: 3, pixels() { return gLineHeight * 3; },
1151 { description: "WM_MOUSEWHEEL, 120, -3 lines, window is deactive (receive the message directly)",
1152 message: WM_MOUSEWHEEL, delta: 120,
1153 target: gP1, x: 10, y: 10, window,
1154 modifiers: 0,
1155 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1156 expected: {
1157 axis: kVAxis, lines: -3, pixels() { return gLineHeight * -3; },
1161 { description: "WM_MOUSEHWHEEL, 120, 3 chars, window is deactive (receive the message directly)",
1162 message: WM_MOUSEHWHEEL, delta: 120,
1163 target: gP1, x: 10, y: 10, window,
1164 modifiers: 0,
1165 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1166 expected: {
1167 axis: kHAxis, lines: 3, pixels() { return gCharWidth * 3; },
1171 { description: "WM_MOUSEHWHEEL, -120, -3 chars, window is deactive (receive the message directly)",
1172 message: WM_MOUSEHWHEEL, delta: -120,
1173 target: gP1, x: 10, y: 10, window,
1174 modifiers: 0,
1175 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1176 expected: {
1177 axis: kHAxis, lines: -3, pixels() { return gCharWidth * -3; },
1181 // Same for WM_*SCROLL if lParam is not NULL
1182 { description: "WM_VSCROLL, SB_LINEUP, lParam is not NULL, emulation disabled, window is deactive",
1183 message: WM_VSCROLL, delta: SB_LINEUP,
1184 target: gP1, x: 10, y: 10, window,
1185 modifiers: 0,
1186 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1187 expected: {
1188 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
1190 init() {
1191 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
1195 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, window is deactive",
1196 message: WM_VSCROLL, delta: SB_LINEDOWN,
1197 target: gP1, x: 10, y: 10, window,
1198 modifiers: 0,
1199 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1200 expected: {
1201 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1205 { description: "WM_HSCROLL, SB_LINELEFT, lParam is not NULL, emulation disabled, window is deactive",
1206 message: WM_HSCROLL, delta: SB_LINELEFT,
1207 target: gP1, x: 10, y: 10, window,
1208 modifiers: 0,
1209 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1210 expected: {
1211 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
1215 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, window is deactive",
1216 message: WM_HSCROLL, delta: SB_LINERIGHT,
1217 target: gP1, x: 10, y: 10, window,
1218 modifiers: 0,
1219 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1220 expected: {
1221 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1225 // Same for WM_*SCROLL if lParam is NULL but emulation is enabled
1226 { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation enabled, window is deactive",
1227 message: WM_VSCROLL, delta: SB_LINEUP,
1228 target: gP1, x: 10, y: 10, window,
1229 modifiers: 0,
1230 additionalFlags: 0,
1231 expected: {
1232 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
1234 init() {
1235 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, true);
1239 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation enabled, window is deactive",
1240 message: WM_VSCROLL, delta: SB_LINEDOWN,
1241 target: gP1, x: 10, y: 10, window,
1242 modifiers: 0,
1243 additionalFlags: 0,
1244 expected: {
1245 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1249 { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation enabled, window is deactive",
1250 message: WM_HSCROLL, delta: SB_LINELEFT,
1251 target: gP1, x: 10, y: 10, window,
1252 modifiers: 0,
1253 additionalFlags: 0,
1254 expected: {
1255 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
1259 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation enabled, window is deactive",
1260 message: WM_HSCROLL, delta: SB_LINERIGHT,
1261 target: gP1, x: 10, y: 10, window,
1262 modifiers: 0,
1263 additionalFlags: 0,
1264 expected: {
1265 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1269 // Same for WM_*SCROLL if lParam is not NULL and message sent to the deactive window directly
1270 { description: "WM_VSCROLL, SB_LINEUP, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
1271 message: WM_VSCROLL, delta: SB_LINEUP,
1272 target: gP1, x: 10, y: 10, window,
1273 modifiers: 0,
1274 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
1275 nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1276 expected: {
1277 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
1279 init() {
1280 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
1284 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
1285 message: WM_VSCROLL, delta: SB_LINEDOWN,
1286 target: gP1, x: 10, y: 10, window,
1287 modifiers: 0,
1288 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
1289 nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1290 expected: {
1291 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1295 { description: "WM_HSCROLL, SB_LINELEFT, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
1296 message: WM_HSCROLL, delta: SB_LINELEFT,
1297 target: gP1, x: 10, y: 10, window,
1298 modifiers: 0,
1299 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
1300 nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1301 expected: {
1302 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
1306 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
1307 message: WM_HSCROLL, delta: SB_LINERIGHT,
1308 target: gP1, x: 10, y: 10, window,
1309 modifiers: 0,
1310 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
1311 nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1312 expected: {
1313 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1317 // Same for WM_*SCROLL if lParam is NULL but emulation is enabled, and message sent to the deactive window directly
1318 { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
1319 message: WM_VSCROLL, delta: SB_LINEUP,
1320 target: gP1, x: 10, y: 10, window,
1321 modifiers: 0,
1322 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1323 expected: {
1324 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
1326 init() {
1327 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, true);
1331 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
1332 message: WM_VSCROLL, delta: SB_LINEDOWN,
1333 target: gP1, x: 10, y: 10, window,
1334 modifiers: 0,
1335 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1336 expected: {
1337 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1341 { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
1342 message: WM_HSCROLL, delta: SB_LINELEFT,
1343 target: gP1, x: 10, y: 10, window,
1344 modifiers: 0,
1345 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1346 expected: {
1347 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
1351 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
1352 message: WM_HSCROLL, delta: SB_LINERIGHT,
1353 target: gP1, x: 10, y: 10, window,
1354 modifiers: 0,
1355 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1356 expected: {
1357 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1360 finish() {
1361 gOtherWindow.close();
1362 gOtherWindow = null;
1363 window.close();
1368 function runDeactiveWindowTests() {
1369 gOtherWindow = window.open("window_mouse_scroll_win_2.html", "_blank",
1370 "chrome,width=100,height=100,top=700,left=700");
1372 window.arguments[0].SimpleTest.waitForFocus(function() {
1373 runNextTest(gDeactiveWindowTests, 0);
1374 }, gOtherWindow);
1377 function runNextTest(aTests, aIndex) {
1378 if (aIndex > 0 && aTests[aIndex - 1] && aTests[aIndex - 1].finish) {
1379 aTests[aIndex - 1].finish();
1382 if (aTests.length == aIndex) {
1383 return;
1386 var test = aTests[aIndex++];
1387 if (test.init) {
1388 test.init();
1390 test.handled = { lines: false, pixels: false };
1392 switch (test.message) {
1393 case WM_MOUSEWHEEL:
1394 case WM_MOUSEHWHEEL:
1395 case WM_VSCROLL:
1396 case WM_HSCROLL:
1397 var expectedLines = test.expected.lines;
1398 var expectedPixels =
1399 cut((typeof test.expected.pixels == "function") ?
1400 test.expected.pixels() : test.expected.pixels);
1401 var handler = function(aEvent) {
1402 var doCommonTests = true;
1404 if (!aEvent) {
1405 ok(!test.handled.lines,
1406 test.description + ", line scroll event has been handled");
1407 ok(!test.handled.pixels,
1408 test.description + ", pixel scroll event has been handled");
1409 doCommonTests = false;
1410 } else if (aEvent.type == kMouseLineScrollEvent) {
1411 ok(!test.handled.lines,
1412 test.description + ":(" + aEvent.type + "), same event has already been handled");
1413 test.handled.lines = true;
1414 isnot(expectedLines, 0,
1415 test.description + ":(" + aEvent.type + "), event shouldn't be fired");
1416 if (test.onLineScrollEvent && test.onLineScrollEvent(aEvent)) {
1417 doCommonTests = false;
1419 } else if (aEvent.type == kMousePixelScrollEvent) {
1420 ok(!test.handled.pixels,
1421 test.description + ":(" + aEvent.type + "), same event has already been handled");
1422 test.handled.pixels = true;
1423 isnot(expectedPixels, 0,
1424 test.description + ":(" + aEvent.type + "), event shouldn't be fired");
1425 if (test.onPixelScrollEvent && test.onPixelScrollEvent(aEvent)) {
1426 doCommonTests = false;
1430 if (doCommonTests) {
1431 var expectedDelta =
1432 (aEvent.type == kMouseLineScrollEvent) ?
1433 expectedLines : expectedPixels;
1434 is(aEvent.target.id, test.target.id,
1435 test.description + ":(" + aEvent.type + "), ID mismatch");
1436 is(aEvent.axis, test.expected.axis,
1437 test.description + ":(" + aEvent.type + "), axis mismatch");
1438 ok(aEvent.detail != 0,
1439 test.description + ":(" + aEvent.type + "), delta must not be 0");
1440 is(aEvent.detail, expectedDelta,
1441 test.description + ":(" + aEvent.type + "), delta mismatch");
1442 is(aEvent.shiftKey, (test.modifiers & (SHIFT_L | SHIFT_R)) != 0,
1443 test.description + ":(" + aEvent.type + "), shiftKey mismatch");
1444 is(aEvent.ctrlKey, (test.modifiers & (CTRL_L | CTRL_R)) != 0,
1445 test.description + ":(" + aEvent.type + "), ctrlKey mismatch");
1446 is(aEvent.altKey, (test.modifiers & (ALT_L | ALT_R)) != 0,
1447 test.description + ":(" + aEvent.type + "), altKey mismatch");
1450 if (!aEvent || (test.handled.lines || expectedLines == 0) &&
1451 (test.handled.pixels || expectedPixels == 0)) {
1452 // Don't scroll actually.
1453 if (aEvent) {
1454 aEvent.preventDefault();
1456 test.target.removeEventListener(kMouseLineScrollEvent, handler, true);
1457 test.target.removeEventListener(kMousePixelScrollEvent, handler, true);
1458 setTimeout(runNextTest, 0, aTests, aIndex);
1462 test.target.addEventListener(kMouseLineScrollEvent, handler, true);
1463 test.target.addEventListener(kMousePixelScrollEvent, handler, true);
1465 if (expectedLines == 0 && expectedPixels == 0) {
1466 // The timeout might not be enough if system is slow by other process,
1467 // so, the test might be passed unexpectedly. However, it must be able
1468 // to be detected by random orange.
1469 setTimeout(handler, 500);
1472 var utils = getWindowUtils(test.window);
1473 var ptInScreen = getPointInScreen(test.target, test.window);
1474 var isVertical =
1475 ((test.message == WM_MOUSEWHEEL) || (test.message == WM_VSCROLL));
1476 var deltaX = !isVertical ? test.delta : 0;
1477 var deltaY = isVertical ? test.delta : 0;
1478 utils.sendNativeMouseScrollEvent(ptInScreen.x + test.x,
1479 ptInScreen.y + test.y,
1480 test.message, deltaX, deltaY, 0,
1481 test.modifiers,
1482 test.additionalFlags,
1483 test.target);
1484 break;
1485 default:
1486 ok(false, test.description + ": invalid message");
1487 // Let's timeout.
1491 function prepareTests() {
1492 // Disable special action with modifier key
1493 SpecialPowers.setIntPref(kAltKeyActionPref, 1);
1494 SpecialPowers.setIntPref(kCtrlKeyActionPref, 1);
1495 SpecialPowers.setIntPref(kShiftKeyActionPref, 1);
1496 SpecialPowers.setIntPref(kWinKeyActionPref, 1);
1498 SpecialPowers.setIntPref(kAltKeyDeltaMultiplierXPref, 100);
1499 SpecialPowers.setIntPref(kAltKeyDeltaMultiplierYPref, 100);
1500 SpecialPowers.setIntPref(kCtrlKeyDeltaMultiplierXPref, 100);
1501 SpecialPowers.setIntPref(kCtrlKeyDeltaMultiplierYPref, 100);
1502 SpecialPowers.setIntPref(kShiftKeyDeltaMultiplierXPref, 100);
1503 SpecialPowers.setIntPref(kShiftKeyDeltaMultiplierYPref, 100);
1504 SpecialPowers.setIntPref(kWinKeyDeltaMultiplierXPref, 100);
1505 SpecialPowers.setIntPref(kWinKeyDeltaMultiplierYPref, 100);
1507 SpecialPowers.setBoolPref(kSystemScrollSpeedOverridePref, false);
1508 SpecialPowers.setIntPref(kTimeoutPref, -1);
1510 runNextTest(gPreparingSteps, 0);
1513 </script>
1514 </body>
1516 </html>