Bug 94514 - POST result page should not appear in global history or history autocomplete results. r=bz, sr=bz

This commit is contained in:
sdwilsh@shawnwilsher.com 2008-02-06 10:18:07 -08:00
Родитель 713f77ff58
Коммит 5a9e2e5116
4 изменённых файлов: 106 добавлений и 0 удалений

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

@ -8612,6 +8612,16 @@ nsDocShell::AddToGlobalHistory(nsIURI * aURI, PRBool aRedirect,
if (mItemType != typeContent || !mGlobalHistory) if (mItemType != typeContent || !mGlobalHistory)
return NS_OK; return NS_OK;
// If this is a POST request, we do not want to include this in global
// history, so return early.
nsCOMPtr<nsIHttpChannel> hchan(do_QueryInterface(aChannel));
if (hchan) {
nsCAutoString type;
nsresult rv = hchan->GetRequestMethod(type);
if (NS_SUCCEEDED(rv) && type.EqualsLiteral("POST"))
return NS_OK;
}
PRBool visited; PRBool visited;
nsresult rv = mGlobalHistory->IsVisited(aURI, &visited); nsresult rv = mGlobalHistory->IsVisited(aURI, &visited);
if (NS_FAILED(rv)) if (NS_FAILED(rv))

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

@ -54,6 +54,8 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk
_TEST_FILES = \ _TEST_FILES = \
test_bug94514.html \
bug94514-postpage.html \
test_bug344861.html \ test_bug344861.html \
test_bug369814.html \ test_bug369814.html \
bug369814.zip \ bug369814.zip \

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

@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=94514
Specifically, this is a test page that actually submits a form.
-->
<head>
<title>Test Page for Bug 94515</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
</head>
<body>
<form id="testForm" method="POST">
<input type="submit" id="send"/>
</form>
<script class="testbody" type="text/javascript">
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
if (!window.location.href.match("posted=1")) {
// Here we just submit the form
var form = $("testForm");
form.action = window.location.href + "?posted=1";
form.submit();
} else {
window.opener.finishTest();
}
</script>
</body>
</html>

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

@ -0,0 +1,64 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=94514
Specifically, this tests that a page that is obtained via a post request does
not get added to global history.
-->
<head>
<title>Test for Bug 94515</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=94514">Mozilla Bug 94514</a>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
var startURI = "http://localhost:8888/tests/docshell/test/bug94514-postpage.html";
var postedURI = startURI + "?posted=1";
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const Cc = Components.classes;
const Ci = Components.interfaces;
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var startPage = ios.newURI(startURI, null, null);
var postedPage = ios.newURI(postedURI, null, null);
var gh = Cc["@mozilla.org/browser/global-history;2"].
getService(Ci.nsIGlobalHistory2);
SimpleTest.ok(!gh.isVisited(startPage),
"Initial page does not start in global history. Note: " +
"this will also fail if you run the test twice.");
SimpleTest.ok(!gh.isVisited(postedPage),
"Posted page does not start in global history.");
var w = window.open(startURI, "", "width=10,height=10");
function finishTest()
{
// We need to check that this was not added to global history.
SimpleTest.ok(gh.isVisited(startPage),
"Initial page was added to global history.");
SimpleTest.ok(!gh.isVisited(postedPage),
"Posted page was not added to global history.");
w.close();
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>