Bug 1613994 - Wait for state telemetry event after resetting enabled pref to ensure add-on has a chance to react. r=dragana, a=test-only
authorNihanth Subramanya <nhnt11@gmail.com>
Mon, 10 Feb 2020 08:07:26 +0000
changeset 574974 5c213138b8bc9ac506f79abe88a00fd1bac8d8c1
parent 574973 1d1b989333f12ae74ce5c6cdfb5c52ce1cf5ef9c
child 574975 ae8d2f148d7d2d30ddbc42ea8404ed4c5613fb2b
push id2265
push userryanvm@gmail.com
push dateThu, 13 Feb 2020 19:21:01 +0000
treeherdermozilla-release@ae8d2f148d7d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana, test-only
bugs1613994
milestone73.0.1
Bug 1613994 - Wait for state telemetry event after resetting enabled pref to ensure add-on has a chance to react. r=dragana, a=test-only Differential Revision: https://phabricator.services.mozilla.com/D62102
browser/extensions/doh-rollout/background.js
browser/extensions/doh-rollout/test/browser/browser_rollback.js
browser/extensions/doh-rollout/test/browser/head.js
--- a/browser/extensions/doh-rollout/background.js
+++ b/browser/extensions/doh-rollout/background.js
@@ -68,31 +68,35 @@ const DOH_DEBUG_PREF = "doh-rollout.debu
 const stateManager = {
   async setState(state) {
     log("setState: ", state);
 
     switch (state) {
       case "uninstalled":
         break;
       case "disabled":
-        rollout.setSetting(TRR_MODE_PREF, 0);
+        await rollout.setSetting(TRR_MODE_PREF, 0);
         break;
       case "manuallyDisabled":
-        browser.experiments.preferences.clearUserPref(DOH_SELF_ENABLED_PREF);
+        await browser.experiments.preferences.clearUserPref(
+          DOH_SELF_ENABLED_PREF
+        );
         break;
       case "UIOk":
-        rollout.setSetting(DOH_SELF_ENABLED_PREF, true);
+        await rollout.setSetting(DOH_SELF_ENABLED_PREF, true);
         break;
       case "enabled":
-        rollout.setSetting(TRR_MODE_PREF, 2);
-        rollout.setSetting(DOH_SELF_ENABLED_PREF, true);
+        await rollout.setSetting(TRR_MODE_PREF, 2);
+        await rollout.setSetting(DOH_SELF_ENABLED_PREF, true);
         break;
       case "UIDisabled":
-        rollout.setSetting(TRR_MODE_PREF, 5);
-        browser.experiments.preferences.clearUserPref(DOH_SELF_ENABLED_PREF);
+        await rollout.setSetting(TRR_MODE_PREF, 5);
+        await browser.experiments.preferences.clearUserPref(
+          DOH_SELF_ENABLED_PREF
+        );
         break;
     }
 
     await browser.experiments.heuristics.sendStatePing(state);
     await stateManager.rememberTRRMode();
   },
 
   async rememberTRRMode() {
--- a/browser/extensions/doh-rollout/test/browser/browser_rollback.js
+++ b/browser/extensions/doh-rollout/test/browser/browser_rollback.js
@@ -62,16 +62,17 @@ add_task(async function testRollback() {
   // Trigger another network change.
   simulateNetworkChange();
   await ensureNoTRRModeChange(0);
   await checkHeuristicsTelemetry("disable_doh", "netchange");
 
   // Rollback!
   setPassingHeuristics();
   Preferences.reset(prefs.DOH_ENABLED_PREF);
+  await waitForStateTelemetry();
   await ensureTRRMode(0);
   await ensureNoHeuristicsTelemetry();
   simulateNetworkChange();
   await ensureNoTRRModeChange(0);
   await ensureNoHeuristicsTelemetry();
 
   // Re-enable.
   Preferences.set(prefs.DOH_ENABLED_PREF, true);
@@ -82,16 +83,17 @@ add_task(async function testRollback() {
   // Change the environment to failing and simulate a network change.
   setFailingHeuristics();
   simulateNetworkChange();
   await ensureTRRMode(0);
   await checkHeuristicsTelemetry("disable_doh", "netchange");
 
   // Rollback again for good measure! This time with failing heuristics.
   Preferences.reset(prefs.DOH_ENABLED_PREF);
+  await waitForStateTelemetry();
   await ensureNoTRRModeChange(0);
   await ensureNoHeuristicsTelemetry();
   simulateNetworkChange();
   await ensureNoTRRModeChange(0);
   await ensureNoHeuristicsTelemetry();
 
   // Re-enable.
   Preferences.set(prefs.DOH_ENABLED_PREF, true);
@@ -102,16 +104,17 @@ add_task(async function testRollback() {
   // Change the environment to passing and simulate a network change.
   setPassingHeuristics();
   simulateNetworkChange();
   await ensureTRRMode(2);
   await checkHeuristicsTelemetry("enable_doh", "netchange");
 
   // Rollback again, this time with TRR mode set to 2 prior to doing so.
   Preferences.reset(prefs.DOH_ENABLED_PREF);
+  await waitForStateTelemetry();
   await ensureTRRMode(0);
   await ensureNoHeuristicsTelemetry();
   simulateNetworkChange();
   await ensureNoTRRModeChange(0);
   await ensureNoHeuristicsTelemetry();
 
   // Re-enable.
   Preferences.set(prefs.DOH_ENABLED_PREF, true);
--- a/browser/extensions/doh-rollout/test/browser/head.js
+++ b/browser/extensions/doh-rollout/test/browser/head.js
@@ -112,16 +112,29 @@ function ensureNoHeuristicsTelemetry() {
     return;
   }
   events = events.filter(
     e => e[1] == "doh" && e[2] == "evaluate" && e[3] == "heuristics"
   );
   is(events.length, 0, "Found no heuristics events.");
 }
 
+async function waitForStateTelemetry() {
+  let events;
+  await BrowserTestUtils.waitForCondition(() => {
+    events = Services.telemetry.snapshotEvents(
+      Ci.nsITelemetry.DATASET_PRERELEASE_CHANNELS
+    ).dynamic;
+    return events;
+  });
+  events = events.filter(e => e[1] == "doh" && e[2] == "state");
+  is(events.length, 1, "Found the expected state event.");
+  Services.telemetry.clearEvents();
+}
+
 function setPassingHeuristics() {
   Preferences.set(prefs.MOCK_HEURISTICS_PREF, fakePassingHeuristics);
 }
 
 function setFailingHeuristics() {
   Preferences.set(prefs.MOCK_HEURISTICS_PREF, fakeFailingHeuristics);
 }