Commit 4cfc1d88 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1738265 - Teach some popup tests to deal with popups having margins by default. r=NeilDeakin

For tests that actually test margin handling I've just removed the default
margin by adding:

  <?xml-stylesheet href="data:text/css,menupopup{margin: 0}" type="text/css"?>

The other tests I've just fixed by accounting for the margins.

Differential Revision: https://phabricator.services.mozilla.com/D129866
parent f5f88b56
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -94,10 +94,12 @@ add_task(async function testPopupSelectPopup() {
  await popupPromise;

  let popupRect = selectPopup.getOuterScreenRect();
  let popupMarginLeft = parseFloat(getComputedStyle(selectPopup).marginLeft);
  let popupMarginTop = parseFloat(getComputedStyle(selectPopup).marginTop);

  is(
    Math.floor(browserForPopup.screenX + selectRect.left),
    popupRect.left,
    popupRect.left - popupMarginLeft,
    "Select popup has the correct x origin"
  );

@@ -105,7 +107,11 @@ add_task(async function testPopupSelectPopup() {
  let expectedY = navigator.platform.includes("Mac")
    ? Math.floor(browserForPopup.screenY)
    : Math.floor(browserForPopup.screenY + selectRect.bottom);
  is(expectedY, popupRect.top, "Select popup has the correct y origin");
  is(
    expectedY,
    popupRect.top - popupMarginTop,
    "Select popup has the correct y origin"
  );

  const onPopupHidden = BrowserTestUtils.waitForEvent(
    selectPopup,
+5 −3
Original line number Diff line number Diff line
@@ -72,9 +72,11 @@ async function runPopupPositionTest(parentDocumentFileName) {
  await openSelectPopup(selectPopup);

  const popup_rect = selectPopup.getBoundingClientRect();
  const popupMarginTop = parseFloat(getComputedStyle(selectPopup).marginTop);
  const popupMarginLeft = parseFloat(getComputedStyle(selectPopup).marginLeft);

  is(
    popup_rect.left,
    popup_rect.left - popupMarginLeft,
    selectRect.x * 2.0,
    "select popup position should be scaled by the desktop zoom"
  );
@@ -83,14 +85,14 @@ async function runPopupPositionTest(parentDocumentFileName) {
  // option element.
  if (!navigator.platform.includes("Mac")) {
    is(
      popup_rect.top,
      popup_rect.top - popupMarginTop,
      tab.linkedBrowser.getBoundingClientRect().top +
        (selectRect.y + selectRect.height) * 2.0,
      "select popup position should be scaled by the desktop zoom"
    );
  } else {
    is(
      popup_rect.top,
      popup_rect.top - popupMarginTop,
      tab.linkedBrowser.getBoundingClientRect().top + selectRect.y * 2.0,
      "select popup position should be scaled by the desktop zoom"
    );
+2 −1
Original line number Diff line number Diff line
@@ -30,8 +30,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=467442

    panel.addEventListener("popupshown", function onpopupshown() {
      let panelRect = panel.getBoundingClientRect();
      let marginLeft  = parseFloat(getComputedStyle(panel).marginLeft);
      let anchorRect = anchor.getBoundingClientRect();
      is(panelRect.left, anchorRect.left, "Panel should be anchored to the button");
      is(panelRect.left - marginLeft, anchorRect.left, "Panel should be anchored to the button");
      panel.addEventListener("popuphidden", function onpopuphidden() {
        SimpleTest.finish();
      }, { once: true });
+4 −2
Original line number Diff line number Diff line
@@ -38,8 +38,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=477754
    }, false);

    function doTest() {
      is(Math.round(testAnchor.getBoundingClientRect().right -
                    testPopup.getBoundingClientRect().right), 10,
      let anchorRect = testAnchor.getBoundingClientRect();
      let popupRect = testPopup.getBoundingClientRect();
      let marginRight = parseFloat(getComputedStyle(testPopup).marginRight)
      is(Math.round(anchorRect.right - popupRect.right - marginRight), 10,
         "RTL popup's right offset should be equal to the x offset passed to openPopup");
      testPopup.hidePopup();
      SimpleTest.finish();
+7 −4
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ XUL <resizer> tests
    var step = 0;
    function popupShown(event)
    {
      let panel = document.getElementById("panel");
      if (step == 0) {
        // check to make sure that the popup cannot be resized past the edges of
        // the content area
@@ -37,7 +38,7 @@ XUL <resizer> tests

        // allow a one pixel variance as rounding is always done to the inside
        // of a rectangle.
        var popuprect = document.getElementById("panel").getBoundingClientRect();
        var popuprect = panel.getBoundingClientRect();
        ok(Math.round(popuprect.right) == window.innerWidth ||
           Math.round(popuprect.right) == window.innerWidth - 1,
           "resized to content edge width");
@@ -52,9 +53,11 @@ XUL <resizer> tests
        // the popup is opened twice. Make sure that for the second time, the
        // resized popup opens in the same direction as there should still be
        // room for it
        var popuprect = document.getElementById("panel").getBoundingClientRect();
        is(Math.round(popuprect.left), window.innerWidth - 130, "reopen popup left");
        is(Math.round(popuprect.top), window.innerHeight - 130, "reopen popup top");
        var popuprect = panel.getBoundingClientRect();
        var marginLeft = parseFloat(getComputedStyle(panel).marginLeft);
        var marginTop = parseFloat(getComputedStyle(panel).marginTop);
        is(Math.round(popuprect.left - marginLeft), window.innerWidth - 130, "reopen popup left");
        is(Math.round(popuprect.top - marginTop), window.innerHeight - 130, "reopen popup top");
      }

      event.target.hidePopup();
Loading