Bug 1769189, ensure history state is updated if beforeunload listener calls replaceState, r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D152170
This commit is contained in:
Olli Pettay 2022-10-17 12:56:37 +00:00
parent d50a36b7e8
commit b989d9a4ca
5 changed files with 42 additions and 2 deletions

View File

@ -572,6 +572,12 @@ CanonicalBrowsingContext::CreateLoadingSessionHistoryEntryForLoad(
if (!entry) {
return nullptr;
}
// If the entry was updated, update also the LoadingSessionHistoryInfo.
UniquePtr<LoadingSessionHistoryInfo> lshi =
MakeUnique<LoadingSessionHistoryInfo>(entry, existingLoadingInfo);
aLoadState->SetLoadingSessionHistoryInfo(std::move(lshi));
existingLoadingInfo = aLoadState->GetLoadingSessionHistoryInfo();
Unused << SetHistoryEntryCount(entry->BCHistoryLength());
} else if (aLoadState->LoadType() == LOAD_REFRESH &&
!ShouldAddEntryForRefresh(aLoadState->URI(),

View File

@ -385,7 +385,7 @@ LoadingSessionHistoryInfo::LoadingSessionHistoryInfo(
}
LoadingSessionHistoryInfo::LoadingSessionHistoryInfo(
SessionHistoryEntry* aEntry, LoadingSessionHistoryInfo* aInfo)
SessionHistoryEntry* aEntry, const LoadingSessionHistoryInfo* aInfo)
: mInfo(aEntry->Info()),
mLoadId(aInfo->mLoadId),
mLoadIsFromSessionHistory(aInfo->mLoadIsFromSessionHistory),

View File

@ -222,7 +222,7 @@ struct LoadingSessionHistoryInfo {
explicit LoadingSessionHistoryInfo(SessionHistoryEntry* aEntry);
// Initializes mInfo using aEntry and otherwise copies the values from aInfo.
LoadingSessionHistoryInfo(SessionHistoryEntry* aEntry,
LoadingSessionHistoryInfo* aInfo);
const LoadingSessionHistoryInfo* aInfo);
// For about:blank only.
explicit LoadingSessionHistoryInfo(const SessionHistoryInfo& aInfo);

View File

@ -111,6 +111,7 @@ https_first_disabled = true
skip-if = !fission || !crashreporter # On a crash we only keep history when fission is enabled.
[browser_bug1719178.js]
[browser_bug1757005.js]
[browser_bug1769189.js]
[browser_bug234628-1.js]
[browser_bug234628-10.js]
[browser_bug234628-11.js]

View File

@ -0,0 +1,33 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function test_beforeUnload_and_replaceState() {
await BrowserTestUtils.withNewTab(
{
gBrowser,
url:
"data:text/html,<script>window.addEventListener('beforeunload', () => { window.history.replaceState(true, ''); });</script>",
},
async function(browser) {
let initialState = await SpecialPowers.spawn(browser, [], () => {
return content.history.state;
});
is(initialState, null, "history.state should be initially null.");
let awaitPageShow = BrowserTestUtils.waitForContentEvent(
browser,
"pageshow"
);
BrowserReload();
await awaitPageShow;
let updatedState = await SpecialPowers.spawn(browser, [], () => {
return content.history.state;
});
is(updatedState, true, "history.state should have been updated.");
}
);
});