Bug 1357460 - add isWebExtension to Telemetry Environment r?dexter draft
authorRobert Helmer <rhelmer@mozilla.com>
Tue, 18 Apr 2017 20:08:48 -0700
changeset 564883 b886503f65eb34aeca6e6f311f2159de238061e0
parent 564857 7e4f4a5192d3d0bc1cc64670d1ecc798468d0e56
child 624854 175926d90a72abbaf59e13fddf6fb9001be07dd1
push id54718
push userrhelmer@mozilla.com
push dateWed, 19 Apr 2017 04:16:00 +0000
reviewersdexter
bugs1357460
milestone55.0a1
Bug 1357460 - add isWebExtension to Telemetry Environment r?dexter MozReview-Commit-ID: lzeHG7nXhf
toolkit/components/telemetry/TelemetryEnvironment.jsm
toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
--- a/toolkit/components/telemetry/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/TelemetryEnvironment.jsm
@@ -619,16 +619,17 @@ EnvironmentAddonBuilder.prototype = {
           scope: addon.scope,
           type: addon.type,
           foreignInstall: enforceBoolean(addon.foreignInstall),
           hasBinaryComponents: addon.hasBinaryComponents,
           installDay: Utils.millisecondsToDays(installDate.getTime()),
           updateDay: Utils.millisecondsToDays(updateDate.getTime()),
           signedState: addon.signedState,
           isSystem: addon.isSystem,
+          isWebExtension: addon.isWebExtension,
         };
 
         if (addon.signedState !== undefined)
           activeAddons[addon.id].signedState = addon.signedState;
 
       } catch (ex) {
         this._environment._log.error("_getActiveAddons - An addon was discarded due to an error", ex);
         continue;
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEnvironment.js
@@ -17,16 +17,19 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 
 // Lazy load |LightweightThemeManager|.
 XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
                                   "resource://gre/modules/LightweightThemeManager.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "ProfileAge",
                                   "resource://gre/modules/ProfileAge.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "ExtensionTestUtils",
+                                  "resource://testing-common/ExtensionXPCShellUtils.jsm");
+
 // The webserver hosting the addons.
 var gHttpServer = null;
 // The URL of the webserver root.
 var gHttpRoot = null;
 // The URL of the data directory, on the webserver.
 var gDataRoot = null;
 
 const PLATFORM_VERSION = "1.9.2";
@@ -667,16 +670,17 @@ function checkActiveAddon(data) {
     scope: "number",
     type: "string",
     foreignInstall: "boolean",
     hasBinaryComponents: "boolean",
     installDay: "number",
     updateDay: "number",
     signedState,
     isSystem: "boolean",
+    isWebExtension: "boolean",
   };
 
   for (let f in EXPECTED_ADDON_FIELDS_TYPES) {
     Assert.ok(f in data, f + " must be available.");
     Assert.equal(typeof data[f], EXPECTED_ADDON_FIELDS_TYPES[f],
                  f + " must have the correct type.");
   }
 
@@ -1121,16 +1125,17 @@ add_task(function* test_addonsAndPlugins
     scope: 1,
     type: "extension",
     foreignInstall: false,
     hasBinaryComponents: false,
     installDay: ADDON_INSTALL_DATE,
     updateDay: ADDON_INSTALL_DATE,
     signedState: mozinfo.addon_signing ? AddonManager.SIGNEDSTATE_SIGNED : AddonManager.SIGNEDSTATE_NOT_REQUIRED,
     isSystem: false,
+    isWebExtension: false,
   };
   const SYSTEM_ADDON_ID = "tel-system-xpi@tests.mozilla.org";
   const EXPECTED_SYSTEM_ADDON_DATA = {
     blocklisted: false,
     description: "A system addon which is shipped with Firefox.",
     name: "XPI Telemetry System Add-on Test",
     userDisabled: false,
     appDisabled: false,
@@ -1138,30 +1143,80 @@ add_task(function* test_addonsAndPlugins
     scope: 1,
     type: "extension",
     foreignInstall: false,
     hasBinaryComponents: false,
     installDay: truncateToDays(SYSTEM_ADDON_INSTALL_DATE),
     updateDay: truncateToDays(SYSTEM_ADDON_INSTALL_DATE),
     signedState: undefined,
     isSystem: true,
+    isWebExtension: false,
+  };
+
+  const WEBEXTENSION_ADDON_ID = "tel-webextension-xpi@tests.mozilla.org";
+  const WEBEXTENSION_ADDON_INSTALL_DATE = truncateToDays(Date.now());
+  const EXPECTED_WEBEXTENSION_ADDON_DATA = {
+    blocklisted: false,
+    description: "A webextension addon.",
+    name: "XPI Telemetry WebExtension Add-on Test",
+    userDisabled: false,
+    appDisabled: false,
+    version: "1.0",
+    scope: 1,
+    type: "extension",
+    foreignInstall: false,
+    hasBinaryComponents: false,
+    installDay: WEBEXTENSION_ADDON_INSTALL_DATE,
+    updateDay: WEBEXTENSION_ADDON_INSTALL_DATE,
+    signedState: mozinfo.addon_signing ? AddonManager.SIGNEDSTATE_SIGNED : AddonManager.SIGNEDSTATE_NOT_REQUIRED,
+    isSystem: false,
+    isWebExtension: true,
   };
 
   const EXPECTED_PLUGIN_DATA = {
     name: FLASH_PLUGIN_NAME,
     version: FLASH_PLUGIN_VERSION,
     description: FLASH_PLUGIN_DESC,
     blocklisted: false,
     disabled: false,
     clicktoplay: true,
   };
 
-  // Install an addon so we have some data.
+  let deferred = PromiseUtils.defer();
+  TelemetryEnvironment.registerChangeListener("test_WebExtension",
+    (reason, data) => {
+      Assert.equal(reason, "addons-changed");
+      deferred.resolve();
+    }
+  );
+
+  // Install an add-on so we have some data.
   yield AddonManagerTesting.installXPIFromURL(ADDON_INSTALL_URL);
 
+  // Install a webextension as well.
+  ExtensionTestUtils.init(this);
+
+  let webextension = ExtensionTestUtils.loadExtension({
+    useAddonManager: "permanent",
+    manifest: {
+      "name": "XPI Telemetry WebExtension Add-on Test",
+      "description": "A webextension addon.",
+      "version": "1.0",
+      "applications": {
+        "gecko": {
+          "id": WEBEXTENSION_ADDON_ID,
+        },
+      },
+    },
+  });
+
+  yield webextension.startup();
+  yield deferred.promise;
+  TelemetryEnvironment.unregisterChangeListener("test_WebExtension");
+
   let data = TelemetryEnvironment.currentEnvironment;
   checkEnvironmentData(data);
 
   // Check addon data.
   Assert.ok(ADDON_ID in data.addons.activeAddons, "We must have one active addon.");
   let targetAddon = data.addons.activeAddons[ADDON_ID];
   for (let f in EXPECTED_ADDON_DATA) {
     Assert.equal(targetAddon[f], EXPECTED_ADDON_DATA[f], f + " must have the correct value.");
@@ -1169,16 +1224,25 @@ add_task(function* test_addonsAndPlugins
 
   // Check system add-on data.
   Assert.ok(SYSTEM_ADDON_ID in data.addons.activeAddons, "We must have one active system addon.");
   let targetSystemAddon = data.addons.activeAddons[SYSTEM_ADDON_ID];
   for (let f in EXPECTED_SYSTEM_ADDON_DATA) {
     Assert.equal(targetSystemAddon[f], EXPECTED_SYSTEM_ADDON_DATA[f], f + " must have the correct value.");
   }
 
+  // Check webextension add-on data.
+  Assert.ok(WEBEXTENSION_ADDON_ID in data.addons.activeAddons, "We must have one active webextension addon.");
+  let targetWebExtensionAddon = data.addons.activeAddons[WEBEXTENSION_ADDON_ID];
+  for (let f in EXPECTED_WEBEXTENSION_ADDON_DATA) {
+    Assert.equal(targetWebExtensionAddon[f], EXPECTED_WEBEXTENSION_ADDON_DATA[f], f + " must have the correct value.");
+  }
+
+  yield webextension.unload();
+
   // Check theme data.
   let theme = data.addons.theme;
   Assert.equal(theme.id, (PERSONA_ID + PERSONA_ID_SUFFIX));
   Assert.equal(theme.name, PERSONA_NAME);
   Assert.equal(theme.description, PERSONA_DESCRIPTION);
 
   // Check plugin data.
   Assert.equal(data.addons.activePlugins.length, 1, "We must have only one active plugin.");