Bug 1392960: Do not hide <preferences> elements for subcategories. draft
authorMichael Kelly <mkelly@mozilla.com>
Wed, 23 Aug 2017 14:47:42 -0700
changeset 656157 6f9b77959334abe580bf29e3cc82b6968927884d
parent 654351 e2efa420beb1a578c7350ba925c82230da6b1267
child 729036 7f61e53a98503368c3b7cf63c31e086dbacb17da
push id77095
push userbmo:mkelly@mozilla.com
push dateWed, 30 Aug 2017 19:56:22 +0000
bugs1392960
milestone57.0a1
Bug 1392960: Do not hide <preferences> elements for subcategories. When filtering for which elements to hide when the user is viewing a subcategory, <preferences> elements are excluded (though they must still match the category search). MozReview-Commit-ID: EvSXgrhuJXl
browser/components/preferences/in-content-new/preferences.js
browser/components/preferences/in-content-new/tests/browser_bug1020245_openPreferences_to_paneContent.js
--- a/browser/components/preferences/in-content-new/preferences.js
+++ b/browser/components/preferences/in-content-new/preferences.js
@@ -225,17 +225,18 @@ function search(aQuery, aAttribute, aSub
     // 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" ||
         element.getAttribute("data-subpanel") == "true") {
       let attributeValue = element.getAttribute(aAttribute);
       if (attributeValue == aQuery) {
         if (!element.classList.contains("header") &&
-             aSubquery && aSubAttribute) {
+            element.localName !== "preferences" &&
+            aSubquery && aSubAttribute) {
           let subAttributeValue = element.getAttribute(aSubAttribute);
           element.hidden = subAttributeValue != aSubquery;
         } else {
           element.hidden = false;
         }
       } else {
         element.hidden = true;
       }
--- a/browser/components/preferences/in-content-new/tests/browser_bug1020245_openPreferences_to_paneContent.js
+++ b/browser/components/preferences/in-content-new/tests/browser_bug1020245_openPreferences_to_paneContent.js
@@ -40,16 +40,59 @@ add_task(async function() {
   openPreferences("privacy-reports");
   let selectedPane = gBrowser.contentWindow.history.state;
   is(selectedPane, "panePrivacy", "Privacy pane should be selected");
   is(doc.location.hash, "#privacy", "The subcategory should be removed from the URI");
   ok(doc.querySelector("#locationBarGroup").hidden, "Location Bar prefs should be hidden when only Reports are requested");
   await BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
+// Test opening to a subcategory displays the correct values for preferences
+add_task(async function() {
+  // Skip if crash reporting isn't enabled since the checkbox will be missing.
+  if (!AppConstants.MOZ_CRASHREPORTER) {
+    return;
+  }
+
+  await SpecialPowers.pushPrefEnv({
+    set: [["browser.crashReports.unsubmittedCheck.autoSubmit", true]],
+  });
+  await openPreferencesViaOpenPreferencesAPI("privacy-reports", {leaveOpen: true});
+
+  let doc = gBrowser.contentDocument;
+  ok(
+    doc.querySelector("#automaticallySubmitCrashesBox").checked,
+    "Checkbox for automatically submitting crashes should be checked when the pref is true and only Reports are requested"
+  );
+
+  await BrowserTestUtils.removeTab(gBrowser.selectedTab);
+  await SpecialPowers.popPrefEnv();
+});
+
+add_task(async function() {
+  // Skip if crash reporting isn't enabled since the checkbox will be missing.
+  if (!AppConstants.MOZ_CRASHREPORTER) {
+    return;
+  }
+
+  await SpecialPowers.pushPrefEnv({
+    set: [["browser.crashReports.unsubmittedCheck.autoSubmit", false]],
+  });
+  await openPreferencesViaOpenPreferencesAPI("privacy-reports", {leaveOpen: true});
+
+  let doc = gBrowser.contentDocument;
+  ok(
+    !doc.querySelector("#automaticallySubmitCrashesBox").checked,
+    "Checkbox for automatically submitting crashes should not be checked when the pref is false only Reports are requested"
+  );
+
+  await BrowserTestUtils.removeTab(gBrowser.selectedTab);
+  await SpecialPowers.popPrefEnv();
+});
+
 
 function openPreferencesViaHash(aPane) {
   return new Promise(resolve => {
     gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:preferences" + (aPane ? "#" + aPane : ""));
     let newTabBrowser = gBrowser.selectedBrowser;
 
     newTabBrowser.addEventListener("Initialized", function() {
       newTabBrowser.contentWindow.addEventListener("load", function() {