From ca3c587dfcac2846e2a377c2d0877932c9838418 Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Sat, 29 May 2021 08:51:47 +0000 Subject: [PATCH] Bug 1705872 - Clear history's epoch in the parent when replacing BC. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D116243 --- docshell/base/CanonicalBrowsingContext.cpp | 8 +-- docshell/test/browser/browser.ini | 1 + docshell/test/browser/browser_bug1705872.js | 74 +++++++++++++++++++++ 3 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 docshell/test/browser/browser_bug1705872.js diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp index d196c342f83d..b8e3e389569d 100644 --- a/docshell/base/CanonicalBrowsingContext.cpp +++ b/docshell/base/CanonicalBrowsingContext.cpp @@ -214,10 +214,10 @@ void CanonicalBrowsingContext::ReplacedBy( if (mSessionHistory) { mSessionHistory->SetBrowsingContext(aNewContext); - if (mozilla::BFCacheInParent()) { - // XXXBFCache Should we clear the epoch always? - mSessionHistory->SetEpoch(0, Nothing()); - } + // At this point we will be creating a new ChildSHistory in the child. + // That means that the child's epoch will be reset, so it makes sense to + // reset the epoch in the parent too. + mSessionHistory->SetEpoch(0, Nothing()); mSessionHistory.swap(aNewContext->mSessionHistory); RefPtr childSHistory = ForgetChildSHistory(); aNewContext->SetChildSHistory(childSHistory); diff --git a/docshell/test/browser/browser.ini b/docshell/test/browser/browser.ini index 9c0c73e96f46..8487dada8a66 100644 --- a/docshell/test/browser/browser.ini +++ b/docshell/test/browser/browser.ini @@ -193,3 +193,4 @@ support-files = [browser_bug1648464-1.js] [browser_bug1688368-1.js] [browser_bug1691153.js] +[browser_bug1705872.js] diff --git a/docshell/test/browser/browser_bug1705872.js b/docshell/test/browser/browser_bug1705872.js new file mode 100644 index 000000000000..35a3f66d1388 --- /dev/null +++ b/docshell/test/browser/browser_bug1705872.js @@ -0,0 +1,74 @@ +"use strict"; + +async function doLoadAndGoBack(browser, ext) { + let loaded = BrowserTestUtils.browserLoaded(browser); + BrowserTestUtils.loadURI(browser, "https://example.com/"); + await ext.awaitMessage("redir-handled"); + await loaded; + + let pageShownPromise = BrowserTestUtils.waitForContentEvent( + browser, + "pageshow", + true + ); + await SpecialPowers.spawn(browser, [], () => { + content.history.back(); + }); + return pageShownPromise; +} + +add_task(async function test_back() { + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + permissions: ["webRequest", "webRequestBlocking", "https://example.com/"], + web_accessible_resources: ["test.html"], + }, + files: { + "test.html": + "Test add-on", + }, + background: () => { + let { browser } = this; + browser.webRequest.onHeadersReceived.addListener( + details => { + if (details.statusCode != 200) { + return undefined; + } + browser.test.sendMessage("redir-handled"); + return { redirectUrl: browser.runtime.getURL("test.html") }; + }, + { + urls: ["https://example.com/"], + types: ["main_frame"], + }, + ["blocking"] + ); + }, + }); + + await extension.startup(); + + await BrowserTestUtils.withNewTab("about:home", async function(browser) { + await doLoadAndGoBack(browser, extension); + + await SpecialPowers.spawn(browser, [], () => { + is( + content.document.documentURI, + "about:home", + "Gone back to the right page" + ); + }); + + await doLoadAndGoBack(browser, extension); + + await SpecialPowers.spawn(browser, [], () => { + is( + content.document.documentURI, + "about:home", + "Gone back to the right page" + ); + }); + }); + + await extension.unload(); +});