2008-04-07 06:39:08 -07:00
|
|
|
/* Tests for proper behaviour of "Show this frame" context menu options */
|
|
|
|
|
|
|
|
// Two frames, one with text content, the other an error page
|
|
|
|
var invalidPage = 'http://127.0.0.1:55555/';
|
|
|
|
var validPage = 'http://example.com/';
|
|
|
|
var testPage = 'data:text/html,<frameset cols="400,400"><frame src="' + validPage + '"><frame src="' + invalidPage + '"></frameset>';
|
|
|
|
|
|
|
|
// Store the tab and window created in tests 2 and 3 respectively
|
|
|
|
var test2tab;
|
|
|
|
var test3window;
|
|
|
|
|
|
|
|
// We use setInterval instead of setTimeout to avoid race conditions on error doc loads
|
|
|
|
var intervalID;
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
2009-09-16 03:21:19 -07:00
|
|
|
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab();
|
|
|
|
gBrowser.selectedBrowser.addEventListener("load", test1Setup, true);
|
|
|
|
content.location = testPage;
|
2008-04-07 06:39:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test1Setup() {
|
2009-09-16 03:21:19 -07:00
|
|
|
if (content.frames.length < 2 ||
|
|
|
|
content.frames[1].location != invalidPage)
|
2008-04-08 11:45:08 -07:00
|
|
|
// The error frame hasn't loaded yet
|
2008-04-07 06:39:08 -07:00
|
|
|
return;
|
|
|
|
|
2009-09-16 03:21:19 -07:00
|
|
|
gBrowser.selectedBrowser.removeEventListener("load", test1Setup, true);
|
|
|
|
|
|
|
|
var badFrame = content.frames[1];
|
2008-04-07 06:39:08 -07:00
|
|
|
document.popupNode = badFrame.document.firstChild;
|
2009-09-16 03:21:19 -07:00
|
|
|
|
2008-04-07 06:39:08 -07:00
|
|
|
var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
|
|
|
|
var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
|
|
|
|
|
|
|
|
// We'd like to use another load listener here, but error pages don't fire load events
|
|
|
|
contextMenu.showOnlyThisFrame();
|
2009-09-16 03:21:19 -07:00
|
|
|
intervalID = setInterval(testShowOnlyThisFrame, 3000);
|
2008-04-07 06:39:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function testShowOnlyThisFrame() {
|
2009-09-16 03:21:19 -07:00
|
|
|
if (content.location.href == testPage)
|
2008-04-07 06:39:08 -07:00
|
|
|
// This is a stale event from the original page loading
|
|
|
|
return;
|
2009-09-16 03:21:19 -07:00
|
|
|
|
2008-04-07 06:39:08 -07:00
|
|
|
// We should now have loaded the error page frame content directly
|
|
|
|
// in the tab, make sure the URL is right.
|
2009-09-16 03:21:19 -07:00
|
|
|
clearInterval(intervalID);
|
|
|
|
|
|
|
|
is(content.location.href, invalidPage, "Should navigate to page url, not about:neterror");
|
|
|
|
|
2008-04-07 06:39:08 -07:00
|
|
|
// Go back to the frames page
|
|
|
|
gBrowser.addEventListener("load", test2Setup, true);
|
2009-09-16 03:21:19 -07:00
|
|
|
content.location = testPage;
|
2008-04-07 06:39:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test2Setup() {
|
2009-09-16 03:21:19 -07:00
|
|
|
if (content.frames.length < 2 ||
|
|
|
|
content.frames[1].location != invalidPage)
|
2008-04-08 11:45:08 -07:00
|
|
|
// The error frame hasn't loaded yet
|
2008-04-07 06:39:08 -07:00
|
|
|
return;
|
2009-09-16 03:21:19 -07:00
|
|
|
|
2008-04-07 06:39:08 -07:00
|
|
|
gBrowser.removeEventListener("load", test2Setup, true);
|
2009-09-16 03:21:19 -07:00
|
|
|
|
2008-04-07 06:39:08 -07:00
|
|
|
// Now let's do the whole thing again, but this time for "Open frame in new tab"
|
2009-09-16 03:21:19 -07:00
|
|
|
var badFrame = content.frames[1];
|
|
|
|
|
2008-04-07 06:39:08 -07:00
|
|
|
document.popupNode = badFrame.document.firstChild;
|
2009-09-16 03:21:19 -07:00
|
|
|
|
2008-04-07 06:39:08 -07:00
|
|
|
var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
|
|
|
|
var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
|
|
|
|
|
|
|
|
test2tab = contextMenu.openFrameInTab();
|
|
|
|
ok(test2tab instanceof XULElement, "openFrameInTab() should return an element (non-null)");
|
|
|
|
is(test2tab.tagName, "tab", "openFrameInTab() should return a *tab* element");
|
2009-09-16 03:21:19 -07:00
|
|
|
|
2008-04-07 06:39:08 -07:00
|
|
|
gBrowser.selectedTab = test2tab;
|
|
|
|
|
2009-09-16 03:21:19 -07:00
|
|
|
intervalID = setInterval(testOpenFrameInTab, 3000);
|
2008-04-07 06:39:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function testOpenFrameInTab() {
|
2009-09-16 03:21:19 -07:00
|
|
|
if (gBrowser.contentDocument.location.href == "about:blank")
|
2008-04-07 06:39:08 -07:00
|
|
|
// Wait another cycle
|
|
|
|
return;
|
2009-09-16 03:21:19 -07:00
|
|
|
|
|
|
|
clearInterval(intervalID);
|
|
|
|
|
2008-04-07 06:39:08 -07:00
|
|
|
// We should now have the error page in a new, active tab.
|
|
|
|
is(gBrowser.contentDocument.location.href, invalidPage, "New tab should have page url, not about:neterror");
|
|
|
|
|
|
|
|
// Clear up the new tab, and punt to test 3
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
|
|
|
|
test3Setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test3Setup() {
|
|
|
|
// One more time, for "Open frame in new window"
|
2009-09-16 03:21:19 -07:00
|
|
|
var badFrame = content.frames[1];
|
2008-04-07 06:39:08 -07:00
|
|
|
document.popupNode = badFrame.document.firstChild;
|
2009-09-16 03:21:19 -07:00
|
|
|
|
2008-04-07 06:39:08 -07:00
|
|
|
var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
|
|
|
|
var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
|
|
|
|
|
|
|
|
test3window = contextMenu.openFrame();
|
|
|
|
ok(test3window instanceof Window, "openFrame() should return a window (non-null) ");
|
2009-09-16 03:21:19 -07:00
|
|
|
|
|
|
|
intervalID = setInterval(testOpenFrame, 3000);
|
2008-04-07 06:39:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function testOpenFrame() {
|
2009-09-16 03:21:19 -07:00
|
|
|
if (test3window.content.location.href == "about:blank")
|
2008-04-07 06:39:08 -07:00
|
|
|
// Wait another cycle
|
|
|
|
return;
|
2009-09-16 03:21:19 -07:00
|
|
|
|
|
|
|
clearInterval(intervalID);
|
|
|
|
|
|
|
|
is(test3window.content.location.href, invalidPage, "New window should have page url, not about:neterror");
|
|
|
|
|
2008-04-07 06:39:08 -07:00
|
|
|
test3window.close();
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup() {
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
finish();
|
|
|
|
}
|