From c961670a08388f0219cce28da20278f72603dd46 Mon Sep 17 00:00:00 2001 From: Fred Chasen Date: Mon, 16 Sep 2024 17:18:35 +0000 Subject: [PATCH] Bug 1917996 - Disable Shopping sidebar when integrated sidebar pref is set. r=shopping-reviewers,kpatenio Differential Revision: https://phabricator.services.mozilla.com/D221871 --- .../shopping/ShoppingSidebarParent.sys.mjs | 19 +++++- .../tests/browser/browser_shopping_sidebar.js | 63 +++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/browser/components/shopping/ShoppingSidebarParent.sys.mjs b/browser/components/shopping/ShoppingSidebarParent.sys.mjs index d35ce0ac5509..1bf3d564c319 100644 --- a/browser/components/shopping/ShoppingSidebarParent.sys.mjs +++ b/browser/components/shopping/ShoppingSidebarParent.sys.mjs @@ -198,6 +198,13 @@ class ShoppingSidebarManagerClass { true, this.updateSidebarVisibility ); + XPCOMUtils.defineLazyPreferenceGetter( + this, + "isIntegratedSidebarPanel", + "browser.shopping.experience2023.integratedSidebar", + false, + this.updateSidebarVisibility + ); this.updateSidebarVisibility(); lazy.EveryWindow.registerCallback( @@ -226,8 +233,9 @@ class ShoppingSidebarManagerClass { } updateSidebarVisibility() { - this.enabled = lazy.NimbusFeatures.shopping2023.getVariable("enabled"); - + this.enabled = + lazy.NimbusFeatures.shopping2023.getVariable("enabled") && + !this.isIntegratedSidebarPanel; for (let window of lazy.BrowserWindowTracker.orderedWindows) { let isPBM = lazy.PrivateBrowsingUtils.isWindowPrivate(window); if (isPBM) { @@ -275,6 +283,13 @@ class ShoppingSidebarManagerClass { .forEach(splitter => { splitter.remove(); }); + let button = document.getElementById("shopping-sidebar-button"); + if (button) { + button.hidden = true; + // Reset attributes to defaults. + button.setAttribute("shoppingsidebaropen", false); + document.l10n.setAttributes(button, "shopping-sidebar-open-button2"); + } return; } diff --git a/browser/components/shopping/tests/browser/browser_shopping_sidebar.js b/browser/components/shopping/tests/browser/browser_shopping_sidebar.js index 31cbc6d732ee..37427b3b671b 100644 --- a/browser/components/shopping/tests/browser/browser_shopping_sidebar.js +++ b/browser/components/shopping/tests/browser/browser_shopping_sidebar.js @@ -3,8 +3,11 @@ "use strict"; +const CONTENT_PAGE = "https://example.com"; const SHOPPING_SIDEBAR_WIDTH_PREF = "browser.shopping.experience2023.sidebarWidth"; +const SHOPPING_INTEGRATED_SIDEBAR_PREF = + "browser.shopping.experience2023.integratedSidebar"; add_task(async function test_sidebar_opens_correct_size() { await SpecialPowers.pushPrefEnv({ @@ -64,3 +67,63 @@ add_task(async function test_sidebar_opens_correct_size() { gBrowser.removeTab(tab); }); + +add_task(async function test_sidebar_and_button_not_present_if_integrated() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["toolkit.shopping.ohttpRelayURL", ""], + ["toolkit.shopping.ohttpConfigURL", ""], + [SHOPPING_INTEGRATED_SIDEBAR_PREF, false], + ], + }); + + await BrowserTestUtils.withNewTab(CONTENT_PAGE, async function (browser) { + let browserPanel = gBrowser.getPanel(browser); + + BrowserTestUtils.startLoadingURIString(browser, PRODUCT_TEST_URL); + await BrowserTestUtils.browserLoaded(browser); + + let sidebar = browserPanel.querySelector("shopping-sidebar"); + + ok(BrowserTestUtils.isVisible(sidebar), "Shopping sidebar should be open"); + + let shoppingButton = document.getElementById("shopping-sidebar-button"); + ok( + BrowserTestUtils.isVisible(shoppingButton), + "Shopping Button should be visible" + ); + + let prefChangedPromise = TestUtils.waitForPrefChange( + SHOPPING_INTEGRATED_SIDEBAR_PREF + ); + Services.prefs.setBoolPref(SHOPPING_INTEGRATED_SIDEBAR_PREF, true); + await prefChangedPromise; + + sidebar = browserPanel.querySelector("shopping-sidebar"); + is(sidebar, null, "Shopping Sidebar should be removed"); + + shoppingButton = document.getElementById("shopping-sidebar-button"); + ok( + BrowserTestUtils.isHidden(shoppingButton), + "Shopping Button should be hidden" + ); + + prefChangedPromise = TestUtils.waitForPrefChange( + SHOPPING_INTEGRATED_SIDEBAR_PREF + ); + Services.prefs.setBoolPref(SHOPPING_INTEGRATED_SIDEBAR_PREF, false); + await prefChangedPromise; + + sidebar = browserPanel.querySelector("shopping-sidebar"); + ok(BrowserTestUtils.isVisible(sidebar), "Shopping sidebar should be open"); + + shoppingButton = document.getElementById("shopping-sidebar-button"); + ok( + BrowserTestUtils.isVisible(shoppingButton), + "Shopping Button should be visible" + ); + }); + + Services.prefs.clearUserPref(SHOPPING_INTEGRATED_SIDEBAR_PREF); + await SpecialPowers.popPrefEnv(); +});