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 | 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 0, | 234 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 0, |
235 1); | 235 1); |
236 histogram_tester().ExpectBucketCount( | 236 histogram_tester().ExpectBucketCount( |
237 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 100, | 237 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 100, |
238 2); | 238 2); |
239 histogram_tester().ExpectBucketCount( | 239 histogram_tester().ExpectBucketCount( |
240 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 50, | 240 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 50, |
241 1); | 241 1); |
242 | 242 |
243 // Counts | 243 // Counts |
| 244 histogram_tester().ExpectBucketCount( |
| 245 "PageLoad.Clients.Ads.Google.ParentExistsForSubFrame", 0, 0); |
| 246 histogram_tester().ExpectTotalCount( |
| 247 "PageLoad.Clients.Ads.Google.ResourceTypeWhenNoFrameFound", 0); |
244 histogram_tester().ExpectUniqueSample( | 248 histogram_tester().ExpectUniqueSample( |
245 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 4, 1); | 249 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 4, 1); |
246 | 250 |
247 // Page percentages | 251 // Page percentages |
248 histogram_tester().ExpectUniqueSample( | 252 histogram_tester().ExpectUniqueSample( |
249 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total.PercentAds", 71, 1); | 253 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total.PercentAds", 71, 1); |
250 histogram_tester().ExpectUniqueSample( | 254 histogram_tester().ExpectUniqueSample( |
251 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.PercentNetwork", 60, | 255 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.PercentNetwork", 60, |
252 1); | 256 1); |
253 histogram_tester().ExpectUniqueSample( | 257 histogram_tester().ExpectUniqueSample( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 // Individual Ad Frame Metrics | 328 // Individual Ad Frame Metrics |
325 histogram_tester().ExpectUniqueSample( | 329 histogram_tester().ExpectUniqueSample( |
326 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Total", 20, 1); | 330 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Total", 20, 1); |
327 histogram_tester().ExpectUniqueSample( | 331 histogram_tester().ExpectUniqueSample( |
328 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Network", 20, 1); | 332 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Network", 20, 1); |
329 histogram_tester().ExpectUniqueSample( | 333 histogram_tester().ExpectUniqueSample( |
330 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 100, | 334 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 100, |
331 1); | 335 1); |
332 | 336 |
333 // Counts | 337 // Counts |
| 338 histogram_tester().ExpectBucketCount( |
| 339 "PageLoad.Clients.Ads.Google.ParentExistsForSubFrame", 0, 0); |
| 340 histogram_tester().ExpectTotalCount( |
| 341 "PageLoad.Clients.Ads.Google.ResourceTypeWhenNoFrameFound", 0); |
334 histogram_tester().ExpectUniqueSample( | 342 histogram_tester().ExpectUniqueSample( |
335 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1); | 343 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1); |
336 | 344 |
337 // Page percentages | 345 // Page percentages |
338 histogram_tester().ExpectUniqueSample( | 346 histogram_tester().ExpectUniqueSample( |
339 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total.PercentAds", 66, 1); | 347 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total.PercentAds", 66, 1); |
340 histogram_tester().ExpectUniqueSample( | 348 histogram_tester().ExpectUniqueSample( |
341 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.PercentNetwork", | 349 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.PercentNetwork", |
342 100, 1); | 350 100, 1); |
343 histogram_tester().ExpectUniqueSample( | 351 histogram_tester().ExpectUniqueSample( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 // Individual Ad Frame Metrics | 394 // Individual Ad Frame Metrics |
387 histogram_tester().ExpectUniqueSample( | 395 histogram_tester().ExpectUniqueSample( |
388 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Total", 10, 2); | 396 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Total", 10, 2); |
389 histogram_tester().ExpectUniqueSample( | 397 histogram_tester().ExpectUniqueSample( |
390 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Network", 10, 2); | 398 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Network", 10, 2); |
391 histogram_tester().ExpectUniqueSample( | 399 histogram_tester().ExpectUniqueSample( |
392 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 100, | 400 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 100, |
393 2); | 401 2); |
394 | 402 |
395 // Counts | 403 // Counts |
| 404 histogram_tester().ExpectBucketCount( |
| 405 "PageLoad.Clients.Ads.Google.ParentExistsForSubFrame", 0, 0); |
| 406 histogram_tester().ExpectTotalCount( |
| 407 "PageLoad.Clients.Ads.Google.ResourceTypeWhenNoFrameFound", 0); |
396 histogram_tester().ExpectUniqueSample( | 408 histogram_tester().ExpectUniqueSample( |
397 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 2, 1); | 409 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 2, 1); |
398 | 410 |
399 // Page percentages | 411 // Page percentages |
400 histogram_tester().ExpectUniqueSample( | 412 histogram_tester().ExpectUniqueSample( |
401 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total.PercentAds", 50, 1); | 413 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total.PercentAds", 50, 1); |
402 histogram_tester().ExpectUniqueSample( | 414 histogram_tester().ExpectUniqueSample( |
403 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.PercentNetwork", | 415 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.PercentNetwork", |
404 100, 1); | 416 100, 1); |
405 histogram_tester().ExpectUniqueSample( | 417 histogram_tester().ExpectUniqueSample( |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 // Individual Ad Frame Metrics | 531 // Individual Ad Frame Metrics |
520 histogram_tester().ExpectUniqueSample( | 532 histogram_tester().ExpectUniqueSample( |
521 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Total", 20, 1); | 533 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Total", 20, 1); |
522 histogram_tester().ExpectUniqueSample( | 534 histogram_tester().ExpectUniqueSample( |
523 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Network", 20, 1); | 535 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Network", 20, 1); |
524 histogram_tester().ExpectUniqueSample( | 536 histogram_tester().ExpectUniqueSample( |
525 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 100, | 537 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", 100, |
526 1); | 538 1); |
527 | 539 |
528 // Counts | 540 // Counts |
| 541 histogram_tester().ExpectBucketCount( |
| 542 "PageLoad.Clients.Ads.Google.ParentExistsForSubFrame", 0, 0); |
| 543 histogram_tester().ExpectUniqueSample( |
| 544 "PageLoad.Clients.Ads.Google.ResourceTypeWhenNoFrameFound", |
| 545 content::RESOURCE_TYPE_SUB_FRAME, 1); |
529 histogram_tester().ExpectUniqueSample( | 546 histogram_tester().ExpectUniqueSample( |
530 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1); | 547 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", 1, 1); |
531 | 548 |
532 // Page percentages | 549 // Page percentages |
533 histogram_tester().ExpectUniqueSample( | 550 histogram_tester().ExpectUniqueSample( |
534 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total.PercentAds", 66, 1); | 551 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total.PercentAds", 66, 1); |
535 histogram_tester().ExpectUniqueSample( | 552 histogram_tester().ExpectUniqueSample( |
536 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.PercentNetwork", | 553 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.PercentNetwork", |
537 100, 1); | 554 100, 1); |
538 histogram_tester().ExpectUniqueSample( | 555 histogram_tester().ExpectUniqueSample( |
539 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Network.PercentAds", 66, 1); | 556 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Network.PercentAds", 66, 1); |
540 | 557 |
541 // Page byte counts | 558 // Page byte counts |
542 histogram_tester().ExpectUniqueSample( | 559 histogram_tester().ExpectUniqueSample( |
543 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", 20, 1); | 560 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Total", 20, 1); |
544 histogram_tester().ExpectUniqueSample( | 561 histogram_tester().ExpectUniqueSample( |
545 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Network", 20, 1); | 562 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.Aggregate.Network", 20, 1); |
546 histogram_tester().ExpectUniqueSample( | 563 histogram_tester().ExpectUniqueSample( |
547 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total", 30, 1); | 564 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Total", 30, 1); |
548 histogram_tester().ExpectUniqueSample( | 565 histogram_tester().ExpectUniqueSample( |
549 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Network", 30, 1); | 566 "PageLoad.Clients.Ads.Google.Bytes.FullPage.Network", 30, 1); |
550 histogram_tester().ExpectUniqueSample( | 567 histogram_tester().ExpectUniqueSample( |
551 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Aggregate.Total", 10, 1); | 568 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Aggregate.Total", 10, 1); |
552 } | 569 } |
| 570 |
| 571 // This tests an issue that is believed to be the cause of |
| 572 // https://crbug.com/721369. The issue is that a frame from a previous |
| 573 // navigation might commit during a new navigation, and the ads metrics won't |
| 574 // know about the frame's parent (because it doesn't exist in the page). |
| 575 TEST_F(AdsPageLoadMetricsObserverTest, FrameWithNoParent) { |
| 576 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 577 RenderFrameHost* sub_frame = |
| 578 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
| 579 |
| 580 histogram_tester().ExpectBucketCount( |
| 581 "PageLoad.Clients.Ads.Google.ParentExistsForSubFrame", 0, 0); |
| 582 |
| 583 // Renavigate the child, but, while navigating, the main frame renavigates. |
| 584 RenderFrameHost* child_of_subframe = |
| 585 RenderFrameHostTester::For(sub_frame)->AppendChild(kAdName); |
| 586 auto navigation_simulator = NavigationSimulator::CreateRendererInitiated( |
| 587 GURL(kNonAdUrl2), child_of_subframe); |
| 588 navigation_simulator->Start(); |
| 589 |
| 590 // Main frame renavigates. |
| 591 NavigateMainFrame(kNonAdUrl); |
| 592 |
| 593 // Child frame commits. |
| 594 navigation_simulator->Commit(); |
| 595 child_of_subframe = navigation_simulator->GetFinalRenderFrameHost(); |
| 596 histogram_tester().ExpectBucketCount( |
| 597 "PageLoad.Clients.Ads.Google.ParentExistsForSubFrame", 0, 1); |
| 598 |
| 599 // Test that a resource loaded into an unknown frame doesn't cause any |
| 600 // issues. |
| 601 histogram_tester().ExpectTotalCount( |
| 602 "PageLoad.Clients.Ads.Google.ResourceTypeWhenNoFrameFound", 0); |
| 603 LoadResource(child_of_subframe, ResourceCached::NOT_CACHED, 10); |
| 604 histogram_tester().ExpectBucketCount( |
| 605 "PageLoad.Clients.Ads.Google.ResourceTypeWhenNoFrameFound", |
| 606 content::RESOURCE_TYPE_SUB_FRAME, 1); |
| 607 } |
OLD | NEW |