--- a/browser/extensions/formautofill/test/unit/test_getFormInputDetails.js
+++ b/browser/extensions/formautofill/test/unit/test_getFormInputDetails.js
@@ -1,67 +1,71 @@
"use strict";
Cu.import("resource://formautofill/FormAutofillContent.jsm");
const TESTCASES = [
{
description: "Form containing 5 fields with autocomplete attribute.",
- document: `<form>
+ document: `<form id="form1">
<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>`,
targetInput: ["street-addr", "country"],
expectedResult: [{
input: {"section": "", "addressType": "", "contactType": "", "fieldName": "street-address"},
+ formId: "form1",
form: [
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "country"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "email"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "tel"},
],
},
{
input: {"section": "", "addressType": "", "contactType": "", "fieldName": "country"},
+ formId: "form1",
form: [
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "country"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "email"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "tel"},
],
}],
},
{
description: "2 forms that are able to be auto filled",
- document: `<form>
+ document: `<form id="form2">
<input id="home-addr" autocomplete="street-address">
<input id="city" autocomplete="address-level2">
<input id="country" autocomplete="country">
</form>
- <form>
+ <form id="form3">
<input id="office-addr" autocomplete="street-address">
<input id="email" autocomplete="email">
<input id="tel" autocomplete="tel">
</form>`,
targetInput: ["home-addr", "office-addr"],
expectedResult: [{
input: {"section": "", "addressType": "", "contactType": "", "fieldName": "street-address"},
+ formId: "form2",
form: [
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "country"},
],
},
{
input: {"section": "", "addressType": "", "contactType": "", "fieldName": "street-address"},
+ formId: "form3",
form: [
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "email"},
{"section": "", "addressType": "", "contactType": "", "fieldName": "tel"},
],
}],
},
];
@@ -73,18 +77,28 @@ TESTCASES.forEach(testcase => {
let doc = MockDocument.createTestDocument(
"http://localhost:8080/test/", testcase.document);
FormAutofillContent._identifyAutofillFields(doc);
for (let i in testcase.targetInput) {
let input = doc.getElementById(testcase.targetInput[i]);
+ // Put the input element reference to `element` to make sure the result of
+ // `getInputDetails` contains the same input element.
+ testcase.expectedResult[i].input.element = input;
Assert.deepEqual(FormAutofillContent.getInputDetails(input),
testcase.expectedResult[i].input,
"Check if returned input information is correct.");
+ let formDetails = testcase.expectedResult[i].form;
+ for (let formDetail of formDetails) {
+ // Compose a query string to get the exact reference of the input
+ // element, e.g. #form1 > input[autocomplete="street-address"]
+ let queryString = "#" + testcase.expectedResult[i].formId + " > input[autocomplete=" + formDetail.fieldName + "]";
+ formDetail.element = doc.querySelector(queryString);
+ }
Assert.deepEqual(FormAutofillContent.getFormDetails(input),
- testcase.expectedResult[i].form,
+ formDetails,
"Check if returned form information is correct.");
}
});
});
deleted file mode 100644
--- a/browser/extensions/formautofill/test/unit/test_populateFieldValues.js
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Test for populating field values in Form Autofill Parent.
- */
-
-"use strict";
-
-Cu.import("resource://formautofill/FormAutofillParent.jsm");
-
-do_get_profile();
-
-const TEST_FIELDS = [
- {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "organization"},
- {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address"},
- {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2"},
- {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level1"},
- {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "postal-code"},
- {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country"},
- {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "tel"},
- {"section": "", "addressType": "shipping", "contactType": "", "fieldName": "email"},
-];
-
-const TEST_GUID = "test-guid";
-
-const TEST_PROFILE = {
- guid: TEST_GUID,
- organization: "World Wide Web Consortium",
- "street-address": "32 Vassar Street\nMIT Room 32-G524",
- "address-level2": "Cambridge",
- "address-level1": "MA",
- postalCode: "02139",
- country: "US",
- tel: "+1 617 253 5702",
- email: "timbl@w3.org",
-};
-
-add_task(function* test_populateFieldValues() {
- let formAutofillParent = new FormAutofillParent();
- formAutofillParent.init();
-
- let store = formAutofillParent.getProfileStore();
- do_check_neq(store, null);
-
- store.get = function(guid) {
- do_check_eq(guid, TEST_GUID);
- return store._clone(TEST_PROFILE);
- };
-
- let notifyUsedCalledCount = 0;
- store.notifyUsed = function(guid) {
- do_check_eq(guid, TEST_GUID);
- notifyUsedCalledCount++;
- };
-
- yield new Promise((resolve) => {
- formAutofillParent.receiveMessage({
- name: "FormAutofill:PopulateFieldValues",
- data: {
- guid: TEST_GUID,
- fields: TEST_FIELDS,
- },
- target: {
- sendAsyncMessage(name, data) {
- do_check_eq(name, "FormAutofill:fillForm");
-
- let fields = data.fields;
- do_check_eq(fields.length, TEST_FIELDS.length);
-
- for (let i = 0; i < fields.length; i++) {
- do_check_eq(fields[i].fieldName, TEST_FIELDS[i].fieldName);
- do_check_eq(fields[i].value,
- TEST_PROFILE[fields[i].fieldName]);
- }
-
- resolve();
- },
- },
- });
- });
-
- do_check_eq(notifyUsedCalledCount, 1);
-
- formAutofillParent._uninit();
- do_check_null(formAutofillParent.getProfileStore());
-});
-
-add_task(function* test_populateFieldValues_with_invalid_guid() {
- let formAutofillParent = new FormAutofillParent();
- formAutofillParent.init();
-
- Assert.throws(() => {
- formAutofillParent.receiveMessage({
- name: "FormAutofill:PopulateFieldValues",
- data: {
- guid: "invalid-guid",
- fields: TEST_FIELDS,
- },
- target: {},
- });
- }, /No matching profile\./);
-
- formAutofillParent._uninit();
-});
--- a/browser/extensions/formautofill/test/unit/test_profileAutocompleteResult.js
+++ b/browser/extensions/formautofill/test/unit/test_profileAutocompleteResult.js
@@ -1,74 +1,152 @@
"use strict";
Cu.import("resource://formautofill/ProfileAutoCompleteResult.jsm");
let matchingProfiles = [{
guid: "test-guid-1",
organization: "Sesame Street",
- streetAddress: "123 Sesame Street.",
+ "street-address": "123 Sesame Street.",
tel: "1-345-345-3456.",
}, {
guid: "test-guid-2",
organization: "Mozilla",
- streetAddress: "331 E. Evelyn Avenue",
+ "street-address": "331 E. Evelyn Avenue",
tel: "1-650-903-0800",
}];
+let allFieldNames = ["street-address", "organization", "tel"];
+
let testCases = [{
options: {},
matchingProfiles,
+ allFieldNames,
searchString: "",
- fieldName: "",
+ fieldName: "organization",
+ expected: {
+ searchResult: Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
+ defaultIndex: 0,
+ items: [{
+ value: "Sesame Street",
+ style: "autofill-profile",
+ comment: JSON.stringify(matchingProfiles[0]),
+ label: JSON.stringify({
+ primary: "Sesame Street",
+ secondary: "123 Sesame Street.",
+ }),
+ image: "",
+ }, {
+ value: "Mozilla",
+ style: "autofill-profile",
+ comment: JSON.stringify(matchingProfiles[1]),
+ label: JSON.stringify({
+ primary: "Mozilla",
+ secondary: "331 E. Evelyn Avenue",
+ }),
+ image: "",
+ }],
+ },
+}, {
+ options: {},
+ matchingProfiles,
+ allFieldNames,
+ searchString: "",
+ fieldName: "tel",
expected: {
searchResult: Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
defaultIndex: 0,
items: [{
+ value: "1-345-345-3456.",
style: "autofill-profile",
+ comment: JSON.stringify(matchingProfiles[0]),
+ label: JSON.stringify({
+ primary: "1-345-345-3456.",
+ secondary: "123 Sesame Street.",
+ }),
image: "",
}, {
+ value: "1-650-903-0800",
style: "autofill-profile",
+ comment: JSON.stringify(matchingProfiles[1]),
+ label: JSON.stringify({
+ primary: "1-650-903-0800",
+ secondary: "331 E. Evelyn Avenue",
+ }),
+ image: "",
+ }],
+ },
+}, {
+ options: {},
+ matchingProfiles,
+ allFieldNames,
+ searchString: "",
+ fieldName: "street-address",
+ expected: {
+ searchResult: Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
+ defaultIndex: 0,
+ items: [{
+ value: "123 Sesame Street.",
+ style: "autofill-profile",
+ comment: JSON.stringify(matchingProfiles[0]),
+ label: JSON.stringify({
+ primary: "123 Sesame Street.",
+ secondary: "Sesame Street",
+ }),
+ image: "",
+ }, {
+ value: "331 E. Evelyn Avenue",
+ style: "autofill-profile",
+ comment: JSON.stringify(matchingProfiles[1]),
+ label: JSON.stringify({
+ primary: "331 E. Evelyn Avenue",
+ secondary: "Mozilla",
+ }),
image: "",
}],
},
}, {
options: {},
matchingProfiles: [],
+ allFieldNames,
searchString: "",
fieldName: "",
expected: {
searchResult: Ci.nsIAutoCompleteResult.RESULT_NOMATCH,
defaultIndex: 0,
items: [],
},
}, {
options: {resultCode: Ci.nsIAutoCompleteResult.RESULT_FAILURE},
matchingProfiles: [],
+ allFieldNames,
searchString: "",
fieldName: "",
expected: {
searchResult: Ci.nsIAutoCompleteResult.RESULT_FAILURE,
defaultIndex: 0,
items: [],
},
}];
add_task(function* test_all_patterns() {
testCases.forEach(pattern => {
let actual = new ProfileAutoCompleteResult(pattern.searchString,
pattern.fieldName,
+ pattern.allFieldNames,
pattern.matchingProfiles,
pattern.options);
let expectedValue = pattern.expected;
equal(actual.searchResult, expectedValue.searchResult);
equal(actual.defaultIndex, expectedValue.defaultIndex);
equal(actual.matchCount, expectedValue.items.length);
expectedValue.items.forEach((item, index) => {
- // TODO: getValueAt, getLabelAt, and getCommentAt should be verified here.
+ equal(actual.getValueAt(index), item.value);
+ equal(actual.getCommentAt(index), item.comment);
+ equal(actual.getLabelAt(index), item.label);
equal(actual.getStyleAt(index), item.style);
equal(actual.getImageAt(index), item.image);
});
if (expectedValue.items.length != 0) {
Assert.throws(() => actual.getValueAt(expectedValue.items.length),
/Index out of range\./);
--- a/browser/extensions/formautofill/test/unit/xpcshell.ini
+++ b/browser/extensions/formautofill/test/unit/xpcshell.ini
@@ -3,11 +3,10 @@ firefox-appdir = browser
head = head.js
support-files =
[test_autofillFormFields.js]
[test_collectFormFields.js]
[test_enabledStatus.js]
[test_getFormInputDetails.js]
[test_markAsAutofillField.js]
-[test_populateFieldValues.js]
[test_profileAutocompleteResult.js]
[test_profileStorage.js]