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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 throttle_->Cancel(); | 117 throttle_->Cancel(); |
116 } | 118 } |
117 | 119 |
118 private: | 120 private: |
119 DelayWillProcessResponseThrottle* throttle_ = nullptr; | 121 DelayWillProcessResponseThrottle* throttle_ = nullptr; |
120 content::GlobalRequestID global_request_id_; | 122 content::GlobalRequestID global_request_id_; |
121 | 123 |
122 DISALLOW_COPY_AND_ASSIGN(DelayWillProcessResponseObserver); | 124 DISALLOW_COPY_AND_ASSIGN(DelayWillProcessResponseObserver); |
123 }; | 125 }; |
124 | 126 |
125 std::string AdTypeToString(AdType ad_type) { | 127 std::string AdTypeToString(page_load_metrics::AdType ad_type) { |
126 switch (ad_type) { | 128 switch (ad_type) { |
127 case AdType::GOOGLE: | 129 case page_load_metrics::AD_TYPE_GOOGLE: |
128 return "Google"; | 130 return "Google"; |
129 case AdType::SUBRESOURCE_FILTER: | 131 case page_load_metrics::AD_TYPE_SUBRESOURCE_FILTER: |
130 return "SubresourceFilter"; | 132 return "SubresourceFilter"; |
131 case AdType::ALL: | 133 case page_load_metrics::AD_TYPE_ALL: |
132 return "All"; | 134 return "All"; |
133 } | 135 } |
134 ADD_FAILURE(); | 136 ADD_FAILURE(); |
135 return ""; | 137 return ""; |
136 } | 138 } |
137 | 139 |
138 std::string TypedHistogram(const std::string& suffix, AdType ad_type) { | 140 std::string TypedHistogram(const std::string& suffix, |
| 141 page_load_metrics::AdType ad_type) { |
139 return base::StringPrintf("PageLoad.Clients.Ads.%s.%s", | 142 return base::StringPrintf("PageLoad.Clients.Ads.%s.%s", |
140 AdTypeToString(ad_type).c_str(), suffix.c_str()); | 143 AdTypeToString(ad_type).c_str(), suffix.c_str()); |
141 } | 144 } |
142 | 145 |
143 // Verifies that the histograms match what is expected given |google_ad_frames| | 146 // Verifies that the histograms match what is expected given |google_ad_frames| |
144 // ad frame byte counts and non-ad counts (|other_cached_kb| and | 147 // ad frame byte counts and non-ad counts (|other_cached_kb| and |
145 // |other_uncached_kb|). | 148 // |other_uncached_kb|). |
146 void TestHistograms(const base::HistogramTester& histograms, | 149 void TestHistograms(const base::HistogramTester& histograms, |
147 const std::vector<ExpectedFrameBytes>& google_ad_frames, | 150 const std::vector<ExpectedFrameBytes>& google_ad_frames, |
148 size_t non_ad_cached_kb, | 151 size_t non_ad_cached_kb, |
149 size_t non_ad_uncached_kb, | 152 size_t non_ad_uncached_kb, |
150 AdType ad_type) { | 153 page_load_metrics::AdType ad_type) { |
151 size_t total_ad_cached_kb = 0; | 154 size_t total_ad_cached_kb = 0; |
152 size_t total_ad_uncached_kb = 0; | 155 size_t total_ad_uncached_kb = 0; |
153 size_t total_ad_kb = 0; | 156 size_t total_ad_kb = 0; |
154 size_t ad_frame_count = 0; | 157 size_t ad_frame_count = 0; |
155 | 158 |
156 std::map<size_t, int> frames_with_total_byte_count; | 159 std::map<size_t, int> frames_with_total_byte_count; |
157 std::map<size_t, int> frames_with_network_byte_count; | 160 std::map<size_t, int> frames_with_network_byte_count; |
158 std::map<size_t, int> frames_with_percent_network_count; | 161 std::map<size_t, int> frames_with_percent_network_count; |
159 | 162 |
160 // Perform some initial calculations on the number of bytes, of each type, | 163 // Perform some initial calculations on the number of bytes, of each type, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); | 346 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
344 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); | 347 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
345 LoadResource(frame1, ResourceCached::NOT_CACHED, 10); | 348 LoadResource(frame1, ResourceCached::NOT_CACHED, 10); |
346 LoadResource(frame2, ResourceCached::NOT_CACHED, 10); | 349 LoadResource(frame2, ResourceCached::NOT_CACHED, 10); |
347 | 350 |
348 // Navigate again to trigger histograms. | 351 // Navigate again to trigger histograms. |
349 NavigateFrame(kNonAdUrl, main_frame); | 352 NavigateFrame(kNonAdUrl, main_frame); |
350 | 353 |
351 TestHistograms(histogram_tester(), std::vector<ExpectedFrameBytes>(), | 354 TestHistograms(histogram_tester(), std::vector<ExpectedFrameBytes>(), |
352 0 /* non_ad_cached_kb */, 30 /* non_ad_uncached_kb */, | 355 0 /* non_ad_cached_kb */, 30 /* non_ad_uncached_kb */, |
353 AdType::GOOGLE); | 356 page_load_metrics::AD_TYPE_GOOGLE); |
354 | 357 |
355 // Verify that other UMA wasn't written. | 358 // Verify that other UMA wasn't written. |
356 histogram_tester().ExpectTotalCount( | 359 histogram_tester().ExpectTotalCount( |
357 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", 0); | 360 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", 0); |
358 } | 361 } |
359 | 362 |
360 TEST_F(AdsPageLoadMetricsObserverTest, ResourceBeforeAdFrameCommits) { | 363 TEST_F(AdsPageLoadMetricsObserverTest, ResourceBeforeAdFrameCommits) { |
361 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 364 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
362 | 365 |
363 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); | 366 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
364 | 367 |
365 // Assume that the next frame's id will be the main frame + 1 and load a | 368 // Assume that the next frame's id will be the main frame + 1 and load a |
366 // resource for that frame. Make sure it gets counted. | 369 // resource for that frame. Make sure it gets counted. |
367 page_load_metrics::ExtraRequestCompleteInfo request( | 370 page_load_metrics::ExtraRequestCompleteInfo request( |
368 GURL(kNonAdUrl), net::HostPortPair(), | 371 GURL(kNonAdUrl), net::HostPortPair(), |
369 main_frame->GetFrameTreeNodeId() + 1, false /* cached */, | 372 main_frame->GetFrameTreeNodeId() + 1, false /* cached */, |
370 10 * 1024 /* size */, 0 /* original_network_content_length */, | 373 10 * 1024 /* size */, 0 /* original_network_content_length */, |
371 nullptr | 374 nullptr |
372 /* data_reduction_proxy_data */, | 375 /* data_reduction_proxy_data */, |
373 content::RESOURCE_TYPE_SUB_FRAME, 0); | 376 content::RESOURCE_TYPE_SUB_FRAME, 0); |
374 SimulateLoadedResource(request); | 377 SimulateLoadedResource(request); |
375 | 378 |
376 CreateAndNavigateSubFrame(kNonAdUrl, kAdName, main_frame); | 379 CreateAndNavigateSubFrame(kNonAdUrl, kAdName, main_frame); |
377 | 380 |
378 // Navigate again to trigger histograms. | 381 // Navigate again to trigger histograms. |
379 NavigateFrame(kNonAdUrl, main_frame); | 382 NavigateFrame(kNonAdUrl, main_frame); |
380 | 383 |
381 TestHistograms(histogram_tester(), {{0, 10}}, 0 /* non_ad_cached_kb */, | 384 TestHistograms(histogram_tester(), {{0, 10}}, 0 /* non_ad_cached_kb */, |
382 10 /*non_ad_uncached_kb*/, AdType::GOOGLE); | 385 10 /*non_ad_uncached_kb*/, page_load_metrics::AD_TYPE_GOOGLE); |
383 } | 386 } |
384 | 387 |
385 TEST_F(AdsPageLoadMetricsObserverTest, AllAdTypesInPage) { | 388 TEST_F(AdsPageLoadMetricsObserverTest, AllAdTypesInPage) { |
386 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 389 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
387 RenderFrameHost* non_ad_frame = | 390 RenderFrameHost* non_ad_frame = |
388 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); | 391 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
389 | 392 |
390 // Create 5 ad frames with the 5th nested inside the 4th. Verify that the | 393 // Create 5 ad frames with the 5th nested inside the 4th. Verify that the |
391 // nested ad frame doesn't get counted separately (but that its bytes are | 394 // nested ad frame doesn't get counted separately (but that its bytes are |
392 // still counted). Also verify that the various ad signals (urls and names) | 395 // still counted). Also verify that the various ad signals (urls and names) |
(...skipping 28 matching lines...) Expand all Loading... |
421 LoadResource(srf_frame1, ResourceCached::NOT_CACHED, 10); | 424 LoadResource(srf_frame1, ResourceCached::NOT_CACHED, 10); |
422 LoadResource(srf_frame2, ResourceCached::NOT_CACHED, 10); | 425 LoadResource(srf_frame2, ResourceCached::NOT_CACHED, 10); |
423 LoadResource(nested_srf_frame3, ResourceCached::CACHED, 10); | 426 LoadResource(nested_srf_frame3, ResourceCached::CACHED, 10); |
424 LoadResource(disallowed_srf_frame, ResourceCached::CACHED, 10); | 427 LoadResource(disallowed_srf_frame, ResourceCached::CACHED, 10); |
425 | 428 |
426 // Navigate again to trigger histograms. | 429 // Navigate again to trigger histograms. |
427 NavigateFrame(kNonAdUrl, main_frame); | 430 NavigateFrame(kNonAdUrl, main_frame); |
428 | 431 |
429 TestHistograms(histogram_tester(), {{10, 0}, {0, 10}}, | 432 TestHistograms(histogram_tester(), {{10, 0}, {0, 10}}, |
430 30 /* non_ad_cached_kb */, 30 /* non_ad_uncached_kb */, | 433 30 /* non_ad_cached_kb */, 30 /* non_ad_uncached_kb */, |
431 AdType::GOOGLE); | 434 page_load_metrics::AD_TYPE_GOOGLE); |
432 TestHistograms(histogram_tester(), {{0, 10}, {10, 10}}, | 435 TestHistograms(histogram_tester(), {{0, 10}, {10, 10}}, |
433 30 /* non_ad_cached_kb */, 20 /* non_ad_uncached_kb */, | 436 30 /* non_ad_cached_kb */, 20 /* non_ad_uncached_kb */, |
434 AdType::SUBRESOURCE_FILTER); | 437 page_load_metrics::AD_TYPE_SUBRESOURCE_FILTER); |
435 TestHistograms(histogram_tester(), {{10, 0}, {0, 10}, {0, 10}, {10, 10}}, | 438 TestHistograms(histogram_tester(), {{10, 0}, {0, 10}, {0, 10}, {10, 10}}, |
436 20 /* non_ad_cached_kb */, 10 /* non_ad_uncached_kb */, | 439 20 /* non_ad_cached_kb */, 10 /* non_ad_uncached_kb */, |
437 AdType::ALL); | 440 page_load_metrics::AD_TYPE_ALL); |
438 histogram_tester().ExpectBucketCount( | 441 histogram_tester().ExpectBucketCount( |
439 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); | 442 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); |
440 histogram_tester().ExpectTotalCount( | 443 histogram_tester().ExpectTotalCount( |
441 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); | 444 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); |
442 } | 445 } |
443 | 446 |
444 TEST_F(AdsPageLoadMetricsObserverTest, PageLoadSubFrameRenavigationMetrics) { | 447 TEST_F(AdsPageLoadMetricsObserverTest, PageLoadSubFrameRenavigationMetrics) { |
445 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 448 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
446 | 449 |
447 // Test behavior of an ad frame. Once a frame is considered an ad, it's | 450 // 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... |
490 // Navigate the ad frame again. | 493 // Navigate the ad frame again. |
491 ad_frame = NavigateFrame(kNonAdUrl, ad_frame); | 494 ad_frame = NavigateFrame(kNonAdUrl, ad_frame); |
492 | 495 |
493 // In total, 30KB for entire page and 20 in one ad frame. | 496 // In total, 30KB for entire page and 20 in one ad frame. |
494 LoadResource(ad_frame, ResourceCached::NOT_CACHED, 10); | 497 LoadResource(ad_frame, ResourceCached::NOT_CACHED, 10); |
495 | 498 |
496 // Navigate again to trigger histograms. | 499 // Navigate again to trigger histograms. |
497 NavigateFrame(kNonAdUrl, main_frame); | 500 NavigateFrame(kNonAdUrl, main_frame); |
498 | 501 |
499 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, | 502 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, |
500 10 /* non_ad_uncached_kb */, AdType::GOOGLE); | 503 10 /* non_ad_uncached_kb */, |
| 504 page_load_metrics::AD_TYPE_GOOGLE); |
501 histogram_tester().ExpectBucketCount( | 505 histogram_tester().ExpectBucketCount( |
502 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); | 506 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); |
503 histogram_tester().ExpectTotalCount( | 507 histogram_tester().ExpectTotalCount( |
504 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); | 508 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); |
505 } | 509 } |
506 | 510 |
507 TEST_F(AdsPageLoadMetricsObserverTest, PageWithNonAdFrameThatRenavigatesToAd) { | 511 TEST_F(AdsPageLoadMetricsObserverTest, PageWithNonAdFrameThatRenavigatesToAd) { |
508 // Main frame. | 512 // Main frame. |
509 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 513 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
510 | 514 |
(...skipping 15 matching lines...) Expand all Loading... |
526 | 530 |
527 // 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 |
528 // frames (the original child ad frame and the renavigated frame which | 532 // frames (the original child ad frame and the renavigated frame which |
529 // turned into an ad). | 533 // turned into an ad). |
530 | 534 |
531 // Navigate again to trigger histograms. | 535 // Navigate again to trigger histograms. |
532 NavigateFrame(kNonAdUrl, main_frame); | 536 NavigateFrame(kNonAdUrl, main_frame); |
533 | 537 |
534 TestHistograms(histogram_tester(), {{0, 10}, {0, 10}}, | 538 TestHistograms(histogram_tester(), {{0, 10}, {0, 10}}, |
535 0 /* non_ad_cached_kb */, 20 /* non_ad_uncached_kb */, | 539 0 /* non_ad_cached_kb */, 20 /* non_ad_uncached_kb */, |
536 AdType::GOOGLE); | 540 page_load_metrics::AD_TYPE_GOOGLE); |
537 histogram_tester().ExpectBucketCount( | 541 histogram_tester().ExpectBucketCount( |
538 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); | 542 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); |
539 histogram_tester().ExpectTotalCount( | 543 histogram_tester().ExpectTotalCount( |
540 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); | 544 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", 0); |
541 } | 545 } |
542 | 546 |
543 TEST_F(AdsPageLoadMetricsObserverTest, CountAbortedNavigation) { | 547 TEST_F(AdsPageLoadMetricsObserverTest, CountAbortedNavigation) { |
544 // 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. |
545 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 549 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
546 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); | 550 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
(...skipping 10 matching lines...) Expand all Loading... |
557 // Load resources for the aborted frame (e.g., simulate the navigation | 561 // Load resources for the aborted frame (e.g., simulate the navigation |
558 // aborting due to a doc.write during provisional navigation). They should | 562 // aborting due to a doc.write during provisional navigation). They should |
559 // be counted. | 563 // be counted. |
560 LoadResource(subframe_ad, ResourceCached::NOT_CACHED, 10); | 564 LoadResource(subframe_ad, ResourceCached::NOT_CACHED, 10); |
561 LoadResource(subframe_ad, ResourceCached::NOT_CACHED, 10); | 565 LoadResource(subframe_ad, ResourceCached::NOT_CACHED, 10); |
562 | 566 |
563 // Navigate again to trigger histograms. | 567 // Navigate again to trigger histograms. |
564 NavigateFrame(kNonAdUrl, main_frame); | 568 NavigateFrame(kNonAdUrl, main_frame); |
565 | 569 |
566 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, | 570 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, |
567 10 /* non_ad_uncached_kb */, AdType::GOOGLE); | 571 10 /* non_ad_uncached_kb */, |
| 572 page_load_metrics::AD_TYPE_GOOGLE); |
568 } | 573 } |
569 | 574 |
570 TEST_F(AdsPageLoadMetricsObserverTest, CountAbortedSecondNavigationForFrame) { | 575 TEST_F(AdsPageLoadMetricsObserverTest, CountAbortedSecondNavigationForFrame) { |
571 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 576 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
572 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); | 577 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
573 | 578 |
574 // Sub frame that is not an ad. | 579 // Sub frame that is not an ad. |
575 RenderFrameHost* sub_frame = | 580 RenderFrameHost* sub_frame = |
576 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); | 581 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
577 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); | 582 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); |
578 | 583 |
579 // Now navigate (and abort) the subframe to an ad. | 584 // Now navigate (and abort) the subframe to an ad. |
580 auto navigation_simulator = | 585 auto navigation_simulator = |
581 NavigationSimulator::CreateRendererInitiated(GURL(kAdUrl), sub_frame); | 586 NavigationSimulator::CreateRendererInitiated(GURL(kAdUrl), sub_frame); |
582 // The sub-frame renavigates before it commits. | 587 // The sub-frame renavigates before it commits. |
583 navigation_simulator->Start(); | 588 navigation_simulator->Start(); |
584 navigation_simulator->Fail(net::ERR_ABORTED); | 589 navigation_simulator->Fail(net::ERR_ABORTED); |
585 | 590 |
586 // Load resources for the aborted frame (e.g., simulate the navigation | 591 // Load resources for the aborted frame (e.g., simulate the navigation |
587 // aborting due to a doc.write during provisional navigation). Since the | 592 // aborting due to a doc.write during provisional navigation). Since the |
588 // frame attempted to load an ad, the frame is tagged forever as an ad. | 593 // frame attempted to load an ad, the frame is tagged forever as an ad. |
589 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); | 594 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); |
590 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); | 595 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); |
591 | 596 |
592 // Navigate again to trigger histograms. | 597 // Navigate again to trigger histograms. |
593 NavigateFrame(kNonAdUrl, main_frame); | 598 NavigateFrame(kNonAdUrl, main_frame); |
594 | 599 |
595 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, | 600 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, |
596 20 /* non_ad_uncached_kb */, AdType::GOOGLE); | 601 20 /* non_ad_uncached_kb */, |
| 602 page_load_metrics::AD_TYPE_GOOGLE); |
597 } | 603 } |
598 | 604 |
599 TEST_F(AdsPageLoadMetricsObserverTest, TwoResourceLoadsBeforeCommit) { | 605 TEST_F(AdsPageLoadMetricsObserverTest, TwoResourceLoadsBeforeCommit) { |
600 // Main frame. | 606 // Main frame. |
601 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); | 607 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
602 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); | 608 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
603 | 609 |
604 // Now open a subframe and have its resource load before notification of | 610 // Now open a subframe and have its resource load before notification of |
605 // navigation finishing. | 611 // navigation finishing. |
606 page_load_metrics::ExtraRequestCompleteInfo request( | 612 page_load_metrics::ExtraRequestCompleteInfo request( |
(...skipping 14 matching lines...) Expand all Loading... |
621 | 627 |
622 // Renavigate the subframe to a successful commit. But again, the resource | 628 // Renavigate the subframe to a successful commit. But again, the resource |
623 // loads before the observer sees the finished navigation. | 629 // loads before the observer sees the finished navigation. |
624 SimulateLoadedResource(request); | 630 SimulateLoadedResource(request); |
625 NavigateFrame(kNonAdUrl, subframe_ad); | 631 NavigateFrame(kNonAdUrl, subframe_ad); |
626 | 632 |
627 // Navigate again to trigger histograms. | 633 // Navigate again to trigger histograms. |
628 NavigateFrame(kNonAdUrl, main_frame); | 634 NavigateFrame(kNonAdUrl, main_frame); |
629 | 635 |
630 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, | 636 TestHistograms(histogram_tester(), {{0, 20}}, 0 /* non_ad_cached_kb */, |
631 10 /* non_ad_uncached_kb */, AdType::GOOGLE); | 637 10 /* non_ad_uncached_kb */, |
| 638 page_load_metrics::AD_TYPE_GOOGLE); |
632 histogram_tester().ExpectBucketCount( | 639 histogram_tester().ExpectBucketCount( |
633 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); | 640 "PageLoad.Clients.Ads.All.ParentExistsForSubFrame", 0, 0); |
634 histogram_tester().ExpectUniqueSample( | 641 histogram_tester().ExpectUniqueSample( |
635 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", | 642 "PageLoad.Clients.Ads.All.ResourceTypeWhenNoFrameFound", |
636 content::RESOURCE_TYPE_SUB_FRAME, 1); | 643 content::RESOURCE_TYPE_SUB_FRAME, 1); |
637 } | 644 } |
638 | 645 |
639 // This tests an issue that is believed to be the cause of | 646 // This tests an issue that is believed to be the cause of |
640 // https://crbug.com/721369. The issue is that a frame from a previous | 647 // https://crbug.com/721369. The issue is that a frame from a previous |
641 // navigation might commit during a new navigation, and the ads metrics won't | 648 // 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... |
730 | 737 |
731 // Force navigation to a new page to make sure OnComplete() runs for the | 738 // Force navigation to a new page to make sure OnComplete() runs for the |
732 // previous failed navigation. | 739 // previous failed navigation. |
733 NavigateToUntrackedUrl(); | 740 NavigateToUntrackedUrl(); |
734 | 741 |
735 // There shouldn't be any histograms for an aborted main frame. | 742 // There shouldn't be any histograms for an aborted main frame. |
736 EXPECT_EQ(0u, histogram_tester() | 743 EXPECT_EQ(0u, histogram_tester() |
737 .GetTotalCountsForPrefix("PageLoad.Clients.Ads.Google.") | 744 .GetTotalCountsForPrefix("PageLoad.Clients.Ads.Google.") |
738 .size()); | 745 .size()); |
739 } | 746 } |
OLD | NEW |