--- a/browser/fuel/src/fuelApplication.js
+++ b/browser/fuel/src/fuelApplication.js
@@ -33,16 +33,18 @@
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const Ci = Components.interfaces;
const Cc = Components.classes;
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
//=================================================
// Shutdown - used to store cleanup functions which will
// be called on Application shutdown
var gShutdown = [];
//=================================================
// Console constructor
function Console() {
@@ -65,17 +67,19 @@ Console.prototype = {
var wWatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Ci.nsIWindowWatcher);
wWatch.openWindow(null, "chrome://global/content/console.xul", "_blank",
"chrome,dialog=no,all", cmdLine);
} else {
// console was already open
console.focus();
}
- }
+ },
+
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIConsole])
};
//=================================================
// EventItem constructor
function EventItem(aType, aData) {
this._type = aType;
this._data = aData;
@@ -91,17 +95,19 @@ EventItem.prototype = {
},
get data() {
return this._data;
},
preventDefault : function ei_pd() {
this._cancel = true;
- }
+ },
+
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIEventItem])
};
//=================================================
// Events constructor
function Events() {
this._listeners = [];
}
@@ -136,17 +142,19 @@ Events.prototype = {
if (key.event == aEvent) {
key.listener.handleEvent ?
key.listener.handleEvent(eventItem) :
key.listener(eventItem);
}
});
return !eventItem._cancel;
- }
+ },
+
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIEvents])
};
//=================================================
// PreferenceBranch constructor
function PreferenceBranch(aBranch) {
if (!aBranch)
aBranch = "";
@@ -156,17 +164,18 @@ function PreferenceBranch(aBranch) {
.getService(Ci.nsIPrefService);
if (aBranch)
this._prefs = this._prefs.getBranch(aBranch);
this._prefs.QueryInterface(Ci.nsIPrefBranch);
this._prefs.QueryInterface(Ci.nsIPrefBranch2);
- this._prefs.addObserver(this._root, this, false);
+ // we want to listen to "all" changes for this branch, so pass in a blank domain
+ this._prefs.addObserver("", this, true);
this._events = new Events();
var self = this;
gShutdown.push(function() { self._shutdown(); });
}
//=================================================
// PreferenceBranch implementation
@@ -258,17 +267,19 @@ PreferenceBranch.prototype = {
break;
default:
throw("Unknown preference value specified.");
}
},
reset : function prefs_reset() {
this._prefs.resetBranch("");
- }
+ },
+
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIPreferenceBranch, Ci.nsISupportsWeakReference])
};
//=================================================
// Preference constructor
function Preference(aName, aBranch) {
this._name = aName;
this._branch = aBranch;
@@ -333,17 +344,19 @@ Preference.prototype = {
},
get events() {
return this._events;
},
reset : function pref_reset() {
this.branch._prefs.clearUserPref(this.name);
- }
+ },
+
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIPreference])
};
//=================================================
// SessionStorage constructor
function SessionStorage() {
this._storage = {};
this._events = new Events();
@@ -362,17 +375,19 @@ SessionStorage.prototype = {
set : function ss_set(aName, aValue) {
this._storage[aName] = aValue;
this._events.dispatch("change", aName);
},
get : function ss_get(aName, aDefaultValue) {
return this.has(aName) ? this._storage[aName] : aDefaultValue;
- }
+ },
+
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelISessionStorage])
};
//=================================================
// Extension constructor
function Extension(aItem) {
this._item = aItem;
this._firstRun = false;
@@ -447,17 +462,19 @@ Extension.prototype = {
},
get prefs() {
return this._prefs;
},
get events() {
return this._events;
- }
+ },
+
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIExtension])
};
//=================================================
// Extensions constructor
function Extensions() {
this._extmgr = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager);
@@ -513,17 +530,19 @@ Extensions.prototype = {
// getItemForID never returns null for a non-existent id, so we
// check the type of the returned update item, which should be
// greater than 1 for a valid extension.
return !!(this._extmgr.getItemForID(aId).type);
},
get : function exts_get(aId) {
return this.has(aId) ? this._get(aId) : null;
- }
+ },
+
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIExtensions])
};
//=================================================
// Singleton that holds services and utilities
var Utilities = {
_bookmarks : null,
get bookmarks() {
if (!this._bookmarks) {
@@ -607,27 +626,27 @@ Window.prototype = {
get events() {
return this._events;
},
/*
* Helper used to setup event handlers on the XBL element. Note that the events
* are actually dispatched to tabs, so we capture them.
*/
- _watch : function(aType) {
+ _watch : function win_watch(aType) {
var self = this;
this._tabbrowser.addEventListener(aType,
this._cleanup[aType] = function(e){ self._event(e); },
true);
},
/*
* Helper event callback used to redirect events made on the XBL element
*/
- _event : function(aEvent) {
+ _event : function win_event(aEvent) {
this._events.dispatch(aEvent.type, "");
},
get tabs() {
var tabs = [];
var browsers = this._tabbrowser.browsers;
for (var i=0; i<browsers.length; i++)
@@ -635,29 +654,31 @@ Window.prototype = {
return tabs;
},
get activeTab() {
return new BrowserTab(this._window, this._tabbrowser.selectedBrowser);
},
- open : function(aURI) {
+ open : function win_open(aURI) {
return new BrowserTab(this._window, this._tabbrowser.addTab(aURI.spec).linkedBrowser);
},
- _shutdown : function() {
+ _shutdown : function win_shutdown() {
for (var type in this._cleanup)
this._tabbrowser.removeEventListener(type, this._cleanup[type], true);
this._cleanup = null;
this._window = null;
this._tabbrowser = null;
this._events = null;
- }
+ },
+
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIWindow])
};
//=================================================
// BrowserTab implementation
function BrowserTab(aWindow, aBrowser) {
this._window = aWindow;
this._tabbrowser = aWindow.getBrowser();
@@ -695,103 +716,112 @@ BrowserTab.prototype = {
get document() {
return this._browser.contentDocument;
},
/*
* Helper used to setup event handlers on the XBL element
*/
- _watch : function(aType) {
+ _watch : function bt_watch(aType) {
var self = this;
this._browser.addEventListener(aType,
this._cleanup[aType] = function(e){ self._event(e); },
true);
},
/*
* Helper event callback used to redirect events made on the XBL element
*/
- _event : function(aEvent) {
- if (aEvent.type == "load" && (!aEvent.originalTarget instanceof Ci.nsIDOMHTMLDocument ||
- aEvent.originalTarget.defaultView.frameElement))
- return;
+ _event : function bt_event(aEvent) {
+ if (aEvent.type == "load") {
+ if (!(aEvent.originalTarget instanceof Ci.nsIDOMHTMLDocument))
+ return;
+
+ if (aEvent.originalTarget.defaultView instanceof Ci.nsIDOMWindowInternal &&
+ aEvent.originalTarget.defaultView.frameElement)
+ return;
+ }
this._events.dispatch(aEvent.type, "");
},
/*
* Helper used to determine the index offset of the browsertab
*/
- _getTab : function() {
+ _getTab : function bt_gettab() {
var tabs = this._tabbrowser.mTabs;
return tabs[this.index] || null;
},
- load : function(aURI) {
+ load : function bt_load(aURI) {
this._browser.loadURI(aURI.spec, null, null);
},
- focus : function() {
+ focus : function bt_focus() {
this._tabbrowser.selectedTab = this._getTab();
this._tabbrowser.focus();
},
- close : function() {
+ close : function bt_close() {
this._tabbrowser.removeTab(this._getTab());
},
- moveBefore : function(aBefore) {
+ moveBefore : function bt_movebefore(aBefore) {
this._tabbrowser.moveTabTo(this._getTab(), aBefore.index);
},
- moveToEnd : function() {
+ moveToEnd : function bt_moveend() {
this._tabbrowser.moveTabTo(this._getTab(), this._tabbrowser.browsers.length);
},
- _shutdown : function() {
+ _shutdown : function bt_shutdown() {
for (var type in this._cleanup)
this._browser.removeEventListener(type, this._cleanup[type], true);
this._cleanup = null;
this._window = null;
this._tabbrowser = null;
this._browser = null;
this._events = null;
- }
+ },
+
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIBrowserTab])
};
//=================================================
// Annotations implementation
function Annotations(aId) {
this._id = aId;
}
Annotations.prototype = {
get names() {
return Utilities.annotations.getItemAnnotationNames(this._id, {});
},
- has : function(aName) {
+ has : function ann_has(aName) {
return Utilities.annotations.itemHasAnnotation(this._id, aName);
},
get : function(aName) {
return Utilities.annotations.getItemAnnotation(this._id, aName);
},
set : function(aName, aValue, aExpiration) {
Utilities.annotations.setItemAnnotation(this._id, aName, aValue, 0, aExpiration);
},
- remove : function(aName) {
+ remove : function ann_remove(aName) {
if (aName)
Utilities.annotations.removeItemAnnotation(this._id, aName);
- }
+ },
+
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIAnnotations])
};
//=================================================
// Bookmark implementation
function Bookmark(aId, aParent, aType) {
this._id = aId;
this._parent = aParent;
@@ -801,17 +831,17 @@ function Bookmark(aId, aParent, aType) {
Utilities.bookmarks.addObserver(this, false);
var self = this;
gShutdown.push(function() { self._shutdown(); });
}
Bookmark.prototype = {
- _shutdown : function() {
+ _shutdown : function bm_shutdown() {
this._annotations = null;
this._events = null;
Utilities.bookmarks.removeObserver(this);
},
get id() {
return this._id;
@@ -865,59 +895,52 @@ Bookmark.prototype = {
get annotations() {
return this._annotations;
},
get events() {
return this._events;
},
- remove : function() {
+ remove : function bm_remove() {
Utilities.bookmarks.removeItem(this._id);
},
// observer
- onBeginUpdateBatch : function() {
+ onBeginUpdateBatch : function bm_obub() {
},
- onEndUpdateBatch : function() {
+ onEndUpdateBatch : function bm_oeub() {
},
- onItemAdded : function(aId, aFolder, aIndex) {
+ onItemAdded : function bm_oia(aId, aFolder, aIndex) {
// bookmark object doesn't exist at this point
},
- onItemRemoved : function(aId, aFolder, aIndex) {
+ onItemRemoved : function bm_oir(aId, aFolder, aIndex) {
if (this._id == aId)
this._events.dispatch("remove", aId);
},
- onItemChanged : function(aId, aProperty, aIsAnnotationProperty, aValue) {
+ onItemChanged : function bm_oic(aId, aProperty, aIsAnnotationProperty, aValue) {
if (this._id == aId)
this._events.dispatch("change", aProperty);
},
- onItemVisited: function(aId, aVisitID, aTime) {
+ onItemVisited: function bm_oiv(aId, aVisitID, aTime) {
},
- onItemMoved: function(aId, aOldParent, aOldIndex, aNewParent, aNewIndex) {
+ onItemMoved: function bm_oim(aId, aOldParent, aOldIndex, aNewParent, aNewIndex) {
if (this._id == aId) {
this._parent = new BookmarkFolder(aNewParent, Utilities.bookmarks.getFolderIdForItem(aNewParent));
this._events.dispatch("move", aId);
}
},
- QueryInterface: function(aIID) {
- if (aIID.equals(Ci.fuelIBookmark) ||
- aIID.equals(Ci.nsINavBookmarkObserver) ||
- aIID.equals(Ci.nsISupports)) {
- return this;
- }
- throw Component.result.NS_ERROR_NO_INTERFACE;
- }
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIBookmark, Ci.nsINavBookmarkObserver])
};
//=================================================
// BookmarkFolder implementation
function BookmarkFolder(aId, aParent) {
this._id = aId;
if (this._id == null)
@@ -930,17 +953,17 @@ function BookmarkFolder(aId, aParent) {
Utilities.bookmarks.addObserver(this, false);
var self = this;
gShutdown.push(function() { self._shutdown(); });
}
BookmarkFolder.prototype = {
- _shutdown : function() {
+ _shutdown : function bmf_shutdown() {
this._annotations = null;
this._events = null;
Utilities.bookmarks.removeObserver(this);
},
get id() {
return this._id;
@@ -1008,90 +1031,83 @@ BookmarkFolder.prototype = {
items.push(bookmark);
}
}
rootNode.containerOpen = false;
return items;
},
- addBookmark : function(aTitle, aUri) {
+ addBookmark : function bmf_addbm(aTitle, aUri) {
var newBookmarkID = Utilities.bookmarks.insertBookmark(this._id, aUri, Utilities.bookmarks.DEFAULT_INDEX, aTitle);
var newBookmark = new Bookmark(newBookmarkID, this, "bookmark");
return newBookmark;
},
- addSeparator : function() {
+ addSeparator : function bmf_addsep() {
var newBookmarkID = Utilities.bookmarks.insertSeparator(this._id, Utilities.bookmarks.DEFAULT_INDEX);
var newBookmark = new Bookmark(newBookmarkID, this, "separator");
return newBookmark;
},
- addFolder : function(aTitle) {
+ addFolder : function bmf_addfolder(aTitle) {
var newFolderID = Utilities.bookmarks.createFolder(this._id, aTitle, Utilities.bookmarks.DEFAULT_INDEX);
var newFolder = new BookmarkFolder(newFolderID, this);
return newFolder;
},
- remove : function() {
+ remove : function bmf_remove() {
Utilities.bookmarks.removeFolder(this._id);
},
// observer
- onBeginUpdateBatch : function() {
+ onBeginUpdateBatch : function bmf_obub() {
},
- onEndUpdateBatch : function() {
+ onEndUpdateBatch : function bmf_oeub() {
},
- onItemAdded : function(aId, aFolder, aIndex) {
+ onItemAdded : function bmf_oia(aId, aFolder, aIndex) {
// handle root folder events
if (!this._parent)
this._events.dispatch("add", aId);
// handle this folder events
if (this._id == aFolder)
this._events.dispatch("addchild", aId);
},
- onItemRemoved : function(aId, aFolder, aIndex) {
+ onItemRemoved : function bmf_oir(aId, aFolder, aIndex) {
// handle root folder events
if (!this._parent || this._id == aId)
this._events.dispatch("remove", aId);
// handle this folder events
if (this._id == aFolder)
this._events.dispatch("removechild", aId);
},
- onItemChanged : function(aId, aProperty, aIsAnnotationProperty, aValue) {
+ onItemChanged : function bmf_oic(aId, aProperty, aIsAnnotationProperty, aValue) {
// handle root folder and this folder events
if (!this._parent || this._id == aId)
this._events.dispatch("change", aProperty);
},
- onItemVisited: function(aId, aVisitID, aTime) {
+ onItemVisited: function bmf_oiv(aId, aVisitID, aTime) {
},
- onItemMoved: function(aId, aOldParent, aOldIndex, aNewParent, aNewIndex) {
+ onItemMoved: function bmf_oim(aId, aOldParent, aOldIndex, aNewParent, aNewIndex) {
// handle this folder event, root folder cannot be moved
if (this._id == aId) {
this._parent = new BookmarkFolder(aNewParent, Utilities.bookmarks.getFolderIdForItem(aNewParent));
this._events.dispatch("move", aId);
}
},
- QueryInterface: function(aIID) {
- if (aIID.equals(Ci.fuelIBookmarkFolder) ||
- aIID.equals(Ci.nsINavBookmarkObserver) ||
- aIID.equals(Ci.nsISupports)) {
- return this;
- }
- throw Component.result.NS_ERROR_NO_INTERFACE;
- }
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIBookmarkFolder, Ci.nsINavBookmarkObserver])
};
const CLASS_ID = Components.ID("fe74cf80-aa2d-11db-abbd-0800200c9a66");
const CLASS_NAME = "Application wrapper";
const CONTRACT_ID = "@mozilla.org/fuel/application;1";
//=================================================
@@ -1190,27 +1206,17 @@ Application.prototype = {
return interfaces;
},
getHelperForLanguage : function app_ghfl(aCount) {
return null;
},
// for nsISupports
- QueryInterface: function app_qi(aIID) {
- // add any other interfaces you support here
- if (aIID.equals(Ci.fuelIApplication) ||
- aIID.equals(Ci.nsIObserver) ||
- aIID.equals(Ci.nsIClassInfo) ||
- aIID.equals(Ci.nsISupports))
- {
- return this;
- }
- throw Components.results.NS_ERROR_NO_INTERFACE;
- },
+ QueryInterface : XPCOMUtils.generateQI([Ci.fuelIApplication, Ci.nsIObserver, Ci.nsIClassInfo]),
get console() {
if (this._console == null)
this._console = new Console();
return this._console;
},
--- a/browser/fuel/test/browser_Extensions.js
+++ b/browser/fuel/test/browser_Extensions.js
@@ -1,14 +1,16 @@
// The various pieces that we'll be testing
var testdata = {
dummyid: "fuel-dummy-extension@mozilla.org",
dummyname: "Dummy Extension",
inspectorid: "inspector@mozilla.org",
- inspectorname: "DOM Inspector"
+ inspectorname: "DOM Inspector",
+ missing: "fuel.fuel-test-missing",
+ dummy: "fuel.fuel-test"
};
var gLastEvent = "";
function test() {
// test to see if a non-existant extension exists
ok(!Application.extensions.has(testdata.dummyid), "Check non-existant extension for existance");
// test to see if an extension exists
@@ -18,20 +20,17 @@ function test() {
is(inspector.id, testdata.inspectorid, "Check 'Extension.id' for known extension");
is(inspector.name, testdata.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");
-
+ // STORAGE TESTING
// 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(testdata.inspectorid);
is(inspector2.id, testdata.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");
@@ -52,17 +51,69 @@ function test() {
extmgr.enableItem(testdata.inspectorid);
is(gLastEvent, "cancel", "Checking that enable (cancel) event is fired");
extmgr.uninstallItem(testdata.inspectorid);
is(gLastEvent, "uninstall", "Checking that uninstall event is fired");
extmgr.cancelUninstallItem(testdata.inspectorid);
is(gLastEvent, "cancel", "Checking that cancel event is fired");
+
+ // PREF TESTING
+ // Reset the install event preference, so that we can test it again later
+ inspector.prefs.get("install-event-fired").reset();
+
+ // test the value of the preference root
+ is(Application.extensions.all[0].prefs.root, "extensions.inspector@mozilla.org.", "Check an extension preference root");
+
+ // test getting non-existing values
+ var itemValue = inspector.prefs.getValue(testdata.missing, "default");
+ is(itemValue, "default", "Check 'Extension.prefs.getValue' for non-existing item");
- // Reset the install event preference, so that we can test it again later [do this last in test]
- inspector.prefs.get("install-event-fired").reset();
+ is(inspector.prefs.get(testdata.missing), null, "Check 'Extension.prefs.get' for non-existing item");
+
+ // test setting and getting a value
+ inspector.prefs.setValue(testdata.dummy, "dummy");
+ itemValue = inspector.prefs.getValue(testdata.dummy, "default");
+ is(itemValue, "dummy", "Check 'Extension.prefs.getValue' for existing item");
+
+ // test for overwriting an existing value
+ inspector.prefs.setValue(testdata.dummy, "smarty");
+ itemValue = inspector.prefs.getValue(testdata.dummy, "default");
+ is(itemValue, "smarty", "Check 'Extension.prefs.getValue' for overwritten item");
+
+ // test setting and getting a value
+ inspector.prefs.get(testdata.dummy).value = "dummy2";
+ itemValue = inspector.prefs.get(testdata.dummy).value;
+ is(itemValue, "dummy2", "Check 'Extension.prefs.get().value' for existing item");
+
+ // test resetting a pref [since there is no default value, the pref should disappear]
+ inspector.prefs.get(testdata.dummy).reset();
+ var itemValue = inspector.prefs.getValue(testdata.dummy, "default");
+ is(itemValue, "default", "Check 'Extension.prefs.getValue' for reset pref");
+
+ // test to see if a non-existant property exists
+ ok(!inspector.prefs.has(testdata.dummy), "Check non-existant property for existance");
+
+ waitForExplicitFinish();
+ inspector.prefs.events.addListener("change", onPrefChange);
+ inspector.prefs.setValue("fuel.fuel-test", "change event");
}
function onGenericEvent(event) {
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
gLastEvent = event.type;
}
+
+function onPrefChange(evt) {
+ var inspector3 = Application.extensions.get(testdata.inspectorid);
+
+ is(evt.data, testdata.dummy, "Check 'Extension.prefs.set' fired a change event");
+ inspector3.prefs.events.removeListener("change", onPrefChange);
+
+ inspector3.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2);
+ inspector3.prefs.setValue("fuel.fuel-test", "change event2");
+}
+
+function onPrefChange2(evt) {
+ is(evt.data, testdata.dummy, "Check 'Extension.prefs.set' fired a change event for a single preference");
+
+ finish();
+}