Bug 1529347 - Record telemetry event on extensions enabled on private windows from the post install notification doorhanger. r=mixedpuppy
authorLuca Greco <lgreco@mozilla.com>
Wed, 06 Mar 2019 13:59:31 +0000
changeset 520484 a5187ade9132c8a456280fe7711feb571f800012
parent 520483 b8e5c1d19e24a94643360c610ef9a3f304dcbc11
child 520485 5cc66e233192de72cf4eac10c20e85b952285f12
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
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 from the post install notification doorhanger. r=mixedpuppy Differential Revision: https://phabricator.services.mozilla.com/D21931
browser/modules/ExtensionsUI.jsm
toolkit/mozapps/extensions/test/xpinstall/browser_doorhanger_installs.js
--- a/browser/modules/ExtensionsUI.jsm
+++ b/browser/modules/ExtensionsUI.jsm
@@ -444,16 +444,24 @@ var ExtensionsUI = {
       let checkbox = window.document.getElementById("addon-incognito-checkbox");
       checkbox.checked = false;
       checkbox.hidden = allowPrivateBrowsingByDefault;
 
       async function actionResolve() {
         if (checkbox.checked) {
           let perms = {permissions: ["internal:privateBrowsingAllowed"], origins: []};
           await ExtensionPermissions.add(addon.id, perms);
+          AMTelemetry.recordActionEvent({
+            addon,
+            object: "doorhanger",
+            action: "privateBrowsingAllowed",
+            view: "postInstall",
+            value: "on",
+          });
+
           // Reload the extension if it is already enabled.  This ensures any change
           // on the private browsing permission is properly handled.
           if (addon.isActive) {
             await addon.reload();
           }
         }
 
         resolve();
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_doorhanger_installs.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_doorhanger_installs.js
@@ -1,19 +1,34 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
+const {AddonTestUtils} = ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm");
+
 const SECUREROOT = "https://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/";
 const PROGRESS_NOTIFICATION = "addon-progress";
 
 const CHROMEROOT = extractChromeRoot(gTestPath);
 
 var gApp = document.getElementById("bundle_brand").getString("brandShortName");
 
+AddonTestUtils.initMochitest(this);
+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);
+}
+
 function waitForTick() {
   return new Promise(resolve => executeSoon(resolve));
 }
 
 function getObserverTopic(aNotificationId) {
   let topic = aNotificationId;
   if (topic == "xpinstall-disabled")
     topic = "addon-install-disabled";
@@ -463,16 +478,30 @@ async function test_urlBar() {
   // to wait for the reload to finish. addon.startupPromise doesn't do it for
   // us, so we'll just restart again.
   await addon.reload();
 
   // This addon should have private browsing permission.
   let policy = WebExtensionPolicy.getByID(addon.id);
   ok(policy.privateBrowsingAllowed, "private browsing permission granted");
 
+  // Verify that the expected telemetry event has been collected for the extension allowed on
+  // PB windows from the "post install" notification doorhanger.
+  assertActionAMTelemetryEvent([{
+    method: "action",
+    object: "doorhanger",
+    value: "on",
+    extra: {
+      action: "privateBrowsingAllowed",
+      view: "postInstall",
+      addonId: addon.id,
+      type: "extension",
+    },
+  }], "Expect telemetry events for privateBrowsingAllowed action", {actionType: "privateBrowsingAllowed"});
+
   addon.uninstall();
 
   Services.prefs.clearUserPref("extensions.allowPrivateBrowsingByDefault");
 
   await removeTabAndWaitForNotificationClose();
 },
 
 async function test_wrongHost() {
@@ -669,10 +698,15 @@ add_task(async function() {
     ok(!PopupNotifications.isPanelOpen, "Notification should be closed");
 
     let installs = await AddonManager.getAllInstalls();
 
     is(installs.length, 0, "Should be no active installs");
     info("Running " + TESTS[i].name);
     gTestStart = Date.now();
     await TESTS[i]();
+
+    // Check that no unexpected telemetry events for the privateBrowsingAllowed action has been
+    // collected while running the test case.
+    assertActionAMTelemetryEvent([], "Expect no telemetry events for privateBrowsingAllowed actions",
+                                 {actionType: "privateBrowsingAllowed"});
   }
 });