Bug 1340104 - Hide the result without primary label in ProfileAutoCompleteResult.; r=MattN
authorSean Lee <selee@mozilla.com>
Thu, 16 Feb 2017 23:05:35 +0800
changeset 393215 1d16150ba521dc1e7d5a71b8bb01beef61c47447
parent 393214 8b02cdbaa32e9a4deedb9cb7fe8eb8a5268c27c6
child 393216 6c746c1306a2d686c6d13ddc004e7e42549812ca
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1340104
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1340104 - Hide the result without primary label in ProfileAutoCompleteResult.; r=MattN MozReview-Commit-ID: FSqU2fnKjeB
browser/extensions/formautofill/ProfileAutoCompleteResult.jsm
browser/extensions/formautofill/test/unit/test_profileAutocompleteResult.js
--- a/browser/extensions/formautofill/ProfileAutoCompleteResult.jsm
+++ b/browser/extensions/formautofill/ProfileAutoCompleteResult.jsm
@@ -64,21 +64,21 @@ ProfileAutoCompleteResult.prototype = {
 
   // An array of primary and secondary labels for each profiles.
   _popupLabels: null,
 
   /**
    * @returns {number} The number of results
    */
   get matchCount() {
-    return this._matchingProfiles.length;
+    return this._popupLabels.length;
   },
 
   _checkIndexBounds(index) {
-    if (index < 0 || index >= this._matchingProfiles.length) {
+    if (index < 0 || index >= this._popupLabels.length) {
       throw Components.Exception("Index out of range.", Cr.NS_ERROR_ILLEGAL_VALUE);
     }
   },
 
   /**
    * Get the secondary label based on the focused field name and related field names
    * in the same form.
    * @param   {string} focusedFieldName The field name of the focused input
@@ -118,17 +118,20 @@ ProfileAutoCompleteResult.prototype = {
         return profile[currentFieldName];
       }
     }
 
     return ""; // Nothing matched.
   },
 
   _generateLabels(focusedFieldName, allFieldNames, profiles) {
-    return profiles.map(profile => {
+    // Skip results without a primary label.
+    return profiles.filter(profile => {
+      return !!profile[focusedFieldName];
+    }).map(profile => {
       return {
         primary: profile[focusedFieldName],
         secondary: this._getSecondaryLabel(focusedFieldName,
                                            allFieldNames,
                                            profile),
       };
     });
   },
--- a/browser/extensions/formautofill/test/unit/test_profileAutocompleteResult.js
+++ b/browser/extensions/formautofill/test/unit/test_profileAutocompleteResult.js
@@ -7,21 +7,27 @@ let matchingProfiles = [{
   organization: "Sesame Street",
   "street-address": "123 Sesame Street.",
   tel: "1-345-345-3456.",
 }, {
   guid: "test-guid-2",
   organization: "Mozilla",
   "street-address": "331 E. Evelyn Avenue",
   tel: "1-650-903-0800",
+}, {
+  guid: "test-guid-3",
+  organization: "",
+  "street-address": "321, No Name St.",
+  tel: "1-000-000-0000",
 }];
 
 let allFieldNames = ["street-address", "organization", "tel"];
 
 let testCases = [{
+  description: "Focus on an `organization` field",
   options: {},
   matchingProfiles,
   allFieldNames,
   searchString: "",
   fieldName: "organization",
   expected: {
     searchResult: Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
     defaultIndex: 0,
@@ -41,16 +47,17 @@ let testCases = [{
       label: JSON.stringify({
         primary: "Mozilla",
         secondary: "331 E. Evelyn Avenue",
       }),
       image: "",
     }],
   },
 }, {
+  description: "Focus on an `tel` field",
   options: {},
   matchingProfiles,
   allFieldNames,
   searchString: "",
   fieldName: "tel",
   expected: {
     searchResult: Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
     defaultIndex: 0,
@@ -67,19 +74,29 @@ let testCases = [{
       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: "",
+    }, {
+      value: "1-000-000-0000",
+      style: "autofill-profile",
+      comment: JSON.stringify(matchingProfiles[2]),
+      label: JSON.stringify({
+        primary: "1-000-000-0000",
+        secondary: "321, No Name St.",
+      }),
+      image: "",
     }],
   },
 }, {
+  description: "Focus on an `street-address` field",
   options: {},
   matchingProfiles,
   allFieldNames,
   searchString: "",
   fieldName: "street-address",
   expected: {
     searchResult: Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
     defaultIndex: 0,
@@ -96,50 +113,62 @@ let testCases = [{
       value: "331 E. Evelyn Avenue",
       style: "autofill-profile",
       comment: JSON.stringify(matchingProfiles[1]),
       label: JSON.stringify({
         primary: "331 E. Evelyn Avenue",
         secondary: "Mozilla",
       }),
       image: "",
+    }, {
+      value: "321, No Name St.",
+      style: "autofill-profile",
+      comment: JSON.stringify(matchingProfiles[2]),
+      label: JSON.stringify({
+        primary: "321, No Name St.",
+        secondary: "1-000-000-0000",
+      }),
+      image: "",
     }],
   },
 }, {
+  description: "No matching profiles",
   options: {},
   matchingProfiles: [],
   allFieldNames,
   searchString: "",
   fieldName: "",
   expected: {
     searchResult: Ci.nsIAutoCompleteResult.RESULT_NOMATCH,
     defaultIndex: 0,
     items: [],
   },
 }, {
+  description: "Search with failure",
   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;
+  testCases.forEach(testCase => {
+    do_print("Starting testcase: " + testCase.description);
+    let actual = new ProfileAutoCompleteResult(testCase.searchString,
+                                               testCase.fieldName,
+                                               testCase.allFieldNames,
+                                               testCase.matchingProfiles,
+                                               testCase.options);
+    let expectedValue = testCase.expected;
     equal(actual.searchResult, expectedValue.searchResult);
     equal(actual.defaultIndex, expectedValue.defaultIndex);
     equal(actual.matchCount, expectedValue.items.length);
     expectedValue.items.forEach((item, index) => {
       equal(actual.getValueAt(index), item.value);
       equal(actual.getCommentAt(index), item.comment);
       equal(actual.getLabelAt(index), item.label);
       equal(actual.getStyleAt(index), item.style);