Commit 876ef492 authored by Masayuki Nakano's avatar Masayuki Nakano
Browse files

Bug 1691622 - part 11: Make mochitests stop using...

Bug 1691622 - part 11: Make mochitests stop using `nsIDOMWindowUtils.sendNativeMouseEvent` directly as far as possible r=smaug

For making the test framework/API change easier, such raw API shouldn't be
used directly.  Therefore, this patch makes tests using it directly stop
using it and use `synthesizeNativeMouseEvent` instead.

However, this patch does not fix `browser_touch_event_iframes.js` because
it accesses the API from `ContentTask`.  So, `EventUtils.js` isn't available
without larger change.

Note that this patch disables `test_bug596600.xhtml` because as I commented
in it, it's completely broken.  It depends on the race of next native event
loop and `waitForTick`, and this patch changes the result of the race.

Differential Revision: https://phabricator.services.mozilla.com/D105765
parent b77b790e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -153,6 +153,9 @@ for (const mvcontent of META_VIEWPORT_CONTENTS) {
              }

              // This function takes screen coordinates in css pixels.
              // TODO: This should stop using nsIDOMWindowUtils.sendNativeMouseEvent
              //       directly, and use `EventUtils.synthesizeNativeMouseEvent` in
              //       a message listener in the chrome.
              function synthesizeNativeMouseClick(win, screenX, screenY) {
                const utils = win.windowUtils;
                const scale = utils.screenPixelsPerCSSPixelNoOverride;
+10 −0
Original line number Diff line number Diff line
@@ -694,6 +694,16 @@ function synthesizeNativeMouseEventWithAPZ(aParams, aObserver = null) {
      "Are you trying to use EventUtils' API? `win` won't be used with synthesizeNativeMouseClickWithAPZ."
    );
  }
  if (aParams.scale !== undefined) {
    throw Error(
      "Are you trying to use EventUtils' API? `scale` won't be used with synthesizeNativeMouseClickWithAPZ."
    );
  }
  if (aParams.elementOnWidget !== undefined) {
    throw Error(
      "Are you trying to use EventUtils' API? `elementOnWidget` won't be used with synthesizeNativeMouseClickWithAPZ."
    );
  }
  const {
    type, // "click", "mousedown", "mouseup" or "mousemove"
    target, // Origin of offsetX and offsetY, must be an element
+13 −26
Original line number Diff line number Diff line
@@ -16,37 +16,19 @@ const PAGECONTENT_TRANSLATED =
  "</iframe>" +
  "</div></body></html>";

function synthesizeNativeMouseClick(aWin, aScreenX, aScreenY) {
  const utils = SpecialPowers.getDOMWindowUtils(aWin);
  const scale = utils.screenPixelsPerCSSPixel;

  utils.sendNativeMouseEvent(
    aScreenX * scale,
    aScreenY * scale,
    utils.NATIVE_MOUSE_MESSAGE_BUTTON_DOWN,
    0,
    0,
    aWin.document.documentElement,
    () => {
      utils.sendNativeMouseEvent(
        aScreenX * scale,
        aScreenY * scale,
        utils.NATIVE_MOUSE_MESSAGE_BUTTON_UP,
        0,
        0,
        aWin.document.documentElement
      );
    }
  );
}

function openSelectPopup(selectPopup, x, y, win) {
  const popupShownPromise = BrowserTestUtils.waitForEvent(
    selectPopup,
    "popupshown"
  );

  synthesizeNativeMouseClick(win, x, y);
  EventUtils.synthesizeNativeMouseEvent({
    type: "click",
    target: win.document.documentElement,
    screenX: x,
    screenY: y,
    scale: "screenPixelsPerCSSPixel",
  });

  return popupShownPromise;
}
@@ -137,7 +119,12 @@ add_task(async function() {
    expectedYPosition += selectRect.height;
  }

  is(popupRect.y, expectedYPosition, "y position of the popup");
  isfuzzy(
    popupRect.y,
    expectedYPosition,
    window.windowUtils.screenPixelsPerCSSPixel,
    "y position of the popup"
  );

  await hideSelectPopup(selectPopup, "enter", newWin);

+6 −8
Original line number Diff line number Diff line
@@ -69,14 +69,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=987230
      info("Mousemove: " + outsideOfFrameX + ", " + outsideOfFrameY +
           " (from innerscreen " + window.mozInnerScreenX + ", " + window.mozInnerScreenY +
           " and rect width " + frameRect.width + " and scale " + scale + ")");
      utils.sendNativeMouseEvent(
        outsideOfFrameX,
        outsideOfFrameY,
        utils.NATIVE_MOUSE_MESSAGE_MOVE,
        0,
        0,
        null
      );
      synthesizeNativeMouseEvent({
        type: "mousemove",
        screenX: outsideOfFrameX,
        screenY: outsideOfFrameY,
        elementOnWidget: null,
      });
      SimpleTest.finish();
    }
  }
+11 −0
Original line number Diff line number Diff line
@@ -1364,6 +1364,17 @@ function testScope(aTester, aTest, expected) {
      Components.stack.caller
    );
  };
  this.isfuzzy = function test_isfuzzy(a, b, epsilon, name) {
    self.record(
      a >= b - epsilon && a <= b + epsilon,
      name,
      `Got ${self.repr(a)}, expected ${self.repr(b)} epsilon: +/- ${self.repr(
        epsilon
      )}`,
      false,
      Components.stack.caller
    );
  };
  this.isnot = function test_isnot(a, b, name) {
    self.record(
      !Object.is(a, b),
Loading