Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2106)

Unified Diff: chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc

Issue 2386143003: Make PageLoadMetricsObserver::OnStart return ObservePolicy (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc
diff --git a/chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc b/chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc
index 9864608fee1337c04da829c71c342b96b3eb7047..33ac22d2fe20419ea336a9e4c64805bccb9b61a1 100644
--- a/chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc
+++ b/chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc
@@ -30,6 +30,7 @@ namespace {
const char kDefaultTestUrl[] = "https://google.com/";
const char kDefaultTestUrlAnchor[] = "https://google.com/#samepage";
const char kDefaultTestUrl2[] = "https://whatever.com/";
+const char kFilteredStartUrl[] = "https://whatever.com/ignore-on-start";
const char kFilteredCommitUrl[] = "https://whatever.com/ignore-on-commit";
// Simple PageLoadMetricsObserver that copies observed PageLoadTimings into the
@@ -43,10 +44,11 @@ class TestPageLoadMetricsObserver : public PageLoadMetricsObserver {
complete_timings_(complete_timings),
observed_committed_urls_(observed_committed_urls) {}
- void OnStart(content::NavigationHandle* navigation_handle,
+ ObservePolicy OnStart(content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url,
bool started_in_foreground) override {
observed_committed_urls_->push_back(currently_committed_url);
+ return CONTINUE_OBSERVING;
}
void OnTimingUpdate(const PageLoadTiming& timing,
@@ -79,6 +81,14 @@ class FilteringPageLoadMetricsObserver : public PageLoadMetricsObserver {
std::vector<GURL>* completed_filtered_urls)
: completed_filtered_urls_(completed_filtered_urls) {}
+ ObservePolicy OnStart(content::NavigationHandle* handle,
+ const GURL& currently_committed_url,
+ bool started_in_foreground) override {
+ const bool should_ignore =
+ handle->GetURL().spec().find("ignore-on-start") != std::string::npos;
+ return should_ignore ? STOP_OBSERVING : CONTINUE_OBSERVING;
+ }
+
ObservePolicy OnCommit(content::NavigationHandle* handle) override {
const bool should_ignore =
handle->GetURL().spec().find("ignore-on-commit") != std::string::npos;
@@ -581,4 +591,27 @@ TEST_F(MetricsWebContentsObserverTest, StopObservingOnCommit) {
completed_filtered_urls());
}
+TEST_F(MetricsWebContentsObserverTest, StopObservingOnStart) {
+ content::WebContentsTester* web_contents_tester =
+ content::WebContentsTester::For(web_contents());
+ ASSERT_TRUE(completed_filtered_urls().empty());
+
+ web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
+ ASSERT_TRUE(completed_filtered_urls().empty());
+
+ // kFilteredCommitUrl should stop observing in OnStart, and thus should not
+ // reach OnComplete().
+ web_contents_tester->NavigateAndCommit(GURL(kFilteredStartUrl));
+ ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}),
+ completed_filtered_urls());
+
+ web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
+ ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}),
+ completed_filtered_urls());
+
+ web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
+ ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl), GURL(kDefaultTestUrl2)}),
+ completed_filtered_urls());
+}
+
} // namespace page_load_metrics

Powered by Google App Engine
This is Rietveld 408576698