mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1151086 - Fix experiment filter functions to use the new telemetry environment, r=gfritzsche
This commit is contained in:
parent
1f81e3d2c9
commit
22972cdab9
@ -26,8 +26,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
|
||||
"resource://gre/modules/AddonManager.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "AddonManagerPrivate",
|
||||
"resource://gre/modules/AddonManager.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "TelemetrySession",
|
||||
"resource://gre/modules/TelemetrySession.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryEnvironment",
|
||||
"resource://gre/modules/TelemetryEnvironment.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryLog",
|
||||
"resource://gre/modules/TelemetryLog.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "CommonUtils",
|
||||
@ -56,8 +56,6 @@ 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_HEALTHREPORT_ENABLED = "datareporting.healthreport.service.enabled";
|
||||
|
||||
const PREF_BRANCH_TELEMETRY = "toolkit.telemetry.";
|
||||
const PREF_TELEMETRY_ENABLED = "enabled";
|
||||
|
||||
@ -285,25 +283,6 @@ Experiments.Policy.prototype = {
|
||||
return chrome.getSelectedLocale("global");
|
||||
},
|
||||
|
||||
/*
|
||||
* @return Promise<> Resolved with the payload data.
|
||||
*/
|
||||
healthReportPayload: function () {
|
||||
return Task.spawn(function*() {
|
||||
let reporter = Cc["@mozilla.org/datareporting/service;1"]
|
||||
.getService(Ci.nsISupports)
|
||||
.wrappedJSObject
|
||||
.healthReporter;
|
||||
yield reporter.onInit();
|
||||
let payload = yield reporter.collectAndObtainJSONPayload();
|
||||
return payload;
|
||||
});
|
||||
},
|
||||
|
||||
telemetryPayload: function () {
|
||||
return TelemetrySession.getPayload();
|
||||
},
|
||||
|
||||
/**
|
||||
* For testing a race condition, one of the tests delays the callback of
|
||||
* writing the cache by replacing this policy function.
|
||||
@ -1706,50 +1685,47 @@ Experiments.ExperimentEntry.prototype = {
|
||||
* Run the jsfilter function from the manifest in a sandbox and return the
|
||||
* result (forced to boolean).
|
||||
*/
|
||||
_runFilterFunction: function (jsfilter) {
|
||||
_runFilterFunction: Task.async(function* (jsfilter) {
|
||||
this._log.trace("runFilterFunction() - filter: " + jsfilter);
|
||||
|
||||
return Task.spawn(function ExperimentEntry_runFilterFunction_task() {
|
||||
const nullprincipal = Cc["@mozilla.org/nullprincipal;1"].createInstance(Ci.nsIPrincipal);
|
||||
let options = {
|
||||
sandboxName: "telemetry experiments jsfilter sandbox",
|
||||
wantComponents: false,
|
||||
};
|
||||
const nullprincipal = Cc["@mozilla.org/nullprincipal;1"].createInstance(Ci.nsIPrincipal);
|
||||
let options = {
|
||||
sandboxName: "telemetry experiments jsfilter sandbox",
|
||||
wantComponents: false,
|
||||
};
|
||||
|
||||
let sandbox = Cu.Sandbox(nullprincipal, options);
|
||||
try {
|
||||
Cu.evalInSandbox(jsfilter, sandbox);
|
||||
} catch (e) {
|
||||
this._log.error("runFilterFunction() - failed to eval jsfilter: " + e.message);
|
||||
throw ["jsfilter-evalfailed"];
|
||||
}
|
||||
let sandbox = Cu.Sandbox(nullprincipal, options);
|
||||
try {
|
||||
Cu.evalInSandbox(jsfilter, sandbox);
|
||||
} catch (e) {
|
||||
this._log.error("runFilterFunction() - failed to eval jsfilter: " + e.message);
|
||||
throw ["jsfilter-evalfailed"];
|
||||
}
|
||||
|
||||
// You can't insert arbitrarily complex objects into a sandbox, so
|
||||
// we serialize everything through JSON.
|
||||
sandbox._hr = yield this._policy.healthReportPayload();
|
||||
Object.defineProperty(sandbox, "_t",
|
||||
{ get: () => JSON.stringify(this._policy.telemetryPayload()) });
|
||||
let currentEnvironment = yield TelemetryEnvironment.onInitialized();
|
||||
|
||||
let result = false;
|
||||
try {
|
||||
result = !!Cu.evalInSandbox("filter({healthReportPayload: JSON.parse(_hr), telemetryPayload: JSON.parse(_t)})", sandbox);
|
||||
}
|
||||
catch (e) {
|
||||
this._log.debug("runFilterFunction() - filter function failed: "
|
||||
Object.defineProperty(sandbox, "_e",
|
||||
{ get: () => Cu.cloneInto(currentEnvironment, sandbox) });
|
||||
|
||||
let result = false;
|
||||
try {
|
||||
result = !!Cu.evalInSandbox("filter({get telemetryEnvironment() { return _e; } })", sandbox);
|
||||
}
|
||||
catch (e) {
|
||||
this._log.debug("runFilterFunction() - filter function failed: "
|
||||
+ e.message + ", " + e.stack);
|
||||
throw ["jsfilter-threw", e.message];
|
||||
}
|
||||
finally {
|
||||
Cu.nukeSandbox(sandbox);
|
||||
}
|
||||
throw ["jsfilter-threw", e.message];
|
||||
}
|
||||
finally {
|
||||
Cu.nukeSandbox(sandbox);
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
throw ["jsfilter-false"];
|
||||
}
|
||||
if (!result) {
|
||||
throw ["jsfilter-false"];
|
||||
}
|
||||
|
||||
throw new Task.Result(true);
|
||||
}.bind(this));
|
||||
},
|
||||
return true;
|
||||
}),
|
||||
|
||||
/*
|
||||
* Start running the experiment.
|
||||
|
@ -8,9 +8,6 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
Cu.import("resource://gre/modules/Task.jsm");
|
||||
Cu.import("resource://gre/modules/osfile.jsm");
|
||||
Cu.import("resource://services-sync/healthreport.jsm", this);
|
||||
Cu.import("resource://testing-common/services/healthreport/utils.jsm", this);
|
||||
Cu.import("resource://gre/modules/services/healthreport/providers.jsm");
|
||||
Cu.import("resource://testing-common/AddonManagerTesting.jsm");
|
||||
|
||||
const PREF_EXPERIMENTS_ENABLED = "experiments.enabled";
|
||||
@ -19,7 +16,6 @@ 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";
|
||||
const PREF_HEALTHREPORT_ENABLED = "datareporting.healthreport.service.enabled";
|
||||
|
||||
function getExperimentPath(base) {
|
||||
let p = do_get_cwd();
|
||||
@ -103,18 +99,6 @@ const FAKE_EXPERIMENTS_2 = [
|
||||
|
||||
let gAppInfo = null;
|
||||
|
||||
function getReporter(name, uri, inspected) {
|
||||
return Task.spawn(function init() {
|
||||
let reporter = getHealthReporter(name, uri, inspected);
|
||||
yield reporter.init();
|
||||
|
||||
yield reporter._providerManager.registerProviderFromType(
|
||||
HealthReportProvider);
|
||||
|
||||
throw new Task.Result(reporter);
|
||||
});
|
||||
}
|
||||
|
||||
function removeCacheFile() {
|
||||
let path = OS.Path.join(OS.Constants.Path.profileDir, "experiments.json");
|
||||
return OS.File.remove(path);
|
||||
|
@ -13,7 +13,6 @@ const MS_IN_ONE_DAY = SEC_IN_ONE_DAY * 1000;
|
||||
let gProfileDir = null;
|
||||
let gHttpServer = null;
|
||||
let gHttpRoot = null;
|
||||
let gReporter = null;
|
||||
let gPolicy = null;
|
||||
|
||||
function ManifestEntry(data) {
|
||||
@ -43,14 +42,8 @@ add_task(function* test_setup() {
|
||||
gHttpServer.registerDirectory("/", do_get_cwd());
|
||||
do_register_cleanup(() => gHttpServer.stop(() => {}));
|
||||
|
||||
gReporter = yield getReporter("json_payload_simple");
|
||||
yield gReporter.collectMeasurements();
|
||||
let payload = yield gReporter.getJSONPayload(false);
|
||||
do_register_cleanup(() => gReporter._shutdown());
|
||||
|
||||
patchPolicy(gPolicy, {
|
||||
updatechannel: () => "nightly",
|
||||
healthReportPayload: () => Promise.resolve(payload),
|
||||
});
|
||||
|
||||
Services.prefs.setBoolPref(PREF_EXPERIMENTS_ENABLED, true);
|
||||
|
@ -19,7 +19,6 @@ let gProfileDir = null;
|
||||
let gHttpServer = null;
|
||||
let gHttpRoot = null;
|
||||
let gDataRoot = null;
|
||||
let gReporter = null;
|
||||
let gPolicy = null;
|
||||
let gManifestObject = null;
|
||||
let gManifestHandlerURI = null;
|
||||
@ -71,15 +70,9 @@ add_task(function* test_setup() {
|
||||
Services.prefs.setCharPref(PREF_MANIFEST_URI, gManifestHandlerURI);
|
||||
Services.prefs.setIntPref(PREF_FETCHINTERVAL, 0);
|
||||
|
||||
gReporter = yield getReporter("json_payload_simple");
|
||||
yield gReporter.collectMeasurements();
|
||||
let payload = yield gReporter.getJSONPayload(false);
|
||||
do_register_cleanup(() => gReporter._shutdown());
|
||||
|
||||
gPolicy = new Experiments.Policy();
|
||||
patchPolicy(gPolicy, {
|
||||
updatechannel: () => "nightly",
|
||||
healthReportPayload: () => Promise.resolve(payload),
|
||||
oneshotTimer: (callback, timeout, thisObj, name) => gTimerScheduleOffset = timeout,
|
||||
});
|
||||
});
|
||||
|
@ -16,7 +16,6 @@ let gProfileDir = null;
|
||||
let gHttpServer = null;
|
||||
let gHttpRoot = null;
|
||||
let gDataRoot = null;
|
||||
let gReporter = null;
|
||||
let gPolicy = null;
|
||||
let gManifestObject = null;
|
||||
let gManifestHandlerURI = null;
|
||||
@ -52,15 +51,9 @@ add_task(function* test_setup() {
|
||||
Services.prefs.setCharPref(PREF_MANIFEST_URI, gManifestHandlerURI);
|
||||
Services.prefs.setIntPref(PREF_FETCHINTERVAL, 0);
|
||||
|
||||
gReporter = yield getReporter("json_payload_simple");
|
||||
yield gReporter.collectMeasurements();
|
||||
let payload = yield gReporter.getJSONPayload(true);
|
||||
do_register_cleanup(() => gReporter._shutdown());
|
||||
|
||||
gPolicy = new Experiments.Policy();
|
||||
patchPolicy(gPolicy, {
|
||||
updatechannel: () => "nightly",
|
||||
healthReportPayload: () => "{}",
|
||||
oneshotTimer: (callback, timeout, thisObj, name) => gTimerScheduleOffset = timeout,
|
||||
});
|
||||
});
|
||||
|
@ -15,7 +15,6 @@ let gProfileDir = null;
|
||||
let gHttpServer = null;
|
||||
let gHttpRoot = null;
|
||||
let gDataRoot = null;
|
||||
let gReporter = null;
|
||||
let gPolicy = null;
|
||||
let gManifestObject = null;
|
||||
let gManifestHandlerURI = null;
|
||||
@ -50,18 +49,12 @@ add_task(function* test_setup() {
|
||||
Services.prefs.setCharPref(PREF_MANIFEST_URI, gManifestHandlerURI);
|
||||
Services.prefs.setIntPref(PREF_FETCHINTERVAL, 0);
|
||||
|
||||
gReporter = yield getReporter("json_payload_simple");
|
||||
yield gReporter.collectMeasurements();
|
||||
let payload = yield gReporter.getJSONPayload(true);
|
||||
do_register_cleanup(() => gReporter._shutdown());
|
||||
|
||||
let ExperimentsScope = Cu.import("resource:///modules/experiments/Experiments.jsm");
|
||||
let Experiments = ExperimentsScope.Experiments;
|
||||
|
||||
gPolicy = new Experiments.Policy();
|
||||
patchPolicy(gPolicy, {
|
||||
updatechannel: () => "nightly",
|
||||
healthReportPayload: () => "{}",
|
||||
delayCacheWrite: (promise) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
promise.then(
|
||||
|
@ -20,7 +20,6 @@ const MS_IN_ONE_DAY = SEC_IN_ONE_DAY * 1000;
|
||||
let gProfileDir = null;
|
||||
let gHttpServer = null;
|
||||
let gHttpRoot = null;
|
||||
let gReporter = null;
|
||||
let gPolicy = null;
|
||||
|
||||
|
||||
@ -73,15 +72,9 @@ add_task(function* test_setup() {
|
||||
yield initialiseTelemetry();
|
||||
gPolicy = new Experiments.Policy();
|
||||
|
||||
gReporter = yield getReporter("json_payload_simple");
|
||||
yield gReporter.collectMeasurements();
|
||||
let payload = yield gReporter.getJSONPayload(false);
|
||||
do_register_cleanup(() => gReporter._shutdown());
|
||||
|
||||
patchPolicy(gPolicy, {
|
||||
updatechannel: () => "nightly",
|
||||
locale: () => "en-US",
|
||||
healthReportPayload: () => Promise.resolve(payload),
|
||||
random: () => 0.5,
|
||||
});
|
||||
|
||||
@ -106,17 +99,11 @@ function arraysEqual(a, b) {
|
||||
|
||||
// This function exists solely to be .toSource()d
|
||||
const sanityFilter = function filter(c) {
|
||||
if (c.telemetryPayload === undefined) {
|
||||
throw Error("No .telemetryPayload");
|
||||
if (c.telemetryEnvironment === undefined) {
|
||||
throw Error("No .telemetryEnvironment");
|
||||
}
|
||||
if (c.telemetryPayload.simpleMeasurements === undefined) {
|
||||
throw Error("No .simpleMeasurements");
|
||||
}
|
||||
if (c.healthReportPayload === undefined) {
|
||||
throw Error("No .healthReportPayload");
|
||||
}
|
||||
if (c.healthReportPayload.geckoAppInfo == undefined) {
|
||||
throw Error("No .geckoAppInfo");
|
||||
if (c.telemetryEnvironment.build == undefined) {
|
||||
throw Error("No .telemetryEnvironment.build");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ let gProfileDir = null;
|
||||
let gHttpServer = null;
|
||||
let gHttpRoot = null;
|
||||
let gDataRoot = null;
|
||||
let gReporter = null;
|
||||
let gPolicy = null;
|
||||
let gManifestObject = null;
|
||||
let gManifestHandlerURI = null;
|
||||
@ -53,15 +52,9 @@ add_task(function* test_setup() {
|
||||
Services.prefs.setCharPref(PREF_MANIFEST_URI, gManifestHandlerURI);
|
||||
Services.prefs.setIntPref(PREF_FETCHINTERVAL, 0);
|
||||
|
||||
gReporter = yield getReporter("json_payload_simple");
|
||||
yield gReporter.collectMeasurements();
|
||||
let payload = yield gReporter.getJSONPayload(false);
|
||||
do_register_cleanup(() => gReporter._shutdown());
|
||||
|
||||
gPolicy = new Experiments.Policy();
|
||||
patchPolicy(gPolicy, {
|
||||
updatechannel: () => "nightly",
|
||||
healthReportPayload: () => Promise.resolve(payload),
|
||||
oneshotTimer: (callback, timeout, thisObj, name) => {},
|
||||
});
|
||||
});
|
||||
|
@ -10,6 +10,8 @@ Cu.import("resource://testing-common/AddonManagerTesting.jsm");
|
||||
Cu.import("resource://testing-common/services/healthreport/utils.jsm");
|
||||
Cu.import("resource://testing-common/services/common/logging.js");
|
||||
|
||||
const PREF_HEALTHREPORT_ENABLED = "datareporting.healthreport.service.enabled";
|
||||
|
||||
const kMeasurementVersion = 2;
|
||||
|
||||
function getStorageAndProvider(name) {
|
||||
|
@ -19,7 +19,6 @@ let gProfileDir = null;
|
||||
let gHttpServer = null;
|
||||
let gHttpRoot = null;
|
||||
let gDataRoot = null;
|
||||
let gReporter = null;
|
||||
let gPolicy = null;
|
||||
let gManifestObject = null;
|
||||
let gManifestHandlerURI = null;
|
||||
@ -84,16 +83,10 @@ add_task(function* test_setup() {
|
||||
Services.prefs.setCharPref(PREF_MANIFEST_URI, gManifestHandlerURI);
|
||||
Services.prefs.setIntPref(PREF_FETCHINTERVAL, 0);
|
||||
|
||||
gReporter = yield getReporter("json_payload_simple");
|
||||
yield gReporter.collectMeasurements();
|
||||
let payload = yield gReporter.getJSONPayload(false);
|
||||
do_register_cleanup(() => gReporter._shutdown());
|
||||
|
||||
gPolicy = new Experiments.Policy();
|
||||
let dummyTimer = { cancel: () => {}, clear: () => {} };
|
||||
patchPolicy(gPolicy, {
|
||||
updatechannel: () => "nightly",
|
||||
healthReportPayload: () => Promise.resolve(payload),
|
||||
oneshotTimer: (callback, timeout, thisObj, name) => dummyTimer,
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user