mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 841028: Add last build ID to telemetry system info if build ID has changed. r=froydnj
This commit is contained in:
parent
9242136aab
commit
d2ce93c04d
@ -23,12 +23,15 @@ const PAYLOAD_VERSION = 1;
|
||||
// submitted ping data with its histogram definition (bug 832007)
|
||||
#expand const HISTOGRAMS_FILE_VERSION = "__HISTOGRAMS_FILE_VERSION__";
|
||||
|
||||
const PREF_SERVER = "toolkit.telemetry.server";
|
||||
const PREF_BRANCH = "toolkit.telemetry.";
|
||||
const PREF_SERVER = PREF_BRANCH + "server";
|
||||
#ifdef MOZ_TELEMETRY_ON_BY_DEFAULT
|
||||
const PREF_ENABLED = "toolkit.telemetry.enabledPreRelease";
|
||||
const PREF_ENABLED = PREF_BRANCH + "enabledPreRelease";
|
||||
#else
|
||||
const PREF_ENABLED = "toolkit.telemetry.enabled";
|
||||
const PREF_ENABLED = PREF_BRANCH + "enabled";
|
||||
#endif
|
||||
const PREF_PREVIOUS_BUILDID = PREF_BRANCH + "previousBuildID";
|
||||
|
||||
// Do not gather data more than once a minute
|
||||
const TELEMETRY_INTERVAL = 60000;
|
||||
// Delay before intializing telemetry (ms)
|
||||
@ -182,6 +185,9 @@ TelemetryPing.prototype = {
|
||||
// handles retrieving histograms and writing the data to disk.
|
||||
_savedSimpleMeasurements: null,
|
||||
_savedInfo: null,
|
||||
// The previous build ID, if this is the first run with a new build.
|
||||
// Undefined if this is not the first run, or the previous build ID is unknown.
|
||||
_previousBuildID: undefined,
|
||||
|
||||
/**
|
||||
* Gets a series of simple measurements (counters). At the moment, this
|
||||
@ -385,6 +391,9 @@ TelemetryPing.prototype = {
|
||||
revision: HISTOGRAMS_FILE_VERSION,
|
||||
locale: getLocale()
|
||||
};
|
||||
if (this._previousBuildID) {
|
||||
ret.previousBuildID = this._previousBuildID;
|
||||
}
|
||||
|
||||
// sysinfo fields are not always available, get what we can.
|
||||
let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
|
||||
@ -753,6 +762,22 @@ TelemetryPing.prototype = {
|
||||
* Initializes telemetry within a timer. If there is no PREF_SERVER set, don't turn on telemetry.
|
||||
*/
|
||||
setup: function setup() {
|
||||
// Record old value and update build ID preference if this is the first
|
||||
// run with a new build ID.
|
||||
let previousBuildID = undefined;
|
||||
try {
|
||||
previousBuildID = Services.prefs.getCharPref(PREF_PREVIOUS_BUILDID);
|
||||
} catch (e) {
|
||||
// Preference was not set.
|
||||
}
|
||||
let thisBuildID = Services.appinfo.appBuildID;
|
||||
// If there is no previousBuildID preference, this._previousBuildID remains
|
||||
// undefined so no value is sent in the telemetry metadata.
|
||||
if (previousBuildID != thisBuildID) {
|
||||
this._previousBuildID = previousBuildID;
|
||||
Services.prefs.setCharPref(PREF_PREVIOUS_BUILDID, thisBuildID);
|
||||
}
|
||||
|
||||
#ifdef MOZILLA_OFFICIAL
|
||||
if (!Telemetry.canSend) {
|
||||
// We can't send data; no point in initializing observers etc.
|
||||
|
@ -0,0 +1,73 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
/* Test inclusion of previous build ID in telemetry pings when build ID changes.
|
||||
* bug 841028
|
||||
*
|
||||
* Cases to cover:
|
||||
* 1) Run with no "previousBuildID" stored in prefs:
|
||||
* -> no previousBuildID in telemetry system info, new value set in prefs.
|
||||
* 2) previousBuildID in prefs, equal to current build ID:
|
||||
* -> no previousBuildID in telemetry, prefs not updated.
|
||||
* 3) previousBuildID in prefs, not equal to current build ID:
|
||||
* -> previousBuildID in telemetry, new value set in prefs.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Get the TelemetryPing definitions directly so we can test it without going through xpcom.
|
||||
Services.scriptloader.loadSubScript("resource://gre/components/TelemetryPing.js");
|
||||
|
||||
// Force the Telemetry enabled preference so that TelemetryPing.setup() doesn't exit early.
|
||||
Services.prefs.setBoolPref(PREF_ENABLED, true);
|
||||
|
||||
// Set up our dummy AppInfo object so we can control the appBuildID.
|
||||
Cu.import("resource://testing-common/AppInfo.jsm");
|
||||
updateAppInfo();
|
||||
|
||||
// Check that when run with no previous build ID stored, we update the pref but do not
|
||||
// put anything into the metadata.
|
||||
function testFirstRun() {
|
||||
let ping = new TelemetryPing();
|
||||
ping.setup();
|
||||
let metadata = ping.getMetadata();
|
||||
do_check_false("previousBuildID" in metadata);
|
||||
let appBuildID = getAppInfo().appBuildID;
|
||||
let buildIDPref = Services.prefs.getCharPref(PREF_PREVIOUS_BUILDID);
|
||||
do_check_eq(appBuildID, buildIDPref);
|
||||
}
|
||||
|
||||
// Check that a subsequent run with the same build ID does not put prev build ID in
|
||||
// metadata. Assumes testFirstRun() has already been called to set the previousBuildID pref.
|
||||
function testSecondRun() {
|
||||
let ping = new TelemetryPing();
|
||||
ping.setup();
|
||||
let metadata = ping.getMetadata();
|
||||
do_check_false("previousBuildID" in metadata);
|
||||
}
|
||||
|
||||
|
||||
// Set up telemetry with a different app build ID and check that the old build ID
|
||||
// is returned in the metadata and the pref is updated to the new build ID.
|
||||
// Assumes testFirstRun() has been called to set the previousBuildID pref.
|
||||
const NEW_BUILD_ID = "20130314";
|
||||
function testNewBuild() {
|
||||
let info = getAppInfo();
|
||||
let oldBuildID = info.appBuildID;
|
||||
info.appBuildID = NEW_BUILD_ID;
|
||||
let ping = new TelemetryPing();
|
||||
ping.setup();
|
||||
let metadata = ping.getMetadata();
|
||||
do_check_eq(metadata.previousBuildID, oldBuildID);
|
||||
let buildIDPref = Services.prefs.getCharPref(PREF_PREVIOUS_BUILDID);
|
||||
do_check_eq(NEW_BUILD_ID, buildIDPref);
|
||||
}
|
||||
|
||||
|
||||
function run_test() {
|
||||
// Make sure we have a profile directory.
|
||||
do_get_profile();
|
||||
testFirstRun();
|
||||
testSecondRun();
|
||||
testNewBuild();
|
||||
}
|
@ -8,3 +8,4 @@ tail =
|
||||
# fail-if = os == "android"
|
||||
[test_TelemetryPing_idle.js]
|
||||
[test_TelemetryStopwatch.js]
|
||||
[test_TelemetryPingBuildID.js]
|
||||
|
Loading…
Reference in New Issue
Block a user