| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 20 matching lines...) Expand all Loading... |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 const char kDefaultTestUrl[] = "https://google.com/"; | 33 const char kDefaultTestUrl[] = "https://google.com/"; |
| 34 const char kDefaultTestUrlAnchor[] = "https://google.com/#samedocument"; | 34 const char kDefaultTestUrlAnchor[] = "https://google.com/#samedocument"; |
| 35 const char kDefaultTestUrl2[] = "https://whatever.com/"; | 35 const char kDefaultTestUrl2[] = "https://whatever.com/"; |
| 36 const char kFilteredStartUrl[] = "https://whatever.com/ignore-on-start"; | 36 const char kFilteredStartUrl[] = "https://whatever.com/ignore-on-start"; |
| 37 const char kFilteredCommitUrl[] = "https://whatever.com/ignore-on-commit"; | 37 const char kFilteredCommitUrl[] = "https://whatever.com/ignore-on-commit"; |
| 38 | 38 |
| 39 // Simple PageLoadMetricsObserver that copies observed PageLoadTimings into the | 39 // Simple PageLoadMetricsObserver that copies observed PageLoadTimings into the |
| 40 // provided std::vector, so they can be analyzed by unit tests. | 40 // provided std::vector, so they can be analyzed by unit tests. |
| 41 class TestPageLoadMetricsObserver : public PageLoadMetricsObserver { | 41 class TestPageLoadMetricsObserver |
| 42 : public PageLoadMetricsObserver, |
| 43 public MetricsWebContentsObserver::TestingObserver { |
| 42 public: | 44 public: |
| 43 TestPageLoadMetricsObserver(std::vector<PageLoadTiming>* updated_timings, | 45 TestPageLoadMetricsObserver( |
| 44 std::vector<PageLoadTiming>* complete_timings, | 46 content::WebContents* web_contents, |
| 45 std::vector<GURL>* observed_committed_urls) | 47 std::vector<PageLoadTiming>* updated_timings, |
| 46 : updated_timings_(updated_timings), | 48 std::vector<PageLoadTiming>* updated_subframe_timings, |
| 49 std::vector<PageLoadTiming>* complete_timings, |
| 50 std::vector<GURL>* observed_committed_urls) |
| 51 : MetricsWebContentsObserver::TestingObserver(web_contents), |
| 52 updated_timings_(updated_timings), |
| 53 updated_subframe_timings_(updated_subframe_timings), |
| 47 complete_timings_(complete_timings), | 54 complete_timings_(complete_timings), |
| 48 observed_committed_urls_(observed_committed_urls) {} | 55 observed_committed_urls_(observed_committed_urls) {} |
| 49 | 56 |
| 50 ObservePolicy OnStart(content::NavigationHandle* navigation_handle, | 57 ObservePolicy OnStart(content::NavigationHandle* navigation_handle, |
| 51 const GURL& currently_committed_url, | 58 const GURL& currently_committed_url, |
| 52 bool started_in_foreground) override { | 59 bool started_in_foreground) override { |
| 53 observed_committed_urls_->push_back(currently_committed_url); | 60 observed_committed_urls_->push_back(currently_committed_url); |
| 54 return CONTINUE_OBSERVING; | 61 return CONTINUE_OBSERVING; |
| 55 } | 62 } |
| 56 | 63 |
| 57 void OnTimingUpdate(const PageLoadTiming& timing, | 64 void OnTimingUpdate(const PageLoadTiming& timing, |
| 58 const PageLoadExtraInfo& extra_info) override { | 65 const PageLoadExtraInfo& extra_info) override { |
| 59 updated_timings_->push_back(timing); | 66 updated_timings_->push_back(timing); |
| 60 } | 67 } |
| 61 | 68 |
| 69 void OnTimingUpdated(bool is_main_frame, |
| 70 const PageLoadTiming& timing, |
| 71 const PageLoadMetadata& metadata) override { |
| 72 if (!is_main_frame) { |
| 73 updated_subframe_timings_->push_back(timing); |
| 74 } |
| 75 } |
| 76 |
| 62 void OnComplete(const PageLoadTiming& timing, | 77 void OnComplete(const PageLoadTiming& timing, |
| 63 const PageLoadExtraInfo& extra_info) override { | 78 const PageLoadExtraInfo& extra_info) override { |
| 64 complete_timings_->push_back(timing); | 79 complete_timings_->push_back(timing); |
| 65 } | 80 } |
| 66 | 81 |
| 67 ObservePolicy FlushMetricsOnAppEnterBackground( | 82 ObservePolicy FlushMetricsOnAppEnterBackground( |
| 68 const PageLoadTiming& timing, | 83 const PageLoadTiming& timing, |
| 69 const PageLoadExtraInfo& extra_info) override { | 84 const PageLoadExtraInfo& extra_info) override { |
| 70 return STOP_OBSERVING; | 85 return STOP_OBSERVING; |
| 71 } | 86 } |
| 72 | 87 |
| 73 private: | 88 private: |
| 74 std::vector<PageLoadTiming>* const updated_timings_; | 89 std::vector<PageLoadTiming>* const updated_timings_; |
| 90 std::vector<PageLoadTiming>* const updated_subframe_timings_; |
| 75 std::vector<PageLoadTiming>* const complete_timings_; | 91 std::vector<PageLoadTiming>* const complete_timings_; |
| 76 std::vector<GURL>* const observed_committed_urls_; | 92 std::vector<GURL>* const observed_committed_urls_; |
| 77 }; | 93 }; |
| 78 | 94 |
| 79 // Test PageLoadMetricsObserver that stops observing page loads with certain | 95 // Test PageLoadMetricsObserver that stops observing page loads with certain |
| 80 // substrings in the URL. | 96 // substrings in the URL. |
| 81 class FilteringPageLoadMetricsObserver : public PageLoadMetricsObserver { | 97 class FilteringPageLoadMetricsObserver : public PageLoadMetricsObserver { |
| 82 public: | 98 public: |
| 83 explicit FilteringPageLoadMetricsObserver( | 99 explicit FilteringPageLoadMetricsObserver( |
| 84 std::vector<GURL>* completed_filtered_urls) | 100 std::vector<GURL>* completed_filtered_urls) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 103 completed_filtered_urls_->push_back(extra_info.url); | 119 completed_filtered_urls_->push_back(extra_info.url); |
| 104 } | 120 } |
| 105 | 121 |
| 106 private: | 122 private: |
| 107 std::vector<GURL>* const completed_filtered_urls_; | 123 std::vector<GURL>* const completed_filtered_urls_; |
| 108 }; | 124 }; |
| 109 | 125 |
| 110 class TestPageLoadMetricsEmbedderInterface | 126 class TestPageLoadMetricsEmbedderInterface |
| 111 : public PageLoadMetricsEmbedderInterface { | 127 : public PageLoadMetricsEmbedderInterface { |
| 112 public: | 128 public: |
| 113 TestPageLoadMetricsEmbedderInterface() : is_ntp_(false) {} | 129 explicit TestPageLoadMetricsEmbedderInterface( |
| 130 content::WebContents* web_contents) |
| 131 : web_contents_(web_contents), is_ntp_(false) {} |
| 114 | 132 |
| 115 bool IsNewTabPageUrl(const GURL& url) override { return is_ntp_; } | 133 bool IsNewTabPageUrl(const GURL& url) override { return is_ntp_; } |
| 116 void set_is_ntp(bool is_ntp) { is_ntp_ = is_ntp; } | 134 void set_is_ntp(bool is_ntp) { is_ntp_ = is_ntp; } |
| 117 void RegisterObservers(PageLoadTracker* tracker) override { | 135 void RegisterObservers(PageLoadTracker* tracker) override { |
| 118 tracker->AddObserver(base::MakeUnique<TestPageLoadMetricsObserver>( | 136 tracker->AddObserver(base::MakeUnique<TestPageLoadMetricsObserver>( |
| 119 &updated_timings_, &complete_timings_, &observed_committed_urls_)); | 137 web_contents_, &updated_timings_, &updated_subframe_timings_, |
| 138 &complete_timings_, &observed_committed_urls_)); |
| 120 tracker->AddObserver(base::MakeUnique<FilteringPageLoadMetricsObserver>( | 139 tracker->AddObserver(base::MakeUnique<FilteringPageLoadMetricsObserver>( |
| 121 &completed_filtered_urls_)); | 140 &completed_filtered_urls_)); |
| 122 } | 141 } |
| 123 const std::vector<PageLoadTiming>& updated_timings() const { | 142 const std::vector<PageLoadTiming>& updated_timings() const { |
| 124 return updated_timings_; | 143 return updated_timings_; |
| 125 } | 144 } |
| 126 const std::vector<PageLoadTiming>& complete_timings() const { | 145 const std::vector<PageLoadTiming>& complete_timings() const { |
| 127 return complete_timings_; | 146 return complete_timings_; |
| 128 } | 147 } |
| 148 const std::vector<PageLoadTiming>& updated_subframe_timings() const { |
| 149 return updated_subframe_timings_; |
| 150 } |
| 129 | 151 |
| 130 // currently_committed_urls passed to OnStart(). | 152 // currently_committed_urls passed to OnStart(). |
| 131 const std::vector<GURL>& observed_committed_urls_from_on_start() const { | 153 const std::vector<GURL>& observed_committed_urls_from_on_start() const { |
| 132 return observed_committed_urls_; | 154 return observed_committed_urls_; |
| 133 } | 155 } |
| 134 | 156 |
| 135 // committed URLs passed to FilteringPageLoadMetricsObserver::OnComplete(). | 157 // committed URLs passed to FilteringPageLoadMetricsObserver::OnComplete(). |
| 136 const std::vector<GURL>& completed_filtered_urls() const { | 158 const std::vector<GURL>& completed_filtered_urls() const { |
| 137 return completed_filtered_urls_; | 159 return completed_filtered_urls_; |
| 138 } | 160 } |
| 139 | 161 |
| 140 private: | 162 private: |
| 141 std::vector<PageLoadTiming> updated_timings_; | 163 std::vector<PageLoadTiming> updated_timings_; |
| 164 std::vector<PageLoadTiming> updated_subframe_timings_; |
| 142 std::vector<PageLoadTiming> complete_timings_; | 165 std::vector<PageLoadTiming> complete_timings_; |
| 143 std::vector<GURL> observed_committed_urls_; | 166 std::vector<GURL> observed_committed_urls_; |
| 144 std::vector<GURL> completed_filtered_urls_; | 167 std::vector<GURL> completed_filtered_urls_; |
| 168 content::WebContents* web_contents_; |
| 145 bool is_ntp_; | 169 bool is_ntp_; |
| 146 }; | 170 }; |
| 147 | 171 |
| 148 } // namespace | 172 } // namespace |
| 149 | 173 |
| 150 class MetricsWebContentsObserverTest : public ChromeRenderViewHostTestHarness { | 174 class MetricsWebContentsObserverTest : public ChromeRenderViewHostTestHarness { |
| 151 public: | 175 public: |
| 152 MetricsWebContentsObserverTest() : num_errors_(0) {} | 176 MetricsWebContentsObserverTest() : num_errors_(0) {} |
| 153 | 177 |
| 154 void SetUp() override { | 178 void SetUp() override { |
| 155 ChromeRenderViewHostTestHarness::SetUp(); | 179 ChromeRenderViewHostTestHarness::SetUp(); |
| 156 AttachObserver(); | 180 AttachObserver(); |
| 157 } | 181 } |
| 158 | 182 |
| 159 void NavigateToUntrackedUrl() { | 183 void NavigateToUntrackedUrl() { |
| 160 content::WebContentsTester::For(web_contents()) | 184 content::WebContentsTester::For(web_contents()) |
| 161 ->NavigateAndCommit(GURL(url::kAboutBlankURL)); | 185 ->NavigateAndCommit(GURL(url::kAboutBlankURL)); |
| 162 } | 186 } |
| 163 | 187 |
| 164 void SimulateTimingUpdate(const PageLoadTiming& timing) { | 188 void SimulateTimingUpdate(const PageLoadTiming& timing) { |
| 165 SimulateTimingUpdate(timing, web_contents()->GetMainFrame()); | 189 SimulateTimingUpdate(timing, web_contents()->GetMainFrame()); |
| 166 } | 190 } |
| 167 | 191 |
| 168 void SimulateTimingUpdate(const PageLoadTiming& timing, | 192 void SimulateTimingUpdate(const PageLoadTiming& timing, |
| 169 content::RenderFrameHost* render_frame_host) { | 193 content::RenderFrameHost* render_frame_host) { |
| 170 observer_->OnTimingUpdated(render_frame_host, timing, PageLoadMetadata()); | 194 observer_->OnTimingUpdated(render_frame_host, timing, PageLoadMetadata()); |
| 171 } | 195 } |
| 172 | 196 |
| 173 void AttachObserver() { | 197 void AttachObserver() { |
| 174 embedder_interface_ = new TestPageLoadMetricsEmbedderInterface(); | 198 embedder_interface_ = |
| 199 new TestPageLoadMetricsEmbedderInterface(web_contents()); |
| 175 // Owned by the web_contents. Tests must be careful not to call | 200 // Owned by the web_contents. Tests must be careful not to call |
| 176 // SimulateTimingUpdate after they call DeleteContents() without also | 201 // SimulateTimingUpdate after they call DeleteContents() without also |
| 177 // calling AttachObserver() again. Otherwise they will use-after-free the | 202 // calling AttachObserver() again. Otherwise they will use-after-free the |
| 178 // observer_. | 203 // observer_. |
| 179 observer_ = MetricsWebContentsObserver::CreateForWebContents( | 204 observer_ = MetricsWebContentsObserver::CreateForWebContents( |
| 180 web_contents(), base::WrapUnique(embedder_interface_)); | 205 web_contents(), base::WrapUnique(embedder_interface_)); |
| 181 observer_->WasShown(); | 206 observer_->WasShown(); |
| 182 } | 207 } |
| 183 | 208 |
| 184 void CheckErrorEvent(InternalErrorLoadEvent error, int count) { | 209 void CheckErrorEvent(InternalErrorLoadEvent error, int count) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 196 | 221 |
| 197 int CountEmptyCompleteTimingReported() { | 222 int CountEmptyCompleteTimingReported() { |
| 198 int empty = 0; | 223 int empty = 0; |
| 199 for (const auto& timing : embedder_interface_->complete_timings()) { | 224 for (const auto& timing : embedder_interface_->complete_timings()) { |
| 200 if (timing.IsEmpty()) | 225 if (timing.IsEmpty()) |
| 201 ++empty; | 226 ++empty; |
| 202 } | 227 } |
| 203 return empty; | 228 return empty; |
| 204 } | 229 } |
| 205 | 230 |
| 206 int CountCompleteTimingReported() { | 231 const std::vector<PageLoadTiming>& updated_timings() const { |
| 207 return embedder_interface_->complete_timings().size(); | 232 return embedder_interface_->updated_timings(); |
| 208 } | 233 } |
| 209 int CountUpdatedTimingReported() { | 234 const std::vector<PageLoadTiming>& complete_timings() const { |
| 210 return embedder_interface_->updated_timings().size(); | 235 return embedder_interface_->complete_timings(); |
| 236 } |
| 237 const std::vector<PageLoadTiming>& updated_subframe_timings() const { |
| 238 return embedder_interface_->updated_subframe_timings(); |
| 239 } |
| 240 int CountCompleteTimingReported() { return complete_timings().size(); } |
| 241 int CountUpdatedTimingReported() { return updated_timings().size(); } |
| 242 int CountUpdatedSubFrameTimingReported() { |
| 243 return updated_subframe_timings().size(); |
| 211 } | 244 } |
| 212 | 245 |
| 213 const std::vector<GURL>& observed_committed_urls_from_on_start() const { | 246 const std::vector<GURL>& observed_committed_urls_from_on_start() const { |
| 214 return embedder_interface_->observed_committed_urls_from_on_start(); | 247 return embedder_interface_->observed_committed_urls_from_on_start(); |
| 215 } | 248 } |
| 216 | 249 |
| 217 const std::vector<GURL>& completed_filtered_urls() const { | 250 const std::vector<GURL>& completed_filtered_urls() const { |
| 218 return embedder_interface_->completed_filtered_urls(); | 251 return embedder_interface_->completed_filtered_urls(); |
| 219 } | 252 } |
| 220 | 253 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 246 ASSERT_EQ(1, CountUpdatedTimingReported()); | 279 ASSERT_EQ(1, CountUpdatedTimingReported()); |
| 247 ASSERT_EQ(0, CountCompleteTimingReported()); | 280 ASSERT_EQ(0, CountCompleteTimingReported()); |
| 248 | 281 |
| 249 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 282 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 250 ASSERT_EQ(1, CountCompleteTimingReported()); | 283 ASSERT_EQ(1, CountCompleteTimingReported()); |
| 251 ASSERT_EQ(0, CountEmptyCompleteTimingReported()); | 284 ASSERT_EQ(0, CountEmptyCompleteTimingReported()); |
| 252 ASSERT_EQ(2u, observed_committed_urls_from_on_start().size()); | 285 ASSERT_EQ(2u, observed_committed_urls_from_on_start().size()); |
| 253 ASSERT_EQ(kDefaultTestUrl, | 286 ASSERT_EQ(kDefaultTestUrl, |
| 254 observed_committed_urls_from_on_start().at(1).spec()); | 287 observed_committed_urls_from_on_start().at(1).spec()); |
| 255 ASSERT_EQ(1, CountUpdatedTimingReported()); | 288 ASSERT_EQ(1, CountUpdatedTimingReported()); |
| 289 ASSERT_EQ(0, CountUpdatedSubFrameTimingReported()); |
| 256 | 290 |
| 257 CheckNoErrorEvents(); | 291 CheckNoErrorEvents(); |
| 258 } | 292 } |
| 259 | 293 |
| 260 TEST_F(MetricsWebContentsObserverTest, NotInMainFrame) { | 294 TEST_F(MetricsWebContentsObserverTest, SubFrame) { |
| 261 PageLoadTiming timing; | 295 PageLoadTiming timing; |
| 262 timing.navigation_start = base::Time::FromDoubleT(1); | 296 timing.navigation_start = base::Time::FromDoubleT(1); |
| 263 | 297 |
| 264 content::WebContentsTester* web_contents_tester = | 298 content::WebContentsTester* web_contents_tester = |
| 265 content::WebContentsTester::For(web_contents()); | 299 content::WebContentsTester::For(web_contents()); |
| 266 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 300 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 301 SimulateTimingUpdate(timing); |
| 267 | 302 |
| 268 content::RenderFrameHostTester* rfh_tester = | 303 content::RenderFrameHostTester* rfh_tester = |
| 269 content::RenderFrameHostTester::For(main_rfh()); | 304 content::RenderFrameHostTester::For(main_rfh()); |
| 270 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); | 305 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); |
| 271 | 306 |
| 307 PageLoadTiming subframe_timing; |
| 308 subframe_timing.navigation_start = base::Time::FromDoubleT(2); |
| 272 content::RenderFrameHostTester* subframe_tester = | 309 content::RenderFrameHostTester* subframe_tester = |
| 273 content::RenderFrameHostTester::For(subframe); | 310 content::RenderFrameHostTester::For(subframe); |
| 274 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); | 311 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); |
| 275 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); | 312 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); |
| 276 SimulateTimingUpdate(timing, subframe); | 313 SimulateTimingUpdate(subframe_timing, subframe); |
| 277 subframe_tester->SimulateNavigationStop(); | 314 subframe_tester->SimulateNavigationStop(); |
| 278 | 315 |
| 279 // Navigate again to see if the timing updated for a subframe message. | 316 // Navigate again to see if the timing updated for a subframe message. |
| 280 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 317 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 281 | 318 |
| 282 ASSERT_EQ(0, CountUpdatedTimingReported()); | |
| 283 ASSERT_EQ(1, CountCompleteTimingReported()); | 319 ASSERT_EQ(1, CountCompleteTimingReported()); |
| 284 ASSERT_EQ(1, CountEmptyCompleteTimingReported()); | 320 ASSERT_EQ(1, CountUpdatedTimingReported()); |
| 285 CheckErrorEvent(ERR_TIMING_IPC_FROM_SUBFRAME, 1); | 321 ASSERT_EQ(0, CountEmptyCompleteTimingReported()); |
| 286 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); | 322 EXPECT_EQ(timing, updated_timings().at(0)); |
| 287 CheckTotalErrorEvents(); | 323 |
| 324 ASSERT_EQ(1, CountUpdatedSubFrameTimingReported()); |
| 325 EXPECT_EQ(subframe_timing, updated_subframe_timings().at(0)); |
| 326 |
| 327 CheckNoErrorEvents(); |
| 288 } | 328 } |
| 289 | 329 |
| 290 TEST_F(MetricsWebContentsObserverTest, SameDocumentNoTrigger) { | 330 TEST_F(MetricsWebContentsObserverTest, SameDocumentNoTrigger) { |
| 291 PageLoadTiming timing; | 331 PageLoadTiming timing; |
| 292 timing.navigation_start = base::Time::FromDoubleT(1); | 332 timing.navigation_start = base::Time::FromDoubleT(1); |
| 293 | 333 |
| 294 content::WebContentsTester* web_contents_tester = | 334 content::WebContentsTester* web_contents_tester = |
| 295 content::WebContentsTester::For(web_contents()); | 335 content::WebContentsTester::For(web_contents()); |
| 296 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 336 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 297 ASSERT_EQ(0, CountUpdatedTimingReported()); | 337 ASSERT_EQ(0, CountUpdatedTimingReported()); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); | 462 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); |
| 423 CheckTotalErrorEvents(); | 463 CheckTotalErrorEvents(); |
| 424 | 464 |
| 425 histogram_tester_.ExpectTotalCount( | 465 histogram_tester_.ExpectTotalCount( |
| 426 page_load_metrics::internal::kPageLoadTimingStatus, 1); | 466 page_load_metrics::internal::kPageLoadTimingStatus, 1); |
| 427 histogram_tester_.ExpectBucketCount( | 467 histogram_tester_.ExpectBucketCount( |
| 428 page_load_metrics::internal::kPageLoadTimingStatus, | 468 page_load_metrics::internal::kPageLoadTimingStatus, |
| 429 page_load_metrics::internal::INVALID_ORDER_PARSE_START_PARSE_STOP, 1); | 469 page_load_metrics::internal::INVALID_ORDER_PARSE_START_PARSE_STOP, 1); |
| 430 } | 470 } |
| 431 | 471 |
| 432 TEST_F(MetricsWebContentsObserverTest, NotInMainError) { | |
| 433 PageLoadTiming timing; | |
| 434 timing.navigation_start = base::Time::FromDoubleT(1); | |
| 435 | |
| 436 content::WebContentsTester* web_contents_tester = | |
| 437 content::WebContentsTester::For(web_contents()); | |
| 438 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | |
| 439 | |
| 440 content::RenderFrameHostTester* rfh_tester = | |
| 441 content::RenderFrameHostTester::For(main_rfh()); | |
| 442 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); | |
| 443 | |
| 444 content::RenderFrameHostTester* subframe_tester = | |
| 445 content::RenderFrameHostTester::For(subframe); | |
| 446 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); | |
| 447 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); | |
| 448 SimulateTimingUpdate(timing, subframe); | |
| 449 CheckErrorEvent(ERR_TIMING_IPC_FROM_SUBFRAME, 1); | |
| 450 CheckTotalErrorEvents(); | |
| 451 ASSERT_EQ(0, CountUpdatedTimingReported()); | |
| 452 ASSERT_EQ(0, CountCompleteTimingReported()); | |
| 453 } | |
| 454 | |
| 455 TEST_F(MetricsWebContentsObserverTest, BadIPC) { | 472 TEST_F(MetricsWebContentsObserverTest, BadIPC) { |
| 456 PageLoadTiming timing; | 473 PageLoadTiming timing; |
| 457 timing.navigation_start = base::Time::FromDoubleT(10); | 474 timing.navigation_start = base::Time::FromDoubleT(10); |
| 458 PageLoadTiming timing2; | 475 PageLoadTiming timing2; |
| 459 timing2.navigation_start = base::Time::FromDoubleT(100); | 476 timing2.navigation_start = base::Time::FromDoubleT(100); |
| 460 | 477 |
| 461 content::WebContentsTester* web_contents_tester = | 478 content::WebContentsTester* web_contents_tester = |
| 462 content::WebContentsTester::For(web_contents()); | 479 content::WebContentsTester::For(web_contents()); |
| 463 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 480 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 464 | 481 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 680 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 664 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}), | 681 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}), |
| 665 completed_filtered_urls()); | 682 completed_filtered_urls()); |
| 666 | 683 |
| 667 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 684 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 668 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl), GURL(kDefaultTestUrl2)}), | 685 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl), GURL(kDefaultTestUrl2)}), |
| 669 completed_filtered_urls()); | 686 completed_filtered_urls()); |
| 670 } | 687 } |
| 671 | 688 |
| 672 } // namespace page_load_metrics | 689 } // namespace page_load_metrics |
| OLD | NEW |