mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 826580 - Record application version history in Firefox Health Report; r=rnewman
This commit is contained in:
parent
f222a856f9
commit
3d492fcc1e
@ -76,6 +76,23 @@ AppInfoMeasurement.prototype = Object.freeze({
|
||||
});
|
||||
|
||||
|
||||
function AppVersionMeasurement() {
|
||||
Metrics.Measurement.call(this);
|
||||
}
|
||||
|
||||
AppVersionMeasurement.prototype = Object.freeze({
|
||||
__proto__: Metrics.Measurement.prototype,
|
||||
|
||||
name: "versions",
|
||||
version: 1,
|
||||
|
||||
configureStorage: function () {
|
||||
return this.registerStorageField("version",
|
||||
this.storage.FIELD_DAILY_DISCRETE_TEXT);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
this.AppInfoProvider = function AppInfoProvider() {
|
||||
Metrics.Provider.call(this);
|
||||
|
||||
@ -86,7 +103,7 @@ AppInfoProvider.prototype = Object.freeze({
|
||||
|
||||
name: "org.mozilla.appInfo",
|
||||
|
||||
measurementTypes: [AppInfoMeasurement],
|
||||
measurementTypes: [AppInfoMeasurement, AppVersionMeasurement],
|
||||
|
||||
appInfoFields: {
|
||||
// From nsIXULAppInfo.
|
||||
@ -103,6 +120,46 @@ AppInfoProvider.prototype = Object.freeze({
|
||||
xpcomabi: "XPCOMABI",
|
||||
},
|
||||
|
||||
onInit: function () {
|
||||
return Task.spawn(this._onInit.bind(this));
|
||||
},
|
||||
|
||||
_onInit: function () {
|
||||
// Services.appInfo should always be defined for any reasonably behaving
|
||||
// Gecko app. If it isn't, we insert a empty string sentinel value.
|
||||
let ai;
|
||||
try {
|
||||
ai = Services.appinfo;
|
||||
} catch (ex) {
|
||||
this._log.error("Could not obtain Services.appinfo: " +
|
||||
CommonUtils.exceptionStr(ex));
|
||||
yield this._setCurrentVersion("");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ai) {
|
||||
this._log.error("Services.appinfo is unavailable.");
|
||||
yield this._setCurrentVersion("");
|
||||
return;
|
||||
}
|
||||
|
||||
let currentVersion = ai.version;
|
||||
let lastVersion = yield this.getState("lastVersion");
|
||||
|
||||
if (currentVersion == lastVersion) {
|
||||
return;
|
||||
}
|
||||
|
||||
yield this._setCurrentVersion(currentVersion);
|
||||
},
|
||||
|
||||
_setCurrentVersion: function (version) {
|
||||
this._log.info("Recording new application version: " + version);
|
||||
let m = this.getMeasurement("versions", 1);
|
||||
m.addDailyDiscreteText("version", version);
|
||||
return this.setState("lastVersion", version);
|
||||
},
|
||||
|
||||
collectConstantData: function () {
|
||||
return this.enqueueStorageOperation(function collect() {
|
||||
return Task.spawn(this._populateConstants.bind(this));
|
||||
|
@ -8,6 +8,8 @@ const {interfaces: Ci, results: Cr, utils: Cu} = Components;
|
||||
Cu.import("resource://gre/modules/Metrics.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/services/healthreport/providers.jsm");
|
||||
Cu.import("resource://testing-common/services/healthreport/utils.jsm");
|
||||
|
||||
|
||||
function run_test() {
|
||||
run_next_test();
|
||||
@ -41,6 +43,60 @@ add_task(function test_collect_smoketest() {
|
||||
do_check_eq(d.os, "XPCShell");
|
||||
do_check_eq(d.xpcomabi, "noarch-spidermonkey");
|
||||
|
||||
yield provider.shutdown();
|
||||
yield storage.close();
|
||||
});
|
||||
|
||||
add_task(function test_record_version() {
|
||||
let storage = yield Metrics.Storage("record_version");
|
||||
|
||||
let provider = new AppInfoProvider();
|
||||
let now = new Date();
|
||||
yield provider.init(storage);
|
||||
|
||||
// The provider records information on startup.
|
||||
let m = provider.getMeasurement("versions", 1);
|
||||
let data = yield m.getValues();
|
||||
|
||||
do_check_true(data.days.hasDay(now));
|
||||
let day = data.days.getDay(now);
|
||||
do_check_eq(day.size, 1);
|
||||
do_check_true(day.has("version"));
|
||||
let value = day.get("version");
|
||||
do_check_true(Array.isArray(value));
|
||||
do_check_eq(value.length, 1);
|
||||
let ai = getAppInfo();
|
||||
do_check_eq(value, ai.version);
|
||||
|
||||
yield provider.shutdown();
|
||||
yield storage.close();
|
||||
});
|
||||
|
||||
add_task(function test_record_version_change() {
|
||||
let storage = yield Metrics.Storage("record_version_change");
|
||||
|
||||
let provider = new AppInfoProvider();
|
||||
let now = new Date();
|
||||
yield provider.init(storage);
|
||||
yield provider.shutdown();
|
||||
|
||||
let ai = getAppInfo();
|
||||
ai.version = "2";
|
||||
updateAppInfo(ai);
|
||||
|
||||
provider = new AppInfoProvider();
|
||||
yield provider.init(storage);
|
||||
|
||||
// There should be 2 records in the versions history.
|
||||
let m = provider.getMeasurement("versions", 1);
|
||||
let data = yield m.getValues();
|
||||
do_check_true(data.days.hasDay(now));
|
||||
let day = data.days.getDay(now);
|
||||
let value = day.get("version");
|
||||
do_check_true(Array.isArray(value));
|
||||
do_check_eq(value.length, 2);
|
||||
do_check_eq(value[1], "2");
|
||||
|
||||
yield provider.shutdown();
|
||||
yield storage.close();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user