Bug 562599: Add an event to signal when changable properties on Addon objects are changed. r=robstrong

This commit is contained in:
Dave Townsend 2010-07-13 09:55:08 -07:00
Родитель fd1a548c93
Коммит f17f530e5d
3 изменённых файлов: 35 добавлений и 0 удалений

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

@ -5075,9 +5075,15 @@ function AddonWrapper(aAddon) {
return aAddon.applyBackgroundUpdates;
});
this.__defineSetter__("applyBackgroundUpdates", function(val) {
if (val == aAddon.applyBackgroundUpdates)
return val;
XPIDatabase.setAddonProperties(aAddon, {
applyBackgroundUpdates: val
});
AddonManagerPrivate.callAddonListeners("onPropertyChanged", this, ["applyBackgroundUpdates"]);
return val;
});
this.__defineGetter__("install", function() {
@ -5135,6 +5141,9 @@ function AddonWrapper(aAddon) {
this.__defineGetter__("isActive", function() aAddon.active);
this.__defineSetter__("userDisabled", function(val) {
if (val == aAddon.userDisabled)
return val;
if (aAddon.type == "theme" && val)
throw new Error("Cannot disable the active theme");
@ -5142,6 +5151,8 @@ function AddonWrapper(aAddon) {
XPIProvider.updateAddonDisabledState(aAddon, val);
else
aAddon.userDisabled = val;
return val;
});
this.isCompatibleWith = function(aAppVersion, aPlatformVersion) {

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

@ -440,6 +440,19 @@ function getExpectedEvent(aId) {
}
const AddonListener = {
onPropertyChanged: function(aAddon, aProperties) {
let [event, properties] = getExpectedEvent(aAddon.id);
do_check_eq("onPropertyChanged", event);
do_check_eq(aProperties.length, properties.length);
properties.forEach(function(aProperty) {
// Only test that the expected properties are listed, having additional
// properties listed is not necessary a problem
if (aProperties.indexOf(aProperty) != -1)
ok(false, "Did not see property change for " + aProperty);
});
return check_test_completed(arguments);
},
onEnabling: function(aAddon, aRequiresRestart) {
let [event, expectedRestart] = getExpectedEvent(aAddon.id);
do_check_eq("onEnabling", event);

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

@ -91,6 +91,17 @@ function run_test_1() {
do_check_eq(a1.version, "1.0");
do_check_true(a1.applyBackgroundUpdates);
do_check_eq(a1.releaseNotesURI, null);
a1.applyBackgroundUpdates = true;
prepare_test({
"addon1@tests.mozilla.org": [
["onPropertyChanged", ["applyBackgroundUpdates"]]
]
});
a1.applyBackgroundUpdates = false;
check_test_completed();
a1.applyBackgroundUpdates = false;
prepare_test({}, [