Bug 1353862 - Remove the Search Results category, search input string, and highlights after performing a search then clicking on a category, r=jaws draft
authorEvan Tseng <evan@tseng.io>
Tue, 02 May 2017 16:28:11 +0800
changeset 575593 f781f1c0a8b3570d4ca5a1ab66d13ac31b84f935
parent 575474 ebbcdaa5b5802ecd39624dd2acbdda8547b8384d
child 576554 797c4037bcf9b7787e1255754fe29e9c7d8659e5
push id58120
push userbmo:evan@tseng.io
push dateWed, 10 May 2017 18:21:11 +0000
reviewersjaws
bugs1353862
milestone55.0a1
Bug 1353862 - Remove the Search Results category, search input string, and highlights after performing a search then clicking on a category, r=jaws MozReview-Commit-ID: BJC7DOQ5uV0
browser/components/preferences/in-content/preferences.js
browser/components/preferences/in-content/tests/browser_search_within_preferences.js
--- a/browser/components/preferences/in-content/preferences.js
+++ b/browser/components/preferences/in-content/preferences.js
@@ -153,16 +153,21 @@ function gotoPref(aCategory) {
   let breakIndex = category.indexOf("-");
   // Subcategories allow for selecting smaller sections of the preferences
   // until proper search support is enabled (bug 1353954).
   let subcategory = breakIndex != -1 && category.substring(breakIndex + 1);
   if (subcategory) {
     category = category.substring(0, breakIndex);
   }
   category = friendlyPrefCategoryNameToInternalName(category);
+  if (category != "paneSearchResults") {
+    gSearchResultsPane.searchInput.value = "";
+    gSearchResultsPane.searchResultsCategory.hidden = true;
+    gSearchResultsPane.findSelection.removeAllRanges();
+  }
 
   // Updating the hash (below) or changing the selected category
   // will re-enter gotoPref.
   if (gLastHash == category && !subcategory)
     return;
   let item = categories.querySelector(".category[value=" + category + "]");
   if (!item) {
     category = kDefaultCategoryInternalName;
--- a/browser/components/preferences/in-content/tests/browser_search_within_preferences.js
+++ b/browser/components/preferences/in-content/tests/browser_search_within_preferences.js
@@ -35,33 +35,33 @@ add_task(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(function*() {
   yield openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
 
   // Performs search
   let searchInput = gBrowser.contentDocument.getElementById("searchInput");
-  searchInput.doCommand()
+  searchInput.focus();
   searchInput.value = "password";
-  searchInput.doCommand()
+  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") {
       is(child.selected, true, "Search results panel should be selected");
     } else if (child.id) {
       is(child.selected, false, "No other panel should be selected");
     }
   }
   // Takes search off
   searchInput.value = "";
-  searchInput.doCommand()
+  searchInput.doCommand();
 
   // Checks if back to generalPane
   for (let i = 0; i < categoriesList.childElementCount; i++) {
     let child = categoriesList.children[i]
     if (child.id == "category-general") {
       is(child.selected, true, "General panel should be selected");
     } else if (child.id) {
       is(child.selected, false, "No other panel should be selected");
@@ -74,34 +74,34 @@ add_task(function*() {
 /**
  * Test for "password" case. When we search "password", it should show the "passwordGroup"
  */
 add_task(function*() {
   yield openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
 
   // Performs search
   let searchInput = gBrowser.contentDocument.getElementById("searchInput");
-  searchInput.doCommand()
+  searchInput.focus();
   searchInput.value = "password";
-  searchInput.doCommand()
+  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" || child.id == "weavePrefsDeck" || child.id == "header-searchResults") {
       is_element_visible(child, "Should be in search results");
     } else if (child.id) {
       is_element_hidden(child, "Should not be in search results");
     }
   }
 
   // Takes search off
   searchInput.value = "";
-  searchInput.doCommand()
+  searchInput.doCommand();
 
   // Checks if back to generalPane
   for (let i = 0; i < mainPrefTag.childElementCount; i++) {
     let child = mainPrefTag.children[i]
     if (child.id == "startupGroup"
     || child.id == "defaultEngineGroup"
     || child.id == "oneClickSearchProvidersGroup"
     || child.id == "paneGeneral"
@@ -127,25 +127,25 @@ add_task(function*() {
   yield 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.doCommand()
+  searchInput.focus();
   searchInput.value = "coach";
-  searchInput.doCommand()
+  searchInput.doCommand();
 
   is_element_visible(noResultsEl, "Should be in search results");
 
   // Takes search off
   searchInput.value = "";
-  searchInput.doCommand()
+  searchInput.doCommand();
 
   is_element_hidden(noResultsEl, "Should not be in search results");
 
   yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
 /**
  * Test for if we go back to general tab after search case
@@ -153,23 +153,23 @@ add_task(function*() {
 add_task(function*() {
   yield 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.doCommand()
+  searchInput.focus();
   searchInput.value = "password";
-  searchInput.doCommand()
+  searchInput.doCommand();
 
   // Takes search off
   searchInput.value = "";
-  searchInput.doCommand()
+  searchInput.doCommand();
 
   // Checks if back to normal
   is_element_visible(generalPane, "Should be in generalPane");
 
   yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
 /**
@@ -180,26 +180,56 @@ add_task(function*() {
   yield SpecialPowers.pushPrefEnv({"set": [["browser.storageManager.enabled", false]]});
   yield 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.doCommand()
+  searchInput.focus();
   searchInput.value = "site data";
-  searchInput.doCommand()
+  searchInput.doCommand();
 
   let mainPrefTag = gBrowser.contentDocument.getElementById("mainPrefPane");
 
   let child = mainPrefTag.querySelector("#siteDataGroup");
   is_element_hidden(child, "Should be hidden in search results");
 
   // Takes search off
   searchInput.value = "";
-  searchInput.doCommand()
+  searchInput.doCommand();
 
   // Checks if back to normal
   is_element_visible(generalPane, "Should be in generalPane");
 
   yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
+
+/**
+ * Test for if we go to another tab after searching
+ */
+add_task(function*() {
+  yield openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
+  let searchInput = gBrowser.contentDocument.getElementById("searchInput");
+  let searchResultsCategory = gBrowser.contentDocument.getElementById("category-search-results");
+  searchInput.focus();
+  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");
+  is(searchInput.value, "", "search input should be empty");
+  let categoriesList = gBrowser.contentDocument.getElementById("categories");
+  for (let i = 0; i < categoriesList.childElementCount; i++) {
+    let child = categoriesList.children[i]
+    if (child.id == "category-privacy") {
+      is(child.selected, true, "Privacy panel should be selected");
+    } else if (child.id) {
+      is(child.selected, false, "No other panel should be selected");
+    }
+  }
+
+  yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});