b=387470. r=gavin. convert FUEL tests to new browser chrome framework.

This commit is contained in:
mark.finkle@gmail.com 2007-07-14 14:13:51 -07:00
Родитель e940cfb755
Коммит f0926cf076
7 изменённых файлов: 550 добавлений и 8 удалений

Просмотреть файл

@ -44,15 +44,15 @@ relativesrcdir = browser/fuel/test
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = test_Application.html \
test_ApplicationPrefs.html \
test_ApplicationStorage.html \
test_Extensions.html \
test_Browser.html \
test_Bookmarks.html \
_BROWSER_FILES =browser_Application.js \
browser_ApplicationPrefs.js \
browser_ApplicationStorage.js \
browser_Extensions.js \
browser_Browser.js \
browser_Bookmarks.js \
ContentA.html \
ContentB.html \
$(NULL)
libs:: $(_TEST_FILES)
$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
libs:: $(_BROWSER_FILES)
$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)

Просмотреть файл

@ -0,0 +1,8 @@
function test() {
ok(Application, "Check global access to Application");
// I'd test these against a specific value, but that is bound to flucuate
ok(Application.id, "Check to see if an ID exists for the Application");
ok(Application.name, "Check to see if a name exists for the Application");
ok(Application.version, "Check to see if a version exists for the Application");
}

Просмотреть файл

@ -0,0 +1,158 @@
// The various properties that we'll be testing
var testdata = {
missing: "fuel.fuel-test-missing",
dummy: "fuel.fuel-test",
string: "browser.active_color",
integer: "permissions.default.image",
boolean: "browser.blink_allowed"
};
function test() {
// test getting non-existing values
var itemValue = Application.prefs.getValue(testdata.missing, "default");
is(itemValue, "default", "Check 'Application.prefs.getValue' for non-existing item");
is(Application.prefs.get(testdata.missing), null, "Check 'Application.prefs.get' for non-existing item");
// test setting and getting a value
Application.prefs.setValue(testdata.dummy, "dummy");
itemValue = Application.prefs.getValue(testdata.dummy, "default");
is(itemValue, "dummy", "Check 'Application.prefs.getValue' for existing item");
// test for overwriting an existing value
Application.prefs.setValue(testdata.dummy, "smarty");
itemValue = Application.prefs.getValue(testdata.dummy, "default");
is(itemValue, "smarty", "Check 'Application.prefs.getValue' for overwritten item");
// test setting and getting a value
Application.prefs.get(testdata.dummy).value = "dummy2";
itemValue = Application.prefs.get(testdata.dummy).value;
is(itemValue, "dummy2", "Check 'Application.prefs.get().value' for existing item");
// test resetting a pref [since there is no default value, the pref should disappear]
Application.prefs.get(testdata.dummy).reset();
var itemValue = Application.prefs.getValue(testdata.dummy, "default");
is(itemValue, "default", "Check 'Application.prefs.getValue' for reset pref");
// test to see if a non-existant property exists
ok(!Application.prefs.has(testdata.dummy), "Check non-existant property for existance");
// PREF: string browser.active_color == #EE0000
// test to see if an existing string property exists
ok(Application.prefs.has(testdata.string), "Check existing string property for existance");
// test accessing a non-existant string property
var val = Application.prefs.getValue(testdata.dummy, "default");
is(val, "default", "Check non-existant string property for expected value");
// test accessing an existing string property
var val = Application.prefs.getValue(testdata.string, "default");
is(val, "#EE0000", "Check existing string property for expected value");
// test manipulating an existing string property
Application.prefs.setValue(testdata.string, "#EF0000");
var val = Application.prefs.getValue(testdata.string, "default");
is(val, "#EF0000", "Set existing string property");
// test resetting an existing string property
Application.prefs.get(testdata.string).reset();
var val = Application.prefs.getValue(testdata.string, "default");
is(val, "#EE0000", "Reset existing string property");
// PREF: integer permissions.default.image == 1
// test to see if an existing integer property exists
ok(Application.prefs.has(testdata.integer), "Check existing integer property for existance");
// test accessing a non-existant integer property
var val = Application.prefs.getValue(testdata.dummy, 0);
is(val, 0, "Check non-existant integer property for expected value");
// test accessing an existing integer property
var val = Application.prefs.getValue(testdata.integer, 0);
is(val, 1, "Check existing integer property for expected value");
// test manipulating an existing integer property
Application.prefs.setValue(testdata.integer, 0);
var val = Application.prefs.getValue(testdata.integer, 1);
is(val, 0, "Set existing integer property");
// test resetting an existing integer property
Application.prefs.get(testdata.integer).reset();
var val = Application.prefs.getValue(testdata.integer, 0);
is(val, 1, "Reset existing integer property");
// PREF: boolean browser.blink_allowed == true
// test to see if an existing boolean property exists
ok(Application.prefs.has(testdata.boolean), "Check existing boolean property for existance");
// test accessing a non-existant boolean property
var val = Application.prefs.getValue(testdata.dummy, true);
ok(val, "Check non-existant boolean property for expected value");
// test accessing an existing boolean property
var val = Application.prefs.getValue(testdata.boolean, false);
ok(val, "Check existing boolean property for expected value");
// test manipulating an existing boolean property
Application.prefs.setValue(testdata.boolean, false);
var val = Application.prefs.getValue(testdata.boolean, true);
ok(!val, "Set existing boolean property");
// test resetting an existing boolean property
Application.prefs.get(testdata.boolean).reset();
var val = Application.prefs.getValue(testdata.boolean, false);
ok(val, "Reset existing string property for expected value");
// test getting all preferences
var allPrefs = Application.prefs.all;
ok(allPrefs.length >= 800, "Check 'Application.prefs.all' for the right number of preferences");
is(allPrefs[0].name, "capability.policy.default.Window.parent.get", "Check 'Application.prefs.all' for the right starting preference");
// test the value of the preference root
is(Application.prefs.root, "", "Check the Application preference root");
// test for user changed preferences
ok(Application.prefs.get("browser.shell.checkDefaultBrowser").modified, "A single preference is marked as modified.");
ok(!Application.prefs.get(testdata.string).modified, "A single preference is marked as not modified.");
// test for a locked preference
var pref = Application.prefs.get(testdata.string);
ok(!pref.locked, "A single preference should not be locked.");
pref.locked = true;
ok(pref.locked, "A single preference should be locked.");
try {
prev.value = "test value";
ok(false, "A locked preference should not be able to be modified.");
} catch(e){
ok(true, "A locked preference should not be able to be modified.");
}
pref.locked = false;
ok(!pref.locked, "A single preference should not be locked.");
// check for change event when setting a value
waitForExplicitFinish();
Application.prefs.events.addListener("change", onPrefChange);
Application.prefs.setValue("fuel.fuel-test", "change event");
}
function onPrefChange(evt) {
is(evt.data, testdata.dummy, "Check 'Application.prefs.set' fired a change event");
Application.prefs.events.removeListener("change", onPrefChange);
Application.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2);
Application.prefs.setValue("fuel.fuel-test", "change event2");
}
function onPrefChange2(evt) {
is(evt.data, testdata.dummy, "Check 'Application.prefs.set' fired a change event for a single preference");
Application.prefs.events.removeListener("change", onPrefChange2);
finish();
}

Просмотреть файл

@ -0,0 +1,30 @@
function test() {
// test for existence of values
var hasItem = Application.storage.has("fuel-test-missing");
is(hasItem, false, "Check 'Application.storage.has' for non-existing item");
Application.storage.set("fuel-test", "dummy");
hasItem = Application.storage.has("fuel-test");
is(hasItem, true, "Check 'Application.storage.has' for existing item");
// test getting non-existing and existing values
var itemValue = Application.storage.get("fuel-test-missing", "default");
is(itemValue, "default", "Check 'Application.storage.get' for non-existing item");
itemValue = Application.storage.get("fuel-test", "default");
is(itemValue, "dummy", "Check 'Application.storage.get' for existing item");
// test for overwriting an existing value
Application.storage.set("fuel-test", "smarty");
itemValue = Application.storage.get("fuel-test", "default");
is(itemValue, "smarty", "Check 'Application.storage.get' for overwritten item");
// check for change event when setting a value
waitForExplicitFinish();
Application.storage.events.addListener("change", onStorageChange);
Application.storage.set("fuel-test", "change event");
}
function onStorageChange(evt) {
is(evt.data, "fuel-test", "Check 'Application.storage.set' fired a change event");
Application.storage.events.removeListener("change", onStorageChange);
finish();
}

Просмотреть файл

@ -0,0 +1,190 @@
const Ci = Components.interfaces;
const Cc = Components.classes;
var gLastFolderAction = "";
var gLastBookmarkAction = "";
function url(spec) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(spec, null, null);
}
function test() {
var root = Application.bookmarks;
ok(root, "Check access to bookmark root");
ok(!root.parent, "Check root parent (should be null)");
var rootKidCount = root.children.length;
// test adding folders
var testFolder = root.addFolder("FUEL");
ok(testFolder, "Check folder creation");
is(testFolder.type, "folder", "Check 'folder.type' after creation");
ok(testFolder.parent, "Check parent after folder creation");
rootKidCount++;
is(root.children.length, rootKidCount, "Check root folder child count after adding a child folder");
// test modifying a folder
testFolder.events.addListener("change", onFolderChange);
testFolder.description = "FUEL folder";
is(testFolder.description, "FUEL folder", "Check setting 'folder.description'");
is(gLastFolderAction, "bookmarkProperties/description", "Check event handler for setting 'folder.description'");
testFolder.title = "fuel-is-cool";
is(testFolder.title, "fuel-is-cool", "Check setting 'folder.title'");
is(gLastFolderAction, "title", "Check event handler for setting 'folder.title'");
testFolder.annotations.set("testing/folder", "annotate-this", 0);
ok(testFolder.annotations.has("testing/folder"), "Checking existence of added annotation");
is(gLastFolderAction, "testing/folder", "Check event handler for setting annotation");
gLastFolderAction = "";
is(testFolder.annotations.get("testing/folder"), "annotate-this", "Checking existence of added annotation");
testFolder.annotations.remove("testing/folder");
ok(!testFolder.annotations.has("testing/folder"), "Checking existence of removed annotation");
is(gLastFolderAction, "testing/folder", "Check event handler for removing annotation");
testFolder.events.addListener("addchild", onFolderAddChild);
testFolder.events.addListener("removechild", onFolderRemoveChild);
// test adding a bookmark
var testBookmark = testFolder.addBookmark("Mozilla", url("http://www.mozilla.com/"));
ok(testBookmark, "Check bookmark creation");
ok(testBookmark.parent, "Check parent after bookmark creation");
is(gLastFolderAction, "addchild", "Check event handler for adding a child to a folder");
is(testBookmark.type, "bookmark", "Check 'bookmark.type' after creation");
is(testBookmark.title, "Mozilla", "Check 'bookmark.title' after creation");
is(testBookmark.uri.spec, "http://www.mozilla.com/", "Check 'bookmark.uri' after creation");
is(testFolder.children.length, 1, "Check test folder child count after adding a child bookmark");
// test modifying a bookmark
testBookmark.events.addListener("change", onBookmarkChange);
testBookmark.description = "mozcorp";
is(testBookmark.description, "mozcorp", "Check setting 'bookmark.description'");
is(gLastBookmarkAction, "bookmarkProperties/description", "Check event handler for setting 'bookmark.description'");
testBookmark.keyword = "moz"
is(testBookmark.keyword, "moz", "Check setting 'bookmark.keyword'");
is(gLastBookmarkAction, "keyword", "Check event handler for setting 'bookmark.keyword'");
testBookmark.title = "MozCorp"
is(testBookmark.title, "MozCorp", "Check setting 'bookmark.title'");
is(gLastBookmarkAction, "title", "Check event handler for setting 'bookmark.title'");
testBookmark.uri = url("http://www.mozilla.org/");
is(testBookmark.uri.spec, "http://www.mozilla.org/", "Check setting 'bookmark.uri'");
is(gLastBookmarkAction, "uri", "Check event handler for setting 'bookmark.uri'");
// test adding and removing a bookmark annotation
testBookmark.annotations.set("testing/bookmark", "annotate-this", 0);
ok(testBookmark.annotations.has("testing/bookmark"), "Checking existence of added annotation");
is(gLastBookmarkAction, "testing/bookmark", "Check event handler for setting annotation");
gLastBookmarkAction = "";
is(testBookmark.annotations.get("testing/bookmark"), "annotate-this", "Checking existence of added annotation");
testBookmark.annotations.remove("testing/bookmark");
ok(!testBookmark.annotations.has("testing/bookmark"), "Checking existence of removed annotation");
is(gLastBookmarkAction, "testing/bookmark", "Check event handler for removing annotation");
// quick annotation type tests
testBookmark.annotations.set("testing/bookmark/string", "annotate-this", 0);
ok(testBookmark.annotations.has("testing/bookmark/string"), "Checking existence of added string annotation");
is(testBookmark.annotations.get("testing/bookmark/string"), "annotate-this", "Checking value of added string annotation");
is(gLastBookmarkAction, "testing/bookmark/string", "Check event handler for setting annotation");
gLastBookmarkAction = "";
testBookmark.annotations.set("testing/bookmark/int", 100, 0);
ok(testBookmark.annotations.has("testing/bookmark/int"), "Checking existence of added integer annotation");
is(testBookmark.annotations.get("testing/bookmark/int"), 100, "Checking value of added integer annotation");
is(gLastBookmarkAction, "testing/bookmark/int", "Check event handler for setting annotation");
gLastBookmarkAction = "";
testBookmark.annotations.set("testing/bookmark/double", 3.333, 0);
ok(testBookmark.annotations.has("testing/bookmark/double"), "Checking existence of added double annotation");
is(testBookmark.annotations.get("testing/bookmark/double"), 3.333, "Checking value of added double annotation");
is(gLastBookmarkAction, "testing/bookmark/double", "Check event handler for setting annotation");
gLastBookmarkAction = "";
// test names array - NOTE: "bookmarkProperties/description" is an annotation too
var names = testBookmark.annotations.names;
is(names[1], "testing/bookmark/string", "Checking contents of annotation names array");
is(names.length, 4, "Checking the annotation names array after adding 3 annotations");
// test adding a separator
var testSeparator = testFolder.addSeparator();
ok(testSeparator, "Check bookmark creation");
ok(testSeparator.parent, "Check parent after separator creation");
is(gLastFolderAction, "addchild", "Check event handler for adding a child separator to a folder");
is(testSeparator.type, "separator", "Check 'bookmark.type' after separator creation");
is(testFolder.children.length, 2, "Check test folder child count after adding a child separator");
// test removing separator
testSeparator.events.addListener("remove", onBookmarkRemove);
testSeparator.remove();
is(gLastBookmarkAction, "remove", "Check event handler for removing separator");
is(gLastFolderAction, "removechild", "Check event handler for removing a child separator from a folder");
is(testFolder.children.length, 1, "Check test folder child count after removing a child separator");
// test removing bookmark
testBookmark.events.addListener("remove", onBookmarkRemove);
testBookmark.remove();
is(gLastBookmarkAction, "remove", "Check event handler for removing bookmark");
is(gLastFolderAction, "removechild", "Check event handler for removing a child from a folder");
is(testFolder.children.length, 0, "Check test folder child count after removing a child bookmark");
// test removing a folder
testFolder.events.addListener("remove", onFolderRemove);
testFolder.remove();
is(gLastFolderAction, "remove", "Check event handler for removing child folder");
rootKidCount--;
is(root.children.length, rootKidCount, "Check root folder child count after removing a child folder");
// test moving between folders
var testFolderA = root.addFolder("folder-a");
var testFolderB = root.addFolder("folder-b");
var testMove = testFolderA.addBookmark("Mozilla", url("http://www.mozilla.com/"));
testMove.events.addListener("move", onBookmarkMove);
is(testMove.parent.title, "folder-a", "Checking for new parent before moving bookmark");
testMove.parent = testFolderB;
is(testMove.parent.title, "folder-b", "Checking for new parent after moving bookmark");
is(gLastBookmarkAction, "move", "Checking for event handler after moving bookmark");
// test moving a folder
testFolderA.events.addListener("move", onFolderMove);
testFolderA.parent = testFolderB;
is(testFolderA.parent.title, "folder-b", "Checking for new parent after moving folder");
is(gLastFolderAction, "move", "Checking for event handler after moving folder");
}
function onFolderChange(evt) {
gLastFolderAction = evt.data;
}
function onFolderRemove(evt) {
gLastFolderAction = evt.type;
}
function onFolderAddChild(evt) {
gLastFolderAction = evt.type;
}
function onFolderRemoveChild(evt) {
gLastFolderAction = evt.type;
}
function onFolderMove(evt) {
gLastFolderAction = evt.type;
}
function onBookmarkChange(evt) {
gLastBookmarkAction = evt.data;
}
function onBookmarkRemove(evt) {
gLastBookmarkAction = evt.type;
}
function onBookmarkMove(evt) {
gLastBookmarkAction = evt.type;
}

Просмотреть файл

@ -0,0 +1,88 @@
const Ci = Components.interfaces;
const Cc = Components.classes;
function url(spec) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ios.newURI(spec, null, null);
}
var gTabOpenCount = 0;
var gTabCloseCount = 0;
var gTabMoveCount = 0;
function test() {
var windows = Application.windows;
ok(windows, "Check access to browser windows");
ok(windows.length, "There should be at least one browser window open");
var activeWin = Application.activeWindow;
activeWin.events.addListener("TabOpen", onTabOpen);
activeWin.events.addListener("TabClose", onTabClose);
activeWin.events.addListener("TabMove", onTabMove);
var pageA = activeWin.open(url("chrome://mochikit/content/browser/browser/fuel/test/ContentA.html"));
var pageB = activeWin.open(url("chrome://mochikit/content/browser/browser/fuel/test/ContentB.html"));
pageB.focus();
is(activeWin.tabs.length, 3, "Checking length of 'Browser.tabs' after opening 2 additional tabs");
is(activeWin.activeTab.index, pageB.index, "Checking 'Browser.activeTab' after setting focus");
waitForExplicitFinish();
setTimeout(afterOpen, 1000);
// need to wait for the url's to be refreshed during the load
function afterOpen() {
is(pageA.uri.spec, "chrome://mochikit/content/browser/browser/fuel/test/ContentA.html", "Checking 'BrowserTab.uri' after opening");
is(pageB.uri.spec, "chrome://mochikit/content/browser/browser/fuel/test/ContentB.html", "Checking 'BrowserTab.uri' after opening");
// check event
is(gTabOpenCount, 2, "Checking event handler for tab open");
// test document access
var test1 = pageA.document.getElementById("test1");
ok(test1, "Checking existence of element in content DOM");
is(test1.innerHTML, "A", "Checking content of element in content DOM");
// test moving tab
pageA.moveToEnd();
is(pageA.index, 2, "Checking index after moving tab");
// check event
is(gTabMoveCount, 1, "Checking event handler for tab move");
// test loading new content into a tab
// the event will be checked in afterClose
pageA.events.addListener("load", onPageLoad);
pageA.load(pageB.uri);
}
function onPageLoad(event) {
is(pageA.uri.spec, "chrome://mochikit/content/browser/browser/fuel/test/ContentB.html", "Checking 'BrowserTab.uri' after loading new content");
// start testing closing tabs
pageA.close();
pageB.close();
setTimeout(afterClose, 1000);
}
function afterClose() {
// check event
is(gTabCloseCount, 2, "Checking event handler for tab close");
is(activeWin.tabs.length, 1, "Checking length of 'Browser.tabs' after closing 2 tabs");
finish();
}
}
function onTabOpen(event) {
gTabOpenCount++;
}
function onTabClose(event) {
gTabCloseCount++;
}
function onTabMove(event) {
gTabMoveCount++;
}

Просмотреть файл

@ -0,0 +1,68 @@
// 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"
};
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
ok(Application.extensions.has(testdata.inspectorid), "Check extension for existance");
var inspector = Application.extensions.get(testdata.inspectorid);
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");
// Reset the install event preference, so that we can test it again later
inspector.prefs.get("install-event-fired").reset();
// 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");
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(testdata.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(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");
}
function onGenericEvent(event) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
gLastEvent = event.type;
}