Bug 1529347 - Record telemetry event on extensions enabled on private windows as part of Firefox upgrade. r=mixedpuppy,Dexter
authorLuca Greco <lgreco@mozilla.com>
Wed, 06 Mar 2019 13:58:07 +0000
changeset 520485 5cc66e233192de72cf4eac10c20e85b952285f12
parent 520484 a5187ade9132c8a456280fe7711feb571f800012
child 520486 f25fac04788d3ac6d2b442021bcf2eb74f423e18
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, Dexter
bugs1529347
milestone67.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 1529347 - Record telemetry event on extensions enabled on private windows as part of Firefox upgrade. r=mixedpuppy,Dexter Depends on D21931 Differential Revision: https://phabricator.services.mozilla.com/D21932
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/test/xpcshell/test_ext_incognito.js
toolkit/components/telemetry/Events.yaml
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -34,16 +34,17 @@ var EXPORTED_SYMBOLS = ["Dictionary", "E
 
 const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   AddonManager: "resource://gre/modules/AddonManager.jsm",
   AddonManagerPrivate: "resource://gre/modules/AddonManager.jsm",
   AddonSettings: "resource://gre/modules/addons/AddonSettings.jsm",
+  AMTelemetry: "resource://gre/modules/AddonManager.jsm",
   AppConstants: "resource://gre/modules/AppConstants.jsm",
   AsyncShutdown: "resource://gre/modules/AsyncShutdown.jsm",
   ExtensionPermissions: "resource://gre/modules/ExtensionPermissions.jsm",
   ExtensionProcessScript: "resource://gre/modules/ExtensionProcessScript.jsm",
   ExtensionStorage: "resource://gre/modules/ExtensionStorage.jsm",
   ExtensionStorageIDB: "resource://gre/modules/ExtensionStorageIDB.jsm",
   ExtensionTelemetry: "resource://gre/modules/ExtensionTelemetry.jsm",
   FileSource: "resource://gre/modules/L10nRegistry.jsm",
@@ -1847,16 +1848,25 @@ class Extension extends ExtensionData {
       }
     }
   }
 
   static async migratePrivateBrowsing(addonData) {
     if (addonData.incognito !== "not_allowed") {
       ExtensionPermissions.add(addonData.id, {permissions: [PRIVATE_ALLOWED_PERMISSION], origins: []});
       await StartupCache.clearAddonData(addonData.id);
+
+      // Record a telemetry event for the extension automatically allowed on private browsing as
+      // part of the Firefox upgrade.
+      AMTelemetry.recordActionEvent({
+        extra: {addonId: addonData.id},
+        object: "appUpgrade",
+        action: "privateBrowsingAllowed",
+        value: "on",
+      });
     }
   }
 
   async startup() {
     this.state = "Startup";
 
     let resolveReadyPromise;
     let readyPromise = new Promise(resolve => {
--- a/toolkit/components/extensions/test/xpcshell/test_ext_incognito.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_incognito.js
@@ -3,16 +3,27 @@
 "use strict";
 
 const {AddonManager} = ChromeUtils.import("resource://gre/modules/AddonManager.jsm");
 
 AddonTestUtils.init(this);
 AddonTestUtils.overrideCertDB();
 AddonTestUtils.createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
 AddonTestUtils.usePrivilegedSignatures = false;
+AddonTestUtils.hookAMTelemetryEvents();
+
+// Assert on the expected "addonsManager.action" telemetry events (and optional filter events to verify
+// by using a given actionType).
+function assertActionAMTelemetryEvent(expectedActionEvents, assertMessage, {actionType} = {}) {
+  const events = AddonTestUtils.getAMTelemetryEvents().filter(({method, extra}) => {
+    return method === "action" && (!actionType ? true : extra && extra.action === actionType);
+  });
+
+  Assert.deepEqual(events, expectedActionEvents, assertMessage);
+}
 
 async function runIncognitoTest(extensionData, privateBrowsingAllowed, allowPrivateBrowsingByDefault) {
   Services.prefs.setBoolPref("extensions.allowPrivateBrowsingByDefault", allowPrivateBrowsingByDefault);
 
   let wrapper = ExtensionTestUtils.loadExtension(extensionData);
   await wrapper.startup();
   let {extension} = wrapper;
 
@@ -124,9 +135,24 @@ add_task(async function test_extension_i
         "privateBrowsingAllowed is not in permissions for disabled addon");
   equal(disabledPolicy.privateBrowsingAllowed, false,
         "privateBrowsingAllowed in disabled addon");
 
   await wrapper.unload();
   await disabledWrapper.unload();
   Services.prefs.clearUserPref("extensions.allowPrivateBrowsingByDefault");
   Services.prefs.clearUserPref("extensions.incognito.migrated");
+
+  const expectedEvents = [{
+    method: "action",
+    object: "appUpgrade",
+    value: "on",
+    extra: {
+      addonId: "@grandfathered",
+      action: "privateBrowsingAllowed",
+    },
+  }];
+
+  assertActionAMTelemetryEvent(
+    expectedEvents,
+    "Got the expected telemetry events for the grandfathered extensions",
+    {actionType: "privateBrowsingAllowed"});
 });
--- a/toolkit/components/telemetry/Events.yaml
+++ b/toolkit/components/telemetry/Events.yaml
@@ -153,37 +153,39 @@ addonsManager:
       addonId: The id of the add-on being acted upon.
     notification_emails: ["addons-dev-internal@mozilla.com"]
     expiry_version: "73"
     record_in_processes: ["main"]
     bug_numbers: [1500147]
     release_channel_collection: opt-out
   action:
     description: >
-      An action method event is triggered when a user performs an action through the UI on an add-on. The object is
-      where in the product the action was performed.
+      An action method event is triggered when a user performs an action through the UI on an add-on
+      (besides the object "appUpgrade" which is referred to action performed automatically for the user
+      as part of a Firefox upgrade). The object is where in the product the action was performed.
     objects:
       - aboutAddons
       - browserAction
       - customize
       - pageAction
       - doorhanger
+      - appUpgrade
     extra_keys:
       action: >
         The action that was performed. Options include disable, enable, uninstall, undo, contribute, preferences,
         installFromFile, manage, dismiss, checkForUpdates, checkForUpdate, setUpdatePolicy, setAddonUpdate,
         resetUpdatePolicy, privateBrowsingAllowed and releaseNotes.
       type: "For enable, disable, uninstall and undo: the add-on type that is being acted upon."
       view: >
         The view for the event when object is aboutAddons, or the specific doorhanger when object is doorhanger.
       addonId: The id of the add-on being acted upon.
     notification_emails: ["addons-dev-internal@mozilla.com"]
     expiry_version: "73"
     record_in_processes: ["main"]
-    bug_numbers: [1500147, 1513344]
+    bug_numbers: [1500147, 1513344, 1529347]
     release_channel_collection: opt-out
 
 extensions.data:
   migrateResult:
     objects: ["storageLocal"]
     bug_numbers: [1470213]
     notification_emails: ["addons-dev-internal@mozilla.com"]
     expiry_version: "70"