From 4cfc1d8874e5409e7475c6cbb0409e3f566a162e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 29 Oct 2021 19:26:37 +0000 Subject: [PATCH] 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: The other tests I've just fixed by accounting for the margins. Differential Revision: https://phabricator.services.mozilla.com/D129866 --- .../browser_ext_popup_select_in_oopif.js | 10 ++++- .../browser_test_select_popup_position.js | 8 ++-- layout/xul/test/test_bug467442.xhtml | 3 +- layout/xul/test/test_bug477754.xhtml | 6 ++- layout/xul/test/test_resizer.xhtml | 11 +++-- .../browser/browser_datetime_datepicker.js | 14 +++++- .../tests/chrome/frame_popup_anchor.xhtml | 9 ++-- .../tests/chrome/test_contextmenu_list.xhtml | 8 ++-- .../tests/chrome/test_popup_coords.xhtml | 10 +++-- .../chrome/test_popup_moveToAnchor.xhtml | 22 +++++----- .../tests/chrome/test_popup_scaled.xhtml | 18 ++++---- .../chrome/window_panel_anchoradjust.xhtml | 44 +++++++++++-------- .../tests/chrome/window_popup_attribute.xhtml | 1 + .../tests/chrome/window_popup_button.xhtml | 7 +-- 14 files changed, 107 insertions(+), 64 deletions(-) diff --git a/browser/components/extensions/test/browser/browser_ext_popup_select_in_oopif.js b/browser/components/extensions/test/browser/browser_ext_popup_select_in_oopif.js index 3b08dc225c27..d7d7c30e17f5 100644 --- a/browser/components/extensions/test/browser/browser_ext_popup_select_in_oopif.js +++ b/browser/components/extensions/test/browser/browser_ext_popup_select_in_oopif.js @@ -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, diff --git a/gfx/layers/apz/test/mochitest/browser_test_select_popup_position.js b/gfx/layers/apz/test/mochitest/browser_test_select_popup_position.js index 51ea50b83035..8b38df1c68c7 100644 --- a/gfx/layers/apz/test/mochitest/browser_test_select_popup_position.js +++ b/gfx/layers/apz/test/mochitest/browser_test_select_popup_position.js @@ -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" ); diff --git a/layout/xul/test/test_bug467442.xhtml b/layout/xul/test/test_bug467442.xhtml index e966bb3fe446..f0f84c3f8614 100644 --- a/layout/xul/test/test_bug467442.xhtml +++ b/layout/xul/test/test_bug467442.xhtml @@ -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 }); diff --git a/layout/xul/test/test_bug477754.xhtml b/layout/xul/test/test_bug477754.xhtml index b53c55723d2e..338f95c62efb 100644 --- a/layout/xul/test/test_bug477754.xhtml +++ b/layout/xul/test/test_bug477754.xhtml @@ -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(); diff --git a/layout/xul/test/test_resizer.xhtml b/layout/xul/test/test_resizer.xhtml index 5e027e5803ce..a0b88d6ebd53 100644 --- a/layout/xul/test/test_resizer.xhtml +++ b/layout/xul/test/test_resizer.xhtml @@ -28,6 +28,7 @@ XUL 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 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 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(); diff --git a/toolkit/content/tests/browser/browser_datetime_datepicker.js b/toolkit/content/tests/browser/browser_datetime_datepicker.js index 85b0daa9b896..a86eb85362ea 100644 --- a/toolkit/content/tests/browser/browser_datetime_datepicker.js +++ b/toolkit/content/tests/browser/browser_datetime_datepicker.js @@ -109,8 +109,18 @@ async function verifyPickerPosition(browsingContext, inputId) { msg + ": " + got + " should be equal(-ish) to " + exp ); } - is_close(helper.panel.screenX, inputRect.left, "datepicker x position"); - is_close(helper.panel.screenY, inputRect.bottom, "datepicker y position"); + const marginLeft = parseFloat(getComputedStyle(helper.panel).marginLeft); + const marginTop = parseFloat(getComputedStyle(helper.panel).marginTop); + is_close( + helper.panel.screenX - marginLeft, + inputRect.left, + "datepicker x position" + ); + is_close( + helper.panel.screenY - marginTop, + inputRect.bottom, + "datepicker y position" + ); } let helper = new DateTimeTestHelper(); diff --git a/toolkit/content/tests/chrome/frame_popup_anchor.xhtml b/toolkit/content/tests/chrome/frame_popup_anchor.xhtml index 142bc7b0af74..934cea6faf71 100644 --- a/toolkit/content/tests/chrome/frame_popup_anchor.xhtml +++ b/toolkit/content/tests/chrome/frame_popup_anchor.xhtml @@ -33,13 +33,13 @@ function popupShowing(event) function popupShown() { var left, top; - var popuprect = document.getElementById("popup").getBoundingClientRect(); + var popup = document.getElementById("popup"); + var popuprect = popup.getBoundingClientRect(); if (isSecondTest) { let buttonrect = document.getElementById("button").getBoundingClientRect(); left = buttonrect.left + 6; top = buttonrect.top + 6; - } - else { + } else { let iframerect = parent.document.getElementById("frame").getBoundingClientRect(); let buttonrect = parent.document.getElementById("outerbutton").getBoundingClientRect(); @@ -54,6 +54,9 @@ function popupShown() top = -(Math.round(iframerect.top) - Math.round(buttonrect.bottom) + 2); } + left += parseFloat(getComputedStyle(popup).marginLeft); + top += parseFloat(getComputedStyle(popup).marginTop); + var testid = isSecondTest ? "with mouse" : "anchored to parent frame"; parent.arguments[0].SimpleTest.is(Math.round(popuprect.left), left, "popup left " + testid); parent.arguments[0].SimpleTest.is(Math.round(popuprect.top), top, "popup top " + testid); diff --git a/toolkit/content/tests/chrome/test_contextmenu_list.xhtml b/toolkit/content/tests/chrome/test_contextmenu_list.xhtml index b47555df3d60..98827c65ccad 100644 --- a/toolkit/content/tests/chrome/test_contextmenu_list.xhtml +++ b/toolkit/content/tests/chrome/test_contextmenu_list.xhtml @@ -83,7 +83,7 @@ var gContextMenuFired = false; async function startTest() { // These tests check behavior of non-native menus, and use anchored and non-anchored popups - // somewhat interchangibly. So disable native context menus for this test. + // somewhat interchangeably. So disable native context menus for this test. // We will have separate tests for native context menu behavior, see bug 1700727. await SpecialPowers.pushPrefEnv({ set: [["widget.macos.native-context-menus", false]] }); @@ -228,14 +228,16 @@ function checkContextMenuForMenu(event) function checkPopup() { var menurect = $("themenu").getBoundingClientRect(); - + // Context menus are offset by a number of pixels from the mouse click // which activates them. This is so that they don't appear exactly // under the mouse which can cause them to be mistakenly dismissed. - // The number of pixels depends on the platform and is defined in + // The number of pixels depends on the platform and is defined in // each platform's nsLookAndFeel var contextMenuOffsetX = platformIsMac() ? 1 : 2; var contextMenuOffsetY = platformIsMac() ? -6 : 2; + contextMenuOffsetY += parseFloat(getComputedStyle($("themenu")).marginTop); + contextMenuOffsetX += parseFloat(getComputedStyle($("themenu")).marginLeft); if (gTestId == 0) { if (gTestElement == "list") { diff --git a/toolkit/content/tests/chrome/test_popup_coords.xhtml b/toolkit/content/tests/chrome/test_popup_coords.xhtml index 86c3f6158a42..1083a3a3343d 100644 --- a/toolkit/content/tests/chrome/test_popup_coords.xhtml +++ b/toolkit/content/tests/chrome/test_popup_coords.xhtml @@ -6,8 +6,8 @@ onload="setTimeout(openThePopup, 0, 'outer');" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> - - + +