зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1300989 - Part 3: Update xpc-shell tests; r=MattN
MozReview-Commit-ID: LtH0i9nSL3U --HG-- extra : rebase_source : 36ed028ca214fc885cc700adca3be41e31e228ca extra : histedit_source : 5eec15c79f079494952e9334f3154139e0eeb1ef
This commit is contained in:
Родитель
7b0e51ac72
Коммит
327d2bec81
|
@ -5,7 +5,7 @@ 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">
|
||||
|
@ -15,6 +15,7 @@ const TESTCASES = [
|
|||
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"},
|
||||
|
@ -25,6 +26,7 @@ const TESTCASES = [
|
|||
},
|
||||
{
|
||||
input: {"section": "", "addressType": "", "contactType": "", "fieldName": "country"},
|
||||
formId: "form1",
|
||||
form: [
|
||||
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address"},
|
||||
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"},
|
||||
|
@ -36,12 +38,12 @@ const TESTCASES = [
|
|||
},
|
||||
{
|
||||
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">
|
||||
|
@ -49,6 +51,7 @@ const TESTCASES = [
|
|||
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"},
|
||||
|
@ -57,6 +60,7 @@ const TESTCASES = [
|
|||
},
|
||||
{
|
||||
input: {"section": "", "addressType": "", "contactType": "", "fieldName": "street-address"},
|
||||
formId: "form3",
|
||||
form: [
|
||||
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address"},
|
||||
{"section": "", "addressType": "", "contactType": "", "fieldName": "email"},
|
||||
|
@ -78,12 +82,22 @@ TESTCASES.forEach(testcase => {
|
|||
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.");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
});
|
|
@ -5,34 +5,108 @@ 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: {
|
||||
|
@ -43,6 +117,7 @@ let testCases = [{
|
|||
}, {
|
||||
options: {resultCode: Ci.nsIAutoCompleteResult.RESULT_FAILURE},
|
||||
matchingProfiles: [],
|
||||
allFieldNames,
|
||||
searchString: "",
|
||||
fieldName: "",
|
||||
expected: {
|
||||
|
@ -56,6 +131,7 @@ 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;
|
||||
|
@ -63,7 +139,9 @@ add_task(function* test_all_patterns() {
|
|||
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);
|
||||
});
|
||||
|
|
|
@ -8,6 +8,5 @@ support-files =
|
|||
[test_enabledStatus.js]
|
||||
[test_getFormInputDetails.js]
|
||||
[test_markAsAutofillField.js]
|
||||
[test_populateFieldValues.js]
|
||||
[test_profileAutocompleteResult.js]
|
||||
[test_profileStorage.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче