2007-04-23 13:27:46 -07:00
< html >
< head >
2007-07-09 13:56:52 -07:00
< title > Testing Extensions< / title >
2007-04-23 13:27:46 -07:00
< script type = "text/javascript" src = "/MochiKit/MochiKit.js" > < / script >
< script type = "text/javascript" src = "/tests/SimpleTest/SimpleTest.js" > < / script >
< script type = "text/javascript" src = "/tests/SimpleTest/EventUtils.js" > < / script >
< link rel = "stylesheet" type = "text/css" href = "/tests/SimpleTest/test.css" > < / link >
< / head >
< body >
< pre id = "test" >
< script class = "testbody" type = "text/javascript" >
// The various pieces that we'll be testing
var test = {
dummyid: "fuel-dummy-extension@mozilla.org",
dummyname: "Dummy Extension",
inspectorid: "inspector@mozilla.org",
inspectorname: "DOM Inspector"
};
2007-07-09 13:56:52 -07:00
var gLastEvent = "";
2007-04-23 13:27:46 -07:00
test_Extensions();
function test_Extensions() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
// test to see if a non-existant extension exists
ok(!Application.extensions.has(test.dummyid), "Check non-existant extension for existance");
// test to see if an extension exists
ok(Application.extensions.has(test.inspectorid), "Check extension for existance");
var inspector = Application.extensions.get(test.inspectorid);
is(inspector.id, test.inspectorid, "Check 'Extension.id' for known extension");
is(inspector.name, test.inspectorname, "Check 'Extension.name' for known extension");
// The known version number changes too frequently to hardcode in
ok(inspector.version, "Check 'Extension.version' for known extension");
ok(inspector.firstRun, "Check 'Extension.firstRun' for known extension");
// test to see if extension find works
is(Application.extensions.all.length, 1, "Check a find for all extensions");
// test the value of the preference root
is(Application.extensions.all[0].prefs.root, "extensions.inspector@mozilla.org.", "Check an extension preference root");
// Reset the install event preference, so that we can test it again later
inspector.prefs.get("install-event-fired").reset();
2007-07-09 13:56:52 -07:00
// Make sure the we are given the same extension (cached) so things like .storage work right
inspector.storage.set("test", "simple check");
ok(inspector.storage.has("test"), "Checking that extension storage worked");
var inspector2 = Application.extensions.get(test.inspectorid);
is(inspector2.id, test.inspectorid, "Check 'Extension.id' for known extension - from cache");
ok(inspector.storage.has("test"), "Checking that extension storage worked - from cache");
is(inspector2.storage.get("test", "cache"), inspector.storage.get("test", "original"), "Checking that the storage of same extension is correct - from cache");
inspector.events.addListener("disable", onGenericEvent);
inspector.events.addListener("enable", onGenericEvent);
inspector.events.addListener("uninstall", onGenericEvent);
inspector.events.addListener("cancel", onGenericEvent);
var extmgr = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
extmgr.disableItem(test.inspectorid);
is(gLastEvent, "disable", "Checking that disable event is fired");
// enabling after a disable will only fire a 'cancel' event
// see - http://mxr.mozilla.org/seamonkey/source/toolkit/mozapps/extensions/src/nsExtensionManager.js.in#5216
extmgr.enableItem(test.inspectorid);
is(gLastEvent, "cancel", "Checking that enable (cancel) event is fired");
extmgr.uninstallItem(test.inspectorid);
is(gLastEvent, "uninstall", "Checking that uninstall event is fired");
extmgr.cancelUninstallItem(test.inspectorid);
is(gLastEvent, "cancel", "Checking that cancel event is fired");
2007-04-23 13:27:46 -07:00
}
2007-07-09 13:56:52 -07:00
function onGenericEvent(event) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
gLastEvent = event.type;
}
2007-04-23 13:27:46 -07:00
< / script >
< / pre >
< / body >
< / html >