commit fac6ae44934cc89d98dffd8b6cc1fdc2ad6cbe44
parent 7c76213cf010ca22262d1e3c1b218b9cfa7a4613
Author: Micah Killoran <mtigley@mozilla.com>
Date: Wed, 19 Nov 2025 23:53:32 +0000
Bug 1996749 - Update tests for payments methods page. r=dimi,omc-reviewers,emcminn
Differential Revision: https://phabricator.services.mozilla.com/D272956
Diffstat:
2 files changed, 185 insertions(+), 108 deletions(-)
diff --git a/browser/components/asrouter/tests/browser/browser_trigger_listeners.js b/browser/components/asrouter/tests/browser/browser_trigger_listeners.js
@@ -46,6 +46,94 @@ async function waitForUrlLoad(url) {
await BrowserTestUtils.browserLoaded(browser, false, url);
}
+async function test_formAutofillTrigger(settingsRedesignEnabled) {
+ const sandbox = sinon.createSandbox();
+ const handlerStub = sandbox.stub();
+ const formAutofillTrigger = ASRouterTriggerListeners.get("formAutofill");
+ sandbox.stub(formAutofillTrigger, "_triggerDelay").value(0);
+ formAutofillTrigger.uninit();
+ formAutofillTrigger.init(handlerStub);
+
+ function notifyCreditCardSaved() {
+ Services.obs.notifyObservers(
+ {
+ wrappedJSObject: { sourceSync: false, collectionName: "creditCards" },
+ },
+ formAutofillTrigger._topic,
+ "add"
+ );
+ }
+
+ // Saving credit cards for autofill currently fails for some hardware
+ // configurations, so mock the event instead of really adding a card.
+ notifyCreditCardSaved();
+ await sleepMs(1);
+ Assert.ok(handlerStub.called, "Called after event");
+
+ // Test that the trigger doesn't fire when the credit card manager is open.
+ handlerStub.resetHistory();
+
+ await SpecialPowers.pushPrefEnv({
+ set: [["browser.settings-redesign.enabled", settingsRedesignEnabled]],
+ });
+ await BrowserTestUtils.withNewTab(
+ { gBrowser, url: "about:preferences#privacy" },
+ async browser => {
+ const redesignEnabled = Services.prefs.getBoolPref(
+ "browser.settings-redesign.enabled",
+ false
+ );
+ if (!redesignEnabled) {
+ await SpecialPowers.spawn(browser, [], async () =>
+ (
+ await ContentTaskUtils.waitForCondition(
+ () =>
+ content.document.querySelector(
+ "#formAutofillGroupBox setting-group[groupid=payments] #savedPaymentsButton"
+ ),
+ "Waiting for credit card manager button"
+ )
+ )?.click()
+ );
+ await BrowserTestUtils.waitForCondition(
+ () => browser.contentWindow?.gSubDialog?.dialogs.length
+ );
+ } else {
+ const savedPaymentsBtn = content.document.querySelector(
+ "#savedPaymentsButton"
+ );
+ savedPaymentsBtn.click();
+ const paymentsPage = content.document.querySelector(
+ '[data-category="paneManagePayments"]'
+ );
+ await BrowserTestUtils.waitForCondition(
+ () => !paymentsPage.hidden,
+ "Payments page failed to show."
+ );
+ }
+
+ notifyCreditCardSaved();
+ await sleepMs(1);
+
+ if (!redesignEnabled) {
+ Assert.ok(
+ handlerStub.notCalled,
+ "Not called when credit card manager is open"
+ );
+ }
+ }
+ );
+
+ formAutofillTrigger.uninit();
+ handlerStub.resetHistory();
+ notifyCreditCardSaved();
+ await sleepMs(1);
+ Assert.ok(handlerStub.notCalled, "Not called after uninit");
+
+ sandbox.restore();
+ formAutofillTrigger.uninit();
+}
+
add_setup(async function () {
// Runtime increases in chaos mode on Mac.
if (inChaosMode && AppConstants.platform === "macosx") {
@@ -382,66 +470,9 @@ add_task(async function test_activityAfterIdleWake() {
restore();
});
-add_task(async function test_formAutofillTrigger() {
- const sandbox = sinon.createSandbox();
- const handlerStub = sandbox.stub();
- const formAutofillTrigger = ASRouterTriggerListeners.get("formAutofill");
- sandbox.stub(formAutofillTrigger, "_triggerDelay").value(0);
- formAutofillTrigger.uninit();
- formAutofillTrigger.init(handlerStub);
-
- function notifyCreditCardSaved() {
- Services.obs.notifyObservers(
- {
- wrappedJSObject: { sourceSync: false, collectionName: "creditCards" },
- },
- formAutofillTrigger._topic,
- "add"
- );
- }
-
- // Saving credit cards for autofill currently fails for some hardware
- // configurations, so mock the event instead of really adding a card.
- notifyCreditCardSaved();
- await sleepMs(1);
- Assert.ok(handlerStub.called, "Called after event");
-
- // Test that the trigger doesn't fire when the credit card manager is open.
- handlerStub.resetHistory();
- await BrowserTestUtils.withNewTab(
- { gBrowser, url: "about:preferences#privacy" },
- async browser => {
- await SpecialPowers.spawn(browser, [], async () =>
- (
- await ContentTaskUtils.waitForCondition(
- () =>
- content.document.querySelector(
- "#formAutofillGroupBox setting-group[groupid=payments] #savedPaymentsButton"
- ),
- "Waiting for credit card manager button"
- )
- )?.click()
- );
- await BrowserTestUtils.waitForCondition(
- () => browser.contentWindow?.gSubDialog?.dialogs.length
- );
- notifyCreditCardSaved();
- await sleepMs(1);
- Assert.ok(
- handlerStub.notCalled,
- "Not called when credit card manager is open"
- );
- }
- );
-
- formAutofillTrigger.uninit();
- handlerStub.resetHistory();
- notifyCreditCardSaved();
- await sleepMs(1);
- Assert.ok(handlerStub.notCalled, "Not called after uninit");
-
- sandbox.restore();
- formAutofillTrigger.uninit();
+add_task(async function test_formAutofill() {
+ await test_formAutofillTrigger(false);
+ await test_formAutofillTrigger(true);
});
add_task(async function test_pageActionInUrlbarTrigger() {
diff --git a/browser/extensions/formautofill/test/browser/creditCard/browser_creditCard_osAuth.js b/browser/extensions/formautofill/test/browser/creditCard/browser_creditCard_osAuth.js
@@ -76,87 +76,133 @@ add_task(async function test_os_auth_disabled_with_checkbox() {
FormAutofillUtils.setOSAuthEnabled(true);
});
-/*
+add_task(async function test_osAuth_enabled() {
+ await test_osAuth_enabled_behaviour(false);
+ await test_osAuth_enabled_behaviour(true);
+});
+
+/**
* This test ensures that there is an OS authentication prompt when OS
* authentication is enabled.
+ *
+ * @param settingsRedesignEnabled string
*/
-add_task(async function test_osAuth_enabled_behaviour() {
+async function test_osAuth_enabled_behaviour(settingsRedesignEnabled) {
+ info(
+ `Running test_osAuth_enabled_behaviour with settings redesign set to ${settingsRedesignEnabled}`
+ );
let finalPrefPaneLoaded = TestUtils.topicObserved("sync-pane-loaded");
await SpecialPowers.pushPrefEnv({
- set: [[FormAutofillUtils.AUTOFILL_CREDITCARDS_OS_AUTH_LOCKED_PREF, true]],
+ set: [
+ [FormAutofillUtils.AUTOFILL_CREDITCARDS_OS_AUTH_LOCKED_PREF, true],
+ ["browser.settings-redesign.enabled", settingsRedesignEnabled],
+ ],
});
await BrowserTestUtils.withNewTab(
{ gBrowser, url: PAGE_PRIVACY },
async function (browser) {
+ const redesignEnabled = Services.prefs.getBoolPref(
+ "browser.settings-redesign.enabled",
+ false
+ );
await finalPrefPaneLoaded;
if (!OSKeyStoreTestUtils.canTestOSKeyStoreLogin()) {
// The rest of the test uses Edit mode which causes an OS prompt in official builds.
return;
}
let reauthObserved = OSKeyStoreTestUtils.waitForOSKeyStoreLogin(true);
- await SpecialPowers.spawn(browser, [SELECTORS], async selectors => {
- content.document.querySelector(selectors.savedCreditCardsBtn).click();
- });
- let ccManageDialog = await waitForSubDialogLoad(
- content,
- MANAGE_CREDIT_CARDS_DIALOG_URL
- );
- await SpecialPowers.spawn(ccManageDialog, [], async () => {
- let selRecords = content.document.getElementById("credit-cards");
- await EventUtils.synthesizeMouseAtCenter(
- selRecords.children[0],
- [],
- content
- );
- content.document.querySelector("#edit").click();
- });
+ await openEditPaymentsList(redesignEnabled, browser);
await reauthObserved; // If the OS does not popup, this will cause a timeout in the test.
- await waitForSubDialogLoad(content, EDIT_CREDIT_CARD_DIALOG_URL);
+
+ if (!redesignEnabled) {
+ await waitForSubDialogLoad(content, EDIT_CREDIT_CARD_DIALOG_URL);
+ }
}
);
+}
+
+add_task(async function test_osAuth_disabled() {
+ await test_osAuth_disabled_behavior(false);
+ await test_osAuth_disabled_behavior(true);
});
-/*
+/**
* This test checks that no OS authentication prompt is triggered when OS
* authentication is disabled.
+ *
+ * @param settingsRedesignEnabled string
*/
-add_task(async function test_osAuth_disabled_behavior() {
+async function test_osAuth_disabled_behavior(settingsRedesignEnabled) {
+ info(
+ `Running test_osAuth_disabled_behavior with settings redesign set to ${settingsRedesignEnabled}`
+ );
+
+ await SpecialPowers.pushPrefEnv({
+ set: [["browser.settings-redesign.enabled", settingsRedesignEnabled]],
+ });
+
let finalPrefPaneLoaded = TestUtils.topicObserved("sync-pane-loaded");
FormAutofillUtils.setOSAuthEnabled(false);
await BrowserTestUtils.withNewTab(
{ gBrowser, url: PAGE_PRIVACY },
async function (browser) {
await finalPrefPaneLoaded;
- await SpecialPowers.spawn(
- browser,
- [SELECTORS.savedCreditCardsBtn, SELECTORS.reauthCheckbox],
- async (saveButton, reauthCheckbox) => {
- is(
- content.document.querySelector(reauthCheckbox).checked,
- false,
- "OSReauth for credit cards should NOT be checked"
- );
- content.document.querySelector(saveButton).click();
- }
- );
- let ccManageDialog = await waitForSubDialogLoad(
- content,
- MANAGE_CREDIT_CARDS_DIALOG_URL
+ const redesignEnabled = Services.prefs.getBoolPref(
+ "browser.settings-redesign.enabled",
+ false
);
- await SpecialPowers.spawn(ccManageDialog, [], async () => {
- let selRecords = content.document.getElementById("credit-cards");
- await EventUtils.synthesizeMouseAtCenter(
- selRecords.children[0],
- [],
- content
- );
- content.document.getElementById("edit").click();
- });
- info("The OS Auth dialog should NOT show up");
+ await openEditPaymentsList(redesignEnabled, browser);
// If OSAuth prompt shows up, the next line would cause a timeout since the edit dialog would not show up.
await waitForSubDialogLoad(content, EDIT_CREDIT_CARD_DIALOG_URL);
}
);
FormAutofillUtils.setOSAuthEnabled(true);
-});
+}
+
+/*
+ * Helper function for opening the payment methods list UI, depending on whether
+ * or not settings redesign is enabled.
+ */
+async function openEditPaymentsList(redesignEnabled, browser) {
+ if (!redesignEnabled) {
+ await SpecialPowers.spawn(browser, [SELECTORS], async selectors => {
+ content.document.querySelector(selectors.savedCreditCardsBtn).click();
+ });
+ let ccManageDialog = await waitForSubDialogLoad(
+ content,
+ MANAGE_CREDIT_CARDS_DIALOG_URL
+ );
+ await SpecialPowers.spawn(ccManageDialog, [], async () => {
+ let selRecords = content.document.getElementById("credit-cards");
+ await EventUtils.synthesizeMouseAtCenter(
+ selRecords.children[0],
+ [],
+ content
+ );
+ content.document.querySelector("#edit").click();
+ });
+ } else {
+ await SpecialPowers.spawn(browser, [], async () => {
+ const savedPaymentsBtn = content.document.querySelector(
+ "#savedPaymentsButton"
+ );
+ savedPaymentsBtn.click();
+
+ info("Ensure we have navigated to the manage payments page.");
+ const paymentsPage = content.document.querySelector(
+ '[data-category="paneManagePayments"]'
+ );
+ await ContentTaskUtils.waitForCondition(
+ () => !paymentsPage.hidden,
+ "Payments page is failed to show."
+ );
+ ok(true, "Payments page is visible");
+ info("Click list item edit button");
+ const editBtn = paymentsPage.querySelector("moz-button[action='edit']");
+ editBtn.click();
+ });
+ }
+}
+
+async function test_OsAuth_Enabled() {}