Bug 1741132 - Correctly evict entries with session history in parent. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D131894
This commit is contained in:
Peter Van der Beken 2021-11-23 15:37:24 +00:00
Родитель 00ffaf83c0
Коммит afd1bab71f
4 изменённых файлов: 99 добавлений и 0 удалений

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

@ -2143,6 +2143,8 @@ void CanonicalBrowsingContext::HistoryCommitIndexAndLength(
GetChildSessionHistory()->SetIndexAndLength(index, length, aChangeID); GetChildSessionHistory()->SetIndexAndLength(index, length, aChangeID);
shistory->EvictOutOfRangeContentViewers(index);
Group()->EachParent([&](ContentParent* aParent) { Group()->EachParent([&](ContentParent* aParent) {
Unused << aParent->SendHistoryCommitIndexAndLength(this, index, length, Unused << aParent->SendHistoryCommitIndexAndLength(this, index, length,
aChangeID); aChangeID);

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

@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script>
window.addEventListener("pageshow", ({ persisted }) => {
let bc = new BroadcastChannel("bug1741132");
bc.addEventListener("message", ({ data: { cmd, arg } }) => {
switch (cmd) {
case "load":
bc.close();
document.location = arg;
break;
case "go":
history.go(arg);
break;
case "close":
window.close();
break;
}
});
bc.postMessage(persisted);
});
</script>
</head>
<body>
</body>
</html>

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

@ -121,6 +121,9 @@ support-files =
support-files = support-files =
file_bug1740517.html file_bug1740517.html
file_bug1740517.html^headers^ file_bug1740517.html^headers^
[test_bug1741132.html]
support-files =
file_bug1741132.html
[test_close_onpagehide_by_history_back.html] [test_close_onpagehide_by_history_back.html]
[test_close_onpagehide_by_window_close.html] [test_close_onpagehide_by_window_close.html]
[test_compressed_multipart.html] [test_compressed_multipart.html]

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

@ -0,0 +1,66 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test form restoration for no-store pages</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
// The number of entries which we keep in the BFCache (see nsSHistory.h).
const VIEWER_WINDOW = 3;
SimpleTest.waitForExplicitFinish();
function runTest() {
let bc = new BroadcastChannel("bug1741132");
let load = new Promise(resolve => {
bc.addEventListener("message", resolve, { once: true });
window.open("file_bug1741132.html", "", "noopener");
});
// We want to try to keep one entry too many in the BFCache,
// so we ensure that there's at least VIEWER_WINDOW + 2
// entries in session history (with one for the displayed
// page).
for (let i = 0; i < VIEWER_WINDOW + 2; ++i) {
load = load.then(() => {
return new Promise((resolve) => {
bc.addEventListener("message", resolve, { once: true });
bc.postMessage({ cmd: "load", arg: `file_bug1741132.html?${i}` });
});
});
}
load.then(() => {
return new Promise((resolve) => {
bc.addEventListener("message", ({ data: persisted }) => {
resolve(persisted);
}, { once: true });
// Go back past the first entry that should be in the BFCache.
bc.postMessage({ cmd: "go", arg: -(VIEWER_WINDOW + 1) });
});
}).then((persisted) => {
ok(!persisted, "Only 3 pages should be kept in the BFCache");
}).then(() => {
return new Promise((resolve) => {
bc.addEventListener("message", ({ data: persisted }) => {
resolve(persisted);
}, { once: true });
// Go forward to the first entry that should be in the BFCache.
bc.postMessage({ cmd: "go", arg: 1 });
});
}).then((persisted) => {
ok(persisted, "3 pages should be kept in the BFCache");
bc.postMessage("close");
SimpleTest.finish();
});
}
</script>
</head>
<body onload="runTest();">
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>