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 22 matching lines...) Expand all Loading... |
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 : public PageLoadMetricsObserver { |
42 public: | 42 public: |
43 TestPageLoadMetricsObserver(std::vector<PageLoadTiming>* updated_timings, | 43 TestPageLoadMetricsObserver( |
44 std::vector<PageLoadTiming>* complete_timings, | 44 std::vector<mojo::StructPtr<PageLoadTiming>>* updated_timings, |
45 std::vector<GURL>* observed_committed_urls) | 45 std::vector<mojo::StructPtr<PageLoadTiming>>* complete_timings, |
| 46 std::vector<GURL>* observed_committed_urls) |
46 : updated_timings_(updated_timings), | 47 : updated_timings_(updated_timings), |
47 complete_timings_(complete_timings), | 48 complete_timings_(complete_timings), |
48 observed_committed_urls_(observed_committed_urls) {} | 49 observed_committed_urls_(observed_committed_urls) {} |
49 | 50 |
50 ObservePolicy OnStart(content::NavigationHandle* navigation_handle, | 51 ObservePolicy OnStart(content::NavigationHandle* navigation_handle, |
51 const GURL& currently_committed_url, | 52 const GURL& currently_committed_url, |
52 bool started_in_foreground) override { | 53 bool started_in_foreground) override { |
53 observed_committed_urls_->push_back(currently_committed_url); | 54 observed_committed_urls_->push_back(currently_committed_url); |
54 return CONTINUE_OBSERVING; | 55 return CONTINUE_OBSERVING; |
55 } | 56 } |
56 | 57 |
57 void OnTimingUpdate(const PageLoadTiming& timing, | 58 void OnTimingUpdate(const PageLoadTiming& timing, |
58 const PageLoadExtraInfo& extra_info) override { | 59 const PageLoadExtraInfo& extra_info) override { |
59 updated_timings_->push_back(timing); | 60 updated_timings_->push_back(timing.Clone()); |
60 } | 61 } |
61 | 62 |
62 void OnComplete(const PageLoadTiming& timing, | 63 void OnComplete(const PageLoadTiming& timing, |
63 const PageLoadExtraInfo& extra_info) override { | 64 const PageLoadExtraInfo& extra_info) override { |
64 complete_timings_->push_back(timing); | 65 complete_timings_->push_back(timing.Clone()); |
65 } | 66 } |
66 | 67 |
67 ObservePolicy FlushMetricsOnAppEnterBackground( | 68 ObservePolicy FlushMetricsOnAppEnterBackground( |
68 const PageLoadTiming& timing, | 69 const PageLoadTiming& timing, |
69 const PageLoadExtraInfo& extra_info) override { | 70 const PageLoadExtraInfo& extra_info) override { |
70 return STOP_OBSERVING; | 71 return STOP_OBSERVING; |
71 } | 72 } |
72 | 73 |
73 private: | 74 private: |
74 std::vector<PageLoadTiming>* const updated_timings_; | 75 std::vector<mojo::StructPtr<PageLoadTiming>>* const updated_timings_; |
75 std::vector<PageLoadTiming>* const complete_timings_; | 76 std::vector<mojo::StructPtr<PageLoadTiming>>* const complete_timings_; |
76 std::vector<GURL>* const observed_committed_urls_; | 77 std::vector<GURL>* const observed_committed_urls_; |
77 }; | 78 }; |
78 | 79 |
79 // Test PageLoadMetricsObserver that stops observing page loads with certain | 80 // Test PageLoadMetricsObserver that stops observing page loads with certain |
80 // substrings in the URL. | 81 // substrings in the URL. |
81 class FilteringPageLoadMetricsObserver : public PageLoadMetricsObserver { | 82 class FilteringPageLoadMetricsObserver : public PageLoadMetricsObserver { |
82 public: | 83 public: |
83 explicit FilteringPageLoadMetricsObserver( | 84 explicit FilteringPageLoadMetricsObserver( |
84 std::vector<GURL>* completed_filtered_urls) | 85 std::vector<GURL>* completed_filtered_urls) |
85 : completed_filtered_urls_(completed_filtered_urls) {} | 86 : completed_filtered_urls_(completed_filtered_urls) {} |
(...skipping 27 matching lines...) Expand all Loading... |
113 TestPageLoadMetricsEmbedderInterface() : is_ntp_(false) {} | 114 TestPageLoadMetricsEmbedderInterface() : is_ntp_(false) {} |
114 | 115 |
115 bool IsNewTabPageUrl(const GURL& url) override { return is_ntp_; } | 116 bool IsNewTabPageUrl(const GURL& url) override { return is_ntp_; } |
116 void set_is_ntp(bool is_ntp) { is_ntp_ = is_ntp; } | 117 void set_is_ntp(bool is_ntp) { is_ntp_ = is_ntp; } |
117 void RegisterObservers(PageLoadTracker* tracker) override { | 118 void RegisterObservers(PageLoadTracker* tracker) override { |
118 tracker->AddObserver(base::MakeUnique<TestPageLoadMetricsObserver>( | 119 tracker->AddObserver(base::MakeUnique<TestPageLoadMetricsObserver>( |
119 &updated_timings_, &complete_timings_, &observed_committed_urls_)); | 120 &updated_timings_, &complete_timings_, &observed_committed_urls_)); |
120 tracker->AddObserver(base::MakeUnique<FilteringPageLoadMetricsObserver>( | 121 tracker->AddObserver(base::MakeUnique<FilteringPageLoadMetricsObserver>( |
121 &completed_filtered_urls_)); | 122 &completed_filtered_urls_)); |
122 } | 123 } |
123 const std::vector<PageLoadTiming>& updated_timings() const { | 124 const std::vector<mojo::StructPtr<PageLoadTiming>>& updated_timings() const { |
124 return updated_timings_; | 125 return updated_timings_; |
125 } | 126 } |
126 const std::vector<PageLoadTiming>& complete_timings() const { | 127 const std::vector<mojo::StructPtr<PageLoadTiming>>& complete_timings() const { |
127 return complete_timings_; | 128 return complete_timings_; |
128 } | 129 } |
129 | 130 |
130 // currently_committed_urls passed to OnStart(). | 131 // currently_committed_urls passed to OnStart(). |
131 const std::vector<GURL>& observed_committed_urls_from_on_start() const { | 132 const std::vector<GURL>& observed_committed_urls_from_on_start() const { |
132 return observed_committed_urls_; | 133 return observed_committed_urls_; |
133 } | 134 } |
134 | 135 |
135 // committed URLs passed to FilteringPageLoadMetricsObserver::OnComplete(). | 136 // committed URLs passed to FilteringPageLoadMetricsObserver::OnComplete(). |
136 const std::vector<GURL>& completed_filtered_urls() const { | 137 const std::vector<GURL>& completed_filtered_urls() const { |
137 return completed_filtered_urls_; | 138 return completed_filtered_urls_; |
138 } | 139 } |
139 | 140 |
140 private: | 141 private: |
141 std::vector<PageLoadTiming> updated_timings_; | 142 std::vector<mojo::StructPtr<PageLoadTiming>> updated_timings_; |
142 std::vector<PageLoadTiming> complete_timings_; | 143 std::vector<mojo::StructPtr<PageLoadTiming>> complete_timings_; |
143 std::vector<GURL> observed_committed_urls_; | 144 std::vector<GURL> observed_committed_urls_; |
144 std::vector<GURL> completed_filtered_urls_; | 145 std::vector<GURL> completed_filtered_urls_; |
145 bool is_ntp_; | 146 bool is_ntp_; |
146 }; | 147 }; |
147 | 148 |
148 } // namespace | 149 } // namespace |
149 | 150 |
150 class MetricsWebContentsObserverTest : public ChromeRenderViewHostTestHarness { | 151 class MetricsWebContentsObserverTest : public ChromeRenderViewHostTestHarness { |
151 public: | 152 public: |
152 MetricsWebContentsObserverTest() : num_errors_(0) {} | 153 MetricsWebContentsObserverTest() : num_errors_(0) {} |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, num_errors_); | 191 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, num_errors_); |
191 } | 192 } |
192 | 193 |
193 void CheckNoErrorEvents() { | 194 void CheckNoErrorEvents() { |
194 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, 0); | 195 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, 0); |
195 } | 196 } |
196 | 197 |
197 int CountEmptyCompleteTimingReported() { | 198 int CountEmptyCompleteTimingReported() { |
198 int empty = 0; | 199 int empty = 0; |
199 for (const auto& timing : embedder_interface_->complete_timings()) { | 200 for (const auto& timing : embedder_interface_->complete_timings()) { |
200 if (timing.IsEmpty()) | 201 if (page_load_metrics::IsEmpty(*timing)) |
201 ++empty; | 202 ++empty; |
202 } | 203 } |
203 return empty; | 204 return empty; |
204 } | 205 } |
205 | 206 |
206 int CountCompleteTimingReported() { | 207 int CountCompleteTimingReported() { |
207 return embedder_interface_->complete_timings().size(); | 208 return embedder_interface_->complete_timings().size(); |
208 } | 209 } |
209 int CountUpdatedTimingReported() { | 210 int CountUpdatedTimingReported() { |
210 return embedder_interface_->updated_timings().size(); | 211 return embedder_interface_->updated_timings().size(); |
(...skipping 13 matching lines...) Expand all Loading... |
224 MetricsWebContentsObserver* observer_; | 225 MetricsWebContentsObserver* observer_; |
225 | 226 |
226 private: | 227 private: |
227 int num_errors_; | 228 int num_errors_; |
228 | 229 |
229 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserverTest); | 230 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserverTest); |
230 }; | 231 }; |
231 | 232 |
232 TEST_F(MetricsWebContentsObserverTest, SuccessfulMainFrameNavigation) { | 233 TEST_F(MetricsWebContentsObserverTest, SuccessfulMainFrameNavigation) { |
233 PageLoadTiming timing; | 234 PageLoadTiming timing; |
| 235 page_load_metrics::InitPageLoadTimingForTest(&timing); |
234 timing.navigation_start = base::Time::FromDoubleT(1); | 236 timing.navigation_start = base::Time::FromDoubleT(1); |
235 | 237 |
236 content::WebContentsTester* web_contents_tester = | 238 content::WebContentsTester* web_contents_tester = |
237 content::WebContentsTester::For(web_contents()); | 239 content::WebContentsTester::For(web_contents()); |
238 | 240 |
239 ASSERT_TRUE(observed_committed_urls_from_on_start().empty()); | 241 ASSERT_TRUE(observed_committed_urls_from_on_start().empty()); |
240 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 242 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
241 ASSERT_EQ(1u, observed_committed_urls_from_on_start().size()); | 243 ASSERT_EQ(1u, observed_committed_urls_from_on_start().size()); |
242 ASSERT_TRUE(observed_committed_urls_from_on_start().at(0).is_empty()); | 244 ASSERT_TRUE(observed_committed_urls_from_on_start().at(0).is_empty()); |
243 | 245 |
244 ASSERT_EQ(0, CountUpdatedTimingReported()); | 246 ASSERT_EQ(0, CountUpdatedTimingReported()); |
245 SimulateTimingUpdate(timing); | 247 SimulateTimingUpdate(timing); |
246 ASSERT_EQ(1, CountUpdatedTimingReported()); | 248 ASSERT_EQ(1, CountUpdatedTimingReported()); |
247 ASSERT_EQ(0, CountCompleteTimingReported()); | 249 ASSERT_EQ(0, CountCompleteTimingReported()); |
248 | 250 |
249 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 251 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
250 ASSERT_EQ(1, CountCompleteTimingReported()); | 252 ASSERT_EQ(1, CountCompleteTimingReported()); |
251 ASSERT_EQ(0, CountEmptyCompleteTimingReported()); | 253 ASSERT_EQ(0, CountEmptyCompleteTimingReported()); |
252 ASSERT_EQ(2u, observed_committed_urls_from_on_start().size()); | 254 ASSERT_EQ(2u, observed_committed_urls_from_on_start().size()); |
253 ASSERT_EQ(kDefaultTestUrl, | 255 ASSERT_EQ(kDefaultTestUrl, |
254 observed_committed_urls_from_on_start().at(1).spec()); | 256 observed_committed_urls_from_on_start().at(1).spec()); |
255 ASSERT_EQ(1, CountUpdatedTimingReported()); | 257 ASSERT_EQ(1, CountUpdatedTimingReported()); |
256 | 258 |
257 CheckNoErrorEvents(); | 259 CheckNoErrorEvents(); |
258 } | 260 } |
259 | 261 |
260 TEST_F(MetricsWebContentsObserverTest, NotInMainFrame) { | 262 TEST_F(MetricsWebContentsObserverTest, NotInMainFrame) { |
261 PageLoadTiming timing; | 263 PageLoadTiming timing; |
| 264 page_load_metrics::InitPageLoadTimingForTest(&timing); |
262 timing.navigation_start = base::Time::FromDoubleT(1); | 265 timing.navigation_start = base::Time::FromDoubleT(1); |
263 | 266 |
264 content::WebContentsTester* web_contents_tester = | 267 content::WebContentsTester* web_contents_tester = |
265 content::WebContentsTester::For(web_contents()); | 268 content::WebContentsTester::For(web_contents()); |
266 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 269 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
267 | 270 |
268 content::RenderFrameHostTester* rfh_tester = | 271 content::RenderFrameHostTester* rfh_tester = |
269 content::RenderFrameHostTester::For(main_rfh()); | 272 content::RenderFrameHostTester::For(main_rfh()); |
270 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); | 273 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); |
271 | 274 |
(...skipping 10 matching lines...) Expand all Loading... |
282 ASSERT_EQ(0, CountUpdatedTimingReported()); | 285 ASSERT_EQ(0, CountUpdatedTimingReported()); |
283 ASSERT_EQ(1, CountCompleteTimingReported()); | 286 ASSERT_EQ(1, CountCompleteTimingReported()); |
284 ASSERT_EQ(1, CountEmptyCompleteTimingReported()); | 287 ASSERT_EQ(1, CountEmptyCompleteTimingReported()); |
285 CheckErrorEvent(ERR_TIMING_IPC_FROM_SUBFRAME, 1); | 288 CheckErrorEvent(ERR_TIMING_IPC_FROM_SUBFRAME, 1); |
286 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); | 289 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); |
287 CheckTotalErrorEvents(); | 290 CheckTotalErrorEvents(); |
288 } | 291 } |
289 | 292 |
290 TEST_F(MetricsWebContentsObserverTest, SameDocumentNoTrigger) { | 293 TEST_F(MetricsWebContentsObserverTest, SameDocumentNoTrigger) { |
291 PageLoadTiming timing; | 294 PageLoadTiming timing; |
| 295 page_load_metrics::InitPageLoadTimingForTest(&timing); |
292 timing.navigation_start = base::Time::FromDoubleT(1); | 296 timing.navigation_start = base::Time::FromDoubleT(1); |
293 | 297 |
294 content::WebContentsTester* web_contents_tester = | 298 content::WebContentsTester* web_contents_tester = |
295 content::WebContentsTester::For(web_contents()); | 299 content::WebContentsTester::For(web_contents()); |
296 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 300 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
297 ASSERT_EQ(0, CountUpdatedTimingReported()); | 301 ASSERT_EQ(0, CountUpdatedTimingReported()); |
298 SimulateTimingUpdate(timing); | 302 SimulateTimingUpdate(timing); |
299 ASSERT_EQ(1, CountUpdatedTimingReported()); | 303 ASSERT_EQ(1, CountUpdatedTimingReported()); |
300 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrlAnchor)); | 304 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrlAnchor)); |
301 // Send the same timing update. The original tracker for kDefaultTestUrl | 305 // Send the same timing update. The original tracker for kDefaultTestUrl |
(...skipping 10 matching lines...) Expand all Loading... |
312 | 316 |
313 // A same page navigation shouldn't trigger logging UMA for the original. | 317 // A same page navigation shouldn't trigger logging UMA for the original. |
314 ASSERT_EQ(1, CountUpdatedTimingReported()); | 318 ASSERT_EQ(1, CountUpdatedTimingReported()); |
315 ASSERT_EQ(1, CountCompleteTimingReported()); | 319 ASSERT_EQ(1, CountCompleteTimingReported()); |
316 ASSERT_EQ(0, CountEmptyCompleteTimingReported()); | 320 ASSERT_EQ(0, CountEmptyCompleteTimingReported()); |
317 CheckNoErrorEvents(); | 321 CheckNoErrorEvents(); |
318 } | 322 } |
319 | 323 |
320 TEST_F(MetricsWebContentsObserverTest, DontLogNewTabPage) { | 324 TEST_F(MetricsWebContentsObserverTest, DontLogNewTabPage) { |
321 PageLoadTiming timing; | 325 PageLoadTiming timing; |
| 326 page_load_metrics::InitPageLoadTimingForTest(&timing); |
322 timing.navigation_start = base::Time::FromDoubleT(1); | 327 timing.navigation_start = base::Time::FromDoubleT(1); |
323 | 328 |
324 content::WebContentsTester* web_contents_tester = | 329 content::WebContentsTester* web_contents_tester = |
325 content::WebContentsTester::For(web_contents()); | 330 content::WebContentsTester::For(web_contents()); |
326 embedder_interface_->set_is_ntp(true); | 331 embedder_interface_->set_is_ntp(true); |
327 | 332 |
328 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 333 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
329 SimulateTimingUpdate(timing); | 334 SimulateTimingUpdate(timing); |
330 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 335 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
331 ASSERT_EQ(0, CountUpdatedTimingReported()); | 336 ASSERT_EQ(0, CountUpdatedTimingReported()); |
332 ASSERT_EQ(0, CountCompleteTimingReported()); | 337 ASSERT_EQ(0, CountCompleteTimingReported()); |
333 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); | 338 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); |
334 CheckTotalErrorEvents(); | 339 CheckTotalErrorEvents(); |
335 } | 340 } |
336 | 341 |
337 TEST_F(MetricsWebContentsObserverTest, DontLogIrrelevantNavigation) { | 342 TEST_F(MetricsWebContentsObserverTest, DontLogIrrelevantNavigation) { |
338 PageLoadTiming timing; | 343 PageLoadTiming timing; |
| 344 page_load_metrics::InitPageLoadTimingForTest(&timing); |
339 timing.navigation_start = base::Time::FromDoubleT(10); | 345 timing.navigation_start = base::Time::FromDoubleT(10); |
340 | 346 |
341 content::WebContentsTester* web_contents_tester = | 347 content::WebContentsTester* web_contents_tester = |
342 content::WebContentsTester::For(web_contents()); | 348 content::WebContentsTester::For(web_contents()); |
343 | 349 |
344 GURL about_blank_url = GURL("about:blank"); | 350 GURL about_blank_url = GURL("about:blank"); |
345 web_contents_tester->NavigateAndCommit(about_blank_url); | 351 web_contents_tester->NavigateAndCommit(about_blank_url); |
346 SimulateTimingUpdate(timing); | 352 SimulateTimingUpdate(timing); |
347 ASSERT_EQ(0, CountUpdatedTimingReported()); | 353 ASSERT_EQ(0, CountUpdatedTimingReported()); |
348 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 354 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
349 ASSERT_EQ(0, CountUpdatedTimingReported()); | 355 ASSERT_EQ(0, CountUpdatedTimingReported()); |
350 ASSERT_EQ(0, CountCompleteTimingReported()); | 356 ASSERT_EQ(0, CountCompleteTimingReported()); |
351 | 357 |
352 CheckErrorEvent(ERR_IPC_FROM_BAD_URL_SCHEME, 1); | 358 CheckErrorEvent(ERR_IPC_FROM_BAD_URL_SCHEME, 1); |
353 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); | 359 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); |
354 CheckTotalErrorEvents(); | 360 CheckTotalErrorEvents(); |
355 } | 361 } |
356 | 362 |
357 TEST_F(MetricsWebContentsObserverTest, EmptyTimingError) { | 363 TEST_F(MetricsWebContentsObserverTest, EmptyTimingError) { |
358 PageLoadTiming timing; | 364 PageLoadTiming timing; |
| 365 page_load_metrics::InitPageLoadTimingForTest(&timing); |
359 | 366 |
360 content::WebContentsTester* web_contents_tester = | 367 content::WebContentsTester* web_contents_tester = |
361 content::WebContentsTester::For(web_contents()); | 368 content::WebContentsTester::For(web_contents()); |
362 | 369 |
363 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 370 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
364 SimulateTimingUpdate(timing); | 371 SimulateTimingUpdate(timing); |
365 ASSERT_EQ(0, CountUpdatedTimingReported()); | 372 ASSERT_EQ(0, CountUpdatedTimingReported()); |
366 NavigateToUntrackedUrl(); | 373 NavigateToUntrackedUrl(); |
367 ASSERT_EQ(0, CountUpdatedTimingReported()); | 374 ASSERT_EQ(0, CountUpdatedTimingReported()); |
368 ASSERT_EQ(1, CountCompleteTimingReported()); | 375 ASSERT_EQ(1, CountCompleteTimingReported()); |
369 | 376 |
370 CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); | 377 CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); |
371 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); | 378 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); |
372 CheckTotalErrorEvents(); | 379 CheckTotalErrorEvents(); |
373 | 380 |
374 histogram_tester_.ExpectTotalCount( | 381 histogram_tester_.ExpectTotalCount( |
375 page_load_metrics::internal::kPageLoadTimingStatus, 1); | 382 page_load_metrics::internal::kPageLoadTimingStatus, 1); |
376 histogram_tester_.ExpectBucketCount( | 383 histogram_tester_.ExpectBucketCount( |
377 page_load_metrics::internal::kPageLoadTimingStatus, | 384 page_load_metrics::internal::kPageLoadTimingStatus, |
378 page_load_metrics::internal::INVALID_EMPTY_TIMING, 1); | 385 page_load_metrics::internal::INVALID_EMPTY_TIMING, 1); |
379 } | 386 } |
380 | 387 |
381 TEST_F(MetricsWebContentsObserverTest, NullNavigationStartError) { | 388 TEST_F(MetricsWebContentsObserverTest, NullNavigationStartError) { |
382 PageLoadTiming timing; | 389 PageLoadTiming timing; |
383 timing.parse_timing.parse_start = base::TimeDelta::FromMilliseconds(1); | 390 page_load_metrics::InitPageLoadTimingForTest(&timing); |
| 391 timing.parse_timing->parse_start = base::TimeDelta::FromMilliseconds(1); |
384 | 392 |
385 content::WebContentsTester* web_contents_tester = | 393 content::WebContentsTester* web_contents_tester = |
386 content::WebContentsTester::For(web_contents()); | 394 content::WebContentsTester::For(web_contents()); |
387 | 395 |
388 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 396 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
389 SimulateTimingUpdate(timing); | 397 SimulateTimingUpdate(timing); |
390 ASSERT_EQ(0, CountUpdatedTimingReported()); | 398 ASSERT_EQ(0, CountUpdatedTimingReported()); |
391 NavigateToUntrackedUrl(); | 399 NavigateToUntrackedUrl(); |
392 ASSERT_EQ(0, CountUpdatedTimingReported()); | 400 ASSERT_EQ(0, CountUpdatedTimingReported()); |
393 ASSERT_EQ(1, CountCompleteTimingReported()); | 401 ASSERT_EQ(1, CountCompleteTimingReported()); |
394 | 402 |
395 CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); | 403 CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); |
396 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); | 404 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); |
397 CheckTotalErrorEvents(); | 405 CheckTotalErrorEvents(); |
398 | 406 |
399 histogram_tester_.ExpectTotalCount( | 407 histogram_tester_.ExpectTotalCount( |
400 page_load_metrics::internal::kPageLoadTimingStatus, 1); | 408 page_load_metrics::internal::kPageLoadTimingStatus, 1); |
401 histogram_tester_.ExpectBucketCount( | 409 histogram_tester_.ExpectBucketCount( |
402 page_load_metrics::internal::kPageLoadTimingStatus, | 410 page_load_metrics::internal::kPageLoadTimingStatus, |
403 page_load_metrics::internal::INVALID_NULL_NAVIGATION_START, 1); | 411 page_load_metrics::internal::INVALID_NULL_NAVIGATION_START, 1); |
404 } | 412 } |
405 | 413 |
406 TEST_F(MetricsWebContentsObserverTest, TimingOrderError) { | 414 TEST_F(MetricsWebContentsObserverTest, TimingOrderError) { |
407 PageLoadTiming timing; | 415 PageLoadTiming timing; |
| 416 page_load_metrics::InitPageLoadTimingForTest(&timing); |
408 timing.navigation_start = base::Time::FromDoubleT(1); | 417 timing.navigation_start = base::Time::FromDoubleT(1); |
409 timing.parse_timing.parse_stop = base::TimeDelta::FromMilliseconds(1); | 418 timing.parse_timing->parse_stop = base::TimeDelta::FromMilliseconds(1); |
410 | 419 |
411 content::WebContentsTester* web_contents_tester = | 420 content::WebContentsTester* web_contents_tester = |
412 content::WebContentsTester::For(web_contents()); | 421 content::WebContentsTester::For(web_contents()); |
413 | 422 |
414 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 423 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
415 SimulateTimingUpdate(timing); | 424 SimulateTimingUpdate(timing); |
416 ASSERT_EQ(0, CountUpdatedTimingReported()); | 425 ASSERT_EQ(0, CountUpdatedTimingReported()); |
417 NavigateToUntrackedUrl(); | 426 NavigateToUntrackedUrl(); |
418 ASSERT_EQ(0, CountUpdatedTimingReported()); | 427 ASSERT_EQ(0, CountUpdatedTimingReported()); |
419 ASSERT_EQ(1, CountCompleteTimingReported()); | 428 ASSERT_EQ(1, CountCompleteTimingReported()); |
420 | 429 |
421 CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); | 430 CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); |
422 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); | 431 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1); |
423 CheckTotalErrorEvents(); | 432 CheckTotalErrorEvents(); |
424 | 433 |
425 histogram_tester_.ExpectTotalCount( | 434 histogram_tester_.ExpectTotalCount( |
426 page_load_metrics::internal::kPageLoadTimingStatus, 1); | 435 page_load_metrics::internal::kPageLoadTimingStatus, 1); |
427 histogram_tester_.ExpectBucketCount( | 436 histogram_tester_.ExpectBucketCount( |
428 page_load_metrics::internal::kPageLoadTimingStatus, | 437 page_load_metrics::internal::kPageLoadTimingStatus, |
429 page_load_metrics::internal::INVALID_ORDER_PARSE_START_PARSE_STOP, 1); | 438 page_load_metrics::internal::INVALID_ORDER_PARSE_START_PARSE_STOP, 1); |
430 } | 439 } |
431 | 440 |
432 TEST_F(MetricsWebContentsObserverTest, NotInMainError) { | 441 TEST_F(MetricsWebContentsObserverTest, NotInMainError) { |
433 PageLoadTiming timing; | 442 PageLoadTiming timing; |
| 443 page_load_metrics::InitPageLoadTimingForTest(&timing); |
434 timing.navigation_start = base::Time::FromDoubleT(1); | 444 timing.navigation_start = base::Time::FromDoubleT(1); |
435 | 445 |
436 content::WebContentsTester* web_contents_tester = | 446 content::WebContentsTester* web_contents_tester = |
437 content::WebContentsTester::For(web_contents()); | 447 content::WebContentsTester::For(web_contents()); |
438 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 448 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
439 | 449 |
440 content::RenderFrameHostTester* rfh_tester = | 450 content::RenderFrameHostTester* rfh_tester = |
441 content::RenderFrameHostTester::For(main_rfh()); | 451 content::RenderFrameHostTester::For(main_rfh()); |
442 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); | 452 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); |
443 | 453 |
444 content::RenderFrameHostTester* subframe_tester = | 454 content::RenderFrameHostTester* subframe_tester = |
445 content::RenderFrameHostTester::For(subframe); | 455 content::RenderFrameHostTester::For(subframe); |
446 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); | 456 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); |
447 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); | 457 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); |
448 SimulateTimingUpdate(timing, subframe); | 458 SimulateTimingUpdate(timing, subframe); |
449 CheckErrorEvent(ERR_TIMING_IPC_FROM_SUBFRAME, 1); | 459 CheckErrorEvent(ERR_TIMING_IPC_FROM_SUBFRAME, 1); |
450 CheckTotalErrorEvents(); | 460 CheckTotalErrorEvents(); |
451 ASSERT_EQ(0, CountUpdatedTimingReported()); | 461 ASSERT_EQ(0, CountUpdatedTimingReported()); |
452 ASSERT_EQ(0, CountCompleteTimingReported()); | 462 ASSERT_EQ(0, CountCompleteTimingReported()); |
453 } | 463 } |
454 | 464 |
455 TEST_F(MetricsWebContentsObserverTest, BadIPC) { | 465 TEST_F(MetricsWebContentsObserverTest, BadIPC) { |
456 PageLoadTiming timing; | 466 PageLoadTiming timing; |
| 467 page_load_metrics::InitPageLoadTimingForTest(&timing); |
457 timing.navigation_start = base::Time::FromDoubleT(10); | 468 timing.navigation_start = base::Time::FromDoubleT(10); |
458 PageLoadTiming timing2; | 469 PageLoadTiming timing2; |
| 470 page_load_metrics::InitPageLoadTimingForTest(&timing2); |
459 timing2.navigation_start = base::Time::FromDoubleT(100); | 471 timing2.navigation_start = base::Time::FromDoubleT(100); |
460 | 472 |
461 content::WebContentsTester* web_contents_tester = | 473 content::WebContentsTester* web_contents_tester = |
462 content::WebContentsTester::For(web_contents()); | 474 content::WebContentsTester::For(web_contents()); |
463 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 475 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
464 | 476 |
465 SimulateTimingUpdate(timing); | 477 SimulateTimingUpdate(timing); |
466 ASSERT_EQ(1, CountUpdatedTimingReported()); | 478 ASSERT_EQ(1, CountUpdatedTimingReported()); |
467 SimulateTimingUpdate(timing2); | 479 SimulateTimingUpdate(timing2); |
468 ASSERT_EQ(1, CountUpdatedTimingReported()); | 480 ASSERT_EQ(1, CountUpdatedTimingReported()); |
469 | 481 |
470 CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING_DESCENDENT, 1); | 482 CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING_DESCENDENT, 1); |
471 CheckTotalErrorEvents(); | 483 CheckTotalErrorEvents(); |
472 } | 484 } |
473 | 485 |
474 TEST_F(MetricsWebContentsObserverTest, ObservePartialNavigation) { | 486 TEST_F(MetricsWebContentsObserverTest, ObservePartialNavigation) { |
475 // Reset the state of the tests, and attach the MetricsWebContentsObserver in | 487 // Reset the state of the tests, and attach the MetricsWebContentsObserver in |
476 // the middle of a navigation. This tests that the class is robust to only | 488 // the middle of a navigation. This tests that the class is robust to only |
477 // observing some of a navigation. | 489 // observing some of a navigation. |
478 DeleteContents(); | 490 DeleteContents(); |
479 SetContents(CreateTestWebContents()); | 491 SetContents(CreateTestWebContents()); |
480 | 492 |
481 PageLoadTiming timing; | 493 PageLoadTiming timing; |
| 494 page_load_metrics::InitPageLoadTimingForTest(&timing); |
482 timing.navigation_start = base::Time::FromDoubleT(10); | 495 timing.navigation_start = base::Time::FromDoubleT(10); |
483 | 496 |
484 content::WebContentsTester* web_contents_tester = | 497 content::WebContentsTester* web_contents_tester = |
485 content::WebContentsTester::For(web_contents()); | 498 content::WebContentsTester::For(web_contents()); |
486 content::RenderFrameHostTester* rfh_tester = | 499 content::RenderFrameHostTester* rfh_tester = |
487 content::RenderFrameHostTester::For(main_rfh()); | 500 content::RenderFrameHostTester::For(main_rfh()); |
488 | 501 |
489 // Start the navigation, then start observing the web contents. This used to | 502 // Start the navigation, then start observing the web contents. This used to |
490 // crash us. Make sure we bail out and don't log histograms. | 503 // crash us. Make sure we bail out and don't log histograms. |
491 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); | 504 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 676 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
664 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}), | 677 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}), |
665 completed_filtered_urls()); | 678 completed_filtered_urls()); |
666 | 679 |
667 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 680 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
668 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl), GURL(kDefaultTestUrl2)}), | 681 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl), GURL(kDefaultTestUrl2)}), |
669 completed_filtered_urls()); | 682 completed_filtered_urls()); |
670 } | 683 } |
671 | 684 |
672 } // namespace page_load_metrics | 685 } // namespace page_load_metrics |
OLD | NEW |