OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/page_load_metrics/observers/ads_page_load_metrics_obser
ver.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/macros.h" |
| 10 #include "base/test/histogram_tester.h" |
| 11 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_
test_harness.h" |
| 12 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" |
| 13 #include "chrome/browser/page_load_metrics/page_load_tracker.h" |
| 14 #include "content/public/browser/render_frame_host.h" |
| 15 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/test/navigation_simulator.h" |
| 17 #include "content/public/test/test_renderer_host.h" |
| 18 #include "url/gurl.h" |
| 19 |
| 20 using content::RenderFrameHost; |
| 21 using content::RenderFrameHostTester; |
| 22 using content::NavigationSimulator; |
| 23 |
| 24 namespace { |
| 25 |
| 26 enum class ResourceCached { NOT_CACHED, CACHED }; |
| 27 enum class FrameType { AD = 0, NON_AD }; |
| 28 |
| 29 const char kAdUrl[] = "https://tpc.googlesyndication.com/safeframe/1"; |
| 30 const char kNonAdUrl[] = "https://foo.com/"; |
| 31 const char kNonAdUrl2[] = "https://bar.com/"; |
| 32 |
| 33 const char kAdName[] = "google_ads_iframe_1"; |
| 34 const char kNonAdName[] = "foo"; |
| 35 |
| 36 } // namespace |
| 37 |
| 38 class AdsPageLoadMetricsObserverTest |
| 39 : public page_load_metrics::PageLoadMetricsObserverTestHarness { |
| 40 public: |
| 41 AdsPageLoadMetricsObserverTest() {} |
| 42 |
| 43 // Returns the final RenderFrameHost after navigation commits. |
| 44 RenderFrameHost* NavigateFrame(const std::string& url, |
| 45 content::RenderFrameHost* frame) { |
| 46 auto navigation_simulator = |
| 47 NavigationSimulator::CreateRendererInitiated(GURL(url), frame); |
| 48 navigation_simulator->Commit(); |
| 49 return navigation_simulator->GetFinalRenderFrameHost(); |
| 50 } |
| 51 |
| 52 // Returns the final RenderFrameHost after navigation commits. |
| 53 RenderFrameHost* NavigateMainFrame(const std::string& url) { |
| 54 return NavigateFrame(url, web_contents()->GetMainFrame()); |
| 55 } |
| 56 |
| 57 // Returns the final RenderFrameHost after navigation commits. |
| 58 RenderFrameHost* CreateAndNavigateSubFrame(const std::string& url, |
| 59 const std::string& frame_name, |
| 60 content::RenderFrameHost* parent) { |
| 61 RenderFrameHost* subframe = |
| 62 RenderFrameHostTester::For(parent)->AppendChild(frame_name); |
| 63 auto navigation_simulator = |
| 64 NavigationSimulator::CreateRendererInitiated(GURL(url), subframe); |
| 65 navigation_simulator->Commit(); |
| 66 return navigation_simulator->GetFinalRenderFrameHost(); |
| 67 } |
| 68 |
| 69 RenderFrameHost* NavigateFrameAndTestRenavigationMetrics( |
| 70 RenderFrameHost* frame, |
| 71 FrameType frame_type, |
| 72 const std::string& url) { |
| 73 base::HistogramTester tester; |
| 74 RenderFrameHost* out_frame = NavigateFrame(url, frame); |
| 75 |
| 76 int bucket = url == kAdUrl ? 1 : 0; |
| 77 |
| 78 if (frame_type == FrameType::AD) { |
| 79 tester.ExpectUniqueSample( |
| 80 "PageLoad.Clients.Ads.Google.AdFrameRenavigatedToAd", bucket, 1); |
| 81 } else { |
| 82 tester.ExpectUniqueSample( |
| 83 "PageLoad.Clients.Ads.Google.NonAdFrameRenavigatedToAd", bucket, 1); |
| 84 } |
| 85 |
| 86 return out_frame; |
| 87 } |
| 88 |
| 89 void LoadResource(RenderFrameHost* frame, |
| 90 ResourceCached resource_cached, |
| 91 int resource_size_in_kb) { |
| 92 page_load_metrics::ExtraRequestInfo request( |
| 93 GURL(kNonAdUrl), frame->GetFrameTreeNodeId(), |
| 94 resource_cached == ResourceCached::CACHED, resource_size_in_kb * 1024, |
| 95 false /* data_reduction_proxy_used */, |
| 96 0 /* original_network_content_length */); |
| 97 SimulateLoadedResource(request); |
| 98 } |
| 99 |
| 100 protected: |
| 101 void RegisterObservers(page_load_metrics::PageLoadTracker* tracker) override { |
| 102 tracker->AddObserver(base::MakeUnique<AdsPageLoadMetricsObserver>()); |
| 103 } |
| 104 |
| 105 private: |
| 106 DISALLOW_COPY_AND_ASSIGN(AdsPageLoadMetricsObserverTest); |
| 107 }; |
| 108 |
| 109 TEST_F(AdsPageLoadMetricsObserverTest, PageWithNoAds) { |
| 110 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 111 RenderFrameHost* frame1 = |
| 112 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
| 113 RenderFrameHost* frame2 = |
| 114 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
| 115 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
| 116 LoadResource(frame1, ResourceCached::NOT_CACHED, 10); |
| 117 LoadResource(frame2, ResourceCached::NOT_CACHED, 10); |
| 118 |
| 119 // Navigate again to trigger histograms. |
| 120 NavigateFrame(kNonAdUrl, main_frame); |
| 121 |
| 122 histogram_tester().ExpectUniqueSample( |
| 123 "PageLoad.Clients.Ads.Google.AdFrameCount", 0, 1); |
| 124 histogram_tester().ExpectTotalCount( |
| 125 "PageLoad.Clients.Ads.Google.Bytes.AllAdFrames.Total", 0); |
| 126 } |
| 127 |
| 128 TEST_F(AdsPageLoadMetricsObserverTest, ResourceBeforeAdFrameCommits) { |
| 129 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 130 |
| 131 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
| 132 |
| 133 // Assume that the next frame's id will be the main frame + 1 and load a |
| 134 // resource for that frame. Make sure it gets counted. |
| 135 page_load_metrics::ExtraRequestInfo request( |
| 136 GURL(kNonAdUrl), main_frame->GetFrameTreeNodeId() + 1, false /* cached */, |
| 137 10 * 1024 /* size */, false /* data_reduction_proxy_used */, |
| 138 0 /* original_network_content_length */); |
| 139 SimulateLoadedResource(request); |
| 140 |
| 141 CreateAndNavigateSubFrame(kNonAdUrl, kAdName, main_frame); |
| 142 |
| 143 // Navigate again to trigger histograms. |
| 144 NavigateFrame(kNonAdUrl, main_frame); |
| 145 |
| 146 // 20KB total were loaded from network, one of which was in an ad frame. |
| 147 histogram_tester().ExpectUniqueSample( |
| 148 "PageLoad.Clients.Ads.Google.AdFrameCount", 1, 1); |
| 149 histogram_tester().ExpectUniqueSample( |
| 150 "PageLoad.Clients.Ads.Google.SubFrameCount.TopLevel", 1, 1); |
| 151 histogram_tester().ExpectUniqueSample( |
| 152 "PageLoad.Clients.Ads.Google.AdFrameCount.TopLevel", 1, 1); |
| 153 histogram_tester().ExpectUniqueSample( |
| 154 "PageLoad.Clients.Ads.Google.PercentSubFramesAreAdFrames.TopLevel", 100, |
| 155 1); |
| 156 |
| 157 // Individual Ad Frame Metrics |
| 158 histogram_tester().ExpectUniqueSample( |
| 159 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Total", 10, 1); |
| 160 histogram_tester().ExpectUniqueSample( |
| 161 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Network", 10, 1); |
| 162 histogram_tester().ExpectUniqueSample( |
| 163 "PageLoad.Clients.Ads.Google.Bytes.PercentAdFrame.Network", 100, 1); |
| 164 |
| 165 // Page percentages |
| 166 histogram_tester().ExpectUniqueSample( |
| 167 "PageLoad.Clients.Ads.Google.Bytes.PercentPage.AllAdFrames.Total", 50, 1); |
| 168 histogram_tester().ExpectUniqueSample( |
| 169 "PageLoad.Clients.Ads.Google.Bytes.PercentAllAdFrames.Network", 100, 1); |
| 170 histogram_tester().ExpectUniqueSample( |
| 171 "PageLoad.Clients.Ads.Google.Bytes." |
| 172 "PercentPage.AllAdFrames.Network", |
| 173 50, 1); |
| 174 |
| 175 // Page byte counts |
| 176 histogram_tester().ExpectUniqueSample( |
| 177 "PageLoad.Clients.Ads.Google.Bytes.AllAdFrames.Total", 10, 1); |
| 178 histogram_tester().ExpectUniqueSample( |
| 179 "PageLoad.Clients.Ads.Google.Bytes.AllAdFrames.Network", 10, 1); |
| 180 histogram_tester().ExpectUniqueSample( |
| 181 "PageLoad.Clients.Ads.Google.Bytes.Total", 20, 1); |
| 182 histogram_tester().ExpectUniqueSample( |
| 183 "PageLoad.Clients.Ads.Google.Bytes.Network", 20, 1); |
| 184 histogram_tester().ExpectUniqueSample( |
| 185 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Total", 10, 1); |
| 186 } |
| 187 |
| 188 TEST_F(AdsPageLoadMetricsObserverTest, PageWithAdFrames) { |
| 189 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 190 RenderFrameHost* non_ad_frame = |
| 191 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
| 192 |
| 193 // Create 5 ad frames with the 5th nested inside the 4th. Verify that the |
| 194 // nested ad frame doesn't get counted separately (but that its bytes are |
| 195 // still counted). Also verify that the various ad signals (urls and names) |
| 196 // are properly detected. |
| 197 RenderFrameHost* ad_frame1 = |
| 198 CreateAndNavigateSubFrame(kNonAdUrl, "google_ads_iframe_1", main_frame); |
| 199 RenderFrameHost* ad_frame2 = |
| 200 CreateAndNavigateSubFrame(kNonAdUrl, "google_ads_frame_2", main_frame); |
| 201 RenderFrameHost* ad_frame3 = CreateAndNavigateSubFrame( |
| 202 "http://tpc.googlesyndication.com/safeframe/", "", main_frame); |
| 203 RenderFrameHost* ad_frame4 = CreateAndNavigateSubFrame( |
| 204 "https://tpc.googlesyndication.com/safeframe/1", "", main_frame); |
| 205 RenderFrameHost* nested_ad_frame4 = CreateAndNavigateSubFrame( |
| 206 "https://tpc.googlesyndication.com/safeframe/2", "", ad_frame4); |
| 207 |
| 208 // Create an addditional ad frame without content, it shouldn't be counted |
| 209 // in some percentage calculations. |
| 210 CreateAndNavigateSubFrame(kAdUrl, kNonAdName, main_frame); |
| 211 |
| 212 // 70KB total in page, 50 from ads, 40 from network, and 30 of those |
| 213 // are from ads. |
| 214 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
| 215 LoadResource(non_ad_frame, ResourceCached::CACHED, 10); |
| 216 LoadResource(ad_frame1, ResourceCached::CACHED, 10); |
| 217 LoadResource(ad_frame2, ResourceCached::NOT_CACHED, 10); |
| 218 LoadResource(ad_frame3, ResourceCached::NOT_CACHED, 10); |
| 219 LoadResource(ad_frame4, ResourceCached::NOT_CACHED, 10); |
| 220 LoadResource(nested_ad_frame4, ResourceCached::CACHED, 10); |
| 221 |
| 222 // Navigate again to trigger histograms. |
| 223 NavigateFrame(kNonAdUrl, main_frame); |
| 224 |
| 225 // Individual Ad Frame Metrics |
| 226 histogram_tester().ExpectBucketCount( |
| 227 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Total", 10, 3); |
| 228 histogram_tester().ExpectBucketCount( |
| 229 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Total", 20, 1); |
| 230 histogram_tester().ExpectBucketCount( |
| 231 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Network", 10, 3); |
| 232 histogram_tester().ExpectBucketCount( |
| 233 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Network", 0, 2); |
| 234 histogram_tester().ExpectBucketCount( |
| 235 "PageLoad.Clients.Ads.Google.Bytes.PercentAdFrame.Network", 0, 1); |
| 236 histogram_tester().ExpectBucketCount( |
| 237 "PageLoad.Clients.Ads.Google.Bytes.PercentAdFrame.Network", 100, 2); |
| 238 histogram_tester().ExpectBucketCount( |
| 239 "PageLoad.Clients.Ads.Google.Bytes.PercentAdFrame.Network", 50, 1); |
| 240 |
| 241 // Counts |
| 242 histogram_tester().ExpectUniqueSample( |
| 243 "PageLoad.Clients.Ads.Google.AdFrameCount", 5, 1); |
| 244 histogram_tester().ExpectUniqueSample( |
| 245 "PageLoad.Clients.Ads.Google.SubFrameCount.TopLevel", 6, 1); |
| 246 histogram_tester().ExpectUniqueSample( |
| 247 "PageLoad.Clients.Ads.Google.AdFrameCount.TopLevel", 5, 1); |
| 248 histogram_tester().ExpectUniqueSample( |
| 249 "PageLoad.Clients.Ads.Google.PercentSubFramesAreAdFrames.TopLevel", 83, |
| 250 1); |
| 251 |
| 252 // Page percentages |
| 253 histogram_tester().ExpectUniqueSample( |
| 254 "PageLoad.Clients.Ads.Google.Bytes.PercentPage.AllAdFrames.Total", 71, 1); |
| 255 histogram_tester().ExpectUniqueSample( |
| 256 "PageLoad.Clients.Ads.Google.Bytes.PercentAllAdFrames.Network", 60, 1); |
| 257 histogram_tester().ExpectUniqueSample( |
| 258 "PageLoad.Clients.Ads.Google.Bytes." |
| 259 "PercentPage.AllAdFrames.Network", |
| 260 75, 1); |
| 261 |
| 262 // Page byte counts |
| 263 histogram_tester().ExpectUniqueSample( |
| 264 "PageLoad.Clients.Ads.Google.Bytes.AllAdFrames.Total", 50, 1); |
| 265 histogram_tester().ExpectUniqueSample( |
| 266 "PageLoad.Clients.Ads.Google.Bytes.AllAdFrames.Network", 30, 1); |
| 267 histogram_tester().ExpectUniqueSample( |
| 268 "PageLoad.Clients.Ads.Google.Bytes.Total", 70, 1); |
| 269 histogram_tester().ExpectUniqueSample( |
| 270 "PageLoad.Clients.Ads.Google.Bytes.Network", 40, 1); |
| 271 histogram_tester().ExpectUniqueSample( |
| 272 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Total", 20, 1); |
| 273 } |
| 274 |
| 275 TEST_F(AdsPageLoadMetricsObserverTest, PageLoadSubFrameRenavigationMetrics) { |
| 276 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 277 |
| 278 // Test behavior of an ad frame. Once a frame is considered an ad, it's |
| 279 // always an ad. |
| 280 RenderFrameHost* ad_sub_frame = |
| 281 CreateAndNavigateSubFrame(kAdUrl, kNonAdName, main_frame); |
| 282 |
| 283 ad_sub_frame = NavigateFrameAndTestRenavigationMetrics(ad_sub_frame, |
| 284 FrameType::AD, kAdUrl); |
| 285 ad_sub_frame = NavigateFrameAndTestRenavigationMetrics( |
| 286 ad_sub_frame, FrameType::AD, kNonAdUrl); |
| 287 ad_sub_frame = NavigateFrameAndTestRenavigationMetrics( |
| 288 ad_sub_frame, FrameType::AD, kNonAdUrl); |
| 289 |
| 290 // Test behavior of a non-ad frame. Again, once it becomes an ad it stays an |
| 291 // ad. |
| 292 RenderFrameHost* non_ad_sub_frame = |
| 293 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
| 294 non_ad_sub_frame = NavigateFrameAndTestRenavigationMetrics( |
| 295 non_ad_sub_frame, FrameType::NON_AD, kNonAdUrl); |
| 296 non_ad_sub_frame = NavigateFrameAndTestRenavigationMetrics( |
| 297 non_ad_sub_frame, FrameType::NON_AD, kAdUrl); |
| 298 non_ad_sub_frame = NavigateFrameAndTestRenavigationMetrics( |
| 299 non_ad_sub_frame, FrameType::AD, kNonAdUrl); |
| 300 non_ad_sub_frame = NavigateFrameAndTestRenavigationMetrics( |
| 301 non_ad_sub_frame, FrameType::AD, kAdUrl); |
| 302 |
| 303 // Verify that children of ad frames don't get counted in the renavigation |
| 304 // metrics. |
| 305 RenderFrameHost* ad_sub_sub_frame = |
| 306 CreateAndNavigateSubFrame(kAdUrl, kNonAdName, ad_sub_frame); |
| 307 base::HistogramTester tester; |
| 308 ad_sub_sub_frame = NavigateFrame(kNonAdUrl2, ad_sub_sub_frame); |
| 309 tester.ExpectTotalCount("PageLoad.Clients.Ads.Google.AdFrameRenavigatedToAd", |
| 310 0); |
| 311 } |
| 312 |
| 313 TEST_F(AdsPageLoadMetricsObserverTest, PageWithAdFrameThatRenavigates) { |
| 314 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 315 RenderFrameHost* ad_frame = |
| 316 CreateAndNavigateSubFrame(kNonAdUrl, kAdName, main_frame); |
| 317 |
| 318 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
| 319 LoadResource(ad_frame, ResourceCached::NOT_CACHED, 10); |
| 320 |
| 321 // Navigate the ad frame again. |
| 322 ad_frame = NavigateFrame(kNonAdUrl, ad_frame); |
| 323 |
| 324 // In total, 30KB for entire page and 20 in one ad frame. |
| 325 LoadResource(ad_frame, ResourceCached::NOT_CACHED, 10); |
| 326 |
| 327 // Navigate again to trigger histograms. |
| 328 NavigateFrame(kNonAdUrl, main_frame); |
| 329 |
| 330 // Individual Ad Frame Metrics |
| 331 histogram_tester().ExpectUniqueSample( |
| 332 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Total", 20, 1); |
| 333 histogram_tester().ExpectUniqueSample( |
| 334 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Network", 20, 1); |
| 335 histogram_tester().ExpectUniqueSample( |
| 336 "PageLoad.Clients.Ads.Google.Bytes.PercentAdFrame.Network", 100, 1); |
| 337 |
| 338 // Counts |
| 339 histogram_tester().ExpectUniqueSample( |
| 340 "PageLoad.Clients.Ads.Google.AdFrameCount", 1, 1); |
| 341 histogram_tester().ExpectUniqueSample( |
| 342 "PageLoad.Clients.Ads.Google.SubFrameCount.TopLevel", 1, 1); |
| 343 histogram_tester().ExpectUniqueSample( |
| 344 "PageLoad.Clients.Ads.Google.AdFrameCount.TopLevel", 1, 1); |
| 345 histogram_tester().ExpectUniqueSample( |
| 346 "PageLoad.Clients.Ads.Google.PercentSubFramesAreAdFrames.TopLevel", 100, |
| 347 1); |
| 348 |
| 349 // Page percentages |
| 350 histogram_tester().ExpectUniqueSample( |
| 351 "PageLoad.Clients.Ads.Google.Bytes.PercentPage.AllAdFrames.Total", 66, 1); |
| 352 histogram_tester().ExpectUniqueSample( |
| 353 "PageLoad.Clients.Ads.Google.Bytes.PercentAllAdFrames.Network", 100, 1); |
| 354 histogram_tester().ExpectUniqueSample( |
| 355 "PageLoad.Clients.Ads.Google.Bytes." |
| 356 "PercentPage.AllAdFrames.Network", |
| 357 66, 1); |
| 358 |
| 359 // Page byte counts |
| 360 histogram_tester().ExpectUniqueSample( |
| 361 "PageLoad.Clients.Ads.Google.Bytes.AllAdFrames.Total", 20, 1); |
| 362 histogram_tester().ExpectUniqueSample( |
| 363 "PageLoad.Clients.Ads.Google.Bytes.AllAdFrames.Network", 20, 1); |
| 364 histogram_tester().ExpectUniqueSample( |
| 365 "PageLoad.Clients.Ads.Google.Bytes.Total", 30, 1); |
| 366 histogram_tester().ExpectUniqueSample( |
| 367 "PageLoad.Clients.Ads.Google.Bytes.Network", 30, 1); |
| 368 histogram_tester().ExpectUniqueSample( |
| 369 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Total", 10, 1); |
| 370 } |
| 371 |
| 372 TEST_F(AdsPageLoadMetricsObserverTest, PageWithNonAdFrameThatRenavigatesToAd) { |
| 373 // Main frame. |
| 374 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 375 |
| 376 // Sub frame that is not an ad. |
| 377 RenderFrameHost* sub_frame = |
| 378 CreateAndNavigateSubFrame(kNonAdUrl, kNonAdName, main_frame); |
| 379 |
| 380 // Child of the sub-frame that is an ad. |
| 381 RenderFrameHost* sub_frame_child_ad = |
| 382 CreateAndNavigateSubFrame(kNonAdUrl2, kAdName, sub_frame); |
| 383 |
| 384 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
| 385 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); |
| 386 LoadResource(sub_frame_child_ad, ResourceCached::NOT_CACHED, 10); |
| 387 |
| 388 // Navigate the subframe again, this time it's an ad. |
| 389 sub_frame = NavigateFrame(kAdUrl, sub_frame); |
| 390 LoadResource(sub_frame, ResourceCached::NOT_CACHED, 10); |
| 391 |
| 392 // In total, 40KB was loaded for the entire page and 20KB from ad |
| 393 // frames (the original child ad frame and the renavigated frame which |
| 394 // turned into an ad). |
| 395 |
| 396 // Navigate again to trigger histograms. |
| 397 NavigateFrame(kNonAdUrl, main_frame); |
| 398 |
| 399 // Individual Ad Frame Metrics |
| 400 histogram_tester().ExpectUniqueSample( |
| 401 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Total", 10, 2); |
| 402 histogram_tester().ExpectUniqueSample( |
| 403 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Network", 10, 2); |
| 404 histogram_tester().ExpectUniqueSample( |
| 405 "PageLoad.Clients.Ads.Google.Bytes.PercentAdFrame.Network", 100, 2); |
| 406 |
| 407 // Counts |
| 408 histogram_tester().ExpectUniqueSample( |
| 409 "PageLoad.Clients.Ads.Google.AdFrameCount", 2, 1); |
| 410 histogram_tester().ExpectUniqueSample( |
| 411 "PageLoad.Clients.Ads.Google.SubFrameCount.TopLevel", 1, 1); |
| 412 histogram_tester().ExpectUniqueSample( |
| 413 "PageLoad.Clients.Ads.Google.AdFrameCount.TopLevel", 1, 1); |
| 414 histogram_tester().ExpectUniqueSample( |
| 415 "PageLoad.Clients.Ads.Google.PercentSubFramesAreAdFrames.TopLevel", 100, |
| 416 1); |
| 417 |
| 418 // Page percentages |
| 419 histogram_tester().ExpectUniqueSample( |
| 420 "PageLoad.Clients.Ads.Google.Bytes.PercentPage.AllAdFrames.Total", 50, 1); |
| 421 histogram_tester().ExpectUniqueSample( |
| 422 "PageLoad.Clients.Ads.Google.Bytes.PercentAllAdFrames.Network", 100, 1); |
| 423 histogram_tester().ExpectUniqueSample( |
| 424 "PageLoad.Clients.Ads.Google.Bytes." |
| 425 "PercentPage.AllAdFrames.Network", |
| 426 50, 1); |
| 427 |
| 428 // Page byte counts |
| 429 histogram_tester().ExpectUniqueSample( |
| 430 "PageLoad.Clients.Ads.Google.Bytes.AllAdFrames.Total", 20, 1); |
| 431 histogram_tester().ExpectUniqueSample( |
| 432 "PageLoad.Clients.Ads.Google.Bytes.AllAdFrames.Network", 20, 1); |
| 433 histogram_tester().ExpectUniqueSample( |
| 434 "PageLoad.Clients.Ads.Google.Bytes.Total", 40, 1); |
| 435 histogram_tester().ExpectUniqueSample( |
| 436 "PageLoad.Clients.Ads.Google.Bytes.Network", 40, 1); |
| 437 histogram_tester().ExpectUniqueSample( |
| 438 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Total", 20, 1); |
| 439 } |
| 440 |
| 441 TEST_F(AdsPageLoadMetricsObserverTest, TwoResourceLoadsBeforeCommit) { |
| 442 // Main frame. |
| 443 RenderFrameHost* main_frame = NavigateMainFrame(kNonAdUrl); |
| 444 LoadResource(main_frame, ResourceCached::NOT_CACHED, 10); |
| 445 |
| 446 // Now open a subframe and have its resource load before notification of |
| 447 // navigation finishing. |
| 448 page_load_metrics::ExtraRequestInfo request( |
| 449 GURL(kNonAdUrl), main_frame->GetFrameTreeNodeId() + 1, false /* cached */, |
| 450 10 * 1024 /* size */, false /* data_reduction_proxy_used */, |
| 451 0 /* original_network_content_length */); |
| 452 SimulateLoadedResource(request); |
| 453 RenderFrameHost* subframe_ad = |
| 454 RenderFrameHostTester::For(main_frame)->AppendChild(kAdName); |
| 455 auto navigation_simulator = NavigationSimulator::CreateRendererInitiated( |
| 456 GURL(kNonAdUrl), subframe_ad); |
| 457 |
| 458 // The sub-frame renavigates before it commits. |
| 459 navigation_simulator->Start(); |
| 460 navigation_simulator->Fail(net::ERR_ABORTED); |
| 461 |
| 462 // Renavigate the subframe to a successful commit. But again, the resource |
| 463 // loads before the observer sees the finished navigation. |
| 464 SimulateLoadedResource(request); |
| 465 NavigateFrame(kNonAdUrl, subframe_ad); |
| 466 |
| 467 // Navigate again to trigger histograms. |
| 468 NavigateFrame(kNonAdUrl, main_frame); |
| 469 |
| 470 // 30KB in total was loaded. Ten for the main page, ten for an aborted |
| 471 // ad subframe, and ten for a successful ad subframe. The aborted ad |
| 472 // subframe's bytes don't count. |
| 473 |
| 474 // Individual Ad Frame Metrics |
| 475 histogram_tester().ExpectUniqueSample( |
| 476 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Total", 10, 1); |
| 477 histogram_tester().ExpectUniqueSample( |
| 478 "PageLoad.Clients.Ads.Google.Bytes.PerAdFrame.Network", 10, 1); |
| 479 histogram_tester().ExpectUniqueSample( |
| 480 "PageLoad.Clients.Ads.Google.Bytes.PercentAdFrame.Network", 100, 1); |
| 481 |
| 482 // Counts |
| 483 histogram_tester().ExpectUniqueSample( |
| 484 "PageLoad.Clients.Ads.Google.AdFrameCount", 1, 1); |
| 485 histogram_tester().ExpectUniqueSample( |
| 486 "PageLoad.Clients.Ads.Google.SubFrameCount.TopLevel", 1, 1); |
| 487 histogram_tester().ExpectUniqueSample( |
| 488 "PageLoad.Clients.Ads.Google.AdFrameCount.TopLevel", 1, 1); |
| 489 histogram_tester().ExpectUniqueSample( |
| 490 "PageLoad.Clients.Ads.Google.PercentSubFramesAreAdFrames.TopLevel", 100, |
| 491 1); |
| 492 |
| 493 // Page percentages |
| 494 histogram_tester().ExpectUniqueSample( |
| 495 "PageLoad.Clients.Ads.Google.Bytes.PercentPage.AllAdFrames.Total", 50, 1); |
| 496 histogram_tester().ExpectUniqueSample( |
| 497 "PageLoad.Clients.Ads.Google.Bytes.PercentAllAdFrames.Network", 100, 1); |
| 498 histogram_tester().ExpectUniqueSample( |
| 499 "PageLoad.Clients.Ads.Google.Bytes." |
| 500 "PercentPage.AllAdFrames.Network", |
| 501 50, 1); |
| 502 |
| 503 // Page byte counts |
| 504 histogram_tester().ExpectUniqueSample( |
| 505 "PageLoad.Clients.Ads.Google.Bytes.AllAdFrames.Total", 10, 1); |
| 506 histogram_tester().ExpectUniqueSample( |
| 507 "PageLoad.Clients.Ads.Google.Bytes.AllAdFrames.Network", 10, 1); |
| 508 histogram_tester().ExpectUniqueSample( |
| 509 "PageLoad.Clients.Ads.Google.Bytes.Total", 20, 1); |
| 510 histogram_tester().ExpectUniqueSample( |
| 511 "PageLoad.Clients.Ads.Google.Bytes.Network", 20, 1); |
| 512 histogram_tester().ExpectUniqueSample( |
| 513 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Total", 10, 1); |
| 514 } |
OLD | NEW |