Bug 1374852 - Visiting preferences should always focus on search field r?jaws
MozReview-Commit-ID: H8vJP9jUjRz
--- a/browser/components/preferences/in-content-new/findInPage.js
+++ b/browser/components/preferences/in-content-new/findInPage.js
@@ -4,25 +4,32 @@
/* import-globals-from preferences.js */
var gSearchResultsPane = {
listSearchTooltips: new Set(),
listSearchMenuitemIndicators: new Set(),
searchResultsCategory: null,
searchInput: null,
+ inited: false,
init() {
+ if (this.inited) {
+ return;
+ }
+ this.inited = true;
this.searchResultsCategory = document.getElementById("category-search-results");
-
this.searchInput = document.getElementById("searchInput");
this.searchInput.hidden = !Services.prefs.getBoolPref("browser.preferences.search");
if (!this.searchInput.hidden) {
this.searchInput.addEventListener("command", this);
- this.searchInput.addEventListener("focus", this);
+ window.addEventListener("load", () => {
+ this.searchInput.focus();
+ this.initializeCategories();
+ });
// Throttling the resize event to reduce the callback frequency
let callbackId;
window.addEventListener("resize", () => {
if (!callbackId) {
callbackId = window.requestAnimationFrame(() => {
this.listSearchTooltips.forEach((anchorNode) => {
this.calculateTooltipPosition(anchorNode);
@@ -32,18 +39,16 @@ var gSearchResultsPane = {
}
});
}
},
handleEvent(event) {
if (event.type === "command") {
this.searchFunction(event);
- } else if (event.type === "focus") {
- this.initializeCategories();
}
},
/**
* Check that the passed string matches the filter arguments.
*
* @param String str
* to search for filter words in.
--- a/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_1.js
+++ b/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_1.js
@@ -40,17 +40,20 @@ add_task(async function() {
* After it runs a search, it tests if the "Search Results" panel is the only selected category.
* The search is then cleared, it then tests if the "General" panel is the only selected category.
*/
add_task(async function() {
await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
// Performs search
let searchInput = gBrowser.contentDocument.getElementById("searchInput");
- searchInput.focus();
+
+ is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"),
+ "Search input should be focused when visiting preferences");
+
searchInput.value = "password";
searchInput.doCommand();
let categoriesList = gBrowser.contentDocument.getElementById("categories");
for (let i = 0; i < categoriesList.childElementCount; i++) {
let child = categoriesList.children[i]
if (child.id == "category-search-results") {
@@ -79,17 +82,20 @@ add_task(async function() {
/**
* Test for "password" case. When we search "password", it should show the "passwordGroup"
*/
add_task(async function() {
await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
// Performs search
let searchInput = gBrowser.contentDocument.getElementById("searchInput");
- searchInput.focus();
+
+ is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"),
+ "Search input should be focused when visiting preferences");
+
searchInput.value = "password";
searchInput.doCommand();
let mainPrefTag = gBrowser.contentDocument.getElementById("mainPrefPane");
for (let i = 0; i < mainPrefTag.childElementCount; i++) {
let child = mainPrefTag.children[i]
if (child.id == "passwordsGroup" ||
@@ -136,17 +142,20 @@ add_task(async function() {
await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
let noResultsEl = gBrowser.contentDocument.querySelector(".no-results-message");
is_element_hidden(noResultsEl, "Should not be in search results yet");
// Performs search
let searchInput = gBrowser.contentDocument.getElementById("searchInput");
- searchInput.focus();
+
+ is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"),
+ "Search input should be focused when visiting preferences");
+
searchInput.value = "coach";
searchInput.doCommand();
is_element_visible(noResultsEl, "Should be in search results");
// Takes search off
searchInput.value = "";
searchInput.doCommand();
@@ -162,17 +171,20 @@ add_task(async function() {
add_task(async function() {
await openPreferencesViaOpenPreferencesAPI("privacy", {leaveOpen: true});
let generalPane = gBrowser.contentDocument.getElementById("header-general");
is_element_hidden(generalPane, "Should not be in general");
// Performs search
let searchInput = gBrowser.contentDocument.getElementById("searchInput");
- searchInput.focus();
+
+ is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"),
+ "Search input should be focused when visiting preferences");
+
searchInput.value = "password";
searchInput.doCommand();
// Takes search off
searchInput.value = "";
searchInput.doCommand();
// Checks if back to normal
@@ -189,17 +201,20 @@ add_task(async function() {
await SpecialPowers.pushPrefEnv({"set": [["browser.storageManager.enabled", false]]});
await openPreferencesViaOpenPreferencesAPI("privacy", {leaveOpen: true});
let generalPane = gBrowser.contentDocument.getElementById("header-general");
is_element_hidden(generalPane, "Should not be in general");
// Performs search
let searchInput = gBrowser.contentDocument.getElementById("searchInput");
- searchInput.focus();
+
+ is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"),
+ "Search input should be focused when visiting preferences");
+
searchInput.value = "site data";
searchInput.doCommand();
let mainPrefTag = gBrowser.contentDocument.getElementById("mainPrefPane");
let child = mainPrefTag.querySelector("#siteDataGroup");
is_element_hidden(child, "Should be hidden in search results");
@@ -215,17 +230,20 @@ add_task(async function() {
/**
* Test for if we go to another tab after searching
*/
add_task(async function() {
await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
let searchInput = gBrowser.contentDocument.getElementById("searchInput");
let searchResultsCategory = gBrowser.contentDocument.getElementById("category-search-results");
- searchInput.focus();
+
+ is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"),
+ "Search input should be focused when visiting preferences");
+
searchInput.value = "password";
searchInput.doCommand();
is(searchResultsCategory.hidden, false, "search results category should be shown");
is(searchResultsCategory.selected, true, "search results category should be selected");
let privacyCategory = gBrowser.contentDocument.getElementById("category-privacy");
privacyCategory.click();
is(searchResultsCategory.hidden, true, "search results category should not be shown");
--- a/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_2.js
+++ b/browser/components/preferences/in-content-new/tests/browser_search_within_preferences_2.js
@@ -22,17 +22,20 @@ add_task(async function() {
// is selected and displayed on the screen.
let weavePrefsDeck = gBrowser.contentDocument.getElementById("weavePrefsDeck");
is(weavePrefsDeck.selectedIndex, 0, "Should select the #noFxaAccount child node");
let noFxaSignUp = weavePrefsDeck.childNodes[0].querySelector("#noFxaSignUp");
is(noFxaSignUp.label, "Create Account", "The Create Account button should exist");
// Performs search.
let searchInput = gBrowser.contentDocument.getElementById("searchInput");
- searchInput.focus();
+
+ is(searchInput, gBrowser.contentDocument.activeElement.closest("#searchInput"),
+ "Search input should be focused when visiting preferences");
+
searchInput.value = "Create Account";
searchInput.doCommand();
let mainPrefTag = gBrowser.contentDocument.getElementById("mainPrefPane");
for (let i = 0; i < mainPrefTag.childElementCount; i++) {
let child = mainPrefTag.children[i];
if (child.id == "header-searchResults" ||
child.id == "weavePrefsDeck") {