Bug 1670973, add a test to check how http redirects affect to the session history, r=peterv

The old implementation and SHIP seem to have the same behavior.

Differential Revision: https://phabricator.services.mozilla.com/D123117
This commit is contained in:
Olli Pettay 2021-08-30 19:33:52 +00:00
Родитель a2ff77838c
Коммит 1c1c20f331
7 изменённых файлов: 158 добавлений и 0 удалений

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

@ -0,0 +1,16 @@
<!DOCTYPE HTML>
<html>
<head>
<script>
window.onpagehide = function(event) {
opener.is(event.persisted, false, "Should have disabled bfcache for this test.");
}
window.onpageshow = function(event) {
opener.pageshow();
}
</script>
</head>
<body>
</body>
</html>

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

@ -0,0 +1 @@
Cache-control: no-store

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

@ -0,0 +1,16 @@
<!DOCTYPE HTML>
<html>
<head>
<script>
window.onpagehide = function(event) {
opener.is(event.persisted, false, "Should have disabled bfcache for this test.");
}
window.onpageshow = function(event) {
opener.pageshow();
}
</script>
</head>
<body>
</body>
</html>

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

@ -0,0 +1 @@
Cache-control: no-store

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

@ -66,6 +66,11 @@ support-files =
file_scrollRestoration_part2_bfcache.html
file_scrollRestoration_part3_nobfcache.html
file_scrollRestoration_part3_nobfcache.html^headers^
file_session_history_on_redirect.html
file_session_history_on_redirect.html^headers^
file_session_history_on_redirect_2.html
file_session_history_on_redirect_2.html^headers^
redirect_handlers.sjs
frame_load_as_example_com.html
frame_load_as_example_org.html
frame_load_as_host1.html
@ -132,6 +137,7 @@ support-files = file_reload.html
skip-if =
(debug && e10s) # bug 1263213
[test_performance_navigation.html]
[test_session_history_on_redirect.html]
[test_sessionhistory.html]
skip-if = verify && (os == 'mac') && debug && webrender # Hit MOZ_CRASH(Shutdown too long, probably frozen, causing a crash.) bug 1677545
[test_dynamic_frame_forward_back.html]

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

@ -0,0 +1,26 @@
function handleRequest(request, response) {
response.setHeader("Cache-Control", "no-cache", false);
response.setHeader("Cache-Control", "no-store", false);
let state = getState("sessionhistory_do_redirect");
if (state != "doredirect") {
response.setHeader("Content-Type", "text/html");
const contents = `
<script>
window.onpageshow = function(event) {
opener.pageshow();
}
</script>
`;
response.write(contents);
// The next load should do a redirect.
setState("sessionhistory_do_redirect", "doredirect");
} else {
setState("sessionhistory_do_redirect", "");
response.setStatusLine("1.1", 302, "Found");
response.setHeader("Location",
"file_session_history_on_redirect_2.html", false);
}
}

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

@ -0,0 +1,92 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Session history on redirect</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
/*
* The test opens a new window and loads a page there. Then another document
* is loaded to the window. The initial load of that second page doesn't do
* a redirect. Now another non-redirecting page is loaded. Then
* history.go(-2) and history.forward() are called. The second time
* the second page is loaded, it does a redirect. history.back() and
* history.forward() are called again. The page which did the redirect
* shouldn't be accessed, but the page which it redirected to.
* Finally history.forward() is called again and the third page should be
* loaded and history.length should have the same value as it had when the
* third page was loaded the first time.
*/
SimpleTest.waitForExplicitFinish();
var win;
var finalHistoryLength = 0;
function run() {
win = window.open("file_session_history_on_redirect.html");
}
var pageshowCounter = 0;
async function pageshow() {
// Need to trigger new loads asynchronously after page load, otherwise
// new loads are treated as replace loads.
await new Promise((r) => setTimeout(r));
++pageshowCounter;
info("Page load: " + win.location.href);
switch (pageshowCounter) {
case 1:
ok(win.location.href.includes("file_session_history_on_redirect.html"));
win.location.href = "redirect_handlers.sjs";
break;
case 2:
ok(win.location.href.includes("redirect_handlers.sjs"));
// Put the initial page also as the last entry in the session history.
win.location.href = "file_session_history_on_redirect.html";
break;
case 3:
ok(win.location.href.includes("file_session_history_on_redirect.html"));
finalHistoryLength = win.history.length;
win.history.go(-2);
break;
case 4:
ok(win.location.href.includes("file_session_history_on_redirect.html"));
win.history.forward();
break;
case 5:
ok(win.location.href.includes("file_session_history_on_redirect_2.html"));
win.history.back();
break;
case 6:
ok(win.location.href.includes("file_session_history_on_redirect.html"));
win.history.forward();
break;
case 7:
ok(win.location.href.includes("file_session_history_on_redirect_2.html"));
is(win.history.length, finalHistoryLength, "Shouldn't have changed the history length.");
win.history.forward();
break;
case 8:
ok(win.location.href.includes("file_session_history_on_redirect.html"));
is(win.history.length, finalHistoryLength, "Shouldn't have changed the history length.");
win.onpagehide = null;
finishTest();
break;
default:
ok(false, "unexpected pageshow");
}
}
function finishTest() {
win.close()
SimpleTest.finish();
}
</script>
</head>
<body onload="run()">
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>