Bug 1370764 - (Part 3) Add browser chrome test for adding and editing credit card. r=lchang
MozReview-Commit-ID: Di1GtjknK5E
--- a/browser/base/content/test/static/browser_all_files_referenced.js
+++ b/browser/base/content/test/static/browser_all_files_referenced.js
@@ -126,16 +126,18 @@ var whitelist = [
{file: "resource://gre/modules/Localization.jsm"},
// Starting from here, files in the whitelist are bugs that need fixing.
// Bug 1339420
{file: "chrome://branding/content/icon128.png"},
// Bug 1339424 (wontfix?)
{file: "chrome://browser/locale/taskbar.properties",
platforms: ["linux", "macosx"]},
+ // Bug 1370768 will reference this file
+ {file: "chrome://formautofill/content/editCreditCard.xhtml"},
// Bug 1316187
{file: "chrome://global/content/customizeToolbar.xul"},
// Bug 1343837
{file: "chrome://global/content/findUtils.js"},
// Bug 1343843
{file: "chrome://global/content/url-classifier/unittests.xul"},
// Bug 1348362
{file: "chrome://global/skin/icons/warning-64.png", platforms: ["linux", "win"]},
--- a/browser/extensions/formautofill/content/editDialog.js
+++ b/browser/extensions/formautofill/content/editDialog.js
@@ -29,16 +29,19 @@ class EditDialog {
window.addEventListener("DOMContentLoaded", this, {once: true});
}
async init() {
if (this._record) {
await this.loadInitialValues(this._record);
}
this.attachEventListeners();
+ // For testing only: loadInitialValues for credit card is an async method, and tests
+ // need to wait until the values have been filled before editing the fields.
+ window.dispatchEvent(new CustomEvent("FormReady"));
}
uninit() {
this.detachEventListeners();
this._elements = null;
}
/**
--- a/browser/extensions/formautofill/test/browser/browser.ini
+++ b/browser/extensions/formautofill/test/browser/browser.ini
@@ -6,14 +6,15 @@ support-files =
../fixtures/autocomplete_creditcard_basic.html
[browser_autocomplete_footer.js]
[browser_autocomplete_marked_back_forward.js]
[browser_autocomplete_marked_detached_tab.js]
[browser_check_installed.js]
[browser_dropdown_layout.js]
[browser_editAddressDialog.js]
+[browser_editCreditCardDialog.js]
[browser_first_time_use_doorhanger.js]
[browser_insecure_form.js]
[browser_manageAddressesDialog.js]
[browser_privacyPreferences.js]
[browser_submission_in_private_mode.js]
[browser_update_doorhanger.js]
--- a/browser/extensions/formautofill/test/browser/browser_editAddressDialog.js
+++ b/browser/extensions/formautofill/test/browser/browser_editAddressDialog.js
@@ -1,13 +1,13 @@
"use strict";
add_task(async function test_cancelEditAddressDialog() {
await new Promise(resolve => {
- let win = window.openDialog(EDIT_ADDRESS_DIALOG_URL, null, null, null);
+ let win = window.openDialog(EDIT_ADDRESS_DIALOG_URL);
win.addEventListener("load", () => {
win.addEventListener("unload", () => {
ok(true, "Edit address dialog is closed");
resolve();
}, {once: true});
win.document.querySelector("#cancel").click();
}, {once: true});
});
@@ -23,17 +23,17 @@ add_task(async function test_cancelEditA
}, {once: true});
EventUtils.synthesizeKey("VK_ESCAPE", {}, win);
}, {once: true});
});
});
add_task(async function test_saveAddress() {
await new Promise(resolve => {
- let win = window.openDialog(EDIT_ADDRESS_DIALOG_URL, null, null, null);
+ let win = window.openDialog(EDIT_ADDRESS_DIALOG_URL);
win.addEventListener("load", () => {
win.addEventListener("unload", () => {
ok(true, "Edit address dialog is closed");
resolve();
}, {once: true});
EventUtils.synthesizeKey("VK_TAB", {}, win);
EventUtils.synthesizeKey(TEST_ADDRESS_1["given-name"], {}, win);
EventUtils.synthesizeKey("VK_TAB", {}, win);
@@ -70,22 +70,23 @@ add_task(async function test_saveAddress
is(addresses[0][fieldName], fieldValue, "check " + fieldName);
}
});
add_task(async function test_editAddress() {
let addresses = await getAddresses();
await new Promise(resolve => {
let win = window.openDialog(EDIT_ADDRESS_DIALOG_URL, null, null, addresses[0]);
- win.addEventListener("load", () => {
+ win.addEventListener("FormReady", () => {
win.addEventListener("unload", () => {
ok(true, "Edit address dialog is closed");
resolve();
}, {once: true});
EventUtils.synthesizeKey("VK_TAB", {}, win);
+ EventUtils.synthesizeKey("VK_RIGHT", {}, win);
EventUtils.synthesizeKey("test", {}, win);
win.document.querySelector("#save").click();
}, {once: true});
});
addresses = await getAddresses();
is(addresses.length, 1, "only one address is in storage");
is(addresses[0]["given-name"], TEST_ADDRESS_1["given-name"] + "test", "given-name changed");
new file mode 100644
--- /dev/null
+++ b/browser/extensions/formautofill/test/browser/browser_editCreditCardDialog.js
@@ -0,0 +1,115 @@
+/* eslint-disable mozilla/no-arbitrary-setTimeout */
+
+"use strict";
+
+add_task(async function test_cancelEditCreditCardDialog() {
+ await new Promise(resolve => {
+ let win = window.openDialog(EDIT_CREDIT_CARD_DIALOG_URL);
+ win.addEventListener("load", () => {
+ win.addEventListener("unload", () => {
+ ok(true, "Edit credit card dialog is closed");
+ resolve();
+ }, {once: true});
+ win.document.querySelector("#cancel").click();
+ }, {once: true});
+ });
+});
+
+add_task(async function test_cancelEditCreditCardDialogWithESC() {
+ await new Promise(resolve => {
+ let win = window.openDialog(EDIT_CREDIT_CARD_DIALOG_URL);
+ win.addEventListener("load", () => {
+ win.addEventListener("unload", () => {
+ ok(true, "Edit credit card dialog is closed with ESC key");
+ resolve();
+ }, {once: true});
+ EventUtils.synthesizeKey("VK_ESCAPE", {}, win);
+ }, {once: true});
+ });
+});
+
+add_task(async function test_saveCreditCard() {
+ await new Promise(resolve => {
+ let win = window.openDialog(EDIT_CREDIT_CARD_DIALOG_URL);
+ win.addEventListener("load", () => {
+ win.addEventListener("unload", () => {
+ ok(true, "Edit credit card dialog is closed");
+ resolve();
+ }, {once: true});
+ EventUtils.synthesizeKey("VK_TAB", {}, win);
+ EventUtils.synthesizeKey(TEST_CREDIT_CARD_1["cc-number"], {}, win);
+ EventUtils.synthesizeKey("VK_TAB", {}, win);
+ EventUtils.synthesizeKey(TEST_CREDIT_CARD_1["cc-name"], {}, win);
+ EventUtils.synthesizeKey("VK_TAB", {}, win);
+ EventUtils.synthesizeKey("0" + TEST_CREDIT_CARD_1["cc-exp-month"].toString(), {}, win);
+ EventUtils.synthesizeKey("VK_TAB", {}, win);
+ EventUtils.synthesizeKey(TEST_CREDIT_CARD_1["cc-exp-year"].toString(), {}, win);
+ EventUtils.synthesizeKey("VK_TAB", {}, win);
+ EventUtils.synthesizeKey("VK_TAB", {}, win);
+ info("saving credit card");
+ EventUtils.synthesizeKey("VK_RETURN", {}, win);
+ }, {once: true});
+ });
+ let creditCards = await getCreditCards();
+
+ is(creditCards.length, 1, "only one credit card is in storage");
+ for (let [fieldName, fieldValue] of Object.entries(TEST_CREDIT_CARD_1)) {
+ if (fieldName === "cc-number") {
+ fieldValue = "*".repeat(fieldValue.length - 4) + fieldValue.substr(-4);
+ }
+ is(creditCards[0][fieldName], fieldValue, "check " + fieldName);
+ }
+ ok(creditCards[0]["cc-number-encrypted"], "cc-number-encrypted exists");
+});
+
+add_task(async function test_editCreditCard() {
+ let creditCards = await getCreditCards();
+ is(creditCards.length, 1, "only one credit card is in storage");
+ await new Promise(resolve => {
+ let win = window.openDialog(EDIT_CREDIT_CARD_DIALOG_URL, null, null, creditCards[0]);
+ win.addEventListener("FormReady", () => {
+ win.addEventListener("unload", () => {
+ ok(true, "Edit credit card dialog is closed");
+ resolve();
+ }, {once: true});
+ EventUtils.synthesizeKey("VK_TAB", {}, win);
+ EventUtils.synthesizeKey("VK_TAB", {}, win);
+ EventUtils.synthesizeKey("VK_RIGHT", {}, win);
+ EventUtils.synthesizeKey("test", {}, win);
+ win.document.querySelector("#save").click();
+ }, {once: true});
+ });
+ creditCards = await getCreditCards();
+
+ is(creditCards.length, 1, "only one credit card is in storage");
+ is(creditCards[0]["cc-name"], TEST_CREDIT_CARD_1["cc-name"] + "test", "cc name changed");
+ await removeCreditCards([creditCards[0].guid]);
+
+ creditCards = await getCreditCards();
+ is(creditCards.length, 0, "Credit card storage is empty");
+});
+
+add_task(async function test_addInvalidCreditCard() {
+ await new Promise(resolve => {
+ let win = window.openDialog(EDIT_CREDIT_CARD_DIALOG_URL);
+ win.addEventListener("FormReady", () => {
+ const unloadHandler = () => ok(false, "Edit credit card dialog shouldn't be closed");
+ win.addEventListener("unload", unloadHandler);
+
+ EventUtils.synthesizeKey("VK_TAB", {}, win);
+ EventUtils.synthesizeKey("test", {}, win);
+ win.document.querySelector("#save").click();
+
+ is(win.document.querySelector("form").checkValidity(), false, "cc-number is invalid");
+ SimpleTest.requestFlakyTimeout("Ensure the window remains open after save attempt");
+ setTimeout(() => {
+ win.removeEventListener("unload", unloadHandler);
+ win.close();
+ resolve();
+ }, 500);
+ }, {once: true});
+ });
+ let creditCards = await getCreditCards();
+
+ is(creditCards.length, 0, "Credit card storage is empty");
+});
--- a/browser/extensions/formautofill/test/browser/head.js
+++ b/browser/extensions/formautofill/test/browser/head.js
@@ -1,20 +1,21 @@
-/* exported MANAGE_ADDRESSES_DIALOG_URL, EDIT_ADDRESS_DIALOG_URL, BASE_URL,
- TEST_ADDRESS_1, TEST_ADDRESS_2, TEST_ADDRESS_3, TEST_ADDRESS_4, TEST_ADDRESS_5,
+/* exported MANAGE_ADDRESSES_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,
FTU_PREF, ENABLED_PREF, SYNC_USERNAME_PREF, SYNC_ADDRESSES_PREF,
sleep, expectPopupOpen, openPopupOn, expectPopupClose, closePopup, clickDoorhangerButton,
getAddresses, saveAddress, removeAddresses, saveCreditCard,
getDisplayedPopupItems, getDoorhangerCheckbox */
"use strict";
const MANAGE_ADDRESSES_DIALOG_URL = "chrome://formautofill/content/manageAddresses.xhtml";
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 FTU_PREF = "extensions.formautofill.firstTimeUse";
const ENABLED_PREF = "extensions.formautofill.addresses.enabled";
const SYNC_USERNAME_PREF = "services.sync.username";
const SYNC_ADDRESSES_PREF = "services.sync.engine.addresses";
const TEST_ADDRESS_1 = {