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
|
"use strict";
var FormAutofillUtils;
add_setup(async () => {
({ FormAutofillUtils } = ChromeUtils.importESModule(
"resource://gre/modules/shared/FormAutofillUtils.sys.mjs"
));
});
add_task(async function test_parseAddressFormat() {
const TEST_CASES = [
{
fmt: "%N%n%O%n%A%n%C, %S %Z", // US
parsed: [
{ fieldId: "name", newLine: true },
{ fieldId: "organization", newLine: true },
{ fieldId: "street-address", newLine: true },
{ fieldId: "address-level2" },
{ fieldId: "address-level1" },
{ fieldId: "postal-code" },
],
},
{
fmt: "%N%n%O%n%A%n%C %S %Z", // CA
parsed: [
{ fieldId: "name", newLine: true },
{ fieldId: "organization", newLine: true },
{ fieldId: "street-address", newLine: true },
{ fieldId: "address-level2" },
{ fieldId: "address-level1" },
{ fieldId: "postal-code" },
],
},
{
fmt: "%N%n%O%n%A%n%Z %C", // DE
parsed: [
{ fieldId: "name", newLine: true },
{ fieldId: "organization", newLine: true },
{ fieldId: "street-address", newLine: true },
{ fieldId: "postal-code" },
{ fieldId: "address-level2" },
],
},
{
fmt: "%N%n%O%n%A%n%D%n%C%n%S %Z", // IE
parsed: [
{ fieldId: "name", newLine: true },
{ fieldId: "organization", newLine: true },
{ fieldId: "street-address", newLine: true },
{ fieldId: "address-level3", newLine: true },
{ fieldId: "address-level2", newLine: true },
{ fieldId: "address-level1" },
{ fieldId: "postal-code" },
],
},
];
Assert.throws(
() => FormAutofillUtils.parseAddressFormat(),
/fmt string is missing./,
"Should throw if fmt is empty"
);
for (let tc of TEST_CASES) {
Assert.deepEqual(FormAutofillUtils.parseAddressFormat(tc.fmt), tc.parsed);
}
});
|