Bug 1548481 - Rewrite assertions used in Add-ons Manager tests to make use of TelemetryTestUtils. r=mstriemer,mixedpuppy
authorLuca Greco <lgreco@mozilla.com>
Wed, 14 Aug 2019 20:31:58 +0000
changeset 488211 31e37db859a9add93c95c0be256f799c1e515fc7
parent 488210 0bc9d6bfeb5a08b9dfe2f03c897e564478982e36
child 488212 94ba58e4790d68d948af6a880e908f04ff235991
push id36437
push userncsoregi@mozilla.com
push dateThu, 15 Aug 2019 19:33:18 +0000
treeherdermozilla-central@44aac6fc3352 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstriemer, mixedpuppy
bugs1548481
milestone70.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 1548481 - Rewrite assertions used in Add-ons Manager tests to make use of TelemetryTestUtils. r=mstriemer,mixedpuppy Differential Revision: https://phabricator.services.mozilla.com/D41594
toolkit/mozapps/extensions/test/browser/browser_interaction_telemetry.js
toolkit/mozapps/extensions/test/browser/browser_webext_incognito.js
toolkit/mozapps/extensions/test/browser/browser_webext_incognito_doorhanger_telemetry.js
toolkit/mozapps/extensions/test/browser/head.js
--- a/toolkit/mozapps/extensions/test/browser/browser_interaction_telemetry.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_interaction_telemetry.js
@@ -201,17 +201,17 @@ function clickLinks(doc) {
     let label = doc.getAnonymousElementByAttribute(creator, "anonid", "label");
     let link = doc.getAnonymousElementByAttribute(
       creator,
       "anonid",
       "creator-link"
     );
     // Check that clicking the label doesn't trigger a telemetry event.
     label.click();
-    assertTelemetryMatches([]);
+    assertAboutAddonsTelemetryEvents([]);
     link.click();
     doc.getElementById("detail-homepage").click();
     doc.getElementById("detail-reviews").click();
   }
 }
 
 async function init(startPage) {
   gManagerWindow = await open_manager(null);
@@ -244,151 +244,162 @@ add_task(async function testBasicViewTel
   await gCategoryUtilities.openType("theme");
   openDetailView(doc, "theme@mochi.test");
   await wait_for_view_load(gManagerWindow);
 
   await gCategoryUtilities.openType("extension");
   openDetailView(doc, "extension@mochi.test");
   await wait_for_view_load(gManagerWindow);
 
-  assertTelemetryMatches(
+  assertAboutAddonsTelemetryEvents(
     [
-      ["view", "aboutAddons", "discover"],
-      ["view", "aboutAddons", "list", { type: "theme" }],
+      ["addonsManager", "view", "aboutAddons", "discover"],
+      ["addonsManager", "view", "aboutAddons", "list", { type: "theme" }],
       [
+        "addonsManager",
         "view",
         "aboutAddons",
         "detail",
         { type: "theme", addonId: "theme@mochi.test" },
       ],
-      ["view", "aboutAddons", "list", { type: "extension" }],
+      ["addonsManager", "view", "aboutAddons", "list", { type: "extension" }],
       [
+        "addonsManager",
         "view",
         "aboutAddons",
         "detail",
         { type: "extension", addonId: "extension@mochi.test" },
       ],
     ],
-    { filterMethods: ["view"] }
+    { methods: ["view"] }
   );
 
   await close_manager(gManagerWindow);
   await Promise.all(addons.map(addon => addon.unload()));
 });
 
 add_task(async function testExtensionEvents() {
   let addon = await installExtension();
   let type = "extension";
   let doc = await init("extension");
 
   // Check/clear the current telemetry.
-  assertTelemetryMatches(
-    [["view", "aboutAddons", "list", { type: "extension" }]],
-    { filterMethods: ["view"] }
+  assertAboutAddonsTelemetryEvents(
+    [["addonsManager", "view", "aboutAddons", "list", { type: "extension" }]],
+    { methods: ["view"] }
   );
 
   let row = getAddonCard(doc, addonId);
 
   // Check disable/enable.
   await enableAndDisable(doc, row);
-  assertTelemetryMatches(
+  assertAboutAddonsTelemetryEvents(
     [
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         null,
         { action: "disable", addonId, type, view: "list" },
       ],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         null,
         { action: "enable", addonId, type, view: "list" },
       ],
     ],
-    { filterMethods: ["action"] }
+    { methods: ["action"] }
   );
 
   // Check remove/undo.
   await removeAddonAndUndo(doc, row);
   let uninstallValue = "accepted";
-  assertTelemetryMatches(
+  assertAboutAddonsTelemetryEvents(
     [
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         uninstallValue,
         { action: "uninstall", addonId, type, view: "list" },
       ],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         null,
         { action: "undo", addonId, type, view: "list" },
       ],
     ],
-    { filterMethods: ["action"] }
+    { methods: ["action"] }
   );
 
   // Open the preferences page.
   let waitForNewTab = BrowserTestUtils.waitForNewTab(gBrowser);
   // Find the row again since it was modified on uninstall.
   row = getAddonCard(doc, addonId);
   await openPrefs(doc, row);
   BrowserTestUtils.removeTab(await waitForNewTab);
-  assertTelemetryMatches(
+  assertAboutAddonsTelemetryEvents(
     [
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         "external",
         { action: "preferences", type, addonId, view: "list" },
       ],
     ],
-    { filterMethods: ["action"] }
+    { methods: ["action"] }
   );
 
   // Go to the detail view.
   openDetailView(doc, addonId);
   await wait_for_view_load(gManagerWindow);
-  assertTelemetryMatches(
-    [["view", "aboutAddons", "detail", { type, addonId }]],
-    { filterMethods: ["view"] }
+  assertAboutAddonsTelemetryEvents(
+    [["addonsManager", "view", "aboutAddons", "detail", { type, addonId }]],
+    { methods: ["view"] }
   );
 
   // Check updates.
   changeAutoUpdates(doc);
-  assertTelemetryMatches(
+  assertAboutAddonsTelemetryEvents(
     [
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         "",
         { action: "setAddonUpdate", type, addonId, view: "detail" },
       ],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         null,
         { action: "checkForUpdate", type, addonId, view: "detail" },
       ],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         "enabled",
         { action: "setAddonUpdate", type, addonId, view: "detail" },
       ],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         "default",
         { action: "setAddonUpdate", type, addonId, view: "detail" },
       ],
     ],
-    { filterMethods: ["action"] }
+    { methods: ["action"] }
   );
 
   // These links don't actually have a URL, so they don't open a tab. They're only
   // shown when there is a URL though.
   clickLinks(doc);
 
   // The support button will open a new tab.
   waitForNewTab = BrowserTestUtils.waitForNewTab(gBrowser);
@@ -396,59 +407,62 @@ add_task(async function testExtensionEve
   BrowserTestUtils.removeTab(await waitForNewTab);
 
   // Check that the preferences button includes the view.
   waitForNewTab = BrowserTestUtils.waitForNewTab(gBrowser);
   row = getAddonCard(doc, addonId);
   await openPrefs(doc, row);
   BrowserTestUtils.removeTab(await waitForNewTab);
 
-  assertTelemetryMatches(
+  assertAboutAddonsTelemetryEvents(
     [
-      ["link", "aboutAddons", "author", { view: "detail" }],
-      ["link", "aboutAddons", "homepage", { view: "detail" }],
-      ["link", "aboutAddons", "rating", { view: "detail" }],
-      ["link", "aboutAddons", "support", { view: "detail" }],
+      ["addonsManager", "link", "aboutAddons", "author", { view: "detail" }],
+      ["addonsManager", "link", "aboutAddons", "homepage", { view: "detail" }],
+      ["addonsManager", "link", "aboutAddons", "rating", { view: "detail" }],
+      ["addonsManager", "link", "aboutAddons", "support", { view: "detail" }],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         "external",
         { action: "preferences", type, addonId, view: "detail" },
       ],
     ],
-    { filterMethods: ["action", "link"] }
+    { methods: ["action", "link"] }
   );
 
   // Update the preferences and check that inline changes.
   await gCategoryUtilities.openType("extension");
   let upgraded = await installExtension({
     options_ui: { page: "options.html" },
     version: "2",
   });
   row = getAddonCard(doc, addonId);
   await openPrefs(doc, row);
   await wait_for_view_load(gManagerWindow);
 
-  assertTelemetryMatches(
+  assertAboutAddonsTelemetryEvents(
     [
-      ["view", "aboutAddons", "list", { type }],
+      ["addonsManager", "view", "aboutAddons", "list", { type }],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         "inline",
         { action: "preferences", type, addonId, view: "list" },
       ],
       [
+        "addonsManager",
         "view",
         "aboutAddons",
         "detail",
         { type: "extension", addonId: "extension@mochi.test" },
       ],
     ],
-    { filterMethods: ["action", "view"] }
+    { methods: ["action", "view"] }
   );
 
   await close_manager(gManagerWindow);
   await addon.unload();
   await upgraded.unload();
 });
 
 add_task(async function testGeneralActions() {
@@ -490,69 +504,81 @@ add_task(async function testGeneralActio
   BrowserTestUtils.removeTab(await waitForNewTab);
 
   waitForNewTab = BrowserTestUtils.waitForNewTab(gBrowser);
   let searchBox = doc.getElementById("header-search");
   searchBox.value = "something";
   searchBox.doCommand();
   BrowserTestUtils.removeTab(await waitForNewTab);
 
-  assertTelemetryMatches(
+  assertAboutAddonsTelemetryEvents(
     [
-      ["view", "aboutAddons", "list", { type: "extension" }],
+      ["addonsManager", "view", "aboutAddons", "list", { type: "extension" }],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         null,
         { action: "checkForUpdates", view: "list" },
       ],
-      ["view", "aboutAddons", "updates", { type: "recent" }],
+      ["addonsManager", "view", "aboutAddons", "updates", { type: "recent" }],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         "default,enabled",
         { action: "setUpdatePolicy", view: "updates" },
       ],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         "enabled",
         { action: "setUpdatePolicy", view: "updates" },
       ],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         null,
         { action: "resetUpdatePolicy", view: "updates" },
       ],
-      ["view", "aboutAddons", "shortcuts"],
+      ["addonsManager", "view", "aboutAddons", "shortcuts"],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         null,
         { action: "checkForUpdates", view: "shortcuts" },
       ],
-      ["link", "aboutAddons", "about:debugging", { view: "shortcuts" }],
       [
+        "addonsManager",
+        "link",
+        "aboutAddons",
+        "about:debugging",
+        { view: "shortcuts" },
+      ],
+      [
+        "addonsManager",
         "link",
         "aboutAddons",
         "search",
         { view: "shortcuts", type: "shortcuts" },
       ],
     ],
-    { filterMethods: TELEMETRY_METHODS }
+    { methods: TELEMETRY_METHODS }
   );
 
   await close_manager(gManagerWindow);
 
-  assertTelemetryMatches([]);
+  assertAboutAddonsTelemetryEvents([]);
 });
 
 add_task(async function testPreferencesLink() {
-  assertTelemetryMatches([]);
+  assertAboutAddonsTelemetryEvents([]);
 
   await init("theme");
 
   let doc = gManagerWindow.document;
 
   // Open the about:preferences page from about:addons.
   let waitForNewTab = BrowserTestUtils.waitForNewTab(
     gBrowser,
@@ -567,19 +593,28 @@ add_task(async function testPreferencesL
   await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
 
   // Open the about:addons page from about:preferences.
   getAddonsButton().click();
 
   // Close the about:preferences tab.
   BrowserTestUtils.removeTab(tab);
 
-  assertTelemetryMatches(
+  TelemetryTestUtils.assertEvents(
     [
-      ["view", "aboutAddons", "list", { type: "theme" }],
-      ["link", "aboutAddons", "about:preferences", { view: "list" }],
-      ["link", "aboutPreferences", "about:addons"],
+      ["addonsManager", "view", "aboutAddons", "list", { type: "theme" }],
+      [
+        "addonsManager",
+        "link",
+        "aboutAddons",
+        "about:preferences",
+        { view: "list" },
+      ],
+      ["addonsManager", "link", "aboutPreferences", "about:addons"],
     ],
-    { filterMethods: ["link", "view"] }
+    {
+      category: "addonsManager",
+      methods: /^(link|view)$/,
+    }
   );
 
   await close_manager(gManagerWindow);
 });
--- a/toolkit/mozapps/extensions/test/browser/browser_webext_incognito.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webext_incognito.js
@@ -256,38 +256,41 @@ add_task(async function test_badge_and_t
   }
 
   const expectedExtras = {
     action: "privateBrowsingAllowed",
     view: "detail",
     type: "extension",
   };
 
-  assertTelemetryMatches(
+  assertAboutAddonsTelemetryEvents(
     [
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         "on",
         { ...expectedExtras, addonId: "@test-default" },
       ],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         "off",
         { ...expectedExtras, addonId: "@test-override" },
       ],
       [
+        "addonsManager",
         "action",
         "aboutAddons",
         "off",
         { ...expectedExtras, addonId: "@test-override-permanent" },
       ],
     ],
-    { filterMethods: ["action"] }
+    { methods: ["action"] }
   );
 
   Services.prefs.clearUserPref("extensions.allowPrivateBrowsingByDefault");
 });
 
 add_task(async function test_addon_preferences_button() {
   await SpecialPowers.pushPrefEnv({
     set: [["extensions.allowPrivateBrowsingByDefault", false]],
--- a/toolkit/mozapps/extensions/test/browser/browser_webext_incognito_doorhanger_telemetry.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webext_incognito_doorhanger_telemetry.js
@@ -11,19 +11,30 @@ function promisePreferenceChanged(pref) 
       resolve();
     };
 
     Services.prefs.addObserver(pref, listener);
   });
 }
 
 function assertDoorhangerTelemetry(action) {
-  assertTelemetryMatches(
-    [["action", "doorhanger", null, { action, view: "privateBrowsing" }]],
-    { filterMethods: ["action"] }
+  TelemetryTestUtils.assertEvents(
+    [
+      [
+        "addonsManager",
+        "action",
+        "doorhanger",
+        null,
+        { action, view: "privateBrowsing" },
+      ],
+    ],
+    {
+      category: "addonsManager",
+      method: "action",
+    }
   );
 }
 
 async function checkDoorhanger(win) {
   await BrowserTestUtils.waitForCondition(
     () => win.AppMenuNotifications.activeNotification,
     "Wait for the AppMenuNotification to be active"
   );
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -1658,51 +1658,16 @@ function assertAboutAddonsTelemetryEvent
     method: actual =>
       filters.methods
         ? filters.methods.includes(actual)
         : ABOUT_ADDONS_METHODS.has(actual),
     object: "aboutAddons",
   });
 }
 
-function assertTelemetryMatches(events, { filterMethods } = {}) {
-  let snapshot = Services.telemetry.snapshotEvents(
-    Ci.nsITelemetry.DATASET_PRERELEASE_CHANNELS,
-    true
-  );
-
-  if (events.length == 0) {
-    ok(
-      !snapshot.parent || snapshot.parent.length == 0,
-      "There are no telemetry events"
-    );
-    return;
-  }
-
-  // Make sure we got some data.
-  ok(
-    snapshot.parent && snapshot.parent.length > 0,
-    "Got parent telemetry events in the snapshot"
-  );
-
-  // Only look at the related events after stripping the timestamp and category (and optionally filter
-  // out the events related to methods that we are not interested in).
-  let relatedEvents = snapshot.parent
-    .filter(([timestamp, category, method]) => {
-      return (
-        category == "addonsManager" &&
-        (filterMethods ? filterMethods.includes(method) : true)
-      );
-    })
-    .map(relatedEvent => relatedEvent.slice(2, 6));
-
-  // Events are now [method, object, value, extra] as expected.
-  Assert.deepEqual(relatedEvents, events, "The events are recorded correctly");
-}
-
 /* HTML view helpers */
 async function loadInitialView(type) {
   // Force the first page load to be the view we want.
   let viewId = type == "discover" ? "discover/" : `list/${type}`;
   Services.prefs.setCharPref(PREF_UI_LASTCATEGORY, `addons://${viewId}`);
 
   let managerWindow = await open_manager(null);