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

Side by Side Diff: chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc

Issue 2820943002: Add detailed tracking for causes of invalid PageLoadTimings. (Closed)
Patch Set: add tests Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/process/kill.h" 12 #include "base/process/kill.h"
13 #include "base/test/histogram_tester.h" 13 #include "base/test/histogram_tester.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "chrome/browser/page_load_metrics/metrics_navigation_throttle.h" 15 #include "chrome/browser/page_load_metrics/metrics_navigation_throttle.h"
16 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface. h" 16 #include "chrome/browser/page_load_metrics/page_load_metrics_embedder_interface. h"
17 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" 17 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
18 #include "chrome/browser/page_load_metrics/page_load_tracker.h" 18 #include "chrome/browser/page_load_metrics/page_load_tracker.h"
19 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" 19 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h"
20 #include "chrome/common/url_constants.h"
20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
21 #include "content/public/browser/navigation_handle.h" 22 #include "content/public/browser/navigation_handle.h"
22 #include "content/public/browser/render_frame_host.h" 23 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/test/test_renderer_host.h" 24 #include "content/public/test/test_renderer_host.h"
24 #include "content/public/test/web_contents_tester.h" 25 #include "content/public/test/web_contents_tester.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 #include "url/gurl.h" 27 #include "url/gurl.h"
27 28
28 namespace page_load_metrics { 29 namespace page_load_metrics {
29 30
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 149
149 class MetricsWebContentsObserverTest : public ChromeRenderViewHostTestHarness { 150 class MetricsWebContentsObserverTest : public ChromeRenderViewHostTestHarness {
150 public: 151 public:
151 MetricsWebContentsObserverTest() : num_errors_(0) {} 152 MetricsWebContentsObserverTest() : num_errors_(0) {}
152 153
153 void SetUp() override { 154 void SetUp() override {
154 ChromeRenderViewHostTestHarness::SetUp(); 155 ChromeRenderViewHostTestHarness::SetUp();
155 AttachObserver(); 156 AttachObserver();
156 } 157 }
157 158
159 void NavigateToUntrackedUrl() {
160 content::WebContentsTester::For(web_contents())
161 ->NavigateAndCommit(GURL(url::kAboutBlankURL));
162 }
163
158 void SimulateTimingUpdate(const PageLoadTiming& timing) { 164 void SimulateTimingUpdate(const PageLoadTiming& timing) {
159 SimulateTimingUpdate(timing, web_contents()->GetMainFrame()); 165 SimulateTimingUpdate(timing, web_contents()->GetMainFrame());
160 } 166 }
161 167
162 void SimulateTimingUpdate(const PageLoadTiming& timing, 168 void SimulateTimingUpdate(const PageLoadTiming& timing,
163 content::RenderFrameHost* render_frame_host) { 169 content::RenderFrameHost* render_frame_host) {
164 ASSERT_TRUE(observer_->OnMessageReceived( 170 ASSERT_TRUE(observer_->OnMessageReceived(
165 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing, 171 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing,
166 PageLoadMetadata()), 172 PageLoadMetadata()),
167 render_frame_host)); 173 render_frame_host));
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 ASSERT_EQ(0, CountUpdatedTimingReported()); 350 ASSERT_EQ(0, CountUpdatedTimingReported());
345 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 351 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
346 ASSERT_EQ(0, CountUpdatedTimingReported()); 352 ASSERT_EQ(0, CountUpdatedTimingReported());
347 ASSERT_EQ(0, CountCompleteTimingReported()); 353 ASSERT_EQ(0, CountCompleteTimingReported());
348 354
349 CheckErrorEvent(ERR_IPC_FROM_BAD_URL_SCHEME, 1); 355 CheckErrorEvent(ERR_IPC_FROM_BAD_URL_SCHEME, 1);
350 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); 356 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1);
351 CheckTotalErrorEvents(); 357 CheckTotalErrorEvents();
352 } 358 }
353 359
360 TEST_F(MetricsWebContentsObserverTest, EmptyTimingError) {
361 PageLoadTiming timing;
362
363 content::WebContentsTester* web_contents_tester =
364 content::WebContentsTester::For(web_contents());
365
366 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
367 SimulateTimingUpdate(timing);
368 ASSERT_EQ(0, CountUpdatedTimingReported());
369 NavigateToUntrackedUrl();
370 ASSERT_EQ(0, CountUpdatedTimingReported());
371 ASSERT_EQ(1, CountCompleteTimingReported());
372
373 CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1);
374 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1);
375 CheckTotalErrorEvents();
376
377 histogram_tester_.ExpectTotalCount(
378 page_load_metrics::internal::kPageLoadTimingStatus, 1);
379 histogram_tester_.ExpectBucketCount(
380 page_load_metrics::internal::kPageLoadTimingStatus,
381 page_load_metrics::internal::INVALID_EMPTY_TIMING, 1);
382 }
383
384 TEST_F(MetricsWebContentsObserverTest, NullNavigationStartError) {
385 PageLoadTiming timing;
386 timing.parse_timing.parse_start = base::TimeDelta::FromMilliseconds(1);
387
388 content::WebContentsTester* web_contents_tester =
389 content::WebContentsTester::For(web_contents());
390
391 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
392 SimulateTimingUpdate(timing);
393 ASSERT_EQ(0, CountUpdatedTimingReported());
394 NavigateToUntrackedUrl();
395 ASSERT_EQ(0, CountUpdatedTimingReported());
396 ASSERT_EQ(1, CountCompleteTimingReported());
397
398 CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1);
399 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1);
400 CheckTotalErrorEvents();
401
402 histogram_tester_.ExpectTotalCount(
403 page_load_metrics::internal::kPageLoadTimingStatus, 1);
404 histogram_tester_.ExpectBucketCount(
405 page_load_metrics::internal::kPageLoadTimingStatus,
406 page_load_metrics::internal::INVALID_NULL_NAVIGATION_START, 1);
407 }
408
409 TEST_F(MetricsWebContentsObserverTest, TimingOrderError) {
410 PageLoadTiming timing;
411 timing.navigation_start = base::Time::FromDoubleT(1);
412 timing.parse_timing.parse_stop = base::TimeDelta::FromMilliseconds(1);
413
414 content::WebContentsTester* web_contents_tester =
415 content::WebContentsTester::For(web_contents());
416
417 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
418 SimulateTimingUpdate(timing);
419 ASSERT_EQ(0, CountUpdatedTimingReported());
420 NavigateToUntrackedUrl();
421 ASSERT_EQ(0, CountUpdatedTimingReported());
422 ASSERT_EQ(1, CountCompleteTimingReported());
423
424 CheckErrorEvent(ERR_BAD_TIMING_IPC_INVALID_TIMING, 1);
425 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1);
426 CheckTotalErrorEvents();
427
428 histogram_tester_.ExpectTotalCount(
429 page_load_metrics::internal::kPageLoadTimingStatus, 1);
430 histogram_tester_.ExpectBucketCount(
431 page_load_metrics::internal::kPageLoadTimingStatus,
432 page_load_metrics::internal::INVALID_ORDER_PARSE_START_PARSE_STOP, 1);
433 }
434
354 TEST_F(MetricsWebContentsObserverTest, NotInMainError) { 435 TEST_F(MetricsWebContentsObserverTest, NotInMainError) {
355 PageLoadTiming timing; 436 PageLoadTiming timing;
356 timing.navigation_start = base::Time::FromDoubleT(1); 437 timing.navigation_start = base::Time::FromDoubleT(1);
357 438
358 content::WebContentsTester* web_contents_tester = 439 content::WebContentsTester* web_contents_tester =
359 content::WebContentsTester::For(web_contents()); 440 content::WebContentsTester::For(web_contents());
360 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 441 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
361 442
362 content::RenderFrameHostTester* rfh_tester = 443 content::RenderFrameHostTester* rfh_tester =
363 content::RenderFrameHostTester::For(main_rfh()); 444 content::RenderFrameHostTester::For(main_rfh());
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); 666 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
586 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}), 667 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl)}),
587 completed_filtered_urls()); 668 completed_filtered_urls());
588 669
589 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 670 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
590 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl), GURL(kDefaultTestUrl2)}), 671 ASSERT_EQ(std::vector<GURL>({GURL(kDefaultTestUrl), GURL(kDefaultTestUrl2)}),
591 completed_filtered_urls()); 672 completed_filtered_urls());
592 } 673 }
593 674
594 } // namespace page_load_metrics 675 } // namespace page_load_metrics
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698