Skip to content

Commit

Permalink
Merge m-c to m-i
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: 2FUpmxEyNnH
  • Loading branch information
philor committed Oct 28, 2017
2 parents 5052f08 + 4bc2b16 commit 7f6c31a
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 30 deletions.
4 changes: 4 additions & 0 deletions browser/base/content/test/tabs/browser_tabCloseProbes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ function assertCount(snapshot, expectedCount) {
add_task(async function setup() {
// These probes are opt-in, meaning we only capture them if extended
// Telemetry recording is enabled.
await SpecialPowers.pushPrefEnv({
set: [["toolkit.telemetry.enabled", true]]
});

let oldCanRecord = Services.telemetry.canRecordExtended;
Services.telemetry.canRecordExtended = true;
registerCleanupFunction(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

add_task(async function test() {
await SpecialPowers.pushPrefEnv({set: [["toolkit.telemetry.enabled", true]]});
let engine = await promiseNewEngine("testEngine.xml");
let histogramKey = "other-" + engine.name + ".contextmenu";
let numSearchesBefore = 0;
Expand Down
1 change: 1 addition & 0 deletions browser/components/search/test/browser_healthreport.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function test() {

Services.obs.addObserver(observer, "browser-search-engine-modified");
SpecialPowers.pushPrefEnv({set: [
["toolkit.telemetry.enabled", true],
["browser.search.widget.inNavBar", true],
]}).then(function() {
Services.search.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine.xml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ add_task(async function setup() {
};

const prefs = [
"toolkit.telemetry.enabled",
"browser.translation.detectLanguage",
"browser.translation.ui.show"
];
Expand Down
18 changes: 16 additions & 2 deletions browser/experiments/Experiments.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "TelemetryEnvironment",
"resource://gre/modules/TelemetryEnvironment.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryLog",
"resource://gre/modules/TelemetryLog.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryUtils",
"resource://gre/modules/TelemetryUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "CommonUtils",
"resource://services-common/utils.js");

Expand All @@ -50,6 +52,8 @@ const PREF_LOGGING_DUMP = PREF_LOGGING + ".dump"; // experiments.logging
const PREF_MANIFEST_URI = "manifest.uri"; // experiments.logging.manifest.uri
const PREF_FORCE_SAMPLE = "force-sample-value"; // experiments.force-sample-value

const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";

const URI_EXTENSION_STRINGS = "chrome://mozapps/locale/extensions/extensions.properties";

const CACHE_WRITE_RETRY_DELAY_SEC = 60 * 3;
Expand Down Expand Up @@ -382,6 +386,8 @@ Experiments.Experiments.prototype = {
this.updateManifest();
} else if (data == PREF_BRANCH + PREF_ENABLED) {
this._toggleExperimentsEnabled(gPrefs.getBoolPref(PREF_ENABLED, false));
} else if (data == PREF_TELEMETRY_ENABLED) {
this._telemetryStatusChanged();
}
break;
}
Expand All @@ -391,13 +397,15 @@ Experiments.Experiments.prototype = {
this._shutdown = false;
configureLogging();

gExperimentsEnabled = gPrefs.getBoolPref(PREF_ENABLED, false) && Services.telemetry.canRecordExtended;
gExperimentsEnabled = gPrefs.getBoolPref(PREF_ENABLED, false) && TelemetryUtils.isTelemetryEnabled;
this._log.trace("enabled=" + gExperimentsEnabled + ", " + this.enabled);

Services.prefs.addObserver(PREF_BRANCH + PREF_LOGGING, configureLogging);
Services.prefs.addObserver(PREF_BRANCH + PREF_MANIFEST_URI, this, true);
Services.prefs.addObserver(PREF_BRANCH + PREF_ENABLED, this, true);

Services.prefs.addObserver(PREF_TELEMETRY_ENABLED, this, true);

AddonManager.shutdown.addBlocker("Experiments.jsm shutdown",
this.uninit.bind(this),
this._getState.bind(this)
Expand Down Expand Up @@ -445,6 +453,8 @@ Experiments.Experiments.prototype = {
Services.prefs.removeObserver(PREF_BRANCH + PREF_MANIFEST_URI, this);
Services.prefs.removeObserver(PREF_BRANCH + PREF_ENABLED, this);

Services.prefs.removeObserver(PREF_TELEMETRY_ENABLED, this);

if (this._timer) {
this._timer.clear();
}
Expand Down Expand Up @@ -588,7 +598,7 @@ Experiments.Experiments.prototype = {
async _toggleExperimentsEnabled(enabled) {
this._log.trace("_toggleExperimentsEnabled(" + enabled + ")");
let wasEnabled = gExperimentsEnabled;
gExperimentsEnabled = enabled && Services.telemetry.canRecordExtended;
gExperimentsEnabled = enabled && TelemetryUtils.isTelemetryEnabled;

if (wasEnabled == gExperimentsEnabled) {
return;
Expand All @@ -604,6 +614,10 @@ Experiments.Experiments.prototype = {
}
},

_telemetryStatusChanged() {
this._toggleExperimentsEnabled(gPrefs.getBoolPref(PREF_ENABLED, false));
},

/**
* Returns a promise that is resolved with an array of `ExperimentInfo` objects,
* which provide info on the currently and recently active experiments.
Expand Down
5 changes: 4 additions & 1 deletion browser/experiments/test/xpcshell/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const PREF_LOGGING_LEVEL = "experiments.logging.level";
const PREF_LOGGING_DUMP = "experiments.logging.dump";
const PREF_MANIFEST_URI = "experiments.manifest.uri";
const PREF_FETCHINTERVAL = "experiments.manifest.fetchIntervalSeconds";
const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";

function getExperimentPath(base) {
let p = do_get_cwd();
Expand Down Expand Up @@ -192,4 +193,6 @@ function replaceExperiments(experiment, list) {
});
}

Services.telemetry.canRecordExtended = true;
// Experiments require Telemetry to be enabled, and that's not true for debug
// builds. Let's just enable it here instead of going through each test.
Services.prefs.setBoolPref(PREF_TELEMETRY_ENABLED, true);
10 changes: 9 additions & 1 deletion browser/experiments/test/xpcshell/test_telemetry_disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ add_test(function test_experiments_activation() {
loadAddonManager();

Services.prefs.setBoolPref(PREF_EXPERIMENTS_ENABLED, true);
Services.telemetry.canRecordExtended = false;
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();
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ add_task(async function setup() {

await SpecialPowers.pushPrefEnv({"set": [
["dom.select_events.enabled", true], // We want select events to be fired.
["toolkit.telemetry.enabled", true] // And Extended Telemetry to be enabled.
]});

// Enable event recording for the events tested here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ add_task(async function setup() {
let engineOneOff = Services.search.getEngineByName("MozSearch2");
Services.search.moveEngine(engineOneOff, 0);

// Enable Extended Telemetry.
await SpecialPowers.pushPrefEnv({"set": [["toolkit.telemetry.enabled", true]]});

// Enable event recording for the events tested here.
Services.telemetry.setEventRecordingEnabled("navigation", true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ add_task(async function setup() {
let oldCanRecord = Services.telemetry.canRecordExtended;
Services.telemetry.canRecordExtended = true;

// Enable Extended Telemetry.
await SpecialPowers.pushPrefEnv({"set": [["toolkit.telemetry.enabled", true]]});

// Enable event recording for the events tested here.
Services.telemetry.setEventRecordingEnabled("navigation", true);

Expand Down
3 changes: 3 additions & 0 deletions browser/modules/test/browser/browser_UsageTelemetry_urlbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ add_task(async function setup() {
// Enable the urlbar one-off buttons.
Services.prefs.setBoolPref(ONEOFF_URLBAR_PREF, true);

// Enable Extended Telemetry.
await SpecialPowers.pushPrefEnv({"set": [["toolkit.telemetry.enabled", true]]});

// Enable local telemetry recording for the duration of the tests.
let oldCanRecord = Services.telemetry.canRecordExtended;
Services.telemetry.canRecordExtended = true;
Expand Down
1 change: 1 addition & 0 deletions dom/ipc/tests/browser_memory_distribution_telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_task(async function test_memory_distribution() {
return;
}

await SpecialPowers.pushPrefEnv({set: [["toolkit.telemetry.enabled", true]]});
Services.telemetry.canRecordExtended = true;

let histogram = Services.telemetry.getKeyedHistogramById("MEMORY_DISTRIBUTION_AMONG_CONTENT");
Expand Down
1 change: 1 addition & 0 deletions dom/ipc/tests/browser_remote_navigation_delay_telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_task(async function test_memory_distribution() {
return;
}

await SpecialPowers.pushPrefEnv({set: [["toolkit.telemetry.enabled", true]]});
let canRecordExtended = Services.telemetry.canRecordExtended;
Services.telemetry.canRecordExtended = true;
registerCleanupFunction(() => Services.telemetry.canRecordExtended = canRecordExtended);
Expand Down
1 change: 1 addition & 0 deletions dom/security/test/hsts/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ function SetupPrefTestEnvironment(which, additional_prefs) {
settings.use_hsts],
["security.mixed_content.send_hsts_priming",
settings.send_hsts_priming],
["toolkit.telemetry.enabled", true],
];

if (additional_prefs) {
Expand Down
2 changes: 1 addition & 1 deletion js/src/tests/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ user_pref("javascript.options.strict", false);
user_pref("javascript.options.werror", false);
user_pref("toolkit.startup.max_resumed_crashes", -1);
user_pref("security.turn_off_all_security_so_that_viruses_can_take_over_this_computer", true);
user_pref("datareporting.healthreport.uploadEnabled", false);
user_pref("toolkit.telemetry.enabled", false);
user_pref("browser.safebrowsing.phishing.enabled", false);
user_pref("browser.safebrowsing.malware.enabled", false);
user_pref("browser.safebrowsing.blockedURIs.enabled", false);
Expand Down
2 changes: 0 additions & 2 deletions layout/tools/reftest/reftest-preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ user_pref("datareporting.policy.dataSubmissionPolicyBypassNotification", true);
// server in the middle of the tests.
user_pref("toolkit.telemetry.enabled", false);
user_pref("toolkit.telemetry.unified", false);
user_pref("datareporting.healthreport.uploadEnabled", false);
user_pref("experiments.enabled", false);
// Likewise for safebrowsing.
user_pref("browser.safebrowsing.phishing.enabled", false);
user_pref("browser.safebrowsing.malware.enabled", false);
Expand Down
14 changes: 0 additions & 14 deletions modules/libpref/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4775,7 +4775,6 @@ pref_InitInitialObjects()
NS_ENSURE_SUCCESS(
rv, Err("pref_LoadPrefsInDirList(NS_APP_PREFS_DEFAULTS_DIR_LIST) failed"));

#ifdef MOZ_WIDGET_ANDROID
// Set up the correct default for toolkit.telemetry.enabled. If this build
// has MOZ_TELEMETRY_ON_BY_DEFAULT *or* we're on the beta channel, telemetry
// is on by default, otherwise not. This is necessary so that beta users who
Expand All @@ -4794,19 +4793,6 @@ pref_InitInitialObjects()
#endif
PREF_SetBoolPref(kTelemetryPref, prerelease, true);
}
#else
// For platforms with Unified Telemetry (here meaning not-Android),
// toolkit.telemetry.enabled determines whether we send "extended" data.
// We only want extended data from pre-release channels due to size.
if (!strcmp(NS_STRINGIFY(MOZ_UPDATE_CHANNEL), "nightly") ||
!strcmp(NS_STRINGIFY(MOZ_UPDATE_CHANNEL), "aurora") ||
!strcmp(NS_STRINGIFY(MOZ_UPDATE_CHANNEL), "beta")) {
PREF_SetBoolPref(kTelemetryPref, true, true);
} else {
PREF_SetBoolPref(kTelemetryPref, false, true);
}
PREF_LockPref(kTelemetryPref, true);
#endif // MOZ_WIDGET_ANDROID

NS_CreateServicesFromCategory(NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID,
nullptr,
Expand Down
2 changes: 2 additions & 0 deletions testing/mozbase/mozprofile/mozprofile/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ class FirefoxProfile(Profile):
'security.notification_enable_delay': 0,
# Suppress automatic safe mode after crashes
'toolkit.startup.max_resumed_crashes': -1,
# Don't report telemetry information
'toolkit.telemetry.enabled': False,
# Don't send Telemetry reports to the production server. This is
# needed as Telemetry sends pings also if FHR upload is enabled.
'toolkit.telemetry.server': 'http://%(server)s/telemetry-dummy/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

add_task(async function test_contentscript_telemetry() {
// Turn on telemetry and reset it to the previous state once the test is completed.
// NOTE: This is only needed on Android (which does not properly support unified telemetry,
// while we're always recording opt-out telemetry on desktop).
// Switching the "toolkit.telemetry.enabled" preference
// (e.g. using SpecialPowers.pushPrefEnv) is unfortunately not enough,
// because the TelemetryController has been already initialized when this
// code is going to be executed.
const telemetryCanRecordBase = SpecialPowers.Services.telemetry.canRecordBase;
SpecialPowers.Services.telemetry.canRecordBase = true;
SimpleTest.registerCleanupFunction(() => {
Expand Down
16 changes: 8 additions & 8 deletions toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,10 @@ add_task(async function test_pref_observer() {

await TelemetrySend.setup(true);

const IS_UNIFIED_TELEMETRY = Services.prefs.getBoolPref(TelemetryUtils.Preferences.Unified, false);

let origTelemetryEnabled = Services.prefs.getBoolPref(TelemetryUtils.Preferences.TelemetryEnabled);
let origFhrUploadEnabled = Services.prefs.getBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled);

if (!IS_UNIFIED_TELEMETRY) {
Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
}
Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true);
Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, true);

function waitAnnotateCrashReport(expectedValue, trigger) {
Expand Down Expand Up @@ -605,13 +601,17 @@ add_task(async function test_pref_observer() {
});
}

const IS_UNIFIED_TELEMETRY = Services.prefs.getBoolPref(TelemetryUtils.Preferences.Unified, false);

await waitAnnotateCrashReport(IS_UNIFIED_TELEMETRY, () => Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, false));

await waitAnnotateCrashReport(true, () => Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, true));

await waitAnnotateCrashReport(!IS_UNIFIED_TELEMETRY, () => Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, false));

await waitAnnotateCrashReport(true, () => Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, true));

if (!IS_UNIFIED_TELEMETRY) {
Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, origTelemetryEnabled);
}
Services.prefs.setBoolPref(TelemetryUtils.Preferences.TelemetryEnabled, origTelemetryEnabled);
Services.prefs.setBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, origFhrUploadEnabled);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ add_task(async function initializeState() {

registerCleanupFunction(() => {
Services.prefs.clearUserPref("experiments.enabled");
Services.prefs.clearUserPref("toolkit.telemetry.enabled");
if (gHttpServer) {
gHttpServer.stop(() => {});
if (gSavedManifestURI !== undefined) {
Expand Down Expand Up @@ -265,7 +266,7 @@ add_task(async function testActivateExperiment() {
// We need to remove the cache file to help ensure consistent state.
await OS.File.remove(gExperiments._cacheFilePath);

Services.telemetry.canRecordExtended = true;
Services.prefs.setBoolPref("toolkit.telemetry.enabled", true);
Services.prefs.setBoolPref("experiments.enabled", true);

info("Initializing experiments service.");
Expand Down Expand Up @@ -607,6 +608,8 @@ add_task(async function testCleanup() {
await OS.File.remove(gExperiments._cacheFilePath);
await gExperiments.uninit();
await gExperiments.init();

Services.prefs.clearUserPref("toolkit.telemetry.enabled");
}

// Check post-conditions.
Expand Down
1 change: 1 addition & 0 deletions toolkit/mozapps/update/tests/data/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const PREF_APP_UPDATE_URL_MANUAL = "app.update.url.manual";
const PREFBRANCH_APP_PARTNER = "app.partner.";
const PREF_DISTRIBUTION_ID = "distribution.id";
const PREF_DISTRIBUTION_VERSION = "distribution.version";
const PREF_TOOLKIT_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";

const NS_APP_PROFILE_DIR_STARTUP = "ProfDS";
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
Expand Down
2 changes: 2 additions & 0 deletions toolkit/mozapps/update/tests/data/xpcshellUtilsAUS.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,8 @@ function setDefaultPrefs() {
// Some apps set this preference to true by default
Services.prefs.setBoolPref(PREF_APP_UPDATE_LOG, false);
}
// In case telemetry is enabled for xpcshell tests.
Services.prefs.setBoolPref(PREF_TOOLKIT_TELEMETRY_ENABLED, false);
}

/**
Expand Down

0 comments on commit 7f6c31a

Please sign in to comment.