Skip to content

Commit

Permalink
Bug 529119 - Funky behavior with XUL error pages, r=bz
Browse files Browse the repository at this point in the history
  • Loading branch information
mayhemer committed Nov 18, 2009
1 parent 7400cac commit 4caede5
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 14 deletions.
28 changes: 14 additions & 14 deletions docshell/base/nsDocShell.cpp
Expand Up @@ -3798,20 +3798,6 @@ nsDocShell::LoadErrorPage(nsIURI *aURI, const PRUnichar *aURL,
mFailedURI = aURI;
mFailedLoadType = mLoadType;

// 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);
}

nsCAutoString url;
nsCAutoString charset;
if (aURI)
Expand Down Expand Up @@ -7052,6 +7038,20 @@ nsDocShell::CreateContentViewer(const char *aContentType,
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);

Expand Down
3 changes: 3 additions & 0 deletions docshell/test/Makefile.in
Expand Up @@ -78,6 +78,9 @@ _TEST_FILES = \
file_bug385434_3.html \
test_bug509055.html \
file_bug509055.html \
test_bug529119-1.html \
test_bug529119-2.html \
bug529119-window.html \
$(NULL)

ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
Expand Down
7 changes: 7 additions & 0 deletions docshell/test/bug529119-window.html
@@ -0,0 +1,7 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test bug 529119, sub-window</title>
<body onload="window.opener.windowLoaded();">
</body>
</html>
99 changes: 99 additions & 0 deletions docshell/test/test_bug529119-1.html
@@ -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 changes: 90 additions & 0 deletions docshell/test/test_bug529119-2.html
@@ -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>

0 comments on commit 4caede5

Please sign in to comment.