"Show Only This Frame" code uses about:neterror url for error pages. b=423833 r=mano a=blocking-firefox3 (beltzner)

This commit is contained in:
johnath@mozilla.com 2008-04-07 06:39:08 -07:00
Родитель 8774c39a05
Коммит 56af4e3787
4 изменённых файлов: 154 добавлений и 12 удалений

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

@ -654,10 +654,10 @@ nsContextMenu.prototype = {
// Open frame in a new tab. // Open frame in a new tab.
openFrameInTab: function() { openFrameInTab: function() {
var doc = this.target.ownerDocument; var doc = this.target.ownerDocument;
var frameURL = doc.documentURIObject.spec; var frameURL = doc.location.href;
var referrer = doc.referrer; var referrer = doc.referrer;
openNewTabWith(frameURL, null, null, null, false, return openNewTabWith(frameURL, null, null, null, false,
referrer ? makeURI(referrer) : null); referrer ? makeURI(referrer) : null);
}, },
@ -669,17 +669,17 @@ nsContextMenu.prototype = {
// Open clicked-in frame in its own window. // Open clicked-in frame in its own window.
openFrame: function() { openFrame: function() {
var doc = this.target.ownerDocument; var doc = this.target.ownerDocument;
var frameURL = doc.documentURIObject.spec; var frameURL = doc.location.href;
var referrer = doc.referrer; var referrer = doc.referrer;
openNewWindowWith(frameURL, null, null, false, return openNewWindowWith(frameURL, null, null, false,
referrer ? makeURI(referrer) : null); referrer ? makeURI(referrer) : null);
}, },
// Open clicked-in frame in the same window. // Open clicked-in frame in the same window.
showOnlyThisFrame: function() { showOnlyThisFrame: function() {
var doc = this.target.ownerDocument; var doc = this.target.ownerDocument;
var frameURL = doc.documentURIObject.spec; var frameURL = doc.location.href;
urlSecurityCheck(frameURL, this.browser.contentPrincipal, urlSecurityCheck(frameURL, this.browser.contentPrincipal,
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT); Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);

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

@ -54,6 +54,7 @@ _BROWSER_FILES = browser_bug321000.js \
browser_bug409481.js \ browser_bug409481.js \
browser_autodiscovery.js \ browser_autodiscovery.js \
browser_bug420160.js \ browser_bug420160.js \
browser_bug423833.js \
autodiscovery.html \ autodiscovery.html \
moz.png \ moz.png \
browser_getshortcutoruri.js \ browser_getshortcutoruri.js \

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

@ -0,0 +1,141 @@
/* 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>';
// Keep track of the browser inside our frame
var newBrowser;
// 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();
var newTab = gBrowser.addTab();
gBrowser.selectedTab = newTab;
newBrowser = gBrowser.getBrowserForTab(newTab);
newBrowser.addEventListener("load", test1Setup, true);
newBrowser.contentWindow.location = testPage;
}
var loadCount = 0;
function test1Setup() {
if(!loadCount++)
// Wait for both frames to load
return;
loadCount = 0;
newBrowser.removeEventListener("load", test1Setup, true);
var badFrame = newBrowser.contentWindow.frames[1];
document.popupNode = badFrame.document.firstChild;
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();
intervalID = window.setInterval(testShowOnlyThisFrame, 3000);
}
function testShowOnlyThisFrame() {
if(newBrowser.contentDocument.location.href == testPage)
// This is a stale event from the original page loading
return;
// We should now have loaded the error page frame content directly
// in the tab, make sure the URL is right.
window.clearInterval(intervalID);
is(newBrowser.contentDocument.location.href, invalidPage, "Should navigate to page url, not about:neterror");
// Go back to the frames page
gBrowser.addEventListener("load", test2Setup, true);
newBrowser.contentWindow.location = testPage;
}
function test2Setup() {
if(!loadCount++)
// Wait for both frames to load
return;
loadCount = 0;
gBrowser.removeEventListener("load", test2Setup, true);
// Now let's do the whole thing again, but this time for "Open frame in new tab"
newBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
var badFrame = newBrowser.contentWindow.frames[1];
document.popupNode = badFrame.document.firstChild;
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");
gBrowser.selectedTab = test2tab;
intervalID = window.setInterval(testOpenFrameInTab, 3000);
}
function testOpenFrameInTab() {
if(gBrowser.contentDocument.location.href == "about:blank")
// Wait another cycle
return;
window.clearInterval(intervalID);
// 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"
newBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
var badFrame = newBrowser.contentWindow.frames[1];
document.popupNode = badFrame.document.firstChild;
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) ");
intervalID = window.setInterval(testOpenFrame, 3000);
}
function testOpenFrame() {
if(test3window.content.document.location.href == "about:blank")
// Wait another cycle
return;
window.clearInterval(intervalID);
is(test3window.content.document.location.href, invalidPage, "New window should have page url, not about:neterror");
test3window.close();
cleanup();
}
function cleanup() {
gBrowser.removeCurrentTab();
finish();
}

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

@ -578,7 +578,7 @@ function openNewTabWith(aURL, aDocument, aPostData, aEvent,
// open link in new tab // open link in new tab
var referrerURI = aDocument ? aDocument.documentURIObject : aReferrer; var referrerURI = aDocument ? aDocument.documentURIObject : aReferrer;
var browser = top.document.getElementById("content"); var browser = top.document.getElementById("content");
browser.loadOneTab(aURL, referrerURI, originCharset, aPostData, return browser.loadOneTab(aURL, referrerURI, originCharset, aPostData,
loadInBackground, aAllowThirdPartyFixup || false); loadInBackground, aAllowThirdPartyFixup || false);
} }
@ -598,7 +598,7 @@ function openNewWindowWith(aURL, aDocument, aPostData, aAllowThirdPartyFixup,
charsetArg = "charset=" + window.content.document.characterSet; charsetArg = "charset=" + window.content.document.characterSet;
var referrerURI = aDocument ? aDocument.documentURIObject : aReferrer; var referrerURI = aDocument ? aDocument.documentURIObject : aReferrer;
window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", return window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no",
aURL, charsetArg, referrerURI, aPostData, aURL, charsetArg, referrerURI, aPostData,
aAllowThirdPartyFixup); aAllowThirdPartyFixup);
} }