Bug 1353805 - Allow showing only subcategories of a section to make finding prefs easier. r?mconley draft
authorJared Wein <jwein@mozilla.com>
Wed, 05 Apr 2017 23:03:10 -0400
changeset 560724 2464ceb680d8c37638851567ed41b41dd61727b3
parent 560546 abf145ebd05fe105efbc78b761858c34f7690154
child 560727 53e5dd3545184ea685b7835d2dfa49d8758576c6
push id53539
push userbmo:jaws@mozilla.com
push dateTue, 11 Apr 2017 22:35:54 +0000
reviewersmconley
bugs1353805, 1353954
milestone55.0a1
Bug 1353805 - Allow showing only subcategories of a section to make finding prefs easier. r?mconley This is a temporary measure until we have search complete and shipped (1353954). MozReview-Commit-ID: KFeOefJ1RGM
browser/base/content/browser-data-submission-info-bar.js
browser/components/preferences/in-content/advanced.xul
browser/components/preferences/in-content/preferences.js
browser/components/preferences/in-content/tests/browser_bug1020245_openPreferences_to_paneContent.js
--- a/browser/base/content/browser-data-submission-info-bar.js
+++ b/browser/base/content/browser-data-submission-info-bar.js
@@ -66,17 +66,17 @@ var gDataNotificationInfoBar = {
       popup: null,
       callback: () => {
         this._actionTaken = true;
         // The advanced subpanes are only supported in the old organization, which will
         // be removed by bug 1349689.
         if (Preferences.get("browser.preferences.useOldOrganization", false)) {
           window.openAdvancedPreferences("dataChoicesTab");
         } else {
-          window.openPreferences("paneAdvanced");
+          window.openPreferences("advanced-reports");
         }
       },
     }];
 
     this._log.info("Creating data reporting policy notification.");
     this._notificationBox.appendNotification(
       message,
       this._DATA_REPORTING_NOTIFICATION,
--- a/browser/components/preferences/in-content/advanced.xul
+++ b/browser/components/preferences/in-content/advanced.xul
@@ -94,17 +94,17 @@
   <checkbox id="enableSearchUpdate"
             label="&enableSearchUpdate.label;"
             accesskey="&enableSearchUpdate.accesskey;"
             preference="browser.search.update"/>
 </groupbox>
 
 <!-- Data Choices -->
 #ifdef MOZ_TELEMETRY_REPORTING
-<groupbox id="historyGroup" data-category="paneAdvanced" hidden="true">
+<groupbox id="historyGroup" data-category="paneAdvanced" data-subcategory="reports" hidden="true">
 <caption><label>&reports.label;</label></caption>
   <vbox>
     <caption>
     <checkbox id="submitHealthReportBox" label="&enableHealthReport.label;"
               accesskey="&enableHealthReport.accesskey;"/>
   </caption>
     <hbox class="indent" flex="1">
       <label flex="1">&healthReportDesc.label;</label>
@@ -126,17 +126,17 @@
       </groupbox>
     </hbox>
   </vbox>
 </groupbox>
 #endif
 
 #ifdef MOZ_DATA_REPORTING
 #ifdef MOZ_CRASHREPORTER
-<groupbox data-category="paneAdvanced" hidden="true">
+<groupbox data-category="paneAdvanced" data-subcategory="reports" hidden="true">
   <caption>
     <checkbox id="automaticallySubmitCrashesBox"
               preference="browser.crashReports.unsubmittedCheck.autoSubmit"
               label="&alwaysSubmitCrashReports.label;"
               accesskey="&alwaysSubmitCrashReports.accesskey;"/>
   </caption>
   <hbox class="indent" flex="1">
     <label flex="1">&crashReporterDesc2.label;</label>
--- a/browser/components/preferences/in-content/preferences.js
+++ b/browser/components/preferences/in-content/preferences.js
@@ -137,65 +137,83 @@ function telemetryBucketForCategory(cate
 function onHashChange() {
   gotoPref();
 }
 
 function gotoPref(aCategory) {
   let categories = document.getElementById("categories");
   const kDefaultCategoryInternalName = "paneGeneral";
   let hash = document.location.hash;
+  // Subcategories allow for selecting smaller sections of the preferences
+  // until proper search support is enabled (bug 1353954).
+  let breakIndex = hash.indexOf("-");
+  let subcategory = breakIndex != -1 && hash.substring(breakIndex + 1);
+  if (subcategory) {
+    hash = hash.substring(0, breakIndex);
+  }
   let category = aCategory || hash.substr(1) || kDefaultCategoryInternalName;
   category = friendlyPrefCategoryNameToInternalName(category);
 
   // Updating the hash (below) or changing the selected category
   // will re-enter gotoPref.
-  if (gLastHash == category)
+  if (gLastHash == category && !subcategory)
     return;
   let item = categories.querySelector(".category[value=" + category + "]");
   if (!item) {
     category = kDefaultCategoryInternalName;
     item = categories.querySelector(".category[value=" + category + "]");
   }
 
   try {
     init_category_if_required(category);
   } catch (ex) {
     Cu.reportError("Error initializing preference category " + category + ": " + ex);
     throw ex;
   }
 
   let friendlyName = internalPrefCategoryNameToFriendlyName(category);
-  if (gLastHash || category != kDefaultCategoryInternalName) {
+  if (gLastHash || category != kDefaultCategoryInternalName || subcategory) {
     document.location.hash = friendlyName;
   }
   // Need to set the gLastHash before setting categories.selectedItem since
   // the categories 'select' event will re-enter the gotoPref codepath.
   gLastHash = category;
   categories.selectedItem = item;
   window.history.replaceState(category, document.title);
-  search(category, "data-category");
+  search(category, "data-category", subcategory, "data-subcategory");
+
   let mainContent = document.querySelector(".main-content");
   mainContent.scrollTop = 0;
 
   Services.telemetry
           .getHistogramById("FX_PREFERENCES_CATEGORY_OPENED_V2")
           .add(telemetryBucketForCategory(friendlyName));
 }
 
-function search(aQuery, aAttribute) {
+function search(aQuery, aAttribute, aSubquery, aSubAttribute) {
   let mainPrefPane = document.getElementById("mainPrefPane");
   let elements = mainPrefPane.children;
   for (let element of elements) {
     // If the "data-hidden-from-search" is "true", the
     // element will not get considered during search. This
     // should only be used when an element is still under
     // development and should not be shown for any reason.
     if (element.getAttribute("data-hidden-from-search") != "true") {
       let attributeValue = element.getAttribute(aAttribute);
-      element.hidden = (attributeValue != aQuery);
+      if (attributeValue == aQuery) {
+        if (!element.classList.contains("header") &&
+             aSubquery && aSubAttribute) {
+          let subAttributeValue = element.getAttribute(aSubAttribute);
+          element.hidden = subAttributeValue != aSubquery;
+        } else {
+          element.hidden = false;
+        }
+      } else {
+        element.hidden = true;
+      }
     }
   }
 
   let keysets = mainPrefPane.getElementsByTagName("keyset");
   for (let element of keysets) {
     let attributeValue = element.getAttribute(aAttribute);
     if (attributeValue == aQuery)
       element.removeAttribute("disabled");
--- a/browser/components/preferences/in-content/tests/browser_bug1020245_openPreferences_to_paneContent.js
+++ b/browser/components/preferences/in-content/tests/browser_bug1020245_openPreferences_to_paneContent.js
@@ -15,16 +15,23 @@ add_task(function*() {
   prefs = yield openPreferencesViaHash("privacy");
   is(prefs.selectedPane, "panePrivacy", "Privacy pane is selected when hash is 'privacy'");
   prefs = yield openPreferencesViaOpenPreferencesAPI("nonexistant-category");
   is(prefs.selectedPane, "paneGeneral", "General pane is selected by default when a nonexistant-category is requested");
   prefs = yield openPreferencesViaHash("nonexistant-category");
   is(prefs.selectedPane, "paneGeneral", "General pane is selected when hash is a nonexistant-category");
   prefs = yield openPreferencesViaHash();
   is(prefs.selectedPane, "paneGeneral", "General pane is selected by default");
+  prefs = yield openPreferencesViaOpenPreferencesAPI("advanced-reports", {leaveOpen: true});
+  is(prefs.selectedPane, "paneAdvanced", "Advanced pane is selected by default");
+  let doc = gBrowser.contentDocument;
+  is(doc.location.hash, "#advanced", "The subcategory should be removed from the URI");
+  ok(doc.querySelector("#updateOthers").hidden, "Search Updates should be hidden when only Reports are requested");
+  ok(!doc.querySelector("#header-advanced").hidden, "The header should be visible when a subcategory is requested");
+  yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
 function openPreferencesViaHash(aPane) {
   let deferred = Promise.defer();
   gBrowser.selectedTab = gBrowser.addTab("about:preferences" + (aPane ? "#" + aPane : ""));
   let newTabBrowser = gBrowser.selectedBrowser;
 
   newTabBrowser.addEventListener("Initialized", function() {