Commit 573470e6 authored by Lowell Manners's avatar Lowell Manners Committed by Commit Bot

[bfcache] Add a method that can disable the BackForwardCache in tests.

This method allows tests to force not using the BackForwardCache, this
is useful when:
  * Tests rely on a new document being loaded.
  * Tests want to specifically test the document not being in the cache.
  * Any other reason BFCache doesn't make sense for a particular test.

Change-Id: I07fbc0a31023a78109268c100e5f454dbfbed13f
Bug: 973855,965925
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1657836Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Commit-Queue: Lowell Manners <lowell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683552}
parent e1b85c15
......@@ -809,6 +809,25 @@ IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest, DoesNotCacheIfWebGL) {
// The page had an active WebGL context when we navigated away,
// so it shouldn't have been cached.
}
IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest,
DisableBackforwardCacheForTesting) {
ASSERT_TRUE(embedded_test_server()->Start());
// Disable the BackForwardCache.
web_contents()->GetController().back_forward_cache().DisableForTesting();
// Navigate to a page that would normally be cacheable.
NavigateToURL(shell(),
embedded_test_server()->GetURL("a.com", "/title1.html"));
RenderFrameDeletedObserver delete_rfh_a(current_frame_host());
// Navigate away.
NavigateToURL(shell(),
embedded_test_server()->GetURL("b.com", "/title1.html"));
// The page should be deleted (not cached).
delete_rfh_a.WaitUntilDeleted();
}
......
......@@ -93,7 +93,7 @@ bool BackForwardCache::CanStoreDocument(RenderFrameHostImpl* rfh) {
if (rfh->GetParent())
return false;
if (!IsBackForwardCacheEnabled())
if (!IsBackForwardCacheEnabled() || is_disabled_for_testing_)
return false;
// Note that we check is_loading on the rfh directly, rather than calling
......@@ -174,9 +174,17 @@ std::unique_ptr<RenderFrameHostImpl> BackForwardCache::RestoreDocument(
return rfh;
}
// Remove all entries from the BackForwardCache.
void BackForwardCache::Flush() {
render_frame_hosts_.clear();
}
void BackForwardCache::DisableForTesting() {
is_disabled_for_testing_ = true;
// This could happen if a test populated some pages in the cache, then
// called DisableForTesting(). This is not something we currently expect tests
// to do.
DCHECK(render_frame_hosts_.empty());
}
} // namespace content
......@@ -49,6 +49,17 @@ class CONTENT_EXPORT BackForwardCache {
// Remove all entries from the BackForwardCache.
void Flush();
// Disables the BackForwardCache so that no documents will be stored/served.
// This allows tests to "force" not using the BackForwardCache, this can be
// useful when:
// * Tests rely on a new document being loaded.
// * Tests want to test this case specifically.
// Note: It's preferable to make tests BackForwardCache compatible
// when feasible, rather than using this method. Also please consider whether
// you actually should have 2 tests, one with the document cached
// (BackForwardCache enabled), and one without.
void DisableForTesting();
private:
// Contains the set of stored RenderFrameHost.
// Invariant:
......@@ -56,6 +67,9 @@ class CONTENT_EXPORT BackForwardCache {
// - Once the list is full, the least recently used document is evicted.
std::list<std::unique_ptr<RenderFrameHostImpl>> render_frame_hosts_;
// Whether the BackforwardCached has been disabled for testing.
bool is_disabled_for_testing_ = false;
DISALLOW_COPY_AND_ASSIGN(BackForwardCache);
};
} // namespace content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment