Bug 1536752 - Remove sync pane from about:preferences when identity.fxaccounts.enabled is false r=Gijs a=pascalc
authorBrian Grinstead <bgrinstead@mozilla.com>
Fri, 22 Mar 2019 20:49:53 +0000
changeset 525725 32cf4d4997be449f91a22ca0c0155860dd49916d
parent 525724 2f5aedeffed90029e870c65b7ad1c797c380186e
child 525726 92077cce211c1cbdad31011f563a7b76d3c163b6
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, pascalc
bugs1536752
milestone67.0
Bug 1536752 - Remove sync pane from about:preferences when identity.fxaccounts.enabled is false r=Gijs a=pascalc This fixes a bug in where we render out the text content of the template when searching. Differential Revision: https://phabricator.services.mozilla.com/D24544
browser/components/preferences/in-content/preferences.js
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_sync_disabled.js
browser/components/preferences/in-content/tests/head.js
--- a/browser/components/preferences/in-content/preferences.js
+++ b/browser/components/preferences/in-content/preferences.js
@@ -76,16 +76,19 @@ function init_all() {
   register_module("paneGeneral", gMainPane);
   register_module("paneHome", gHomePane);
   register_module("paneSearch", gSearchPane);
   register_module("panePrivacy", gPrivacyPane);
   register_module("paneContainers", gContainersPane);
   if (Services.prefs.getBoolPref("identity.fxaccounts.enabled")) {
     document.getElementById("category-sync").hidden = false;
     register_module("paneSync", gSyncPane);
+  } else {
+    // Remove the pane from the DOM so it doesn't get incorrectly included in search results.
+    document.getElementById("template-paneSync").remove();
   }
   register_module("paneSearchResults", gSearchResultsPane);
   gSearchResultsPane.init();
   gMainPane.preInit();
 
   let categories = document.getElementById("categories");
   categories.addEventListener("select", event => gotoPref(event.target.value));
 
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -81,16 +81,17 @@ skip-if = e10s
 [browser_spotlight.js]
 [browser_site_login_exceptions.js]
 [browser_site_autoplay_media_exceptions.js]
 [browser_permissions_dialog.js]
 [browser_subdialogs.js]
 support-files =
   subdialog.xul
   subdialog2.xul
+[browser_sync_disabled.js]
 [browser_sync_sanitize.js]
 skip-if = os == 'win' && processor == "x86_64" && bits == 64 # bug 1522821
 [browser_sync_pairing.js]
 [browser_telemetry.js]
 # Skip this test on Android as FHR and Telemetry are separate systems there.
 skip-if = !healthreport || !telemetry || (os == 'linux' && debug) || (os == 'android')
 [browser_warning_permanent_private_browsing.js]
 [browser_containers_name_input.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_sync_disabled.js
@@ -0,0 +1,24 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Test that we don't show sync pane when it's disabled.
+ * See https://bugzilla.mozilla.org/show_bug.cgi?id=1536752.
+ */
+add_task(async function() {
+  await SpecialPowers.pushPrefEnv({
+    set: [
+      ["identity.fxaccounts.enabled", false],
+    ],
+  });
+  await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
+  ok(!gBrowser.contentDocument.getElementById("template-paneSync"), "sync pane removed");
+  ok(gBrowser.contentDocument.getElementById("category-sync").hidden, "sync category hidden");
+
+  // Check that we don't get any results in sync when searching:
+  await evaluateSearchResults("sync", "no-results-message");
+
+  BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
--- a/browser/components/preferences/in-content/tests/head.js
+++ b/browser/components/preferences/in-content/tests/head.js
@@ -104,17 +104,19 @@ function waitForEvent(aSubject, aEventNa
     return aEventOrError;
   }
   aSubject.addEventListener(aEventName, listener);
   return eventDeferred.promise.then(cleanup, cleanup);
 }
 
 function openPreferencesViaOpenPreferencesAPI(aPane, aOptions) {
   return new Promise(resolve => {
-    let finalPrefPaneLoaded = TestUtils.topicObserved("sync-pane-loaded", () => true);
+    let finalPaneEvent = Services.prefs.getBoolPref("identity.fxaccounts.enabled") ?
+                           "sync-pane-loaded" : "privacy-pane-loaded";
+    let finalPrefPaneLoaded = TestUtils.topicObserved(finalPaneEvent, () => true);
     gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:blank");
     openPreferences(aPane);
     let newTabBrowser = gBrowser.selectedBrowser;
 
     newTabBrowser.addEventListener("Initialized", function() {
       newTabBrowser.contentWindow.addEventListener("load", async function() {
         let win = gBrowser.contentWindow;
         let selectedPane = win.history.state;
@@ -137,19 +139,19 @@ async function evaluateSearchResults(key
     gBrowser.contentWindow, "PreferencesSearchCompleted", evt => evt.detail == keyword);
   EventUtils.sendString(keyword);
   await searchCompletedPromise;
 
   let mainPrefTag = gBrowser.contentDocument.getElementById("mainPrefPane");
   for (let i = 0; i < mainPrefTag.childElementCount; i++) {
     let child = mainPrefTag.children[i];
     if (searchReults.includes(child.id)) {
-      is_element_visible(child, "Should be in search results");
+      is_element_visible(child, `${child.id} should be in search results`);
     } else if (child.id) {
-      is_element_hidden(child, "Should not be in search results");
+      is_element_hidden(child, `${child.id} should not be in search results`);
     }
   }
 }
 
 function waitForMutation(target, opts, cb) {
   return new Promise((resolve) => {
     let observer = new MutationObserver(() => {
       if (!cb || cb(target)) {