Bug 1335454 - Add the ability to open the "Data Choices" options section through UITour, r?jaws draft
authorFischer.json <fischer.json@gmail.com>
Sun, 23 Apr 2017 16:27:26 +0800
changeset 585891 237c57f4c68bc0d37371778ad975a2c7a5563dc5
parent 585722 6a235092bda7c20cb83651d3404284fe36d04c1b
child 630824 0b1126488f73ae307af856c48d2d91614dccb8c3
push id61222
push userbmo:fliu@mozilla.com
push dateMon, 29 May 2017 08:22:34 +0000
reviewersjaws
bugs1335454
milestone55.0a1
Bug 1335454 - Add the ability to open the "Data Choices" options section through UITour, r?jaws This patch does: - Update UITour.jsm to make websites able to open to the old Prefernces advanced pane > dataChoicesTab by calling `Mozilla.UITour.openPreferences("privacy-reports")`. - Update the comments of `Mozilla.UITour.openPreferences` to explain the old and new Preference to api users. MozReview-Commit-ID: IdNDKiqfxKo
browser/base/content/utilityOverlay.js
browser/components/uitour/UITour-lib.js
browser/components/uitour/UITour.jsm
browser/components/uitour/test/browser_openPreferences.js
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -719,18 +719,23 @@ function openPreferences(paneID, extraAr
   let histogram = Services.telemetry.getHistogramById("FX_PREFERENCES_OPENED_VIA");
   if (extraArgs && extraArgs.origin) {
     histogram.add(extraArgs.origin);
   } else {
     histogram.add("other");
   }
   function switchToAdvancedSubPane(doc) {
     if (extraArgs && extraArgs["advancedTab"]) {
+      // After the Preferences reorg works in Bug 1335907, no more advancedPrefs element.
+      // The old Preference is pref-off behind `browser.preferences.useOldOrganization` on Nightly.
+      // During the transition between the old and new Preferences, should do checking before proceeding.
       let advancedPaneTabs = doc.getElementById("advancedPrefs");
-      advancedPaneTabs.selectedTab = doc.getElementById(extraArgs["advancedTab"]);
+      if (advancedPaneTabs) {
+        advancedPaneTabs.selectedTab = doc.getElementById(extraArgs["advancedTab"]);
+      }
     }
   }
 
   // This function is duplicated from preferences.js.
   function internalPrefCategoryNameToFriendlyName(aName) {
     return (aName || "").replace(/^pane./, function(toReplace) { return toReplace[4].toLowerCase(); });
   }
 
--- a/browser/components/uitour/UITour-lib.js
+++ b/browser/components/uitour/UITour-lib.js
@@ -37,18 +37,18 @@ if (typeof Mozilla == "undefined") {
       themeIntervalId = null;
     }
   }
 
   function _sendEvent(action, data) {
     var event = new CustomEvent("mozUITour", {
       bubbles: true,
       detail: {
-	action,
-	data: data || {}
+        action,
+        data: data || {}
       }
     });
 
     document.dispatchEvent(event);
   }
 
   function _generateCallbackID() {
     return Math.random().toString(36).replace(/[^a-z]+/g, "");
@@ -741,26 +741,44 @@ if (typeof Mozilla == "undefined") {
    * UITour APIs.
    */
   Mozilla.UITour.toggleReaderMode = function() {
     _sendEvent("toggleReaderMode");
   };
 
   /**
    * @param {String} pane - Pane to open/switch the preferences to.
-   * Valid values match fragments on about:preferences and are subject to change e.g.:<ul>
+   * Valid values match fragments on about:preferences and are subject to change e.g.:
+   * <ul>
+   * For the old Preferences
    * <li>general
    * <li>search
    * <li>content
    * <li>applications
    * <li>privacy
    * <li>security
    * <li>sync
    * <li>advanced
    * </ul>
+   *
+   * <ul>
+   * For the new Preferences
+   * <li>general
+   * <li>applications
+   * <li>sync
+   * <li>privacy
+   * <li>advanced
+   * </ul>
+   *
+   * The mapping between the old and the new Preferences:
+   * To open to the options of sending telemetry, health report, crach reports,
+   * that is, the advanced pane > dataChoicesTab on the old and the privcacy pane > reports on the new.
+   * Please call `Mozilla.UITour.openPreferences("privacy-reports")`.
+   * UITour would do route mapping automatically.
+   *
    * @since 42
    */
   Mozilla.UITour.openPreferences = function(pane) {
     _sendEvent("openPreferences", {
       pane
     });
   };
 
--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -531,17 +531,31 @@ this.UITour = {
       }
 
       case "openPreferences": {
         if (typeof data.pane != "string" && typeof data.pane != "undefined") {
           log.warn("openPreferences: Invalid pane specified");
           return false;
         }
 
-        window.openPreferences(data.pane, { origin: "UITour" });
+        let paneID = data.pane;
+        let extraArgs = { origin: "UITour" };
+        if (Services.prefs.getBoolPref("browser.preferences.useOldOrganization", true)) {
+          // We are heading to the old Preferences so
+          // let's map the new one to the old one if the `paneID` was for the new Preferences.
+          // Currently only the old advanced pane > dataChoicesTab has the mapping need,
+          // so here only do mapping for it right now.
+          // We could add another mapping when there is need.
+          if (paneID == "privacy-reports") {
+            paneID = "advanced";
+            extraArgs.advancedTab = "dataChoicesTab";
+          }
+        }
+
+        window.openPreferences(paneID, extraArgs);
         break;
       }
 
       case "showFirefoxAccounts": {
         // 'signup' is the only action that makes sense currently, so we don't
         // accept arbitrary actions just to be safe...
         let p = new URLSearchParams("action=signup&entrypoint=uitour");
         // Call our helper to validate extraURLCampaignParams and populate URLSearchParams
--- a/browser/components/uitour/test/browser_openPreferences.js
+++ b/browser/components/uitour/test/browser_openPreferences.js
@@ -29,8 +29,40 @@ add_UITour_task(async function test_open
 });
 
 add_UITour_task(async function test_openPrivacyPreferences() {
   let promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#privacy");
   await gContentAPI.openPreferences("privacy");
   let tab = await promiseTabOpened;
   await BrowserTestUtils.removeTab(tab);
 });
+
+add_UITour_task(async function test_openOldDataChoicesTab() {
+  if (!AppConstants.MOZ_DATA_REPORTING) {
+    return;
+  }
+  await SpecialPowers.pushPrefEnv({set: [["browser.preferences.useOldOrganization", true]]});
+  let promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#advanced");
+  await gContentAPI.openPreferences("privacy-reports");
+  let tab = await promiseTabOpened;
+  await BrowserTestUtils.waitForEvent(gBrowser.selectedBrowser, "Initialized");
+  let doc = gBrowser.selectedBrowser.contentDocument;
+  let selectedTab = doc.getElementById("advancedPrefs").selectedTab;
+  is(selectedTab.id, "dataChoicesTab", "Should open to the dataChoicesTab in the old Preferences");
+  await BrowserTestUtils.removeTab(tab);
+});
+
+add_UITour_task(async function test_openPrivacyReports() {
+  if (!AppConstants.MOZ_TELEMETRY_REPORTING &&
+      !(AppConstants.MOZ_DATA_REPORTING && AppConstants.MOZ_CRASHREPORTER)) {
+    return;
+  }
+  await SpecialPowers.pushPrefEnv({set: [["browser.preferences.useOldOrganization", false]]});
+  let promiseTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, "about:preferences#privacy-reports");
+  await gContentAPI.openPreferences("privacy-reports");
+  let tab = await promiseTabOpened;
+  await BrowserTestUtils.waitForEvent(gBrowser.selectedBrowser, "Initialized");
+  let doc = gBrowser.selectedBrowser.contentDocument;
+  let reports = doc.querySelector("groupbox[data-subcategory='reports']");
+  is(doc.location.hash, "#privacy", "Should not display the reports subcategory in the location hash.");
+  is(reports.hidden, false, "Should open to the reports subcategory in the privacy pane in the new Preferences.");
+  await BrowserTestUtils.removeTab(tab);
+});