Bug 1294811: Fix external tests that import head_addons.js. r=rhelmer

MozReview-Commit-ID: EWo7Gv9oSsz

--HG--
extra : rebase_source : e83863f0ef55f04be32a5062d0f672c8a3d88cb5
This commit is contained in:
Kris Maglione 2016-08-16 17:02:44 -07:00
Родитель 71550e4477
Коммит fd4b3a748c
8 изменённых файлов: 52 добавлений и 75 удалений

Просмотреть файл

@ -9,6 +9,10 @@ Cu.import("resource://gre/modules/Promise.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/osfile.jsm");
Cu.import("resource://testing-common/AddonManagerTesting.jsm");
Cu.import("resource://testing-common/AddonTestUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
"resource://gre/modules/AddonManager.jsm");
const PREF_EXPERIMENTS_ENABLED = "experiments.enabled";
const PREF_LOGGING_LEVEL = "experiments.logging.level";
@ -127,16 +131,16 @@ function dateToSeconds(date) {
var gGlobalScope = this;
function loadAddonManager() {
let ns = {};
Cu.import("resource://gre/modules/Services.jsm", ns);
let head = "../../../../toolkit/mozapps/extensions/test/xpcshell/head_addons.js";
let file = do_get_file(head);
let uri = ns.Services.io.newFileURI(file);
ns.Services.scriptloader.loadSubScript(uri.spec, gGlobalScope);
AddonTestUtils.init(gGlobalScope);
AddonTestUtils.overrideCertDB();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
startupManager();
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() {
@ -162,13 +166,8 @@ function getExperimentAddons(previous=false) {
function createAppInfo(ID="xpcshell@tests.mozilla.org", name="XPCShell",
version="1.0", platformVersion="1.0") {
let tmp = {};
Cu.import("resource://testing-common/AppInfo.jsm", tmp);
tmp.updateAppInfo({
ID, name, version, platformVersion,
crashReporter: true,
});
gAppInfo = tmp.getAppInfo();
AddonTestUtils.createAppInfo(ID, name, version, platformVersion);
gAppInfo = AddonTestUtils.appInfo;
}
/**

Просмотреть файл

@ -28,7 +28,7 @@ function uninstallExperimentAddons() {
return Task.spawn(function* () {
let addons = yield getExperimentAddons();
for (let a of addons) {
yield AddonTestUtils.uninstallAddonByID(a.id);
yield AddonManagerTesting.uninstallAddonByID(a.id);
}
});
}
@ -412,7 +412,7 @@ add_task(function* test_addonAlreadyInstalled() {
// Install conflicting addon.
yield AddonTestUtils.installXPIFromURL(gDataRoot + EXPERIMENT1_XPI_NAME, EXPERIMENT1_XPI_SHA1);
yield AddonManagerTesting.installXPIFromURL(gDataRoot + EXPERIMENT1_XPI_NAME, EXPERIMENT1_XPI_SHA1);
addons = yield getExperimentAddons();
Assert.equal(addons.length, 1, "1 add-on is installed.");
list = yield experiments.getExperiments();
@ -1407,7 +1407,7 @@ add_task(function* test_unexpectedUninstall() {
// Uninstall the addon through the addon manager instead of stopping it through
// the experiments API.
yield AddonTestUtils.uninstallAddonByID(EXPERIMENT1_ID);
yield AddonManagerTesting.uninstallAddonByID(EXPERIMENT1_ID);
yield experiments._mainTask;
yield experiments.notify();
@ -1433,7 +1433,7 @@ add_task(function* testUnknownExperimentsUninstalled() {
// Simulate us not listening.
experiments._unregisterWithAddonManager();
yield AddonTestUtils.installXPIFromURL(gDataRoot + EXPERIMENT1_XPI_NAME, EXPERIMENT1_XPI_SHA1);
yield AddonManagerTesting.installXPIFromURL(gDataRoot + EXPERIMENT1_XPI_NAME, EXPERIMENT1_XPI_SHA1);
experiments._registerWithAddonManager();
addons = yield getExperimentAddons();
@ -1472,7 +1472,7 @@ add_task(function* testForeignExperimentInstall() {
let failed = false;
try {
yield AddonTestUtils.installXPIFromURL(gDataRoot + EXPERIMENT1_XPI_NAME, EXPERIMENT1_XPI_SHA1);
yield AddonManagerTesting.installXPIFromURL(gDataRoot + EXPERIMENT1_XPI_NAME, EXPERIMENT1_XPI_SHA1);
} catch (ex) {
failed = true;
}
@ -1622,7 +1622,7 @@ add_task(function* test_foreignUninstallAndRestart() {
Assert.equal(addons.length, 1, "A single experiment add-on is installed.");
Assert.ok(addons[0].isActive, "That experiment is active.");
yield AddonTestUtils.uninstallAddonByID(EXPERIMENT1_ID);
yield AddonManagerTesting.uninstallAddonByID(EXPERIMENT1_ID);
yield experiments._mainTask;
addons = yield getExperimentAddons();

Просмотреть файл

@ -25,18 +25,6 @@ var gManifestHandlerURI = null;
const TLOG = bsp.TELEMETRY_LOG;
var gGlobalScope = this;
function loadAddonManager() {
let ns = {};
Cu.import("resource://gre/modules/Services.jsm", ns);
let head = "../../../../toolkit/mozapps/extensions/test/xpcshell/head_addons.js";
let file = do_get_file(head);
let uri = ns.Services.io.newFileURI(file);
ns.Services.scriptloader.loadSubScript(uri.spec, gGlobalScope);
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
startupManager();
}
function checkEvent(event, id, data)
{
do_print("Checking message " + id);

Просмотреть файл

@ -7,9 +7,16 @@ Cu.import("resource://gre/modules/TelemetryController.jsm", this);
Cu.import("resource://gre/modules/Services.jsm", this);
Cu.import("resource://gre/modules/PromiseUtils.jsm", this);
Cu.import("resource://gre/modules/Task.jsm", this);
Cu.import("resource://gre/modules/FileUtils.jsm", this);
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
Cu.import("resource://testing-common/httpd.js", this);
Cu.import("resource://gre/modules/AppConstants.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AddonTestUtils",
"resource://testing-common/AddonTestUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "OS",
"resource://gre/modules/osfile.jsm");
const gIsWindows = AppConstants.platform == "win";
const gIsMac = AppConstants.platform == "macosx";
const gIsAndroid = AppConstants.platform == "android";
@ -160,31 +167,24 @@ function wrapWithExceptionHandler(f) {
return wrapper;
}
function loadAddonManager(ID, name, version, platformVersion) {
let ns = {};
Cu.import("resource://gre/modules/Services.jsm", ns);
let head = "../../../../mozapps/extensions/test/xpcshell/head_addons.js";
let file = do_get_file(head);
let uri = ns.Services.io.newFileURI(file);
ns.Services.scriptloader.loadSubScript(uri.spec, gGlobalScope);
createAppInfo(ID, name, version, platformVersion);
function loadAddonManager(...args) {
AddonTestUtils.init(gGlobalScope);
AddonTestUtils.overrideCertDB();
createAppInfo(...args);
// As we're not running in application, we need to setup the features directory
// used by system add-ons.
const distroDir = FileUtils.getDir("ProfD", ["sysfeatures", "app0"], true);
registerDirectory("XREAppFeat", distroDir);
startupManager();
AddonTestUtils.registerDirectory("XREAppFeat", distroDir);
return AddonTestUtils.promiseStartupManager();
}
var gAppInfo = null;
function createAppInfo(ID, name, version, platformVersion) {
let tmp = {};
Cu.import("resource://testing-common/AppInfo.jsm", tmp);
tmp.updateAppInfo({
ID, name, version, platformVersion,
crashReporter: true,
});
gAppInfo = tmp.getAppInfo();
function createAppInfo(ID="xpcshell@tests.mozilla.org", name="XPCShell",
version="1.0", platformVersion="1.0") {
AddonTestUtils.createAppInfo(ID, name, version, platformVersion);
gAppInfo = AddonTestUtils.appInfo;
}
// Fake the timeout functions for the TelemetryScheduler.

Просмотреть файл

@ -907,13 +907,13 @@ add_task(function* test_addonsWatch_InterestingChange() {
// Test for receiving one notification after each change.
let checkpointPromise = registerCheckpointPromise(1);
yield AddonTestUtils.installXPIFromURL(ADDON_INSTALL_URL);
yield AddonManagerTesting.installXPIFromURL(ADDON_INSTALL_URL);
yield checkpointPromise;
assertCheckpoint(1);
Assert.ok(ADDON_ID in TelemetryEnvironment.currentEnvironment.addons.activeAddons);
checkpointPromise = registerCheckpointPromise(2);
let addon = yield AddonTestUtils.getAddonById(ADDON_ID);
let addon = yield AddonManagerTesting.getAddonById(ADDON_ID);
addon.userDisabled = true;
yield checkpointPromise;
assertCheckpoint(2);
@ -926,7 +926,7 @@ add_task(function* test_addonsWatch_InterestingChange() {
Assert.ok(ADDON_ID in TelemetryEnvironment.currentEnvironment.addons.activeAddons);
checkpointPromise = registerCheckpointPromise(4);
yield AddonTestUtils.uninstallAddonByID(ADDON_ID);
yield AddonManagerTesting.uninstallAddonByID(ADDON_ID);
yield checkpointPromise;
assertCheckpoint(4);
Assert.ok(!(ADDON_ID in TelemetryEnvironment.currentEnvironment.addons.activeAddons));
@ -1017,8 +1017,8 @@ add_task(function* test_addonsWatch_NotInterestingChange() {
deferred.resolve();
});
yield AddonTestUtils.installXPIFromURL(DICTIONARY_ADDON_INSTALL_URL);
yield AddonTestUtils.installXPIFromURL(INTERESTING_ADDON_INSTALL_URL);
yield AddonManagerTesting.installXPIFromURL(DICTIONARY_ADDON_INSTALL_URL);
yield AddonManagerTesting.installXPIFromURL(INTERESTING_ADDON_INSTALL_URL);
yield deferred.promise;
Assert.ok(!("telemetry-dictionary@tests.mozilla.org" in
@ -1076,7 +1076,7 @@ add_task(function* test_addonsAndPlugins() {
};
// Install an addon so we have some data.
yield AddonTestUtils.installXPIFromURL(ADDON_INSTALL_URL);
yield AddonManagerTesting.installXPIFromURL(ADDON_INSTALL_URL);
let data = TelemetryEnvironment.currentEnvironment;
checkEnvironmentData(data);
@ -1117,7 +1117,7 @@ add_task(function* test_addonsAndPlugins() {
Assert.equal(data.addons.persona, personaId, "The correct Persona Id must be reported.");
// Uninstall the addon.
yield AddonTestUtils.uninstallAddonByID(ADDON_ID);
yield AddonManagerTesting.uninstallAddonByID(ADDON_ID);
});
add_task(function* test_signedAddon() {
@ -1146,7 +1146,7 @@ add_task(function* test_signedAddon() {
TelemetryEnvironment.registerChangeListener("test_signedAddon", deferred.resolve);
// Install the addon.
yield AddonTestUtils.installXPIFromURL(ADDON_INSTALL_URL);
yield AddonManagerTesting.installXPIFromURL(ADDON_INSTALL_URL);
yield deferred.promise;
// Unregister the listener.
@ -1173,7 +1173,7 @@ add_task(function* test_addonsFieldsLimit() {
// Install the addon and wait for the TelemetryEnvironment to pick it up.
let deferred = PromiseUtils.defer();
TelemetryEnvironment.registerChangeListener("test_longFieldsAddon", deferred.resolve);
yield AddonTestUtils.installXPIFromURL(ADDON_INSTALL_URL);
yield AddonManagerTesting.installXPIFromURL(ADDON_INSTALL_URL);
yield deferred.promise;
TelemetryEnvironment.unregisterChangeListener("test_longFieldsAddon");
@ -1255,7 +1255,7 @@ add_task(function* test_collectionWithbrokenAddonData() {
gNow = fakeNow(futureDate(gNow, 10 * MILLISECONDS_PER_MINUTE));
// Now install an addon which returns the correct information.
checkpointPromise = registerCheckpointPromise(2);
yield AddonTestUtils.installXPIFromURL(ADDON_INSTALL_URL);
yield AddonManagerTesting.installXPIFromURL(ADDON_INSTALL_URL);
yield checkpointPromise;
assertCheckpoint(2);
@ -1278,7 +1278,7 @@ add_task(function* test_collectionWithbrokenAddonData() {
AddonManagerPrivate.unregisterProvider(brokenAddonProvider);
// Uninstall the valid addon.
yield AddonTestUtils.uninstallAddonByID(ADDON_ID);
yield AddonManagerTesting.uninstallAddonByID(ADDON_ID);
});
add_task(function* test_changeThrottling() {

Просмотреть файл

@ -16,16 +16,6 @@ Cu.import("resource://testing-common/AppInfo.jsm");
updateAppInfo();
var gGlobalScope = this;
function loadAddonManager() {
let ns = {};
Cu.import("resource://gre/modules/Services.jsm", ns);
let head = "../../../../mozapps/extensions/test/xpcshell/head_addons.js";
let file = do_get_file(head);
let uri = ns.Services.io.newFileURI(file);
ns.Services.scriptloader.loadSubScript(uri.spec, gGlobalScope);
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
startupManager();
}
function getSimpleMeasurementsFromTelemetryController() {
return TelemetrySession.getPayload().simpleMeasurements;

Просмотреть файл

@ -8,7 +8,7 @@
"use strict";
this.EXPORTED_SYMBOLS = [
"AddonTestUtils",
"AddonManagerTesting",
];
const {utils: Cu} = Components;
@ -19,7 +19,7 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
"resource://gre/modules/AddonManager.jsm");
this.AddonTestUtils = {
this.AddonManagerTesting = {
/**
* Get the add-on that is specified by its ID.
*

Просмотреть файл

@ -4,7 +4,7 @@
Components.utils.import("resource://gre/modules/Promise.jsm", this);
var {AddonTestUtils} = Components.utils.import("resource://testing-common/AddonManagerTesting.jsm", {});
var {AddonManagerTesting} = Components.utils.import("resource://testing-common/AddonManagerTesting.jsm", {});
var {HttpServer} = Components.utils.import("resource://testing-common/httpd.js", {});
var gManagerWindow;
@ -254,7 +254,7 @@ add_task(function* testButtonPresence() {
// Remove the add-on we've been testing with.
add_task(function* testCleanup() {
yield AddonTestUtils.uninstallAddonByID("test-experiment1@experiments.mozilla.org");
yield AddonManagerTesting.uninstallAddonByID("test-experiment1@experiments.mozilla.org");
// Verify some conditions, just in case.
let addons = yield getExperimentAddons();
Assert.equal(addons.length, 0, "No experiment add-ons are installed.");