Bug 1335454 - Add the ability to open the "Data Choices" options section through UITour, r=jaws
authorFischer.json <fischer.json@gmail.com>
Sun, 23 Apr 2017 16:27:26 +0800
changeset 409207 6380ec73b69604f39e081a5d67b0fbe000210380
parent 409206 1df25c9d3299711f01643e51f2a277b6c23b102d
child 409208 abd213bb84d414a5a28abbfb327cb333e53bb59c
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1335454
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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);
+});