From 303eae9cecfd76668b07f9206fbdc048b1d0ef31 Mon Sep 17 00:00:00 2001 From: Alessio Placitelli Date: Fri, 2 Sep 2016 03:44:00 -0400 Subject: [PATCH] Bug 1288709 - Split the browser_UsageTelemetry.js test. r=gijs MozReview-Commit-ID: IykhSB7RtSH --HG-- rename : browser/modules/test/browser_UsageTelemetry.js => browser/modules/test/browser_UsageTelemetry_private_and_restore.js --- browser/modules/test/browser.ini | 1 + .../modules/test/browser_UsageTelemetry.js | 80 ----------------- ...wser_UsageTelemetry_private_and_restore.js | 88 +++++++++++++++++++ 3 files changed, 89 insertions(+), 80 deletions(-) create mode 100644 browser/modules/test/browser_UsageTelemetry_private_and_restore.js diff --git a/browser/modules/test/browser.ini b/browser/modules/test/browser.ini index fb926c445c07..13cb18d719eb 100644 --- a/browser/modules/test/browser.ini +++ b/browser/modules/test/browser.ini @@ -24,4 +24,5 @@ support-files = [browser_taskbar_preview.js] skip-if = os != "win" [browser_UsageTelemetry.js] +[browser_UsageTelemetry_private_and_restore.js] [browser_urlBar_zoom.js] diff --git a/browser/modules/test/browser_UsageTelemetry.js b/browser/modules/test/browser_UsageTelemetry.js index ff437c92a1ee..ab172fdbea68 100644 --- a/browser/modules/test/browser_UsageTelemetry.js +++ b/browser/modules/test/browser_UsageTelemetry.js @@ -44,15 +44,6 @@ function browserLocationChanged(browser) { }); } -function promiseBrowserStateRestored() { - return new Promise(resolve => { - Services.obs.addObserver(function observer(aSubject, aTopic) { - Services.obs.removeObserver(observer, "sessionstore-browser-state-restored"); - resolve(); - }, "sessionstore-browser-state-restored", false); - }); -} - /** * An helper that checks the value of a scalar if it's expected to be > 0, * otherwise makes sure that the scalar it's not reported. @@ -251,74 +242,3 @@ add_task(function* test_URIAndDomainCounts() { yield BrowserTestUtils.removeTab(firstTab); yield BrowserTestUtils.closeWindow(newWin); }); - -add_task(function* test_privateMode() { - // Let's reset the counts. - Services.telemetry.clearScalars(); - - // Open a private window and load a website in it. - let privateWin = yield BrowserTestUtils.openNewBrowserWindow({private: true}); - yield BrowserTestUtils.loadURI(privateWin.gBrowser.selectedBrowser, "http://example.com/"); - yield BrowserTestUtils.browserLoaded(privateWin.gBrowser.selectedBrowser); - - // Check that tab and window count is recorded. - const scalars = - Services.telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN); - - ok(!(TOTAL_URI_COUNT in scalars), "We should not track URIs in private mode."); - ok(!(UNIQUE_DOMAINS_COUNT in scalars), "We should not track unique domains in private mode."); - is(scalars[TAB_EVENT_COUNT], 1, "The number of open tab event count must match the expected value."); - is(scalars[MAX_CONCURRENT_TABS], 2, "The maximum tab count must match the expected value."); - is(scalars[WINDOW_OPEN_COUNT], 1, "The number of window open event count must match the expected value."); - is(scalars[MAX_CONCURRENT_WINDOWS], 2, "The maximum window count must match the expected value."); - - // Clean up. - yield BrowserTestUtils.closeWindow(privateWin); -}); - -add_task(function* test_sessionRestore() { - const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; - Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); - registerCleanupFunction(() => { - Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); - }); - - // Let's reset the counts. - Services.telemetry.clearScalars(); - - // The first window will be put into the already open window and the second - // window will be opened with _openWindowWithState, which is the source of the problem. - const state = { - windows: [ - { - tabs: [ - { entries: [{ url: "http://example.org" }], extData: { "uniq": 3785 } } - ], - selected: 1 - } - ] - }; - - // Save the current session. - let SessionStore = - Cu.import("resource:///modules/sessionstore/SessionStore.jsm", {}).SessionStore; - let backupState = SessionStore.getBrowserState(); - - // Load the custom state and wait for SSTabRestored, as we want to make sure - // that the URI counting code was hit. - let tabRestored = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "SSTabRestored"); - SessionStore.setBrowserState(JSON.stringify(state)); - yield tabRestored; - - // Check that the URI is not recorded. - const scalars = - Services.telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN); - - ok(!(TOTAL_URI_COUNT in scalars), "We should not track URIs from restored sessions."); - ok(!(UNIQUE_DOMAINS_COUNT in scalars), "We should not track unique domains from restored sessions."); - - // Restore the original session and cleanup. - let sessionRestored = promiseBrowserStateRestored(); - SessionStore.setBrowserState(JSON.stringify(state)); - yield sessionRestored; -}); diff --git a/browser/modules/test/browser_UsageTelemetry_private_and_restore.js b/browser/modules/test/browser_UsageTelemetry_private_and_restore.js new file mode 100644 index 000000000000..2b9c2e9b316e --- /dev/null +++ b/browser/modules/test/browser_UsageTelemetry_private_and_restore.js @@ -0,0 +1,88 @@ +"use strict"; + +const MAX_CONCURRENT_TABS = "browser.engagement.max_concurrent_tab_count"; +const TAB_EVENT_COUNT = "browser.engagement.tab_open_event_count"; +const MAX_CONCURRENT_WINDOWS = "browser.engagement.max_concurrent_window_count"; +const WINDOW_OPEN_COUNT = "browser.engagement.window_open_event_count"; +const TOTAL_URI_COUNT = "browser.engagement.total_uri_count"; +const UNIQUE_DOMAINS_COUNT = "browser.engagement.unique_domains_count"; + +function promiseBrowserStateRestored() { + return new Promise(resolve => { + Services.obs.addObserver(function observer(aSubject, aTopic) { + Services.obs.removeObserver(observer, "sessionstore-browser-state-restored"); + resolve(); + }, "sessionstore-browser-state-restored", false); + }); +} + +add_task(function* test_privateMode() { + // Let's reset the counts. + Services.telemetry.clearScalars(); + + // Open a private window and load a website in it. + let privateWin = yield BrowserTestUtils.openNewBrowserWindow({private: true}); + yield BrowserTestUtils.loadURI(privateWin.gBrowser.selectedBrowser, "http://example.com/"); + yield BrowserTestUtils.browserLoaded(privateWin.gBrowser.selectedBrowser); + + // Check that tab and window count is recorded. + const scalars = + Services.telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN); + + ok(!(TOTAL_URI_COUNT in scalars), "We should not track URIs in private mode."); + ok(!(UNIQUE_DOMAINS_COUNT in scalars), "We should not track unique domains in private mode."); + is(scalars[TAB_EVENT_COUNT], 1, "The number of open tab event count must match the expected value."); + is(scalars[MAX_CONCURRENT_TABS], 2, "The maximum tab count must match the expected value."); + is(scalars[WINDOW_OPEN_COUNT], 1, "The number of window open event count must match the expected value."); + is(scalars[MAX_CONCURRENT_WINDOWS], 2, "The maximum window count must match the expected value."); + + // Clean up. + yield BrowserTestUtils.closeWindow(privateWin); +}); + +add_task(function* test_sessionRestore() { + const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; + Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); + registerCleanupFunction(() => { + Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); + }); + + // Let's reset the counts. + Services.telemetry.clearScalars(); + + // The first window will be put into the already open window and the second + // window will be opened with _openWindowWithState, which is the source of the problem. + const state = { + windows: [ + { + tabs: [ + { entries: [{ url: "http://example.org" }], extData: { "uniq": 3785 } } + ], + selected: 1 + } + ] + }; + + // Save the current session. + let SessionStore = + Cu.import("resource:///modules/sessionstore/SessionStore.jsm", {}).SessionStore; + let backupState = SessionStore.getBrowserState(); + + // Load the custom state and wait for SSTabRestored, as we want to make sure + // that the URI counting code was hit. + let tabRestored = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "SSTabRestored"); + SessionStore.setBrowserState(JSON.stringify(state)); + yield tabRestored; + + // Check that the URI is not recorded. + const scalars = + Services.telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN); + + ok(!(TOTAL_URI_COUNT in scalars), "We should not track URIs from restored sessions."); + ok(!(UNIQUE_DOMAINS_COUNT in scalars), "We should not track unique domains from restored sessions."); + + // Restore the original session and cleanup. + let sessionRestored = promiseBrowserStateRestored(); + SessionStore.setBrowserState(JSON.stringify(state)); + yield sessionRestored; +});