Skip to content

Commit

Permalink
Bug 1393756 - Part 1: Add mochitest for credit card doorhanger never …
Browse files Browse the repository at this point in the history
…save option. r=lchang

MozReview-Commit-ID: EhKx52OqXOp

--HG--
extra : rebase_source : 383ceb1ff76b10afd749d9bb1c7613f7650abea6
  • Loading branch information
steveck-chung committed Sep 20, 2017
1 parent a9b71ba commit 440e4c0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,39 @@ add_task(async function test_submit_creditCard_saved() {
);

let creditCards = await getCreditCards();
is(creditCards.length, 1, "Still 1 address in storage");
is(creditCards.length, 1, "1 address in storage");
is(creditCards[0]["cc-name"], "User 1", "Verify the name field");
});

add_task(async function test_submit_creditCard_never_save() {
await BrowserTestUtils.withNewTab({gBrowser, url: CREDITCARD_FORM_URL},
async function(browser) {
let promiseShown = BrowserTestUtils.waitForEvent(PopupNotifications.panel,
"popupshown");
await ContentTask.spawn(browser, null, async function() {
let form = content.document.getElementById("form");
let name = form.querySelector("#cc-name");
name.focus();
await new Promise(resolve => setTimeout(resolve, 1000));
name.setUserInput("User 0");

let number = form.querySelector("#cc-number");
number.setUserInput("1234123412341234");

// Wait 1000ms before submission to make sure the input value applied
await new Promise(resolve => setTimeout(resolve, 1000));
form.querySelector("input[type=submit]").click();
});

await promiseShown;
await clickDoorhangerButton(MENU_BUTTON, 0);
}
);

await sleep(1000);
let creditCards = await getCreditCards();
let creditCardPref = SpecialPowers.getBoolPref(ENABLED_AUTOFILL_CREDITCARDS_PREF);
is(creditCards.length, 1, "Still 1 address in storage");
is(creditCardPref, false, "Credit card is disabled");
SpecialPowers.clearUserPref(ENABLED_AUTOFILL_CREDITCARDS_PREF);
});
22 changes: 12 additions & 10 deletions browser/extensions/formautofill/test/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ function removeCreditCards(guids) {
return TestUtils.topicObserved("formautofill-storage-changed");
}

function getNotification(index = 0) {
let notifications = PopupNotifications.panel.childNodes;
ok(notifications.length > 0, "at least one notification displayed");
ok(true, notifications.length + " notification(s)");
return notifications[index];
}

/**
* Clicks the popup notification button and wait for popup hidden.
*
Expand All @@ -197,19 +204,17 @@ function removeCreditCards(guids) {
*/
async function clickDoorhangerButton(button, index) {
let popuphidden = BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popuphidden");
let notifications = PopupNotifications.panel.childNodes;
ok(notifications.length > 0, "at least one notification displayed");
ok(true, notifications.length + " notification(s)");
let notification = notifications[0];

if (button == MAIN_BUTTON || button == SECONDARY_BUTTON) {
EventUtils.synthesizeMouseAtCenter(notification[button], {});
EventUtils.synthesizeMouseAtCenter(getNotification()[button], {});
} else if (button == MENU_BUTTON) {
// Click the dropmarker arrow and wait for the menu to show up.
await sleep(); // menubutton needs extra time for binding
let notification = getNotification();
ok(notification.menubutton, "notification menupopup displayed");
let dropdownPromise =
BrowserTestUtils.waitForEvent(notification.menupopup, "popupshown");
await EventUtils.synthesizeMouseAtCenter(notification.menubutton, {});
ok(true, "notification menupopup displayed");
await dropdownPromise;

let actionMenuItem = notification.querySelectorAll("menuitem")[index];
Expand All @@ -219,10 +224,7 @@ async function clickDoorhangerButton(button, index) {
}

function getDoorhangerCheckbox() {
let notifications = PopupNotifications.panel.childNodes;
ok(notifications.length > 0, "at least one notification displayed");
ok(true, notifications.length + " notification(s)");
return notifications[0].checkbox;
return getNotification().checkbox;
}

// Wait for master password dialog and cancel to close it.
Expand Down

0 comments on commit 440e4c0

Please sign in to comment.