diff --git a/browser/components/firefoxview/firefoxview-next.mjs b/browser/components/firefoxview/firefoxview-next.mjs index 55c576e07e0d..938a87a86d69 100644 --- a/browser/components/firefoxview/firefoxview-next.mjs +++ b/browser/components/firefoxview/firefoxview-next.mjs @@ -61,6 +61,9 @@ window.addEventListener("DOMContentLoaded", async () => { if (document.location.hash) { changePage(document.location.hash.substring(1)); } + if (Cu.isInAutomation) { + Services.obs.notifyObservers(null, "firefoxview-entered"); + } }); document @@ -78,6 +81,9 @@ document document.addEventListener("visibilitychange", () => { if (document.visibilityState === "visible") { recordEnteredTelemetry(); + if (Cu.isInAutomation) { + Services.obs.notifyObservers(null, "firefoxview-entered"); + } } }); diff --git a/browser/components/firefoxview/firefoxview.mjs b/browser/components/firefoxview/firefoxview.mjs index 02b132126a75..e30e6c48d207 100644 --- a/browser/components/firefoxview/firefoxview.mjs +++ b/browser/components/firefoxview/firefoxview.mjs @@ -4,6 +4,15 @@ window.addEventListener("DOMContentLoaded", async () => { Services.telemetry.recordEvent("firefoxview", "entered", "firefoxview", null); + if (Cu.isInAutomation) { + Services.obs.notifyObservers(null, "firefoxview-entered"); + document.addEventListener("visibilitychange", () => { + if (document.visibilityState === "visible") { + Services.obs.notifyObservers(null, "firefoxview-entered"); + } + }); + } + document.getElementById("recently-closed-tabs-container").onLoad(); // If Firefox View was reloaded by the user, force syncing of tabs // to get the most up to date synced tabs. diff --git a/browser/components/firefoxview/tests/browser/FirefoxViewTestUtils.sys.mjs b/browser/components/firefoxview/tests/browser/FirefoxViewTestUtils.sys.mjs index 82adc8924bd7..3b47a5d6d327 100644 --- a/browser/components/firefoxview/tests/browser/FirefoxViewTestUtils.sys.mjs +++ b/browser/components/firefoxview/tests/browser/FirefoxViewTestUtils.sys.mjs @@ -5,6 +5,24 @@ import { BrowserTestUtils } from "resource://testing-common/BrowserTestUtils.sys import { Assert } from "resource://testing-common/Assert.sys.mjs"; import { TestUtils } from "resource://testing-common/TestUtils.sys.mjs"; +var testScope; + +/** + * Module consumers can optionally initialize the module + * + * @param {Object} scope + * object with SimpleTest and info properties. + */ +function init(scope) { + testScope = scope; +} + +function getFirefoxViewURL() { + return Services.prefs.getBoolPref("browser.tabs.firefox-view-next", true) + ? "about:firefoxview-next" + : "about:firefoxview"; +} + function assertFirefoxViewTab(win) { Assert.ok(win.FirefoxViewHandler.tab, "Firefox View tab exists"); Assert.ok(win.FirefoxViewHandler.tab?.hidden, "Firefox View tab is hidden"); @@ -27,6 +45,18 @@ async function assertFirefoxViewTabSelected(win) { } async function openFirefoxViewTab(win) { + if (!testScope?.SimpleTest) { + throw new Error( + "Must initialize FirefoxViewTestUtils with a test scope which has a SimpleTest property" + ); + } + await testScope.SimpleTest.promiseFocus(win); + + const fxViewTab = win.FirefoxViewHandler.tab; + const alreadyLoaded = + fxViewTab?.linkedBrowser?.currentURI.spec.split("#")[0] == + getFirefoxViewURL(); + const enteredPromise = TestUtils.topicObserved("firefoxview-entered"); await BrowserTestUtils.synthesizeMouseAtCenter( "#firefox-view-button", { type: "mousedown" }, @@ -37,9 +67,14 @@ async function openFirefoxViewTab(win) { win.FirefoxViewHandler.tab.selected, "Firefox View tab is selected" ); - await BrowserTestUtils.browserLoaded( - win.FirefoxViewHandler.tab.linkedBrowser - ); + + if (!alreadyLoaded) { + testScope.info("Not already loaded, waiting for browserLoaded"); + await BrowserTestUtils.browserLoaded( + win.FirefoxViewHandler.tab.linkedBrowser + ); + } + await enteredPromise; return win.FirefoxViewHandler.tab; } @@ -111,14 +146,16 @@ async function withFirefoxView( } function isFirefoxViewTabSelectedInWindow(win) { - return win.gBrowser.selectedBrowser.currentURI.spec == "about:firefoxview"; + return win.gBrowser.selectedBrowser.currentURI.spec == getFirefoxViewURL(); } export { + init, withFirefoxView, assertFirefoxViewTab, assertFirefoxViewTabSelected, openFirefoxViewTab, closeFirefoxViewTab, isFirefoxViewTabSelectedInWindow, + getFirefoxViewURL, }; diff --git a/browser/components/firefoxview/tests/browser/head.js b/browser/components/firefoxview/tests/browser/head.js index 4f6e0424e611..11710c5ef0ac 100644 --- a/browser/components/firefoxview/tests/browser/head.js +++ b/browser/components/firefoxview/tests/browser/head.js @@ -8,6 +8,7 @@ const { openFirefoxViewTab, closeFirefoxViewTab, isFirefoxViewTabSelectedInWindow, + init: FirefoxViewTestUtilsInit, } = ChromeUtils.importESModule( "resource://testing-common/FirefoxViewTestUtils.sys.mjs" ); @@ -35,6 +36,7 @@ const { SessionStoreTestUtils } = ChromeUtils.importESModule( "resource://testing-common/SessionStoreTestUtils.sys.mjs" ); SessionStoreTestUtils.init(this, window); +FirefoxViewTestUtilsInit(this, window); ChromeUtils.defineESModuleGetters(this, { AboutWelcomeParent: "resource:///actors/AboutWelcomeParent.sys.mjs", diff --git a/browser/components/newtab/test/browser/browser_aboutwelcome_upgrade_multistage_mr.js b/browser/components/newtab/test/browser/browser_aboutwelcome_upgrade_multistage_mr.js index a7c94b012bd0..5d36c66f58f2 100644 --- a/browser/components/newtab/test/browser/browser_aboutwelcome_upgrade_multistage_mr.js +++ b/browser/components/newtab/test/browser/browser_aboutwelcome_upgrade_multistage_mr.js @@ -6,10 +6,14 @@ const { OnboardingMessageProvider } = ChromeUtils.import( const { SpecialMessageActions } = ChromeUtils.importESModule( "resource://messaging-system/lib/SpecialMessageActions.sys.mjs" ); -const { assertFirefoxViewTabSelected, closeFirefoxViewTab } = - ChromeUtils.importESModule( - "resource://testing-common/FirefoxViewTestUtils.sys.mjs" - ); +const { + assertFirefoxViewTabSelected, + closeFirefoxViewTab, + init: FirefoxViewTestUtilsInit, +} = ChromeUtils.importESModule( + "resource://testing-common/FirefoxViewTestUtils.sys.mjs" +); +FirefoxViewTestUtilsInit(this); const HOMEPAGE_PREF = "browser.startup.homepage"; const NEWTAB_PREF = "browser.newtabpage.enabled"; diff --git a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_click_element.js b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_click_element.js index 23453909b389..78a1255444e1 100644 --- a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_click_element.js +++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_click_element.js @@ -11,9 +11,11 @@ const { assertFirefoxViewTab, openFirefoxViewTab, closeFirefoxViewTab, + init: FirefoxViewTestUtilsInit, } = ChromeUtils.importESModule( "resource://testing-common/FirefoxViewTestUtils.sys.mjs" ); +FirefoxViewTestUtilsInit(this); const TEST_MESSAGE = { message: { diff --git a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_open_firefox_view.js b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_open_firefox_view.js index 110d86412140..b79356711dd5 100644 --- a/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_open_firefox_view.js +++ b/toolkit/components/messaging-system/schemas/SpecialMessageActionSchemas/test/browser/browser_sma_open_firefox_view.js @@ -3,10 +3,14 @@ "use strict"; -const { assertFirefoxViewTab, closeFirefoxViewTab } = - ChromeUtils.importESModule( - "resource://testing-common/FirefoxViewTestUtils.sys.mjs" - ); +const { + assertFirefoxViewTab, + closeFirefoxViewTab, + init: FirefoxViewTestUtilsInit, +} = ChromeUtils.importESModule( + "resource://testing-common/FirefoxViewTestUtils.sys.mjs" +); +FirefoxViewTestUtilsInit(this); add_setup(async () => { await SpecialPowers.pushPrefEnv({