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
115
116
117
118
119
120
121
122
|
/*
* Test for form auto fill content helper collectFormFields functions.
*/
"use strict";
let {FormAutofillHandler} = importAutofillModule("FormAutofillContent.jsm");
const TESTCASES = [
{
description: "Form without autocomplete property",
document: `<form><input id="given-name"><input id="family-name">
<input id="street-addr"><input id="city"><input id="country">
<input id='email'><input id="tel"></form>`,
returnedFormat: [],
fieldDetails: [],
},
{
description: "Form with autocomplete properties and 1 token",
document: `<form><input id="given-name" autocomplete="given-name">
<input id="family-name" autocomplete="family-name">
<input id="street-addr" autocomplete="street-address">
<input id="city" autocomplete="address-level2">
<input id="country" autocomplete="country">
<input id="email" autocomplete="email">
<input id="tel" autocomplete="tel"></form>`,
returnedFormat: [
{"section": "", "addressType": "", "contactType": "", "fieldName": "given-name", "index": 0},
{"section": "", "addressType": "", "contactType": "", "fieldName": "family-name", "index": 1},
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address", "index": 2},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2", "index": 3},
{"section": "", "addressType": "", "contactType": "", "fieldName": "country", "index": 4},
{"section": "", "addressType": "", "contactType": "", "fieldName": "email", "index": 5},
{"section": "", "addressType": "", "contactType": "", "fieldName": "tel", "index": 6},
],
fieldDetails: [
{"section": "", "addressType": "", "contactType": "", "fieldName": "given-name", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "family-name", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "country", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "email", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "tel", "element": {}},
],
},
{
description: "Form with autocomplete properties and 2 tokens",
document: `<form><input id="given-name" autocomplete="shipping given-name">
<input id="family-name" autocomplete="shipping family-name">
<input id="street-addr" autocomplete="shipping street-address">
<input id="city" autocomplete="shipping address-level2">
<input id="country" autocomplete="shipping country">
<input id='email' autocomplete="shipping email">
<input id="tel" autocomplete="shipping tel"></form>`,
returnedFormat: [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name", "index": 0},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name", "index": 1},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address", "index": 2},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2", "index": 3},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country", "index": 4},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email", "index": 5},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel", "index": 6},
],
fieldDetails: [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel", "element": {}},
],
},
{
description: "Form with autocomplete properties and profile is partly matched",
document: `<form><input id="given-name" autocomplete="shipping given-name">
<input id="family-name" autocomplete="shipping family-name">
<input id="street-addr" autocomplete="shipping street-address">
<input id="city" autocomplete="shipping address-level2">
<input id="country" autocomplete="shipping country">
<input id='email' autocomplete="shipping email">
<input id="tel" autocomplete="shipping tel"></form>`,
returnedFormat: [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name", "index": 0},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name", "index": 1},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address", "index": 2},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2", "index": 3},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country", "index": 4},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email", "index": 5},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel", "index": 6},
],
fieldDetails: [
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email", "element": {}},
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel", "element": {}},
],
},
];
for (let tc of TESTCASES) {
(function() {
let testcase = tc;
add_task(function* () {
do_print("Starting testcase: " + testcase.description);
let doc = MockDocument.createTestDocument("http://localhost:8080/test/",
testcase.document);
let form = doc.querySelector("form");
let handler = new FormAutofillHandler(form);
Assert.deepEqual(handler.collectFormFields(), testcase.returnedFormat,
"Check the format of form autofill were returned correctly");
Assert.deepEqual(handler.fieldDetails, testcase.fieldDetails,
"Check the fieldDetails were set correctly");
});
})();
}
|