Bug 1852622 - Add a test-only firefoxview-entered notification, and modify the test helpers to use it. r=sclements,fxview-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D189443
This commit is contained in:
Sam Foster 2023-10-05 23:44:56 +00:00
parent 4a2eed2ffb
commit 3d1fa88e86
7 changed files with 76 additions and 12 deletions

View File

@ -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");
}
}
});

View File

@ -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.

View File

@ -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,
};

View File

@ -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",

View File

@ -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";

View File

@ -11,9 +11,11 @@ const {
assertFirefoxViewTab,
openFirefoxViewTab,
closeFirefoxViewTab,
init: FirefoxViewTestUtilsInit,
} = ChromeUtils.importESModule(
"resource://testing-common/FirefoxViewTestUtils.sys.mjs"
);
FirefoxViewTestUtilsInit(this);
const TEST_MESSAGE = {
message: {

View File

@ -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({