2008-11-06 12:48:41 -08:00
|
|
|
var gPageA = null;
|
|
|
|
var gPageB = null;
|
|
|
|
|
2009-01-15 21:35:01 -08:00
|
|
|
// cached data from events
|
|
|
|
var gTabOpenPageA = null;
|
|
|
|
var gTabOpenPageB = 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
|
|
|
|
2010-09-10 10:20:38 -07:00
|
|
|
var rootDir = getRootDirectory(gTestPath);
|
|
|
|
const CHROMEROOT = rootDir;
|
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
function test() {
|
2009-11-22 06:05:54 -08:00
|
|
|
waitForExplicitFinish();
|
2009-08-17 02:35:05 -07:00
|
|
|
|
2007-07-14 14:13:51 -07:00
|
|
|
var windows = Application.windows;
|
|
|
|
ok(windows, "Check access to browser windows");
|
2009-08-17 02:35:05 -07:00
|
|
|
is(windows.length, 1, "There should be one browser window open");
|
2007-07-14 14:13:51 -07:00
|
|
|
|
|
|
|
var activeWin = Application.activeWindow;
|
|
|
|
activeWin.events.addListener("TabOpen", onTabOpen);
|
|
|
|
activeWin.events.addListener("TabClose", onTabClose);
|
|
|
|
activeWin.events.addListener("TabMove", onTabMove);
|
|
|
|
|
2010-09-10 10:20:38 -07:00
|
|
|
gPageA = activeWin.open(makeURI(CHROMEROOT + "ContentA.html"));
|
2008-11-06 12:48:41 -08:00
|
|
|
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
|
|
|
|
2008-11-06 12:48:41 -08:00
|
|
|
function onPageAFirstLoad(event) {
|
|
|
|
gPageA.events.removeListener("load", onPageAFirstLoad);
|
2009-01-15 21:35:01 -08:00
|
|
|
is(gPageA.uri.spec, event.data.uri.spec, "Checking event browser tab is equal to page A");
|
2008-11-06 12:48:41 -08:00
|
|
|
|
2010-09-10 10:20:38 -07:00
|
|
|
gPageB = activeWin.open(makeURI(CHROMEROOT + "ContentB.html"));
|
2009-01-15 10:47:55 -08:00
|
|
|
gPageB.events.addListener("load", delayAfterOpen);
|
2008-11-06 12:48:41 -08:00
|
|
|
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
|
|
|
|
2009-01-15 10:47:55 -08:00
|
|
|
function delayAfterOpen() {
|
|
|
|
executeSoon(afterOpen);
|
|
|
|
}
|
|
|
|
|
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) {
|
2009-01-15 10:47:55 -08:00
|
|
|
gPageB.events.removeListener("load", delayAfterOpen);
|
2009-01-15 21:35:01 -08:00
|
|
|
// check actuals
|
2010-09-10 10:20:38 -07:00
|
|
|
is(gPageA.uri.spec, CHROMEROOT + "ContentA.html", "Checking 'BrowserTab.uri' after opening");
|
|
|
|
is(gPageB.uri.spec, CHROMEROOT + "ContentB.html", "Checking 'BrowserTab.uri' after opening");
|
2007-07-14 14:13:51 -07:00
|
|
|
|
2010-03-13 08:55:44 -08:00
|
|
|
// check event
|
|
|
|
is(gTabOpenCount, 2, "Checking event handler for tab open");
|
2009-01-15 21:35:01 -08:00
|
|
|
// check cached values from TabOpen event
|
|
|
|
is(gPageA.uri.spec, gTabOpenPageA.uri.spec, "Checking first browser tab open is equal to page A");
|
|
|
|
is(gPageB.uri.spec, gTabOpenPageB.uri.spec, "Checking second browser tab open is equal to page B");
|
2007-07-14 14:13:51 -07:00
|
|
|
|
|
|
|
// 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
|
2009-01-15 10:47:55 -08:00
|
|
|
is(gTabMoveCount, 0, "Checking initial tab move count");
|
|
|
|
|
|
|
|
// move the 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");
|
|
|
|
|
2010-05-16 13:27:20 -07:00
|
|
|
gBrowser.addProgressListener({
|
2009-09-19 18:59:39 -07:00
|
|
|
onStateChange: function (webProgress, request, stateFlags, status) {
|
|
|
|
info("onStateChange: " + stateFlags);
|
|
|
|
|
2008-11-07 13:31:42 -08:00
|
|
|
const complete = Ci.nsIWebProgressListener.STATE_IS_WINDOW +
|
|
|
|
Ci.nsIWebProgressListener.STATE_IS_NETWORK +
|
|
|
|
Ci.nsIWebProgressListener.STATE_STOP;
|
|
|
|
if ((stateFlags & complete) == complete) {
|
2010-05-16 13:27:20 -07:00
|
|
|
gBrowser.removeProgressListener(this);
|
2008-11-07 13:31:42 -08:00
|
|
|
onPageBLoadComplete();
|
|
|
|
}
|
|
|
|
},
|
2009-09-19 18:59:39 -07:00
|
|
|
onLocationChange: function () 0,
|
|
|
|
onProgressChange: function () 0,
|
|
|
|
onStatusChange: function () 0,
|
2010-05-17 00:36:22 -07:00
|
|
|
onSecurityChange: function () 0
|
2008-11-07 13:31:42 -08:00
|
|
|
});
|
2007-07-19 11:17:55 -07:00
|
|
|
|
|
|
|
// test loading new content with a frame into a tab
|
2009-01-15 10:47:55 -08:00
|
|
|
// the event will be checked in onPageBLoadComplete
|
2008-11-06 12:48:41 -08:00
|
|
|
gPageB.events.addListener("load", onPageBLoadWithFrames);
|
2010-09-10 10:20:38 -07:00
|
|
|
gPageB.load(makeURI(CHROMEROOT + "ContentWithFrames.html"));
|
2007-07-14 14:13:51 -07:00
|
|
|
}
|
|
|
|
|
2008-11-07 13:31:42 -08:00
|
|
|
function onPageBLoadWithFrames(event) {
|
|
|
|
gPageLoadCount++;
|
2009-09-19 18:59:39 -07:00
|
|
|
info("onPageBLoadWithFrames: " + gPageLoadCount);
|
2008-11-07 13:31:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function onPageBLoadComplete() {
|
|
|
|
gPageB.events.removeListener("load", onPageBLoadWithFrames);
|
|
|
|
// check page load with frame event
|
|
|
|
is(gPageLoadCount, 1, "Checking load count after loading new content with a frame");
|
|
|
|
|
|
|
|
// test loading new content into a tab
|
2009-01-15 10:47:55 -08:00
|
|
|
// the event will be checked in onPageASecondLoad
|
2008-11-07 13:31:42 -08:00
|
|
|
gPageA.events.addListener("load", onPageASecondLoad);
|
2010-09-10 10:20:38 -07:00
|
|
|
gPageA.load(makeURI(CHROMEROOT + "ContentB.html"));
|
2008-11-07 13:31:42 -08:00
|
|
|
}
|
|
|
|
|
2008-11-06 12:48:41 -08:00
|
|
|
function onPageASecondLoad(event) {
|
2008-11-07 13:31:42 -08:00
|
|
|
gPageA.events.removeListener("load", onPageASecondLoad);
|
2010-09-10 10:20:38 -07:00
|
|
|
is(gPageA.uri.spec, CHROMEROOT + "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-07 13:31:42 -08:00
|
|
|
gPageA.close();
|
|
|
|
gPageB.close();
|
2007-07-19 11:17:55 -07:00
|
|
|
|
2008-11-07 13:31:42 -08:00
|
|
|
is(gTabCloseCount, 2, "Checking that tabs closed");
|
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++;
|
|
|
|
|
2009-01-15 21:35:01 -08:00
|
|
|
// cache these values so we can check them later (after loading completes)
|
|
|
|
if (gTabOpenCount == 1)
|
|
|
|
gTabOpenPageA = event.data;
|
|
|
|
|
|
|
|
if (gTabOpenCount == 2)
|
|
|
|
gTabOpenPageB = event.data;
|
|
|
|
}
|
2007-07-14 14:13:51 -07:00
|
|
|
function onTabClose(event) {
|
|
|
|
gTabCloseCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTabMove(event) {
|
|
|
|
gTabMoveCount++;
|
|
|
|
}
|