mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 00:35:44 +00:00
Bug 1371113 - Part 3: Add mochitest for credit card doorhanger. r=lchang
MozReview-Commit-ID: A8dawwdJrV2 --HG-- extra : rebase_source : 133fa7cba2339c4d2500829b7ca4df104f1184f1
This commit is contained in:
parent
205d33c7d5
commit
a4c9ab7763
@ -9,6 +9,7 @@ support-files =
|
||||
[browser_autocomplete_marked_back_forward.js]
|
||||
[browser_autocomplete_marked_detached_tab.js]
|
||||
[browser_check_installed.js]
|
||||
[browser_creditCard_doorhanger.js]
|
||||
[browser_dropdown_layout.js]
|
||||
[browser_editAddressDialog.js]
|
||||
[browser_editCreditCardDialog.js]
|
||||
|
@ -0,0 +1,61 @@
|
||||
/* eslint-disable mozilla/no-arbitrary-setTimeout */
|
||||
"use strict";
|
||||
|
||||
add_task(async function test_submit_creditCard_cancel_saving() {
|
||||
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();
|
||||
name.setUserInput("User 1");
|
||||
|
||||
let number = form.querySelector("#cc-number");
|
||||
number.setUserInput("1111222233334444");
|
||||
|
||||
// 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(SECONDARY_BUTTON);
|
||||
}
|
||||
);
|
||||
|
||||
await sleep(1000);
|
||||
let creditCards = await getCreditCards();
|
||||
is(creditCards.length, 0, "No credit card saved");
|
||||
});
|
||||
|
||||
add_task(async function test_submit_creditCard_saved() {
|
||||
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();
|
||||
name.setUserInput("User 1");
|
||||
|
||||
let number = form.querySelector("#cc-number");
|
||||
number.setUserInput("1111222233334444");
|
||||
|
||||
// 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(MAIN_BUTTON);
|
||||
await TestUtils.topicObserved("formautofill-storage-changed");
|
||||
}
|
||||
);
|
||||
|
||||
let creditCards = await getCreditCards();
|
||||
is(creditCards.length, 1, "Still 1 address in storage");
|
||||
is(creditCards[0]["cc-name"], "User 1", "Verify the name field");
|
||||
});
|
@ -32,7 +32,7 @@ add_task(async function test_first_time_save() {
|
||||
let cb = getDoorhangerCheckbox();
|
||||
ok(cb.hidden, "Sync checkbox should be hidden");
|
||||
// Open the panel via main button
|
||||
await clickDoorhangerButton(MAIN_BUTTON_INDEX);
|
||||
await clickDoorhangerButton(MAIN_BUTTON);
|
||||
let tab = await tabPromise;
|
||||
ok(tab, "Privacy panel opened");
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
@ -111,7 +111,7 @@ add_task(async function test_first_time_save_with_sync_account() {
|
||||
is(SpecialPowers.getBoolPref(SYNC_ADDRESSES_PREF), true,
|
||||
"addresses sync should be enabled after checked");
|
||||
// Open the panel via main button
|
||||
await clickDoorhangerButton(MAIN_BUTTON_INDEX);
|
||||
await clickDoorhangerButton(MAIN_BUTTON);
|
||||
let tab = await tabPromise;
|
||||
ok(tab, "Privacy panel opened");
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
|
@ -26,7 +26,7 @@ add_task(async function test_update_address() {
|
||||
});
|
||||
|
||||
await promiseShown;
|
||||
await clickDoorhangerButton(MAIN_BUTTON_INDEX);
|
||||
await clickDoorhangerButton(MAIN_BUTTON);
|
||||
}
|
||||
);
|
||||
|
||||
@ -59,7 +59,7 @@ add_task(async function test_create_new_address() {
|
||||
});
|
||||
|
||||
await promiseShown;
|
||||
await clickDoorhangerButton(SECONDARY_BUTTON_INDEX);
|
||||
await clickDoorhangerButton(SECONDARY_BUTTON);
|
||||
}
|
||||
);
|
||||
|
||||
@ -92,7 +92,7 @@ add_task(async function test_create_new_address_merge() {
|
||||
});
|
||||
|
||||
await promiseShown;
|
||||
await clickDoorhangerButton(SECONDARY_BUTTON_INDEX);
|
||||
await clickDoorhangerButton(SECONDARY_BUTTON);
|
||||
}
|
||||
);
|
||||
|
||||
@ -128,7 +128,7 @@ add_task(async function test_submit_untouched_fields() {
|
||||
});
|
||||
|
||||
await promiseShown;
|
||||
await clickDoorhangerButton(MAIN_BUTTON_INDEX);
|
||||
await clickDoorhangerButton(MAIN_BUTTON);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* exported MANAGE_ADDRESSES_DIALOG_URL, MANAGE_CREDIT_CARDS_DIALOG_URL, EDIT_ADDRESS_DIALOG_URL, EDIT_CREDIT_CARD_DIALOG_URL,
|
||||
BASE_URL, TEST_ADDRESS_1, TEST_ADDRESS_2, TEST_ADDRESS_3, TEST_ADDRESS_4, TEST_ADDRESS_5,
|
||||
TEST_CREDIT_CARD_1, TEST_CREDIT_CARD_2, TEST_CREDIT_CARD_3, FORM_URL,
|
||||
TEST_CREDIT_CARD_1, TEST_CREDIT_CARD_2, TEST_CREDIT_CARD_3, FORM_URL, CREDITCARD_FORM_URL,
|
||||
FTU_PREF, ENABLED_AUTOFILL_ADDRESSES_PREF, ENABLED_AUTOFILL_CREDITCARDS_PREF, SYNC_USERNAME_PREF, SYNC_ADDRESSES_PREF,
|
||||
sleep, expectPopupOpen, openPopupOn, expectPopupClose, closePopup, clickDoorhangerButton,
|
||||
getAddresses, saveAddress, removeAddresses, saveCreditCard,
|
||||
@ -14,6 +14,8 @@ const EDIT_ADDRESS_DIALOG_URL = "chrome://formautofill/content/editAddress.xhtml
|
||||
const EDIT_CREDIT_CARD_DIALOG_URL = "chrome://formautofill/content/editCreditCard.xhtml";
|
||||
const BASE_URL = "http://mochi.test:8888/browser/browser/extensions/formautofill/test/browser/";
|
||||
const FORM_URL = "http://mochi.test:8888/browser/browser/extensions/formautofill/test/browser/autocomplete_basic.html";
|
||||
const CREDITCARD_FORM_URL =
|
||||
"http://mochi.test:8888/browser/browser/extensions/formautofill/test/browser/autocomplete_creditcard_basic.html";
|
||||
const FTU_PREF = "extensions.formautofill.firstTimeUse";
|
||||
const ENABLED_AUTOFILL_ADDRESSES_PREF = "extensions.formautofill.addresses.enabled";
|
||||
const ENABLED_AUTOFILL_CREDITCARDS_PREF = "extensions.formautofill.creditCards.enabled";
|
||||
@ -60,7 +62,6 @@ const TEST_ADDRESS_5 = {
|
||||
const TEST_CREDIT_CARD_1 = {
|
||||
"cc-name": "John Doe",
|
||||
"cc-number": "1234567812345678",
|
||||
// "cc-number-encrypted": "",
|
||||
"cc-exp-month": 4,
|
||||
"cc-exp-year": 2017,
|
||||
};
|
||||
@ -78,8 +79,9 @@ const TEST_CREDIT_CARD_3 = {
|
||||
"cc-exp-year": 2000,
|
||||
};
|
||||
|
||||
const MAIN_BUTTON_INDEX = 0;
|
||||
const SECONDARY_BUTTON_INDEX = 1;
|
||||
const MAIN_BUTTON = "button";
|
||||
const SECONDARY_BUTTON = "secondaryButton";
|
||||
const MENU_BUTTON = "menubutton";
|
||||
|
||||
function getDisplayedPopupItems(browser, selector = ".autocomplete-richlistitem") {
|
||||
const {autoCompletePopup: {richlistbox: itemsBox}} = browser;
|
||||
@ -188,25 +190,28 @@ function removeCreditCards(guids) {
|
||||
/**
|
||||
* Clicks the popup notification button and wait for popup hidden.
|
||||
*
|
||||
* @param {number} buttonIndex Number indicating which button to click.
|
||||
* See the constants in this file.
|
||||
* @param {string} button The button type in popup notification.
|
||||
* @param {number} index The action's index in menu list.
|
||||
*/
|
||||
async function clickDoorhangerButton(buttonIndex) {
|
||||
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 (buttonIndex == MAIN_BUTTON_INDEX) {
|
||||
ok(true, "Triggering main action");
|
||||
EventUtils.synthesizeMouseAtCenter(notification.button, {});
|
||||
} else if (buttonIndex == SECONDARY_BUTTON_INDEX) {
|
||||
ok(true, "Triggering secondary action");
|
||||
EventUtils.synthesizeMouseAtCenter(notification.secondaryButton, {});
|
||||
} else if (notification.childNodes[buttonIndex - 1]) {
|
||||
ok(true, "Triggering secondary action with index " + buttonIndex);
|
||||
EventUtils.synthesizeMouseAtCenter(notification.childNodes[buttonIndex - 1], {});
|
||||
if (button == MAIN_BUTTON || button == SECONDARY_BUTTON) {
|
||||
EventUtils.synthesizeMouseAtCenter(notification[button], {});
|
||||
} else if (button == MENU_BUTTON) {
|
||||
// Click the dropmarker arrow and wait for the menu to show up.
|
||||
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];
|
||||
await EventUtils.synthesizeMouseAtCenter(actionMenuItem, {});
|
||||
}
|
||||
await popuphidden;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user