Bug 1374852 - Visiting preferences should always focus on search field r?jaws draft
authorRicky Chien <ricky060709@gmail.com>
Thu, 22 Jun 2017 14:59:51 +0800
changeset 600272 53214cc6f673f3de44a26d4f74bd04d0cd3440df
parent 599983 92dc60b522d81862e52bff5cdb1b698eb5608658
child 634940 1ddee8f0514b2d993bcca84b8c2c0a348a30603c
push id65701
push userbmo:rchien@mozilla.com
push dateSun, 25 Jun 2017 06:07:30 +0000
reviewersjaws
bugs1374852
milestone56.0a1
Bug 1374852 - Visiting preferences should always focus on search field r?jaws MozReview-Commit-ID: I7mnm5EkeIg
browser/components/preferences/in-content-new/findInPage.js
browser/components/preferences/in-content-new/tests/browser_search_within_preferences_1.js
browser/components/preferences/in-content-new/tests/browser_search_within_preferences_2.js
--- a/browser/components/preferences/in-content-new/findInPage.js
+++ b/browser/components/preferences/in-content-new/findInPage.js
@@ -11,16 +11,17 @@ var gSearchResultsPane = {
   searchInput: null,
 
   init() {
     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.focus();
       this.searchInput.addEventListener("command", this);
       this.searchInput.addEventListener("focus", this);
     }
   },
 
   handleEvent(event) {
     if (event.type === "command") {
       this.searchFunction(event);
--- 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") {