Bug 1180673 - Part 1 - Use a different URL pref for healthreport when Unified Telemetry is on and opt-out. r=bsmedberg,a=ritu
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Wed, 29 Jul 2015 16:59:52 +0200
changeset 281902 85aa9f19ebd7b937e382fa9fcfca6621b506bc9d
parent 281901 5650d1a8106fde22c67f1e152442eb135c9aaad6
child 281903 7a23c634f65e1f585e00e3a411402e0cd7f5c4b8
push id4952
push usergeorg.fritzsche@googlemail.com
push dateThu, 13 Aug 2015 12:06:41 +0000
treeherdermozilla-beta@7a23c634f65e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg, ritu
bugs1180673
milestone41.0
Bug 1180673 - Part 1 - Use a different URL pref for healthreport when Unified Telemetry is on and opt-out. r=bsmedberg,a=ritu
browser/base/content/abouthealthreport/abouthealth.js
browser/base/content/test/general/browser_aboutHealthReport.js
services/healthreport/docs/architecture.rst
services/healthreport/healthreport-prefs.js
testing/profiles/prefs_general.js
--- a/browser/base/content/abouthealthreport/abouthealth.js
+++ b/browser/base/content/abouthealthreport/abouthealth.js
@@ -6,16 +6,23 @@
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 const prefs = new Preferences("datareporting.healthreport.");
 
+const PREF_UNIFIED = "toolkit.telemetry.unified";
+const PREF_UNIFIED_OPTIN = "toolkit.telemetry.unifiedIsOptIn";
+
+// Whether v4 behavior is enabled, i.e. unified Telemetry features are on by default.
+const IS_V4 = Preferences.get(PREF_UNIFIED, false) &&
+              !Preferences.get(PREF_UNIFIED_OPTIN, false);
+
 let healthReportWrapper = {
   init: function () {
     let iframe = document.getElementById("remote-report");
     iframe.addEventListener("load", healthReportWrapper.initRemotePage, false);
     iframe.src = this._getReportURI().spec;
     iframe.onload = () => {
       MozSelfSupport.getHealthReportPayload().then(this.updatePayload,
                                                    this.handleInitFailure);
@@ -23,17 +30,19 @@ let healthReportWrapper = {
     prefs.observe("uploadEnabled", this.updatePrefState, healthReportWrapper);
   },
 
   uninit: function () {
     prefs.ignore("uploadEnabled", this.updatePrefState, healthReportWrapper);
   },
 
   _getReportURI: function () {
-    let url = Services.urlFormatter.formatURLPref("datareporting.healthreport.about.reportUrl");
+    const pref = IS_V4 ? "datareporting.healthreport.about.reportUrl"
+                       : "datareporting.healthreport.about.reportUrlUnified";
+    let url = Services.urlFormatter.formatURLPref(pref);
     return Services.io.newURI(url, null, null);
   },
 
   setDataSubmission: function (enabled) {
     MozSelfSupport.healthReportDataSubmissionEnabled = enabled;
     this.updatePrefState();
   },
 
--- a/browser/base/content/test/general/browser_aboutHealthReport.js
+++ b/browser/base/content/test/general/browser_aboutHealthReport.js
@@ -8,26 +8,30 @@ XPCOMUtils.defineLazyModuleGetter(this, 
   "resource://gre/modules/Task.jsm");
 
 const CHROME_BASE = "chrome://mochitests/content/browser/browser/base/content/test/general/";
 const HTTPS_BASE = "https://example.com/browser/browser/base/content/test/general/";
 
 const TELEMETRY_LOG_PREF = "toolkit.telemetry.log.level";
 const telemetryOriginalLogPref = Preferences.get(TELEMETRY_LOG_PREF, null);
 
+const originalReportUrl = Services.prefs.getCharPref("datareporting.healthreport.about.reportUrl");
+const originalReportUrlUnified = Services.prefs.getCharPref("datareporting.healthreport.about.reportUrlUnified");
+
 registerCleanupFunction(function() {
   // Ensure we don't pollute prefs for next tests.
   if (telemetryOriginalLogPref) {
     Preferences.set(TELEMETRY_LOG_PREF, telemetryOriginalLogPref);
   } else {
     Preferences.reset(TELEMETRY_LOG_PREF);
   }
 
   try {
-    Services.prefs.clearUserPref("datareporting.healthreport.about.reportUrl");
+    Services.prefs.setCharPref("datareporting.healthreport.about.reportUrl", originalReportUrl);
+    Services.prefs.setCharPref("datareporting.healthreport.about.reportUrlUnified", originalReportUrlUnified);
     let policy = Cc["@mozilla.org/datareporting/service;1"]
                  .getService(Ci.nsISupports)
                  .wrappedJSObject
                  .policy;
     policy.recordHealthReportUploadEnabled(true,
                                            "Resetting after tests.");
   } catch (ex) {}
 });
@@ -65,16 +69,18 @@ let gTests = [
 {
   desc: "Test the remote commands",
   setup: Task.async(function*()
   {
     Preferences.set(TELEMETRY_LOG_PREF, "Trace");
     yield setupPingArchive();
     Preferences.set("datareporting.healthreport.about.reportUrl",
                     HTTPS_BASE + "healthreport_testRemoteCommands.html");
+    Preferences.set("datareporting.healthreport.about.reportUrlUnified",
+                    HTTPS_BASE + "healthreport_testRemoteCommands.html");
   }),
   run: function (iframe)
   {
     let deferred = Promise.defer();
 
     let policy = Cc["@mozilla.org/datareporting/service;1"]
                  .getService(Ci.nsISupports)
                  .wrappedJSObject
--- a/services/healthreport/docs/architecture.rst
+++ b/services/healthreport/docs/architecture.rst
@@ -78,16 +78,19 @@ documentServerNamespace
 
 infoURL
    The URL of a page containing more info about FHR, it's privacy
    policy, etc.
 
 about.reportUrl
    The URL to load in ``about:healthreport``.
 
+about.reportUrlUnified
+   The URL to load in ``about:healthreport``. This is used instead of ``reportUrl`` for UnifiedTelemetry when it is not opt-in.
+
 service.providerCategories
    A comma-delimited list of category manager categories that contain
    registered ``Metrics.Provider`` records. Read below for how provider
    registration works.
 
 If the entire service is disabled, you lose data collection. This means
 that **local** data analysis won't be available because there is no data
 to analyze! Keep in mind that Firefox Health Report can be useful even
--- a/services/healthreport/healthreport-prefs.js
+++ b/services/healthreport/healthreport-prefs.js
@@ -29,9 +29,10 @@ pref("datareporting.healthreport.service
     "healthreport-js-provider-default"
 #elif MOZ_UPDATE_CHANNEL == default
     "healthreport-js-provider-default"
 #else
     "healthreport-js-provider-default,healthreport-js-provider-@MOZ_UPDATE_CHANNEL@"
 #endif
     );
 
-pref("datareporting.healthreport.about.reportUrl",   "https://fhr.cdn.mozilla.net/%LOCALE%/");
+pref("datareporting.healthreport.about.reportUrl", "https://fhr.cdn.mozilla.net/%LOCALE%/");
+pref("datareporting.healthreport.about.reportUrlUnified", "https://fhr.cdn.mozilla.net/%LOCALE%/");
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -135,16 +135,17 @@ user_pref("network.activity.blipInterval
 // cause other tests to fail. Tests that wish to test the notification functionality
 // should explicitly disable this pref.
 user_pref("datareporting.policy.dataSubmissionPolicyBypassNotification", true);
 
 // Point Firefox Health Report at a local server. We don't care if it actually
 // works. It just can't hit the default production endpoint.
 user_pref("datareporting.healthreport.documentServerURI", "http://%(server)s/healthreport/");
 user_pref("datareporting.healthreport.about.reportUrl", "http://%(server)s/abouthealthreport/");
+user_pref("datareporting.healthreport.about.reportUrlUnified", "http://%(server)s/abouthealthreport/v4/");
 
 // Make sure CSS error reporting is enabled for tests
 user_pref("layout.css.report_errors", true);
 
 // Enable CSS Grid for testing
 user_pref("layout.css.grid.enabled", true);
 
 // Enable CSS 'contain' for testing