forked from mirrors/gecko-dev
This patch was autogenerated by my decomponents.py
It covers almost every file with the extension js, jsm, html, py,
xhtml, or xul.
It removes blank lines after removed lines, when the removed lines are
preceded by either blank lines or the start of a new block. The "start
of a new block" is defined fairly hackily: either the line starts with
//, ends with */, ends with {, <![CDATA[, """ or '''. The first two
cover comments, the third one covers JS, the fourth covers JS embedded
in XUL, and the final two cover JS embedded in Python. This also
applies if the removed line was the first line of the file.
It covers the pattern matching cases like "var {classes: Cc,
interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove
the entire thing if they are all either Ci, Cr, Cc or Cu, or it will
remove the appropriate ones and leave the residue behind. If there's
only one behind, then it will turn it into a normal, non-pattern
matching variable definition. (For instance, "const { classes: Cc,
Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes
"const CC = Components.Constructor".)
MozReview-Commit-ID: DeSHcClQ7cG
--HG--
extra : rebase_source : d9c41878036c1ef7766ef5e91a7005025bc1d72b
193 lines
6.1 KiB
JavaScript
193 lines
6.1 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
/* exported PREF_EXPERIMENTS_ENABLED, PREF_LOGGING_LEVEL, PREF_LOGGING_DUMP
|
|
PREF_MANIFEST_URI, PREF_FETCHINTERVAL, EXPERIMENT1_ID,
|
|
EXPERIMENT1_NAME, EXPERIMENT1_XPI_SHA1, EXPERIMENT1A_NAME,
|
|
EXPERIMENT1A_XPI_SHA1, EXPERIMENT2_ID, EXPERIMENT2_XPI_SHA1,
|
|
EXPERIMENT3_ID, EXPERIMENT4_ID, FAKE_EXPERIMENTS_1,
|
|
FAKE_EXPERIMENTS_2, gAppInfo, removeCacheFile, defineNow,
|
|
futureDate, dateToSeconds, loadAddonManager, promiseRestartManager,
|
|
startAddonManagerOnly, getExperimentAddons, replaceExperiments */
|
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
|
ChromeUtils.import("resource://testing-common/AddonManagerTesting.jsm");
|
|
ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "AddonManager",
|
|
"resource://gre/modules/AddonManager.jsm");
|
|
|
|
const PREF_EXPERIMENTS_ENABLED = "experiments.enabled";
|
|
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";
|
|
|
|
function getExperimentPath(base) {
|
|
let p = do_get_cwd();
|
|
p.append(base);
|
|
return p.path;
|
|
}
|
|
|
|
function sha1File(path) {
|
|
let f = Cc["@mozilla.org/file/local;1"]
|
|
.createInstance(Ci.nsIFile);
|
|
f.initWithPath(path);
|
|
let hasher = Cc["@mozilla.org/security/hash;1"]
|
|
.createInstance(Ci.nsICryptoHash);
|
|
hasher.init(hasher.SHA1);
|
|
|
|
let is = Cc["@mozilla.org/network/file-input-stream;1"]
|
|
.createInstance(Ci.nsIFileInputStream);
|
|
is.init(f, -1, 0, 0);
|
|
hasher.updateFromStream(is, Math.pow(2, 32) - 1);
|
|
is.close();
|
|
let bytes = hasher.finish(false);
|
|
|
|
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";
|
|
const EXPERIMENT1_XPI_NAME = "experiment-1.xpi";
|
|
const EXPERIMENT1_NAME = "Test experiment 1";
|
|
const EXPERIMENT1_PATH = getExperimentPath(EXPERIMENT1_XPI_NAME);
|
|
const EXPERIMENT1_XPI_SHA1 = "sha1:" + sha1File(EXPERIMENT1_PATH);
|
|
|
|
|
|
const EXPERIMENT1A_XPI_NAME = "experiment-1a.xpi";
|
|
const EXPERIMENT1A_NAME = "Test experiment 1.1";
|
|
const EXPERIMENT1A_PATH = getExperimentPath(EXPERIMENT1A_XPI_NAME);
|
|
const EXPERIMENT1A_XPI_SHA1 = "sha1:" + sha1File(EXPERIMENT1A_PATH);
|
|
|
|
const EXPERIMENT2_ID = "test-experiment-2@tests.mozilla.org";
|
|
const EXPERIMENT2_XPI_NAME = "experiment-2.xpi";
|
|
const EXPERIMENT2_PATH = getExperimentPath(EXPERIMENT2_XPI_NAME);
|
|
const EXPERIMENT2_XPI_SHA1 = "sha1:" + sha1File(EXPERIMENT2_PATH);
|
|
|
|
const EXPERIMENT3_ID = "test-experiment-3@tests.mozilla.org";
|
|
const EXPERIMENT4_ID = "test-experiment-4@tests.mozilla.org";
|
|
|
|
const FAKE_EXPERIMENTS_1 = [
|
|
{
|
|
id: "id1",
|
|
name: "experiment1",
|
|
description: "experiment 1",
|
|
active: true,
|
|
detailUrl: "https://dummy/experiment1",
|
|
branch: "foo",
|
|
},
|
|
];
|
|
|
|
const FAKE_EXPERIMENTS_2 = [
|
|
{
|
|
id: "id2",
|
|
name: "experiment2",
|
|
description: "experiment 2",
|
|
active: false,
|
|
endDate: new Date(2014, 2, 11, 2, 4, 35, 42).getTime(),
|
|
detailUrl: "https://dummy/experiment2",
|
|
branch: null,
|
|
},
|
|
{
|
|
id: "id1",
|
|
name: "experiment1",
|
|
description: "experiment 1",
|
|
active: false,
|
|
endDate: new Date(2014, 2, 10, 0, 0, 0, 0).getTime(),
|
|
detailURL: "https://dummy/experiment1",
|
|
branch: null,
|
|
},
|
|
];
|
|
|
|
var gAppInfo = null;
|
|
|
|
function removeCacheFile() {
|
|
let path = OS.Path.join(OS.Constants.Path.profileDir, "experiments.json");
|
|
return OS.File.remove(path);
|
|
}
|
|
|
|
function patchPolicy(policy, data) {
|
|
for (let key of Object.keys(data)) {
|
|
Object.defineProperty(policy, key, {
|
|
value: data[key],
|
|
writable: true,
|
|
});
|
|
}
|
|
}
|
|
|
|
function defineNow(policy, time) {
|
|
patchPolicy(policy, { now: () => new Date(time) });
|
|
}
|
|
|
|
function futureDate(date, offset) {
|
|
return new Date(date.getTime() + offset);
|
|
}
|
|
|
|
function dateToSeconds(date) {
|
|
return date.getTime() / 1000;
|
|
}
|
|
|
|
var gGlobalScope = this;
|
|
function loadAddonManager() {
|
|
AddonTestUtils.init(gGlobalScope);
|
|
AddonTestUtils.overrideCertDB();
|
|
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
|
|
return AddonTestUtils.promiseStartupManager();
|
|
}
|
|
|
|
const {
|
|
promiseRestartManager,
|
|
} = AddonTestUtils;
|
|
|
|
// Starts the addon manager without creating app info. We can't directly use
|
|
// |loadAddonManager| defined above in test_conditions.js as it would make the test fail.
|
|
function startAddonManagerOnly() {
|
|
let addonManager = Cc["@mozilla.org/addons/integration;1"]
|
|
.getService(Ci.nsIObserver)
|
|
.QueryInterface(Ci.nsITimerCallback);
|
|
addonManager.observe(null, "addons-startup", null);
|
|
Services.obs.notifyObservers(null, "sessionstore-windows-restored");
|
|
}
|
|
|
|
function getExperimentAddons(previous = false) {
|
|
return new Promise(resolve => {
|
|
|
|
AddonManager.getAddonsByTypes(["experiment"], (addons) => {
|
|
if (previous) {
|
|
resolve(addons);
|
|
} else {
|
|
resolve(addons.filter(a => !a.appDisabled));
|
|
}
|
|
});
|
|
|
|
});
|
|
}
|
|
|
|
function createAppInfo(ID = "xpcshell@tests.mozilla.org", name = "XPCShell",
|
|
version = "1.0", platformVersion = "1.0") {
|
|
AddonTestUtils.createAppInfo(ID, name, version, platformVersion);
|
|
gAppInfo = AddonTestUtils.appInfo;
|
|
}
|
|
|
|
/**
|
|
* Replace the experiments on an Experiments with a new list.
|
|
*
|
|
* This monkeypatches getExperiments(). It doesn't monkeypatch the internal
|
|
* experiments list. So its utility is not as great as it could be.
|
|
*/
|
|
function replaceExperiments(experiment, list) {
|
|
Object.defineProperty(experiment, "getExperiments", {
|
|
writable: true,
|
|
value: () => {
|
|
return Promise.resolve(list);
|
|
},
|
|
});
|
|
}
|
|
|
|
Services.telemetry.canRecordExtended = true;
|