From 0fab52422c858f9ce5ba11b75d7252cf0d2284a8 Mon Sep 17 00:00:00 2001 From: Noemi Erli Date: Wed, 6 Jan 2021 01:35:37 +0200 Subject: [PATCH] Backed out 2 changesets (bug 1674214) for causing failures in browser_fission_maxOrigins.js CLOSED TREE Backed out changeset 19fbaf9cd86f (bug 1674214) Backed out changeset 7ef22fe8f73a (bug 1674214) --- docshell/test/browser/browser.ini | 1 - .../browser/browser_fission_maxOrigins.js | 195 ------------------ toolkit/modules/BrowserUtils.jsm | 138 ++----------- 3 files changed, 12 insertions(+), 322 deletions(-) delete mode 100644 docshell/test/browser/browser_fission_maxOrigins.js diff --git a/docshell/test/browser/browser.ini b/docshell/test/browser/browser.ini index 20832481d487..12c86f9cf9c5 100644 --- a/docshell/test/browser/browser.ini +++ b/docshell/test/browser/browser.ini @@ -126,7 +126,6 @@ skip-if = (verify && debug && (os == 'win')) [browser_bug92473.js] [browser_data_load_inherit_csp.js] [browser_dataURI_unique_opaque_origin.js] -[browser_fission_maxOrigins.js] [browser_uriFixupIntegration.js] [browser_uriFixupAlternateRedirects.js] support-files = diff --git a/docshell/test/browser/browser_fission_maxOrigins.js b/docshell/test/browser/browser_fission_maxOrigins.js deleted file mode 100644 index 4270de2f59db..000000000000 --- a/docshell/test/browser/browser_fission_maxOrigins.js +++ /dev/null @@ -1,195 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ -"use strict"; - -SimpleTest.requestFlakyTimeout("Need to test expiration timeout"); - -function delay(msec) { - // eslint-disable-next-line mozilla/no-arbitrary-setTimeout - return new Promise(resolve => setTimeout(resolve, msec)); -} - -const ORIGIN_CAP = 5; -const SLIDING_WINDOW_MS = 5000; - -const PREF_ORIGIN_CAP = "fission.experiment.max-origins.origin-cap"; -const PREF_SLIDING_WINDOW_MS = - "fission.experiment.max-origins.sliding-window-ms"; -const PREF_QUALIFIED = "fission.experiment.max-origins.qualified"; -const PREF_LAST_QUALIFIED = "fission.experiment.max-origins.last-qualified"; -const PREF_LAST_DISQUALIFIED = - "fission.experiment.max-origins.last-disqualified"; - -const SITE_ORIGINS = [ - "http://example.com/", - "http://example.org/", - "http://example.net/", - "http://example.tw/", - "http://example.cn/", - "http://example.fi/", - "http://example.in/", - "http://example.lk/", - "http://w3c-test.org/", - "https://www.mozilla.org/", -]; - -function openTab(url) { - return BrowserTestUtils.openNewForegroundTab({ - gBrowser, - url, - waitForStateStop: true, - }); -} - -function assertQualified() { - let qualified = Services.prefs.getBoolPref(PREF_QUALIFIED); - let lastQualified = Services.prefs.getIntPref(PREF_LAST_QUALIFIED); - let lastDisqualified = Services.prefs.getIntPref(PREF_LAST_DISQUALIFIED); - let currentTime = Date.now() / 1000; - - ok(qualified, "Should be qualified"); - ok( - lastQualified > 0, - `Last qualified timestamp (${lastQualified}) should be greater than 0` - ); - ok( - lastQualified < currentTime, - `Last qualified timestamp (${lastQualified}) should be less than the current time (${currentTime})` - ); - ok( - lastQualified > lastDisqualified, - `Last qualified timestamp (${lastQualified}) should be after the last disqualified time (${lastDisqualified})` - ); - - ok( - lastDisqualified < currentTime, - `Last disqualified timestamp (${lastDisqualified}) should be less than the current time (${currentTime})` - ); -} - -function assertDisqualified(opts) { - let qualified = Services.prefs.getBoolPref(PREF_QUALIFIED); - let lastQualified = Services.prefs.getIntPref(PREF_LAST_QUALIFIED, 0); - let lastDisqualified = Services.prefs.getIntPref(PREF_LAST_DISQUALIFIED); - let currentTime = Date.now() / 1000; - - ok(!qualified, "Should not be qualified"); - if (!opts.initialValues) { - ok( - lastQualified > 0, - `Last qualified timestamp (${lastQualified}) should be greater than 0` - ); - } - ok( - lastQualified < currentTime, - `Last qualified timestamp (${lastQualified}) should be less than the current time (${currentTime})` - ); - - ok( - lastDisqualified < currentTime, - `Last disqualified timestamp (${lastDisqualified}) should be less than the current time (${currentTime})` - ); - - ok( - lastDisqualified > 0, - `Last disqualified timestamp (${lastDisqualified}) should be greater than 0` - ); - - if (opts.qualificationPending) { - ok( - lastQualified > lastDisqualified, - `Last qualified timestamp (${lastQualified}) should be after the last disqualified time (${lastDisqualified})` - ); - } else { - ok( - lastDisqualified > lastQualified, - `Last disqualified timestamp (${lastDisqualified}) should be after the last qualified time (${lastQualified})` - ); - } -} - -add_task(async function() { - await SpecialPowers.pushPrefEnv({ - set: [ - [PREF_ORIGIN_CAP, ORIGIN_CAP], - [PREF_SLIDING_WINDOW_MS, SLIDING_WINDOW_MS], - ], - }); - - // Make sure we actually record telemetry for our disqualifying origin - // count. - BrowserUtils.min_interval = 1; - - let tabs = []; - - // Open one initial tab to make sure the origin counting code has had - // a chance to run before checking the initial state. - tabs.push(await openTab("http://mochi.test:8888/")); - - // Make sure the clock has advanced since the qualification timestamp - // was recorded. - await delay(1); - - assertQualified(); - - let lastDisqualified = Services.prefs.getIntPref(PREF_LAST_DISQUALIFIED); - is(lastDisqualified, 0, "Last disqualification timestamp should be 0"); - - info( - `Opening ${SITE_ORIGINS.length} tabs with distinct origins to exceed the cap (${ORIGIN_CAP})` - ); - ok( - SITE_ORIGINS.length > ORIGIN_CAP, - "Should have enough site origins to exceed the origin cap" - ); - tabs.push(...(await Promise.all(SITE_ORIGINS.map(openTab)))); - - assertDisqualified({ qualificationPending: false }); - - info("Close unique-origin tabs"); - await Promise.all(tabs.map(tab => BrowserTestUtils.removeTab(tab))); - - info("Open a new tab to trigger the origin count code once more"); - tabs = [await openTab(SITE_ORIGINS[0])]; - - assertDisqualified({ qualificationPending: true }); - - info( - "Wait long enough to clear the sliding window since last disqualified state" - ); - await delay(SLIDING_WINDOW_MS + 1000); - - info("Open a new tab to trigger the origin count code again"); - tabs.push(await openTab(SITE_ORIGINS[0])); - - assertQualified(); - - info( - "Clear preference values and re-populate the initial value from telemetry" - ); - Services.prefs.clearUserPref(PREF_QUALIFIED); - Services.prefs.clearUserPref(PREF_LAST_QUALIFIED); - Services.prefs.clearUserPref(PREF_LAST_DISQUALIFIED); - BrowserUtils._checkedInitialExperimentQualification = false; - - info("Open a new tab to trigger the origin count code again"); - tabs.push(await openTab(SITE_ORIGINS[0])); - - assertDisqualified({ initialValues: true }); - - info( - "Wait long enough to clear the sliding window since last disqualified state" - ); - await delay(SLIDING_WINDOW_MS + 1000); - - info("Open a new tab to trigger the origin count code again"); - tabs.push(await openTab(SITE_ORIGINS[0])); - - assertQualified(); - - await Promise.all(tabs.map(tab => BrowserTestUtils.removeTab(tab))); - - // Clear the cached recording interval so it resets to the default - // value on the next call. - BrowserUtils.min_interval = null; -}); diff --git a/toolkit/modules/BrowserUtils.jsm b/toolkit/modules/BrowserUtils.jsm index 1020f9ca16d4..ce2cf01a0ea9 100644 --- a/toolkit/modules/BrowserUtils.jsm +++ b/toolkit/modules/BrowserUtils.jsm @@ -17,55 +17,6 @@ ChromeUtils.defineModuleGetter( "resource://gre/modules/PlacesUtils.jsm" ); -// The maximum number of concurrently-loaded origins allowed in order to -// qualify for the Fission rollout experiment. -XPCOMUtils.defineLazyPreferenceGetter( - this, - "fissionExperimentMaxOrigins", - "fission.experiment.max-origins.origin-cap", - 30 -); -// The length of the sliding window during which a user must stay below -// the max origin cap. If the last time a user passed the max origin cap -// fell outside of this window, they will requalify for the experiment. -XPCOMUtils.defineLazyPreferenceGetter( - this, - "fissionExperimentSlidingWindowMS", - "fission.experiment.max-origins.sliding-window-ms", - 7 * 24 * 60 * 60 * 1000 -); -// The pref holding the current qaualification state of the user. If -// true, the user is currently qualified from the experiment. -const FISSION_EXPERIMENT_PREF_QUALIFIED = - "fission.experiment.max-origins.qualified"; -XPCOMUtils.defineLazyPreferenceGetter( - this, - "fissionExperimentQualified", - FISSION_EXPERIMENT_PREF_QUALIFIED, - false -); -// The pref holding the timestamp of the last time we saw an origin -// count below the cap while the user was not currently marked as -// qualified. -const FISSION_EXPERIMENT_PREF_LAST_QUALIFIED = - "fission.experiment.max-origins.last-qualified"; -XPCOMUtils.defineLazyPreferenceGetter( - this, - "fissionExperimentLastQualified", - FISSION_EXPERIMENT_PREF_LAST_QUALIFIED, - 0 -); -// The pref holding the timestamp of the last time we saw an origin -// count exceeding the cap. -const FISSION_EXPERIMENT_PREF_LAST_DISQUALIFIED = - "fission.experiment.max-origins.last-disqualified"; -XPCOMUtils.defineLazyPreferenceGetter( - this, - "fissionExperimentLastDisqualified", - FISSION_EXPERIMENT_PREF_LAST_DISQUALIFIED, - 0 -); - var BrowserUtils = { /** * Prints arguments separated by a space and appends a new line. @@ -931,88 +882,23 @@ var BrowserUtils = { ); } - let originCount = this.computeSiteOriginCount(aWindows, aIsGeckoView); - let histogram = Services.telemetry.getHistogramById( - "FX_NUMBER_OF_UNIQUE_SITE_ORIGINS_ALL_TABS" - ); - // Discard the first load because most of the time the first load only has 1 // tab and 1 window open, so it is useless to report it. - if (!this._lastRecordSiteOrigin) { - this._lastRecordSiteOrigin = currentTime; - } else if (currentTime >= this._lastRecordSiteOrigin + this.min_interval) { - this._lastRecordSiteOrigin = currentTime; - - histogram.add(originCount); + if ( + !this._lastRecordSiteOrigin || + currentTime < this._lastRecordSiteOrigin + this.min_interval + ) { + if (!this._lastRecordSiteOrigin) { + this._lastRecordSiteOrigin = currentTime; + } + return; } - // Update the Fission experiment qualification state based on the - // current origin count: + this._lastRecordSiteOrigin = currentTime; - // If we don't already have a last disqualification timestamp, look - // through the existing histogram values, and use the existing - // maximum value as the initial count. This will prevent us from - // enrolling users in the experiment if they have a history of - // exceeding our origin cap. - if (!this._checkedInitialExperimentQualification) { - this._checkedInitialExperimentQualification = true; - if ( - !Services.prefs.prefHasUserValue( - FISSION_EXPERIMENT_PREF_LAST_DISQUALIFIED - ) - ) { - for (let [bucketStr, entryCount] of Object.entries( - histogram.snapshot().values - )) { - let bucket = Number(bucketStr); - if (bucket > originCount && entryCount > 0) { - originCount = bucket; - } - } - Services.prefs.setIntPref(FISSION_EXPERIMENT_PREF_LAST_DISQUALIFIED, 0); - } - } - - let currentTimeSec = currentTime / 1000; - if (originCount < fissionExperimentMaxOrigins) { - let lastDisqualified = fissionExperimentLastDisqualified; - let lastQualified = fissionExperimentLastQualified; - - // If the last time we saw a qualifying origin count was earlier - // than the last time we say a disqualifying count, update any - // existing last disqualified timestamp to just before now, on the - // basis that our origin count has probably just fallen below the - // cap. - if (lastDisqualified > 0 && lastQualified <= lastDisqualified) { - Services.prefs.setIntPref( - FISSION_EXPERIMENT_PREF_LAST_DISQUALIFIED, - currentTimeSec - 1 - ); - } - - if (!fissionExperimentQualified) { - Services.prefs.setIntPref( - FISSION_EXPERIMENT_PREF_LAST_QUALIFIED, - currentTimeSec - ); - - // We have a qualifying origin count now. If the last time we were - // disqualified was prior to the start of our current sliding - // window, re-qualify the user. - if ( - currentTimeSec - lastDisqualified >= - fissionExperimentSlidingWindowMS / 1000 - ) { - Services.prefs.setBoolPref(FISSION_EXPERIMENT_PREF_QUALIFIED, true); - } - } - } else { - Services.prefs.setIntPref( - FISSION_EXPERIMENT_PREF_LAST_DISQUALIFIED, - currentTimeSec - ); - Services.prefs.setBoolPref(FISSION_EXPERIMENT_PREF_QUALIFIED, false); - } + Services.telemetry + .getHistogramById("FX_NUMBER_OF_UNIQUE_SITE_ORIGINS_ALL_TABS") + .add(this.computeSiteOriginCount(aWindows, aIsGeckoView)); }, /**