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

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

Issue 1449253002: [do not review][page_load_metrics] User Initiated Abort Tracking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@plm_navigation_start
Patch Set: Created 5 years, 1 month 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
OLDNEW
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 "components/page_load_metrics/browser/metrics_web_contents_observer.h" 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/process/kill.h" 8 #include "base/process/kill.h"
9 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 433
434 // Navigate again to see if the timing updated for the foregrounded load. 434 // Navigate again to see if the timing updated for the foregrounded load.
435 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 435 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
436 436
437 histogram_tester_.ExpectTotalCount(kHistogramDomContentLoaded, 0); 437 histogram_tester_.ExpectTotalCount(kHistogramDomContentLoaded, 0);
438 histogram_tester_.ExpectTotalCount(kHistogramLoad, 0); 438 histogram_tester_.ExpectTotalCount(kHistogramLoad, 0);
439 histogram_tester_.ExpectTotalCount(kHistogramFirstLayout, 1); 439 histogram_tester_.ExpectTotalCount(kHistogramFirstLayout, 1);
440 histogram_tester_.ExpectBucketCount(kHistogramFirstLayout, 440 histogram_tester_.ExpectBucketCount(kHistogramFirstLayout,
441 first_layout.InMilliseconds(), 1); 441 first_layout.InMilliseconds(), 1);
442 histogram_tester_.ExpectTotalCount(kHistogramFirstTextPaint, 0); 442 histogram_tester_.ExpectTotalCount(kHistogramFirstTextPaint, 0);
443
444 histogram_tester_.ExpectTotalCount(kHistogramProvisionalAbortNewNavigation,
445 1);
446 }
447
448 TEST_F(MetricsWebContentsObserverTest, AbortStopClose) {
449 PageLoadTiming timing;
450 timing.navigation_start = base::Time::FromDoubleT(1);
451 content::WebContentsTester* web_contents_tester =
452 content::WebContentsTester::For(web_contents());
453 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
454 observer_->OnMessageReceived(
455 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing),
456 main_rfh());
457 // Simulate the user pressing the stop button.
458 observer_->NavigationStopped();
459 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
460 observer_->OnMessageReceived(
461 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing),
462 main_rfh());
463 // Kill the MetricsWebContentsObserver to simulate closing the tab.
464 observer_.reset();
465 histogram_tester_.ExpectTotalCount(kHistogramCommittedAbortStop, 1);
466 histogram_tester_.ExpectTotalCount(kHistogramCommittedAbortClose, 1);
467 }
468
469 TEST_F(MetricsWebContentsObserverTest, AbortNewNavigation) {
470 PageLoadTiming timing;
471 timing.navigation_start = base::Time::FromDoubleT(1);
472 content::WebContentsTester* web_contents_tester =
473 content::WebContentsTester::For(web_contents());
474 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
475 observer_->OnMessageReceived(
476 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing),
477 main_rfh());
478 // Simulate the user performaning another navigation before first paint.
479 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
480 histogram_tester_.ExpectTotalCount(kHistogramCommittedAbortNewNavigation, 1);
481 }
482
483 TEST_F(MetricsWebContentsObserverTest, AbortBackground) {
484 PageLoadTiming timing;
485 timing.navigation_start = base::Time::FromDoubleT(1);
486 timing.first_paint = base::TimeDelta::FromSeconds(10);
487 content::WebContentsTester* web_contents_tester =
488 content::WebContentsTester::For(web_contents());
489 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
490 // Background the tab and go for a coffee or something.
491 observer_->WasHidden();
492 observer_->OnMessageReceived(
493 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing),
494 main_rfh());
495 // Come back and start browsing again.
496 observer_->WasShown();
497 // Simulate the user performaning another navigation.
498 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
499 histogram_tester_.ExpectTotalCount(kHistogramCommittedAbortBackground, 1);
443 } 500 }
444 501
445 TEST_F(MetricsWebContentsObserverTest, FailProvisionalLoad) { 502 TEST_F(MetricsWebContentsObserverTest, FailProvisionalLoad) {
446 content::WebContentsTester* web_contents_tester = 503 content::WebContentsTester* web_contents_tester =
447 content::WebContentsTester::For(web_contents()); 504 content::WebContentsTester::For(web_contents());
448 505
449 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); 506 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl));
450 content::RenderFrameHostTester* rfh_tester = 507 content::RenderFrameHostTester* rfh_tester =
451 content::RenderFrameHostTester::For(main_rfh()); 508 content::RenderFrameHostTester::For(main_rfh());
452 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl), 509 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl),
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 EXPECT_NE(string_it, sample_obj->string_fields.end()); 767 EXPECT_NE(string_it, sample_obj->string_fields.end());
711 EXPECT_EQ(rappor::GetDomainAndRegistrySampleFromGURL(GURL(kDefaultTestUrl)), 768 EXPECT_EQ(rappor::GetDomainAndRegistrySampleFromGURL(GURL(kDefaultTestUrl)),
712 string_it->second); 769 string_it->second);
713 770
714 const auto& flag_it = sample_obj->flag_fields.find("IsSlow"); 771 const auto& flag_it = sample_obj->flag_fields.find("IsSlow");
715 EXPECT_NE(flag_it, sample_obj->flag_fields.end()); 772 EXPECT_NE(flag_it, sample_obj->flag_fields.end());
716 EXPECT_EQ(0u, flag_it->second); 773 EXPECT_EQ(0u, flag_it->second);
717 } 774 }
718 775
719 } // namespace page_load_metrics 776 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698