Bug 1750973, don't replace the nsILayoutHistoryState object when doing same document history navigations, r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D137703
This commit is contained in:
Olli Pettay 2022-02-04 11:37:14 +00:00
parent bc552e977b
commit 90b2d9e86c
4 changed files with 80 additions and 0 deletions

View File

@ -9005,7 +9005,20 @@ nsresult nsDocShell::HandleSameDocumentNavigation(
"%s",
this, mLoadingEntry->mInfo.GetURI()->GetSpecOrDefault().get()));
bool hadActiveEntry = !!mActiveEntry;
nsCOMPtr<nsILayoutHistoryState> currentLayoutHistoryState;
if (mActiveEntry) {
currentLayoutHistoryState = mActiveEntry->GetLayoutHistoryState();
}
mActiveEntry = MakeUnique<SessionHistoryInfo>(mLoadingEntry->mInfo);
if (currentLayoutHistoryState) {
// Restore the existing nsILayoutHistoryState object, since it is
// possibly being used by the layout. When doing a new load, the
// shared state is copied from the existing active entry, so this
// special case is needed only with the history loads.
mActiveEntry->SetLayoutHistoryState(currentLayoutHistoryState);
}
if (cacheKey != 0) {
mActiveEntry->SetCacheKey(cacheKey);
}

View File

@ -0,0 +1,45 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script>
function test() {
history.scrollRestoration = "manual";
document.getElementById("initialfocus").focus();
history.pushState('data', '', '');
history.back();
}
window.onpopstate = function() {
window.onscroll = function() {
window.onscroll = null;
document.documentElement.style.display = "none";
// focus() triggers recreation of the nsIFrames without a reflow.
document.getElementById("focustarget").focus();
document.documentElement.style.display = "";
// Flush the layout.
document.documentElement.getBoundingClientRect();
opener.isnot(window.scrollY, 0, "The page should have been scrolled down(1)");
requestAnimationFrame(
function() {
// Extra timeout to ensure we're called after rAF has triggered a
// reflow.
setTimeout(function() {
opener.isnot(window.scrollY, 0, "The page should have been scrolled down(2)");
window.close();
opener.SimpleTest.finish();
});
});
}
window.scrollTo(0, 1000);
}
</script>
</head>
<body onload="setTimeout(test)">
<div style="position: fixed;">
<input type="button" value="" id="initialfocus">
<input type="button" value="" id="focustarget">
</div>
<div style="border: 1px solid black; width: 100px; height: 9000px;"></div>
</body>
</html>

View File

@ -104,6 +104,8 @@ support-files = file_bug1745638.html
support-files =
goback.html
cache_control_max_age_3600.sjs
[test_bug1750973.html]
support-files = file_bug1750973.html
[test_bug270414.html]
[test_bug278916.html]
[test_bug279495.html]

View File

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>The layout state restoration when reframing the root element</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
SimpleTest.waitForExplicitFinish();
function test() {
window.open("file_bug1750973.html");
}
</script>
</head>
<body onload="setTimeout(test)">
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>