Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / browser / fuel / test / browser_Extensions.js
blobe5a2a817d0f23c6047ffe827d1dd2b1c601b8480
1 // The various pieces that we'll be testing
2 var testdata = {
3 dummyid: "fuel-dummy-extension@mozilla.org",
4 dummyname: "Dummy Extension",
5 inspectorid: "inspector@mozilla.org",
6 inspectorname: "DOM Inspector",
7 missing: "fuel.fuel-test-missing",
8 dummy: "fuel.fuel-test"
9 };
10 var gLastEvent = "";
12 function test() {
13 // test to see if the extensions object is available
14 ok(Application.extensions, "Check for the 'Extensions' object");
16 // test to see if a non-existant extension exists
17 ok(!Application.extensions.has(testdata.dummyid), "Check non-existant extension for existance");
19 // BUG 420028: Must find a way to add a dummy extension for test suite
20 return;
22 // test to see if an extension exists
23 ok(Application.extensions.has(testdata.inspectorid), "Check extension for existance");
25 var inspector = Application.extensions.get(testdata.inspectorid);
26 is(inspector.id, testdata.inspectorid, "Check 'Extension.id' for known extension");
27 is(inspector.name, testdata.inspectorname, "Check 'Extension.name' for known extension");
28 // The known version number changes too frequently to hardcode in
29 ok(inspector.version, "Check 'Extension.version' for known extension");
30 ok(inspector.firstRun, "Check 'Extension.firstRun' for known extension");
31 ok(inspector.enabled, "Check 'Extension.enabled' for known extension");
33 // test to see if extension find works
34 is(Application.extensions.all.length, 1, "Check a find for all extensions");
35 // STORAGE TESTING
36 // Make sure the we are given the same extension (cached) so things like .storage work right
37 inspector.storage.set("test", "simple check");
38 ok(inspector.storage.has("test"), "Checking that extension storage worked");
40 var inspector2 = Application.extensions.get(testdata.inspectorid);
41 is(inspector2.id, testdata.inspectorid, "Check 'Extension.id' for known extension - from cache");
42 ok(inspector.storage.has("test"), "Checking that extension storage worked - from cache");
43 is(inspector2.storage.get("test", "cache"), inspector.storage.get("test", "original"), "Checking that the storage of same extension is correct - from cache");
45 inspector.events.addListener("disable", onGenericEvent);
46 inspector.events.addListener("enable", onGenericEvent);
47 inspector.events.addListener("uninstall", onGenericEvent);
48 inspector.events.addListener("cancel", onGenericEvent);
50 var extmgr = Components.classes["@mozilla.org/extensions/manager;1"]
51 .getService(Components.interfaces.nsIExtensionManager);
53 extmgr.disableItem(testdata.inspectorid);
54 is(gLastEvent, "disable", "Checking that disable event is fired");
56 // enabling after a disable will only fire a 'cancel' event
57 // see - http://mxr.mozilla.org/seamonkey/source/toolkit/mozapps/extensions/src/nsExtensionManager.js.in#5216
58 extmgr.enableItem(testdata.inspectorid);
59 is(gLastEvent, "cancel", "Checking that enable (cancel) event is fired");
61 extmgr.uninstallItem(testdata.inspectorid);
62 is(gLastEvent, "uninstall", "Checking that uninstall event is fired");
64 extmgr.cancelUninstallItem(testdata.inspectorid);
65 is(gLastEvent, "cancel", "Checking that cancel event is fired");
67 // PREF TESTING
68 // Reset the install event preference, so that we can test it again later
69 inspector.prefs.get("install-event-fired").reset();
71 // test the value of the preference root
72 is(Application.extensions.all[0].prefs.root, "extensions.inspector@mozilla.org.", "Check an extension preference root");
74 // test getting non-existing values
75 var itemValue = inspector.prefs.getValue(testdata.missing, "default");
76 is(itemValue, "default", "Check 'Extension.prefs.getValue' for non-existing item");
78 is(inspector.prefs.get(testdata.missing), null, "Check 'Extension.prefs.get' for non-existing item");
80 // test setting and getting a value
81 inspector.prefs.setValue(testdata.dummy, "dummy");
82 itemValue = inspector.prefs.getValue(testdata.dummy, "default");
83 is(itemValue, "dummy", "Check 'Extension.prefs.getValue' for existing item");
85 // test for overwriting an existing value
86 inspector.prefs.setValue(testdata.dummy, "smarty");
87 itemValue = inspector.prefs.getValue(testdata.dummy, "default");
88 is(itemValue, "smarty", "Check 'Extension.prefs.getValue' for overwritten item");
90 // test setting and getting a value
91 inspector.prefs.get(testdata.dummy).value = "dummy2";
92 itemValue = inspector.prefs.get(testdata.dummy).value;
93 is(itemValue, "dummy2", "Check 'Extension.prefs.get().value' for existing item");
95 // test resetting a pref [since there is no default value, the pref should disappear]
96 inspector.prefs.get(testdata.dummy).reset();
97 var itemValue = inspector.prefs.getValue(testdata.dummy, "default");
98 is(itemValue, "default", "Check 'Extension.prefs.getValue' for reset pref");
100 // test to see if a non-existant property exists
101 ok(!inspector.prefs.has(testdata.dummy), "Check non-existant property for existance");
103 waitForExplicitFinish();
104 inspector.prefs.events.addListener("change", onPrefChange);
105 inspector.prefs.setValue("fuel.fuel-test", "change event");
108 function onGenericEvent(event) {
109 gLastEvent = event.type;
112 function onPrefChange(evt) {
113 var inspector3 = Application.extensions.get(testdata.inspectorid);
115 is(evt.data, testdata.dummy, "Check 'Extension.prefs.set' fired a change event");
116 inspector3.prefs.events.removeListener("change", onPrefChange);
118 inspector3.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2);
119 inspector3.prefs.setValue("fuel.fuel-test", "change event2");
122 function onPrefChange2(evt) {
123 is(evt.data, testdata.dummy, "Check 'Extension.prefs.set' fired a change event for a single preference");
125 finish();