Bug 1420853 - Ensure only fields valid for the given country are saved. r=MattN

Differential Revision: https://phabricator.services.mozilla.com/D9034

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jared Wein 2018-10-19 16:36:45 +00:00
Родитель 27d8b8ee2d
Коммит eb7010591a
3 изменённых файлов: 196 добавлений и 1 удалений

Просмотреть файл

@ -582,7 +582,10 @@ var paymentDialogWrapper = {
formAutofillStorage[collectionName];
if (guid) {
let preserveOldProperties = true;
// We only care to preserve old properties for credit cards,
// because credit cards don't get their full record sent to the
// unprivileged frame (the cc-number is excluded).
let preserveOldProperties = collectionName == "creditCards";
await collection.update(guid, record, preserveOldProperties);
} else {
responseMessage.guid = await collection.add(record);

Просмотреть файл

@ -592,3 +592,141 @@ add_task(async function test_private_persist_addresses() {
"Original 1 stored address at end of test");
});
add_task(async function test_hiddenFieldNotSaved() {
await setup();
await BrowserTestUtils.withNewTab({
gBrowser,
url: BLANK_PAGE_URL,
}, async browser => {
let {win, frame} =
await setupPaymentDialog(browser, {
methodData: [PTU.MethodData.basicCard],
details: Object.assign({}, PTU.Details.twoShippingOptions, PTU.Details.total2USD),
options: PTU.Options.requestShippingOption,
merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
}
);
let newAddress = Object.assign({}, PTU.Addresses.TimBL);
newAddress["given-name"] = "hiddenFields";
let shippingAddressChangePromise = ContentTask.spawn(browser, {
eventName: "shippingaddresschange",
}, PTU.ContentTasks.awaitPaymentRequestEventPromise);
let options = {
expectPersist: true,
isEditing: false,
};
await navigateToAddAddressPage(frame);
info("navigated to add address page");
await fillInShippingAddressForm(frame, newAddress, options);
info("filled in TimBL address");
await spawnPaymentDialogTask(frame, async (args) => {
let countryField = content.document.getElementById("country");
await content.fillField(countryField, "DE");
});
info("changed selected country to Germany");
await submitAddressForm(frame, null, options);
await shippingAddressChangePromise;
info("got shippingaddresschange event");
await spawnPaymentDialogTask(frame, async () => {
let {
PaymentTestUtils: PTU,
} = ChromeUtils.import("resource://testing-common/PaymentTestUtils.jsm", {});
let {savedAddresses} = await PTU.DialogContentUtils.getCurrentState(content);
is(Object.keys(savedAddresses).length, 2, "2 saved addresses");
let savedAddress = Object.values(savedAddresses)
.find(address => address["given-name"] == "hiddenFields");
ok(savedAddress, "found the saved address");
is(savedAddress.country, "DE", "check country");
is(savedAddress["address-level2"], PTU.Addresses.TimBL["address-level2"],
"check address-level2");
is(savedAddress["address-level1"], undefined, "address-level1 should not be saved");
});
info("clicking cancel");
spawnPaymentDialogTask(frame, PTU.DialogContentTasks.manuallyClickCancel);
await BrowserTestUtils.waitForCondition(() => win.closed, "dialog should be closed");
});
await cleanupFormAutofillStorage();
});
add_task(async function test_hiddenFieldRemovedWhenCountryChanged() {
await setup();
await BrowserTestUtils.withNewTab({
gBrowser,
url: BLANK_PAGE_URL,
}, async browser => {
let {win, frame} =
await setupPaymentDialog(browser, {
methodData: [PTU.MethodData.basicCard],
details: Object.assign({}, PTU.Details.twoShippingOptions, PTU.Details.total2USD),
options: PTU.Options.requestShippingOption,
merchantTaskFn: PTU.ContentTasks.createAndShowRequest,
}
);
let shippingAddressChangePromise = ContentTask.spawn(browser, {
eventName: "shippingaddresschange",
}, PTU.ContentTasks.awaitPaymentRequestEventPromise);
await spawnPaymentDialogTask(frame, async (args) => {
let {
PaymentTestUtils: PTU,
} = ChromeUtils.import("resource://testing-common/PaymentTestUtils.jsm", {});
let picker = content.document
.querySelector("address-picker[selected-state-key='selectedShippingAddress']");
Cu.waiveXrays(picker).dropdown.popupBox.focus();
EventUtils.synthesizeKey(PTU.Addresses.TimBL["given-name"], {}, content.window);
let editLink = content.document.querySelector("address-picker .edit-link");
is(editLink.textContent, "Edit", "Edit link text");
editLink.click();
await PTU.DialogContentUtils.waitForState(content, (state) => {
return state.page.id == "address-page" && !!state["address-page"].guid;
}, "Check edit page state");
let countryField = content.document.getElementById("country");
await content.fillField(countryField, "DE");
info("changed selected country to Germany");
});
let options = {
isEditing: true,
};
await submitAddressForm(frame, null, options);
await shippingAddressChangePromise;
info("got shippingaddresschange event");
await spawnPaymentDialogTask(frame, async () => {
let {
PaymentTestUtils: PTU,
} = ChromeUtils.import("resource://testing-common/PaymentTestUtils.jsm", {});
let {savedAddresses} = await PTU.DialogContentUtils.getCurrentState(content);
is(Object.keys(savedAddresses).length, 1, "1 saved address");
let savedAddress = Object.values(savedAddresses)[0];
is(savedAddress.country, "DE", "check country");
is(savedAddress["address-level2"], PTU.Addresses.TimBL["address-level2"],
"check address-level2");
is(savedAddress["address-level1"], undefined, "address-level1 should not be saved");
});
info("clicking cancel");
spawnPaymentDialogTask(frame, PTU.DialogContentTasks.manuallyClickCancel);
await BrowserTestUtils.waitForCondition(() => win.closed, "dialog should be closed");
});
await cleanupFormAutofillStorage();
});

Просмотреть файл

@ -425,3 +425,57 @@ add_task(async function test_combined_name_fields_error() {
doc.querySelector("#cancel").click();
});
});
add_task(async function test_hiddenFieldNotSaved() {
await testDialog(EDIT_ADDRESS_DIALOG_URL, win => {
let doc = win.document;
doc.querySelector("#address-level2").focus();
EventUtils.synthesizeKey(TEST_ADDRESS_1["address-level2"], {}, win);
doc.querySelector("#address-level1").focus();
EventUtils.synthesizeKey(TEST_ADDRESS_1["address-level1"], {}, win);
doc.querySelector("#country").focus();
EventUtils.synthesizeKey("Germany", {}, win);
doc.querySelector("#save").focus();
EventUtils.synthesizeKey("VK_RETURN", {}, win);
});
let addresses = await getAddresses();
is(addresses[0].country, "DE", "check country");
is(addresses[0]["address-level2"], TEST_ADDRESS_1["address-level2"], "check address-level2");
is(addresses[0]["address-level1"], undefined, "address-level1 should not be saved");
await removeAllRecords();
});
add_task(async function test_hiddenFieldRemovedWhenCountryChanged() {
let addresses = await getAddresses();
ok(!addresses.length, "no addresses at start of test");
await testDialog(EDIT_ADDRESS_DIALOG_URL, win => {
let doc = win.document;
doc.querySelector("#address-level2").focus();
EventUtils.synthesizeKey(TEST_ADDRESS_1["address-level2"], {}, win);
doc.querySelector("#address-level1").focus();
EventUtils.synthesizeKey(TEST_ADDRESS_1["address-level1"], {}, win);
doc.querySelector("#save").focus();
EventUtils.synthesizeKey("VK_RETURN", {}, win);
});
addresses = await getAddresses();
is(addresses[0].country, "US", "check country");
is(addresses[0]["address-level2"], TEST_ADDRESS_1["address-level2"], "check address-level2");
is(addresses[0]["address-level1"], TEST_ADDRESS_1["address-level1"], "check address-level1");
await testDialog(EDIT_ADDRESS_DIALOG_URL, win => {
let doc = win.document;
doc.querySelector("#country").focus();
EventUtils.synthesizeKey("Germany", {}, win);
win.document.querySelector("#save").click();
}, {
record: addresses[0],
});
addresses = await getAddresses();
is(addresses.length, 1, "only one address is in storage");
is(addresses[0]["address-level2"], TEST_ADDRESS_1["address-level2"], "check address-level2");
is(addresses[0]["address-level1"], undefined, "address-level1 should be removed");
is(addresses[0].country, "DE", "country changed");
await removeAllRecords();
});