Bug 1950524 - set newPositionCard.hasSeen shopping pref to true when RC panel is closed with X button. r=shopping-reviewers,fchasen

Differential Revision: https://phabricator.services.mozilla.com/D242237
This commit is contained in:
kpatenio
2025-03-29 01:27:59 +00:00
parent e6a58d725d
commit 901aab06ac
3 changed files with 230 additions and 160 deletions

View File

@@ -693,6 +693,18 @@ export class ShoppingContainer extends MozLitElement {
handleCloseButtonClick() {
let canShowKeepClosedMessage;
let showingNewPositionCard =
RPMGetBoolPref(INTEGRATED_SIDEBAR_PREF, false) &&
this.showNewPositionCard &&
!RPMGetBoolPref(HAS_SEEN_POSITION_NOTIFICATION_CARD_PREF, true);
// Consider the notification card as seen if the user closes RC with the X button
// when the card is already rendered.
if (showingNewPositionCard) {
this.showNewPositionCard = false;
RPMSetPref(HAS_SEEN_POSITION_NOTIFICATION_CARD_PREF, true);
}
if (this.autoOpenEnabled && this.autoOpenEnabledByUser) {
canShowKeepClosedMessage =
this._canShowKeepClosedMessageOnCloseButtonClick();

View File

@@ -12,54 +12,59 @@
const CONTENT_PAGE = "https://example.com";
const NON_PDP_PAGE = "about:about";
const HAS_SEEN_PREF = "browser.shopping.experience2023.newPositionCard.hasSeen";
const SIDEBAR_POSITION_START_PREF = "sidebar.position_start";
async function testMoveToRight() {
await withReviewCheckerSidebar(async _args => {
let card;
let shoppingContainer = await ContentTaskUtils.waitForCondition(
() =>
content.document.querySelector("shopping-container")?.wrappedJSObject,
"Review Checker is loaded."
);
await ContentTaskUtils.waitForCondition(
() => typeof shoppingContainer.showNewPositionCard !== "undefined",
"showNewPositionCard is set."
);
await shoppingContainer.updateComplete;
await withReviewCheckerSidebar(
async sidebarStartPref => {
let card;
let shoppingContainer = await ContentTaskUtils.waitForCondition(
() =>
content.document.querySelector("shopping-container")?.wrappedJSObject,
"Review Checker is loaded."
);
await ContentTaskUtils.waitForCondition(
() => typeof shoppingContainer.showNewPositionCard !== "undefined",
"showNewPositionCard is set."
);
await shoppingContainer.updateComplete;
Assert.ok(
shoppingContainer.showNewPositionCard,
"showNewPositionCard is true"
);
Assert.ok(
shoppingContainer.showNewPositionCard,
"showNewPositionCard is true"
);
card = shoppingContainer.newPositionNotificationCardEl;
Assert.ok(card, "new-position-notification-card is visible");
Assert.ok(card.moveRightButtonEl, "Card has 'Move right' button");
let buttonChangePromise = ContentTaskUtils.waitForCondition(() => {
card = shoppingContainer.newPositionNotificationCardEl;
return !!card.moveLeftButtonEl;
}, "Button changed to 'Move to left'");
Assert.ok(card, "new-position-notification-card is visible");
Assert.ok(card.moveRightButtonEl, "Card has 'Move right' button");
const { TestUtils } = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
);
let positionStartPrefUpdated = TestUtils.waitForPrefChange(
"sidebar.position_start"
);
let buttonChangePromise = ContentTaskUtils.waitForCondition(() => {
card = shoppingContainer.newPositionNotificationCardEl;
return !!card.moveLeftButtonEl;
}, "Button changed to 'Move to left'");
card.moveRightButtonEl.click();
const { TestUtils } = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
);
let positionStartPrefUpdated =
TestUtils.waitForPrefChange(sidebarStartPref);
await card.updateComplete;
await buttonChangePromise;
await positionStartPrefUpdated;
card.moveRightButtonEl.click();
card = shoppingContainer.newPositionNotificationCardEl;
Assert.ok(card.moveLeftButtonEl, "Card has 'Move to left' button");
Assert.ok(
!card.moveRightButtonEl,
"Card no longer has 'Move to right' button"
);
});
await card.updateComplete;
await buttonChangePromise;
await positionStartPrefUpdated;
card = shoppingContainer.newPositionNotificationCardEl;
Assert.ok(card.moveLeftButtonEl, "Card has 'Move to left' button");
Assert.ok(
!card.moveRightButtonEl,
"Card no longer has 'Move to right' button"
);
},
[SIDEBAR_POSITION_START_PREF]
);
}
async function testMoveToLeft() {
@@ -117,8 +122,8 @@ add_setup(async function setup() {
add_task(async function test_new_position_notification_card_visibility() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.newPositionCard.hasSeen", false],
["sidebar.position_start", true],
[HAS_SEEN_PREF, false],
[SIDEBAR_POSITION_START_PREF, true],
],
});
/* First, load a non PDP so that we can then make RC auto open once we
@@ -220,9 +225,7 @@ add_task(async function test_new_position_notification_card_visibility() {
Assert.ok(!card, "Card is no longer visible");
});
let hasSeen = Services.prefs.getBoolPref(
"browser.shopping.experience2023.newPositionCard.hasSeen"
);
let hasSeen = Services.prefs.getBoolPref(HAS_SEEN_PREF);
// We check that the pref is still false here since there is no further user action.
Assert.ok(
@@ -243,8 +246,8 @@ add_task(async function test_new_position_notification_card_visibility() {
add_task(async function test_new_position_notification_card_change_position() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.newPositionCard.hasSeen", false],
["sidebar.position_start", true],
[HAS_SEEN_PREF, false],
[SIDEBAR_POSITION_START_PREF, true],
],
});
await BrowserTestUtils.withNewTab(PRODUCT_TEST_URL, async _browser => {
@@ -256,30 +259,26 @@ add_task(async function test_new_position_notification_card_change_position() {
await TestUtils.waitForTick();
let hasSeen = Services.prefs.getBoolPref(
"browser.shopping.experience2023.newPositionCard.hasSeen"
);
let hasSeen = Services.prefs.getBoolPref(HAS_SEEN_PREF);
Assert.ok(
!hasSeen,
"browser.shopping.experience2023.newPositionCard.hasSeen is false after reverse position"
);
let startPosition = Services.prefs.getBoolPref("sidebar.position_start");
let startPosition = Services.prefs.getBoolPref(SIDEBAR_POSITION_START_PREF);
Assert.ok(!startPosition, "sidebar.position_start is false");
await testMoveToLeft();
await TestUtils.waitForTick();
hasSeen = Services.prefs.getBoolPref(
"browser.shopping.experience2023.newPositionCard.hasSeen"
);
hasSeen = Services.prefs.getBoolPref(HAS_SEEN_PREF);
Assert.ok(
!hasSeen,
"browser.shopping.experience2023.newPositionCard.hasSeen is still false after undoing reverse position"
);
startPosition = Services.prefs.getBoolPref("sidebar.position_start");
startPosition = Services.prefs.getBoolPref(SIDEBAR_POSITION_START_PREF);
Assert.ok(startPosition, "sidebar.position_start is now true");
});
SidebarController.hide();
@@ -292,8 +291,8 @@ add_task(async function test_new_position_notification_card_change_position() {
add_task(async function test_new_position_notification_card_dismiss() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.newPositionCard.hasSeen", false],
["sidebar.position_start", true],
[HAS_SEEN_PREF, false],
[SIDEBAR_POSITION_START_PREF, true],
],
});
await BrowserTestUtils.withNewTab(PRODUCT_TEST_URL, async _browser => {
@@ -334,15 +333,13 @@ add_task(async function test_new_position_notification_card_dismiss() {
await TestUtils.waitForTick();
let hasSeen = Services.prefs.getBoolPref(
"browser.shopping.experience2023.newPositionCard.hasSeen"
);
let hasSeen = Services.prefs.getBoolPref(HAS_SEEN_PREF);
Assert.ok(
hasSeen,
"browser.shopping.experience2023.newPositionCard.hasSeen is true"
);
let startPosition = Services.prefs.getBoolPref("sidebar.position_start");
let startPosition = Services.prefs.getBoolPref(SIDEBAR_POSITION_START_PREF);
Assert.ok(startPosition, "sidebar.position_start is still true");
});
SidebarController.hide();
@@ -356,8 +353,8 @@ add_task(async function test_new_position_notification_card_dismiss() {
add_task(async function test_new_position_notification_card_show_settings() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.newPositionCard.hasSeen", false],
["sidebar.position_start", true],
[HAS_SEEN_PREF, false],
[SIDEBAR_POSITION_START_PREF, true],
],
});
await BrowserTestUtils.withNewTab(PRODUCT_TEST_URL, async _browser => {
@@ -399,15 +396,13 @@ add_task(async function test_new_position_notification_card_show_settings() {
"The sidebar settings panel is open"
);
let hasSeen = Services.prefs.getBoolPref(
"browser.shopping.experience2023.newPositionCard.hasSeen"
);
let hasSeen = Services.prefs.getBoolPref(HAS_SEEN_PREF);
Assert.ok(
hasSeen,
"browser.shopping.experience2023.newPositionCard.hasSeen is true"
);
let startPosition = Services.prefs.getBoolPref("sidebar.position_start");
let startPosition = Services.prefs.getBoolPref(SIDEBAR_POSITION_START_PREF);
Assert.ok(startPosition, "sidebar.position_start is still true");
});
SidebarController.hide();
@@ -421,8 +416,8 @@ add_task(async function test_new_position_notification_card_show_settings() {
add_task(async function test_new_position_notification_card_rtl() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.newPositionCard.hasSeen", false],
["sidebar.position_start", true],
[HAS_SEEN_PREF, false],
[SIDEBAR_POSITION_START_PREF, true],
// Mock RTL
["intl.l10n.pseudo", "bidi"],
],
@@ -448,15 +443,13 @@ add_task(async function test_new_position_notification_card_rtl() {
await TestUtils.waitForTick();
let hasSeen = Services.prefs.getBoolPref(
"browser.shopping.experience2023.newPositionCard.hasSeen"
);
let hasSeen = Services.prefs.getBoolPref(HAS_SEEN_PREF);
Assert.ok(
!hasSeen,
"browser.shopping.experience2023.newPositionCard.hasSeen is false after reverse position"
);
let startPosition = Services.prefs.getBoolPref("sidebar.position_start");
let startPosition = Services.prefs.getBoolPref(SIDEBAR_POSITION_START_PREF);
Assert.ok(!startPosition, "sidebar.position_start is false");
await withReviewCheckerSidebar(async _args => {
@@ -475,17 +468,76 @@ add_task(async function test_new_position_notification_card_rtl() {
await TestUtils.waitForTick();
hasSeen = Services.prefs.getBoolPref(
"browser.shopping.experience2023.newPositionCard.hasSeen"
);
hasSeen = Services.prefs.getBoolPref(HAS_SEEN_PREF);
Assert.ok(
!hasSeen,
"browser.shopping.experience2023.newPositionCard.hasSeen is still false after undoing reverse position"
);
startPosition = Services.prefs.getBoolPref("sidebar.position_start");
startPosition = Services.prefs.getBoolPref(SIDEBAR_POSITION_START_PREF);
Assert.ok(startPosition, "sidebar.position_start is now true");
});
SidebarController.hide();
await SpecialPowers.popPrefEnv();
});
/**
* Tests that notification card is considered seen once the RC panel is closed via the X button.
*/
add_task(
async function test_new_position_notification_card_hasSeen_close_with_X() {
await SpecialPowers.pushPrefEnv({
set: [
[HAS_SEEN_PREF, false],
[SIDEBAR_POSITION_START_PREF, true],
],
});
await BrowserTestUtils.withNewTab(PRODUCT_TEST_URL, async _browser => {
await SidebarController.show("viewReviewCheckerSidebar");
info("Waiting for sidebar to update.");
await reviewCheckerSidebarUpdated(PRODUCT_TEST_URL);
let prefChangedPromise = TestUtils.waitForPrefChange(HAS_SEEN_PREF);
await withReviewCheckerSidebar(async _args => {
let card;
let shoppingContainer = await ContentTaskUtils.waitForCondition(
() =>
content.document.querySelector("shopping-container")
?.wrappedJSObject,
"Review Checker is loaded."
);
await ContentTaskUtils.waitForCondition(
() => typeof shoppingContainer.showNewPositionCard !== "undefined",
"showNewPositionCard is set."
);
await shoppingContainer.updateComplete;
Assert.ok(
shoppingContainer.showNewPositionCard,
"showNewPositionCard is true"
);
card = shoppingContainer.newPositionNotificationCardEl;
Assert.ok(card, "new-position-notification-card is visible");
Assert.ok(
shoppingContainer.closeButtonEl,
"Sidebar close button is visible"
);
shoppingContainer.closeButtonEl.click();
});
await prefChangedPromise;
let hasSeen = Services.prefs.getBoolPref(HAS_SEEN_PREF);
Assert.ok(
hasSeen,
"browser.shopping.experience2023.newPositionCard.hasSeen is true"
);
});
SidebarController.hide();
await SpecialPowers.popPrefEnv();
}
);

View File

@@ -11,6 +11,14 @@
const NON_PDP_PAGE = "about:about";
const HAS_SEEN_PREF = "browser.shopping.experience2023.newPositionCard.hasSeen";
const SIDEBAR_POSITION_START_PREF = "sidebar.position_start";
const SHOW_KEEP_MESSAGE_PREF =
"browser.shopping.experience2023.showKeepSidebarClosedMessage";
/**
* Checks that the notification card is visible. Closes RC afterwards.
*/
async function testNotificationCardThenCloseRC() {
await withReviewCheckerSidebar(async _args => {
let shoppingContainer = await ContentTaskUtils.waitForCondition(
@@ -38,19 +46,15 @@ async function testNotificationCardThenCloseRC() {
shoppingContainer.closeButtonEl.click();
await shoppingContainer.updateComplete;
Assert.ok(
!shoppingContainer.showingKeepClosedMessage,
"showingKeepClosedMessage is false"
);
Assert.ok(
!shoppingContainer.keepClosedMessageBarEl,
"'Keep closed' message is not visible"
);
});
}
async function testDismissNotificationThenCheckKeepClosed() {
/**
* Checks that the notification card is visible before closing the RC panel.
* Then, dismisses the notification card, checks card visibility, and closes
* the RC panel.
*/
async function testDismissNotificationThenCloseRC() {
await withReviewCheckerSidebar(async _args => {
let shoppingContainer = await ContentTaskUtils.waitForCondition(
() =>
@@ -99,7 +103,10 @@ async function testDismissNotificationThenCheckKeepClosed() {
});
}
async function testKeepClosedAfterNotificationDismissed() {
/**
* Checks that the keep closed message is visible in RC.
*/
async function testKeepClosedIsVisible() {
await withReviewCheckerSidebar(async _args => {
let shoppingContainer = await ContentTaskUtils.waitForCondition(
() =>
@@ -146,15 +153,15 @@ add_setup(async function setup() {
/**
* Tests that the 'Keep closed' message does not appear when the notification card
* is set to be displayed. Only show the message once the notification card is dismissed.
* is set to be displayed.
*/
add_task(
async function test_do_not_show_keep_closed_until_notification_dismissed() {
async function test_do_not_show_keep_closed_if_notification_card_visible() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.newPositionCard.hasSeen", false],
["sidebar.position_start", true],
["browser.shopping.experience2023.showKeepSidebarClosedMessage", true],
[HAS_SEEN_PREF, false],
[SIDEBAR_POSITION_START_PREF, true],
[SHOW_KEEP_MESSAGE_PREF, true],
// Set to minimum closed counts met, to speed up testing
["browser.shopping.experience2023.sidebarClosedCount", 4],
],
@@ -164,6 +171,8 @@ add_task(
info("Waiting for sidebar to update.");
await reviewCheckerSidebarUpdated(PRODUCT_TEST_URL);
let hasSeenPrefUpdated = TestUtils.waitForPrefChange(HAS_SEEN_PREF);
await testNotificationCardThenCloseRC();
Assert.ok(
@@ -171,48 +180,44 @@ add_task(
"Sidebar is closed without a problem"
);
let hasSeen = Services.prefs.getBoolPref(
"browser.shopping.experience2023.newPositionCard.hasSeen"
);
await hasSeenPrefUpdated;
let hasSeen = Services.prefs.getBoolPref(HAS_SEEN_PREF);
Assert.ok(
!hasSeen,
"browser.shopping.experience2023.newPositionCard.hasSeen is still false"
hasSeen,
"browser.shopping.experience2023.newPositionCard.hasSeen is true after closing RC"
);
});
// Let's open another tab, to force auto open and show the notification card again
let newProductTab = BrowserTestUtils.addTab(
gBrowser,
OTHER_PRODUCT_TEST_URL
);
let newProductBrowser = newProductTab.linkedBrowser;
let browserLoadedPromise = BrowserTestUtils.browserLoaded(
newProductBrowser,
false,
OTHER_PRODUCT_TEST_URL
);
await browserLoadedPromise;
await SpecialPowers.popPrefEnv();
}
);
let shownPromise = BrowserTestUtils.waitForEvent(window, "SidebarShown");
info("Switching tabs now");
await BrowserTestUtils.switchTab(gBrowser, newProductTab);
Assert.ok(true, "Browser is loaded");
info("Waiting for shown");
await shownPromise;
await TestUtils.waitForTick();
Assert.ok(SidebarController.isOpen, "Sidebar is open now");
/**
* Tests that the 'Keep closed' message is shown after dismissing the notification card.
*/
add_task(
async function test_do_not_show_keep_closed_until_notification_dismissed() {
await SpecialPowers.pushPrefEnv({
set: [
[HAS_SEEN_PREF, false],
[SIDEBAR_POSITION_START_PREF, true],
[SHOW_KEEP_MESSAGE_PREF, true],
// Set to minimum closed counts met, to speed up testing
["browser.shopping.experience2023.sidebarClosedCount", 4],
],
});
await BrowserTestUtils.withNewTab(PRODUCT_TEST_URL, async _browser => {
await SidebarController.show("viewReviewCheckerSidebar");
info("Waiting for sidebar to update.");
await reviewCheckerSidebarUpdated(PRODUCT_TEST_URL);
// Now, check content again to dismiss the notification and verify "Keep closed"
await testDismissNotificationThenCheckKeepClosed();
await testDismissNotificationThenCloseRC();
Assert.ok(SidebarController.isOpen, "Sidebar is still open");
hasSeen = Services.prefs.getBoolPref(
"browser.shopping.experience2023.newPositionCard.hasSeen"
);
let hasSeen = Services.prefs.getBoolPref(HAS_SEEN_PREF);
Assert.ok(
hasSeen,
"browser.shopping.experience2023.newPositionCard.hasSeen is now true"
@@ -224,10 +229,9 @@ add_task(
"Asserting false. Cannot test 'Keep closed' message if sidebar is closed"
);
} else {
await testKeepClosedAfterNotificationDismissed();
Assert.ok(true, "Sidebar is not closed yet");
await testKeepClosedIsVisible();
}
await BrowserTestUtils.removeTab(newProductTab);
});
SidebarController.hide();
@@ -238,8 +242,8 @@ add_task(
add_task(async function test_keep_closed_message_not_visible_non_pdp() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.newPositionCard.hasSeen", true],
["browser.shopping.experience2023.showKeepSidebarClosedMessage", true],
[HAS_SEEN_PREF, true],
[SHOW_KEEP_MESSAGE_PREF, true],
// Set to minimum closed counts met, to speed up testing
["browser.shopping.experience2023.sidebarClosedCount", 4],
],
@@ -263,14 +267,12 @@ add_task(async function test_keep_closed_message_not_visible_non_pdp() {
await shoppingContainer.updateComplete;
info("Shopping container update complete");
let keepClosedPromise = ContentTaskUtils.waitForCondition(
() => shoppingContainer.keepClosedMessageBarEl,
"Keep closed message is visible."
);
shoppingContainer.closeButtonEl.click();
await keepClosedPromise;
await ContentTaskUtils.waitForCondition(
() => shoppingContainer.keepClosedMessageBarEl,
"Keep closed message is visible"
);
});
let nonPDPTab = BrowserTestUtils.addTab(gBrowser, NON_PDP_PAGE);
@@ -288,35 +290,39 @@ add_task(async function test_keep_closed_message_not_visible_non_pdp() {
Assert.ok(true, "Browser is loaded");
await SidebarController.show("viewReviewCheckerSidebar");
await withReviewCheckerSidebar(async _args => {
let shoppingContainer = await ContentTaskUtils.waitForCondition(
() =>
content.document.querySelector("shopping-container")?.wrappedJSObject,
"Review Checker is loaded."
);
await withReviewCheckerSidebar(
async showKeepClosedMessagePref => {
let shoppingContainer = await ContentTaskUtils.waitForCondition(
() =>
content.document.querySelector("shopping-container")
?.wrappedJSObject,
"Review Checker is loaded."
);
await shoppingContainer.updateComplete;
await shoppingContainer.updateComplete;
Assert.ok(
!shoppingContainer.keepClosedMessageBarEl,
"'Keep closed' message is not visible before close button click"
);
Assert.ok(
!shoppingContainer.keepClosedMessageBarEl,
"'Keep closed' message is not visible before close button click"
);
shoppingContainer.closeButtonEl.click();
shoppingContainer.closeButtonEl.click();
let showKeepSidebarClosedMessage = Services.prefs.getBoolPref(
"browser.shopping.experience2023.showKeepSidebarClosedMessage"
);
Assert.ok(
!shoppingContainer.keepClosedMessageBarEl,
"'Keep closed' message is not visible after close button click"
);
Assert.ok(
showKeepSidebarClosedMessage,
"browser.shopping.experience2023.showKeepSidebarClosedMessage is true"
);
});
let showKeepSidebarClosedMessage = Services.prefs.getBoolPref(
showKeepClosedMessagePref
);
Assert.ok(
!SidebarController.isOpen,
"'Keep closed' message did not prevent sidebar from closing"
Assert.ok(
showKeepSidebarClosedMessage,
"browser.shopping.experience2023.showKeepSidebarClosedMessage is true"
);
},
[SHOW_KEEP_MESSAGE_PREF]
);
await BrowserTestUtils.removeTab(nonPDPTab);