Bug 514232, r=bzbarsky + bug 529119 - Funky behavior with XUL error pages, r=bzbarsky
git-svn-id: svn://10.0.0.236/trunk@259021 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -3251,35 +3251,14 @@ nsDocShell::LoadErrorPage(nsIURI *aURI, const PRUnichar *aURL,
|
||||
spec.get(), NS_ConvertUTF16toUTF8(aURL).get(), chanName.get()));
|
||||
}
|
||||
#endif
|
||||
// Create an shistory entry for the old load, if we have a channel
|
||||
if (aFailedChannel) {
|
||||
mURIResultedInDocument = PR_TRUE;
|
||||
OnLoadingSite(aFailedChannel, PR_TRUE, PR_FALSE);
|
||||
} else if (aURI) {
|
||||
mURIResultedInDocument = PR_TRUE;
|
||||
OnNewURI(aURI, nsnull, mLoadType, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
// Be sure to have a correct mLSHE, it may have been cleared by
|
||||
// EndPageLoad. See bug 302115.
|
||||
if (mSessionHistory && !mLSHE) {
|
||||
PRInt32 idx;
|
||||
mSessionHistory->GetRequestedIndex(&idx);
|
||||
if (idx == -1)
|
||||
mSessionHistory->GetIndex(&idx);
|
||||
|
||||
nsCOMPtr<nsIHistoryEntry> entry;
|
||||
mSessionHistory->GetEntryAtIndex(idx, PR_FALSE,
|
||||
getter_AddRefs(entry));
|
||||
mLSHE = do_QueryInterface(entry);
|
||||
}
|
||||
|
||||
mFailedChannel = aFailedChannel;
|
||||
mFailedURI = aURI;
|
||||
mFailedLoadType = mLoadType;
|
||||
|
||||
nsCAutoString url;
|
||||
nsCAutoString charset;
|
||||
if (aURI)
|
||||
{
|
||||
// Set our current URI
|
||||
SetCurrentURI(aURI);
|
||||
|
||||
nsresult rv = aURI->GetSpec(url);
|
||||
rv |= aURI->GetOriginCharset(charset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@@ -3405,10 +3384,15 @@ nsDocShell::Stop(PRUint32 aStopFlags)
|
||||
// Revoke any pending event related to content viewer restoration
|
||||
mRestorePresentationEvent.Revoke();
|
||||
|
||||
if (mLoadType == LOAD_ERROR_PAGE && mLSHE) {
|
||||
// Since error page loads never unset mLSHE, do so now
|
||||
SetHistoryEntry(&mOSHE, mLSHE);
|
||||
SetHistoryEntry(&mLSHE, nsnull);
|
||||
if (mLoadType == LOAD_ERROR_PAGE) {
|
||||
if (mLSHE) {
|
||||
// Since error page loads never unset mLSHE, do so now
|
||||
SetHistoryEntry(&mOSHE, mLSHE);
|
||||
SetHistoryEntry(&mLSHE, nsnull);
|
||||
}
|
||||
|
||||
mFailedChannel = nsnull;
|
||||
mFailedURI = nsnull;
|
||||
}
|
||||
|
||||
if (nsIWebNavigation::STOP_CONTENT & aStopFlags) {
|
||||
@@ -6138,6 +6122,49 @@ nsDocShell::CreateContentViewer(const char *aContentType,
|
||||
// notifications before we've called Embed(). See bug 284993.
|
||||
mURIResultedInDocument = PR_TRUE;
|
||||
|
||||
if (mLoadType == LOAD_ERROR_PAGE) {
|
||||
// We need to set the SH entry and our current URI here and not
|
||||
// at the moment we load the page. We want the same behavior
|
||||
// of Stop() as for a normal page load. See bug 514232 for details.
|
||||
|
||||
// Revert mLoadType to load type to state the page load failed,
|
||||
// following function calls need it.
|
||||
mLoadType = mFailedLoadType;
|
||||
|
||||
nsCOMPtr<nsIChannel> failedChannel = mFailedChannel;
|
||||
nsCOMPtr<nsIURI> failedURI = mFailedURI;
|
||||
mFailedChannel = nsnull;
|
||||
mFailedURI = nsnull;
|
||||
|
||||
// Create an shistory entry for the old load, if we have a channel
|
||||
if (failedChannel) {
|
||||
mURIResultedInDocument = PR_TRUE;
|
||||
OnLoadingSite(failedChannel, PR_TRUE, PR_FALSE);
|
||||
} else if (failedURI) {
|
||||
mURIResultedInDocument = PR_TRUE;
|
||||
OnNewURI(failedURI, nsnull, nsnull, mLoadType, PR_TRUE, PR_FALSE);
|
||||
}
|
||||
|
||||
// Be sure to have a correct mLSHE, it may have been cleared by
|
||||
// EndPageLoad. See bug 302115.
|
||||
if (mSessionHistory && !mLSHE) {
|
||||
PRInt32 idx;
|
||||
mSessionHistory->GetRequestedIndex(&idx);
|
||||
if (idx == -1)
|
||||
mSessionHistory->GetIndex(&idx);
|
||||
|
||||
nsCOMPtr<nsIHistoryEntry> entry;
|
||||
mSessionHistory->GetEntryAtIndex(idx, PR_FALSE,
|
||||
getter_AddRefs(entry));
|
||||
mLSHE = do_QueryInterface(entry);
|
||||
}
|
||||
|
||||
// Set our current URI
|
||||
SetCurrentURI(failedURI);
|
||||
|
||||
mLoadType = LOAD_ERROR_PAGE;
|
||||
}
|
||||
|
||||
PRBool onLocationChangeNeeded = OnLoadingSite(aOpenedChannel, PR_FALSE);
|
||||
|
||||
// let's try resetting the load group if we need to...
|
||||
|
||||
@@ -70,6 +70,9 @@ _TEST_FILES = \
|
||||
test_bug402210.html \
|
||||
test_bug475636.html \
|
||||
file_bug475636.sjs \
|
||||
test_bug529119-1.html \
|
||||
test_bug529119-2.html \
|
||||
bug529119-window.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
||||
7
mozilla/docshell/test/bug529119-window.html
Normal file
7
mozilla/docshell/test/bug529119-window.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test bug 529119, sub-window</title>
|
||||
<body onload="window.opener.windowLoaded();">
|
||||
</body>
|
||||
</html>
|
||||
99
mozilla/docshell/test/test_bug529119-1.html
Normal file
99
mozilla/docshell/test/test_bug529119-1.html
Normal file
@@ -0,0 +1,99 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test bug 529119</title>
|
||||
<script type="text/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var workingURL = "http://localhost:8888/tests/docshell/test/bug529119-window.html";
|
||||
var faultyURL = "http://some-non-existent-domain-27489274c892748217cn2384.com/";
|
||||
|
||||
var w = null;
|
||||
var phase = 0;
|
||||
var gotWrongPageOnTryAgainClick = false;
|
||||
|
||||
function pollForPage(expected_title, f, w)
|
||||
{
|
||||
// Start with polling after a delay, we might mistakenly take the current page
|
||||
// as an expected one.
|
||||
window.setTimeout(function() {
|
||||
var iterationsLeft = 20;
|
||||
var int = window.setInterval(function() {
|
||||
iterationsLeft--;
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
try {
|
||||
var title = w.document.title;
|
||||
}
|
||||
catch (ex) {
|
||||
alert(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (iterationsLeft == 0 || title.match(expected_title)) {
|
||||
window.clearInterval(int);
|
||||
f(iterationsLeft > 0);
|
||||
}
|
||||
}, 100);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function windowLoaded()
|
||||
{
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
switch (phase)
|
||||
{
|
||||
case 0:
|
||||
/* 2. We have succeededfully loaded a page, now go to a faulty URL */
|
||||
window.setTimeout(function() {
|
||||
w.location.href = faultyURL;
|
||||
}, 0);
|
||||
|
||||
phase = 1;
|
||||
|
||||
pollForPage("Problem loading page", function(succeeded) {
|
||||
ok(succeeded, "Waiting for error page succeeded");
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
/* 3. now, while we are on the error page, try to reload it, actually
|
||||
click the "Try Again" button */
|
||||
w.location.reload();
|
||||
|
||||
pollForPage("Problem loading page", function(succeeded) {
|
||||
ok(succeeded, "Waiting for error page succeeded");
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
/* 4-finish, check we are still on the error page */
|
||||
is(w.location.href, faultyURL, "Is on an error page");
|
||||
isnot(w.location.href, workingURL, "Is not on the previous page");
|
||||
is(gotWrongPageOnTryAgainClick, false,
|
||||
"Must not get www.example.com page on reload of an error page");
|
||||
w.close();
|
||||
SimpleTest.finish();
|
||||
}, w);
|
||||
}, w);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
/* 4-check, we must not get here! */
|
||||
gotWrongPageOnTryAgainClick = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function startTest()
|
||||
{
|
||||
/* 1. load a URL that leads to an error page */
|
||||
w = window.open(workingURL);
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload="startTest();">
|
||||
</body>
|
||||
</html>
|
||||
90
mozilla/docshell/test/test_bug529119-2.html
Normal file
90
mozilla/docshell/test/test_bug529119-2.html
Normal file
@@ -0,0 +1,90 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test bug 529119</title>
|
||||
<script type="text/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
|
||||
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var workingURL = "http://localhost:8888/tests/docshell/test/bug529119-window.html";
|
||||
var faultyURL = "http://some-non-existent-domain-27489274c892748217cn2384.com/";
|
||||
|
||||
var w = null;
|
||||
var phase = 0;
|
||||
|
||||
function pollForPage(expected_title, f, w)
|
||||
{
|
||||
// Start with polling after a delay, we might mistakenly take the current page
|
||||
// as an expected one.
|
||||
window.setTimeout(function() {
|
||||
var iterationsLeft = 20;
|
||||
var int = window.setInterval(function() {
|
||||
iterationsLeft--;
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
try {
|
||||
var title = w.document.title;
|
||||
}
|
||||
catch (ex) {
|
||||
alert(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (iterationsLeft == 0 || title.match(expected_title)) {
|
||||
window.clearInterval(int);
|
||||
f(iterationsLeft > 0);
|
||||
}
|
||||
}, 100);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function windowLoaded()
|
||||
{
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
/* 2. We have successfully loaded a page, now go to a faulty URL */
|
||||
// XXX The test fails when we change the location synchronously
|
||||
window.setTimeout(function() {
|
||||
w.location.href = faultyURL;
|
||||
}, 0);
|
||||
|
||||
pollForPage("Problem loading page", function(succeeded) {
|
||||
ok(succeeded, "Waiting for error page succeeded");
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
/* 3. now, while we are on the error page, navigate back */
|
||||
try {
|
||||
w.back();
|
||||
}
|
||||
catch(ex) {
|
||||
ok(false, "w.back() threw " + ex);
|
||||
}
|
||||
|
||||
pollForPage("Test bug 529119, sub-window", function(succeeded) {
|
||||
ok(succeeded, "Waiting for original page succeeded");
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
/* 4-finish, check we are back at the original page */
|
||||
isnot(w.location.href, faultyURL, "Is on an error page");
|
||||
is(w.location.href, workingURL, "Is not on the previous page");
|
||||
w.close();
|
||||
SimpleTest.finish();
|
||||
}, w);
|
||||
}, w);
|
||||
}
|
||||
|
||||
function startTest()
|
||||
{
|
||||
/* 1. load a URL that leads to an error page */
|
||||
w = window.open(workingURL);
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload="startTest();">
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user