Files
firefox/toolkit/mozapps/extensions/test/xpcshell/data/BootstrapMonitor.jsm
T
Dave Townsend f64b1b0bd5 Bug 1207772: Add some better sanity checks for the bootstrap function calls. r=rhelmer
Unifies the methods we have to check that bootstrap add-ons are correctly loaded
and makes it easier to make changes to them all in the future without needing to
re-sign add-ons etc.

This code allows a bootstrap script to use a shared script in a single line of
code. The shared scripts sends out all the relevant info over the observer
service, the add-ons manager test harness receives and retains the current state
for every add-on also performing sanity checks like making sure an "install"
method is always called before any "startup" method etc. It also provides simple
functions to check the state of a given add-on.
2015-09-15 10:45:52 -07:00

29 lines
844 B
JavaScript

Components.utils.import("resource://gre/modules/Services.jsm");
this.EXPORTED_SYMBOLS = [ "monitor" ];
function notify(event, originalMethod, data, reason) {
let info = {
event,
data: Object.assign({}, data, {
installPath: data.installPath.path,
resourceURI: data.resourceURI.spec,
}),
reason
};
Services.obs.notifyObservers(null, "bootstrapmonitor-event", JSON.stringify(info));
// If the bootstrap scope already declares a method call it
if (originalMethod)
originalMethod(data, reason);
}
// Allows a simple one-line bootstrap script:
// Components.utils.import("resource://xpcshelldata/bootstrapmonitor.jsm").monitor(this);
this.monitor = function(scope) {
for (let event of ["install", "startup", "shutdown", "uninstall"]) {
scope[event] = notify.bind(null, event, scope[event]);
}
}