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

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: Add 100ms condition to overriding ABORT_OTHER. Remove ABORT_OTHER for committed loads 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } 443 }
444 444
445 TEST_F(MetricsWebContentsObserverTest, AbortStopClose) {
446 PageLoadTiming timing;
447 timing.navigation_start = base::Time::FromDoubleT(1);
448 content::WebContentsTester* web_contents_tester =
449 content::WebContentsTester::For(web_contents());
450 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
451 observer_->OnMessageReceived(
452 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing),
453 main_rfh());
454 // Simulate the user pressing the stop button.
455 observer_->NavigationStopped();
456 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
457 observer_->OnMessageReceived(
458 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing),
459 main_rfh());
460 // Kill the MetricsWebContentsObserver to simulate closing the tab.
461 observer_.reset();
462 histogram_tester_.ExpectTotalCount(kHistogramCommittedAbortStop, 1);
463 histogram_tester_.ExpectTotalCount(kHistogramCommittedAbortClose, 1);
464 }
465
466 TEST_F(MetricsWebContentsObserverTest, AbortNewNavigation) {
467 PageLoadTiming timing;
468 timing.navigation_start = base::Time::FromDoubleT(1);
469 content::WebContentsTester* web_contents_tester =
470 content::WebContentsTester::For(web_contents());
471 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
472 observer_->OnMessageReceived(
473 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing),
474 main_rfh());
475 // Simulate the user performaning another navigation before first paint.
476 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
477 histogram_tester_.ExpectTotalCount(kHistogramCommittedAbortNewNavigation, 1);
478 }
479
480 TEST_F(MetricsWebContentsObserverTest, AbortBackground) {
481 PageLoadTiming timing;
482 timing.navigation_start = base::Time::FromDoubleT(1);
483 timing.first_paint = base::TimeDelta::FromSeconds(10);
484 content::WebContentsTester* web_contents_tester =
485 content::WebContentsTester::For(web_contents());
486 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
487 // Background the tab and go for a coffee or something.
488 observer_->WasHidden();
489 observer_->OnMessageReceived(
490 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing),
491 main_rfh());
492 // Come back and start browsing again.
493 observer_->WasShown();
494 // Simulate the user performaning another navigation.
495 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
496 histogram_tester_.ExpectTotalCount(kHistogramBackgroundBeforePaint, 1);
497 }
498
445 TEST_F(MetricsWebContentsObserverTest, FailProvisionalLoad) { 499 TEST_F(MetricsWebContentsObserverTest, FailProvisionalLoad) {
446 content::WebContentsTester* web_contents_tester = 500 content::WebContentsTester* web_contents_tester =
447 content::WebContentsTester::For(web_contents()); 501 content::WebContentsTester::For(web_contents());
448 502
449 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); 503 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl));
450 content::RenderFrameHostTester* rfh_tester = 504 content::RenderFrameHostTester* rfh_tester =
451 content::RenderFrameHostTester::For(main_rfh()); 505 content::RenderFrameHostTester::For(main_rfh());
452 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl), 506 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl),
453 net::ERR_TIMED_OUT); 507 net::ERR_TIMED_OUT);
454 rfh_tester->SimulateNavigationStop(); 508 rfh_tester->SimulateNavigationStop();
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 EXPECT_NE(string_it, sample_obj->string_fields.end()); 764 EXPECT_NE(string_it, sample_obj->string_fields.end());
711 EXPECT_EQ(rappor::GetDomainAndRegistrySampleFromGURL(GURL(kDefaultTestUrl)), 765 EXPECT_EQ(rappor::GetDomainAndRegistrySampleFromGURL(GURL(kDefaultTestUrl)),
712 string_it->second); 766 string_it->second);
713 767
714 const auto& flag_it = sample_obj->flag_fields.find("IsSlow"); 768 const auto& flag_it = sample_obj->flag_fields.find("IsSlow");
715 EXPECT_NE(flag_it, sample_obj->flag_fields.end()); 769 EXPECT_NE(flag_it, sample_obj->flag_fields.end());
716 EXPECT_EQ(0u, flag_it->second); 770 EXPECT_EQ(0u, flag_it->second);
717 } 771 }
718 772
719 } // namespace page_load_metrics 773 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698