Commit 44086fbe authored by Sreeja Kamishetty's avatar Sreeja Kamishetty Committed by Chromium LUCI CQ

Fix failing MetricsWebContentsObserverTest with BackForwardCache

This CL fixes all the MetricsWebContentsObserverTest which
checks for ERR_NO_IPCS_RECEIVED event during deletion of page after
navigating away. As with BFCache, page is kept alive after navigating.

ERR_NO_IPCS_RECEIVED is logged during desturction of a page
which happens when page navigates away. But with BackForwardCache,
page is stored in back-forward cache.

We also add BackForwardCache::IsBackForwardCacheFeatureEnabled()
to //content/public to check if BackForwardCache is enabled or not.

Bug: 1157426
Change-Id: I989a033f55a7f626b426c3c013c136f00f35e704
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2611007Reviewed-by: default avatarHajime Hoshi <hajimehoshi@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Sreeja Kamishetty <sreejakshetty@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840969}
parent 649224bd
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "components/page_load_metrics/browser/page_load_metrics_test_content_browser_client.h" #include "components/page_load_metrics/browser/page_load_metrics_test_content_browser_client.h"
#include "components/page_load_metrics/browser/page_load_tracker.h" #include "components/page_load_metrics/browser/page_load_tracker.h"
#include "components/page_load_metrics/browser/test_metrics_web_contents_observer_embedder.h" #include "components/page_load_metrics/browser/test_metrics_web_contents_observer_embedder.h"
#include "content/public/browser/back_forward_cache.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
...@@ -174,6 +175,14 @@ class MetricsWebContentsObserverTest ...@@ -174,6 +175,14 @@ class MetricsWebContentsObserverTest
return empty; return empty;
} }
void CheckErrorNoIPCsReceivedIfNeeded(int count) {
// With BackForwardCache, page is kept alive after navigation.
// ERR_NO_IPCS_RECEIVED isn't recorded as it is reported during destruction
// of page after navigation which doesn't happen with BackForwardCache.
if (!content::BackForwardCache::IsBackForwardCacheFeatureEnabled())
CheckErrorEvent(ERR_NO_IPCS_RECEIVED, count);
}
const std::vector<mojom::PageLoadTimingPtr>& updated_timings() const { const std::vector<mojom::PageLoadTimingPtr>& updated_timings() const {
return embedder_interface_->updated_timings(); return embedder_interface_->updated_timings();
} }
...@@ -550,7 +559,7 @@ TEST_F(MetricsWebContentsObserverTest, DontLogAbortChains) { ...@@ -550,7 +559,7 @@ TEST_F(MetricsWebContentsObserverTest, DontLogAbortChains) {
NavigateAndCommit(GURL(kDefaultTestUrl2)); NavigateAndCommit(GURL(kDefaultTestUrl2));
NavigateAndCommit(GURL(kDefaultTestUrl)); NavigateAndCommit(GURL(kDefaultTestUrl));
histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNewNavigation, 0); histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNewNavigation, 0);
CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 2); CheckErrorNoIPCsReceivedIfNeeded(2);
CheckTotalErrorEvents(); CheckTotalErrorEvents();
} }
...@@ -881,7 +890,7 @@ TEST_F(MetricsWebContentsObserverTest, ...@@ -881,7 +890,7 @@ TEST_F(MetricsWebContentsObserverTest,
page_load_metrics::internal::INVALID_NULL_FIRST_INPUT_TIMESTAMP, 1); page_load_metrics::internal::INVALID_NULL_FIRST_INPUT_TIMESTAMP, 1);
CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1);
CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); CheckErrorNoIPCsReceivedIfNeeded(1);
CheckTotalErrorEvents(); CheckTotalErrorEvents();
} }
...@@ -911,7 +920,7 @@ TEST_F(MetricsWebContentsObserverTest, ...@@ -911,7 +920,7 @@ TEST_F(MetricsWebContentsObserverTest,
page_load_metrics::internal::INVALID_NULL_FIRST_INPUT_DELAY, 1); page_load_metrics::internal::INVALID_NULL_FIRST_INPUT_DELAY, 1);
CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1);
CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); CheckErrorNoIPCsReceivedIfNeeded(1);
CheckTotalErrorEvents(); CheckTotalErrorEvents();
} }
...@@ -941,7 +950,7 @@ TEST_F(MetricsWebContentsObserverTest, ...@@ -941,7 +950,7 @@ TEST_F(MetricsWebContentsObserverTest,
page_load_metrics::internal::INVALID_NULL_LONGEST_INPUT_TIMESTAMP, 1); page_load_metrics::internal::INVALID_NULL_LONGEST_INPUT_TIMESTAMP, 1);
CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1);
CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); CheckErrorNoIPCsReceivedIfNeeded(1);
CheckTotalErrorEvents(); CheckTotalErrorEvents();
} }
...@@ -971,7 +980,7 @@ TEST_F(MetricsWebContentsObserverTest, ...@@ -971,7 +980,7 @@ TEST_F(MetricsWebContentsObserverTest,
page_load_metrics::internal::INVALID_NULL_LONGEST_INPUT_DELAY, 1); page_load_metrics::internal::INVALID_NULL_LONGEST_INPUT_DELAY, 1);
CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1);
CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); CheckErrorNoIPCsReceivedIfNeeded(1);
CheckTotalErrorEvents(); CheckTotalErrorEvents();
} }
...@@ -1010,7 +1019,7 @@ TEST_F(MetricsWebContentsObserverTest, ...@@ -1010,7 +1019,7 @@ TEST_F(MetricsWebContentsObserverTest,
1); 1);
CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1);
CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); CheckErrorNoIPCsReceivedIfNeeded(1);
CheckTotalErrorEvents(); CheckTotalErrorEvents();
} }
...@@ -1049,7 +1058,7 @@ TEST_F(MetricsWebContentsObserverTest, ...@@ -1049,7 +1058,7 @@ TEST_F(MetricsWebContentsObserverTest,
1); 1);
CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1);
CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); CheckErrorNoIPCsReceivedIfNeeded(1);
CheckTotalErrorEvents(); CheckTotalErrorEvents();
} }
......
...@@ -632,6 +632,11 @@ void BackForwardCacheImpl::PostTaskToDestroyEvictedFrames() { ...@@ -632,6 +632,11 @@ void BackForwardCacheImpl::PostTaskToDestroyEvictedFrames() {
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
// static
bool BackForwardCache::IsBackForwardCacheFeatureEnabled() {
return IsBackForwardCacheEnabled();
}
// static // static
void BackForwardCache::DisableForRenderFrameHost(RenderFrameHost* rfh, void BackForwardCache::DisableForRenderFrameHost(RenderFrameHost* rfh,
base::StringPiece reason) { base::StringPiece reason) {
......
...@@ -28,6 +28,9 @@ class RenderFrameHost; ...@@ -28,6 +28,9 @@ class RenderFrameHost;
// All methods of this class should be called from the UI thread. // All methods of this class should be called from the UI thread.
class CONTENT_EXPORT BackForwardCache { class CONTENT_EXPORT BackForwardCache {
public: public:
// Returns true if BackForwardCache is enabled.
static bool IsBackForwardCacheFeatureEnabled();
// Prevents the |render_frame_host| from entering the BackForwardCache. A // Prevents the |render_frame_host| from entering the BackForwardCache. A
// RenderFrameHost can only enter the BackForwardCache if the main one and all // RenderFrameHost can only enter the BackForwardCache if the main one and all
// its children can. This action can not be undone. Any document that is // its children can. This action can not be undone. Any document that is
......
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