Bug 1379575 - Do not show focused category in autofill notes if none of the profiles have been selected. r=MattN
MozReview-Commit-ID: LqOKKZMWtvR
--- a/browser/extensions/formautofill/ProfileAutoCompleteResult.jsm
+++ b/browser/extensions/formautofill/ProfileAutoCompleteResult.jsm
@@ -38,16 +38,17 @@ this.ProfileAutoCompleteResult = functio
this._allFieldNames,
this._matchingProfiles);
// Add an empty result entry for footer. Its content will come from
// the footer binding, so don't assign any value to it.
this._popupLabels.push({
primary: "",
secondary: "",
categories: FormAutofillUtils.getCategoriesFromFieldNames(allFieldNames),
+ focusedCategory: FormAutofillUtils.getCategoryFromFieldName(focusedFieldName),
});
};
ProfileAutoCompleteResult.prototype = {
// The user's query string
searchString: "",
--- a/browser/extensions/formautofill/content/formautofill.xml
+++ b/browser/extensions/formautofill/content/formautofill.xml
@@ -164,67 +164,67 @@
);
this._optionButton = document.getAnonymousElementByAttribute(
this, "anonid", "autofill-option-button"
);
this._warningTextBox = document.getAnonymousElementByAttribute(
this, "anonid", "autofill-warning"
);
- this.allFieldCategories = JSON.parse(this.getAttribute("ac-value")).categories;
+ let {categories: allFieldCategories, focusedCategory} = JSON.parse(this.getAttribute("ac-value"));
/**
* Update the text on the footer.
*
* @private
* @param {string|string[]} categories
* A list of categories that used to generate the message.
* @param {boolean} hasExtraCategories
* Used to determine if it has the extra categories other than the focued category. If
* the value is true, we show "Also fill ...", otherwise, show "Fill ..." only.
*/
- this._updateText = (categories = this.allFieldCategories, hasExtraCategories = true) => {
+ this._updateText = (categories = allFieldCategories, hasExtraCategories = true) => {
let warningTextTmplKey = hasExtraCategories ? "phishingWarningMessage" : "phishingWarningMessage2";
let sep = this._stringBundle.GetStringFromName("fieldNameSeparator");
- let categoriesText = categories.map(this._stringBundle.GetStringFromName).join(sep);
+ // Show the categories in certain order to conform with the spec.
+ let orderedCategoryList = ["address", "name", "organization", "tel", "email"];
+ let showCategories = hasExtraCategories ?
+ orderedCategoryList.filter(category => categories.includes(category) && category != focusedCategory) :
+ [focusedCategory];
+ let categoriesText = showCategories.map(this._stringBundle.GetStringFromName).join(sep);
this._warningTextBox.textContent = this._stringBundle.formatStringFromName(warningTextTmplKey,
[categoriesText], 1);
this.parentNode.parentNode.adjustHeight();
};
/**
* A handler for updating warning message once selectedIndex has been changed.
*
* There're three different states of warning message:
* 1. None of addresses were selected: We show all the categories in the form.
* 2. An address was selested: Show the additional categories that will also be filled.
* 3. An address was selected, but the focused category is the same as the only all categories: Only show
* the exact category that we're going to fill in.
*
* @private
- * @param {string} focusedCategory
- * The category that the focused input's field belongs to.
* @param {string[]} categories
* The categories of all the fields contained in the selected address.
*/
- this._updateWarningMsgHandler = ({data: {focusedCategory, categories}} = {data: {}}) => {
+ this._updateWarningMsgHandler = ({data: {categories}} = {data: {}}) => {
let hasSelectedAddress = focusedCategory && categories;
// If the length of categories is 1, that means all the fillable fields are in the same
// category. We will change the way to inform user according to this flag.
let hasExtraCategories = hasSelectedAddress && categories.length > 1;
if (!hasSelectedAddress) {
this._updateText();
return;
}
- let showCategories = hasExtraCategories ?
- categories.filter(category => category != focusedCategory) :
- [focusedCategory];
- this._updateText(showCategories, hasExtraCategories);
+ this._updateText(categories, hasExtraCategories);
};
this._adjustAcItem();
this._updateText();
]]>
</constructor>
<method name="_onCollapse">
--- a/browser/extensions/formautofill/test/browser/browser_autocomplete_footer.js
+++ b/browser/extensions/formautofill/test/browser/browser_autocomplete_footer.js
@@ -64,24 +64,24 @@ add_task(async function test_press_enter
add_task(async function test_phishing_warning() {
await BrowserTestUtils.withNewTab({gBrowser, url: URL}, async function(browser) {
const {autoCompletePopup, autoCompletePopup: {richlistbox: itemsBox}} = browser;
await openPopupOn(browser, "#street-address");
const warningBox = itemsBox.querySelector(".autocomplete-richlistitem:last-child")._warningTextBox;
ok(warningBox, "Got phishing warning box");
- await expectWarningText(browser, "Also fill company, address, phone, email");
+ await expectWarningText(browser, "Also fill company, phone, email");
await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
await expectWarningText(browser, "Also fill company, phone, email");
await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
await expectWarningText(browser, "Fill address");
await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
- await expectWarningText(browser, "Also fill company, address, phone, email");
+ await expectWarningText(browser, "Also fill company, phone, email");
// Ensure the popup is closed before entering the next test.
await ContentTask.spawn(browser, {}, async function() {
content.document.getElementById("street-address").blur();
});
await BrowserTestUtils.waitForCondition(() => !autoCompletePopup.popupOpen);
});
});