Skip to content

Commit

Permalink
Bug 1849159 - Toolbar button should hide when opted out. r=shopping-r…
Browse files Browse the repository at this point in the history
…eviewers,Gijs

Differential Revision: https://phabricator.services.mozilla.com/D187052
  • Loading branch information
Niklas Baumgardner committed Sep 7, 2023
1 parent 3ff2c56 commit 4d87f3f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10052,6 +10052,11 @@ var ShoppingSidebarManager = {
document.querySelectorAll("shopping-sidebar").forEach(sidebar => {
sidebar.remove();
});

if (optedOut) {
let button = document.getElementById("shopping-sidebar-button");
button.hidden = true;
}
return;
}

Expand Down
2 changes: 2 additions & 0 deletions browser/components/shopping/content/settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ShoppingSettings extends MozLitElement {
return {
recommendationsToggleEl: "#shopping-settings-recommendations-toggle",
optOutButtonEl: "#shopping-settings-opt-out-button",
shoppingCardEl: "shopping-card",
};
}

Expand All @@ -36,6 +37,7 @@ class ShoppingSettings extends MozLitElement {

onDisableShopping() {
RPMSetPref("browser.shopping.experience2023.optedIn", 2);
RPMSetPref("browser.shopping.experience2023.active", false);
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,75 @@ add_task(async function test_sidebar_navigation() {
});
});
});

add_task(async function test_button_hidden_when_opted_out() {
await BrowserTestUtils.withNewTab(
{
url: PRODUCT_TEST_URL,
gBrowser,
},
async browser => {
let shoppingBrowser = gBrowser.ownerDocument.querySelector(
"browser.shopping-sidebar"
);

let shoppingButton = document.getElementById("shopping-sidebar-button");

ok(
BrowserTestUtils.is_visible(shoppingButton),
"Shopping Button should be visible on a product page"
);

let sidebar = gBrowser
.getPanel(browser)
.querySelector("shopping-sidebar");
Assert.ok(sidebar, "Sidebar should exist");
Assert.ok(
BrowserTestUtils.is_visible(sidebar),
"Sidebar should be visible."
);
info("Waiting for sidebar to update.");
await promiseSidebarUpdated(sidebar, PRODUCT_TEST_URL);

await SpecialPowers.spawn(shoppingBrowser, [], async () => {
let shoppingContainer =
content.document.querySelector("shopping-container").wrappedJSObject;
// shoppingContainer.data = Cu.cloneInto(mockData, content);
await shoppingContainer.updateComplete;
let shoppingSettings = shoppingContainer.settingsEl;
await shoppingSettings.updateComplete;

shoppingSettings.shoppingCardEl.detailsEl.open = true;
let optOutButton = shoppingSettings.optOutButtonEl;
optOutButton.click();
});

await BrowserTestUtils.waitForMutationCondition(
shoppingButton,
{ attributes: true, attributeFilter: ["hidden"] },
() => shoppingButton.hidden
);

ok(
!Services.prefs.getBoolPref("browser.shopping.experience2023.active"),
"Shopping sidebar is no longer active"
);
is(
Services.prefs.getIntPref("browser.shopping.experience2023.optedIn"),
2,
"Opted out of shopping experience"
);

ok(
BrowserTestUtils.is_hidden(shoppingButton),
"Shopping Button should be hidden after opting out"
);

Services.prefs.setBoolPref(
"browser.shopping.experience2023.active",
true
);
Services.prefs.setIntPref("browser.shopping.experience2023.optedIn", 1);
}
);
});

0 comments on commit 4d87f3f

Please sign in to comment.