Bug 850483 - Record "blocklist enabled" flag in FHR; r=rnewman, a=bajaj
authorGregory Szorc <gps@mozilla.com>
Tue, 19 Mar 2013 11:18:07 -0700
changeset 128722 372f9555e35485dcc31ac5797b4cc3a37f774d0b
parent 128721 72bdfa761b1f27ffe1f65eb534a46a8df20aa5a5
child 128723 b28fcc0c943f03cb91f5203eab618f7806dd2f46
push id3568
push usergszorc@mozilla.com
push dateThu, 28 Mar 2013 22:57:01 +0000
treeherdermozilla-aurora@a084be958224 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, bajaj
bugs850483
milestone21.0a2
Bug 850483 - Record "blocklist enabled" flag in FHR; r=rnewman, a=bajaj
services/healthreport/providers.jsm
services/healthreport/tests/xpcshell/test_provider_appinfo.js
--- a/services/healthreport/providers.jsm
+++ b/services/healthreport/providers.jsm
@@ -89,16 +89,17 @@ AppInfoMeasurement.prototype = Object.fr
     xpcomabi: LAST_TEXT_FIELD,
     updateChannel: LAST_TEXT_FIELD,
     distributionID: LAST_TEXT_FIELD,
     distributionVersion: LAST_TEXT_FIELD,
     hotfixVersion: LAST_TEXT_FIELD,
     locale: LAST_TEXT_FIELD,
     isDefaultBrowser: {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC},
     isTelemetryEnabled: {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC},
+    isBlocklistEnabled: {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC},
   },
 });
 
 
 /**
  * Legacy version of app info before Telemetry was added.
  *
  * The "last" fields have all been removed. We only report the longitudinal
@@ -328,25 +329,32 @@ AppInfoProvider.prototype = Object.freez
       yield m.setLastText("locale", locale);
     } catch (ex) {
       this._log.warn("Could not obtain application locale: " +
                      CommonUtils.exceptionStr(ex));
     }
 
     // FUTURE this should be retrieved periodically or at upload time.
     yield this._recordIsTelemetryEnabled(m);
+    yield this._recordIsBlocklistEnabled(m);
     yield this._recordDefaultBrowser(m);
   },
 
   _recordIsTelemetryEnabled: function (m) {
     let enabled = TELEMETRY_PREF && this._prefs.get(TELEMETRY_PREF, false);
     this._log.debug("Recording telemetry enabled (" + TELEMETRY_PREF + "): " + enabled);
     yield m.setDailyLastNumeric("isTelemetryEnabled", enabled ? 1 : 0);
   },
 
+  _recordIsBlocklistEnabled: function (m) {
+    let enabled = this._prefs.get("extensions.blocklist.enabled", false);
+    this._log.debug("Recording blocklist enabled: " + enabled);
+    yield m.setDailyLastNumeric("isBlocklistEnabled", enabled ? 1 : 0);
+  },
+
   _recordDefaultBrowser: function (m) {
     let shellService;
     try {
       shellService = Cc["@mozilla.org/browser/shell-service;1"]
                        .getService(Ci.nsIShellService);
     } catch (ex) {
       this._log.warn("Could not obtain shell service: " +
                      CommonUtils.exceptionStr(ex));
--- a/services/healthreport/tests/xpcshell/test_provider_appinfo.js
+++ b/services/healthreport/tests/xpcshell/test_provider_appinfo.js
@@ -44,19 +44,20 @@ add_task(function test_collect_smoketest
   do_check_eq(d.platformVersion, "p-ver");
   do_check_eq(d.platformBuildID, "20121106");
   do_check_eq(d.os, "XPCShell");
   do_check_eq(d.xpcomabi, "noarch-spidermonkey");
 
   do_check_eq(data.days.size, 1);
   do_check_true(data.days.hasDay(now));
   let day = data.days.getDay(now);
-  do_check_eq(day.size, 2);
+  do_check_eq(day.size, 3);
   do_check_true(day.has("isDefaultBrowser"));
   do_check_true(day.has("isTelemetryEnabled"));
+  do_check_true(day.has("isBlocklistEnabled"));
 
   // TODO Bug 827189 Actually test this properly. On some local builds, this
   // is always -1 (the service throws). On buildbot, it seems to always be 0.
   do_check_neq(day.get("isDefaultBrowser"), 1);
 
   yield provider.shutdown();
   yield storage.close();
 });
@@ -188,8 +189,39 @@ add_task(function test_record_telemetry(
   data = yield m.getValues();
   d = yield m.serializer(m.SERIALIZE_JSON).daily(data.days.getDay(now));
   do_check_eq(0, d.isTelemetryEnabled);
   yield provider.shutdown();
 
   yield storage.close();
 });
 
+add_task(function test_record_blocklist() {
+  let storage = yield Metrics.Storage("record_blocklist");
+
+  let now = new Date();
+
+  Services.prefs.setBoolPref("extensions.blocklist.enabled", true);
+  let provider = new AppInfoProvider();
+  yield provider.init(storage);
+  yield provider.onInit();
+  yield provider.collectConstantData();
+
+  let m = provider.getMeasurement("appinfo", 2);
+  let data = yield m.getValues();
+  let d = yield m.serializer(m.SERIALIZE_JSON).daily(data.days.getDay(now));
+  do_check_eq(d.isBlocklistEnabled, 1);
+  yield provider.shutdown();
+
+  Services.prefs.setBoolPref("extensions.blocklist.enabled", false);
+  provider = new AppInfoProvider();
+  yield provider.init(storage);
+  yield provider.onInit();
+  yield provider.collectConstantData();
+
+  m = provider.getMeasurement("appinfo", 2);
+  data = yield m.getValues();
+  d = yield m.serializer(m.SERIALIZE_JSON).daily(data.days.getDay(now));
+  do_check_eq(d.isBlocklistEnabled, 0);
+  yield provider.shutdown();
+
+  yield storage.close();
+});