Bug 1361855 - Record TAB_COUNT histogram during TabOpen event; r=Gijs
☠☠ backed out by 3325a300f82f ☠ ☠
authorLie Ryan <lie.1296@gmail.com>
Fri, 09 Jun 2017 18:40:24 +0000
changeset 369260 2d6877c0b84e14435a73ad2ea75812d290957130
parent 369259 6bfc9384ed6413cb32bf61b20c1b79b9e8d12085
child 369261 06dbf8fc7da316a35db5a84ff12988344e369183
push id46631
push userkwierso@gmail.com
push dateTue, 18 Jul 2017 00:38:28 +0000
treeherderautoland@216a5bf264b2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1361855
milestone56.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 1361855 - Record TAB_COUNT histogram during TabOpen event; r=Gijs MozReview-Commit-ID: 7ZHakmLZYHu
browser/modules/BrowserUsageTelemetry.jsm
browser/modules/test/browser/browser_UsageTelemetry.js
--- a/browser/modules/BrowserUsageTelemetry.jsm
+++ b/browser/modules/BrowserUsageTelemetry.jsm
@@ -606,16 +606,18 @@ let BrowserUsageTelemetry = {
    *        is computed manually if not provided.
    */
   _onTabOpen(tabCount = 0) {
     // Use the provided tab count if available. Otherwise, go on and compute it.
     tabCount = tabCount || getOpenTabsAndWinsCounts().tabCount;
     // Update the "tab opened" count and its maximum.
     Services.telemetry.scalarAdd(TAB_OPEN_EVENT_COUNT_SCALAR_NAME, 1);
     Services.telemetry.scalarSetMaximum(MAX_TAB_COUNT_SCALAR_NAME, tabCount);
+
+    this._recordTabCount(tabCount);
   },
 
   /**
    * Tracks the window count and registers the listeners for the tab count.
    * @param{Object} win The window object.
    */
   _onWindowOpen(win) {
     // Make sure to have a |nsIDOMWindow|.
--- a/browser/modules/test/browser/browser_UsageTelemetry.js
+++ b/browser/modules/test/browser/browser_UsageTelemetry.js
@@ -262,8 +262,44 @@ add_task(async function test_URIAndDomai
   await BrowserTestUtils.loadURI(newWin.gBrowser.selectedBrowser, TEST_PAGE);
   await BrowserTestUtils.browserLoaded(newWin.gBrowser.selectedBrowser);
   checkCounts({totalURIs: 5, domainCount: 2, totalUnfilteredURIs: 6});
 
   // Clean up.
   await BrowserTestUtils.removeTab(firstTab);
   await BrowserTestUtils.closeWindow(newWin);
 });
+
+function checkTabCountHistogram(result, expected, message) {
+  let expectedPadded = result.counts.map((val, idx) => idx < expected.length ? expected[idx] : 0);
+  Assert.deepEqual(result.counts, expectedPadded, message);
+}
+
+add_task(async function test_tabsHistogram() {
+  let openedTabs = [];
+  let tabCountHist = getAndClearHistogram("TAB_COUNT");
+
+  checkTabCountHistogram(tabCountHist.snapshot(), [0, 0], "TAB_COUNT telemetry - initial tab counts")
+
+  // Add a new tab and check that the count is right.
+  openedTabs.push(await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank"));
+  checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1], "TAB_COUNT telemetry - opening tabs");
+
+  // Add two new tabs in the same window.
+  openedTabs.push(await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank"));
+  openedTabs.push(await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank"));
+  checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 1, 1], "TAB_COUNT telemetry - opening more tabs");
+
+  // Add a new window and then some tabs in it. A new window starts with one tab.
+  let win = await BrowserTestUtils.openNewBrowserWindow();
+  checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 1, 1, 1], "TAB_COUNT telemetry - opening window");
+
+  openedTabs.push(await BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:blank"));
+  openedTabs.push(await BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:blank"));
+  openedTabs.push(await BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:blank"));
+  checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 1, 1, 1, 1, 1, 1], "TAB_COUNT telemetry - opening more tabs in another window");
+
+  // Remove all the extra windows and tabs.
+  for (let tab of openedTabs) {
+    await BrowserTestUtils.removeTab(tab);
+  }
+  await BrowserTestUtils.closeWindow(win);
+});