Bug 1154518 - Make sure extended data gathering (Telemetry) is disabled when FHR is disabled. r=Gijs, a=sledru
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Wed, 15 Apr 2015 08:25:00 +0200
changeset 260297 cb2725c612b2
parent 260296 0fcbbecc843d
child 260298 987c18b686eb
push id741
push userryanvm@gmail.com
push date2015-04-27 20:01 +0000
treeherdermozilla-release@d10817faa571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, sledru
bugs1154518
milestone38.0
Bug 1154518 - Make sure extended data gathering (Telemetry) is disabled when FHR is disabled. r=Gijs, a=sledru
browser/components/preferences/advanced.js
browser/components/preferences/in-content/advanced.js
browser/components/preferences/in-content/tests/browser_telemetry.js
browser/components/preferences/tests/browser_telemetry.js
--- a/browser/components/preferences/advanced.js
+++ b/browser/components/preferences/advanced.js
@@ -241,17 +241,17 @@ var gAdvancedPane = {
   setTelemetrySectionEnabled: function (aEnabled)
   {
 #ifdef MOZ_TELEMETRY_REPORTING
     // If FHR is disabled, additional data sharing should be disabled as well.
     let disabled = !aEnabled;
     document.getElementById("submitTelemetryBox").disabled = disabled;
     if (disabled) {
       // If we disable FHR, untick the telemetry checkbox.
-      document.getElementById("submitTelemetryBox").checked = false;
+      Services.prefs.setBoolPref("toolkit.telemetry.enabled", false);
     }
     document.getElementById("telemetryDataDesc").disabled = disabled;
 #endif
   },
 
 #ifdef MOZ_SERVICES_HEALTHREPORT
   /**
    * Initialize the health report service reference and checkbox.
--- a/browser/components/preferences/in-content/advanced.js
+++ b/browser/components/preferences/in-content/advanced.js
@@ -270,17 +270,17 @@ var gAdvancedPane = {
   setTelemetrySectionEnabled: function (aEnabled)
   {
 #ifdef MOZ_TELEMETRY_REPORTING
     // If FHR is disabled, additional data sharing should be disabled as well.
     let disabled = !aEnabled;
     document.getElementById("submitTelemetryBox").disabled = disabled;
     if (disabled) {
       // If we disable FHR, untick the telemetry checkbox.
-      document.getElementById("submitTelemetryBox").checked = false;
+      Services.prefs.setBoolPref("toolkit.telemetry.enabled", false);
     }
     document.getElementById("telemetryDataDesc").disabled = disabled;
 #endif
   },
 
 #ifdef MOZ_SERVICES_HEALTHREPORT
   /**
    * Initialize the health report service reference and checkbox.
--- a/browser/components/preferences/in-content/tests/browser_telemetry.js
+++ b/browser/components/preferences/in-content/tests/browser_telemetry.js
@@ -1,13 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
+const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";
+
 function runPaneTest(fn) {
   open_preferences((win) => {
     let doc = win.document;
     win.gotoPref("paneAdvanced");
     let advancedPrefs = doc.getElementById("advancedPrefs");
     let tab = doc.getElementById("dataChoicesTab");
     advancedPrefs.selectedTab = tab;
     fn(win, doc);
@@ -23,23 +25,28 @@ function test() {
 
 function testTelemetryState(win, doc) {
   let fhrCheckbox = doc.getElementById("submitHealthReportBox");
   Assert.ok(fhrCheckbox.checked, "Health Report checkbox is checked on app first run.");
 
   let telmetryCheckbox = doc.getElementById("submitTelemetryBox");
   Assert.ok(!telmetryCheckbox.disabled,
             "Telemetry checkbox must be enabled if FHR is checked.");
+  Assert.ok(Services.prefs.getBoolPref(PREF_TELEMETRY_ENABLED),
+            "Telemetry must be enabled if the checkbox is ticked.");
 
   // Uncheck the FHR checkbox and make sure that Telemetry checkbox gets disabled.
   fhrCheckbox.click();
 
   Assert.ok(telmetryCheckbox.disabled,
             "Telemetry checkbox must be disabled if FHR is unchecked.");
+  Assert.ok(!Services.prefs.getBoolPref(PREF_TELEMETRY_ENABLED),
+            "Telemetry must be disabled if the checkbox is unticked.");
 
   win.close();
   finish();
 }
 
 function resetPreferences() {
   Services.prefs.clearUserPref("datareporting.healthreport.uploadEnabled");
+  Services.prefs.clearUserPref(PREF_TELEMETRY_ENABLED);
 }
 
--- a/browser/components/preferences/tests/browser_telemetry.js
+++ b/browser/components/preferences/tests/browser_telemetry.js
@@ -1,13 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
+const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";
+
 function runPaneTest(fn) {
   function observer(win, topic, data) {
     Services.obs.removeObserver(observer, "advanced-pane-loaded");
 
     let policy = Components.classes["@mozilla.org/datareporting/service;1"]
                                    .getService(Components.interfaces.nsISupports)
                                    .wrappedJSObject
                                    .policy;
@@ -35,27 +37,32 @@ function testTelemetryState(win) {
   let doc = win.document;
 
   let fhrCheckbox = doc.getElementById("submitHealthReportBox");
   Assert.ok(fhrCheckbox.checked, "Health Report checkbox is checked on app first run.");
 
   let telmetryCheckbox = doc.getElementById("submitTelemetryBox");
   Assert.ok(!telmetryCheckbox.disabled,
             "Telemetry checkbox must be enabled if FHR is checked.");
+  Assert.ok(Services.prefs.getBoolPref(PREF_TELEMETRY_ENABLED),
+            "Telemetry must be enabled if the checkbox is ticked.");
 
   // Uncheck the FHR checkbox and make sure that Telemetry checkbox gets disabled.
   fhrCheckbox.click();
 
   Assert.ok(telmetryCheckbox.disabled,
             "Telemetry checkbox must be disabled if FHR is unchecked.");
+  Assert.ok(!Services.prefs.getBoolPref(PREF_TELEMETRY_ENABLED),
+            "Telemetry must be disabled if the checkbox is unticked.");
 
   win.close();
   finish();
 }
 
 function resetPreferences() {
   let service = Cc["@mozilla.org/datareporting/service;1"]
                   .getService(Ci.nsISupports)
                   .wrappedJSObject;
   service.policy._prefs.resetBranch("datareporting.policy.");
   service.policy.dataSubmissionPolicyBypassNotification = true;
+  Services.prefs.clearUserPref(PREF_TELEMETRY_ENABLED);
 }