Bug 1361855 - Update tab count on page load and other URL changes; r?Gijs draft
authorLie Ryan <lie.1296@gmail.com>
Sun, 11 Jun 2017 19:28:20 +0000
changeset 647634 77f0130b6835cf6ca400fccee816a1b6959adfec
parent 647633 70f9e6205b028f9e3f1797bc5a2cf8d9d0fc61ad
child 647635 9c462fa1024a1ce285c9051477c666a6bdb0d6d1
push id74488
push userbmo:lie.1296@gmail.com
push dateWed, 16 Aug 2017 17:50:44 +0000
reviewersGijs
bugs1361855
milestone57.0a1
Bug 1361855 - Update tab count on page load and other URL changes; r?Gijs MozReview-Commit-ID: gKqdEHI3M1
browser/modules/BrowserUsageTelemetry.jsm
browser/modules/test/browser/browser_UsageTelemetry.js
--- a/browser/modules/BrowserUsageTelemetry.jsm
+++ b/browser/modules/BrowserUsageTelemetry.jsm
@@ -192,16 +192,19 @@ let URICountListener = {
 
     if (!this.isHttpURI(uri)) {
       return;
     }
 
     // Update the URI counts.
     Services.telemetry.scalarAdd(TOTAL_URI_COUNT_SCALAR_NAME, 1);
 
+    // Update tab count
+    BrowserUsageTelemetry._recordTabCount();
+
     // We only want to count the unique domains up to MAX_UNIQUE_VISITED_DOMAINS.
     if (this._domainSet.size == MAX_UNIQUE_VISITED_DOMAINS) {
       return;
     }
 
     // Unique domains should be aggregated by (eTLD + 1): x.test.com and y.test.com
     // are counted once as test.com.
     try {
--- a/browser/modules/test/browser/browser_UsageTelemetry.js
+++ b/browser/modules/test/browser/browser_UsageTelemetry.js
@@ -278,28 +278,34 @@ add_task(async function test_tabsHistogr
   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.
+  // Open a different page and check the counts.
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank");
+  openedTabs.push(tab);
+  await BrowserTestUtils.loadURI(tab.linkedBrowser, "http://example.com/");
+  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+  checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 2], "TAB_COUNT telemetry - loading page");
+
+  // Open another tab
   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");
+  checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 2, 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");
+  checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 2, 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");
+  checkTabCountHistogram(tabCountHist.snapshot(), [0, 0, 1, 2, 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);
 });