Bug 1692218 - Add Page Action Menu use counter prefs. r=harry
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 12 Feb 2021 20:58:18 +0000
changeset 567397 78fac34502ccebf64b59d85f8d0c17817958148f
parent 567396 27dee66eba834658f0b98504f05213341d0b3cd7
child 567398 bdef3d98e687e8df0fa73827b972c09ef5bfa97b
push id136390
push usermak77@bonardo.net
push dateFri, 12 Feb 2021 21:02:16 +0000
treeherderautoland@78fac34502cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersharry
bugs1692218, 1692216, 1692215
milestone87.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 1692218 - Add Page Action Menu use counter prefs. r=harry Also includes: https://bugzilla.mozilla.org/show_bug.cgi?id=1692216 https://bugzilla.mozilla.org/show_bug.cgi?id=1692215 Differential Revision: https://phabricator.services.mozilla.com/D105033
browser/modules/BrowserUsageTelemetry.jsm
browser/modules/test/browser/browser_UsageTelemetry_usagePrefs.js
--- a/browser/modules/BrowserUsageTelemetry.jsm
+++ b/browser/modules/BrowserUsageTelemetry.jsm
@@ -131,16 +131,30 @@ const KNOWN_ADDONS = [];
 const SET_USAGE_PREF_BUTTONS = [
   "downloads-button",
   "fxa-toolbar-menu-button",
   "home-button",
   "sidebar-button",
   "library-button",
 ];
 
+// Buttons that, when clicked, increase a counter. The convention
+// is that the preference is named:
+//
+// browser.engagement.<button id>.used-count
+//
+// and doesn't have a default value.
+const SET_USAGECOUNT_PREF_BUTTONS = [
+  "pageAction-panel-copyURL",
+  "pageAction-panel-emailLink",
+  "pageAction-panel-pinTab",
+  "pageAction-panel-screenshots_mozilla_org",
+  "pageAction-panel-shareURL",
+];
+
 function telemetryId(widgetId, obscureAddons = true) {
   // Add-on IDs need to be obscured.
   function addonId(id) {
     if (!obscureAddons) {
       return id;
     }
 
     let pos = KNOWN_ADDONS.indexOf(id);
@@ -823,17 +837,20 @@ let BrowserUsageTelemetry = {
     }
 
     let item = this._getWidgetID(node);
     let source = this._getWidgetContainer(node);
 
     if (item && source) {
       let scalar = `browser.ui.interaction.${source.replace("-", "_")}`;
       Services.telemetry.keyedScalarAdd(scalar, telemetryId(item), 1);
-
+      if (SET_USAGECOUNT_PREF_BUTTONS.includes(item)) {
+        let pref = `browser.engagement.${item}.used-count`;
+        Services.prefs.setIntPref(pref, Services.prefs.getIntPref(pref, 0) + 1);
+      }
       if (SET_USAGE_PREF_BUTTONS.includes(item)) {
         Services.prefs.setBoolPref(`browser.engagement.${item}.has-used`, true);
       }
     }
   },
 
   /**
    * Listens for UI interactions in the window.
--- a/browser/modules/test/browser/browser_UsageTelemetry_usagePrefs.js
+++ b/browser/modules/test/browser/browser_UsageTelemetry_usagePrefs.js
@@ -74,8 +74,69 @@ add_task(async function test_usage_ctrlt
 
   EventUtils.synthesizeKey("VK_TAB", { ctrlKey: true });
 
   Assert.ok(
     Services.prefs.getBoolPref(ctrlTabUsed),
     `${ctrlTabUsed} should now be true after interacting.`
   );
 });
+
+/**
+ * Tests that browser.engagement.pageAction-panel-*.used.count is incremented
+ * when user clicks on certain page action buttons.
+ */
+add_task(async function test_usage_pageAction_buttons() {
+  // Skip the test if proton is enabled, since these buttons are hidden.
+  if (gProton) {
+    return;
+  }
+
+  await SpecialPowers.pushPrefEnv({
+    set: [["extensions.screenshots.disabled", false]],
+  });
+
+  const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");
+  const sandbox = sinon.createSandbox();
+  registerCleanupFunction(sandbox.restore);
+  sandbox.stub(BrowserPageActions, "doCommandForAction").callsFake(() => {});
+
+  await BrowserTestUtils.withNewTab("http://example.com/", async browser => {
+    info("Open the pageAction panel");
+    await promiseOpenPageActionPanel();
+
+    function click(button) {
+      info(`Click on ${button.id}`);
+      EventUtils.synthesizeMouseAtCenter(button, {}, window);
+    }
+
+    let ids = [
+      "pageAction-panel-copyURL",
+      "pageAction-panel-emailLink",
+      "pageAction-panel-pinTab",
+      "pageAction-panel-screenshots_mozilla_org",
+    ];
+    if (
+      AppConstants.platform == "macosx" ||
+      AppConstants.isPlatformAndVersionAtLeast("win", "6.4")
+    ) {
+      ids.push("pageAction-panel-shareURL");
+    }
+    for (let id of ids) {
+      let pref = `browser.engagement.${id}.used-count`;
+      let button = document.getElementById(id);
+      Assert.ok(button, `The button "${id}" should be present`);
+      Services.prefs.clearUserPref(pref);
+      Assert.equal(Services.prefs.getIntPref(pref, 0), 0, "Check initial");
+      click(button);
+      Assert.equal(Services.prefs.getIntPref(pref, 0), 1, "Check increment");
+      click(button);
+      Assert.equal(Services.prefs.getIntPref(pref, 0), 2, "Check increment");
+      Services.prefs.clearUserPref(pref);
+    }
+
+    let hidePromise = promisePageActionPanelHidden();
+    BrowserPageActions.panelNode.hidePopup();
+    await hidePromise;
+  });
+
+  await SpecialPowers.popPrefEnv();
+});