Bug 1379226 - Add telemetry probes to measure use of session restore button in tab bar. r=gijs draft
authorErica Wright <ewright@mozilla.com>
Tue, 11 Jul 2017 16:13:56 -0400
changeset 614581 086fbd125f50e84f2931d3c3b0237978dc4037c5
parent 614544 462d7561089c98e33382384896434861ad7bc491
child 638915 e3777a7607461c6aa5d199a464ac7e4239b107ae
push id70067
push userbmo:ewright@mozilla.com
push dateMon, 24 Jul 2017 20:35:43 +0000
reviewersgijs
bugs1379226
milestone56.0a1
Bug 1379226 - Add telemetry probes to measure use of session restore button in tab bar. r=gijs MozReview-Commit-ID: 2u5CtatqBBT
browser/app/profile/firefox.js
browser/base/content/browser.js
browser/components/sessionstore/SessionStore.jsm
testing/firefox-ui/tests/functional/sessionstore/test_tabbar_session_restore_button.py
toolkit/components/telemetry/Scalars.yaml
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -469,20 +469,22 @@ pref("browser.tabs.loadDivertedInBackgro
 pref("browser.tabs.loadBookmarksInBackground", false);
 pref("browser.tabs.tabClipWidth", 140);
 #ifdef UNIX_BUT_NOT_MAC
 pref("browser.tabs.drawInTitlebar", false);
 #else
 pref("browser.tabs.drawInTitlebar", true);
 #endif
 
-// false - disable the tabbar session restore button
-// true - enable the tabbar session restore button
-// To be enabled with shield
-pref("browser.tabs.restorebutton", false);
+// 0 - Disable the tabbar session restore button.
+// 1 - Enable the tabbar session restore button.
+// 2 - Control group. The tabbar session restore button is disabled,
+// but we will record data on other session restore usage.
+// To be enabled with shield.
+pref("browser.tabs.restorebutton", 0);
 
 // When tabs opened by links in other tabs via a combination of
 // browser.link.open_newwindow being set to 3 and target="_blank" etc are
 // closed:
 // true   return to the tab that opened this tab (its owner)
 // false  return to the adjacent tab (old default)
 pref("browser.tabs.selectOwnerOnClose", true);
 
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -8317,25 +8317,32 @@ function switchToTabHavingURI(aURI, aOpe
       openUILinkIn(aURI.spec, "tab", aOpenParams);
   }
 
   return false;
 }
 
 var RestoreLastSessionObserver = {
   init() {
+    let browser_tabs_restorebutton_pref = Services.prefs.getIntPref("browser.tabs.restorebutton");
+    Services.telemetry.scalarSet("browser.session.restore.browser_tabs_restorebutton", browser_tabs_restorebutton_pref);
+    Services.telemetry.scalarSet("browser.session.restore.browser_startup_page", Services.prefs.getIntPref("browser.startup.page"));
     if (SessionStore.canRestoreLastSession &&
         !PrivateBrowsingUtils.isWindowPrivate(window)) {
-      if (Services.prefs.getBoolPref("browser.tabs.restorebutton")) {
+      if (browser_tabs_restorebutton_pref == 1) {
         let {restoreTabsButton, restoreTabsButtonWrapperWidth} = gBrowser.tabContainer;
         let restoreTabsButtonWrapper = restoreTabsButton.parentNode;
         restoreTabsButtonWrapper.setAttribute("session-exists", "true");
         gBrowser.tabContainer.updateSessionRestoreVisibility();
         restoreTabsButton.style.maxWidth = `${restoreTabsButtonWrapperWidth}px`;
         gBrowser.tabContainer.addEventListener("TabOpen", this);
+        Services.telemetry.scalarSet("browser.session.restore.tabbar_restore_available", true);
+        restoreTabsButton.addEventListener("click", () => {
+          Services.telemetry.scalarSet("browser.session.restore.tabbar_restore_clicked", true);
+        });
       }
       Services.obs.addObserver(this, "sessionstore-last-session-cleared", true);
       goSetCommandEnabled("Browser:RestoreLastSession", true);
     }
   },
 
   handleEvent(event) {
     switch (event.type) {
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -3409,16 +3409,20 @@ var SessionStoreInternal = {
     if (winData.tabs.length) {
       this.restoreTabs(aWindow, tabs, winData.tabs, selectTab);
     }
 
     // set smoothScroll back to the original value
     tabstrip.smoothScroll = smoothScroll;
 
     TelemetryStopwatch.finish("FX_SESSION_RESTORE_RESTORE_WINDOW_MS");
+    if (Services.prefs.getIntPref("browser.tabs.restorebutton") != 0 ) {
+      Services.telemetry.scalarAdd("browser.session.restore.number_of_tabs", winData.tabs.length);
+      Services.telemetry.scalarAdd("browser.session.restore.number_of_win", 1);
+    }
 
     this._setWindowStateReady(aWindow);
 
     this._sendWindowRestoredNotification(aWindow);
 
     Services.obs.notifyObservers(aWindow, NOTIFY_SINGLE_WINDOW_RESTORED);
 
     this._sendRestoreCompletedNotifications();
--- a/testing/firefox-ui/tests/functional/sessionstore/test_tabbar_session_restore_button.py
+++ b/testing/firefox-ui/tests/functional/sessionstore/test_tabbar_session_restore_button.py
@@ -2,19 +2,19 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 from firefox_puppeteer import PuppeteerMixin
 from marionette_harness import MarionetteTestCase
 from marionette_driver import Wait
 
 
 class TestBaseTabbarSessionRestoreButton(PuppeteerMixin, MarionetteTestCase):
-    def setUp(self, prefValue=True):
+    def setUp(self, restore_button_pref=1):
         super(TestBaseTabbarSessionRestoreButton, self).setUp()
-        self.marionette.enforce_gecko_prefs({'browser.tabs.restorebutton': prefValue})
+        self.marionette.enforce_gecko_prefs({'browser.tabs.restorebutton': restore_button_pref})
 
         # Each list element represents a window of tabs loaded at
         # some testing URL, the URLS are arbitrary.
         self.test_windows = set([
             (self.marionette.absolute_url('layout/mozilla_projects.html'),
              self.marionette.absolute_url('layout/mozilla.html'),
              self.marionette.absolute_url('layout/mozilla_mission.html')),
         ])
@@ -91,16 +91,16 @@ class TestTabbarSessionRestoreButton(Tes
 
         # After clicking the button to restore the session,
         # there is more than one tab.
         self.assertTrue(len(self.puppeteer.windows.current.tabbar.tabs) > 1)
 
 
 class TestNoTabbarSessionRestoreButton(TestBaseTabbarSessionRestoreButton):
     def setUp(self):
-        super(TestNoTabbarSessionRestoreButton, self).setUp(False)
+        super(TestNoTabbarSessionRestoreButton, self).setUp(restore_button_pref=0)
 
     def test_pref_off_button_does_not_show(self):
         wrapper = self.puppeteer.windows.current.tabbar.restore_tabs_button_wrapper
 
         # A session-exists attribute is not on the button,
         # since the button will never show itself with the pref off.
         self.assertEqual(wrapper.get_attribute('session-exists'), '')
--- a/toolkit/components/telemetry/Scalars.yaml
+++ b/toolkit/components/telemetry/Scalars.yaml
@@ -272,16 +272,100 @@ browser.usage:
     kind: uint
     notification_emails:
       - bsmedberg@mozilla.com
     release_channel_collection: opt-out
     record_in_processes:
       - 'main'
       - 'content'
 
+# The following section contains the session restore scalars.
+browser.session.restore:
+  number_of_win:
+    bug_numbers:
+      - 1379226
+    description: The count of windows open after a session has been restored.
+    expires: never
+    kind: uint
+    notification_emails:
+      - bwinton@mozilla.com
+    release_channel_collection: opt-out
+    record_in_processes:
+      - 'main'
+
+  number_of_tabs:
+    bug_numbers:
+      - 1379226
+    description: The count of tabs open after a session has been restored.
+    expires: never
+    kind: uint
+    notification_emails:
+      - bwinton@mozilla.com
+    release_channel_collection: opt-out
+    record_in_processes:
+      - 'main'
+
+  tabbar_restore_available:
+    bug_numbers:
+      - 1379226
+    description: >
+      Recorded on startup. Boolean stating whether the tabbar session
+      restore button was ever available.
+    expires: never
+    kind: boolean
+    notification_emails:
+      - bwinton@mozilla.com
+    release_channel_collection: opt-out
+    record_in_processes:
+      - 'main'
+
+  tabbar_restore_clicked:
+    bug_numbers:
+      - 1379226
+    description: >
+      Recorded on click event. Boolean stating if the session restore button
+      was clicked.
+    expires: never
+    kind: boolean
+    notification_emails:
+      - bwinton@mozilla.com
+    release_channel_collection: opt-out
+    record_in_processes:
+      - 'main'
+
+  browser_startup_page:
+    bug_numbers:
+      - 1379226
+    description: >
+      The value of the browser.startup.page pref.
+      This pref restores the tabs and windows automatically when set to 3.
+    expires: never
+    kind: uint
+    notification_emails:
+      - bwinton@mozilla.com
+    release_channel_collection: opt-out
+    record_in_processes:
+      - 'main'
+
+  browser_tabs_restorebutton:
+    bug_numbers:
+      - 1379226
+    description: >
+      The value of the browser.tabs.restorebutton pref.
+      0 - the user is not a part of the experiment
+      1 - the user is a part of the experiment
+      2 - the user is part of the control group
+    expires: never
+    kind: uint
+    notification_emails:
+      - bwinton@mozilla.com
+    release_channel_collection: opt-out
+    record_in_processes:
+      - 'main'
+
 # This section is for probes used to measure use of the Webextensions storage.sync API.
 storage.sync.api.usage:
   extensions_using:
     bug_numbers:
       - 1328974
     description: >
       The count of webextensions that have data stored in the chrome.storage.sync API.
       This includes extensions that have not used the storage.sync API this session.