fune/browser/experiments/test/xpcshell/test_telemetry_disabled.js
Mark Banner ec019988a1 Bug 1348097 - Fix intermittent failures caused by Experiments.jsm by ensuring the preference monitoring is in sync. r=gfritzsche
Change the ExperimentsService to get the current value of the preferences (since it only uses them once or twice), so that they match the values in Experiments, and avoid differences causing promises to be rejected in the updateManifest call.
Also fix Experiments to correctly re-enable itself when toolkit.telemetry.enabled is changed from false to true (also fixes bug 1232648).
Finally, add a catch for a promise when calling updateManifest so that we don't get an uncaught promise exception.

MozReview-Commit-ID: GD6gfcRSgbx

--HG--
extra : rebase_source : a5045275c2f864b75443c2cb8fc531ea0e84a704
2017-04-19 12:06:16 +01:00

28 lines
918 B
JavaScript

/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
Cu.import("resource:///modules/experiments/Experiments.jsm");
add_test(function test_experiments_activation() {
do_get_profile();
loadAddonManager();
Services.prefs.setBoolPref(PREF_EXPERIMENTS_ENABLED, true);
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, false);
let experiments = Experiments.instance();
Assert.ok(!experiments.enabled, "Experiments must be disabled if Telemetry is disabled.");
// Patch updateManifest to not do anything when the pref is switched back to true,
// otherwise it attempts to connect to the server.
experiments.updateManifest = () => Promise.resolve();
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
Assert.ok(experiments.enabled, "Experiments must be re-enabled if Telemetry is re-enabled");
run_next_test();
});