Bug 1572867 - Use toolbox topWindow to prepare telemetry "open" event r=nchevobbe a=RyanVM
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 19 Aug 2019 15:21:58 +0000
changeset 545223 a1f1970711628653b6f51207c09a5ab091cb135c
parent 545222 0c5705cd989971ed10e0c3e6801ce4bc272d2d84
child 545224 b0109dd26903109a0f5e04ec7dc99299116df18d
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe, RyanVM
bugs1572867
milestone69.0
Bug 1572867 - Use toolbox topWindow to prepare telemetry "open" event r=nchevobbe a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D41801
devtools/client/framework/devtools.js
devtools/client/framework/moz.build
devtools/client/framework/test/browser-telemetry-startup.ini
devtools/client/framework/test/browser_toolbox_telemetry_open_event.js
devtools/client/framework/toolbox.js
--- a/devtools/client/framework/devtools.js
+++ b/devtools/client/framework/devtools.js
@@ -576,17 +576,17 @@ DevTools.prototype = {
     const delay = Cu.now() - startTime;
     const panelName = this.makeToolIdHumanReadable(toolId);
 
     const telemetryKey = this._firstShowToolbox
       ? "DEVTOOLS_COLD_TOOLBOX_OPEN_DELAY_MS"
       : "DEVTOOLS_WARM_TOOLBOX_OPEN_DELAY_MS";
     this._telemetry.getKeyedHistogramById(telemetryKey).add(toolId, delay);
 
-    const browserWin = toolbox.win.top;
+    const browserWin = toolbox.topWindow;
     this._telemetry.addEventProperty(
       browserWin,
       "open",
       "tools",
       null,
       "first_panel",
       panelName
     );
--- a/devtools/client/framework/moz.build
+++ b/devtools/client/framework/moz.build
@@ -2,16 +2,17 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 BROWSER_CHROME_MANIFESTS += [
     'test/allocations/browser_allocations_target.ini',
     'test/browser-rtl.ini',
+    'test/browser-telemetry-startup.ini',
     'test/browser.ini',
     'test/metrics/browser_metrics_debugger.ini',
     'test/metrics/browser_metrics_inspector.ini',
     'test/metrics/browser_metrics_netmonitor.ini',
     'test/metrics/browser_metrics_webconsole.ini',
 ]
 XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
 
new file mode 100644
--- /dev/null
+++ b/devtools/client/framework/test/browser-telemetry-startup.ini
@@ -0,0 +1,13 @@
+[DEFAULT]
+tags = devtools
+subsuite = devtools
+support-files =
+  head.js
+  !/devtools/client/shared/test/shared-head.js
+  !/devtools/client/shared/test/telemetry-test-helpers.js
+
+# This test suite is dedicated to run a test for the telemetry event logged when
+# opening the toolbox for the first time. This test has to be the first test
+# running for a given instance of Firefox. A dedicated ini file will ensure a
+# new browser instance is created just for this test.
+[browser_toolbox_telemetry_open_event.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/framework/test/browser_toolbox_telemetry_open_event.js
@@ -0,0 +1,35 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test that the "open" telemetry event is correctly logged when opening the
+// toolbox.
+const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
+
+add_task(async function() {
+  Services.prefs.clearUserPref("devtools.toolbox.selectedTool");
+  const tab = await addTab("data:text/html;charset=utf-8,Test open event");
+
+  info("Open the toolbox with a shortcut to trigger the open event");
+  const onToolboxReady = gDevTools.once("toolbox-ready");
+  EventUtils.synthesizeKey("VK_F12", {});
+  await onToolboxReady;
+
+  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
+  const events = snapshot.parent.filter(
+    event =>
+      event[1] === "devtools.main" && event[2] === "open" && event[4] === null
+  );
+
+  is(events.length, 1, "Telemetry open event was logged");
+
+  const extras = events[0][5];
+  is(extras.entrypoint, "KeyShortcut", "entrypoint extra is correct");
+  // The logged shortcut is `${modifiers}+${shortcut}`, which adds an
+  // extra `+` before F12 here.
+  // See https://searchfox.org/mozilla-central/rev/c7e8bc4996f979e5876b33afae3de3b1ab4f3ae1/devtools/startup/DevToolsStartup.jsm#1070
+  is(extras.shortcut, "+F12", "entrypoint shortcut is correct");
+
+  gBrowser.removeTab(tab);
+});
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -735,26 +735,26 @@ Toolbox.prototype = {
       await this.selectTool(this._defaultToolId, "initial_panel");
 
       // Wait until the original tool is selected so that the split
       // console input will receive focus.
       let splitConsolePromise = promise.resolve();
       if (Services.prefs.getBoolPref(SPLITCONSOLE_ENABLED_PREF)) {
         splitConsolePromise = this.openSplitConsole();
         this.telemetry.addEventProperty(
-          this.win,
+          this.topWindow,
           "open",
           "tools",
           null,
           "splitconsole",
           true
         );
       } else {
         this.telemetry.addEventProperty(
-          this.win,
+          this.topWindow,
           "open",
           "tools",
           null,
           "splitconsole",
           false
         );
       }
 
@@ -1238,17 +1238,17 @@ Toolbox.prototype = {
       .getHistogramById(HOST_HISTOGRAM)
       .add(this._getTelemetryHostId());
 
     // Log current theme. The question we want to answer is:
     // "What proportion of users use which themes?"
     const currentTheme = Services.prefs.getCharPref("devtools.theme");
     this.telemetry.keyedScalarAdd(CURRENT_THEME_SCALAR, currentTheme, 1);
 
-    const browserWin = this.win.top;
+    const browserWin = this.topWindow;
     this.telemetry.preparePendingEvent(browserWin, "open", "tools", null, [
       "entrypoint",
       "first_panel",
       "host",
       "shortcut",
       "splitconsole",
       "width",
       "session_id",
@@ -2509,17 +2509,17 @@ Toolbox.prototype = {
         width: width,
         panel_name: prevPanelName,
         next_panel: panelName,
         reason: reason,
         session_id: this.sessionId,
       });
     }
 
-    this.telemetry.addEventProperties(this.win, "open", "tools", null, {
+    this.telemetry.addEventProperties(this.topWindow, "open", "tools", null, {
       width: width,
       session_id: this.sessionId,
     });
 
     if (id === "webconsole") {
       pending.push("message_count");
     }