Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 completed_filtered_urls_->push_back(extra_info.committed_url); | 102 completed_filtered_urls_->push_back(extra_info.committed_url); |
| 103 } | 103 } |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 std::vector<GURL>* const completed_filtered_urls_; | 106 std::vector<GURL>* const completed_filtered_urls_; |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 class TestPageLoadMetricsEmbedderInterface | 109 class TestPageLoadMetricsEmbedderInterface |
| 110 : public PageLoadMetricsEmbedderInterface { | 110 : public PageLoadMetricsEmbedderInterface { |
| 111 public: | 111 public: |
| 112 TestPageLoadMetricsEmbedderInterface() | 112 TestPageLoadMetricsEmbedderInterface() : is_ntp_(false) {} |
| 113 : is_prerendering_(false), is_ntp_(false) {} | |
| 114 | 113 |
| 115 bool IsPrerendering(content::WebContents* web_contents) override { | |
| 116 return is_prerendering_; | |
| 117 } | |
| 118 bool IsNewTabPageUrl(const GURL& url) override { return is_ntp_; } | 114 bool IsNewTabPageUrl(const GURL& url) override { return is_ntp_; } |
| 119 void set_is_prerendering(bool is_prerendering) { | |
| 120 is_prerendering_ = is_prerendering; | |
| 121 } | |
| 122 void set_is_ntp(bool is_ntp) { is_ntp_ = is_ntp; } | 115 void set_is_ntp(bool is_ntp) { is_ntp_ = is_ntp; } |
| 123 void RegisterObservers(PageLoadTracker* tracker) override { | 116 void RegisterObservers(PageLoadTracker* tracker) override { |
| 124 tracker->AddObserver(base::MakeUnique<TestPageLoadMetricsObserver>( | 117 tracker->AddObserver(base::MakeUnique<TestPageLoadMetricsObserver>( |
| 125 &updated_timings_, &complete_timings_, &observed_committed_urls_)); | 118 &updated_timings_, &complete_timings_, &observed_committed_urls_)); |
| 126 tracker->AddObserver(base::MakeUnique<FilteringPageLoadMetricsObserver>( | 119 tracker->AddObserver(base::MakeUnique<FilteringPageLoadMetricsObserver>( |
| 127 &completed_filtered_urls_)); | 120 &completed_filtered_urls_)); |
| 128 } | 121 } |
| 129 const std::vector<PageLoadTiming>& updated_timings() const { | 122 const std::vector<PageLoadTiming>& updated_timings() const { |
| 130 return updated_timings_; | 123 return updated_timings_; |
| 131 } | 124 } |
| 132 const std::vector<PageLoadTiming>& complete_timings() const { | 125 const std::vector<PageLoadTiming>& complete_timings() const { |
| 133 return complete_timings_; | 126 return complete_timings_; |
| 134 } | 127 } |
| 135 | 128 |
| 136 // currently_committed_urls passed to OnStart(). | 129 // currently_committed_urls passed to OnStart(). |
| 137 const std::vector<GURL>& observed_committed_urls_from_on_start() const { | 130 const std::vector<GURL>& observed_committed_urls_from_on_start() const { |
| 138 return observed_committed_urls_; | 131 return observed_committed_urls_; |
| 139 } | 132 } |
| 140 | 133 |
| 141 // committed URLs passed to FilteringPageLoadMetricsObserver::OnComplete(). | 134 // committed URLs passed to FilteringPageLoadMetricsObserver::OnComplete(). |
| 142 const std::vector<GURL>& completed_filtered_urls() const { | 135 const std::vector<GURL>& completed_filtered_urls() const { |
| 143 return completed_filtered_urls_; | 136 return completed_filtered_urls_; |
| 144 } | 137 } |
| 145 | 138 |
| 146 private: | 139 private: |
| 147 std::vector<PageLoadTiming> updated_timings_; | 140 std::vector<PageLoadTiming> updated_timings_; |
| 148 std::vector<PageLoadTiming> complete_timings_; | 141 std::vector<PageLoadTiming> complete_timings_; |
| 149 std::vector<GURL> observed_committed_urls_; | 142 std::vector<GURL> observed_committed_urls_; |
| 150 std::vector<GURL> completed_filtered_urls_; | 143 std::vector<GURL> completed_filtered_urls_; |
| 151 bool is_prerendering_; | |
| 152 bool is_ntp_; | 144 bool is_ntp_; |
| 153 }; | 145 }; |
| 154 | 146 |
| 155 } // namespace | 147 } // namespace |
| 156 | 148 |
| 157 class MetricsWebContentsObserverTest : public ChromeRenderViewHostTestHarness { | 149 class MetricsWebContentsObserverTest : public ChromeRenderViewHostTestHarness { |
| 158 public: | 150 public: |
| 159 MetricsWebContentsObserverTest() : num_errors_(0) {} | 151 MetricsWebContentsObserverTest() : num_errors_(0) {} |
| 160 | 152 |
| 161 void SetUp() override { | 153 void SetUp() override { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 // Navigate again to force histogram logging. | 307 // Navigate again to force histogram logging. |
| 316 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 308 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 317 | 309 |
| 318 // A same page navigation shouldn't trigger logging UMA for the original. | 310 // A same page navigation shouldn't trigger logging UMA for the original. |
| 319 ASSERT_EQ(1, CountUpdatedTimingReported()); | 311 ASSERT_EQ(1, CountUpdatedTimingReported()); |
| 320 ASSERT_EQ(1, CountCompleteTimingReported()); | 312 ASSERT_EQ(1, CountCompleteTimingReported()); |
| 321 ASSERT_EQ(0, CountEmptyCompleteTimingReported()); | 313 ASSERT_EQ(0, CountEmptyCompleteTimingReported()); |
| 322 CheckNoErrorEvents(); | 314 CheckNoErrorEvents(); |
| 323 } | 315 } |
| 324 | 316 |
| 325 TEST_F(MetricsWebContentsObserverTest, DontLogPrerender) { | |
|
Charlie Harrison
2016/11/21 14:30:17
It would be nice if we could keep a test like this
| |
| 326 PageLoadTiming timing; | |
| 327 timing.navigation_start = base::Time::FromDoubleT(1); | |
| 328 | |
| 329 content::WebContentsTester* web_contents_tester = | |
| 330 content::WebContentsTester::For(web_contents()); | |
| 331 embedder_interface_->set_is_prerendering(true); | |
| 332 observer_->WasHidden(); | |
| 333 | |
| 334 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | |
| 335 SimulateTimingUpdate(timing); | |
| 336 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | |
| 337 ASSERT_EQ(0, CountUpdatedTimingReported()); | |
| 338 ASSERT_EQ(0, CountCompleteTimingReported()); | |
| 339 CheckNoErrorEvents(); | |
| 340 } | |
| 341 | |
| 342 TEST_F(MetricsWebContentsObserverTest, DontLogNewTabPage) { | 317 TEST_F(MetricsWebContentsObserverTest, DontLogNewTabPage) { |
| 343 PageLoadTiming timing; | 318 PageLoadTiming timing; |
| 344 timing.navigation_start = base::Time::FromDoubleT(1); | 319 timing.navigation_start = base::Time::FromDoubleT(1); |
| 345 | 320 |
| 346 content::WebContentsTester* web_contents_tester = | 321 content::WebContentsTester* web_contents_tester = |
| 347 content::WebContentsTester::For(web_contents()); | 322 content::WebContentsTester::For(web_contents()); |
| 348 embedder_interface_->set_is_ntp(true); | 323 embedder_interface_->set_is_ntp(true); |
| 349 | 324 |
| 350 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 325 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 351 SimulateTimingUpdate(timing); | 326 SimulateTimingUpdate(timing); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 585 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 611 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}), | 586 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}), |
| 612 completed_filtered_urls()); | 587 completed_filtered_urls()); |
| 613 | 588 |
| 614 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 589 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 615 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl), GURL(kDefaultTestUrl2)}), | 590 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl), GURL(kDefaultTestUrl2)}), |
| 616 completed_filtered_urls()); | 591 completed_filtered_urls()); |
| 617 } | 592 } |
| 618 | 593 |
| 619 } // namespace page_load_metrics | 594 } // namespace page_load_metrics |
| OLD | NEW |