| OLD | NEW |
| 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 #include <utility> |
| 9 #include <vector> |
| 8 | 10 |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 11 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
| 14 #include "chrome/browser/page_load_metrics/ads_detection.h" |
| 12 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | 15 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
| 13 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_
test_harness.h" | 16 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_
test_harness.h" |
| 14 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" | 17 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" |
| 15 #include "chrome/browser/page_load_metrics/page_load_tracker.h" | 18 #include "chrome/browser/page_load_metrics/page_load_tracker.h" |
| 16 #include "components/subresource_filter/content/browser/subresource_filter_obser
ver_manager.h" | 19 #include "components/subresource_filter/content/browser/subresource_filter_obser
ver_manager.h" |
| 17 #include "components/subresource_filter/core/common/load_policy.h" | 20 #include "components/subresource_filter/core/common/load_policy.h" |
| 18 #include "content/public/browser/global_request_id.h" | 21 #include "content/public/browser/global_request_id.h" |
| 19 #include "content/public/browser/navigation_handle.h" | 22 #include "content/public/browser/navigation_handle.h" |
| 20 #include "content/public/browser/navigation_throttle.h" | 23 #include "content/public/browser/navigation_throttle.h" |
| 21 #include "content/public/browser/render_frame_host.h" | 24 #include "content/public/browser/render_frame_host.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 | 35 |
| 33 namespace { | 36 namespace { |
| 34 | 37 |
| 35 struct ExpectedFrameBytes { | 38 struct ExpectedFrameBytes { |
| 36 ExpectedFrameBytes(size_t cached_kb, size_t uncached_kb) | 39 ExpectedFrameBytes(size_t cached_kb, size_t uncached_kb) |
| 37 : cached_kb(cached_kb), uncached_kb(uncached_kb) {} | 40 : cached_kb(cached_kb), uncached_kb(uncached_kb) {} |
| 38 size_t cached_kb; | 41 size_t cached_kb; |
| 39 size_t uncached_kb; | 42 size_t uncached_kb; |
| 40 }; | 43 }; |
| 41 | 44 |
| 42 enum class AdType { GOOGLE = 0, SUBRESOURCE_FILTER = 1, ALL = 2 }; | |
| 43 enum class ResourceCached { NOT_CACHED, CACHED }; | 45 enum class ResourceCached { NOT_CACHED, CACHED }; |
| 44 enum class FrameType { AD = 0, NON_AD }; | 46 enum class FrameType { AD = 0, NON_AD }; |
| 45 | 47 |
| 46 const char kAdUrl[] = "https://tpc.googlesyndication.com/safeframe/1"; | 48 const char kAdUrl[] = "https://tpc.googlesyndication.com/safeframe/1"; |
| 47 const char kSubresourceFilterWouldDisallowAdUrl[] = "https://ad.example.com/"; | 49 const char kSubresourceFilterWouldDisallowAdUrl[] = "https://ad.example.com/"; |
| 48 const char kSubresourceFilterDisallowAdUrl[] = | 50 const char kSubresourceFilterDisallowAdUrl[] = |
| 49 "https://ad.example.com/disallow"; | 51 "https://ad.example.com/disallow"; |
| 50 const char kNonAdUrl[] = "https://foo.com/"; | 52 const char kNonAdUrl[] = "https://foo.com/"; |
| 51 const char kNonAdUrl2[] = "https://bar.com/"; | 53 const char kNonAdUrl2[] = "https://bar.com/"; |
| 52 | 54 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 121 |
| 120 private: | 122 private: |
| 121 DelayWillProcessResponseThrottle* throttle_ = nullptr; | 123 DelayWillProcessResponseThrottle* throttle_ = nullptr; |
| 122 content::GlobalRequestID global_request_id_; | 124 content::GlobalRequestID global_request_id_; |
| 123 | 125 |
| 124 DISALLOW_COPY_AND_ASSIGN(DelayWillProcessResponseObserver); | 126 DISALLOW_COPY_AND_ASSIGN(DelayWillProcessResponseObserver); |
| 125 }; | 127 }; |
| 126 | 128 |
| 127 std::string AdTypeToString(AdType ad_type) { | 129 std::string AdTypeToString(AdType ad_type) { |
| 128 switch (ad_type) { | 130 switch (ad_type) { |
| 129 case AdType::GOOGLE: | 131 case AD_TYPE_GOOGLE: |
| 130 return "Google"; | 132 return "Google"; |
| 131 case AdType::SUBRESOURCE_FILTER: | 133 case AD_TYPE_SUBRESOURCE_FILTER: |
| 132 return "SubresourceFilter"; | 134 return "SubresourceFilter"; |
| 133 case AdType::ALL: | 135 case AD_TYPE_ALL: |
| 134 return "All"; | 136 return "All"; |
| 135 } | 137 } |
| 136 ADD_FAILURE(); | 138 ADD_FAILURE(); |
| 137 return ""; | 139 return ""; |
| 138 } | 140 } |
| 139 | 141 |
| 140 std::string TypedHistogram(const std::string& suffix, AdType ad_type) { | 142 std::string TypedHistogram(const std::string& suffix, AdType ad_type) { |
| 141 return base::StringPrintf("PageLoad.Clients.Ads.%s.%s", | 143 return base::StringPrintf("PageLoad.Clients.Ads.%s.%s", |
| 142 AdTypeToString(ad_type).c_str(), suffix.c_str()); | 144 AdTypeToString(ad_type).c_str(), suffix.c_str()); |
| 143 } | 145 } |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); | 347 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
| 346 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); | 348 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
| 347 LoadResource(frame1, ResourceCached::NOT_CACHED, 10); | 349 LoadResource(frame1, ResourceCached::NOT_CACHED, 10); |
| 348 LoadResource(frame2, ResourceCached::NOT_CACHED, 10); | 350 LoadResource(frame2, ResourceCached::NOT_CACHED, 10); |
| 349 | 351 |
| 350 // Navigate again to trigger histograms. | 352 // Navigate again to trigger histograms. |
| 351 NavigateFrame(kNonAdUrl, main_frame); | 353 NavigateFrame(kNonAdUrl, main_frame); |
| 352 | 354 |
| 353 TestHistograms(histogram_tester(), std::vector<ExpectedFrameBytes>(), | 355 TestHistograms(histogram_tester(), std::vector<ExpectedFrameBytes>(), |
| 354 0 /* non_ad_cached_kb */, 30 /* non_ad_uncached_kb */, | 356 0 /* non_ad_cached_kb */, 30 /* non_ad_uncached_kb */, |
| 355 AdType::GOOGLE); | 357 AD_TYPE_GOOGLE); |
| 356 | 358 |
| 357 // Verify that other UMA wasn't written. | 359 // Verify that other UMA wasn't written. |
| 358 histogram_tester().ExpectTotalCount( | 360 histogram_tester().ExpectTotalCount( |
| 359 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", 0); | 361 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", 0); |
| 360 } | 362 } |
| 361 | 363 |
| 362 TEST_F(AdsPageLoadMetricsObserverTest, ResourceBeforeAdFrameCommits) { | 364 TEST_F(AdsPageLoadMetricsObserverTest, ResourceBeforeAdFrameCommits) { |
| 363 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 365 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 364 | 366 |
| 365 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); | 367 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
| 366 | 368 |
| 367 // Assume that the next frame's id will be the main frame + 1 and load a | 369 // Assume that the next frame's id will be the main frame + 1 and load a |
| 368 // resource for that frame. Make sure it gets counted. | 370 // resource for that frame. Make sure it gets counted. |
| 369 page_load_metrics::ExtraRequestCompleteInfo request( | 371 page_load_metrics::ExtraRequestCompleteInfo request( |
| 370 GURL(kNonAdUrl), net::HostPortPair(), | 372 GURL(kNonAdUrl), net::HostPortPair(), |
| 371 main_frame->GetFrameTreeNodeId() + 1, false /* cached */, | 373 main_frame->GetFrameTreeNodeId() + 1, false /* cached */, |
| 372 10 * 1024 /* size */, 0 /* original_network_content_length */, | 374 10 * 1024 /* size */, 0 /* original_network_content_length */, |
| 373 nullptr | 375 nullptr |
| 374 /* data_reduction_proxy_data */, | 376 /* data_reduction_proxy_data */, |
| 375 content::RESOURCE_TYPE_SUB_FRAME, 0); | 377 content::RESOURCE_TYPE_SUB_FRAME, 0); |
| 376 SimulateLoadedResource(request); | 378 SimulateLoadedResource(request); |
| 377 | 379 |
| 378 CreateAndNavigateSubFrame(kNonAdUrl, kAdName, main_frame); | 380 CreateAndNavigateSubFrame(kNonAdUrl, kAdName, main_frame); |
| 379 | 381 |
| 380 // Navigate again to trigger histograms. | 382 // Navigate again to trigger histograms. |
| 381 NavigateFrame(kNonAdUrl, main_frame); | 383 NavigateFrame(kNonAdUrl, main_frame); |
| 382 | 384 |
| 383 TestHistograms(histogram_tester(), {{0, 10}}, 0 /* non_ad_cached_kb */, | 385 TestHistograms(histogram_tester(), {{0, 10}}, 0 /* non_ad_cached_kb */, |
| 384 10 /*non_ad_uncached_kb*/, AdType::GOOGLE); | 386 10 /*non_ad_uncached_kb*/, AD_TYPE_GOOGLE); |
| 385 } | 387 } |
| 386 | 388 |
| 387 TEST_F(AdsPageLoadMetricsObserverTest, AllAdTypesInPage) { | 389 TEST_F(AdsPageLoadMetricsObserverTest, AllAdTypesInPage) { |
| 388 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 390 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 389 RenderFrameHost* non_ad_frame = | 391 RenderFrameHost* non_ad_frame = |
| 390 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); | 392 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
| 391 | 393 |
| 392 // Create 5 ad frames with the 5th nested inside the 4th. Verify that the | 394 // Create 5 ad frames with the 5th nested inside the 4th. Verify that the |
| 393 // nested ad frame doesn't get counted separately (but that its bytes are | 395 // nested ad frame doesn't get counted separately (but that its bytes are |
| 394 // still counted). Also verify that the various ad signals (urls and names) | 396 // still counted). Also verify that the various ad signals (urls and names) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 423 LoadResource(srf_frame1, ResourceCached::NOT_CACHED, 10); | 425 LoadResource(srf_frame1, ResourceCached::NOT_CACHED, 10); |
| 424 LoadResource(srf_frame2, ResourceCached::NOT_CACHED, 10); | 426 LoadResource(srf_frame2, ResourceCached::NOT_CACHED, 10); |
| 425 LoadResource(nested_srf_frame3, ResourceCached::CACHED, 10); | 427 LoadResource(nested_srf_frame3, ResourceCached::CACHED, 10); |
| 426 LoadResource(disallowed_srf_frame, ResourceCached::CACHED, 10); | 428 LoadResource(disallowed_srf_frame, ResourceCached::CACHED, 10); |
| 427 | 429 |
| 428 // Navigate again to trigger histograms. | 430 // Navigate again to trigger histograms. |
| 429 NavigateFrame(kNonAdUrl, main_frame); | 431 NavigateFrame(kNonAdUrl, main_frame); |
| 430 | 432 |
| 431 TestHistograms(histogram_tester(), {{10, 0}, {0, 10}}, | 433 TestHistograms(histogram_tester(), {{10, 0}, {0, 10}}, |
| 432 30 /* non_ad_cached_kb */, 30 /* non_ad_uncached_kb */, | 434 30 /* non_ad_cached_kb */, 30 /* non_ad_uncached_kb */, |
| 433 AdType::GOOGLE); | 435 AD_TYPE_GOOGLE); |
| 434 TestHistograms(histogram_tester(), {{0, 10}, {10, 10}}, | 436 TestHistograms(histogram_tester(), {{0, 10}, {10, 10}}, |
| 435 30 /* non_ad_cached_kb */, 20 /* non_ad_uncached_kb */, | 437 30 /* non_ad_cached_kb */, 20 /* non_ad_uncached_kb */, |
| 436 AdType::SUBRESOURCE_FILTER); | 438 AD_TYPE_SUBRESOURCE_FILTER); |
| 437 TestHistograms(histogram_tester(), {{10, 0}, {0, 10}, {0, 10}, {10, 10}}, | 439 TestHistograms(histogram_tester(), {{10, 0}, {0, 10}, {0, 10}, {10, 10}}, |
| 438 20 /* non_ad_cached_kb */, 10 /* non_ad_uncached_kb */, | 440 20 /* non_ad_cached_kb */, 10 /* non_ad_uncached_kb */, |
| 439 AdType::ALL); | 441 AD_TYPE_ALL); |
| 440 histogram_tester().ExpectBucketCount( | 442 histogram_tester().ExpectBucketCount( |
| 441 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); | 443 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); |
| 442 histogram_tester().ExpectTotalCount( | 444 histogram_tester().ExpectTotalCount( |
| 443 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); | 445 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); |
| 444 } | 446 } |
| 445 | 447 |
| 446 TEST_F(AdsPageLoadMetricsObserverTest, PageLoadSubFrameRenavigationMetrics) { | 448 TEST_F(AdsPageLoadMetricsObserverTest, PageLoadSubFrameRenavigationMetrics) { |
| 447 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 449 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 448 | 450 |
| 449 // Test behavior of an ad frame. Once a frame is considered an ad, it's | 451 // Test behavior of an ad frame. Once a frame is considered an ad, it's |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 // Navigate the ad frame again. | 494 // Navigate the ad frame again. |
| 493 ad_frame = NavigateFrame(kNonAdUrl, ad_frame); | 495 ad_frame = NavigateFrame(kNonAdUrl, ad_frame); |
| 494 | 496 |
| 495 // In total, 30KB for entire page and 20 in one ad frame. | 497 // In total, 30KB for entire page and 20 in one ad frame. |
| 496 LoadResource(ad_frame, ResourceCached::NOT_CACHED, 10); | 498 LoadResource(ad_frame, ResourceCached::NOT_CACHED, 10); |
| 497 | 499 |
| 498 // Navigate again to trigger histograms. | 500 // Navigate again to trigger histograms. |
| 499 NavigateFrame(kNonAdUrl, main_frame); | 501 NavigateFrame(kNonAdUrl, main_frame); |
| 500 | 502 |
| 501 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, | 503 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, |
| 502 10 /* non_ad_uncached_kb */, AdType::GOOGLE); | 504 10 /* non_ad_uncached_kb */, AD_TYPE_GOOGLE); |
| 503 histogram_tester().ExpectBucketCount( | 505 histogram_tester().ExpectBucketCount( |
| 504 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); | 506 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); |
| 505 histogram_tester().ExpectTotalCount( | 507 histogram_tester().ExpectTotalCount( |
| 506 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); | 508 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); |
| 507 } | 509 } |
| 508 | 510 |
| 509 TEST_F(AdsPageLoadMetricsObserverTest, PageWithNonAdFrameThatRenavigatesToAd) { | 511 TEST_F(AdsPageLoadMetricsObserverTest, PageWithNonAdFrameThatRenavigatesToAd) { |
| 510 // Main frame. | 512 // Main frame. |
| 511 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 513 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 512 | 514 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 528 | 530 |
| 529 // In total, 40KB was loaded for the entire page and 20KB from ad | 531 // In total, 40KB was loaded for the entire page and 20KB from ad |
| 530 // frames (the original child ad frame and the renavigated frame which | 532 // frames (the original child ad frame and the renavigated frame which |
| 531 // turned into an ad). | 533 // turned into an ad). |
| 532 | 534 |
| 533 // Navigate again to trigger histograms. | 535 // Navigate again to trigger histograms. |
| 534 NavigateFrame(kNonAdUrl, main_frame); | 536 NavigateFrame(kNonAdUrl, main_frame); |
| 535 | 537 |
| 536 TestHistograms(histogram_tester(), {{0, 10}, {0, 10}}, | 538 TestHistograms(histogram_tester(), {{0, 10}, {0, 10}}, |
| 537 0 /* non_ad_cached_kb */, 20 /* non_ad_uncached_kb */, | 539 0 /* non_ad_cached_kb */, 20 /* non_ad_uncached_kb */, |
| 538 AdType::GOOGLE); | 540 AD_TYPE_GOOGLE); |
| 539 histogram_tester().ExpectBucketCount( | 541 histogram_tester().ExpectBucketCount( |
| 540 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); | 542 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); |
| 541 histogram_tester().ExpectTotalCount( | 543 histogram_tester().ExpectTotalCount( |
| 542 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); | 544 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); |
| 543 } | 545 } |
| 544 | 546 |
| 545 TEST_F(AdsPageLoadMetricsObserverTest, CountAbortedNavigation) { | 547 TEST_F(AdsPageLoadMetricsObserverTest, CountAbortedNavigation) { |
| 546 // If the first navigation in a frame is aborted, keep track of its bytes. | 548 // If the first navigation in a frame is aborted, keep track of its bytes. |
| 547 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 549 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 548 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); | 550 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 559 // Load resources for the aborted frame (e.g., simulate the navigation | 561 // Load resources for the aborted frame (e.g., simulate the navigation |
| 560 // aborting due to a doc.write during provisional navigation). They should | 562 // aborting due to a doc.write during provisional navigation). They should |
| 561 // be counted. | 563 // be counted. |
| 562 LoadResource(subframe_ad, ResourceCached::NOT_CACHED, 10); | 564 LoadResource(subframe_ad, ResourceCached::NOT_CACHED, 10); |
| 563 LoadResource(subframe_ad, ResourceCached::NOT_CACHED, 10); | 565 LoadResource(subframe_ad, ResourceCached::NOT_CACHED, 10); |
| 564 | 566 |
| 565 // Navigate again to trigger histograms. | 567 // Navigate again to trigger histograms. |
| 566 NavigateFrame(kNonAdUrl, main_frame); | 568 NavigateFrame(kNonAdUrl, main_frame); |
| 567 | 569 |
| 568 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, | 570 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, |
| 569 10 /* non_ad_uncached_kb */, AdType::GOOGLE); | 571 10 /* non_ad_uncached_kb */, AD_TYPE_GOOGLE); |
| 570 } | 572 } |
| 571 | 573 |
| 572 TEST_F(AdsPageLoadMetricsObserverTest, CountAbortedSecondNavigationForFrame) { | 574 TEST_F(AdsPageLoadMetricsObserverTest, CountAbortedSecondNavigationForFrame) { |
| 573 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 575 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 574 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); | 576 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
| 575 | 577 |
| 576 // Sub frame that is not an ad. | 578 // Sub frame that is not an ad. |
| 577 RenderFrameHost* sub_frame = | 579 RenderFrameHost* sub_frame = |
| 578 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); | 580 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
| 579 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); | 581 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); |
| 580 | 582 |
| 581 // Now navigate (and abort) the subframe to an ad. | 583 // Now navigate (and abort) the subframe to an ad. |
| 582 auto navigation_simulator = | 584 auto navigation_simulator = |
| 583 NavigationSimulator::CreateRendererInitiated(GURL(kAdUrl), sub_frame); | 585 NavigationSimulator::CreateRendererInitiated(GURL(kAdUrl), sub_frame); |
| 584 // The sub-frame renavigates before it commits. | 586 // The sub-frame renavigates before it commits. |
| 585 navigation_simulator->Start(); | 587 navigation_simulator->Start(); |
| 586 navigation_simulator->Fail(net::ERR_ABORTED); | 588 navigation_simulator->Fail(net::ERR_ABORTED); |
| 587 | 589 |
| 588 // Load resources for the aborted frame (e.g., simulate the navigation | 590 // Load resources for the aborted frame (e.g., simulate the navigation |
| 589 // aborting due to a doc.write during provisional navigation). Since the | 591 // aborting due to a doc.write during provisional navigation). Since the |
| 590 // frame attempted to load an ad, the frame is tagged forever as an ad. | 592 // frame attempted to load an ad, the frame is tagged forever as an ad. |
| 591 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); | 593 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); |
| 592 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); | 594 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); |
| 593 | 595 |
| 594 // Navigate again to trigger histograms. | 596 // Navigate again to trigger histograms. |
| 595 NavigateFrame(kNonAdUrl, main_frame); | 597 NavigateFrame(kNonAdUrl, main_frame); |
| 596 | 598 |
| 597 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, | 599 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, |
| 598 20 /* non_ad_uncached_kb */, AdType::GOOGLE); | 600 20 /* non_ad_uncached_kb */, AD_TYPE_GOOGLE); |
| 599 } | 601 } |
| 600 | 602 |
| 601 TEST_F(AdsPageLoadMetricsObserverTest, TwoResourceLoadsBeforeCommit) { | 603 TEST_F(AdsPageLoadMetricsObserverTest, TwoResourceLoadsBeforeCommit) { |
| 602 // Main frame. | 604 // Main frame. |
| 603 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 605 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 604 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); | 606 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
| 605 | 607 |
| 606 // Now open a subframe and have its resource load before notification of | 608 // Now open a subframe and have its resource load before notification of |
| 607 // navigation finishing. | 609 // navigation finishing. |
| 608 page_load_metrics::ExtraRequestCompleteInfo request( | 610 page_load_metrics::ExtraRequestCompleteInfo request( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 623 | 625 |
| 624 // Renavigate the subframe to a successful commit. But again, the resource | 626 // Renavigate the subframe to a successful commit. But again, the resource |
| 625 // loads before the observer sees the finished navigation. | 627 // loads before the observer sees the finished navigation. |
| 626 SimulateLoadedResource(request); | 628 SimulateLoadedResource(request); |
| 627 NavigateFrame(kNonAdUrl, subframe_ad); | 629 NavigateFrame(kNonAdUrl, subframe_ad); |
| 628 | 630 |
| 629 // Navigate again to trigger histograms. | 631 // Navigate again to trigger histograms. |
| 630 NavigateFrame(kNonAdUrl, main_frame); | 632 NavigateFrame(kNonAdUrl, main_frame); |
| 631 | 633 |
| 632 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, | 634 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, |
| 633 10 /* non_ad_uncached_kb */, AdType::GOOGLE); | 635 10 /* non_ad_uncached_kb */, AD_TYPE_GOOGLE); |
| 634 histogram_tester().ExpectBucketCount( | 636 histogram_tester().ExpectBucketCount( |
| 635 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); | 637 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); |
| 636 histogram_tester().ExpectUniqueSample( | 638 histogram_tester().ExpectUniqueSample( |
| 637 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", | 639 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", |
| 638 content::RESOURCE_TYPE_SUB_FRAME, 1); | 640 content::RESOURCE_TYPE_SUB_FRAME, 1); |
| 639 } | 641 } |
| 640 | 642 |
| 641 // This tests an issue that is believed to be the cause of | 643 // This tests an issue that is believed to be the cause of |
| 642 // https://crbug.com/721369. The issue is that a frame from a previous | 644 // https://crbug.com/721369. The issue is that a frame from a previous |
| 643 // navigation might commit during a new navigation, and the ads metrics won't | 645 // navigation might commit during a new navigation, and the ads metrics won't |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 | 734 |
| 733 // Force navigation to a new page to make sure OnComplete() runs for the | 735 // Force navigation to a new page to make sure OnComplete() runs for the |
| 734 // previous failed navigation. | 736 // previous failed navigation. |
| 735 NavigateToUntrackedUrl(); | 737 NavigateToUntrackedUrl(); |
| 736 | 738 |
| 737 // There shouldn't be any histograms for an aborted main frame. | 739 // There shouldn't be any histograms for an aborted main frame. |
| 738 EXPECT_EQ(0u, histogram_tester() | 740 EXPECT_EQ(0u, histogram_tester() |
| 739 .GetTotalCountsForPrefix("PageLoad.Clients.Ads.Google.") | 741 .GetTotalCountsForPrefix("PageLoad.Clients.Ads.Google.") |
| 740 .size()); | 742 .size()); |
| 741 } | 743 } |
| OLD | NEW |