Bug 1456098 - Create tests for devtools.main.activate telemetry event r=yulia
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Wed, 25 Apr 2018 18:04:35 +0100
changeset 415860 c9566c1573ab15809ab1b0482e543db443774d81
parent 415859 e720e80865b2efc109a95d0607e338526a2f1030
child 415861 029547eb5a875602cabe07deaca2fee28deec4dc
push id33911
push usercsabou@mozilla.com
push dateFri, 27 Apr 2018 10:01:39 +0000
treeherdermozilla-central@822936017145 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1456098
milestone61.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 1456098 - Create tests for devtools.main.activate telemetry event r=yulia MozReview-Commit-ID: III7oI427vr
devtools/client/framework/test/browser.ini
devtools/client/framework/test/browser_toolbox_telemetry_activate_splitconsole.js
devtools/client/responsive.html/test/browser/browser.ini
devtools/client/responsive.html/test/browser/browser_telemetry_activate_rdm.js
--- a/devtools/client/framework/test/browser.ini
+++ b/devtools/client/framework/test/browser.ini
@@ -100,16 +100,17 @@ skip-if = e10s # Bug 1069044 - destroyIn
 [browser_toolbox_selectionchanged_event.js]
 [browser_toolbox_sidebar.js]
 [browser_toolbox_sidebar_events.js]
 [browser_toolbox_sidebar_existing_tabs.js]
 [browser_toolbox_sidebar_overflow_menu.js]
 [browser_toolbox_split_console.js]
 [browser_toolbox_target.js]
 [browser_toolbox_tabsswitch_shortcuts.js]
+[browser_toolbox_telemetry_activate_splitconsole.js]
 [browser_toolbox_telemetry_close.js]
 [browser_toolbox_telemetry_enter.js]
 [browser_toolbox_telemetry_exit.js]
 [browser_toolbox_textbox_context_menu.js]
 [browser_toolbox_theme.js]
 [browser_toolbox_theme_registration.js]
 [browser_toolbox_toggle.js]
 [browser_toolbox_tool_ready.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/framework/test/browser_toolbox_telemetry_activate_splitconsole.js
@@ -0,0 +1,75 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const URL =
+  "data:text/html;charset=utf8,browser_toolbox_telemetry_activate_splitconsole.js";
+const OPTOUT = Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT;
+const DATA = [
+  {
+    timestamp: null,
+    category: "devtools.main",
+    method: "activate",
+    object: "split_console",
+    value: null,
+    extra: {
+      host: "bottom",
+      width: "1300"
+    }
+  }, {
+    timestamp: null,
+    category: "devtools.main",
+    method: "activate",
+    object: "split_console",
+    value: null,
+    extra: {
+      host: "bottom",
+      width: "1300"
+    }
+  }
+];
+
+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 tab = await addTab(URL);
+  const target = TargetFactory.forTab(tab);
+  const toolbox = await gDevTools.showToolbox(target, "inspector");
+
+  await toolbox.openSplitConsole();
+  await toolbox.closeSplitConsole();
+  await toolbox.openSplitConsole();
+  await toolbox.closeSplitConsole();
+
+  await checkResults();
+});
+
+async function checkResults() {
+  const snapshot = Services.telemetry.snapshotEvents(OPTOUT, true);
+  const events = snapshot.parent.filter(event => event[1] === "devtools.main" &&
+                                                 event[2] === "activate" &&
+                                                 event[4] === null
+  );
+
+  for (let i in DATA) {
+    const [ timestamp, category, method, object, value, extra ] = events[i];
+    const expected = DATA[i];
+
+    // ignore timestamp
+    ok(timestamp > 0, "timestamp is greater than 0");
+    is(category, expected.category, "category is correct");
+    is(method, expected.method, "method is correct");
+    is(object, expected.object, "object is correct");
+    is(value, expected.value, "value is correct");
+
+    // extras
+    is(extra.host, expected.extra.host, "host is correct");
+    ok(extra.width > 0, "width is greater than 0");
+  }
+}
--- a/devtools/client/responsive.html/test/browser/browser.ini
+++ b/devtools/client/responsive.html/test/browser/browser.ini
@@ -41,16 +41,17 @@ skip-if = true # Bug 1413765
 [browser_permission_doorhanger.js]
 tags = devtools geolocation
 skip-if = true # Bug 1413765
 [browser_resize_cmd.js]
 [browser_screenshot_button.js]
 [browser_tab_close.js]
 [browser_tab_remoteness_change.js]
 [browser_target_blank.js]
+[browser_telemetry_activate_rdm.js]
 [browser_toolbox_computed_view.js]
 [browser_toolbox_rule_view.js]
 [browser_toolbox_swap_browsers.js]
 [browser_toolbox_swap_inspector.js]
 [browser_touch_device.js]
 [browser_touch_simulation.js]
 [browser_viewport_basics.js]
 [browser_window_close.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/responsive.html/test/browser/browser_telemetry_activate_rdm.js
@@ -0,0 +1,88 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+const URL =
+  "data:text/html;charset=utf8,browser_telemetry_activate_rdm.js";
+const OPTOUT = Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT;
+const DATA = [
+  {
+    timestamp: null,
+    category: "devtools.main",
+    method: "activate",
+    object: "responsive_design",
+    value: null,
+    extra: {
+      host: "none",
+      width: "1300"
+    }
+  }, {
+    timestamp: null,
+    category: "devtools.main",
+    method: "activate",
+    object: "responsive_design",
+    value: null,
+    extra: {
+      host: "bottom",
+      width: "1300"
+    }
+  }
+];
+
+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 tab = await addTab(URL);
+  const target = TargetFactory.forTab(tab);
+
+  await openCloseRDM(tab);
+  await gDevTools.showToolbox(target, "inspector");
+  await openCloseRDM(tab);
+  await checkResults();
+});
+
+async function openCloseRDM(tab) {
+  let { ui } = await openRDM(tab);
+  let clientClosed = waitForClientClose(ui);
+
+  closeRDM(tab, {
+    reason: "TabClose",
+  });
+
+  // This flag is set at the end of `ResponsiveUI.destroy`.  If it is true
+  // without waiting for `closeRDM` above, then we must have closed
+  // synchronously.
+  is(ui.destroyed, true, "RDM closed synchronously");
+
+  await clientClosed;
+}
+
+async function checkResults() {
+  const snapshot = Services.telemetry.snapshotEvents(OPTOUT, true);
+  const events = snapshot.parent.filter(event => event[1] === "devtools.main" &&
+                                                 event[2] === "activate" &&
+                                                 event[4] === null
+  );
+
+  for (let i in events) {
+    const [ timestamp, category, method, object, value, extra ] = events[i];
+
+    const expected = DATA[i];
+
+    // ignore timestamp
+    ok(timestamp > 0, "timestamp is greater than 0");
+    is(category, expected.category, "category is correct");
+    is(method, expected.method, "method is correct");
+    is(object, expected.object, "object is correct");
+    is(value, expected.value, "value is correct");
+
+    // extras
+    is(extra.host, expected.extra.host, "host is correct");
+    ok(extra.width > 0, "width is greater than 0");
+  }
+}