browser_Extensions.js
Go to the documentation of this file.
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 = "";
11 
12 function test() {
13  // test to see if the extensions object is available
14  ok(Application.extensions, "Check for the 'Extensions' object");
15 
16  // test to see if a non-existant extension exists
17  ok(!Application.extensions.has(testdata.dummyid), "Check non-existant extension for existance");
18 
19  // BUG 420028: Must find a way to add a dummy extension for test suite
20  return;
21 
22  // test to see if an extension exists
23  ok(Application.extensions.has(testdata.inspectorid), "Check extension for existance");
24 
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");
32 
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");
39 
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");
44 
45  inspector.events.addListener("disable", onGenericEvent);
46  inspector.events.addListener("enable", onGenericEvent);
47  inspector.events.addListener("uninstall", onGenericEvent);
48  inspector.events.addListener("cancel", onGenericEvent);
49 
50  var extmgr = Components.classes["@mozilla.org/extensions/manager;1"]
51  .getService(Components.interfaces.nsIExtensionManager);
52 
53  extmgr.disableItem(testdata.inspectorid);
54  is(gLastEvent, "disable", "Checking that disable event is fired");
55 
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");
60 
61  extmgr.uninstallItem(testdata.inspectorid);
62  is(gLastEvent, "uninstall", "Checking that uninstall event is fired");
63 
64  extmgr.cancelUninstallItem(testdata.inspectorid);
65  is(gLastEvent, "cancel", "Checking that cancel event is fired");
66 
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();
70 
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");
73 
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");
77 
78  is(inspector.prefs.get(testdata.missing), null, "Check 'Extension.prefs.get' for non-existing item");
79 
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");
84 
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");
89 
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");
94 
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");
99 
100  // test to see if a non-existant property exists
101  ok(!inspector.prefs.has(testdata.dummy), "Check non-existant property for existance");
102 
104  inspector.prefs.events.addListener("change", onPrefChange);
105  inspector.prefs.setValue("fuel.fuel-test", "change event");
106 }
107 
109  gLastEvent = event.type;
110 }
111 
112 function onPrefChange(evt) {
113  var inspector3 = Application.extensions.get(testdata.inspectorid);
114 
115  is(evt.data, testdata.dummy, "Check 'Extension.prefs.set' fired a change event");
116  inspector3.prefs.events.removeListener("change", onPrefChange);
117 
118  inspector3.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2);
119  inspector3.prefs.setValue("fuel.fuel-test", "change event2");
120 }
121 
122 function onPrefChange2(evt) {
123  is(evt.data, testdata.dummy, "Check 'Extension.prefs.set' fired a change event for a single preference");
124 
125  finish();
126 }
function onPrefChange2(evt)
var Application
Definition: sbAboutDRM.js:37
var event
var testdata
function onGenericEvent(event)
function test()
var gLastEvent
waitForExplicitFinish()
return null
Definition: FeedWriter.js:1143
function onPrefChange(evt)