Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Bug 864745 Reject promise when invalid IDs given to disable, uninstal…
Browse files Browse the repository at this point in the history
…l in addon installer
  • Loading branch information
jsantell committed Sep 6, 2013
1 parent 97838a0 commit e150a1f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
20 changes: 12 additions & 8 deletions lib/sdk/addon/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,24 @@ exports.uninstall = function uninstall(addonId) {
AddonManager.addAddonListener(listener);

// Order Addonmanager to uninstall the addon
AddonManager.getAddonByID(addonId, function (addon) {
addon.uninstall();
});
getAddon(addonId).then(addon => addon.uninstall(), reject);

return promise;
};

exports.disable = function disable(addonId) {
let { promise, resolve, reject } = defer();

AddonManager.getAddonByID(addonId, function (addon) {
return getAddon(addonId).then(addon => {
addon.userDisabled = true;
resolve();
return addonId;
});
};

return promise;
exports.isActive = function isActive(addonId) {
return getAddon(addonId).then(addon => addon.isActive && !addon.appDisabled);
};

function getAddon (id) {
let { promise, resolve, reject } = defer();
AddonManager.getAddonByID(id, addon => addon ? resolve(addon) : reject());
return promise;
}
38 changes: 35 additions & 3 deletions test/test-addon-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ exports["test Install"] = function (assert, done) {
done();
}
);
}
};

exports["test Failing Install With Invalid Path"] = function (assert, done) {
AddonInstaller.install("invalid-path").then(
Expand All @@ -62,7 +62,7 @@ exports["test Failing Install With Invalid Path"] = function (assert, done) {
done();
}
);
}
};

exports["test Failing Install With Invalid File"] = function (assert, done) {
let directory = system.pathFor("ProfD");
Expand Down Expand Up @@ -131,6 +131,38 @@ exports["test Update"] = function (assert, done) {
}

next();
}
};

exports['test Uninstall failure'] = function (assert, done) {
AddonInstaller.uninstall('invalid-addon-path').then(
() => assert.fail('Addon uninstall should not resolve successfully'),
() => assert.pass('Addon correctly rejected invalid uninstall')
).then(done, assert.fail);
};

exports['test Addon Disable'] = function (assert, done) {
let ensureActive = (addonId) => AddonInstaller.isActive(addonId).then(state => {
assert.equal(state, true, 'Addon should be enabled by default');
return addonId;
});
let ensureInactive = (addonId) => AddonInstaller.isActive(addonId).then(state => {
assert.equal(state, false, 'Addon should be disabled after disabling');
return addonId;
});

AddonInstaller.install(ADDON_PATH)
.then(ensureActive)
.then(AddonInstaller.disable)
.then(ensureInactive)
.then(AddonInstaller.uninstall)
.then(done, assert.fail);
};

exports['test Disable failure'] = function (assert, done) {
AddonInstaller.disable('not-an-id').then(
() => assert.fail('Addon disable should not resolve successfully'),
() => assert.pass('Addon correctly rejected invalid disable')
).then(done, assert.fail);
};

require("test").run(exports);

0 comments on commit e150a1f

Please sign in to comment.