1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
"use strict";
const SUBMIT_RECORD = {
"given-name": "John",
"family-name": "Doe",
organization: "Mozilla",
"street-address": "123 Sesame Street",
tel: "+13453453456",
};
const TEST_CASE = [
{
description: "adding the email field",
editedFields: {
email: "test@mozilla.org",
},
},
{
description: "changing the given-name field",
editedFields: {
name: "Jane",
},
},
{
description: "appending the street-address field",
editedFields: {
"street-address": SUBMIT_RECORD["street-address"] + " 4F",
},
},
{
description: "removing some fields",
editedFields: {
name: "",
tel: "",
},
},
{
description: "doing all kinds of stuff",
editedFields: {
organization: SUBMIT_RECORD.organization.toLowerCase(),
"address-level1": "California",
tel: "",
"street-address": SUBMIT_RECORD["street-address"] + " Apt.6",
name: "Jane Doe",
},
},
];
async function expectSavedAddresses(expectedCount) {
const addresses = await getAddresses();
is(
addresses.length,
expectedCount,
`${addresses.length} address in the storage`
);
return addresses;
}
function recordToFormSelector(record) {
let obj = {};
for (const [key, value] of Object.entries(record)) {
obj[`#${key}`] = value;
}
return obj;
}
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [
["extensions.formautofill.addresses.capture.enabled", true],
["extensions.formautofill.addresses.supported", "on"],
],
});
});
// Test different scenarios when we change something in the edit address dorhanger
add_task(async function test_save_edited_fields() {
await expectSavedAddresses(0);
for (const TEST of TEST_CASE) {
await BrowserTestUtils.withNewTab(
{ gBrowser, url: ADDRESS_FORM_URL },
async function (browser) {
info(`Test ${TEST.description}`);
const onSavePopupShown = waitForPopupShown();
await focusUpdateSubmitForm(browser, {
focusSelector: "#given-name",
newValues: recordToFormSelector(SUBMIT_RECORD),
});
await onSavePopupShown;
const onEditPopupShown = waitForPopupShown();
await clickAddressDoorhangerButton(EDIT_ADDRESS_BUTTON);
await onEditPopupShown;
fillEditDoorhanger(TEST.editedFields);
await clickAddressDoorhangerButton(MAIN_BUTTON);
}
);
const expectedRecord = normalizeAddressFields({
...SUBMIT_RECORD,
...TEST.editedFields,
});
const addresses = await expectSavedAddresses(1);
for (const [key, value] of Object.entries(expectedRecord)) {
is(addresses[0][key] ?? "", value, `${key} field is saved`);
}
await removeAllRecords();
}
});
|