From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../browser/browser_ext_popup_select_in_oopif.js | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 browser/components/extensions/test/browser/browser_ext_popup_select_in_oopif.js (limited to 'browser/components/extensions/test/browser/browser_ext_popup_select_in_oopif.js') 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 new file mode 100644 index 0000000000..fa2c414047 --- /dev/null +++ b/browser/components/extensions/test/browser/browser_ext_popup_select_in_oopif.js @@ -0,0 +1,131 @@ +/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set sts=2 sw=2 et tw=80: */ +"use strict"; + +// This test is based on browser_ext_popup_select.js. + +const iframeSrc = encodeURIComponent(` + + + +`); + +add_task(async function testPopupSelectPopup() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + browser_action: { + default_popup: "popup.html", + browser_style: false, + }, + }, + + files: { + "popup.html": ` + + + + + + + `, + }, + }); + + await extension.startup(); + + const browserForPopup = await openBrowserActionPanel( + extension, + undefined, + true + ); + + const iframe = await SpecialPowers.spawn(browserForPopup, [], async () => { + await ContentTaskUtils.waitForCondition(() => { + return content.document && content.document.querySelector("iframe"); + }); + const iframeElement = content.document.querySelector("iframe"); + + await ContentTaskUtils.waitForCondition(() => { + return iframeElement.browsingContext; + }); + return iframeElement.browsingContext; + }); + + const selectRect = await SpecialPowers.spawn(iframe, [], async () => { + await ContentTaskUtils.waitForCondition(() => { + return content.document.querySelector("select"); + }); + const select = content.document.querySelector("select"); + const focusPromise = new Promise(resolve => { + select.addEventListener("focus", resolve, { once: true }); + }); + select.focus(); + await focusPromise; + + const r = select.getBoundingClientRect(); + + return { left: r.left, bottom: r.bottom }; + }); + + const popupPromise = BrowserTestUtils.waitForSelectPopupShown(window); + + BrowserTestUtils.synthesizeMouseAtCenter("select", {}, iframe); + + const selectPopup = await popupPromise; + + let popupRect = selectPopup.getOuterScreenRect(); + let popupMarginLeft = parseFloat(getComputedStyle(selectPopup).marginLeft); + let popupMarginTop = parseFloat(getComputedStyle(selectPopup).marginTop); + + const offsetToSelectedItem = + selectPopup.querySelector("menuitem[selected]").getBoundingClientRect() + .top - selectPopup.getBoundingClientRect().top; + info( + `Browser is at ${browserForPopup.screenY}, popup is at ${popupRect.top} with ${offsetToSelectedItem} to the selected item` + ); + + is( + Math.floor(browserForPopup.screenX + selectRect.left), + popupRect.left - popupMarginLeft, + "Select popup has the correct x origin" + ); + + // On Mac select popup window appears aligned to the selected option. + let expectedY = navigator.platform.includes("Mac") + ? Math.floor(browserForPopup.screenY - offsetToSelectedItem) + : Math.floor(browserForPopup.screenY + selectRect.bottom); + is( + expectedY, + popupRect.top - popupMarginTop, + "Select popup has the correct y origin" + ); + + const onPopupHidden = BrowserTestUtils.waitForEvent( + selectPopup, + "popuphidden" + ); + selectPopup.hidePopup(); + await onPopupHidden; + + await closeBrowserAction(extension); + + await extension.unload(); +}); -- cgit v1.2.3