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

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

Issue 1377223002: Add page load abort metrics to PageLoadMetrics system (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@plm_backgrounded_master
Patch Set: remove TODO Created 5 years, 2 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
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 17 matching lines...) Expand all
28 "PageLoad.Timing2.NavigationToDOMContentLoadedEventFired"; 28 "PageLoad.Timing2.NavigationToDOMContentLoadedEventFired";
29 const char kHistogramNameLoad[] = 29 const char kHistogramNameLoad[] =
30 "PageLoad.Timing2.NavigationToLoadEventFired"; 30 "PageLoad.Timing2.NavigationToLoadEventFired";
31 31
32 const char kBGHistogramNameFirstLayout[] = 32 const char kBGHistogramNameFirstLayout[] =
33 "PageLoad.Timing2.NavigationToFirstLayout.BG"; 33 "PageLoad.Timing2.NavigationToFirstLayout.BG";
34 const char kBGHistogramNameDomContent[] = 34 const char kBGHistogramNameDomContent[] =
35 "PageLoad.Timing2.NavigationToDOMContentLoadedEventFired.BG"; 35 "PageLoad.Timing2.NavigationToDOMContentLoadedEventFired.BG";
36 const char kBGHistogramNameLoad[] = 36 const char kBGHistogramNameLoad[] =
37 "PageLoad.Timing2.NavigationToLoadEventFired.BG"; 37 "PageLoad.Timing2.NavigationToLoadEventFired.BG";
38
39 const char kHistogramNameEvents[] = "PageLoad.EventCounts";
40
38 } // namespace 41 } // namespace
39 42
40 class MetricsWebContentsObserverTest 43 class MetricsWebContentsObserverTest
41 : public content::RenderViewHostTestHarness { 44 : public content::RenderViewHostTestHarness {
42 public: 45 public:
43 MetricsWebContentsObserverTest() {} 46 MetricsWebContentsObserverTest() {}
44 47
45 void SetUp() override { 48 void SetUp() override {
46 RenderViewHostTestHarness::SetUp(); 49 RenderViewHostTestHarness::SetUp();
47 observer_ = make_scoped_ptr(new MetricsWebContentsObserver(web_contents())); 50 observer_ = make_scoped_ptr(new MetricsWebContentsObserver(web_contents()));
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 330
328 // Navigate again to see if the timing updated for a subframe message. 331 // Navigate again to see if the timing updated for a subframe message.
329 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 332 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
330 333
331 histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 0); 334 histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 0);
332 histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 0); 335 histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 0);
333 histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 1); 336 histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 1);
334 histogram_tester_.ExpectBucketCount(kHistogramNameFirstLayout, 337 histogram_tester_.ExpectBucketCount(kHistogramNameFirstLayout,
335 first_layout.InMilliseconds(), 1); 338 first_layout.InMilliseconds(), 1);
336 } 339 }
340
341 TEST_F(MetricsWebContentsObserverTest, FailProvisionalLoad) {
342 content::WebContentsTester* web_contents_tester =
343 content::WebContentsTester::For(web_contents());
344
345 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl));
346 content::RenderFrameHostTester* rfh_tester =
347 content::RenderFrameHostTester::For(main_rfh());
348 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl),
349 net::ERR_TIMED_OUT);
350 rfh_tester->SimulateNavigationStop();
351
352 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 3);
353 histogram_tester_.ExpectBucketCount(kHistogramNameEvents,
354 PAGE_LOAD_STARTED, 1);
355 histogram_tester_.ExpectBucketCount(kHistogramNameEvents,
356 PAGE_LOAD_FAILED_BEFORE_COMMIT, 1);
357 histogram_tester_.ExpectBucketCount(kHistogramNameEvents,
358 PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT, 1);
359 histogram_tester_.ExpectBucketCount(kHistogramNameEvents,
360 PAGE_LOAD_ABORTED_BEFORE_COMMIT, 0);
361 }
362
363 TEST_F(MetricsWebContentsObserverTest, AbortProvisionalLoad) {
364 content::WebContentsTester* web_contents_tester =
365 content::WebContentsTester::For(web_contents());
366
367 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl));
368 content::RenderFrameHostTester* rfh_tester =
369 content::RenderFrameHostTester::For(main_rfh());
370 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl), net::ERR_ABORTED);
371 rfh_tester->SimulateNavigationStop();
372
373 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 4);
374 histogram_tester_.ExpectBucketCount(kHistogramNameEvents,
375 PAGE_LOAD_STARTED, 1);
376 histogram_tester_.ExpectBucketCount(kHistogramNameEvents,
377 PAGE_LOAD_FAILED_BEFORE_COMMIT, 1);
378 histogram_tester_.ExpectBucketCount(kHistogramNameEvents,
379 PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT, 1);
380 histogram_tester_.ExpectBucketCount(kHistogramNameEvents,
381 PAGE_LOAD_ABORTED_BEFORE_COMMIT, 1);
382 }
383
384 TEST_F(MetricsWebContentsObserverTest, AbortCommittedLoadBeforeFirstLayout) {
385 PageLoadTiming timing;
386 timing.navigation_start = base::Time::FromDoubleT(10);
387
388 content::WebContentsTester* web_contents_tester =
389 content::WebContentsTester::For(web_contents());
390 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
391
392 observer_->OnMessageReceived(
393 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing),
394 main_rfh());
395 // Navigate again to force histogram logging.
396 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
397
398 // 3 events: 2 starts and one abort before first layout.
399 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 3);
400 histogram_tester_.ExpectBucketCount(kHistogramNameEvents,
401 PAGE_LOAD_STARTED, 2);
402 histogram_tester_.ExpectBucketCount(
403 kHistogramNameEvents, PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT, 1);
404 }
405
406 TEST_F(MetricsWebContentsObserverTest,
407 SuccessfulFirstLayoutInForeGroundEvent) {
408 PageLoadTiming timing;
409 timing.navigation_start = base::Time::FromDoubleT(10);
410 timing.first_layout = base::TimeDelta::FromMilliseconds(100);
411
412 content::WebContentsTester* web_contents_tester =
413 content::WebContentsTester::For(web_contents());
414 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
415
416 observer_->OnMessageReceived(
417 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing),
418 main_rfh());
419 // Navigate again to force histogram logging.
420 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
421
422 // 3 events: 2 starts and one successful first layout.
423 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 3);
424 histogram_tester_.ExpectBucketCount(kHistogramNameEvents,
425 PAGE_LOAD_STARTED, 2);
426 histogram_tester_.ExpectBucketCount(
427 kHistogramNameEvents, PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_FOREGROUND, 1);
428 }
429
430 TEST_F(MetricsWebContentsObserverTest,
431 SuccessfulFirstLayoutInBackgroundEvent) {
432 PageLoadTiming timing;
433 timing.navigation_start = base::Time::FromDoubleT(
434 (base::TimeTicks::Now() - base::TimeTicks::UnixEpoch()).InSecondsF() - 1);
435
436 timing.first_layout = base::TimeDelta::FromSeconds(30);
437
438 content::WebContentsTester* web_contents_tester =
439 content::WebContentsTester::For(web_contents());
440 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
441 // Background the tab.
442 observer_->WasHidden();
443
444 observer_->OnMessageReceived(
445 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing),
446 main_rfh());
447
448 observer_->WasShown();
449 // Navigate again to force histogram logging.
450 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
451
452 // 3 events: 2 starts and one successful first layout.
453 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 3);
454 histogram_tester_.ExpectBucketCount(kHistogramNameEvents,
455 PAGE_LOAD_STARTED, 2);
456 histogram_tester_.ExpectBucketCount(
457 kHistogramNameEvents, PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_BACKGROUND, 1);
458 }
337 } // namespace page_load_metrics 459 } // namespace page_load_metrics
OLDNEW
« no previous file with comments | « components/page_load_metrics/browser/metrics_web_contents_observer.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698