Bug 1688354 [wpt PR 27298] - Treat 'rem' as an absolute unit for font size, a=testonly
[gecko.git] / widget / tests / window_mouse_scroll_win.html
blobd982061076f4087aecaa354b045aa6d23702ebf1
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 { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
23 const WHEEL_PAGESCROLL = 4294967295;
25 const WM_VSCROLL = 0x0115;
26 const WM_HSCROLL = 0x0114;
27 const WM_MOUSEWHEEL = 0x020A;
28 const WM_MOUSEHWHEEL = 0x020E;
30 const SB_LINEUP = 0;
31 const SB_LINELEFT = 0;
32 const SB_LINEDOWN = 1;
33 const SB_LINERIGHT = 1;
34 const SB_PAGEUP = 2;
35 const SB_PAGELEFT = 2;
36 const SB_PAGEDOWN = 3;
37 const SB_PAGERIGHT = 3;
39 const SHIFT_L = 0x0100;
40 const SHIFT_R = 0x0200;
41 const CTRL_L = 0x0400;
42 const CTRL_R = 0x0800;
43 const ALT_L = 0x1000;
44 const ALT_R = 0x2000;
46 const DOM_PAGE_SCROLL_DELTA = 32768;
48 const kSystemScrollSpeedOverridePref = "mousewheel.system_scroll_override_on_root_content.enabled";
50 const kAltKeyActionPref = "mousewheel.with_alt.action";
51 const kCtrlKeyActionPref = "mousewheel.with_control.action";
52 const kShiftKeyActionPref = "mousewheel.with_shift.action";
53 const kWinKeyActionPref = "mousewheel.with_win.action";
55 const kAltKeyDeltaMultiplierXPref = "mousewheel.with_alt.delta_multiplier_x";
56 const kAltKeyDeltaMultiplierYPref = "mousewheel.with_alt.delta_multiplier_y";
57 const kCtrlKeyDeltaMultiplierXPref = "mousewheel.with_control.delta_multiplier_x";
58 const kCtrlKeyDeltaMultiplierYPref = "mousewheel.with_control.delta_multiplier_y";
59 const kShiftKeyDeltaMultiplierXPref = "mousewheel.with_shift.delta_multiplier_x";
60 const kShiftKeyDeltaMultiplierYPref = "mousewheel.with_shift.delta_multiplier_y";
61 const kWinKeyDeltaMultiplierXPref = "mousewheel.with_win.delta_multiplier_x";
62 const kWinKeyDeltaMultiplierYPref = "mousewheel.with_win.delta_multiplier_y";
64 const kEmulateWheelByWMSCROLLPref = "mousewheel.emulate_at_wm_scroll";
65 const kVAmountPref = "mousewheel.windows.vertical_amount_override";
66 const kHAmountPref = "mousewheel.windows.horizontal_amount_override";
67 const kTimeoutPref = "mousewheel.windows.transaction.timeout";
69 const kMouseLineScrollEvent = "DOMMouseScroll";
70 const kMousePixelScrollEvent = "MozMousePixelScroll";
72 const kVAxis = MouseScrollEvent.VERTICAL_AXIS;
73 const kHAxis = MouseScrollEvent.HORIZONTAL_AXIS;
75 var gLineHeight = 0;
76 var gCharWidth = 0;
77 var gPageHeight = 0;
78 var gPageWidth = 0;
80 var gP1 = document.getElementById("p1");
81 var gP2 = document.getElementById("p2");
83 var gOtherWindow;
85 function ok(aCondition, aMessage) {
86 window.arguments[0].SimpleTest.ok(aCondition, aMessage);
89 function is(aLeft, aRight, aMessage) {
90 window.arguments[0].SimpleTest.is(aLeft, aRight, aMessage);
93 function isnot(aLeft, aRight, aMessage) {
94 window.arguments[0].SimpleTest.isnot(aLeft, aRight, aMessage);
97 function todo_is(aLeft, aRight, aMessage) {
98 window.arguments[0].SimpleTest.todo_is(aLeft, aRight, aMessage);
101 function onUnload() {
102 SpecialPowers.clearUserPref(kAltKeyActionPref);
103 SpecialPowers.clearUserPref(kCtrlKeyActionPref);
104 SpecialPowers.clearUserPref(kShiftKeyActionPref);
105 SpecialPowers.clearUserPref(kWinKeyActionPref);
107 SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierXPref);
108 SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierYPref);
109 SpecialPowers.clearUserPref(kCtrlKeyDeltaMultiplierXPref);
110 SpecialPowers.clearUserPref(kCtrlKeyDeltaMultiplierYPref);
111 SpecialPowers.clearUserPref(kShiftKeyDeltaMultiplierXPref);
112 SpecialPowers.clearUserPref(kShiftKeyDeltaMultiplierYPref);
113 SpecialPowers.clearUserPref(kWinKeyDeltaMultiplierXPref);
114 SpecialPowers.clearUserPref(kWinKeyDeltaMultiplierYPref);
116 SpecialPowers.clearUserPref(kSystemScrollSpeedOverridePref);
117 SpecialPowers.clearUserPref(kEmulateWheelByWMSCROLLPref);
118 SpecialPowers.clearUserPref(kVAmountPref);
119 SpecialPowers.clearUserPref(kHAmountPref);
120 SpecialPowers.clearUserPref(kTimeoutPref);
121 window.arguments[0].SimpleTest.finish();
124 function getWindowUtils(aWindow) {
125 if (!aWindow) {
126 aWindow = window;
128 return aWindow.windowUtils;
131 function getPointInScreen(aElement, aWindow) {
132 if (!aWindow) {
133 aWindow = window;
135 var bounds = aElement.getBoundingClientRect();
136 return { x: bounds.left + aWindow.mozInnerScreenX,
137 y: bounds.top + aWindow.mozInnerScreenY };
140 function cut(aNum) {
141 return (aNum >= 0) ? Math.floor(aNum) : Math.ceil(aNum);
145 * Make each steps for the tests in following arrays in global scope. Each item
146 * of the arrays will be executed after previous test is finished.
148 * description:
149 * Set the description of the test. This will be used for the message of is()
150 * or the others.
152 * message:
153 * aNativeMessage of nsIDOMWindowUtils.sendNativeMouseScrollEvent().
154 * Must be WM_MOUSEWHEEL, WM_MOUSEHWHEEL, WM_VSCROLL or WM_HSCROLL.
156 * delta:
157 * The native delta value for WM_MOUSEWHEEL or WM_MOUSEHWHEEL.
158 * Or one of the SB_* const value for WM_VSCROLL or WM_HSCROLL.
160 * target:
161 * The target element, under the mouse cursor.
163 * window:
164 * The window which is used for getting nsIDOMWindowUtils.
166 * modifiers:
167 * Pressed modifier keys, 0 means no modifier key is pressed.
168 * Otherwise, one or more values of SHIFT_L, SHIFT_R, CTRL_L, CTRL_R,
169 * ALT_L or ALT_R.
171 * additionalFlags:
172 * aAdditionalFlags of nsIDOMWindowUtils.sendNativeMouseScrollEvent().
173 * See the document of nsIDOMWindowUtils for the detail of the values.
175 * onLineScrollEvent:
176 * Must be a function or null.
177 * If the value is a function, it will be called when DOMMouseScroll event
178 * is received by the synthesized event.
179 * If return true, the common checks are canceled.
181 * onPixelScrollEvent:
182 * Must be a function or null.
183 * If the value is a function, it will be called when MozMousePixelScroll
184 * event is received by the synthesized event.
185 * If return true, the common checks are canceled.
187 * expected:
188 * Must not be null and this must have:
189 * axis:
190 * kVAxis if the synthesized event causes vertical scroll. Otherwise,
191 * it causes horizontal scroll, kHAxis.
192 * lines:
193 * Integer value which is expected detail attribute value of
194 * DOMMouseScroll. If the event shouldn't be fired, must be 0.
195 * pixels:
196 * Integer value or a function which returns double value. The value is
197 * expected detail attribute value of MozMousePixelScroll.
198 * If the event shouldn't be fired, must be 0.
200 * Note that if both lines and pixels are 0, the test framework waits
201 * a few seconds. After that, go to next test.
203 * init:
204 * Must be a function or null. If this value is a function, it's called
205 * before synthesizing the native event.
207 * finish:
208 * Must be a function or null. If this value is a function, it's called
209 * after received all expected events or timeout if no events are expected.
212 // First, get the computed line height, char width, page height and page width.
213 var gPreparingSteps = [
214 { description: "Preparing gLineHeight",
215 message: WM_MOUSEWHEEL, delta: -120,
216 target: gP1, x: 10, y: 10, window,
217 modifiers: 0,
218 additionalFlags: 0,
219 onLineScrollEvent(aEvent) {
220 return true;
222 onPixelScrollEvent(aEvent) {
223 gLineHeight = aEvent.detail;
224 return true;
226 expected: {
227 axis: kVAxis, lines: 1, pixels: 1,
229 init() {
230 SpecialPowers.setIntPref(kVAmountPref, 1);
231 SpecialPowers.setIntPref(kHAmountPref, 1);
234 { description: "Preparing gCharWidth",
235 message: WM_MOUSEHWHEEL, delta: 120,
236 target: gP1, x: 10, y: 10, window,
237 modifiers: 0,
238 additionalFlags: 0,
239 onLineScrollEvent(aEvent) {
240 return true;
242 onPixelScrollEvent(aEvent) {
243 gCharWidth = aEvent.detail;
244 return true;
246 expected: {
247 axis: kVAxis, lines: 1, pixels: 1,
250 { description: "Preparing gPageHeight",
251 message: WM_MOUSEWHEEL, delta: -120,
252 target: gP1, x: 10, y: 10, window,
253 modifiers: 0,
254 additionalFlags: 0,
255 onLineScrollEvent(aEvent) {
256 return true;
258 onPixelScrollEvent(aEvent) {
259 gPageHeight = aEvent.detail;
260 return true;
262 expected: {
263 axis: kHAxis, lines: 1, pixels: 1,
265 init() {
266 SpecialPowers.setIntPref(kVAmountPref, 0xFFFF);
267 SpecialPowers.setIntPref(kHAmountPref, 0xFFFF);
270 { description: "Preparing gPageWidth",
271 message: WM_MOUSEHWHEEL, delta: 120,
272 target: gP1, x: 10, y: 10, window,
273 modifiers: 0,
274 additionalFlags: 0,
275 onLineScrollEvent(aEvent) {
276 return true;
278 onPixelScrollEvent(aEvent) {
279 gPageWidth = aEvent.detail;
280 return true;
282 expected: {
283 axis: kHAxis, lines: 1, pixels: 1,
285 finish() {
286 ok(gLineHeight > 0, "gLineHeight isn't positive got " + gLineHeight);
287 ok(gCharWidth > 0, "gCharWidth isn't positive got " + gCharWidth);
288 ok(gPageHeight > 0, "gPageHeight isn't positive got " + gPageHeight);
289 ok(gPageWidth > 0, "gPageWidth isn't positive got " + gPageWidth);
291 ok(gPageHeight > gLineHeight,
292 "gPageHeight must be larger than gLineHeight");
293 ok(gPageWidth > gCharWidth,
294 "gPageWidth must be larger than gCharWidth");
295 runNextTest(gBasicTests, 0);
300 var gBasicTests = [
301 // Widget shouldn't dispatch a pixel event if the delta can be devided by
302 // lines to be scrolled. However, pixel events should be fired by ESM.
303 { description: "WM_MOUSEWHEEL, -120, 3 lines",
304 message: WM_MOUSEWHEEL, delta: -120,
305 target: gP1, x: 10, y: 10, window,
306 modifiers: 0,
307 additionalFlags: 0,
308 expected: {
309 axis: kVAxis, lines: 3, pixels() { return gLineHeight * 3; },
311 init() {
312 SpecialPowers.setIntPref(kVAmountPref, 3);
313 SpecialPowers.setIntPref(kHAmountPref, 3);
317 { description: "WM_MOUSEWHEEL, 120, -3 lines",
318 message: WM_MOUSEWHEEL, delta: 120,
319 target: gP1, x: 10, y: 10, window,
320 modifiers: 0,
321 additionalFlags: 0,
322 expected: {
323 axis: kVAxis, lines: -3, pixels() { return gLineHeight * -3; },
327 { description: "WM_MOUSEHWHEEL, 120, 3 chars",
328 message: WM_MOUSEHWHEEL, delta: 120,
329 target: gP1, x: 10, y: 10, window,
330 modifiers: 0,
331 additionalFlags: 0,
332 expected: {
333 axis: kHAxis, lines: 3, pixels() { return gCharWidth * 3; },
337 { description: "WM_MOUSEHWHEEL, -120, -3 chars",
338 message: WM_MOUSEHWHEEL, delta: -120,
339 target: gP1, x: 10, y: 10, window,
340 modifiers: 0,
341 additionalFlags: 0,
342 expected: {
343 axis: kHAxis, lines: -3, pixels() { return gCharWidth * -3; },
347 // Pixel scroll event should be fired always but line scroll event should be
348 // fired only when accumulated delta value is over a line.
349 { description: "WM_MOUSEWHEEL, -20, 0.5 lines",
350 message: WM_MOUSEWHEEL, delta: -20,
351 target: gP1, x: 10, y: 10, window,
352 modifiers: 0,
353 additionalFlags: 0,
354 expected: {
355 axis: kVAxis, lines: 0, pixels() { return gLineHeight / 2; },
358 { description: "WM_MOUSEWHEEL, -20, 0.5 lines (pending: 0.5 lines)",
359 message: WM_MOUSEWHEEL, delta: -20,
360 target: gP1, x: 10, y: 10, window,
361 modifiers: 0,
362 additionalFlags: 0,
363 expected: {
364 axis: kVAxis, lines: 1, pixels() { return gLineHeight / 2; },
367 { description: "WM_MOUSEWHEEL, -20, 0.5 lines",
368 message: WM_MOUSEWHEEL, delta: -20,
369 target: gP1, x: 10, y: 10, window,
370 modifiers: 0,
371 additionalFlags: 0,
372 expected: {
373 axis: kVAxis, lines: 0, pixels() { return gLineHeight / 2; },
377 { description: "WM_MOUSEWHEEL, 20, -0.5 lines (pending: 0.5 lines)",
378 message: WM_MOUSEWHEEL, delta: 20,
379 target: gP1, x: 10, y: 10, window,
380 modifiers: 0,
381 additionalFlags: 0,
382 expected: {
383 axis: kVAxis, lines: 0, pixels() { return gLineHeight / -2; },
386 { description: "WM_MOUSEWHEEL, 20, -0.5 lines (pending: -0.5 lines)",
387 message: WM_MOUSEWHEEL, delta: 20,
388 target: gP1, x: 10, y: 10, window,
389 modifiers: 0,
390 additionalFlags: 0,
391 expected: {
392 axis: kVAxis, lines: -1, pixels() { return -gLineHeight / 2; },
395 { description: "WM_MOUSEWHEEL, 20, -0.5 lines",
396 message: WM_MOUSEWHEEL, delta: 20,
397 target: gP1, x: 10, y: 10, window,
398 modifiers: 0,
399 additionalFlags: 0,
400 expected: {
401 axis: kVAxis, lines: 0, pixels() { return gLineHeight / -2; },
405 { description: "WM_MOUSEHWHEEL, 20, 0.5 chars",
406 message: WM_MOUSEHWHEEL, delta: 20,
407 target: gP1, x: 10, y: 10, window,
408 modifiers: 0,
409 additionalFlags: 0,
410 expected: {
411 axis: kHAxis, lines: 0, pixels() { return gCharWidth / 2; },
414 { description: "WM_MOUSEHWHEEL, 20, 0.5 chars (pending: 0.5 chars)",
415 message: WM_MOUSEHWHEEL, delta: 20,
416 target: gP1, x: 10, y: 10, window,
417 modifiers: 0,
418 additionalFlags: 0,
419 expected: {
420 axis: kHAxis, lines: 1, pixels() { return gCharWidth / 2; },
423 { description: "WM_MOUSEHWHEEL, 20, 0.5 chars",
424 message: WM_MOUSEHWHEEL, delta: 20,
425 target: gP1, x: 10, y: 10, window,
426 modifiers: 0,
427 additionalFlags: 0,
428 expected: {
429 axis: kHAxis, lines: 0, pixels() { return gCharWidth / 2; },
433 { description: "WM_MOUSEHWHEEL, -20, -0.5 chars (pending: 0.5 chars)",
434 message: WM_MOUSEHWHEEL, delta: -20,
435 target: gP1, x: 10, y: 10, window,
436 modifiers: 0,
437 additionalFlags: 0,
438 expected: {
439 axis: kHAxis, lines: 0, pixels() { return gCharWidth / -2; },
442 { description: "WM_MOUSEHWHEEL, -20, -0.5 chars (pending: -0.5 chars)",
443 message: WM_MOUSEHWHEEL, delta: -20,
444 target: gP1, x: 10, y: 10, window,
445 modifiers: 0,
446 additionalFlags: 0,
447 expected: {
448 axis: kHAxis, lines: -1, pixels() { return -gCharWidth / 2; },
451 { description: "WM_MOUSEHWHEEL, -20, -0.5 chars",
452 message: WM_MOUSEHWHEEL, delta: -20,
453 target: gP1, x: 10, y: 10, window,
454 modifiers: 0,
455 additionalFlags: 0,
456 expected: {
457 axis: kHAxis, lines: 0, pixels() { return gCharWidth / -2; },
461 // Even if the mouse cursor is an element whose font-size is different than
462 // the scrollable element, the pixel scroll amount shouldn't be changed.
463 // Widget shouldn't dispatch a pixel event if the delta can be devided by
464 // lines to be scrolled. However, pixel events should be fired by ESM.
465 { description: "WM_MOUSEWHEEL, -120, 3 lines, on the other div whose font-size is larger",
466 message: WM_MOUSEWHEEL, delta: -120,
467 target: gP2, x: 10, y: 10, window,
468 modifiers: 0,
469 additionalFlags: 0,
470 expected: {
471 axis: kVAxis, lines: 3, pixels() { return gLineHeight * 3; },
475 { description: "WM_MOUSEWHEEL, 120, -3 lines, on the other div whose font-size is larger",
476 message: WM_MOUSEWHEEL, delta: 120,
477 target: gP2, x: 10, y: 10, window,
478 modifiers: 0,
479 additionalFlags: 0,
480 expected: {
481 axis: kVAxis, lines: -3, pixels() { return gLineHeight * -3; },
485 { description: "WM_MOUSEHWHEEL, 120, 3 chars, on the other div whose font-size is larger",
486 message: WM_MOUSEHWHEEL, delta: 120,
487 target: gP2, x: 10, y: 10, window,
488 modifiers: 0,
489 additionalFlags: 0,
490 expected: {
491 axis: kHAxis, lines: 3, pixels() { return gCharWidth * 3; },
495 { description: "WM_MOUSEHWHEEL, -120, -3 chars, on the other div whose font-size is larger",
496 message: WM_MOUSEHWHEEL, delta: -120,
497 target: gP2, x: 10, y: 10, window,
498 modifiers: 0,
499 additionalFlags: 0,
500 expected: {
501 axis: kHAxis, lines: -3, pixels() { return gCharWidth * -3; },
505 // Modifier key tests
506 { description: "WM_MOUSEWHEEL, -40, 1 line with left Shift",
507 message: WM_MOUSEWHEEL, delta: -40,
508 target: gP1, x: 10, y: 10, window,
509 modifiers: SHIFT_L,
510 additionalFlags: 0,
511 expected: {
512 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
515 { description: "WM_MOUSEWHEEL, -40, 1 line with right Shift",
516 message: WM_MOUSEWHEEL, delta: -40,
517 target: gP1, x: 10, y: 10, window,
518 modifiers: SHIFT_R,
519 additionalFlags: 0,
520 expected: {
521 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
524 { description: "WM_MOUSEWHEEL, -40, 1 line with left Ctrl",
525 message: WM_MOUSEWHEEL, delta: -40,
526 target: gP1, x: 10, y: 10, window,
527 modifiers: CTRL_L,
528 additionalFlags: 0,
529 expected: {
530 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
533 { description: "WM_MOUSEWHEEL, -40, 1 line with right Ctrl",
534 message: WM_MOUSEWHEEL, delta: -40,
535 target: gP1, x: 10, y: 10, window,
536 modifiers: CTRL_R,
537 additionalFlags: 0,
538 expected: {
539 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
542 { description: "WM_MOUSEWHEEL, -40, 1 line with left Alt",
543 message: WM_MOUSEWHEEL, delta: -40,
544 target: gP1, x: 10, y: 10, window,
545 modifiers: ALT_L,
546 additionalFlags: 0,
547 expected: {
548 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
551 { description: "WM_MOUSEWHEEL, -40, 1 line with right Alt",
552 message: WM_MOUSEWHEEL, delta: -40,
553 target: gP1, x: 10, y: 10, window,
554 modifiers: ALT_R,
555 additionalFlags: 0,
556 expected: {
557 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
561 { description: "WM_MOUSEHWHEEL, 40, 1 character with left Shift",
562 message: WM_MOUSEHWHEEL, delta: 40,
563 target: gP1, x: 10, y: 10, window,
564 modifiers: SHIFT_L,
565 additionalFlags: 0,
566 expected: {
567 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
570 { description: "WM_MOUSEHWHEEL, 40, 1 character with right Shift",
571 message: WM_MOUSEHWHEEL, delta: 40,
572 target: gP1, x: 10, y: 10, window,
573 modifiers: SHIFT_R,
574 additionalFlags: 0,
575 expected: {
576 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
579 { description: "WM_MOUSEHWHEEL, 40, 1 character with left Ctrl",
580 message: WM_MOUSEHWHEEL, delta: 40,
581 target: gP1, x: 10, y: 10, window,
582 modifiers: CTRL_L,
583 additionalFlags: 0,
584 expected: {
585 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
588 { description: "WM_MOUSEHWHEEL, 40, 1 character with right Ctrl",
589 message: WM_MOUSEHWHEEL, delta: 40,
590 target: gP1, x: 10, y: 10, window,
591 modifiers: CTRL_R,
592 additionalFlags: 0,
593 expected: {
594 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
597 { description: "WM_MOUSEHWHEEL, 40, 1 character with left Alt",
598 message: WM_MOUSEHWHEEL, delta: 40,
599 target: gP1, x: 10, y: 10, window,
600 modifiers: ALT_L,
601 additionalFlags: 0,
602 expected: {
603 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
606 { description: "WM_MOUSEHWHEEL, 40, 1 character with right Alt",
607 message: WM_MOUSEHWHEEL, delta: 40,
608 target: gP1, x: 10, y: 10, window,
609 modifiers: ALT_R,
610 additionalFlags: 0,
611 expected: {
612 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
615 finish() {
616 runNextTest(gScrollMessageTests, 0);
621 var gPageScrllTests = [
622 // Pixel scroll event should be fired always but line scroll event should be
623 // fired only when accumulated delta value is over a line.
624 { description: "WM_MOUSEWHEEL, -60, 0.5 pages",
625 message: WM_MOUSEWHEEL, delta: -60,
626 target: gP1, x: 10, y: 10, window,
627 modifiers: 0,
628 additionalFlags: 0,
629 expected: {
630 axis: kVAxis, lines: 0, pixels() { return gPageHeight / 2; },
633 { description: "WM_MOUSEWHEEL, -60, 0.5 pages (pending: 0.5 pages)",
634 message: WM_MOUSEWHEEL, delta: -60,
635 target: gP1, x: 10, y: 10, window,
636 modifiers: 0,
637 additionalFlags: 0,
638 expected: {
639 axis: kVAxis, lines: DOM_PAGE_SCROLL_DELTA,
640 pixels() { return ((gPageHeight / 2) + (gPageHeight % 2)); },
643 { description: "WM_MOUSEWHEEL, -60, 0.5 pages",
644 message: WM_MOUSEWHEEL, delta: -60,
645 target: gP1, x: 10, y: 10, window,
646 modifiers: 0,
647 additionalFlags: 0,
648 expected: {
649 axis: kVAxis, lines: 0, pixels() { return gPageHeight / 2; },
653 { description: "WM_MOUSEWHEEL, 60, -0.5 pages (pending: 0.5 pages)",
654 message: WM_MOUSEWHEEL, delta: 60,
655 target: gP1, x: 10, y: 10, window,
656 modifiers: 0,
657 additionalFlags: 0,
658 expected: {
659 axis: kVAxis, lines: 0, pixels() { return gPageHeight / -2; },
662 { description: "WM_MOUSEWHEEL, 60, -0.5 pages (pending: -0.5 pages)",
663 message: WM_MOUSEWHEEL, delta: 60,
664 target: gP1, x: 10, y: 10, window,
665 modifiers: 0,
666 additionalFlags: 0,
667 expected: {
668 axis: kVAxis, lines: -DOM_PAGE_SCROLL_DELTA,
669 pixels() { return -((gPageHeight / 2) + (gPageHeight % 2)); },
672 { description: "WM_MOUSEWHEEL, 60, -0.5 pages",
673 message: WM_MOUSEWHEEL, delta: 60,
674 target: gP1, x: 10, y: 10, window,
675 modifiers: 0,
676 additionalFlags: 0,
677 expected: {
678 axis: kVAxis, lines: 0, pixels() { return gPageHeight / -2; },
682 { description: "WM_MOUSEHWHEEL, 60, 0.5 pages",
683 message: WM_MOUSEHWHEEL, delta: 60,
684 target: gP1, x: 10, y: 10, window,
685 modifiers: 0,
686 additionalFlags: 0,
687 expected: {
688 axis: kHAxis, lines: 0, pixels() { return gPageWidth / 2; },
691 { description: "WM_MOUSEHWHEEL, 60, 0.5 pages (pending: 0.5 pages)",
692 message: WM_MOUSEHWHEEL, delta: 60,
693 target: gP1, x: 10, y: 10, window,
694 modifiers: 0,
695 additionalFlags: 0,
696 expected: {
697 axis: kHAxis, lines: DOM_PAGE_SCROLL_DELTA,
698 pixels() { return ((gPageWidth / 2) + (gPageWidth % 2)); },
701 { description: "WM_MOUSEHWHEEL, 60, 0.5 pages",
702 message: WM_MOUSEHWHEEL, delta: 60,
703 target: gP1, x: 10, y: 10, window,
704 modifiers: 0,
705 additionalFlags: 0,
706 expected: {
707 axis: kHAxis, lines: 0, pixels() { return gPageWidth / 2; },
711 { description: "WM_MOUSEHWHEEL, -60, -0.5 pages (pending: 0.5 pages)",
712 message: WM_MOUSEHWHEEL, delta: -60,
713 target: gP1, x: 10, y: 10, window,
714 modifiers: 0,
715 additionalFlags: 0,
716 expected: {
717 axis: kHAxis, lines: 0, pixels() { return gCharWidth / -2; },
720 { description: "WM_MOUSEHWHEEL, -60, -0.5 pages (pending: -0.5 pages)",
721 message: WM_MOUSEHWHEEL, delta: -60,
722 target: gP1, x: 10, y: 10, window,
723 modifiers: 0,
724 additionalFlags: 0,
725 expected: {
726 axis: kHAxis, lines: -DOM_PAGE_SCROLL_DELTA,
727 pixels() { return -((gCharWidth / 2) + (gCharWidth % 2)); },
730 { description: "WM_MOUSEHWHEEL, -60, -0.5 pages",
731 message: WM_MOUSEHWHEEL, delta: -60,
732 target: gP1, x: 10, y: 10, window,
733 modifiers: 0,
734 additionalFlags: 0,
735 expected: {
736 axis: kHAxis, lines: 0, pixels() { return gCharWidth / -2; },
741 var gScrollMessageTests = [
742 // Widget should dispatch neither line scroll event nor pixel scroll event if
743 // the WM_*SCROLL's lParam is NULL and mouse wheel emulation is disabled.
744 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation disabled",
745 message: WM_VSCROLL, delta: SB_LINEDOWN,
746 target: gP1, x: 10, y: 10, window,
747 modifiers: 0,
748 additionalFlags: 0,
749 expected: {
750 axis: kVAxis, lines: 0, pixels: 0,
752 init() {
753 SpecialPowers.setIntPref(kVAmountPref, 3);
754 SpecialPowers.setIntPref(kHAmountPref, 3);
755 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
759 { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation disabled",
760 message: WM_VSCROLL, delta: SB_LINEUP,
761 target: gP1, x: 10, y: 10, window,
762 modifiers: 0,
763 additionalFlags: 0,
764 expected: {
765 axis: kVAxis, lines: 0, pixels: 0,
769 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation disabled",
770 message: WM_HSCROLL, delta: SB_LINERIGHT,
771 target: gP1, x: 10, y: 10, window,
772 modifiers: 0,
773 additionalFlags: 0,
774 expected: {
775 axis: kHAxis, lines: 0, pixels: 0,
779 { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation disabled",
780 message: WM_HSCROLL, delta: SB_LINELEFT,
781 target: gP1, x: 10, y: 10, window,
782 modifiers: 0,
783 additionalFlags: 0,
784 expected: {
785 axis: kHAxis, lines: 0, pixels: 0,
789 // Widget should emulate mouse wheel behavior for WM_*SCROLL even if the
790 // kEmulateWheelByWMSCROLLPref is disabled but the message's lParam is not
791 // NULL. Then, widget doesn't dispatch a pixel event for WM_*SCROLL messages,
792 // but ESM dispatches it instead.
793 { description: "WM_VSCROLL, SB_LINEUP, lParam is not NULL, emulation disabled",
794 message: WM_VSCROLL, delta: SB_LINEUP,
795 target: gP1, x: 10, y: 10, window,
796 modifiers: 0,
797 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
798 expected: {
799 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
801 init() {
802 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
806 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled",
807 message: WM_VSCROLL, delta: SB_LINEDOWN,
808 target: gP1, x: 10, y: 10, window,
809 modifiers: 0,
810 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
811 expected: {
812 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
816 { description: "WM_HSCROLL, SB_LINELEFT, lParam is not NULL, emulation disabled",
817 message: WM_HSCROLL, delta: SB_LINELEFT,
818 target: gP1, x: 10, y: 10, window,
819 modifiers: 0,
820 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
821 expected: {
822 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
826 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled",
827 message: WM_HSCROLL, delta: SB_LINERIGHT,
828 target: gP1, x: 10, y: 10, window,
829 modifiers: 0,
830 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
831 expected: {
832 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
836 { description: "WM_VSCROLL, SB_PAGEUP, lParam is not NULL, emulation disabled",
837 message: WM_VSCROLL, delta: SB_PAGEUP,
838 target: gP1, x: 10, y: 10, window,
839 modifiers: 0,
840 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
841 expected: {
842 axis: kVAxis, lines: -DOM_PAGE_SCROLL_DELTA,
843 pixels() { return -gPageHeight; },
847 { description: "WM_VSCROLL, SB_PAGEDOWN, lParam is not NULL, emulation disabled",
848 message: WM_VSCROLL, delta: SB_PAGEDOWN,
849 target: gP1, x: 10, y: 10, window,
850 modifiers: 0,
851 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
852 expected: {
853 axis: kVAxis, lines: DOM_PAGE_SCROLL_DELTA,
854 pixels() { return gPageHeight; },
858 { description: "WM_HSCROLL, SB_PAGELEFT, lParam is not NULL, emulation disabled",
859 message: WM_HSCROLL, delta: SB_PAGELEFT,
860 target: gP1, x: 10, y: 10, window,
861 modifiers: 0,
862 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
863 expected: {
864 axis: kHAxis, lines: -DOM_PAGE_SCROLL_DELTA,
865 pixels() { return -gPageWidth; },
869 { description: "WM_HSCROLL, SB_PAGERIGHT, lParam is not NULL, emulation disabled",
870 message: WM_HSCROLL, delta: SB_PAGERIGHT,
871 target: gP1, x: 10, y: 10, window,
872 modifiers: 0,
873 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
874 expected: {
875 axis: kHAxis, lines: DOM_PAGE_SCROLL_DELTA,
876 pixels() { return gPageWidth; },
880 // Widget should emulate mouse wheel behavior for WM_*SCROLL when the
881 // kEmulateWheelByWMSCROLLPref is enabled even if the message's lParam is
882 // NULL. Then, widget doesn't dispatch a pixel event for WM_*SCROLL messages,
883 // but ESM dispatches it instead.
884 { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation enabled",
885 message: WM_VSCROLL, delta: SB_LINEUP,
886 target: gP1, x: 10, y: 10, window,
887 modifiers: 0,
888 additionalFlags: 0,
889 expected: {
890 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
892 init() {
893 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, true);
897 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation enabled",
898 message: WM_VSCROLL, delta: SB_LINEDOWN,
899 target: gP1, x: 10, y: 10, window,
900 modifiers: 0,
901 additionalFlags: 0,
902 expected: {
903 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
907 { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation enabled",
908 message: WM_HSCROLL, delta: SB_LINELEFT,
909 target: gP1, x: 10, y: 10, window,
910 modifiers: 0,
911 additionalFlags: 0,
912 expected: {
913 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
917 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation enabled",
918 message: WM_HSCROLL, delta: SB_LINERIGHT,
919 target: gP1, x: 10, y: 10, window,
920 modifiers: 0,
921 additionalFlags: 0,
922 expected: {
923 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
927 { description: "WM_VSCROLL, SB_PAGEUP, lParam is NULL, emulation enabled",
928 message: WM_VSCROLL, delta: SB_PAGEUP,
929 target: gP1, x: 10, y: 10, window,
930 modifiers: 0,
931 additionalFlags: 0,
932 expected: {
933 axis: kVAxis, lines: -DOM_PAGE_SCROLL_DELTA,
934 pixels() { return -gPageHeight; },
938 { description: "WM_VSCROLL, SB_PAGEDOWN, lParam is NULL, emulation enabled",
939 message: WM_VSCROLL, delta: SB_PAGEDOWN,
940 target: gP1, x: 10, y: 10, window,
941 modifiers: 0,
942 additionalFlags: 0,
943 expected: {
944 axis: kVAxis, lines: DOM_PAGE_SCROLL_DELTA,
945 pixels() { return gPageHeight; },
949 { description: "WM_HSCROLL, SB_PAGELEFT, lParam is NULL, emulation enabled",
950 message: WM_HSCROLL, delta: SB_PAGELEFT,
951 target: gP1, x: 10, y: 10, window,
952 modifiers: 0,
953 additionalFlags: 0,
954 expected: {
955 axis: kHAxis, lines: -DOM_PAGE_SCROLL_DELTA,
956 pixels() { return -gPageWidth; },
960 { description: "WM_HSCROLL, SB_PAGERIGHT, lParam is NULL, emulation enabled",
961 message: WM_HSCROLL, delta: SB_PAGERIGHT,
962 target: gP1, x: 10, y: 10, window,
963 modifiers: 0,
964 additionalFlags: 0,
965 expected: {
966 axis: kHAxis, lines: DOM_PAGE_SCROLL_DELTA,
967 pixels() { return gPageWidth; },
971 // Modifier key tests for WM_*SCROLL
972 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with left Shift",
973 message: WM_VSCROLL, delta: SB_LINEDOWN,
974 target: gP1, x: 10, y: 10, window,
975 modifiers: SHIFT_L,
976 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
977 expected: {
978 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
980 init() {
981 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
984 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with right Shift",
985 message: WM_VSCROLL, delta: SB_LINEDOWN,
986 target: gP1, x: 10, y: 10, window,
987 modifiers: SHIFT_R,
988 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
989 expected: {
990 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
993 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with left Ctrl",
994 message: WM_VSCROLL, delta: SB_LINEDOWN,
995 target: gP1, x: 10, y: 10, window,
996 modifiers: CTRL_L,
997 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
998 expected: {
999 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1002 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with right Ctrl",
1003 message: WM_VSCROLL, delta: SB_LINEDOWN,
1004 target: gP1, x: 10, y: 10, window,
1005 modifiers: CTRL_L,
1006 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1007 expected: {
1008 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1011 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with left Alt",
1012 message: WM_VSCROLL, delta: SB_LINEDOWN,
1013 target: gP1, x: 10, y: 10, window,
1014 modifiers: ALT_L,
1015 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1016 expected: {
1017 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1020 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with right Alt",
1021 message: WM_VSCROLL, delta: SB_LINEDOWN,
1022 target: gP1, x: 10, y: 10, window,
1023 modifiers: ALT_R,
1024 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1025 expected: {
1026 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1030 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with left Shift",
1031 message: WM_HSCROLL, delta: SB_LINERIGHT,
1032 target: gP1, x: 10, y: 10, window,
1033 modifiers: SHIFT_L,
1034 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1035 expected: {
1036 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1039 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with right Shift",
1040 message: WM_HSCROLL, delta: SB_LINERIGHT,
1041 target: gP1, x: 10, y: 10, window,
1042 modifiers: SHIFT_R,
1043 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1044 expected: {
1045 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1048 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with left Ctrl",
1049 message: WM_HSCROLL, delta: SB_LINERIGHT,
1050 target: gP1, x: 10, y: 10, window,
1051 modifiers: CTRL_L,
1052 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1053 expected: {
1054 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1057 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with right Ctrl",
1058 message: WM_HSCROLL, delta: SB_LINERIGHT,
1059 target: gP1, x: 10, y: 10, window,
1060 modifiers: CTRL_L,
1061 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1062 expected: {
1063 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1066 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with left Alt",
1067 message: WM_HSCROLL, delta: SB_LINERIGHT,
1068 target: gP1, x: 10, y: 10, window,
1069 modifiers: ALT_L,
1070 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1071 expected: {
1072 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1075 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with right Alt",
1076 message: WM_HSCROLL, delta: SB_LINERIGHT,
1077 target: gP1, x: 10, y: 10, window,
1078 modifiers: ALT_R,
1079 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1080 expected: {
1081 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1084 finish() {
1085 runDeactiveWindowTests();
1090 var gDeactiveWindowTests = [
1091 // Typically, mouse drivers send wheel messages to focused window.
1092 // However, we prefer to scroll a scrollable element under the mouse cursor.
1093 { description: "WM_MOUSEWHEEL, -120, 3 lines, window is deactive",
1094 message: WM_MOUSEWHEEL, delta: -120,
1095 target: gP1, x: 10, y: 10, window,
1096 modifiers: 0,
1097 additionalFlags: 0,
1098 expected: {
1099 axis: kVAxis, lines: 3, pixels() { return gLineHeight * 3; },
1101 init() {
1102 SpecialPowers.setIntPref(kVAmountPref, 3);
1103 SpecialPowers.setIntPref(kHAmountPref, 3);
1105 onLineScrollEvent(aEvent) {
1106 var fm = Services.focus;
1107 is(fm.activeWindow, gOtherWindow, "The other window isn't activated");
1111 { description: "WM_MOUSEWHEEL, 120, -3 lines, window is deactive",
1112 message: WM_MOUSEWHEEL, delta: 120,
1113 target: gP1, x: 10, y: 10, window,
1114 modifiers: 0,
1115 additionalFlags: 0,
1116 expected: {
1117 axis: kVAxis, lines: -3, pixels() { return gLineHeight * -3; },
1121 { description: "WM_MOUSEHWHEEL, 120, 3 chars, window is deactive",
1122 message: WM_MOUSEHWHEEL, delta: 120,
1123 target: gP1, x: 10, y: 10, window,
1124 modifiers: 0,
1125 additionalFlags: 0,
1126 expected: {
1127 axis: kHAxis, lines: 3, pixels() { return gCharWidth * 3; },
1131 { description: "WM_MOUSEHWHEEL, -120, -3 chars, window is deactive",
1132 message: WM_MOUSEHWHEEL, delta: -120,
1133 target: gP1, x: 10, y: 10, window,
1134 modifiers: 0,
1135 additionalFlags: 0,
1136 expected: {
1137 axis: kHAxis, lines: -3, pixels() { return gCharWidth * -3; },
1141 // Of course, even if some drivers prefer the cursor position, we don't need
1142 // to change anything.
1143 { description: "WM_MOUSEWHEEL, -120, 3 lines, window is deactive (receive the message directly)",
1144 message: WM_MOUSEWHEEL, delta: -120,
1145 target: gP1, x: 10, y: 10, window,
1146 modifiers: 0,
1147 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1148 expected: {
1149 axis: kVAxis, lines: 3, pixels() { return gLineHeight * 3; },
1153 { description: "WM_MOUSEWHEEL, 120, -3 lines, window is deactive (receive the message directly)",
1154 message: WM_MOUSEWHEEL, delta: 120,
1155 target: gP1, x: 10, y: 10, window,
1156 modifiers: 0,
1157 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1158 expected: {
1159 axis: kVAxis, lines: -3, pixels() { return gLineHeight * -3; },
1163 { description: "WM_MOUSEHWHEEL, 120, 3 chars, window is deactive (receive the message directly)",
1164 message: WM_MOUSEHWHEEL, delta: 120,
1165 target: gP1, x: 10, y: 10, window,
1166 modifiers: 0,
1167 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1168 expected: {
1169 axis: kHAxis, lines: 3, pixels() { return gCharWidth * 3; },
1173 { description: "WM_MOUSEHWHEEL, -120, -3 chars, window is deactive (receive the message directly)",
1174 message: WM_MOUSEHWHEEL, delta: -120,
1175 target: gP1, x: 10, y: 10, window,
1176 modifiers: 0,
1177 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1178 expected: {
1179 axis: kHAxis, lines: -3, pixels() { return gCharWidth * -3; },
1183 // Same for WM_*SCROLL if lParam is not NULL
1184 { description: "WM_VSCROLL, SB_LINEUP, lParam is not NULL, emulation disabled, window is deactive",
1185 message: WM_VSCROLL, delta: SB_LINEUP,
1186 target: gP1, x: 10, y: 10, window,
1187 modifiers: 0,
1188 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1189 expected: {
1190 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
1192 init() {
1193 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
1197 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, window is deactive",
1198 message: WM_VSCROLL, delta: SB_LINEDOWN,
1199 target: gP1, x: 10, y: 10, window,
1200 modifiers: 0,
1201 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1202 expected: {
1203 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1207 { description: "WM_HSCROLL, SB_LINELEFT, lParam is not NULL, emulation disabled, window is deactive",
1208 message: WM_HSCROLL, delta: SB_LINELEFT,
1209 target: gP1, x: 10, y: 10, window,
1210 modifiers: 0,
1211 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1212 expected: {
1213 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
1217 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, window is deactive",
1218 message: WM_HSCROLL, delta: SB_LINERIGHT,
1219 target: gP1, x: 10, y: 10, window,
1220 modifiers: 0,
1221 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
1222 expected: {
1223 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1227 // Same for WM_*SCROLL if lParam is NULL but emulation is enabled
1228 { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation enabled, window is deactive",
1229 message: WM_VSCROLL, delta: SB_LINEUP,
1230 target: gP1, x: 10, y: 10, window,
1231 modifiers: 0,
1232 additionalFlags: 0,
1233 expected: {
1234 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
1236 init() {
1237 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, true);
1241 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation enabled, window is deactive",
1242 message: WM_VSCROLL, delta: SB_LINEDOWN,
1243 target: gP1, x: 10, y: 10, window,
1244 modifiers: 0,
1245 additionalFlags: 0,
1246 expected: {
1247 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1251 { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation enabled, window is deactive",
1252 message: WM_HSCROLL, delta: SB_LINELEFT,
1253 target: gP1, x: 10, y: 10, window,
1254 modifiers: 0,
1255 additionalFlags: 0,
1256 expected: {
1257 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
1261 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation enabled, window is deactive",
1262 message: WM_HSCROLL, delta: SB_LINERIGHT,
1263 target: gP1, x: 10, y: 10, window,
1264 modifiers: 0,
1265 additionalFlags: 0,
1266 expected: {
1267 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1271 // Same for WM_*SCROLL if lParam is not NULL and message sent to the deactive window directly
1272 { description: "WM_VSCROLL, SB_LINEUP, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
1273 message: WM_VSCROLL, delta: SB_LINEUP,
1274 target: gP1, x: 10, y: 10, window,
1275 modifiers: 0,
1276 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
1277 nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1278 expected: {
1279 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
1281 init() {
1282 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
1286 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
1287 message: WM_VSCROLL, delta: SB_LINEDOWN,
1288 target: gP1, x: 10, y: 10, window,
1289 modifiers: 0,
1290 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
1291 nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1292 expected: {
1293 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1297 { description: "WM_HSCROLL, SB_LINELEFT, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
1298 message: WM_HSCROLL, delta: SB_LINELEFT,
1299 target: gP1, x: 10, y: 10, window,
1300 modifiers: 0,
1301 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
1302 nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1303 expected: {
1304 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
1308 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
1309 message: WM_HSCROLL, delta: SB_LINERIGHT,
1310 target: gP1, x: 10, y: 10, window,
1311 modifiers: 0,
1312 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
1313 nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1314 expected: {
1315 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1319 // Same for WM_*SCROLL if lParam is NULL but emulation is enabled, and message sent to the deactive window directly
1320 { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
1321 message: WM_VSCROLL, delta: SB_LINEUP,
1322 target: gP1, x: 10, y: 10, window,
1323 modifiers: 0,
1324 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1325 expected: {
1326 axis: kVAxis, lines: -1, pixels() { return -gLineHeight; },
1328 init() {
1329 SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, true);
1333 { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
1334 message: WM_VSCROLL, delta: SB_LINEDOWN,
1335 target: gP1, x: 10, y: 10, window,
1336 modifiers: 0,
1337 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1338 expected: {
1339 axis: kVAxis, lines: 1, pixels() { return gLineHeight; },
1343 { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
1344 message: WM_HSCROLL, delta: SB_LINELEFT,
1345 target: gP1, x: 10, y: 10, window,
1346 modifiers: 0,
1347 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1348 expected: {
1349 axis: kHAxis, lines: -1, pixels() { return -gCharWidth; },
1353 { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
1354 message: WM_HSCROLL, delta: SB_LINERIGHT,
1355 target: gP1, x: 10, y: 10, window,
1356 modifiers: 0,
1357 additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
1358 expected: {
1359 axis: kHAxis, lines: 1, pixels() { return gCharWidth; },
1362 finish() {
1363 gOtherWindow.close();
1364 gOtherWindow = null;
1365 window.close();
1370 function runDeactiveWindowTests() {
1371 gOtherWindow = window.open("window_mouse_scroll_win_2.html", "_blank",
1372 "chrome,width=100,height=100,top=700,left=700");
1374 window.arguments[0].SimpleTest.waitForFocus(function() {
1375 runNextTest(gDeactiveWindowTests, 0);
1376 }, gOtherWindow);
1379 function runNextTest(aTests, aIndex) {
1380 if (aIndex > 0 && aTests[aIndex - 1] && aTests[aIndex - 1].finish) {
1381 aTests[aIndex - 1].finish();
1384 if (aTests.length == aIndex) {
1385 return;
1388 var test = aTests[aIndex++];
1389 if (test.init) {
1390 test.init();
1392 test.handled = { lines: false, pixels: false };
1394 switch (test.message) {
1395 case WM_MOUSEWHEEL:
1396 case WM_MOUSEHWHEEL:
1397 case WM_VSCROLL:
1398 case WM_HSCROLL:
1399 var expectedLines = test.expected.lines;
1400 var expectedPixels =
1401 cut((typeof test.expected.pixels == "function") ?
1402 test.expected.pixels() : test.expected.pixels);
1403 var handler = function(aEvent) {
1404 var doCommonTests = true;
1406 if (!aEvent) {
1407 ok(!test.handled.lines,
1408 test.description + ", line scroll event has been handled");
1409 ok(!test.handled.pixels,
1410 test.description + ", pixel scroll event has been handled");
1411 doCommonTests = false;
1412 } else if (aEvent.type == kMouseLineScrollEvent) {
1413 ok(!test.handled.lines,
1414 test.description + ":(" + aEvent.type + "), same event has already been handled");
1415 test.handled.lines = true;
1416 isnot(expectedLines, 0,
1417 test.description + ":(" + aEvent.type + "), event shouldn't be fired");
1418 if (test.onLineScrollEvent && test.onLineScrollEvent(aEvent)) {
1419 doCommonTests = false;
1421 } else if (aEvent.type == kMousePixelScrollEvent) {
1422 ok(!test.handled.pixels,
1423 test.description + ":(" + aEvent.type + "), same event has already been handled");
1424 test.handled.pixels = true;
1425 isnot(expectedPixels, 0,
1426 test.description + ":(" + aEvent.type + "), event shouldn't be fired");
1427 if (test.onPixelScrollEvent && test.onPixelScrollEvent(aEvent)) {
1428 doCommonTests = false;
1432 if (doCommonTests) {
1433 var expectedDelta =
1434 (aEvent.type == kMouseLineScrollEvent) ?
1435 expectedLines : expectedPixels;
1436 is(aEvent.target.id, test.target.id,
1437 test.description + ":(" + aEvent.type + "), ID mismatch");
1438 is(aEvent.axis, test.expected.axis,
1439 test.description + ":(" + aEvent.type + "), axis mismatch");
1440 ok(aEvent.detail != 0,
1441 test.description + ":(" + aEvent.type + "), delta must not be 0");
1442 is(aEvent.detail, expectedDelta,
1443 test.description + ":(" + aEvent.type + "), delta mismatch");
1444 is(aEvent.shiftKey, (test.modifiers & (SHIFT_L | SHIFT_R)) != 0,
1445 test.description + ":(" + aEvent.type + "), shiftKey mismatch");
1446 is(aEvent.ctrlKey, (test.modifiers & (CTRL_L | CTRL_R)) != 0,
1447 test.description + ":(" + aEvent.type + "), ctrlKey mismatch");
1448 is(aEvent.altKey, (test.modifiers & (ALT_L | ALT_R)) != 0,
1449 test.description + ":(" + aEvent.type + "), altKey mismatch");
1452 if (!aEvent || (test.handled.lines || expectedLines == 0) &&
1453 (test.handled.pixels || expectedPixels == 0)) {
1454 // Don't scroll actually.
1455 if (aEvent) {
1456 aEvent.preventDefault();
1458 test.target.removeEventListener(kMouseLineScrollEvent, handler, true);
1459 test.target.removeEventListener(kMousePixelScrollEvent, handler, true);
1460 setTimeout(runNextTest, 0, aTests, aIndex);
1464 test.target.addEventListener(kMouseLineScrollEvent, handler, true);
1465 test.target.addEventListener(kMousePixelScrollEvent, handler, true);
1467 if (expectedLines == 0 && expectedPixels == 0) {
1468 // The timeout might not be enough if system is slow by other process,
1469 // so, the test might be passed unexpectedly. However, it must be able
1470 // to be detected by random orange.
1471 setTimeout(handler, 500);
1474 var utils = getWindowUtils(test.window);
1475 var ptInScreen = getPointInScreen(test.target, test.window);
1476 var isVertical =
1477 ((test.message == WM_MOUSEWHEEL) || (test.message == WM_VSCROLL));
1478 var deltaX = !isVertical ? test.delta : 0;
1479 var deltaY = isVertical ? test.delta : 0;
1480 utils.sendNativeMouseScrollEvent(ptInScreen.x + test.x,
1481 ptInScreen.y + test.y,
1482 test.message, deltaX, deltaY, 0,
1483 test.modifiers,
1484 test.additionalFlags,
1485 test.target);
1486 break;
1487 default:
1488 ok(false, test.description + ": invalid message");
1489 // Let's timeout.
1493 function prepareTests() {
1494 // Disable special action with modifier key
1495 SpecialPowers.setIntPref(kAltKeyActionPref, 1);
1496 SpecialPowers.setIntPref(kCtrlKeyActionPref, 1);
1497 SpecialPowers.setIntPref(kShiftKeyActionPref, 1);
1498 SpecialPowers.setIntPref(kWinKeyActionPref, 1);
1500 SpecialPowers.setIntPref(kAltKeyDeltaMultiplierXPref, 100);
1501 SpecialPowers.setIntPref(kAltKeyDeltaMultiplierYPref, 100);
1502 SpecialPowers.setIntPref(kCtrlKeyDeltaMultiplierXPref, 100);
1503 SpecialPowers.setIntPref(kCtrlKeyDeltaMultiplierYPref, 100);
1504 SpecialPowers.setIntPref(kShiftKeyDeltaMultiplierXPref, 100);
1505 SpecialPowers.setIntPref(kShiftKeyDeltaMultiplierYPref, 100);
1506 SpecialPowers.setIntPref(kWinKeyDeltaMultiplierXPref, 100);
1507 SpecialPowers.setIntPref(kWinKeyDeltaMultiplierYPref, 100);
1509 SpecialPowers.setBoolPref(kSystemScrollSpeedOverridePref, false);
1510 SpecialPowers.setIntPref(kTimeoutPref, -1);
1512 runNextTest(gPreparingSteps, 0);
1515 </script>
1516 </body>
1518 </html>