widget/tests/window_mouse_scroll_win.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/tests/window_mouse_scroll_win.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1533 @@
     1.4 +<html lang="en-US"
     1.5 +      style="font-family: Arial; font-size: 10px; line-height: 16px;">
     1.6 +<head>
     1.7 +  <title>Test for mouse scroll handling on Windows</title>
     1.8 +  <script type="text/javascript"
     1.9 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <script type="text/javascript"
    1.11 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    1.12 +  <script type="text/javascript"
    1.13 +          src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css"
    1.15 +          href="chrome://mochikit/content/tests/SimpleTest/test.css" />
    1.16 +</head>
    1.17 +<body onunload="onUnload();">
    1.18 +<div id="display" style="width: 5000px; height: 5000px;">
    1.19 +<p id="p1" style="font-size: 16px; width: 100px; height: 100px;">1st &lt;p&gt;.</p>
    1.20 +<p id="p2" style="font-size: 32px; width: 100px; height: 100px;">2nd &lt;p&gt;.</p>
    1.21 +</div>
    1.22 +<script class="testbody" type="application/javascript">
    1.23 +
    1.24 +window.opener.wrappedJSObject.SimpleTest.waitForFocus(prepareTests, window);
    1.25 +
    1.26 +const nsIDOMWindowUtils = Components.interfaces.nsIDOMWindowUtils;
    1.27 +
    1.28 +const WHEEL_PAGESCROLL = 4294967295;
    1.29 +
    1.30 +const WM_VSCROLL     = 0x0115;
    1.31 +const WM_HSCROLL     = 0x0114;
    1.32 +const WM_MOUSEWHEEL  = 0x020A;
    1.33 +const WM_MOUSEHWHEEL = 0x020E;
    1.34 +
    1.35 +const SB_LINEUP    = 0;
    1.36 +const SB_LINELEFT  = 0;
    1.37 +const SB_LINEDOWN  = 1;
    1.38 +const SB_LINERIGHT = 1;
    1.39 +const SB_PAGEUP    = 2;
    1.40 +const SB_PAGELEFT  = 2;
    1.41 +const SB_PAGEDOWN  = 3;
    1.42 +const SB_PAGERIGHT = 3;
    1.43 +
    1.44 +const SHIFT_L = 0x0100;
    1.45 +const SHIFT_R = 0x0200;
    1.46 +const CTRL_L  = 0x0400;
    1.47 +const CTRL_R  = 0x0800;
    1.48 +const ALT_L   = 0x1000;
    1.49 +const ALT_R   = 0x2000;
    1.50 +
    1.51 +const DOM_PAGE_SCROLL_DELTA = 32768;
    1.52 +
    1.53 +const kSystemScrollSpeedOverridePref = "mousewheel.system_scroll_override_on_root_content.enabled";
    1.54 +
    1.55 +const kAltKeyActionPref         = "mousewheel.with_alt.action";
    1.56 +const kCtrlKeyActionPref        = "mousewheel.with_control.action";
    1.57 +const kShiftKeyActionPref       = "mousewheel.with_shift.action";
    1.58 +const kWinKeyActionPref         = "mousewheel.with_win.action";
    1.59 +
    1.60 +const kAltKeyDeltaMultiplierXPref   = "mousewheel.with_alt.delta_multiplier_x";
    1.61 +const kAltKeyDeltaMultiplierYPref   = "mousewheel.with_alt.delta_multiplier_y";
    1.62 +const kCtrlKeyDeltaMultiplierXPref  = "mousewheel.with_control.delta_multiplier_x";
    1.63 +const kCtrlKeyDeltaMultiplierYPref  = "mousewheel.with_control.delta_multiplier_y";
    1.64 +const kShiftKeyDeltaMultiplierXPref = "mousewheel.with_shift.delta_multiplier_x";
    1.65 +const kShiftKeyDeltaMultiplierYPref = "mousewheel.with_shift.delta_multiplier_y";
    1.66 +const kWinKeyDeltaMultiplierXPref   = "mousewheel.with_win.delta_multiplier_x";
    1.67 +const kWinKeyDeltaMultiplierYPref   = "mousewheel.with_win.delta_multiplier_y";
    1.68 +
    1.69 +const kEmulateWheelByWMSCROLLPref = "mousewheel.emulate_at_wm_scroll";
    1.70 +const kVAmountPref                = "mousewheel.windows.vertical_amount_override";
    1.71 +const kHAmountPref                = "mousewheel.windows.horizontal_amount_override";
    1.72 +const kTimeoutPref                = "mousewheel.windows.transaction.timeout";
    1.73 +
    1.74 +const kMouseLineScrollEvent  = "DOMMouseScroll";
    1.75 +const kMousePixelScrollEvent = "MozMousePixelScroll";
    1.76 +
    1.77 +const kVAxis = Components.interfaces.nsIDOMMouseScrollEvent.VERTICAL_AXIS;
    1.78 +const kHAxis = Components.interfaces.nsIDOMMouseScrollEvent.HORIZONTAL_AXIS;
    1.79 +
    1.80 +var gLineHeight = 0;
    1.81 +var gCharWidth  = 0;
    1.82 +var gPageHeight = 0;
    1.83 +var gPageWidth  = 0;
    1.84 +
    1.85 +var gP1 = document.getElementById("p1");
    1.86 +var gP2 = document.getElementById("p2");
    1.87 +
    1.88 +var gOtherWindow;
    1.89 +
    1.90 +function ok(aCondition, aMessage)
    1.91 +{
    1.92 +  window.opener.wrappedJSObject.SimpleTest.ok(aCondition, aMessage);
    1.93 +}
    1.94 +
    1.95 +function is(aLeft, aRight, aMessage)
    1.96 +{
    1.97 +  window.opener.wrappedJSObject.SimpleTest.is(aLeft, aRight, aMessage);
    1.98 +}
    1.99 +
   1.100 +function isnot(aLeft, aRight, aMessage)
   1.101 +{
   1.102 +  window.opener.wrappedJSObject.SimpleTest.isnot(aLeft, aRight, aMessage);
   1.103 +}
   1.104 +
   1.105 +function todo_is(aLeft, aRight, aMessage)
   1.106 +{
   1.107 +  window.opener.wrappedJSObject.SimpleTest.todo_is(aLeft, aRight, aMessage);
   1.108 +}
   1.109 +
   1.110 +function onUnload()
   1.111 +{
   1.112 +  SpecialPowers.clearUserPref(kAltKeyActionPref);
   1.113 +  SpecialPowers.clearUserPref(kCtrlKeyActionPref);
   1.114 +  SpecialPowers.clearUserPref(kShiftKeyActionPref);
   1.115 +  SpecialPowers.clearUserPref(kWinKeyActionPref);
   1.116 +
   1.117 +  SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierXPref);
   1.118 +  SpecialPowers.clearUserPref(kAltKeyDeltaMultiplierYPref);
   1.119 +  SpecialPowers.clearUserPref(kCtrlKeyDeltaMultiplierXPref);
   1.120 +  SpecialPowers.clearUserPref(kCtrlKeyDeltaMultiplierYPref);
   1.121 +  SpecialPowers.clearUserPref(kShiftKeyDeltaMultiplierXPref);
   1.122 +  SpecialPowers.clearUserPref(kShiftKeyDeltaMultiplierYPref);
   1.123 +  SpecialPowers.clearUserPref(kWinKeyDeltaMultiplierXPref);
   1.124 +  SpecialPowers.clearUserPref(kWinKeyDeltaMultiplierYPref);
   1.125 +
   1.126 +  SpecialPowers.clearUserPref(kSystemScrollSpeedOverridePref);
   1.127 +  SpecialPowers.clearUserPref(kEmulateWheelByWMSCROLLPref);
   1.128 +  SpecialPowers.clearUserPref(kVAmountPref);
   1.129 +  SpecialPowers.clearUserPref(kHAmountPref);
   1.130 +  SpecialPowers.clearUserPref(kTimeoutPref);
   1.131 +  window.opener.wrappedJSObject.SimpleTest.finish();
   1.132 +}
   1.133 +
   1.134 +function getWindowUtils(aWindow)
   1.135 +{
   1.136 +  if (!aWindow) {
   1.137 +    aWindow = window;
   1.138 +  }
   1.139 +  return aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
   1.140 +                .getInterface(nsIDOMWindowUtils);
   1.141 +}
   1.142 +
   1.143 +function getPointInScreen(aElement, aWindow)
   1.144 +{
   1.145 +  if (!aWindow) {
   1.146 +    aWindow = window;
   1.147 +  }
   1.148 +  var bounds = aElement.getBoundingClientRect();
   1.149 +  return { x: bounds.left + aWindow.mozInnerScreenX,
   1.150 +           y: bounds.top + aWindow.mozInnerScreenY };
   1.151 +}
   1.152 +
   1.153 +function cut(aNum)
   1.154 +{
   1.155 +  return (aNum >= 0) ? Math.floor(aNum) : Math.ceil(aNum);
   1.156 +}
   1.157 +
   1.158 +/**
   1.159 + * Make each steps for the tests in following arrays in global scope. Each item
   1.160 + * of the arrays will be executed after previous test is finished.
   1.161 + *
   1.162 + * description:
   1.163 + *   Set the description of the test.  This will be used for the message of is()
   1.164 + *   or the others.
   1.165 + *
   1.166 + * message:
   1.167 + *   aNativeMessage of nsIDOMWindowUtils.sendNativeMouseScrollEvent().
   1.168 + *   Must be WM_MOUSEWHEEL, WM_MOUSEHWHEEL, WM_VSCROLL or WM_HSCROLL.
   1.169 + *
   1.170 + * delta:
   1.171 + *   The native delta value for WM_MOUSEWHEEL or WM_MOUSEHWHEEL.
   1.172 + *   Or one of the SB_* const value for WM_VSCROLL or WM_HSCROLL.
   1.173 + *
   1.174 + * target:
   1.175 + *   The target element, under the mouse cursor.
   1.176 + *
   1.177 + * window:
   1.178 + *   The window which is used for getting nsIDOMWindowUtils.
   1.179 + *
   1.180 + * modifiers:
   1.181 + *   Pressed modifier keys, 0 means no modifier key is pressed.
   1.182 + *   Otherwise, one or more values of SHIFT_L, SHIFT_R, CTRL_L, CTRL_R,
   1.183 + *   ALT_L or ALT_R.
   1.184 + *
   1.185 + * additionalFlags:
   1.186 + *   aAdditionalFlags of nsIDOMWindowUtils.sendNativeMouseScrollEvent().
   1.187 + *   See the document of nsIDOMWindowUtils for the detail of the values.
   1.188 + *
   1.189 + * onLineScrollEvent:
   1.190 + *   Must be a function or null.
   1.191 + *   If the value is a function, it will be called when DOMMouseScroll event
   1.192 + *   is received by the synthesized event.
   1.193 + *   If return true, the common checks are canceled.
   1.194 + *
   1.195 + * onPixelScrollEvent:
   1.196 + *   Must be a function or null.
   1.197 + *   If the value is a function, it will be called when MozMousePixelScroll
   1.198 + *   event is received by the synthesized event.
   1.199 + *   If return true, the common checks are canceled.
   1.200 + *
   1.201 + * expected:
   1.202 + *   Must not be null and this must have:
   1.203 + *     axis:
   1.204 + *       kVAxis if the synthesized event causes vertical scroll. Otherwise,
   1.205 + *       it causes horizontal scroll, kHAxis.
   1.206 + *     lines:
   1.207 + *       Integer value which is expected detail attribute value of
   1.208 + *       DOMMouseScroll.  If the event shouldn't be fired, must be 0.
   1.209 + *     pixels:
   1.210 + *       Integer value or a function which returns double value.  The value is
   1.211 + *       expected detail attribute value of MozMousePixelScroll.
   1.212 + *       If the event shouldn't be fired, must be 0.
   1.213 + *
   1.214 + *   Note that if both lines and pixels are 0, the test framework waits
   1.215 + *   a few seconds. After that, go to next test.
   1.216 + *
   1.217 + * init:
   1.218 + *   Must be a function or null.  If this value is a function, it's called
   1.219 + *   before synthesizing the native event.
   1.220 + *
   1.221 + * finish:
   1.222 + *   Must be a function or null.  If this value is a function, it's called
   1.223 + *   after received all expected events or timeout if no events are expected.
   1.224 + */
   1.225 +
   1.226 +// First, get the computed line height, char width, page height and page width.
   1.227 +var gPreparingSteps = [
   1.228 +  { description: "Preparing gLineHeight",
   1.229 +    message: WM_MOUSEWHEEL, delta: -120,
   1.230 +    target: gP1, x: 10, y: 10, window: window,
   1.231 +    modifiers: 0,
   1.232 +    additionalFlags: 0,
   1.233 +    onLineScrollEvent: function (aEvent) {
   1.234 +      return true;
   1.235 +    },
   1.236 +    onPixelScrollEvent: function (aEvent) {
   1.237 +      gLineHeight = aEvent.detail;
   1.238 +      return true;
   1.239 +    },
   1.240 +    expected: {
   1.241 +      axis: kVAxis, lines: 1, pixels: 1,
   1.242 +    },
   1.243 +    init: function () {
   1.244 +      SpecialPowers.setIntPref(kVAmountPref, 1);
   1.245 +      SpecialPowers.setIntPref(kHAmountPref, 1);
   1.246 +    },
   1.247 +  },
   1.248 +  { description: "Preparing gCharWidth",
   1.249 +    message: WM_MOUSEHWHEEL, delta: 120,
   1.250 +    target: gP1, x: 10, y: 10, window: window,
   1.251 +    modifiers: 0,
   1.252 +    additionalFlags: 0,
   1.253 +    onLineScrollEvent: function (aEvent) {
   1.254 +      return true;
   1.255 +    },
   1.256 +    onPixelScrollEvent: function (aEvent) {
   1.257 +      gCharWidth = aEvent.detail;
   1.258 +      return true;
   1.259 +    },
   1.260 +    expected: {
   1.261 +      axis: kVAxis, lines: 1, pixels: 1,
   1.262 +    },
   1.263 +  },
   1.264 +  { description: "Preparing gPageHeight",
   1.265 +    message: WM_MOUSEWHEEL, delta: -120,
   1.266 +    target: gP1, x: 10, y: 10, window: window,
   1.267 +    modifiers: 0,
   1.268 +    additionalFlags: 0,
   1.269 +    onLineScrollEvent: function (aEvent) {
   1.270 +      return true;
   1.271 +    },
   1.272 +    onPixelScrollEvent: function (aEvent) {
   1.273 +      gPageHeight = aEvent.detail;
   1.274 +      return true;
   1.275 +    },
   1.276 +    expected: {
   1.277 +      axis: kHAxis, lines: 1, pixels: 1,
   1.278 +    },
   1.279 +    init: function () {
   1.280 +      SpecialPowers.setIntPref(kVAmountPref, 0xFFFF);
   1.281 +      SpecialPowers.setIntPref(kHAmountPref, 0xFFFF);
   1.282 +    },
   1.283 +  },
   1.284 +  { description: "Preparing gPageWidth",
   1.285 +    message: WM_MOUSEHWHEEL, delta: 120,
   1.286 +    target: gP1, x: 10, y: 10, window: window,
   1.287 +    modifiers: 0,
   1.288 +    additionalFlags: 0,
   1.289 +    onLineScrollEvent: function (aEvent) {
   1.290 +      return true;
   1.291 +    },
   1.292 +    onPixelScrollEvent: function (aEvent) {
   1.293 +      gPageWidth = aEvent.detail;
   1.294 +      return true;
   1.295 +    },
   1.296 +    expected: {
   1.297 +      axis: kHAxis, lines: 1, pixels: 1,
   1.298 +    },
   1.299 +    finish: function () {
   1.300 +      ok(gLineHeight > 0, "gLineHeight isn't positive got " + gLineHeight);
   1.301 +      ok(gCharWidth > 0, "gCharWidth isn't positive got " + gCharWidth);
   1.302 +      ok(gPageHeight > 0, "gPageHeight isn't positive got " + gPageHeight);
   1.303 +      ok(gPageWidth > 0, "gPageWidth isn't positive got " + gPageWidth);
   1.304 +
   1.305 +      ok(gPageHeight > gLineHeight,
   1.306 +         "gPageHeight must be larger than gLineHeight");
   1.307 +      ok(gPageWidth > gCharWidth,
   1.308 +         "gPageWidth must be larger than gCharWidth");
   1.309 +      runNextTest(gBasicTests, 0)
   1.310 +    }
   1.311 +  },
   1.312 +];
   1.313 +
   1.314 +var gBasicTests = [
   1.315 +  // Widget shouldn't dispatch a pixel event if the delta can be devided by
   1.316 +  // lines to be scrolled.  However, pixel events should be fired by ESM.
   1.317 +  { description: "WM_MOUSEWHEEL, -120, 3 lines",
   1.318 +    message: WM_MOUSEWHEEL, delta: -120,
   1.319 +    target: gP1, x: 10, y: 10, window: window,
   1.320 +    modifiers: 0,
   1.321 +    additionalFlags: 0,
   1.322 +    expected: {
   1.323 +      axis: kVAxis, lines: 3, pixels: function () { return gLineHeight * 3; },
   1.324 +    },
   1.325 +    init: function () {
   1.326 +      SpecialPowers.setIntPref(kVAmountPref, 3);
   1.327 +      SpecialPowers.setIntPref(kHAmountPref, 3);
   1.328 +    },
   1.329 +  },
   1.330 +
   1.331 +  { description: "WM_MOUSEWHEEL, 120, -3 lines",
   1.332 +    message: WM_MOUSEWHEEL, delta: 120,
   1.333 +    target: gP1, x: 10, y: 10, window: window,
   1.334 +    modifiers: 0,
   1.335 +    additionalFlags: 0,
   1.336 +    expected: {
   1.337 +      axis: kVAxis, lines: -3, pixels: function () { return gLineHeight * -3; },
   1.338 +    },
   1.339 +  },
   1.340 +
   1.341 +  { description: "WM_MOUSEHWHEEL, 120, 3 chars",
   1.342 +    message: WM_MOUSEHWHEEL, delta: 120,
   1.343 +    target: gP1, x: 10, y: 10, window: window,
   1.344 +    modifiers: 0,
   1.345 +    additionalFlags: 0,
   1.346 +    expected: {
   1.347 +      axis: kHAxis, lines: 3, pixels: function () { return gCharWidth * 3; },
   1.348 +    },
   1.349 +  },
   1.350 +
   1.351 +  { description: "WM_MOUSEHWHEEL, -120, -3 chars",
   1.352 +    message: WM_MOUSEHWHEEL, delta: -120,
   1.353 +    target: gP1, x: 10, y: 10, window: window,
   1.354 +    modifiers: 0,
   1.355 +    additionalFlags: 0,
   1.356 +    expected: {
   1.357 +      axis: kHAxis, lines: -3, pixels: function () { return gCharWidth * -3; },
   1.358 +    },
   1.359 +  },
   1.360 +
   1.361 +  // Pixel scroll event should be fired always but line scroll event should be
   1.362 +  // fired only when accumulated delta value is over a line.
   1.363 +  { description: "WM_MOUSEWHEEL, -20, 0.5 lines",
   1.364 +    message: WM_MOUSEWHEEL, delta: -20,
   1.365 +    target: gP1, x: 10, y: 10, window: window,
   1.366 +    modifiers: 0,
   1.367 +    additionalFlags: 0,
   1.368 +    expected: {
   1.369 +      axis: kVAxis, lines: 0, pixels: function () { return gLineHeight / 2; },
   1.370 +    },
   1.371 +  },
   1.372 +  { description: "WM_MOUSEWHEEL, -20, 0.5 lines (pending: 0.5 lines)",
   1.373 +    message: WM_MOUSEWHEEL, delta: -20,
   1.374 +    target: gP1, x: 10, y: 10, window: window,
   1.375 +    modifiers: 0,
   1.376 +    additionalFlags: 0,
   1.377 +    expected: {
   1.378 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight / 2; },
   1.379 +    },
   1.380 +  },
   1.381 +  { description: "WM_MOUSEWHEEL, -20, 0.5 lines",
   1.382 +    message: WM_MOUSEWHEEL, delta: -20,
   1.383 +    target: gP1, x: 10, y: 10, window: window,
   1.384 +    modifiers: 0,
   1.385 +    additionalFlags: 0,
   1.386 +    expected: {
   1.387 +      axis: kVAxis, lines: 0, pixels: function () { return gLineHeight / 2; },
   1.388 +    },
   1.389 +  },
   1.390 +
   1.391 +  { description: "WM_MOUSEWHEEL, 20, -0.5 lines (pending: 0.5 lines)",
   1.392 +    message: WM_MOUSEWHEEL, delta: 20,
   1.393 +    target: gP1, x: 10, y: 10, window: window,
   1.394 +    modifiers: 0,
   1.395 +    additionalFlags: 0,
   1.396 +    expected: {
   1.397 +      axis: kVAxis, lines: 0, pixels: function () { return gLineHeight / -2; },
   1.398 +    },
   1.399 +  },
   1.400 +  { description: "WM_MOUSEWHEEL, 20, -0.5 lines (pending: -0.5 lines)",
   1.401 +    message: WM_MOUSEWHEEL, delta: 20,
   1.402 +    target: gP1, x: 10, y: 10, window: window,
   1.403 +    modifiers: 0,
   1.404 +    additionalFlags: 0,
   1.405 +    expected: {
   1.406 +      axis: kVAxis, lines: -1, pixels: function () { return -gLineHeight / 2; },
   1.407 +    },
   1.408 +  },
   1.409 +  { description: "WM_MOUSEWHEEL, 20, -0.5 lines",
   1.410 +    message: WM_MOUSEWHEEL, delta: 20,
   1.411 +    target: gP1, x: 10, y: 10, window: window,
   1.412 +    modifiers: 0,
   1.413 +    additionalFlags: 0,
   1.414 +    expected: {
   1.415 +      axis: kVAxis, lines: 0, pixels: function () { return gLineHeight / -2; },
   1.416 +    },
   1.417 +  },
   1.418 +
   1.419 +  { description: "WM_MOUSEHWHEEL, 20, 0.5 chars",
   1.420 +    message: WM_MOUSEHWHEEL, delta: 20,
   1.421 +    target: gP1, x: 10, y: 10, window: window,
   1.422 +    modifiers: 0,
   1.423 +    additionalFlags: 0,
   1.424 +    expected: {
   1.425 +      axis: kHAxis, lines: 0, pixels: function () { return gCharWidth / 2; },
   1.426 +    },
   1.427 +  },
   1.428 +  { description: "WM_MOUSEHWHEEL, 20, 0.5 chars (pending: 0.5 chars)",
   1.429 +    message: WM_MOUSEHWHEEL, delta: 20,
   1.430 +    target: gP1, x: 10, y: 10, window: window,
   1.431 +    modifiers: 0,
   1.432 +    additionalFlags: 0,
   1.433 +    expected: {
   1.434 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth / 2; },
   1.435 +    },
   1.436 +  },
   1.437 +  { description: "WM_MOUSEHWHEEL, 20, 0.5 chars",
   1.438 +    message: WM_MOUSEHWHEEL, delta: 20,
   1.439 +    target: gP1, x: 10, y: 10, window: window,
   1.440 +    modifiers: 0,
   1.441 +    additionalFlags: 0,
   1.442 +    expected: {
   1.443 +      axis: kHAxis, lines: 0, pixels: function () { return gCharWidth / 2; },
   1.444 +    },
   1.445 +  },
   1.446 +
   1.447 +  { description: "WM_MOUSEHWHEEL, -20, -0.5 chars (pending: 0.5 chars)",
   1.448 +    message: WM_MOUSEHWHEEL, delta: -20,
   1.449 +    target: gP1, x: 10, y: 10, window: window,
   1.450 +    modifiers: 0,
   1.451 +    additionalFlags: 0,
   1.452 +    expected: {
   1.453 +      axis: kHAxis, lines: 0, pixels: function () { return gCharWidth / -2; },
   1.454 +    },
   1.455 +  },
   1.456 +  { description: "WM_MOUSEHWHEEL, -20, -0.5 chars (pending: -0.5 chars)",
   1.457 +    message: WM_MOUSEHWHEEL, delta: -20,
   1.458 +    target: gP1, x: 10, y: 10, window: window,
   1.459 +    modifiers: 0,
   1.460 +    additionalFlags: 0,
   1.461 +    expected: {
   1.462 +      axis: kHAxis, lines: -1, pixels: function () { return -gCharWidth / 2; },
   1.463 +    },
   1.464 +  },
   1.465 +  { description: "WM_MOUSEHWHEEL, -20, -0.5 chars",
   1.466 +    message: WM_MOUSEHWHEEL, delta: -20,
   1.467 +    target: gP1, x: 10, y: 10, window: window,
   1.468 +    modifiers: 0,
   1.469 +    additionalFlags: 0,
   1.470 +    expected: {
   1.471 +      axis: kHAxis, lines: 0, pixels: function () { return gCharWidth / -2; },
   1.472 +    },
   1.473 +  },
   1.474 +
   1.475 +  // Even if the mouse cursor is an element whose font-size is different than
   1.476 +  // the scrollable element, the pixel scroll amount shouldn't be changed.
   1.477 +  // Widget shouldn't dispatch a pixel event if the delta can be devided by
   1.478 +  // lines to be scrolled.  However, pixel events should be fired by ESM.
   1.479 +  { description: "WM_MOUSEWHEEL, -120, 3 lines, on the other div whose font-size is larger",
   1.480 +    message: WM_MOUSEWHEEL, delta: -120,
   1.481 +    target: gP2, x: 10, y: 10, window: window,
   1.482 +    modifiers: 0,
   1.483 +    additionalFlags: 0,
   1.484 +    expected: {
   1.485 +      axis: kVAxis, lines: 3, pixels: function () { return gLineHeight * 3; },
   1.486 +    },
   1.487 +  },
   1.488 +
   1.489 +  { description: "WM_MOUSEWHEEL, 120, -3 lines, on the other div whose font-size is larger",
   1.490 +    message: WM_MOUSEWHEEL, delta: 120,
   1.491 +    target: gP2, x: 10, y: 10, window: window,
   1.492 +    modifiers: 0,
   1.493 +    additionalFlags: 0,
   1.494 +    expected: {
   1.495 +      axis: kVAxis, lines: -3, pixels: function () { return gLineHeight * -3; },
   1.496 +    },
   1.497 +  },
   1.498 +
   1.499 +  { description: "WM_MOUSEHWHEEL, 120, 3 chars, on the other div whose font-size is larger",
   1.500 +    message: WM_MOUSEHWHEEL, delta: 120,
   1.501 +    target: gP2, x: 10, y: 10, window: window,
   1.502 +    modifiers: 0,
   1.503 +    additionalFlags: 0,
   1.504 +    expected: {
   1.505 +      axis: kHAxis, lines: 3, pixels: function () { return gCharWidth * 3; },
   1.506 +    },
   1.507 +  },
   1.508 +
   1.509 +  { description: "WM_MOUSEHWHEEL, -120, -3 chars, on the other div whose font-size is larger",
   1.510 +    message: WM_MOUSEHWHEEL, delta: -120,
   1.511 +    target: gP2, x: 10, y: 10, window: window,
   1.512 +    modifiers: 0,
   1.513 +    additionalFlags: 0,
   1.514 +    expected: {
   1.515 +      axis: kHAxis, lines: -3, pixels: function () { return gCharWidth * -3; },
   1.516 +    },
   1.517 +  },
   1.518 +
   1.519 +  // Modifier key tests
   1.520 +  { description: "WM_MOUSEWHEEL, -40, 1 line with left Shift",
   1.521 +    message: WM_MOUSEWHEEL, delta: -40,
   1.522 +    target: gP1, x: 10, y: 10, window: window,
   1.523 +    modifiers: SHIFT_L,
   1.524 +    additionalFlags: 0,
   1.525 +    expected: {
   1.526 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
   1.527 +    },
   1.528 +  },
   1.529 +  { description: "WM_MOUSEWHEEL, -40, 1 line with right Shift",
   1.530 +    message: WM_MOUSEWHEEL, delta: -40,
   1.531 +    target: gP1, x: 10, y: 10, window: window,
   1.532 +    modifiers: SHIFT_R,
   1.533 +    additionalFlags: 0,
   1.534 +    expected: {
   1.535 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
   1.536 +    },
   1.537 +  },
   1.538 +  { description: "WM_MOUSEWHEEL, -40, 1 line with left Ctrl",
   1.539 +    message: WM_MOUSEWHEEL, delta: -40,
   1.540 +    target: gP1, x: 10, y: 10, window: window,
   1.541 +    modifiers: CTRL_L,
   1.542 +    additionalFlags: 0,
   1.543 +    expected: {
   1.544 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
   1.545 +    },
   1.546 +  },
   1.547 +  { description: "WM_MOUSEWHEEL, -40, 1 line with right Ctrl",
   1.548 +    message: WM_MOUSEWHEEL, delta: -40,
   1.549 +    target: gP1, x: 10, y: 10, window: window,
   1.550 +    modifiers: CTRL_R,
   1.551 +    additionalFlags: 0,
   1.552 +    expected: {
   1.553 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
   1.554 +    },
   1.555 +  },
   1.556 +  { description: "WM_MOUSEWHEEL, -40, 1 line with left Alt",
   1.557 +    message: WM_MOUSEWHEEL, delta: -40,
   1.558 +    target: gP1, x: 10, y: 10, window: window,
   1.559 +    modifiers: ALT_L,
   1.560 +    additionalFlags: 0,
   1.561 +    expected: {
   1.562 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
   1.563 +    },
   1.564 +  },
   1.565 +  { description: "WM_MOUSEWHEEL, -40, 1 line with right Alt",
   1.566 +    message: WM_MOUSEWHEEL, delta: -40,
   1.567 +    target: gP1, x: 10, y: 10, window: window,
   1.568 +    modifiers: ALT_R,
   1.569 +    additionalFlags: 0,
   1.570 +    expected: {
   1.571 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
   1.572 +    },
   1.573 +  },
   1.574 +
   1.575 +  { description: "WM_MOUSEHWHEEL, 40, 1 character with left Shift",
   1.576 +    message: WM_MOUSEHWHEEL, delta: 40,
   1.577 +    target: gP1, x: 10, y: 10, window: window,
   1.578 +    modifiers: SHIFT_L,
   1.579 +    additionalFlags: 0,
   1.580 +    expected: {
   1.581 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
   1.582 +    },
   1.583 +  },
   1.584 +  { description: "WM_MOUSEHWHEEL, 40, 1 character with right Shift",
   1.585 +    message: WM_MOUSEHWHEEL, delta: 40,
   1.586 +    target: gP1, x: 10, y: 10, window: window,
   1.587 +    modifiers: SHIFT_R,
   1.588 +    additionalFlags: 0,
   1.589 +    expected: {
   1.590 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
   1.591 +    },
   1.592 +  },
   1.593 +  { description: "WM_MOUSEHWHEEL, 40, 1 character with left Ctrl",
   1.594 +    message: WM_MOUSEHWHEEL, delta: 40,
   1.595 +    target: gP1, x: 10, y: 10, window: window,
   1.596 +    modifiers: CTRL_L,
   1.597 +    additionalFlags: 0,
   1.598 +    expected: {
   1.599 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
   1.600 +    },
   1.601 +  },
   1.602 +  { description: "WM_MOUSEHWHEEL, 40, 1 character with right Ctrl",
   1.603 +    message: WM_MOUSEHWHEEL, delta: 40,
   1.604 +    target: gP1, x: 10, y: 10, window: window,
   1.605 +    modifiers: CTRL_R,
   1.606 +    additionalFlags: 0,
   1.607 +    expected: {
   1.608 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
   1.609 +    },
   1.610 +  },
   1.611 +  { description: "WM_MOUSEHWHEEL, 40, 1 character with left Alt",
   1.612 +    message: WM_MOUSEHWHEEL, delta: 40,
   1.613 +    target: gP1, x: 10, y: 10, window: window,
   1.614 +    modifiers: ALT_L,
   1.615 +    additionalFlags: 0,
   1.616 +    expected: {
   1.617 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
   1.618 +    },
   1.619 +  },
   1.620 +  { description: "WM_MOUSEHWHEEL, 40, 1 character with right Alt",
   1.621 +    message: WM_MOUSEHWHEEL, delta: 40,
   1.622 +    target: gP1, x: 10, y: 10, window: window,
   1.623 +    modifiers: ALT_R,
   1.624 +    additionalFlags: 0,
   1.625 +    expected: {
   1.626 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
   1.627 +    },
   1.628 +
   1.629 +    finish: function () {
   1.630 +      runNextTest(gScrollMessageTests, 0);
   1.631 +    }
   1.632 +  },
   1.633 +];
   1.634 +
   1.635 +var gPageScrllTests = [
   1.636 +  // Pixel scroll event should be fired always but line scroll event should be
   1.637 +  // fired only when accumulated delta value is over a line.
   1.638 +  { description: "WM_MOUSEWHEEL, -60, 0.5 pages",
   1.639 +    message: WM_MOUSEWHEEL, delta: -60,
   1.640 +    target: gP1, x: 10, y: 10, window: window,
   1.641 +    modifiers: 0,
   1.642 +    additionalFlags: 0,
   1.643 +    expected: {
   1.644 +      axis: kVAxis, lines: 0, pixels: function () { return gPageHeight / 2; },
   1.645 +    },
   1.646 +  },
   1.647 +  { description: "WM_MOUSEWHEEL, -60, 0.5 pages (pending: 0.5 pages)",
   1.648 +    message: WM_MOUSEWHEEL, delta: -60,
   1.649 +    target: gP1, x: 10, y: 10, window: window,
   1.650 +    modifiers: 0,
   1.651 +    additionalFlags: 0,
   1.652 +    expected: {
   1.653 +      axis: kVAxis, lines: DOM_PAGE_SCROLL_DELTA,
   1.654 +      pixels: function () { return ((gPageHeight / 2) + (gPageHeight % 2)); },
   1.655 +    },
   1.656 +  },
   1.657 +  { description: "WM_MOUSEWHEEL, -60, 0.5 pages",
   1.658 +    message: WM_MOUSEWHEEL, delta: -60,
   1.659 +    target: gP1, x: 10, y: 10, window: window,
   1.660 +    modifiers: 0,
   1.661 +    additionalFlags: 0,
   1.662 +    expected: {
   1.663 +      axis: kVAxis, lines: 0, pixels: function () { return gPageHeight / 2; },
   1.664 +    },
   1.665 +  },
   1.666 +
   1.667 +  { description: "WM_MOUSEWHEEL, 60, -0.5 pages (pending: 0.5 pages)",
   1.668 +    message: WM_MOUSEWHEEL, delta: 60,
   1.669 +    target: gP1, x: 10, y: 10, window: window,
   1.670 +    modifiers: 0,
   1.671 +    additionalFlags: 0,
   1.672 +    expected: {
   1.673 +      axis: kVAxis, lines: 0, pixels: function () { return gPageHeight / -2; },
   1.674 +    },
   1.675 +  },
   1.676 +  { description: "WM_MOUSEWHEEL, 60, -0.5 pages (pending: -0.5 pages)",
   1.677 +    message: WM_MOUSEWHEEL, delta: 60,
   1.678 +    target: gP1, x: 10, y: 10, window: window,
   1.679 +    modifiers: 0,
   1.680 +    additionalFlags: 0,
   1.681 +    expected: {
   1.682 +      axis: kVAxis, lines: -DOM_PAGE_SCROLL_DELTA,
   1.683 +      pixels: function () { return -((gPageHeight / 2) + (gPageHeight % 2)); },
   1.684 +    },
   1.685 +  },
   1.686 +  { description: "WM_MOUSEWHEEL, 60, -0.5 pages",
   1.687 +    message: WM_MOUSEWHEEL, delta: 60,
   1.688 +    target: gP1, x: 10, y: 10, window: window,
   1.689 +    modifiers: 0,
   1.690 +    additionalFlags: 0,
   1.691 +    expected: {
   1.692 +      axis: kVAxis, lines: 0, pixels: function () { return gPageHeight / -2; },
   1.693 +    },
   1.694 +  },
   1.695 +
   1.696 +  { description: "WM_MOUSEHWHEEL, 60, 0.5 pages",
   1.697 +    message: WM_MOUSEHWHEEL, delta: 60,
   1.698 +    target: gP1, x: 10, y: 10, window: window,
   1.699 +    modifiers: 0,
   1.700 +    additionalFlags: 0,
   1.701 +    expected: {
   1.702 +      axis: kHAxis, lines: 0, pixels: function () { return gPageWidth / 2; },
   1.703 +    },
   1.704 +  },
   1.705 +  { description: "WM_MOUSEHWHEEL, 60, 0.5 pages (pending: 0.5 pages)",
   1.706 +    message: WM_MOUSEHWHEEL, delta: 60,
   1.707 +    target: gP1, x: 10, y: 10, window: window,
   1.708 +    modifiers: 0,
   1.709 +    additionalFlags: 0,
   1.710 +    expected: {
   1.711 +      axis: kHAxis, lines: DOM_PAGE_SCROLL_DELTA,
   1.712 +      pixels: function () { return ((gPageWidth / 2) + (gPageWidth % 2)); },
   1.713 +    },
   1.714 +  },
   1.715 +  { description: "WM_MOUSEHWHEEL, 60, 0.5 pages",
   1.716 +    message: WM_MOUSEHWHEEL, delta: 60,
   1.717 +    target: gP1, x: 10, y: 10, window: window,
   1.718 +    modifiers: 0,
   1.719 +    additionalFlags: 0,
   1.720 +    expected: {
   1.721 +      axis: kHAxis, lines: 0, pixels: function () { return gPageWidth / 2; },
   1.722 +    },
   1.723 +  },
   1.724 +
   1.725 +  { description: "WM_MOUSEHWHEEL, -60, -0.5 pages (pending: 0.5 pages)",
   1.726 +    message: WM_MOUSEHWHEEL, delta: -60,
   1.727 +    target: gP1, x: 10, y: 10, window: window,
   1.728 +    modifiers: 0,
   1.729 +    additionalFlags: 0,
   1.730 +    expected: {
   1.731 +      axis: kHAxis, lines: 0, pixels: function () { return gCharWidth / -2; },
   1.732 +    },
   1.733 +  },
   1.734 +  { description: "WM_MOUSEHWHEEL, -60, -0.5 pages (pending: -0.5 pages)",
   1.735 +    message: WM_MOUSEHWHEEL, delta: -60,
   1.736 +    target: gP1, x: 10, y: 10, window: window,
   1.737 +    modifiers: 0,
   1.738 +    additionalFlags: 0,
   1.739 +    expected: {
   1.740 +      axis: kHAxis, lines: -DOM_PAGE_SCROLL_DELTA,
   1.741 +      pixels: function () { return -((gCharWidth / 2) + (gCharWidth % 2)); },
   1.742 +    },
   1.743 +  },
   1.744 +  { description: "WM_MOUSEHWHEEL, -60, -0.5 pages",
   1.745 +    message: WM_MOUSEHWHEEL, delta: -60,
   1.746 +    target: gP1, x: 10, y: 10, window: window,
   1.747 +    modifiers: 0,
   1.748 +    additionalFlags: 0,
   1.749 +    expected: {
   1.750 +      axis: kHAxis, lines: 0, pixels: function () { return gCharWidth / -2; },
   1.751 +    },
   1.752 +  },
   1.753 +];
   1.754 +
   1.755 +var gScrollMessageTests = [
   1.756 +  // Widget should dispatch neither line scroll event nor pixel scroll event if
   1.757 +  // the WM_*SCROLL's lParam is NULL and mouse wheel emulation is disabled.
   1.758 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation disabled",
   1.759 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
   1.760 +    target: gP1, x: 10, y: 10, window: window,
   1.761 +    modifiers: 0,
   1.762 +    additionalFlags: 0,
   1.763 +    expected: {
   1.764 +      axis: kVAxis, lines: 0, pixels: 0,
   1.765 +    },
   1.766 +    init: function () {
   1.767 +      SpecialPowers.setIntPref(kVAmountPref, 3);
   1.768 +      SpecialPowers.setIntPref(kHAmountPref, 3);
   1.769 +      SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
   1.770 +    },
   1.771 +  },
   1.772 +
   1.773 +  { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation disabled",
   1.774 +    message: WM_VSCROLL, delta: SB_LINEUP,
   1.775 +    target: gP1, x: 10, y: 10, window: window,
   1.776 +    modifiers: 0,
   1.777 +    additionalFlags: 0,
   1.778 +    expected: {
   1.779 +      axis: kVAxis, lines: 0, pixels: 0,
   1.780 +    },
   1.781 +  },
   1.782 +
   1.783 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation disabled",
   1.784 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
   1.785 +    target: gP1, x: 10, y: 10, window: window,
   1.786 +    modifiers: 0,
   1.787 +    additionalFlags: 0,
   1.788 +    expected: {
   1.789 +      axis: kHAxis, lines: 0, pixels: 0,
   1.790 +    },
   1.791 +  },
   1.792 +
   1.793 +  { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation disabled",
   1.794 +    message: WM_HSCROLL, delta: SB_LINELEFT,
   1.795 +    target: gP1, x: 10, y: 10, window: window,
   1.796 +    modifiers: 0,
   1.797 +    additionalFlags: 0,
   1.798 +    expected: {
   1.799 +      axis: kHAxis, lines: 0, pixels: 0,
   1.800 +    },
   1.801 +  },
   1.802 +
   1.803 +  // Widget should emulate mouse wheel behavior for WM_*SCROLL even if the
   1.804 +  // kEmulateWheelByWMSCROLLPref is disabled but the message's lParam is not
   1.805 +  // NULL. Then, widget doesn't dispatch a pixel event for WM_*SCROLL messages,
   1.806 +  // but ESM dispatches it instead.
   1.807 +  { description: "WM_VSCROLL, SB_LINEUP, lParam is not NULL, emulation disabled",
   1.808 +    message: WM_VSCROLL, delta: SB_LINEUP,
   1.809 +    target: gP1, x: 10, y: 10, window: window,
   1.810 +    modifiers: 0,
   1.811 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
   1.812 +    expected: {
   1.813 +      axis: kVAxis, lines: -1, pixels: function () { return -gLineHeight; },
   1.814 +    },
   1.815 +    init: function () {
   1.816 +      SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
   1.817 +    },
   1.818 +  },
   1.819 +
   1.820 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled",
   1.821 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
   1.822 +    target: gP1, x: 10, y: 10, window: window,
   1.823 +    modifiers: 0,
   1.824 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
   1.825 +    expected: {
   1.826 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
   1.827 +    },
   1.828 +  },
   1.829 +
   1.830 +  { description: "WM_HSCROLL, SB_LINELEFT, lParam is not NULL, emulation disabled",
   1.831 +    message: WM_HSCROLL, delta: SB_LINELEFT,
   1.832 +    target: gP1, x: 10, y: 10, window: window,
   1.833 +    modifiers: 0,
   1.834 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
   1.835 +    expected: {
   1.836 +      axis: kHAxis, lines: -1, pixels: function () { return -gCharWidth; },
   1.837 +    },
   1.838 +  },
   1.839 +
   1.840 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled",
   1.841 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
   1.842 +    target: gP1, x: 10, y: 10, window: window,
   1.843 +    modifiers: 0,
   1.844 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
   1.845 +    expected: {
   1.846 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
   1.847 +    },
   1.848 +  },
   1.849 +
   1.850 +  { description: "WM_VSCROLL, SB_PAGEUP, lParam is not NULL, emulation disabled",
   1.851 +    message: WM_VSCROLL, delta: SB_PAGEUP,
   1.852 +    target: gP1, x: 10, y: 10, window: window,
   1.853 +    modifiers: 0,
   1.854 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
   1.855 +    expected: {
   1.856 +      axis: kVAxis, lines: -DOM_PAGE_SCROLL_DELTA,
   1.857 +      pixels: function () { return -gPageHeight; },
   1.858 +    },
   1.859 +  },
   1.860 +
   1.861 +  { description: "WM_VSCROLL, SB_PAGEDOWN, lParam is not NULL, emulation disabled",
   1.862 +    message: WM_VSCROLL, delta: SB_PAGEDOWN,
   1.863 +    target: gP1, x: 10, y: 10, window: window,
   1.864 +    modifiers: 0,
   1.865 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
   1.866 +    expected: {
   1.867 +      axis: kVAxis, lines: DOM_PAGE_SCROLL_DELTA,
   1.868 +      pixels: function () { return gPageHeight; },
   1.869 +    },
   1.870 +  },
   1.871 +
   1.872 +  { description: "WM_HSCROLL, SB_PAGELEFT, lParam is not NULL, emulation disabled",
   1.873 +    message: WM_HSCROLL, delta: SB_PAGELEFT,
   1.874 +    target: gP1, x: 10, y: 10, window: window,
   1.875 +    modifiers: 0,
   1.876 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
   1.877 +    expected: {
   1.878 +      axis: kHAxis, lines: -DOM_PAGE_SCROLL_DELTA,
   1.879 +      pixels: function () { return -gPageWidth; },
   1.880 +    },
   1.881 +  },
   1.882 +
   1.883 +  { description: "WM_HSCROLL, SB_PAGERIGHT, lParam is not NULL, emulation disabled",
   1.884 +    message: WM_HSCROLL, delta: SB_PAGERIGHT,
   1.885 +    target: gP1, x: 10, y: 10, window: window,
   1.886 +    modifiers: 0,
   1.887 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
   1.888 +    expected: {
   1.889 +      axis: kHAxis, lines: DOM_PAGE_SCROLL_DELTA,
   1.890 +      pixels: function () { return gPageWidth; },
   1.891 +    },
   1.892 +  },
   1.893 +
   1.894 +  // Widget should emulate mouse wheel behavior for WM_*SCROLL when the
   1.895 +  // kEmulateWheelByWMSCROLLPref is enabled even if the message's lParam is
   1.896 +  // NULL. Then, widget doesn't dispatch a pixel event for WM_*SCROLL messages,
   1.897 +  // but ESM dispatches it instead.
   1.898 +  { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation enabled",
   1.899 +    message: WM_VSCROLL, delta: SB_LINEUP,
   1.900 +    target: gP1, x: 10, y: 10, window: window,
   1.901 +    modifiers: 0,
   1.902 +    additionalFlags: 0,
   1.903 +    expected: {
   1.904 +      axis: kVAxis, lines: -1, pixels: function () { return -gLineHeight; },
   1.905 +    },
   1.906 +    init: function () {
   1.907 +      SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, true);
   1.908 +    },
   1.909 +  },
   1.910 +
   1.911 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation enabled",
   1.912 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
   1.913 +    target: gP1, x: 10, y: 10, window: window,
   1.914 +    modifiers: 0,
   1.915 +    additionalFlags: 0,
   1.916 +    expected: {
   1.917 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
   1.918 +    },
   1.919 +  },
   1.920 +
   1.921 +  { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation enabled",
   1.922 +    message: WM_HSCROLL, delta: SB_LINELEFT,
   1.923 +    target: gP1, x: 10, y: 10, window: window,
   1.924 +    modifiers: 0,
   1.925 +    additionalFlags: 0,
   1.926 +    expected: {
   1.927 +      axis: kHAxis, lines: -1, pixels: function () { return -gCharWidth; },
   1.928 +    },
   1.929 +  },
   1.930 +
   1.931 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation enabled",
   1.932 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
   1.933 +    target: gP1, x: 10, y: 10, window: window,
   1.934 +    modifiers: 0,
   1.935 +    additionalFlags: 0,
   1.936 +    expected: {
   1.937 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
   1.938 +    },
   1.939 +  },
   1.940 +
   1.941 +  { description: "WM_VSCROLL, SB_PAGEUP, lParam is NULL, emulation enabled",
   1.942 +    message: WM_VSCROLL, delta: SB_PAGEUP,
   1.943 +    target: gP1, x: 10, y: 10, window: window,
   1.944 +    modifiers: 0,
   1.945 +    additionalFlags: 0,
   1.946 +    expected: {
   1.947 +      axis: kVAxis, lines: -DOM_PAGE_SCROLL_DELTA,
   1.948 +      pixels: function () { return -gPageHeight; },
   1.949 +    },
   1.950 +  },
   1.951 +
   1.952 +  { description: "WM_VSCROLL, SB_PAGEDOWN, lParam is NULL, emulation enabled",
   1.953 +    message: WM_VSCROLL, delta: SB_PAGEDOWN,
   1.954 +    target: gP1, x: 10, y: 10, window: window,
   1.955 +    modifiers: 0,
   1.956 +    additionalFlags: 0,
   1.957 +    expected: {
   1.958 +      axis: kVAxis, lines: DOM_PAGE_SCROLL_DELTA,
   1.959 +      pixels: function () { return gPageHeight; },
   1.960 +    },
   1.961 +  },
   1.962 +
   1.963 +  { description: "WM_HSCROLL, SB_PAGELEFT, lParam is NULL, emulation enabled",
   1.964 +    message: WM_HSCROLL, delta: SB_PAGELEFT,
   1.965 +    target: gP1, x: 10, y: 10, window: window,
   1.966 +    modifiers: 0,
   1.967 +    additionalFlags: 0,
   1.968 +    expected: {
   1.969 +      axis: kHAxis, lines: -DOM_PAGE_SCROLL_DELTA,
   1.970 +      pixels: function () { return -gPageWidth; },
   1.971 +    },
   1.972 +  },
   1.973 +
   1.974 +  { description: "WM_HSCROLL, SB_PAGERIGHT, lParam is NULL, emulation enabled",
   1.975 +    message: WM_HSCROLL, delta: SB_PAGERIGHT,
   1.976 +    target: gP1, x: 10, y: 10, window: window,
   1.977 +    modifiers: 0,
   1.978 +    additionalFlags: 0,
   1.979 +    expected: {
   1.980 +      axis: kHAxis, lines: DOM_PAGE_SCROLL_DELTA,
   1.981 +      pixels: function () { return gPageWidth; },
   1.982 +    },
   1.983 +  },
   1.984 +
   1.985 +  // Modifier key tests for WM_*SCROLL
   1.986 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with left Shift",
   1.987 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
   1.988 +    target: gP1, x: 10, y: 10, window: window,
   1.989 +    modifiers: SHIFT_L,
   1.990 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
   1.991 +    expected: {
   1.992 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
   1.993 +    },
   1.994 +    init: function () {
   1.995 +      SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
   1.996 +    },
   1.997 +  },
   1.998 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with right Shift",
   1.999 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
  1.1000 +    target: gP1, x: 10, y: 10, window: window,
  1.1001 +    modifiers: SHIFT_R,
  1.1002 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1003 +    expected: {
  1.1004 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
  1.1005 +    },
  1.1006 +  },
  1.1007 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with left Ctrl",
  1.1008 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
  1.1009 +    target: gP1, x: 10, y: 10, window: window,
  1.1010 +    modifiers: CTRL_L,
  1.1011 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1012 +    expected: {
  1.1013 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
  1.1014 +    },
  1.1015 +  },
  1.1016 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with right Ctrl",
  1.1017 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
  1.1018 +    target: gP1, x: 10, y: 10, window: window,
  1.1019 +    modifiers: CTRL_L,
  1.1020 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1021 +    expected: {
  1.1022 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
  1.1023 +    },
  1.1024 +  },
  1.1025 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with left Alt",
  1.1026 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
  1.1027 +    target: gP1, x: 10, y: 10, window: window,
  1.1028 +    modifiers: ALT_L,
  1.1029 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1030 +    expected: {
  1.1031 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
  1.1032 +    },
  1.1033 +  },
  1.1034 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, with right Alt",
  1.1035 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
  1.1036 +    target: gP1, x: 10, y: 10, window: window,
  1.1037 +    modifiers: ALT_R,
  1.1038 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1039 +    expected: {
  1.1040 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
  1.1041 +    },
  1.1042 +  },
  1.1043 +
  1.1044 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with left Shift",
  1.1045 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
  1.1046 +    target: gP1, x: 10, y: 10, window: window,
  1.1047 +    modifiers: SHIFT_L,
  1.1048 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1049 +    expected: {
  1.1050 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
  1.1051 +    },
  1.1052 +  },
  1.1053 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with right Shift",
  1.1054 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
  1.1055 +    target: gP1, x: 10, y: 10, window: window,
  1.1056 +    modifiers: SHIFT_R,
  1.1057 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1058 +    expected: {
  1.1059 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
  1.1060 +    },
  1.1061 +  },
  1.1062 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with left Ctrl",
  1.1063 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
  1.1064 +    target: gP1, x: 10, y: 10, window: window,
  1.1065 +    modifiers: CTRL_L,
  1.1066 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1067 +    expected: {
  1.1068 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
  1.1069 +    },
  1.1070 +  },
  1.1071 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with right Ctrl",
  1.1072 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
  1.1073 +    target: gP1, x: 10, y: 10, window: window,
  1.1074 +    modifiers: CTRL_L,
  1.1075 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1076 +    expected: {
  1.1077 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
  1.1078 +    },
  1.1079 +  },
  1.1080 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with left Alt",
  1.1081 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
  1.1082 +    target: gP1, x: 10, y: 10, window: window,
  1.1083 +    modifiers: ALT_L,
  1.1084 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1085 +    expected: {
  1.1086 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
  1.1087 +    },
  1.1088 +  },
  1.1089 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, with right Alt",
  1.1090 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
  1.1091 +    target: gP1, x: 10, y: 10, window: window,
  1.1092 +    modifiers: ALT_R,
  1.1093 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1094 +    expected: {
  1.1095 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
  1.1096 +    },
  1.1097 +
  1.1098 +    finish: function () {
  1.1099 +      runDeactiveWindowTests();
  1.1100 +    }
  1.1101 +  },
  1.1102 +];
  1.1103 +
  1.1104 +var gDeactiveWindowTests = [
  1.1105 +  // Typically, mouse drivers send wheel messages to focused window.
  1.1106 +  // However, we prefer to scroll a scrollable element under the mouse cursor.
  1.1107 +  { description: "WM_MOUSEWHEEL, -120, 3 lines, window is deactive",
  1.1108 +    message: WM_MOUSEWHEEL, delta: -120,
  1.1109 +    target: gP1, x: 10, y: 10, window: window,
  1.1110 +    modifiers: 0,
  1.1111 +    additionalFlags: 0,
  1.1112 +    expected: {
  1.1113 +      axis: kVAxis, lines: 3, pixels: function () { return gLineHeight * 3; },
  1.1114 +    },
  1.1115 +    init: function () {
  1.1116 +      SpecialPowers.setIntPref(kVAmountPref, 3);
  1.1117 +      SpecialPowers.setIntPref(kHAmountPref, 3);
  1.1118 +    },
  1.1119 +    onLineScrollEvent: function (aEvent) {
  1.1120 +      var fm = Components.classes["@mozilla.org/focus-manager;1"].
  1.1121 +            getService(Components.interfaces.nsIFocusManager);
  1.1122 +      is(fm.activeWindow, gOtherWindow, "The other window isn't activated");
  1.1123 +    },
  1.1124 +  },
  1.1125 +
  1.1126 +  { description: "WM_MOUSEWHEEL, 120, -3 lines, window is deactive",
  1.1127 +    message: WM_MOUSEWHEEL, delta: 120,
  1.1128 +    target: gP1, x: 10, y: 10, window: window,
  1.1129 +    modifiers: 0,
  1.1130 +    additionalFlags: 0,
  1.1131 +    expected: {
  1.1132 +      axis: kVAxis, lines: -3, pixels: function () { return gLineHeight * -3; },
  1.1133 +    },
  1.1134 +  },
  1.1135 +
  1.1136 +  { description: "WM_MOUSEHWHEEL, 120, 3 chars, window is deactive",
  1.1137 +    message: WM_MOUSEHWHEEL, delta: 120,
  1.1138 +    target: gP1, x: 10, y: 10, window: window,
  1.1139 +    modifiers: 0,
  1.1140 +    additionalFlags: 0,
  1.1141 +    expected: {
  1.1142 +      axis: kHAxis, lines: 3, pixels: function () { return gCharWidth * 3; },
  1.1143 +    },
  1.1144 +  },
  1.1145 +
  1.1146 +  { description: "WM_MOUSEHWHEEL, -120, -3 chars, window is deactive",
  1.1147 +    message: WM_MOUSEHWHEEL, delta: -120,
  1.1148 +    target: gP1, x: 10, y: 10, window: window,
  1.1149 +    modifiers: 0,
  1.1150 +    additionalFlags: 0,
  1.1151 +    expected: {
  1.1152 +      axis: kHAxis, lines: -3, pixels: function () { return gCharWidth * -3; },
  1.1153 +    },
  1.1154 +  },
  1.1155 +
  1.1156 +  // Of course, even if some drivers prefer the cursor position, we don't need
  1.1157 +  // to change anything.
  1.1158 +  { description: "WM_MOUSEWHEEL, -120, 3 lines, window is deactive (receive the message directly)",
  1.1159 +    message: WM_MOUSEWHEEL, delta: -120,
  1.1160 +    target: gP1, x: 10, y: 10, window: window,
  1.1161 +    modifiers: 0,
  1.1162 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1163 +    expected: {
  1.1164 +      axis: kVAxis, lines: 3, pixels: function () { return gLineHeight * 3; },
  1.1165 +    },
  1.1166 +  },
  1.1167 +
  1.1168 +  { description: "WM_MOUSEWHEEL, 120, -3 lines, window is deactive (receive the message directly)",
  1.1169 +    message: WM_MOUSEWHEEL, delta: 120,
  1.1170 +    target: gP1, x: 10, y: 10, window: window,
  1.1171 +    modifiers: 0,
  1.1172 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1173 +    expected: {
  1.1174 +      axis: kVAxis, lines: -3, pixels: function () { return gLineHeight * -3; },
  1.1175 +    },
  1.1176 +  },
  1.1177 +
  1.1178 +  { description: "WM_MOUSEHWHEEL, 120, 3 chars, window is deactive (receive the message directly)",
  1.1179 +    message: WM_MOUSEHWHEEL, delta: 120,
  1.1180 +    target: gP1, x: 10, y: 10, window: window,
  1.1181 +    modifiers: 0,
  1.1182 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1183 +    expected: {
  1.1184 +      axis: kHAxis, lines: 3, pixels: function () { return gCharWidth * 3; },
  1.1185 +    },
  1.1186 +  },
  1.1187 +
  1.1188 +  { description: "WM_MOUSEHWHEEL, -120, -3 chars, window is deactive (receive the message directly)",
  1.1189 +    message: WM_MOUSEHWHEEL, delta: -120,
  1.1190 +    target: gP1, x: 10, y: 10, window: window,
  1.1191 +    modifiers: 0,
  1.1192 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1193 +    expected: {
  1.1194 +      axis: kHAxis, lines: -3, pixels: function () { return gCharWidth * -3; },
  1.1195 +    },
  1.1196 +  },
  1.1197 +
  1.1198 +  // Same for WM_*SCROLL if lParam is not NULL
  1.1199 +  { description: "WM_VSCROLL, SB_LINEUP, lParam is not NULL, emulation disabled, window is deactive",
  1.1200 +    message: WM_VSCROLL, delta: SB_LINEUP,
  1.1201 +    target: gP1, x: 10, y: 10, window: window,
  1.1202 +    modifiers: 0,
  1.1203 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1204 +    expected: {
  1.1205 +      axis: kVAxis, lines: -1, pixels: function () { return -gLineHeight; },
  1.1206 +    },
  1.1207 +    init: function () {
  1.1208 +      SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
  1.1209 +    },
  1.1210 +  },
  1.1211 +
  1.1212 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, window is deactive",
  1.1213 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
  1.1214 +    target: gP1, x: 10, y: 10, window: window,
  1.1215 +    modifiers: 0,
  1.1216 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1217 +    expected: {
  1.1218 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
  1.1219 +    },
  1.1220 +  },
  1.1221 +
  1.1222 +  { description: "WM_HSCROLL, SB_LINELEFT, lParam is not NULL, emulation disabled, window is deactive",
  1.1223 +    message: WM_HSCROLL, delta: SB_LINELEFT,
  1.1224 +    target: gP1, x: 10, y: 10, window: window,
  1.1225 +    modifiers: 0,
  1.1226 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1227 +    expected: {
  1.1228 +      axis: kHAxis, lines: -1, pixels: function () { return -gCharWidth; },
  1.1229 +    },
  1.1230 +  },
  1.1231 +
  1.1232 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, window is deactive",
  1.1233 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
  1.1234 +    target: gP1, x: 10, y: 10, window: window,
  1.1235 +    modifiers: 0,
  1.1236 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL,
  1.1237 +    expected: {
  1.1238 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
  1.1239 +    },
  1.1240 +  },
  1.1241 +
  1.1242 +  // Same for WM_*SCROLL if lParam is NULL but emulation is enabled
  1.1243 +  { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation enabled, window is deactive",
  1.1244 +    message: WM_VSCROLL, delta: SB_LINEUP,
  1.1245 +    target: gP1, x: 10, y: 10, window: window,
  1.1246 +    modifiers: 0,
  1.1247 +    additionalFlags: 0,
  1.1248 +    expected: {
  1.1249 +      axis: kVAxis, lines: -1, pixels: function () { return -gLineHeight; },
  1.1250 +    },
  1.1251 +    init: function () {
  1.1252 +      SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, true);
  1.1253 +    },
  1.1254 +  },
  1.1255 +
  1.1256 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation enabled, window is deactive",
  1.1257 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
  1.1258 +    target: gP1, x: 10, y: 10, window: window,
  1.1259 +    modifiers: 0,
  1.1260 +    additionalFlags: 0,
  1.1261 +    expected: {
  1.1262 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
  1.1263 +    },
  1.1264 +  },
  1.1265 +
  1.1266 +  { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation enabled, window is deactive",
  1.1267 +    message: WM_HSCROLL, delta: SB_LINELEFT,
  1.1268 +    target: gP1, x: 10, y: 10, window: window,
  1.1269 +    modifiers: 0,
  1.1270 +    additionalFlags: 0,
  1.1271 +    expected: {
  1.1272 +      axis: kHAxis, lines: -1, pixels: function () { return -gCharWidth; },
  1.1273 +    },
  1.1274 +  },
  1.1275 +
  1.1276 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation enabled, window is deactive",
  1.1277 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
  1.1278 +    target: gP1, x: 10, y: 10, window: window,
  1.1279 +    modifiers: 0,
  1.1280 +    additionalFlags: 0,
  1.1281 +    expected: {
  1.1282 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
  1.1283 +    },
  1.1284 +  },
  1.1285 +
  1.1286 +  // Same for WM_*SCROLL if lParam is not NULL and message sent to the deactive window directly
  1.1287 +  { description: "WM_VSCROLL, SB_LINEUP, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
  1.1288 +    message: WM_VSCROLL, delta: SB_LINEUP,
  1.1289 +    target: gP1, x: 10, y: 10, window: window,
  1.1290 +    modifiers: 0,
  1.1291 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
  1.1292 +                     nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1293 +    expected: {
  1.1294 +      axis: kVAxis, lines: -1, pixels: function () { return -gLineHeight; },
  1.1295 +    },
  1.1296 +    init: function () {
  1.1297 +      SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, false);
  1.1298 +    },
  1.1299 +  },
  1.1300 +
  1.1301 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
  1.1302 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
  1.1303 +    target: gP1, x: 10, y: 10, window: window,
  1.1304 +    modifiers: 0,
  1.1305 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
  1.1306 +                     nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1307 +    expected: {
  1.1308 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
  1.1309 +    },
  1.1310 +  },
  1.1311 +
  1.1312 +  { description: "WM_HSCROLL, SB_LINELEFT, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
  1.1313 +    message: WM_HSCROLL, delta: SB_LINELEFT,
  1.1314 +    target: gP1, x: 10, y: 10, window: window,
  1.1315 +    modifiers: 0,
  1.1316 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
  1.1317 +                     nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1318 +    expected: {
  1.1319 +      axis: kHAxis, lines: -1, pixels: function () { return -gCharWidth; },
  1.1320 +    },
  1.1321 +  },
  1.1322 +
  1.1323 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is not NULL, emulation disabled, window is deactive (receive the message directly)",
  1.1324 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
  1.1325 +    target: gP1, x: 10, y: 10, window: window,
  1.1326 +    modifiers: 0,
  1.1327 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_WIN_SCROLL_LPARAM_NOT_NULL |
  1.1328 +                     nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1329 +    expected: {
  1.1330 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
  1.1331 +    },
  1.1332 +  },
  1.1333 +
  1.1334 +  // Same for WM_*SCROLL if lParam is NULL but emulation is enabled, and message sent to the deactive window directly
  1.1335 +  { description: "WM_VSCROLL, SB_LINEUP, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
  1.1336 +    message: WM_VSCROLL, delta: SB_LINEUP,
  1.1337 +    target: gP1, x: 10, y: 10, window: window,
  1.1338 +    modifiers: 0,
  1.1339 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1340 +    expected: {
  1.1341 +      axis: kVAxis, lines: -1, pixels: function () { return -gLineHeight; },
  1.1342 +    },
  1.1343 +    init: function () {
  1.1344 +      SpecialPowers.setBoolPref(kEmulateWheelByWMSCROLLPref, true);
  1.1345 +    },
  1.1346 +  },
  1.1347 +
  1.1348 +  { description: "WM_VSCROLL, SB_LINEDOWN, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
  1.1349 +    message: WM_VSCROLL, delta: SB_LINEDOWN,
  1.1350 +    target: gP1, x: 10, y: 10, window: window,
  1.1351 +    modifiers: 0,
  1.1352 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1353 +    expected: {
  1.1354 +      axis: kVAxis, lines: 1, pixels: function () { return gLineHeight; },
  1.1355 +    },
  1.1356 +  },
  1.1357 +
  1.1358 +  { description: "WM_HSCROLL, SB_LINELEFT, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
  1.1359 +    message: WM_HSCROLL, delta: SB_LINELEFT,
  1.1360 +    target: gP1, x: 10, y: 10, window: window,
  1.1361 +    modifiers: 0,
  1.1362 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1363 +    expected: {
  1.1364 +      axis: kHAxis, lines: -1, pixels: function () { return -gCharWidth; },
  1.1365 +    },
  1.1366 +  },
  1.1367 +
  1.1368 +  { description: "WM_HSCROLL, SB_LINERIGHT, lParam is NULL, emulation enabled, window is deactive (receive the message directly)",
  1.1369 +    message: WM_HSCROLL, delta: SB_LINERIGHT,
  1.1370 +    target: gP1, x: 10, y: 10, window: window,
  1.1371 +    modifiers: 0,
  1.1372 +    additionalFlags: nsIDOMWindowUtils.MOUSESCROLL_PREFER_WIDGET_AT_POINT,
  1.1373 +    expected: {
  1.1374 +      axis: kHAxis, lines: 1, pixels: function () { return gCharWidth; },
  1.1375 +    },
  1.1376 +
  1.1377 +    finish: function () {
  1.1378 +      gOtherWindow.close();
  1.1379 +      gOtherWindow = null;
  1.1380 +      window.close();
  1.1381 +    }
  1.1382 +  },
  1.1383 +];
  1.1384 +
  1.1385 +function runDeactiveWindowTests()
  1.1386 +{
  1.1387 +  gOtherWindow = window.open("data:text/html,", "_blank",
  1.1388 +                             "chrome,width=100,height=100,top=700,left=700");
  1.1389 +
  1.1390 +  window.opener.wrappedJSObject.SimpleTest.waitForFocus(function () {
  1.1391 +    runNextTest(gDeactiveWindowTests, 0);
  1.1392 +  }, gOtherWindow);
  1.1393 +}
  1.1394 +
  1.1395 +function runNextTest(aTests, aIndex)
  1.1396 +{
  1.1397 +  if (aIndex > 0 && aTests[aIndex - 1] && aTests[aIndex - 1].finish) {
  1.1398 +    aTests[aIndex - 1].finish();
  1.1399 +  }
  1.1400 +
  1.1401 +  if (aTests.length == aIndex) {
  1.1402 +    return;
  1.1403 +  }
  1.1404 +
  1.1405 +  var test = aTests[aIndex++];
  1.1406 +  if (test.init) {
  1.1407 +    test.init();
  1.1408 +  }
  1.1409 +  test.handled = { lines: false, pixels: false };
  1.1410 +
  1.1411 +  switch (test.message) {
  1.1412 +    case WM_MOUSEWHEEL:
  1.1413 +    case WM_MOUSEHWHEEL:
  1.1414 +    case WM_VSCROLL:
  1.1415 +    case WM_HSCROLL:
  1.1416 +      var expectedLines = test.expected.lines;
  1.1417 +      var expectedPixels =
  1.1418 +        cut((typeof test.expected.pixels == "function") ?
  1.1419 +               test.expected.pixels() : test.expected.pixels);
  1.1420 +      var handler = function (aEvent) {
  1.1421 +        var doCommonTests = true;
  1.1422 +
  1.1423 +        if (!aEvent) {
  1.1424 +          ok(!test.handled.lines,
  1.1425 +             test.description + ", line scroll event has been handled");
  1.1426 +          ok(!test.handled.pixels,
  1.1427 +             test.description + ", pixel scroll event has been handled");
  1.1428 +          doCommonTests = false;
  1.1429 +        } else if (aEvent.type == kMouseLineScrollEvent) {
  1.1430 +          ok(!test.handled.lines,
  1.1431 +             test.description + ":(" + aEvent.type + "), same event has already been handled");
  1.1432 +          test.handled.lines = true;
  1.1433 +          isnot(expectedLines, 0,
  1.1434 +                test.description + ":(" + aEvent.type + "), event shouldn't be fired");
  1.1435 +          if (test.onLineScrollEvent && test.onLineScrollEvent(aEvent)) {
  1.1436 +            doCommonTests = false;
  1.1437 +          }
  1.1438 +        } else if (aEvent.type == kMousePixelScrollEvent) {
  1.1439 +          ok(!test.handled.pixels,
  1.1440 +             test.description + ":(" + aEvent.type + "), same event has already been handled");
  1.1441 +          test.handled.pixels = true;
  1.1442 +          isnot(expectedPixels, 0,
  1.1443 +                test.description + ":(" + aEvent.type + "), event shouldn't be fired");
  1.1444 +          if (test.onPixelScrollEvent && test.onPixelScrollEvent(aEvent)) {
  1.1445 +            doCommonTests = false;
  1.1446 +          }
  1.1447 +        }
  1.1448 +
  1.1449 +        if (doCommonTests) {
  1.1450 +          var expectedDelta =
  1.1451 +            (aEvent.type == kMouseLineScrollEvent) ?
  1.1452 +              expectedLines : expectedPixels;
  1.1453 +          is(aEvent.target.id, test.target.id,
  1.1454 +             test.description + ":(" + aEvent.type + "), ID mismatch");
  1.1455 +          is(aEvent.axis, test.expected.axis,
  1.1456 +             test.description + ":(" + aEvent.type + "), axis mismatch");
  1.1457 +          ok(aEvent.detail != 0,
  1.1458 +             test.description + ":(" + aEvent.type + "), delta must not be 0");
  1.1459 +          is(aEvent.detail, expectedDelta,
  1.1460 +             test.description + ":(" + aEvent.type + "), delta mismatch");
  1.1461 +          is(aEvent.shiftKey, (test.modifiers & (SHIFT_L | SHIFT_R)) != 0,
  1.1462 +             test.description + ":(" + aEvent.type + "), shiftKey mismatch");
  1.1463 +          is(aEvent.ctrlKey, (test.modifiers & (CTRL_L | CTRL_R)) != 0,
  1.1464 +             test.description + ":(" + aEvent.type + "), ctrlKey mismatch");
  1.1465 +          is(aEvent.altKey, (test.modifiers & (ALT_L | ALT_R)) != 0,
  1.1466 +             test.description + ":(" + aEvent.type + "), altKey mismatch");
  1.1467 +        }
  1.1468 +
  1.1469 +        if (!aEvent || (test.handled.lines || expectedLines == 0) &&
  1.1470 +                       (test.handled.pixels || expectedPixels == 0)) {
  1.1471 +          // Don't scroll actually.
  1.1472 +          if (aEvent) {
  1.1473 +            aEvent.preventDefault();
  1.1474 +          }
  1.1475 +          test.target.removeEventListener(kMouseLineScrollEvent, handler, true);
  1.1476 +          test.target.removeEventListener(kMousePixelScrollEvent, handler, true);
  1.1477 +          setTimeout(runNextTest, 0, aTests, aIndex);
  1.1478 +        }
  1.1479 +      };
  1.1480 +
  1.1481 +      test.target.addEventListener(kMouseLineScrollEvent, handler, true);
  1.1482 +      test.target.addEventListener(kMousePixelScrollEvent, handler, true);
  1.1483 +
  1.1484 +      if (expectedLines == 0 && expectedPixels == 0) {
  1.1485 +        // The timeout might not be enough if system is slow by other process,
  1.1486 +        // so, the test might be passed unexpectedly.  However, it must be able
  1.1487 +        // to be detected by random orange.
  1.1488 +        setTimeout(handler, 500);
  1.1489 +      }
  1.1490 +
  1.1491 +      var utils = getWindowUtils(test.window);
  1.1492 +      var ptInScreen = getPointInScreen(test.target, test.window);
  1.1493 +      var isVertical =
  1.1494 +        ((test.message == WM_MOUSEWHEEL) || (test.message == WM_VSCROLL));
  1.1495 +      var deltaX = !isVertical ? test.delta : 0;
  1.1496 +      var deltaY = isVertical  ? test.delta : 0;
  1.1497 +      utils.sendNativeMouseScrollEvent(ptInScreen.x + test.x,
  1.1498 +                                       ptInScreen.y + test.y,
  1.1499 +                                       test.message, deltaX, deltaY, 0,
  1.1500 +                                       test.modifiers,
  1.1501 +                                       test.additionalFlags,
  1.1502 +                                       test.target);
  1.1503 +      break;
  1.1504 +    default:
  1.1505 +      ok(false, test.description + ": invalid message");
  1.1506 +      // Let's timeout.
  1.1507 +  }
  1.1508 +}
  1.1509 +
  1.1510 +function prepareTests()
  1.1511 +{
  1.1512 +  // Disable special action with modifier key
  1.1513 +  SpecialPowers.setIntPref(kAltKeyActionPref, 1);
  1.1514 +  SpecialPowers.setIntPref(kCtrlKeyActionPref, 1);
  1.1515 +  SpecialPowers.setIntPref(kShiftKeyActionPref, 1);
  1.1516 +  SpecialPowers.setIntPref(kWinKeyActionPref, 1);
  1.1517 +
  1.1518 +  SpecialPowers.setIntPref(kAltKeyDeltaMultiplierXPref, 100);
  1.1519 +  SpecialPowers.setIntPref(kAltKeyDeltaMultiplierYPref, 100);
  1.1520 +  SpecialPowers.setIntPref(kCtrlKeyDeltaMultiplierXPref, 100);
  1.1521 +  SpecialPowers.setIntPref(kCtrlKeyDeltaMultiplierYPref, 100);
  1.1522 +  SpecialPowers.setIntPref(kShiftKeyDeltaMultiplierXPref, 100);
  1.1523 +  SpecialPowers.setIntPref(kShiftKeyDeltaMultiplierYPref, 100);
  1.1524 +  SpecialPowers.setIntPref(kWinKeyDeltaMultiplierXPref, 100);
  1.1525 +  SpecialPowers.setIntPref(kWinKeyDeltaMultiplierYPref, 100);
  1.1526 +
  1.1527 +  SpecialPowers.setBoolPref(kSystemScrollSpeedOverridePref, false);
  1.1528 +  SpecialPowers.setIntPref(kTimeoutPref, -1);
  1.1529 +
  1.1530 +  runNextTest(gPreparingSteps, 0);
  1.1531 +}
  1.1532 +
  1.1533 +</script>
  1.1534 +</body>
  1.1535 +
  1.1536 +</html>

mercurial