Files
tubestation/browser/components/shopping/ReviewCheckerParent.sys.mjs
Fred Chasen b7006f76c9 Bug 1939621 - Update tests to run with both ShoppingSidebar and ReviewChecker actors. r=shopping-reviewers,rking,kpatenio
- Adds a `browser_reviewchecker.toml` to run tests specific to the Review Checker sidebar and common "about:shoppingsidebar" UI tests with the ReviewChecker actors enabled.
- Prefaces Review Checker test filenames with `browser_reviewchecker_`.
- Only runs shopping sidebar specific tests in `browser.toml` and prefaces those filenames with `browser_shoppingsidebar_`.
- Splits out parts of test files that are specific only to one actor.
- Renames all common tests to `browser_shopping_`
- Updates `ReviewCheckerParent` to not return a url on `about:shoppingsidebar` so it is not handled valid non-product page, replicating the behavior of the current sidebar tests.
- Adds versions of sidebar test helper methods that work with the new sidebar.

Differential Revision: https://phabricator.services.mozilla.com/D233121
2025-01-08 23:15:08 +00:00

119 lines
3.5 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
isSupportedSiteURL: "chrome://global/content/shopping/ShoppingProduct.mjs",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
ShoppingUtils: "resource:///modules/ShoppingUtils.sys.mjs",
});
const ABOUT_SHOPPING_SIDEBAR = "about:shoppingsidebar";
/**
* When a Review Checker sidebar panel is open ReviewCheckerParent
* handles listening for location changes and determining if the
* location or the current URI is a product or not.
*
* The ReviewCheckerChild will use that info to update the sidebar UI.
*
* This is a simplified version of the `ShoppingSidebarParent` for
* using the shopping components in the main sidebar instead of the
* custom shopping sidebar.
*/
export class ReviewCheckerParent extends JSWindowActorParent {
static SHOPPING_OPTED_IN_PREF = "browser.shopping.experience2023.optedIn";
actorCreated() {
this.topBrowserWindow = this.browsingContext.topChromeWindow;
this.topBrowserWindow.gBrowser.addProgressListener(this);
}
didDestroy() {
if (this.topBrowserWindow) {
this.topBrowserWindow.gBrowser.removeProgressListener(this);
this.topBrowserWindow = undefined;
}
}
updateCurrentURL(uri, flags, isSupportedSite) {
// about:shoppingsidebar is only used for testing with fake data.
if (!uri || uri.spec == ABOUT_SHOPPING_SIDEBAR) {
return;
}
this.sendAsyncMessage("ShoppingSidebar:UpdateProductURL", {
url: uri.spec,
isReload: !!(flags & Ci.nsIWebProgressListener.LOCATION_CHANGE_RELOAD),
isSupportedSite,
});
}
getCurrentURL() {
let window = this.browsingContext.topChromeWindow;
let { selectedBrowser } = window.gBrowser;
let uri = selectedBrowser.currentURI;
// about:shoppingsidebar is only used for testing with fake data.
if (!uri || uri.spec == ABOUT_SHOPPING_SIDEBAR) {
return null;
}
return uri.spec;
}
async receiveMessage(message) {
if (this.browsingContext.usePrivateBrowsing) {
throw new Error("We should never be invoked in PBM.");
}
switch (message.name) {
case "GetProductURL":
return this.getCurrentURL();
case "DisableShopping":
Services.prefs.setIntPref(
ReviewCheckerParent.SHOPPING_OPTED_IN_PREF,
2
);
break;
case "CloseShoppingSidebar":
this.closeSidebarPanel();
break;
}
return null;
}
/**
* Called by TabsProgressListener whenever any browser navigates from one
* URL to another.
* Note that this includes hash changes / pushState navigations, because
* those can be significant for us.
*/
onLocationChange(aWebProgress, _aRequest, aLocationURI, aFlags) {
if (aWebProgress && !aWebProgress.isTopLevel) {
return;
}
let isPBM = lazy.PrivateBrowsingUtils.isWindowPrivate(
this.topBrowserWindow
);
if (isPBM) {
return;
}
lazy.ShoppingUtils.onLocationChange(aLocationURI, aFlags);
this.updateCurrentURL(
aLocationURI,
aFlags,
lazy.isSupportedSiteURL(aLocationURI)
);
}
closeSidebarPanel() {
let window = this.browsingContext.topChromeWindow;
let { SidebarController } = window;
if (SidebarController?.isOpen) {
SidebarController.hide();
}
}
}