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

Side by Side Diff: chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer_unittest.cc

Issue 2883433002: [PageLoadMetrics] Handle case where navigation aborts (Closed)
Patch Set: Back to PS3 Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/observers/ads_page_load_metrics_obser ver.h" 5 #include "chrome/browser/page_load_metrics/observers/ads_page_load_metrics_obser ver.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 histogram_tester().ExpectUniqueSample( 443 histogram_tester().ExpectUniqueSample(
444 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Network", 20, 1); 444 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Network", 20, 1);
445 histogram_tester().ExpectUniqueSample( 445 histogram_tester().ExpectUniqueSample(
446 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total", 40, 1); 446 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total", 40, 1);
447 histogram_tester().ExpectUniqueSample( 447 histogram_tester().ExpectUniqueSample(
448 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Network", 40, 1); 448 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Network", 40, 1);
449 histogram_tester().ExpectUniqueSample( 449 histogram_tester().ExpectUniqueSample(
450 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Aggregate.Total", 20, 1); 450 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Aggregate.Total", 20, 1);
451 } 451 }
452 452
453 TEST_F(AdsPageLoadMetricsObserverTest, CountAbortedNavigation) {
454 // If the first navigation in a frame is aborted, keep track of its bytes.
455 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl);
456 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10);
457
458 // Create an ad subframe that aborts before committing.
459 RenderFrameHost* subframe_ad =
460 RenderFrameHostTester::For(main_frame)->AppendChild(kAdName);
461 auto navigation_simulator = NavigationSimulator::CreateRendererInitiated(
462 GURL(kNonAdUrl), subframe_ad);
463 // The sub-frame renavigates before it commits.
464 navigation_simulator->Start();
465 navigation_simulator->Fail(net::ERR_ABORTED);
466
467 // Load resources for the aborted frame (e.g., simulate the navigation
468 // aborting due to a doc.write during provisional navigation). They should
469 // be counted.
470 LoadResource(subframe_ad, ResourceCached::NOT_CACHED, 10);
471 LoadResource(subframe_ad, ResourceCached::NOT_CACHED, 10);
472
473 // Navigate again to trigger histograms.
474 NavigateFrame(kNonAdUrl, main_frame);
475
476 histogram_tester().ExpectUniqueSample(
477 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1);
478 histogram_tester().ExpectUniqueSample(
479 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", 20, 1);
480 histogram_tester().ExpectUniqueSample(
481 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total", 30, 1);
482 }
483
484 TEST_F(AdsPageLoadMetricsObserverTest, CountAbortedSecondNavigationForFrame) {
485 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl);
486 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10);
487
488 // Sub frame that is not an ad.
489 RenderFrameHost* sub_frame =
490 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame);
491 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10);
492
493 // Now navigate (and abort) the subframe to an ad.
494 auto navigation_simulator =
495 NavigationSimulator::CreateRendererInitiated(GURL(kAdUrl), sub_frame);
496 // The sub-frame renavigates before it commits.
497 navigation_simulator->Start();
498 navigation_simulator->Fail(net::ERR_ABORTED);
499
500 // Load resources for the aborted frame (e.g., simulate the navigation
501 // aborting due to a doc.write during provisional navigation). Since the
502 // frame attempted to load an ad, the frame is tagged forever as an ad.
503 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10);
504 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10);
505
506 // Navigate again to trigger histograms.
507 NavigateFrame(kNonAdUrl, main_frame);
508
509 histogram_tester().ExpectUniqueSample(
510 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1);
511 histogram_tester().ExpectUniqueSample(
512 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", 20, 1);
513 histogram_tester().ExpectUniqueSample(
514 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total", 40, 1);
515 }
516
453 TEST_F(AdsPageLoadMetricsObserverTest, TwoResourceLoadsBeforeCommit) { 517 TEST_F(AdsPageLoadMetricsObserverTest, TwoResourceLoadsBeforeCommit) {
454 // Main frame. 518 // Main frame.
455 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); 519 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl);
456 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); 520 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10);
457 521
458 // Now open a subframe and have its resource load before notification of 522 // Now open a subframe and have its resource load before notification of
459 // navigation finishing. 523 // navigation finishing.
460 page_load_metrics::ExtraRequestCompleteInfo request( 524 page_load_metrics::ExtraRequestCompleteInfo request(
461 GURL(kNonAdUrl), main_frame->GetFrameTreeNodeId() + 1, false /* cached */, 525 GURL(kNonAdUrl), main_frame->GetFrameTreeNodeId() + 1, false /* cached */,
462 10 * 1024 /* size */, false /* data_reduction_proxy_used */, 526 10 * 1024 /* size */, false /* data_reduction_proxy_used */,
(...skipping 12 matching lines...) Expand all
475 // Renavigate the subframe to a successful commit. But again, the resource 539 // Renavigate the subframe to a successful commit. But again, the resource
476 // loads before the observer sees the finished navigation. 540 // loads before the observer sees the finished navigation.
477 SimulateLoadedResource(request); 541 SimulateLoadedResource(request);
478 NavigateFrame(kNonAdUrl, subframe_ad); 542 NavigateFrame(kNonAdUrl, subframe_ad);
479 543
480 // Navigate again to trigger histograms. 544 // Navigate again to trigger histograms.
481 NavigateFrame(kNonAdUrl, main_frame); 545 NavigateFrame(kNonAdUrl, main_frame);
482 546
483 // 30KB in total was loaded. Ten for the main page, ten for an aborted 547 // 30KB in total was loaded. Ten for the main page, ten for an aborted
484 // ad subframe, and ten for a successful ad subframe. The aborted ad 548 // ad subframe, and ten for a successful ad subframe. The aborted ad
485 // subframe's bytes don't count. 549 // subframe's bytes count.
486 550
487 // Individual Ad Frame Metrics 551 // Individual Ad Frame Metrics
488 histogram_tester().ExpectUniqueSample( 552 histogram_tester().ExpectUniqueSample(
489 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Total", 10, 1); 553 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Total", 20, 1);
490 histogram_tester().ExpectUniqueSample( 554 histogram_tester().ExpectUniqueSample(
491 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Network", 10, 1); 555 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Network", 20, 1);
492 histogram_tester().ExpectUniqueSample( 556 histogram_tester().ExpectUniqueSample(
493 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 100, 557 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 100,
494 1); 558 1);
495 559
496 // Counts 560 // Counts
497 histogram_tester().ExpectUniqueSample( 561 histogram_tester().ExpectUniqueSample(
498 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1); 562 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1);
499 histogram_tester().ExpectUniqueSample( 563 histogram_tester().ExpectUniqueSample(
500 "PageLoad.Clients.Ads.Google.FrameCounts.MainFrameParent.TotalFrames", 1, 564 "PageLoad.Clients.Ads.Google.FrameCounts.MainFrameParent.TotalFrames", 1,
501 1); 565 1);
502 histogram_tester().ExpectUniqueSample( 566 histogram_tester().ExpectUniqueSample(
503 "PageLoad.Clients.Ads.Google.FrameCounts.MainFrameParent.AdFrames", 1, 1); 567 "PageLoad.Clients.Ads.Google.FrameCounts.MainFrameParent.AdFrames", 1, 1);
504 histogram_tester().ExpectUniqueSample( 568 histogram_tester().ExpectUniqueSample(
505 "PageLoad.Clients.Ads.Google.FrameCounts.MainFrameParent.PercentAdFrames", 569 "PageLoad.Clients.Ads.Google.FrameCounts.MainFrameParent.PercentAdFrames",
506 100, 1); 570 100, 1);
507 571
508 // Page percentages 572 // Page percentages
509 histogram_tester().ExpectUniqueSample( 573 histogram_tester().ExpectUniqueSample(
510 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total.PercentAds", 50, 1); 574 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total.PercentAds", 66, 1);
511 histogram_tester().ExpectUniqueSample( 575 histogram_tester().ExpectUniqueSample(
512 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.PercentNetwork", 576 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.PercentNetwork",
513 100, 1); 577 100, 1);
514 histogram_tester().ExpectUniqueSample( 578 histogram_tester().ExpectUniqueSample(
515 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Network.PercentAds", 50, 1); 579 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Network.PercentAds", 66, 1);
516 580
517 // Page byte counts 581 // Page byte counts
518 histogram_tester().ExpectUniqueSample( 582 histogram_tester().ExpectUniqueSample(
519 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", 10, 1); 583 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", 20, 1);
520 histogram_tester().ExpectUniqueSample( 584 histogram_tester().ExpectUniqueSample(
521 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Network", 10, 1); 585 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Network", 20, 1);
522 histogram_tester().ExpectUniqueSample( 586 histogram_tester().ExpectUniqueSample(
523 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total", 20, 1); 587 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total", 30, 1);
524 histogram_tester().ExpectUniqueSample( 588 histogram_tester().ExpectUniqueSample(
525 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Network", 20, 1); 589 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Network", 30, 1);
526 histogram_tester().ExpectUniqueSample( 590 histogram_tester().ExpectUniqueSample(
527 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Aggregate.Total", 10, 1); 591 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Aggregate.Total", 10, 1);
528 } 592 }
OLDNEW
« no previous file with comments | « chrome/browser/page_load_metrics/observers/ads_page_load_metrics_observer_browsertest.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698