зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1334037 - [Form Autofill] Support name fields in profiles. r=MattN
MozReview-Commit-ID: AW2CVAY0ghi --HG-- extra : rebase_source : c193be5b6e7f7aba6467673594af584d1e40a4be
This commit is contained in:
Родитель
d05d6700df
Коммит
74015d07b3
|
@ -17,6 +17,9 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|||
*/
|
||||
this.FormAutofillHeuristics = {
|
||||
VALID_FIELDS: [
|
||||
"given-name",
|
||||
"additional-name",
|
||||
"family-name",
|
||||
"organization",
|
||||
"street-address",
|
||||
"address-level2",
|
||||
|
|
|
@ -90,18 +90,28 @@ ProfileAutoCompleteResult.prototype = {
|
|||
/* TODO: Since "name" is a special case here, so the secondary "name" label
|
||||
will be refined when the handling rule for "name" is ready.
|
||||
*/
|
||||
const possibleNameFields = ["given-name", "additional-name", "family-name"];
|
||||
const possibleNameFields = [
|
||||
"name",
|
||||
"given-name",
|
||||
"additional-name",
|
||||
"family-name",
|
||||
];
|
||||
|
||||
focusedFieldName = possibleNameFields.includes(focusedFieldName) ?
|
||||
"name" : focusedFieldName;
|
||||
if (!profile.name) {
|
||||
profile.name = FormAutofillUtils.generateFullName(profile["given-name"],
|
||||
profile["family-name"],
|
||||
profile["additional-name"]);
|
||||
|
||||
// Clones the profile to avoid exposing our modification.
|
||||
let clonedProfile = Object.assign({}, profile);
|
||||
if (!clonedProfile.name) {
|
||||
clonedProfile.name =
|
||||
FormAutofillUtils.generateFullName(clonedProfile["given-name"],
|
||||
clonedProfile["family-name"],
|
||||
clonedProfile["additional-name"]);
|
||||
}
|
||||
|
||||
const secondaryLabelOrder = [
|
||||
"street-address", // Street address
|
||||
"name", // Full name if needed
|
||||
"name", // Full name
|
||||
"address-level2", // City/Town
|
||||
"organization", // Company or organization name
|
||||
"address-level1", // Province/State (Standardized code if possible)
|
||||
|
@ -112,10 +122,20 @@ ProfileAutoCompleteResult.prototype = {
|
|||
];
|
||||
|
||||
for (const currentFieldName of secondaryLabelOrder) {
|
||||
if (focusedFieldName != currentFieldName &&
|
||||
allFieldNames.includes(currentFieldName) &&
|
||||
profile[currentFieldName]) {
|
||||
return profile[currentFieldName];
|
||||
if (focusedFieldName == currentFieldName ||
|
||||
!clonedProfile[currentFieldName]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let matching;
|
||||
if (currentFieldName == "name") {
|
||||
matching = allFieldNames.some(fieldName => possibleNameFields.includes(fieldName));
|
||||
} else {
|
||||
matching = allFieldNames.includes(currentFieldName);
|
||||
}
|
||||
|
||||
if (matching) {
|
||||
return clonedProfile[currentFieldName];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
* guid, // 12 character...
|
||||
*
|
||||
* // profile
|
||||
* given-name,
|
||||
* additional-name,
|
||||
* family-name,
|
||||
* organization, // Company
|
||||
* street-address, // (Multiline)
|
||||
* address-level2, // City/Town
|
||||
|
@ -63,6 +66,9 @@ const SCHEMA_VERSION = 1;
|
|||
|
||||
// Name-related fields will be handled in follow-up bugs due to the complexity.
|
||||
const VALID_FIELDS = [
|
||||
"given-name",
|
||||
"additional-name",
|
||||
"family-name",
|
||||
"organization",
|
||||
"street-address",
|
||||
"address-level2",
|
||||
|
|
|
@ -25,6 +25,8 @@ const TESTCASES = [
|
|||
<input id="email" autocomplete="email">
|
||||
<input id="tel" autocomplete="tel"></form>`,
|
||||
fieldDetails: [
|
||||
{"section": "", "addressType": "", "contactType": "", "fieldName": "given-name"},
|
||||
{"section": "", "addressType": "", "contactType": "", "fieldName": "family-name"},
|
||||
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address"},
|
||||
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2"},
|
||||
{"section": "", "addressType": "", "contactType": "", "fieldName": "country"},
|
||||
|
@ -42,6 +44,8 @@ const TESTCASES = [
|
|||
<input id='email' autocomplete="shipping email">
|
||||
<input id="tel" autocomplete="shipping tel"></form>`,
|
||||
fieldDetails: [
|
||||
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name"},
|
||||
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name"},
|
||||
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address"},
|
||||
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2"},
|
||||
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country"},
|
||||
|
@ -59,6 +63,8 @@ const TESTCASES = [
|
|||
<input id='email' autocomplete="shipping email">
|
||||
<input id="tel" autocomplete="shipping tel"></form>`,
|
||||
fieldDetails: [
|
||||
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "given-name"},
|
||||
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "family-name"},
|
||||
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "street-address"},
|
||||
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "address-level2"},
|
||||
{"section": "", "addressType": "shipping", "contactType": "", "fieldName": "country"},
|
||||
|
|
|
@ -4,8 +4,11 @@ Cu.import("resource://formautofill/FormAutofillContent.jsm");
|
|||
|
||||
const TESTCASES = [
|
||||
{
|
||||
description: "Form containing 5 fields with autocomplete attribute.",
|
||||
description: "Form containing 8 fields with autocomplete attribute.",
|
||||
document: `<form>
|
||||
<input id="given-name" autocomplete="given-name">
|
||||
<input id="additional-name" autocomplete="additional-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">
|
||||
|
@ -15,6 +18,9 @@ const TESTCASES = [
|
|||
<input id="without-autocomplete-2">
|
||||
</form>`,
|
||||
expectedResult: [
|
||||
"given-name",
|
||||
"additional-name",
|
||||
"family-name",
|
||||
"street-addr",
|
||||
"city",
|
||||
"country",
|
||||
|
|
|
@ -4,11 +4,15 @@ Cu.import("resource://formautofill/ProfileAutoCompleteResult.jsm");
|
|||
|
||||
let matchingProfiles = [{
|
||||
guid: "test-guid-1",
|
||||
"given-name": "Timothy",
|
||||
"family-name": "Berners-Lee",
|
||||
organization: "Sesame Street",
|
||||
"street-address": "123 Sesame Street.",
|
||||
tel: "1-345-345-3456.",
|
||||
}, {
|
||||
guid: "test-guid-2",
|
||||
"given-name": "John",
|
||||
"family-name": "Doe",
|
||||
organization: "Mozilla",
|
||||
"street-address": "331 E. Evelyn Avenue",
|
||||
tel: "1-650-903-0800",
|
||||
|
@ -19,7 +23,7 @@ let matchingProfiles = [{
|
|||
tel: "1-000-000-0000",
|
||||
}];
|
||||
|
||||
let allFieldNames = ["street-address", "organization", "tel"];
|
||||
let allFieldNames = ["given-name", "family-name", "street-address", "organization", "tel"];
|
||||
|
||||
let testCases = [{
|
||||
description: "Focus on an `organization` field",
|
||||
|
@ -106,7 +110,7 @@ let testCases = [{
|
|||
comment: JSON.stringify(matchingProfiles[0]),
|
||||
label: JSON.stringify({
|
||||
primary: "123 Sesame Street.",
|
||||
secondary: "Sesame Street",
|
||||
secondary: "Timothy Berners-Lee",
|
||||
}),
|
||||
image: "",
|
||||
}, {
|
||||
|
@ -115,7 +119,7 @@ let testCases = [{
|
|||
comment: JSON.stringify(matchingProfiles[1]),
|
||||
label: JSON.stringify({
|
||||
primary: "331 E. Evelyn Avenue",
|
||||
secondary: "Mozilla",
|
||||
secondary: "John Doe",
|
||||
}),
|
||||
image: "",
|
||||
}, {
|
||||
|
|
|
@ -10,6 +10,9 @@ Cu.import("resource://formautofill/ProfileStorage.jsm");
|
|||
const TEST_STORE_FILE_NAME = "test-profile.json";
|
||||
|
||||
const TEST_PROFILE_1 = {
|
||||
"given-name": "Timothy",
|
||||
"additional-name": "John",
|
||||
"family-name": "Berners-Lee",
|
||||
organization: "World Wide Web Consortium",
|
||||
"street-address": "32 Vassar Street\nMIT Room 32-G524",
|
||||
"address-level2": "Cambridge",
|
||||
|
|
Загрузка…
Ссылка в новой задаче