Bug 1233492 - make browser/experiments eslintable, r=felipe

This commit is contained in:
Gijs Kruitbosch 2015-12-17 19:42:24 +00:00
parent 9bfa781081
commit c6feda4ec8
5 changed files with 54 additions and 38 deletions

View File

@ -78,7 +78,6 @@ browser/components/shell/**
browser/components/tabview/**
browser/components/translation/**
browser/components/uitour/**
browser/experiments/**
browser/extensions/pdfjs/**
browser/extensions/shumway/**
browser/fuel/**

View File

@ -175,7 +175,7 @@ function addonInstallForURL(url, hash) {
function installedExperimentAddons() {
let deferred = Promise.defer();
AddonManager.getAddonsByTypes(["experiment"], (addons) => {
deferred.resolve([a for (a of addons) if (!a.appDisabled)]);
deferred.resolve(addons.filter(a => !a.appDisabled));
});
return deferred.promise;
}
@ -183,7 +183,7 @@ function installedExperimentAddons() {
// Takes an Array<Addon> and returns a promise that is resolved when the
// addons are uninstalled.
function uninstallAddons(addons) {
let ids = new Set([a.id for (a of addons)]);
let ids = new Set(addons.map(addon => addon.id));
let deferred = Promise.defer();
let listener = {};
@ -463,11 +463,12 @@ Experiments.Experiments.prototype = {
try {
this._log.trace("uninit: waiting on _mainTask");
yield this._mainTask;
} catch (e if e instanceof AlreadyShutdownError) {
// We error out of tasks after shutdown via that exception.
} catch (e) {
this._latestError = e;
throw e;
// We error out of tasks after shutdown via this exception.
if (!(e instanceof AlreadyShutdownError)) {
this._latestError = e;
throw e;
}
}
}
@ -760,19 +761,23 @@ Experiments.Experiments.prototype = {
this._mainTask = Task.spawn(function*() {
try {
yield this._main();
} catch (e if e instanceof CacheWriteError) {
// In this case we want to reschedule
} catch (e) {
this._log.error("_main caught error: " + e);
return;
// In the CacheWriteError case we want to reschedule
if (!(e instanceof CacheWriteError)) {
this._log.error("_main caught error: " + e);
return;
}
} finally {
this._mainTask = null;
}
this._log.trace("_main finished, scheduling next run");
try {
yield this._scheduleNextRun();
} catch (ex if ex instanceof AlreadyShutdownError) {
// We error out of tasks after shutdown via that exception.
} catch (ex) {
// We error out of tasks after shutdown via this exception.
if (!(ex instanceof AlreadyShutdownError)) {
throw ex;
}
}
}.bind(this));
}
@ -866,15 +871,18 @@ Experiments.Experiments.prototype = {
this.disableExperiment(TELEMETRY_LOG.TERMINATION.ADDON_UNINSTALLED);
},
/**
* @returns {Boolean} returns false when we cancel the install.
*/
onInstallStarted: function (install) {
if (install.addon.type != "experiment") {
return;
return true;
}
this._log.trace("onInstallStarted() - " + install.addon.id);
if (install.addon.appDisabled) {
// This is a PreviousExperiment
return;
return true;
}
// We want to be in control of all experiment add-ons: reject installs
@ -894,13 +902,13 @@ Experiments.Experiments.prototype = {
if (this._trackedAddonIds.has(install.addon.id)) {
this._log.info("onInstallStarted allowing install because add-on ID " +
"tracked by us.");
return;
return true;
}
if (gActiveInstallURLs.has(install.sourceURI.spec)) {
this._log.info("onInstallStarted allowing install because install " +
"tracked by us.");
return;
return true;
}
this._log.warn("onInstallStarted cancelling install of unknown " +
@ -985,7 +993,7 @@ Experiments.Experiments.prototype = {
try {
let textData = JSON.stringify({
version: CACHE_VERSION,
data: [e[1].toJSON() for (e of this._experiments.entries())],
data: [...this._experiments.values()].map(e => e.toJSON()),
});
let encoder = new TextEncoder();
@ -1011,9 +1019,13 @@ Experiments.Experiments.prototype = {
try {
let result = yield loadJSONAsync(path, { compression: "lz4" });
this._populateFromCache(result);
} catch (e if e instanceof OS.File.Error && e.becauseNoSuchFile) {
// No cached manifest yet.
this._experiments = new Map();
} catch (e) {
if (e instanceof OS.File.Error && e.becauseNoSuchFile) {
// No cached manifest yet.
this._experiments = new Map();
} else {
throw e;
}
}
}),
@ -1116,7 +1128,7 @@ Experiments.Experiments.prototype = {
},
_getActiveExperiment: function () {
let enabled = [experiment for ([,experiment] of this._experiments) if (experiment._enabled)];
let enabled = [...this._experiments.values()].filter(experiment => experiment._enabled);
if (enabled.length == 1) {
return enabled[0];
@ -1153,7 +1165,7 @@ Experiments.Experiments.prototype = {
return new Set();
}
return new Set([e._addonId for ([,e] of this._experiments) if (e._addonId)]);
return new Set([...this._experiments.values()].map(e => e._addonId));
},
/*
@ -1181,10 +1193,10 @@ Experiments.Experiments.prototype = {
// knowledge for these unknown experiment add-ons.
let installedExperiments = yield installedExperimentAddons();
let expectedAddonIds = this._trackedAddonIds;
let unknownAddons = [a for (a of installedExperiments) if (!expectedAddonIds.has(a.id))];
let unknownAddons = installedExperiments.filter(a => !expectedAddonIds.has(a.id));
if (unknownAddons.length) {
this._log.warn("_evaluateExperiments() - unknown add-ons in AddonManager: " +
[a.id for (a of unknownAddons)].join(", "));
unknownAddons.map(a => a.id).join(", "));
yield uninstallAddons(unknownAddons);
}
@ -2263,18 +2275,18 @@ this.Experiments.PreviousExperimentProvider.prototype = Object.freeze({
return;
}
cb([new PreviousExperimentAddon(e) for (e of this._experimentList)]);
cb(this._experimentList.map(e => new PreviousExperimentAddon(e)));
},
_updateExperimentList: function () {
return this._experiments.getExperiments().then((experiments) => {
let list = [e for (e of experiments) if (!e.active)];
let list = experiments.filter(e => !e.active);
let newMap = new Map([[e.id, e] for (e of list)]);
let oldMap = new Map([[e.id, e] for (e of this._experimentList)]);
let newMap = new Map(list.map(e => [e.id, e]));
let oldMap = new Map(this._experimentList.map(e => [e.id, e]));
let added = [e.id for (e of list) if (!oldMap.has(e.id))];
let removed = [e.id for (e of this._experimentList) if (!newMap.has(e.id))];
let added = [...newMap.keys()].filter(id => !oldMap.has(id));
let removed = [...oldMap.keys()].filter(id => !newMap.has(id));
for (let id of added) {
this._log.trace("updateExperimentList() - adding " + id);

View File

@ -38,9 +38,11 @@ function sha1File(path) {
is.close();
let bytes = hasher.finish(false);
return [("0" + bytes.charCodeAt(byte).toString(16)).slice(-2)
for (byte in bytes)]
.join("");
let rv = "";
for (let i = 0; i < bytes.length; i++) {
rv += ("0" + bytes.charCodeAt(i).toString(16)).substr(-2);
}
return rv;
}
const EXPERIMENT1_ID = "test-experiment-1@tests.mozilla.org";
@ -153,7 +155,7 @@ function getExperimentAddons(previous=false) {
if (previous) {
deferred.resolve(addons);
} else {
deferred.resolve([a for (a of addons) if (!a.appDisabled)]);
deferred.resolve(addons.filter(a => !a.appDisabled));
}
});

View File

@ -156,8 +156,11 @@ add_task(function* test_disableExperiments() {
try {
yield experiments.updateManifest();
} catch (e if e.message == "experiments are disabled") {
// This exception is expected.
} catch (e) {
// This exception is expected, we rethrow everything else
if (e.message != "experiments are disabled") {
throw e;
}
}
experiments.notify();

View File

@ -40,7 +40,7 @@ add_test(function setup() {
run_next_test();
});
add_task(function test_constructor() {
add_task(function* test_constructor() {
Experiments.instance();
yield Experiments._mainTask;
let provider = new ExperimentsProvider();