Bug 1642723 - Pref-off automatic TRR-selection by default. r=johannh, a=RyanVM FIREFOX_77_0_1_BUILD1 FIREFOX_77_0_1_RELEASE
authorNihanth Subramanya <nhnt11@gmail.com>
Tue, 02 Jun 2020 18:40:27 +0000
changeset 595169 b8d272601020250ac2897e113b3fc3b53b72cf4b
parent 595168 74c70d8f058a8359bb85fa437dae6bee90735347
child 595170 8c02d8ff3f6d73d9a253a04d480fbb39d2b5e9d5
push id2348
push userryanvm@gmail.com
push dateTue, 02 Jun 2020 22:27:27 +0000
treeherdermozilla-release@b8d272601020 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh, RyanVM
bugs1642723
milestone77.0.1
Bug 1642723 - Pref-off automatic TRR-selection by default. r=johannh, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D77869
browser/app/profile/firefox.js
browser/extensions/doh-rollout/experiments/trrselect/api.js
browser/extensions/doh-rollout/test/browser/browser.ini
browser/extensions/doh-rollout/test/browser/browser_trrSelection_disable.js
browser/extensions/doh-rollout/test/browser/head.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1820,16 +1820,20 @@ pref("extensions.screenshots.disabled", 
 pref("extensions.screenshots.upload-disabled", false);
 
 // DoH Rollout: the earliest date of profile creation for which we don't need
 // to show the doorhanger. This is when the version of the privacy statement
 // that includes DoH went live - Oct 31, 2019. This has to be a string because
 // the number is outside the signed 32-bit integer range.
 pref("doh-rollout.profileCreationThreshold", "1572476400000");
 
+// DoH Rollout: whether to enable automatic performance-based TRR-selection.
+// This pref is controlled by a Normandy rollout so we don't overload providers.
+pref("doh-rollout.trr-selection.enabled", false);
+
 // URL for Learn More link for browser error logging in preferences
 pref("browser.chrome.errorReporter.infoURL",
      "https://support.mozilla.org/1/firefox/%VERSION%/%OS%/%LOCALE%/nightly-error-collection");
 
 // Normandy client preferences
 pref("app.normandy.api_url", "https://normandy.cdn.mozilla.net/api/v1");
 pref("app.normandy.dev_mode", false);
 pref("app.normandy.enabled", true);
--- a/browser/extensions/doh-rollout/experiments/trrselect/api.js
+++ b/browser/extensions/doh-rollout/experiments/trrselect/api.js
@@ -5,31 +5,36 @@
 "use strict";
 
 /* global Cc, Ci, ExtensionAPI, TRRRacer  */
 
 ChromeUtils.import("resource://gre/modules/Services.jsm", this);
 ChromeUtils.import("resource:///modules/TRRPerformance.jsm", this);
 
 const kDryRunResultPref = "doh-rollout.trr-selection.dry-run-result";
+const kEnabledPref = "doh-rollout.trr-selection.enabled";
 
 const TRRSELECT_TELEMETRY_CATEGORY = "security.doh.trrPerformance";
 
 Services.telemetry.setEventRecordingEnabled(TRRSELECT_TELEMETRY_CATEGORY, true);
 
 this.trrselect = class trrselect extends ExtensionAPI {
   getAPI() {
     return {
       experiments: {
         trrselect: {
           async dryRun() {
             if (Services.prefs.prefHasUserValue(kDryRunResultPref)) {
               return;
             }
 
+            if (!Services.prefs.getBoolPref(kEnabledPref, false)) {
+              return;
+            }
+
             let setDryRunResultAndRecordTelemetry = trr => {
               Services.prefs.setCharPref(kDryRunResultPref, trr);
               Services.telemetry.recordEvent(
                 TRRSELECT_TELEMETRY_CATEGORY,
                 "trrselect",
                 "dryrunresult",
                 trr.substring(0, 40) // Telemetry payload max length
               );
--- a/browser/extensions/doh-rollout/test/browser/browser.ini
+++ b/browser/extensions/doh-rollout/test/browser/browser.ini
@@ -5,10 +5,11 @@ skip-if = debug # Bug 1548006 - reloadin
 [browser_cleanFlow.js]
 [browser_dirtyEnable.js]
 [browser_doorhangerUserReject.js]
 [browser_doorhanger_newProfile.js]
 [browser_policyOverride.js]
 skip-if = (!debug && bits == 64) #Bug 1605297
 [browser_rollback.js]
 skip-if = asan && !debug && os == 'linux' && bits == 64 && os_version == '18.04' # Bug 1613994 for linux1804
+[browser_trrSelection_disable.js]
 [browser_userInterference.js]
 skip-if = asan && !debug && os == 'linux' && bits == 64 && os_version == '18.04' # Bug 1615815 for linux1804
new file mode 100644
--- /dev/null
+++ b/browser/extensions/doh-rollout/test/browser/browser_trrSelection_disable.js
@@ -0,0 +1,70 @@
+"use strict";
+
+add_task(setup);
+
+add_task(async function testTrrSelectionDisable() {
+  // Set up a passing environment and enable DoH.
+  Preferences.set(prefs.DOH_TRR_SELECT_ENABLED_PREF, false);
+  setPassingHeuristics();
+  let promise = waitForDoorhanger();
+  Preferences.set(prefs.DOH_ENABLED_PREF, true);
+  await BrowserTestUtils.waitForCondition(() => {
+    return Preferences.get(prefs.DOH_SELF_ENABLED_PREF);
+  });
+  is(Preferences.get(prefs.DOH_SELF_ENABLED_PREF), true, "Breadcrumb saved.");
+  is(
+    Preferences.get(prefs.DOH_TRR_SELECT_DRY_RUN_RESULT_PREF),
+    undefined,
+    "TRR selection dry run not performed."
+  );
+  ensureNoTRRSelectionTelemetry();
+
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, EXAMPLE_URL);
+  let panel = await promise;
+  is(
+    Preferences.get(prefs.DOH_DOORHANGER_SHOWN_PREF),
+    undefined,
+    "Doorhanger shown pref undefined before user interaction."
+  );
+
+  // Click the doorhanger's "accept" button.
+  let button = panel.querySelector(".popup-notification-primary-button");
+  promise = BrowserTestUtils.waitForEvent(panel, "popuphidden");
+  EventUtils.synthesizeMouseAtCenter(button, {});
+  await promise;
+
+  await ensureTRRMode(2);
+  await checkHeuristicsTelemetry("enable_doh", "startup");
+
+  await BrowserTestUtils.waitForCondition(() => {
+    return Preferences.get(prefs.DOH_DOORHANGER_SHOWN_PREF);
+  });
+  is(
+    Preferences.get(prefs.DOH_DOORHANGER_SHOWN_PREF),
+    true,
+    "Doorhanger shown pref saved."
+  );
+  is(
+    Preferences.get(prefs.DOH_DOORHANGER_USER_DECISION_PREF),
+    "UIOk",
+    "Doorhanger decision saved."
+  );
+  is(
+    Preferences.get(prefs.DOH_SELF_ENABLED_PREF),
+    true,
+    "Breadcrumb not cleared."
+  );
+
+  BrowserTestUtils.removeTab(tab);
+
+  // Restart the add-on for good measure.
+  await restartAddon();
+  ensureNoTRRSelectionTelemetry();
+  is(
+    Preferences.get(prefs.DOH_TRR_SELECT_DRY_RUN_RESULT_PREF),
+    undefined,
+    "TRR selection dry run not performed."
+  );
+  await ensureNoTRRModeChange(2);
+  await checkHeuristicsTelemetry("enable_doh", "startup");
+});
--- a/browser/extensions/doh-rollout/test/browser/head.js
+++ b/browser/extensions/doh-rollout/test/browser/head.js
@@ -27,16 +27,17 @@ const prefs = {
   DOH_PREVIOUS_TRR_MODE_PREF: "doh-rollout.previous.trr.mode",
   DOH_DOORHANGER_SHOWN_PREF: "doh-rollout.doorhanger-shown",
   DOH_DOORHANGER_USER_DECISION_PREF: "doh-rollout.doorhanger-decision",
   DOH_DISABLED_PREF: "doh-rollout.disable-heuristics",
   DOH_SKIP_HEURISTICS_PREF: "doh-rollout.skipHeuristicsCheck",
   DOH_DONE_FIRST_RUN_PREF: "doh-rollout.doneFirstRun",
   DOH_BALROG_MIGRATION_PREF: "doh-rollout.balrog-migration-done",
   DOH_DEBUG_PREF: "doh-rollout.debug",
+  DOH_TRR_SELECT_ENABLED_PREF: "doh-rollout.trr-selection.enabled",
   DOH_TRR_SELECT_DRY_RUN_RESULT_PREF:
     "doh-rollout.trr-selection.dry-run-result",
   MOCK_HEURISTICS_PREF: "doh-rollout.heuristics.mockValues",
   PROFILE_CREATION_THRESHOLD_PREF: "doh-rollout.profileCreationThreshold",
 };
 
 const fakePassingHeuristics = JSON.stringify({
   google: "enable_doh",
@@ -68,16 +69,20 @@ async function setup() {
   Services.telemetry.canRecordExtended = true;
   Services.telemetry.clearEvents();
 
   // Set the profile creation threshold to very far in the future by defualt,
   // so that we can test the doorhanger. browser_doorhanger_newProfile.js
   // overrides this.
   Preferences.set(prefs.PROFILE_CREATION_THRESHOLD_PREF, "99999999999999");
 
+  // Enable trr selection for tests. This is off by default so it can be
+  // controlled via Normandy.
+  Preferences.set(prefs.DOH_TRR_SELECT_ENABLED_PREF, true);
+
   registerCleanupFunction(async () => {
     Services.telemetry.canRecordExtended = oldCanRecord;
     Services.telemetry.clearEvents();
     await resetPrefsAndRestartAddon();
   });
 }
 
 async function checkTRRSelectionTelemetry() {