Bug 1909698 - Use URI from session history when coming out from bfcache. r=peterv

Differential Revision: https://phabricator.services.mozilla.com/D222118
This commit is contained in:
Andreas Farre 2024-09-17 12:17:38 +00:00
parent 52ec377ade
commit ff63578440
3 changed files with 49 additions and 1 deletions

View File

@ -1329,7 +1329,20 @@ void nsDocShell::FirePageHideShowNonRecursive(bool aShow) {
mEODForCurrentDocument = false;
mIsRestoringDocument = true;
mLoadGroup->AddRequest(channel, nullptr);
SetCurrentURI(doc->GetDocumentURI(), channel,
nsCOMPtr<nsIURI> uri;
if (doc->FragmentDirective()) {
// If we have fragment directives, then we've mutated the document
// uri. Set the current URI from session history instead.
if (mozilla::SessionHistoryInParent()) {
uri = mActiveEntry ? mActiveEntry->GetURI() : nullptr;
} else if (mOSHE) {
uri = mOSHE->GetURI();
}
}
if (!uri) {
uri = doc->GetDocumentURI();
}
SetCurrentURI(uri, channel,
/* aFireOnLocationChange */ true,
/* aIsInitialAboutBlank */ false,
/* aLocationFlags */ 0);

View File

@ -78,6 +78,8 @@ support-files = [
"file_backforward_restore_scroll.html^headers^",
]
["browser_backforward_text_fragment_restore_urlbar.js"]
["browser_backforward_userinteraction.js"]
support-files = ["dummy_iframe_page.html"]
skip-if = ["os == 'linux' && bits == 64 && !debug"] # Bug 1607713

View File

@ -0,0 +1,33 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const ROOT = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"http://mochi.test:8888"
);
const URL = `${ROOT}/dummy_page.html#:~:text=dummy`;
function waitForPageShow(browser) {
return BrowserTestUtils.waitForContentEvent(browser, "pageshow", true);
}
add_task(async function test_fragment_restore_urlbar() {
await BrowserTestUtils.withNewTab("https://example.com", async browser => {
let loaded = BrowserTestUtils.browserLoaded(browser, false);
BrowserTestUtils.startLoadingURIString(browser, URL);
await loaded;
// Go back in history.
let change = waitForPageShow(browser);
browser.goBack();
await change;
change = waitForPageShow(browser);
// Go forward in history.
browser.goForward();
await change;
is(gURLBar.inputField.value, URL, "URL should have text directive");
});
});