Bug 1361855 - Record TAB_COUNT histogram during TabOpen event; r?Gijs
MozReview-Commit-ID: 7ZHakmLZYHu
--- a/browser/modules/BrowserUsageTelemetry.jsm
+++ b/browser/modules/BrowserUsageTelemetry.jsm
@@ -602,16 +602,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 openTab of openedTabs) {
+ await BrowserTestUtils.removeTab(openTab);
+ }
+ await BrowserTestUtils.closeWindow(win);
+});