Bug 1478556 - Add a test for jump_to_definition telemetry event log; r=miker.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Fri, 03 Aug 2018 13:35:00 +0000
changeset 826527 a2269f12b9d7fcc1d17bb3721464d02ef82c7b77
parent 826526 d2eea4c02840f08c9cb383942614a19eab4d38e3
child 826528 47aef65bc40dae041cc2c8635fc2594d6ef8aaa4
push id118355
push userwisniewskit@gmail.com
push dateSat, 04 Aug 2018 00:24:59 +0000
reviewersmiker
bugs1478556
milestone63.0a1
Bug 1478556 - Add a test for jump_to_definition telemetry event log; r=miker. Differential Revision: https://phabricator.services.mozilla.com/D2712
devtools/client/webconsole/test/mochitest/browser.ini
devtools/client/webconsole/test/mochitest/browser_webconsole_telemetry_jump_to_definition.js
--- a/devtools/client/webconsole/test/mochitest/browser.ini
+++ b/devtools/client/webconsole/test/mochitest/browser.ini
@@ -359,16 +359,17 @@ skip-if = verify
 [browser_webconsole_split_escape_key.js]
 [browser_webconsole_split_focus.js]
 [browser_webconsole_split_persist.js]
 [browser_webconsole_stacktrace_location_debugger_link.js]
 [browser_webconsole_stacktrace_location_scratchpad_link.js]
 [browser_webconsole_strict_mode_errors.js]
 [browser_webconsole_string.js]
 [browser_webconsole_telemetry_filters_changed.js]
+[browser_webconsole_telemetry_jump_to_definition.js]
 [browser_webconsole_time_methods.js]
 [browser_webconsole_timestamps.js]
 [browser_webconsole_trackingprotection_errors.js]
 tags = trackingprotection
 [browser_webconsole_view_source.js]
 [browser_webconsole_visibility_messages.js]
 [browser_webconsole_warn_about_replaced_api.js]
 [browser_webconsole_websocket.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/webconsole/test/mochitest/browser_webconsole_telemetry_jump_to_definition.js
@@ -0,0 +1,51 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Tests the jump_to_definition telemetry event.
+
+"use strict";
+
+const TEST_URI = `data:text/html,<meta charset=utf8><script>
+  function x(){}
+  console.log("test message", x);
+</script>`;
+
+const OPTOUT = Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT;
+
+add_task(async function() {
+  // Let's reset the counts.
+  Services.telemetry.clearEvents();
+
+  // Ensure no events have been logged
+  const snapshot = Services.telemetry.snapshotEvents(OPTOUT, true);
+  ok(!snapshot.parent, "No events have been logged for the main process");
+
+  const hud = await openNewTabAndConsole(TEST_URI);
+
+  const message = await waitFor(() => findMessage(hud, "test message"));
+  info("Click on the 'jump to definition' button");
+  const jumpIcon = message.querySelector(".jump-definition");
+  jumpIcon.click();
+
+  const events = getJumpToDefinitionEventsExtra();
+  is(events.length, 1, "There was 1 event logged");
+  const [event] = events;
+  ok(event.session_id > 0, "There is a valid session_id in the logged event");
+});
+
+function getJumpToDefinitionEventsExtra() {
+  // Retrieve and clear telemetry events.
+  const snapshot = Services.telemetry.snapshotEvents(OPTOUT, true);
+
+  const events = snapshot.parent.filter(event =>
+    event[1] === "devtools.main" &&
+    event[2] === "jump_to_definition" &&
+    event[3] === "webconsole"
+  );
+
+  // Since we already know we have the correct event, we only return the `extra` field
+  // that was passed to it (which is event[5] here).
+  return events.map(event => event[5]);
+}