mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-05 05:30:29 +00:00
Bug 1220911: Switch test_experiment.js to task style. r=rhelmer
Before changing the handling of experiments make the tests a bit more readable and use BootstrapMonitor to verify things. --HG-- extra : commitid : LnQTmpOqRgj extra : rebase_source : be63740ca7613bf685c9d69722e9fb2e1bb0d5e3
This commit is contained in:
parent
95d4a64276
commit
0ca2ae256e
1
toolkit/mozapps/extensions/test/addons/test_experiment1/bootstrap.js
vendored
Normal file
1
toolkit/mozapps/extensions/test/addons/test_experiment1/bootstrap.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Components.utils.import("resource://xpcshell-data/BootstrapMonitor.jsm").monitor(this);
|
@ -1404,6 +1404,23 @@ function ensure_test_completed() {
|
|||||||
do_check_eq(gExpectedInstalls.length, 0);
|
do_check_eq(gExpectedInstalls.length, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a promise that resolves when the given add-on event is fired. The
|
||||||
|
* resolved value is an array of arguments passed for the event.
|
||||||
|
*/
|
||||||
|
function promiseAddonEvent(event) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
let listener = {
|
||||||
|
[event]: function(...args) {
|
||||||
|
AddonManager.removeAddonListener(listener);
|
||||||
|
resolve(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AddonManager.addAddonListener(listener);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper method to install an array of AddonInstall to completion and then
|
* A helper method to install an array of AddonInstall to completion and then
|
||||||
* call a provided callback.
|
* call a provided callback.
|
||||||
|
@ -3,10 +3,12 @@
|
|||||||
|
|
||||||
var scope = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm");
|
var scope = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm");
|
||||||
const XPIProvider = scope.XPIProvider;
|
const XPIProvider = scope.XPIProvider;
|
||||||
|
const ID = "experiment1@tests.mozilla.org";
|
||||||
|
|
||||||
var gIsNightly = false;
|
var gIsNightly = false;
|
||||||
|
|
||||||
function run_test() {
|
function run_test() {
|
||||||
|
BootstrapMonitor.init();
|
||||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
|
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
|
||||||
startupManager();
|
startupManager();
|
||||||
|
|
||||||
@ -15,115 +17,115 @@ function run_test() {
|
|||||||
run_next_test();
|
run_next_test();
|
||||||
}
|
}
|
||||||
|
|
||||||
add_test(function test_experiment() {
|
add_task(function* test_experiment() {
|
||||||
AddonManager.getInstallForFile(do_get_addon("test_experiment1"), (install) => {
|
BootstrapMonitor.checkAddonNotInstalled(ID);
|
||||||
completeAllInstalls([install], () => {
|
BootstrapMonitor.checkAddonNotStarted(ID);
|
||||||
AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
|
|
||||||
Assert.ok(addon, "Addon is found.");
|
|
||||||
|
|
||||||
Assert.ok(addon.userDisabled, "Experiments are userDisabled by default.");
|
yield promiseInstallAllFiles([do_get_addon("test_experiment1")]);
|
||||||
Assert.ok(!addon.appDisabled, "Experiments are not appDisabled by compatibility.");
|
|
||||||
Assert.equal(addon.isActive, false, "Add-on is not active.");
|
|
||||||
Assert.equal(addon.updateURL, null, "No updateURL for experiments.");
|
|
||||||
Assert.equal(addon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE,
|
|
||||||
"Background updates are disabled.");
|
|
||||||
Assert.equal(addon.permissions, AddonManager.PERM_CAN_UNINSTALL,
|
|
||||||
"Permissions are minimal.");
|
|
||||||
Assert.ok(!(addon.pendingOperations & AddonManager.PENDING_ENABLE),
|
|
||||||
"Should not be pending enable");
|
|
||||||
Assert.ok(!(addon.pendingOperations & AddonManager.PENDING_DISABLE),
|
|
||||||
"Should not be pending disable");
|
|
||||||
|
|
||||||
// Setting applyBackgroundUpdates should not work.
|
BootstrapMonitor.checkAddonInstalled(ID, "1.0");
|
||||||
addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE;
|
BootstrapMonitor.checkAddonNotStarted(ID);
|
||||||
Assert.equal(addon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE,
|
|
||||||
"Setting applyBackgroundUpdates shouldn't do anything.");
|
|
||||||
|
|
||||||
let noCompatibleCalled = false;
|
let addon = yield promiseAddonByID(ID);
|
||||||
let noUpdateCalled = false;
|
Assert.ok(addon, "Addon is found.");
|
||||||
let finishedCalled = false;
|
|
||||||
|
|
||||||
let listener = {
|
Assert.ok(addon.userDisabled, "Experiments are userDisabled by default.");
|
||||||
onNoCompatibilityUpdateAvailable: () => { noCompatibleCalled = true; },
|
Assert.ok(!addon.appDisabled, "Experiments are not appDisabled by compatibility.");
|
||||||
onNoUpdateAvailable: () => { noUpdateCalled = true; },
|
Assert.equal(addon.isActive, false, "Add-on is not active.");
|
||||||
onUpdateFinished: () => { finishedCalled = true; },
|
Assert.equal(addon.updateURL, null, "No updateURL for experiments.");
|
||||||
};
|
Assert.equal(addon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE,
|
||||||
|
"Background updates are disabled.");
|
||||||
|
Assert.equal(addon.permissions, AddonManager.PERM_CAN_UNINSTALL,
|
||||||
|
"Permissions are minimal.");
|
||||||
|
Assert.ok(!(addon.pendingOperations & AddonManager.PENDING_ENABLE),
|
||||||
|
"Should not be pending enable");
|
||||||
|
Assert.ok(!(addon.pendingOperations & AddonManager.PENDING_DISABLE),
|
||||||
|
"Should not be pending disable");
|
||||||
|
|
||||||
addon.findUpdates(listener, "testing", null, null);
|
// Setting applyBackgroundUpdates should not work.
|
||||||
Assert.ok(noCompatibleCalled, "Listener called.");
|
addon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE;
|
||||||
Assert.ok(noUpdateCalled, "Listener called.");
|
Assert.equal(addon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE,
|
||||||
Assert.ok(finishedCalled, "Listener called.");
|
"Setting applyBackgroundUpdates shouldn't do anything.");
|
||||||
|
|
||||||
run_next_test();
|
let noCompatibleCalled = false;
|
||||||
});
|
let noUpdateCalled = false;
|
||||||
});
|
let finishedCalled = false;
|
||||||
});
|
|
||||||
|
let listener = {
|
||||||
|
onNoCompatibilityUpdateAvailable: () => { noCompatibleCalled = true; },
|
||||||
|
onNoUpdateAvailable: () => { noUpdateCalled = true; },
|
||||||
|
onUpdateFinished: () => { finishedCalled = true; },
|
||||||
|
};
|
||||||
|
|
||||||
|
addon.findUpdates(listener, "testing", null, null);
|
||||||
|
Assert.ok(noCompatibleCalled, "Listener called.");
|
||||||
|
Assert.ok(noUpdateCalled, "Listener called.");
|
||||||
|
Assert.ok(finishedCalled, "Listener called.");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Changes to userDisabled should not be persisted to the database.
|
// Changes to userDisabled should not be persisted to the database.
|
||||||
add_test(function test_userDisabledNotPersisted() {
|
add_task(function* test_userDisabledNotPersisted() {
|
||||||
AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
|
let addon = yield promiseAddonByID(ID);
|
||||||
Assert.ok(addon, "Add-on is found.");
|
Assert.ok(addon, "Add-on is found.");
|
||||||
Assert.ok(addon.userDisabled, "Add-on is user disabled.");
|
Assert.ok(addon.userDisabled, "Add-on is user disabled.");
|
||||||
|
|
||||||
let listener = {
|
let promise = promiseAddonEvent("onEnabled");
|
||||||
onEnabled: (addon2) => {
|
addon.userDisabled = false;
|
||||||
AddonManager.removeAddonListener(listener);
|
let [addon2] = yield promise;
|
||||||
|
|
||||||
Assert.equal(addon2.id, addon.id, "Changed add-on matches expected.");
|
BootstrapMonitor.checkAddonInstalled(ID, "1.0");
|
||||||
Assert.equal(addon2.userDisabled, false, "Add-on is no longer user disabled.");
|
BootstrapMonitor.checkAddonStarted(ID, "1.0");
|
||||||
Assert.ok(addon2.isActive, "Add-on is active.");
|
|
||||||
|
|
||||||
Assert.ok("experiment1@tests.mozilla.org" in XPIProvider.bootstrappedAddons,
|
Assert.equal(addon2.id, addon.id, "Changed add-on matches expected.");
|
||||||
"Experiment add-on listed in XPIProvider bootstrapped list.");
|
Assert.equal(addon2.userDisabled, false, "Add-on is no longer user disabled.");
|
||||||
|
Assert.ok(addon2.isActive, "Add-on is active.");
|
||||||
|
|
||||||
AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
|
Assert.ok(ID in XPIProvider.bootstrappedAddons,
|
||||||
Assert.ok(addon, "Add-on retrieved.");
|
"Experiment add-on listed in XPIProvider bootstrapped list.");
|
||||||
Assert.equal(addon.userDisabled, false, "Add-on is still enabled after API retrieve.");
|
|
||||||
Assert.ok(addon.isActive, "Add-on is still active.");
|
|
||||||
Assert.ok(!(addon.pendingOperations & AddonManager.PENDING_ENABLE),
|
|
||||||
"Should not be pending enable");
|
|
||||||
Assert.ok(!(addon.pendingOperations & AddonManager.PENDING_DISABLE),
|
|
||||||
"Should not be pending disable");
|
|
||||||
|
|
||||||
// Now when we restart the manager the add-on should revert state.
|
addon = yield promiseAddonByID(ID);
|
||||||
restartManager();
|
Assert.ok(addon, "Add-on retrieved.");
|
||||||
let persisted = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons"));
|
Assert.equal(addon.userDisabled, false, "Add-on is still enabled after API retrieve.");
|
||||||
Assert.ok(!("experiment1@tests.mozilla.org" in persisted),
|
Assert.ok(addon.isActive, "Add-on is still active.");
|
||||||
"Experiment add-on not persisted to bootstrappedAddons.");
|
Assert.ok(!(addon.pendingOperations & AddonManager.PENDING_ENABLE),
|
||||||
|
"Should not be pending enable");
|
||||||
|
Assert.ok(!(addon.pendingOperations & AddonManager.PENDING_DISABLE),
|
||||||
|
"Should not be pending disable");
|
||||||
|
|
||||||
AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
|
// Now when we restart the manager the add-on should revert state.
|
||||||
Assert.ok(addon, "Add-on retrieved.");
|
yield promiseRestartManager();
|
||||||
Assert.ok(addon.userDisabled, "Add-on is disabled after restart.");
|
let persisted = JSON.parse(Services.prefs.getCharPref("extensions.bootstrappedAddons"));
|
||||||
Assert.equal(addon.isActive, false, "Add-on is not active after restart.");
|
Assert.ok(!(ID in persisted),
|
||||||
addon.uninstall();
|
"Experiment add-on not persisted to bootstrappedAddons.");
|
||||||
|
|
||||||
run_next_test();
|
BootstrapMonitor.checkAddonInstalled(ID, "1.0");
|
||||||
});
|
BootstrapMonitor.checkAddonNotStarted(ID);
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
AddonManager.addAddonListener(listener);
|
addon = yield promiseAddonByID(ID);
|
||||||
addon.userDisabled = false;
|
Assert.ok(addon, "Add-on retrieved.");
|
||||||
});
|
Assert.ok(addon.userDisabled, "Add-on is disabled after restart.");
|
||||||
|
Assert.equal(addon.isActive, false, "Add-on is not active after restart.");
|
||||||
|
addon.uninstall();
|
||||||
|
|
||||||
|
BootstrapMonitor.checkAddonNotInstalled(ID);
|
||||||
|
BootstrapMonitor.checkAddonNotStarted(ID);
|
||||||
});
|
});
|
||||||
|
|
||||||
add_test(function test_checkCompatibility() {
|
add_task(function test_checkCompatibility() {
|
||||||
if (gIsNightly)
|
if (gIsNightly)
|
||||||
Services.prefs.setBoolPref("extensions.checkCompatibility.nightly", false);
|
Services.prefs.setBoolPref("extensions.checkCompatibility.nightly", false);
|
||||||
else
|
else
|
||||||
Services.prefs.setBoolPref("extensions.checkCompatibility.1", false);
|
Services.prefs.setBoolPref("extensions.checkCompatibility.1", false);
|
||||||
|
|
||||||
restartManager();
|
yield promiseRestartManager();
|
||||||
|
|
||||||
installAllFiles([do_get_addon("test_experiment1")], () => {
|
yield promiseInstallAllFiles([do_get_addon("test_experiment1")]);
|
||||||
AddonManager.getAddonByID("experiment1@tests.mozilla.org", (addon) => {
|
let addon = yield promiseAddonByID(ID);
|
||||||
Assert.ok(addon, "Add-on is found.");
|
|
||||||
Assert.ok(addon.userDisabled, "Add-on is user disabled.");
|
|
||||||
Assert.ok(!addon.appDisabled, "Add-on is not app disabled.");
|
|
||||||
|
|
||||||
run_next_test();
|
BootstrapMonitor.checkAddonInstalled(ID, "1.0");
|
||||||
});
|
BootstrapMonitor.checkAddonNotStarted(ID);
|
||||||
});
|
|
||||||
|
Assert.ok(addon, "Add-on is found.");
|
||||||
|
Assert.ok(addon.userDisabled, "Add-on is user disabled.");
|
||||||
|
Assert.ok(!addon.appDisabled, "Add-on is not app disabled.");
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user