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
|
"use strict";
var FormAutofillUtils;
add_setup(async () => {
({ FormAutofillUtils } = ChromeUtils.importESModule(
"resource://gre/modules/shared/FormAutofillUtils.sys.mjs"
));
});
add_task(async function test_getCategoriesFromFieldNames() {
const TEST_CASES = [
{
strings: ["A", "B", "C", "D"],
expectedValue: "A B C D",
},
{
strings: ["A", "B", "", "D"],
expectedValue: "A B D",
},
{
strings: ["", "B", "", "D"],
expectedValue: "B D",
},
{
strings: [null, "B", " ", "D"],
expectedValue: "B D",
},
{
strings: "A B C",
expectedValue: "A B C",
},
{
strings: "A\nB\n\n\nC",
expectedValue: "A B C",
},
{
strings: "A B \nC",
expectedValue: "A B C",
},
{
strings: "A-B-C",
expectedValue: "A B C",
delimiter: "-",
},
{
strings: "A B\n \nC",
expectedValue: "A B C",
},
{
strings: null,
expectedValue: "",
},
];
for (let tc of TEST_CASES) {
let result;
if (tc.delimiter) {
result = FormAutofillUtils.toOneLineAddress(tc.strings, tc.delimiter);
} else {
result = FormAutofillUtils.toOneLineAddress(tc.strings);
}
Assert.equal(result, tc.expectedValue);
}
});
|