mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 04:38:02 +00:00
Bug 1734858, use the real index when updating the index after a bfcache load, r=peterv
The issue is that when going back from a non-bfcacheable page to a bfcacheable page and the first page modifies requested index around the same time, UpdateIndex() doesn't have the right requested index. This is a variant of bug 1725680. The test case loads a non-bfcacheable page, then bfcachable, then another non-bfcacheable and then goes back and forward. Without the patch indexes go wrong and forward doesn't do anything. Differential Revision: https://phabricator.services.mozilla.com/D127963
This commit is contained in:
parent
65e776bc5a
commit
9eb90441a7
@ -1202,9 +1202,14 @@ static void FinishRestore(CanonicalBrowsingContext* aBrowsingContext,
|
||||
|
||||
aEntry->SetFrameLoader(nullptr);
|
||||
|
||||
nsCOMPtr<nsISHistory> shistory = aEntry->GetShistory();
|
||||
int32_t indexOfHistoryLoad =
|
||||
shistory ? shistory->GetIndexOfEntry(aEntry) : -1;
|
||||
|
||||
nsCOMPtr<nsFrameLoaderOwner> frameLoaderOwner =
|
||||
do_QueryInterface(aBrowsingContext->GetEmbedderElement());
|
||||
if (frameLoaderOwner && aFrameLoader->GetMaybePendingBrowsingContext()) {
|
||||
if (frameLoaderOwner && aFrameLoader->GetMaybePendingBrowsingContext() &&
|
||||
indexOfHistoryLoad >= 0) {
|
||||
// Synthesize a STATE_START WebProgress state change event from here
|
||||
// in order to ensure emitting it on the BrowsingContext we navigate *from*
|
||||
// instead of the BrowsingContext we navigate *to*.
|
||||
@ -1255,7 +1260,8 @@ static void FinishRestore(CanonicalBrowsingContext* aBrowsingContext,
|
||||
|
||||
// Assuming we still have the session history, update the index.
|
||||
if (loadingBC->GetSessionHistory()) {
|
||||
loadingBC->GetSessionHistory()->UpdateIndex();
|
||||
shistory->InternalSetRequestedIndex(indexOfHistoryLoad);
|
||||
shistory->UpdateIndex();
|
||||
}
|
||||
loadingBC->HistoryCommitIndexAndLength();
|
||||
Unused << loadingBC->SetIsInBFCache(false);
|
||||
|
@ -0,0 +1,22 @@
|
||||
<script>
|
||||
window.onpageshow = function(e) {
|
||||
if (location.search == "?v2") {
|
||||
onbeforeunload = function() {
|
||||
history.pushState("data1", "", "?push1");
|
||||
}
|
||||
}
|
||||
|
||||
let bc = new BroadcastChannel("new_shentry_during_history_navigation");
|
||||
bc.onmessage = function(event) {
|
||||
bc.close();
|
||||
if (event.data == "loadnext") {
|
||||
location.href = "file_new_shentry_during_history_navigation_4.html";
|
||||
} else if (event.data == "back") {
|
||||
history.back();
|
||||
} else if (event.data == "close") {
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
bc.postMessage({page: location.href, type: e.type, persisted: e.persisted});
|
||||
}
|
||||
</script>
|
@ -0,0 +1 @@
|
||||
Cache-control: no-store
|
@ -0,0 +1,16 @@
|
||||
<script>
|
||||
window.onpageshow = function(e) {
|
||||
let bc = new BroadcastChannel("new_shentry_during_history_navigation");
|
||||
bc.onmessage = function(event) {
|
||||
bc.close();
|
||||
if (event.data == "loadnext") {
|
||||
location.href = "file_new_shentry_during_history_navigation_3.html?v2";
|
||||
} else if (event.data == "forward") {
|
||||
history.forward();
|
||||
} else if (event.data == "close") {
|
||||
window.close();
|
||||
}
|
||||
}
|
||||
bc.postMessage({page: location.href, type: e.type, persisted: e.persisted});
|
||||
}
|
||||
</script>
|
@ -133,6 +133,9 @@ support-files =
|
||||
file_new_shentry_during_history_navigation_1.html^headers^
|
||||
file_new_shentry_during_history_navigation_2.html
|
||||
file_new_shentry_during_history_navigation_2.html^headers^
|
||||
file_new_shentry_during_history_navigation_3.html
|
||||
file_new_shentry_during_history_navigation_3.html^headers^
|
||||
file_new_shentry_during_history_navigation_4.html
|
||||
[test_not-opener.html]
|
||||
[test_online_offline_bfcache.html]
|
||||
support-files = file_online_offline_bfcache.html
|
||||
|
@ -43,13 +43,43 @@
|
||||
setTimeout(function() {
|
||||
win.onmessage = null;
|
||||
win.close();
|
||||
SimpleTest.finish();
|
||||
testBfcache();
|
||||
}, 500);
|
||||
window.onmessage = function(event) {
|
||||
ok(false, "Should not get a message " + event.data);
|
||||
}
|
||||
}
|
||||
|
||||
async function testBfcache() {
|
||||
let bc = new BroadcastChannel("new_shentry_during_history_navigation");
|
||||
let pageshowCount = 0;
|
||||
bc.onmessage = function(event) {
|
||||
if (event.data.type == "pageshow") {
|
||||
++pageshowCount;
|
||||
info("pageshow: " + pageshowCount + ", page: " + event.data.page);
|
||||
if (pageshowCount == 1) {
|
||||
ok(!event.data.persisted, "The page should not be bfcached.");
|
||||
bc.postMessage("loadnext");
|
||||
} else if (pageshowCount == 2) {
|
||||
ok(!event.data.persisted, "The page should not be bfcached.");
|
||||
bc.postMessage("loadnext");
|
||||
} else if (pageshowCount == 3) {
|
||||
ok(!event.data.persisted, "The page should not be bfcached.");
|
||||
bc.postMessage("back");
|
||||
} else if (pageshowCount == 4) {
|
||||
ok(event.data.persisted, "The page should be bfcached.");
|
||||
bc.postMessage("forward");
|
||||
} else if (pageshowCount == 5) {
|
||||
ok(event.data.page.includes("v2"), "Should have gone forward.");
|
||||
bc.postMessage("close");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
win = window.open("file_new_shentry_during_history_navigation_3.html", "", "noopener");
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload="test()">
|
||||
|
Loading…
x
Reference in New Issue
Block a user