Bug 1340842 - Add tests for FX_TAB_CLOSE_TIME_ANIM_MS and FX_TAB_CLOSE_TIME_NO_ANIM_MS probes. r?Mossop draft
authorMike Conley <mconley@mozilla.com>
Fri, 17 Mar 2017 09:50:00 -0400
changeset 503030 46a40c4f8f407947a5ae659ec8b100b15d1772d8
parent 503029 bb328ee7a303958925769e705202a33935f9f814
child 503031 5f36602655fd81daf04692a40556f88c45289b05
push id50459
push usermconley@mozilla.com
push dateWed, 22 Mar 2017 17:36:55 +0000
reviewersMossop
bugs1340842
milestone55.0a1
Bug 1340842 - Add tests for FX_TAB_CLOSE_TIME_ANIM_MS and FX_TAB_CLOSE_TIME_NO_ANIM_MS probes. r?Mossop MozReview-Commit-ID: B9tLzrvBg04
browser/base/content/test/tabs/browser.ini
browser/base/content/test/tabs/browser_tabCloseProbes.js
--- a/browser/base/content/test/tabs/browser.ini
+++ b/browser/base/content/test/tabs/browser.ini
@@ -1,14 +1,15 @@
 [DEFAULT]
 support-files =
   dummy_page.html
 
 [browser_abandonment_telemetry.js]
 [browser_allow_process_switches_despite_related_browser.js]
+[browser_tabCloseProbes.js]
 [browser_tabSpinnerProbe.js]
 skip-if = !e10s # Tab spinner is e10s only.
 [browser_tabSpinnerTypeProbe.js]
 skip-if = !e10s # Tab spinner is e10s only.
 [browser_tabSwitchPrintPreview.js]
 skip-if = os == 'mac'
 [browser_navigatePinnedTab.js]
 [browser_new_web_tab_in_file_process_pref.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabs/browser_tabCloseProbes.js
@@ -0,0 +1,77 @@
+"use strict";
+
+var gAnimHistogram = Services.telemetry
+                             .getHistogramById("FX_TAB_CLOSE_TIME_ANIM_MS");
+var gNoAnimHistogram = Services.telemetry
+                               .getHistogramById("FX_TAB_CLOSE_TIME_NO_ANIM_MS");
+
+/**
+ * Takes a Telemetry histogram snapshot and makes sure
+ * that the sum of all counts equals expectedCount.
+ *
+ * @param snapshot (Object)
+ *        The Telemetry histogram snapshot to examine.
+ * @param expectedCount (int)
+ *        What we expect the number of incremented counts to be. For example,
+ *        If we expect this probe to have only had a single recording, this
+ *        would be 1. If we expected it to have not recorded any data at all,
+ *        this would be 0.
+ */
+function assertCount(snapshot, expectedCount) {
+  // Use Array.prototype.reduce to sum up all of the
+  // snapshot.count entries
+  Assert.equal(snapshot.counts.reduce((a, b) => a + b), expectedCount,
+               `Should only be ${expectedCount} collected value.`);
+}
+
+add_task(function* setup() {
+  // These probes are opt-in, meaning we only capture them if extended
+  // Telemetry recording is enabled.
+  yield SpecialPowers.pushPrefEnv({
+    set: [["toolkit.telemetry.enabled", true]]
+  });
+
+  let oldCanRecord = Services.telemetry.canRecordExtended;
+  Services.telemetry.canRecordExtended = true;
+  registerCleanupFunction(() => {
+    Services.telemetry.canRecordExtended = oldCanRecord;
+  });
+});
+
+/**
+ * Tests the FX_TAB_CLOSE_TIME_ANIM_MS probe by closing a tab with the tab
+ * close animation.
+ */
+add_task(function* test_close_time_anim_probe() {
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser);
+
+  gAnimHistogram.clear();
+  gNoAnimHistogram.clear();
+
+  yield BrowserTestUtils.removeTab(tab, { animate: true });
+
+  assertCount(gAnimHistogram.snapshot(), 1);
+  assertCount(gNoAnimHistogram.snapshot(), 0);
+
+  gAnimHistogram.clear();
+  gNoAnimHistogram.clear();
+});
+
+/**
+ * Tests the FX_TAB_CLOSE_TIME_NO_ANIM_MS probe by closing a tab without the
+ * tab close animation.
+ */
+add_task(function* test_close_time_no_anim_probe() {
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser);
+
+  gAnimHistogram.clear();
+  gNoAnimHistogram.clear();
+
+  yield BrowserTestUtils.removeTab(tab, { animate: false });
+
+  assertCount(gAnimHistogram.snapshot(), 0);
+  assertCount(gNoAnimHistogram.snapshot(), 1);
+
+  gAnimHistogram.clear();
+  gNoAnimHistogram.clear();
+});