--- a/browser/extensions/formautofill/test/unit/test_autofillFormFields.js
+++ b/browser/extensions/formautofill/test/unit/test_autofillFormFields.js
@@ -10,21 +10,22 @@ 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>`,
fieldDetails: [],
profileData: {},
expectedResult: {
- "street-addr": "",
- "city": "",
- "country": "",
- "email": "",
- "tel": "",
+ "family-name": {value: "", state: "fall-back"},
+ "street-addr": {value: "", state: "fall-back"},
+ "city": {value: "", state: "fall-back"},
+ "country": {value: "", state: "fall-back"},
+ "email": {value: "", state: "fall-back"},
+ "tel": {value: "", state: "fall-back"},
},
},
{
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">
@@ -44,21 +45,23 @@ const TESTCASES = [
"guid": "123",
"street-address": "2 Harrison St",
"address-level2": "San Francisco",
"country": "US",
"email": "foo@mozilla.com",
"tel": "1234567",
},
expectedResult: {
- "street-addr": "2 Harrison St",
- "city": "San Francisco",
- "country": "US",
- "email": "foo@mozilla.com",
- "tel": "1234567",
+ "given-name": {value: "", state: "fall-back"},
+ "family-name": {value: "", state: "fall-back"},
+ "street-addr": {value: "2 Harrison St", state: "auto-filled"},
+ "city": {value: "San Francisco", state: "auto-filled"},
+ "country": {value: "US", state: "auto-filled"},
+ "email": {value: "foo@mozilla.com", state: "auto-filled"},
+ "tel": {value: "1234567", state: "auto-filled"},
},
},
{
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">
@@ -78,21 +81,23 @@ const TESTCASES = [
"guid": "123",
"street-address": "2 Harrison St",
"address-level2": "San Francisco",
"country": "US",
"email": "foo@mozilla.com",
"tel": "1234567",
},
expectedResult: {
- "street-addr": "2 Harrison St",
- "city": "San Francisco",
- "country": "US",
- "email": "foo@mozilla.com",
- "tel": "1234567",
+ "given-name": {value: "", state: "fall-back"},
+ "family-name": {value: "", state: "fall-back"},
+ "street-addr": {value: "2 Harrison St", state: "auto-filled"},
+ "city": {value: "San Francisco", state: "auto-filled"},
+ "country": {value: "US", state: "auto-filled"},
+ "email": {value: "foo@mozilla.com", state: "auto-filled"},
+ "tel": {value: "1234567", state: "auto-filled"},
},
},
{
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">
@@ -112,21 +117,23 @@ const TESTCASES = [
"guid": "123",
"street-address": "2 Harrison St",
"address-level2": "San Francisco",
"country": "US",
"email": "",
"tel": "",
},
expectedResult: {
- "street-addr": "2 Harrison St",
- "city": "San Francisco",
- "country": "US",
- "email": "",
- "tel": "",
+ "given-name": {value: "", state: "fall-back"},
+ "family-name": {value: "", state: "fall-back"},
+ "street-addr": {value: "2 Harrison St", state: "auto-filled"},
+ "city": {value: "San Francisco", state: "auto-filled"},
+ "country": {value: "US", state: "auto-filled"},
+ "email": {value: "", state: "fall-back"},
+ "tel": {value: "", state: "fall-back"},
},
},
{
description: "Form with autocomplete properties but mismatched",
document: `<form><input id="given-name" autocomplete="shipping given-name">
<input id="family-name" autocomplete="shipping family-name">
<input id="street-addr" autocomplete="billing street-address">
<input id="city" autocomplete="billing address-level2">
@@ -146,21 +153,23 @@ const TESTCASES = [
"guid": "123",
"street-address": "",
"address-level2": "",
"country": "",
"email": "foo@mozilla.com",
"tel": "1234567",
},
expectedResult: {
- "street-addr": "",
- "city": "",
- "country": "",
- "email": "foo@mozilla.com",
- "tel": "1234567",
+ "given-name": {value: "", state: "fall-back"},
+ "family-name": {value: "", state: "fall-back"},
+ "street-addr": {value: "", state: "fall-back"},
+ "city": {value: "", state: "fall-back"},
+ "country": {value: "", state: "fall-back"},
+ "email": {value: "foo@mozilla.com", state: "auto-filled"},
+ "tel": {value: "1234567", state: "auto-filled"},
},
},
];
for (let tc of TESTCASES) {
(function() {
let testcase = tc;
add_task(function* () {
@@ -179,23 +188,28 @@ for (let tc of TESTCASES) {
if (!testcase.profileData[field.fieldName]) {
// Avoid waiting for `change` event of a input with a blank value to
// be filled.
return;
}
onChangePromises.push(new Promise(resolve => {
element.addEventListener("change", () => {
let id = element.id;
- Assert.equal(element.value, testcase.expectedResult[id],
+ Assert.equal(element.value, testcase.expectedResult[id].value,
"Check the " + id + " fields were filled with correct data");
resolve();
}, {once: true});
}));
});
handler.autofillFormFields(testcase.profileData);
Assert.equal(handler.filledProfileGUID, testcase.profileData.guid,
"Check if filledProfileGUID is set correctly");
+
+ handler.fieldDetails.forEach((detail) => {
+ Assert.equal(detail.state, testcase.expectedResult[detail.element.id].state,
+ "Check if state is set correctly");
+ });
yield Promise.all(onChangePromises);
});
})();
}