2007-07-14 14:13:51 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-11-06 12:48:41 -08:00
|
|
|
var gPageA = null;
|
|
|
|
var gPageB = null;
|
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
var gTabOpenCount = 0;
|
|
|
|
var gTabCloseCount = 0;
|
|
|
|
var gTabMoveCount = 0;
|
2007-07-19 11:17:55 -07:00
|
|
|
var gPageLoadCount = 0;
|
2007-07-14 14:13:51 -07:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2008-11-06 12:48:41 -08:00
|
|
|
gPageA = activeWin.open(url("chrome://mochikit/content/browser/browser/fuel/test/ContentA.html"));
|
|
|
|
gPageA.events.addListener("load", onPageAFirstLoad);
|
2007-07-14 14:13:51 -07:00
|
|
|
|
2008-11-06 12:48:41 -08:00
|
|
|
is(activeWin.tabs.length, 2, "Checking length of 'Browser.tabs' after opening 1 additional tab");
|
2007-07-14 14:13:51 -07:00
|
|
|
|
|
|
|
waitForExplicitFinish();
|
2008-11-06 12:48:41 -08:00
|
|
|
|
|
|
|
function onPageAFirstLoad(event) {
|
|
|
|
gPageA.events.removeListener("load", onPageAFirstLoad);
|
|
|
|
|
|
|
|
gPageB = activeWin.open(url("chrome://mochikit/content/browser/browser/fuel/test/ContentB.html"));
|
|
|
|
gPageB.events.addListener("load", afterOpen);
|
|
|
|
gPageB.focus();
|
|
|
|
|
|
|
|
is(activeWin.tabs.length, 3, "Checking length of 'Browser.tabs' after opening a second additional tab");
|
|
|
|
is(activeWin.activeTab.index, gPageB.index, "Checking 'Browser.activeTab' after setting focus");
|
|
|
|
}
|
2007-07-14 14:13:51 -07:00
|
|
|
|
|
|
|
// need to wait for the url's to be refreshed during the load
|
2008-11-06 12:48:41 -08:00
|
|
|
function afterOpen(event) {
|
|
|
|
gPageB.events.removeListener("load", afterOpen);
|
|
|
|
|
|
|
|
is(gPageA.uri.spec, "chrome://mochikit/content/browser/browser/fuel/test/ContentA.html", "Checking 'BrowserTab.uri' after opening");
|
|
|
|
is(gPageB.uri.spec, "chrome://mochikit/content/browser/browser/fuel/test/ContentB.html", "Checking 'BrowserTab.uri' after opening");
|
2007-07-14 14:13:51 -07:00
|
|
|
|
|
|
|
// check event
|
|
|
|
is(gTabOpenCount, 2, "Checking event handler for tab open");
|
|
|
|
|
|
|
|
// test document access
|
2008-11-06 12:48:41 -08:00
|
|
|
var test1 = gPageA.document.getElementById("test1");
|
2007-07-14 14:13:51 -07:00
|
|
|
ok(test1, "Checking existence of element in content DOM");
|
|
|
|
is(test1.innerHTML, "A", "Checking content of element in content DOM");
|
|
|
|
|
|
|
|
// test moving tab
|
2008-11-06 12:48:41 -08:00
|
|
|
gPageA.moveToEnd();
|
|
|
|
is(gPageA.index, 2, "Checking index after moving tab");
|
2007-07-14 14:13:51 -07:00
|
|
|
|
|
|
|
// check event
|
|
|
|
is(gTabMoveCount, 1, "Checking event handler for tab move");
|
|
|
|
|
|
|
|
// test loading new content into a tab
|
2007-07-19 11:17:55 -07:00
|
|
|
// the event will be checked in onPageLoad
|
2008-11-06 12:48:41 -08:00
|
|
|
gPageA.events.addListener("load", onPageASecondLoad);
|
|
|
|
gPageA.load(gPageB.uri);
|
2007-07-19 11:17:55 -07:00
|
|
|
|
|
|
|
// test loading new content with a frame into a tab
|
|
|
|
// the event will be checked in afterClose
|
2008-11-06 12:48:41 -08:00
|
|
|
gPageB.events.addListener("load", onPageBLoadWithFrames);
|
|
|
|
gPageB.load(url("chrome://mochikit/content/browser/browser/fuel/test/ContentWithFrames.html"));
|
2007-07-14 14:13:51 -07:00
|
|
|
}
|
|
|
|
|
2008-11-06 12:48:41 -08:00
|
|
|
function onPageASecondLoad(event) {
|
|
|
|
is(gPageA.uri.spec, "chrome://mochikit/content/browser/browser/fuel/test/ContentB.html", "Checking 'BrowserTab.uri' after loading new content");
|
2007-07-14 14:13:51 -07:00
|
|
|
|
|
|
|
// start testing closing tabs
|
2007-07-19 11:17:55 -07:00
|
|
|
// the event will be checked in afterClose
|
2008-11-06 12:48:41 -08:00
|
|
|
// use executeSoon so the onPageASecondLoad
|
2007-07-19 11:17:55 -07:00
|
|
|
// has a chance to finish first
|
2008-11-06 12:48:41 -08:00
|
|
|
executeSoon(function() {
|
|
|
|
gPageA.close();
|
|
|
|
gPageB.close();
|
|
|
|
executeSoon(afterClose);
|
|
|
|
});
|
2007-07-14 14:13:51 -07:00
|
|
|
}
|
|
|
|
|
2008-11-06 12:48:41 -08:00
|
|
|
function onPageBLoadWithFrames(event) {
|
2007-07-19 11:17:55 -07:00
|
|
|
gPageLoadCount++;
|
|
|
|
}
|
2008-11-06 12:48:41 -08:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
function afterClose() {
|
2007-07-19 11:17:55 -07:00
|
|
|
// check close event
|
2007-07-14 14:13:51 -07:00
|
|
|
is(gTabCloseCount, 2, "Checking event handler for tab close");
|
|
|
|
|
2007-07-19 11:17:55 -07:00
|
|
|
// check page load with frame event
|
|
|
|
is(gPageLoadCount, 1, "Checking 'BrowserTab.uri' after loading new content with a frame");
|
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
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++;
|
|
|
|
}
|