OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/data_reduction_proxy_metric
s_observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/data_reduction_proxy_metric
s_observer.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <functional> | 9 #include <functional> |
10 #include <memory> | 10 #include <memory> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 send_pingback_called_(false) {} | 55 send_pingback_called_(false) {} |
56 ~TestPingbackClient() override {} | 56 ~TestPingbackClient() override {} |
57 | 57 |
58 void SendPingback( | 58 void SendPingback( |
59 const data_reduction_proxy::DataReductionProxyData& data, | 59 const data_reduction_proxy::DataReductionProxyData& data, |
60 const data_reduction_proxy::DataReductionProxyPageLoadTiming& timing) | 60 const data_reduction_proxy::DataReductionProxyPageLoadTiming& timing) |
61 override { | 61 override { |
62 timing_.reset( | 62 timing_.reset( |
63 new data_reduction_proxy::DataReductionProxyPageLoadTiming(timing)); | 63 new data_reduction_proxy::DataReductionProxyPageLoadTiming(timing)); |
64 send_pingback_called_ = true; | 64 send_pingback_called_ = true; |
| 65 data_ = data.DeepCopy(); |
65 } | 66 } |
66 | 67 |
67 data_reduction_proxy::DataReductionProxyPageLoadTiming* timing() const { | 68 data_reduction_proxy::DataReductionProxyPageLoadTiming* timing() const { |
68 return timing_.get(); | 69 return timing_.get(); |
69 } | 70 } |
70 | 71 |
| 72 const data_reduction_proxy::DataReductionProxyData& data() const { |
| 73 return *data_; |
| 74 } |
| 75 |
71 bool send_pingback_called() const { return send_pingback_called_; } | 76 bool send_pingback_called() const { return send_pingback_called_; } |
72 | 77 |
73 void Reset() { | 78 void Reset() { |
74 send_pingback_called_ = false; | 79 send_pingback_called_ = false; |
75 timing_.reset(); | 80 timing_.reset(); |
76 } | 81 } |
77 | 82 |
78 private: | 83 private: |
79 std::unique_ptr<data_reduction_proxy::DataReductionProxyPageLoadTiming> | 84 std::unique_ptr<data_reduction_proxy::DataReductionProxyPageLoadTiming> |
80 timing_; | 85 timing_; |
| 86 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> data_; |
81 bool send_pingback_called_; | 87 bool send_pingback_called_; |
82 | 88 |
83 DISALLOW_COPY_AND_ASSIGN(TestPingbackClient); | 89 DISALLOW_COPY_AND_ASSIGN(TestPingbackClient); |
84 }; | 90 }; |
85 | 91 |
86 } // namespace | 92 } // namespace |
87 | 93 |
88 // DataReductionProxyMetricsObserver responsible for modifying data about the | 94 // DataReductionProxyMetricsObserver responsible for modifying data about the |
89 // navigation in OnCommit. It is also responsible for using a passed in | 95 // navigation in OnCommit. It is also responsible for using a passed in |
90 // DataReductionProxyPingbackClient instead of the default. | 96 // DataReductionProxyPingbackClient instead of the default. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 timing_.first_meaningful_paint, | 192 timing_.first_meaningful_paint, |
187 pingback_client_->timing()->experimental_first_meaningful_paint); | 193 pingback_client_->timing()->experimental_first_meaningful_paint); |
188 ExpectEqualOrUnset(timing_.response_start, | 194 ExpectEqualOrUnset(timing_.response_start, |
189 pingback_client_->timing()->response_start); | 195 pingback_client_->timing()->response_start); |
190 ExpectEqualOrUnset(timing_.load_event_start, | 196 ExpectEqualOrUnset(timing_.load_event_start, |
191 pingback_client_->timing()->load_event_start); | 197 pingback_client_->timing()->load_event_start); |
192 ExpectEqualOrUnset(timing_.first_image_paint, | 198 ExpectEqualOrUnset(timing_.first_image_paint, |
193 pingback_client_->timing()->first_image_paint); | 199 pingback_client_->timing()->first_image_paint); |
194 } | 200 } |
195 | 201 |
| 202 void ValidateLoFiInPingback(bool lofi_expected) { |
| 203 EXPECT_TRUE(pingback_client_->send_pingback_called()); |
| 204 EXPECT_EQ(lofi_expected, pingback_client_->data().lofi_received()); |
| 205 } |
| 206 |
196 void ValidateHistograms() { | 207 void ValidateHistograms() { |
197 ValidateHistogramsForSuffix( | 208 ValidateHistogramsForSuffix( |
198 internal::kHistogramDOMContentLoadedEventFiredSuffix, | 209 internal::kHistogramDOMContentLoadedEventFiredSuffix, |
199 timing_.dom_content_loaded_event_start); | 210 timing_.dom_content_loaded_event_start); |
200 ValidateHistogramsForSuffix(internal::kHistogramFirstLayoutSuffix, | 211 ValidateHistogramsForSuffix(internal::kHistogramFirstLayoutSuffix, |
201 timing_.first_layout); | 212 timing_.first_layout); |
202 ValidateHistogramsForSuffix(internal::kHistogramLoadEventFiredSuffix, | 213 ValidateHistogramsForSuffix(internal::kHistogramLoadEventFiredSuffix, |
203 timing_.load_event_start); | 214 timing_.load_event_start); |
204 ValidateHistogramsForSuffix(internal::kHistogramFirstContentfulPaintSuffix, | 215 ValidateHistogramsForSuffix(internal::kHistogramFirstContentfulPaintSuffix, |
205 timing_.first_contentful_paint); | 216 timing_.first_contentful_paint); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 timing_.first_meaningful_paint = base::nullopt; | 399 timing_.first_meaningful_paint = base::nullopt; |
389 RunTestAndNavigateToUntrackedUrl(true, false); | 400 RunTestAndNavigateToUntrackedUrl(true, false); |
390 ValidateTimes(); | 401 ValidateTimes(); |
391 | 402 |
392 ResetTest(); | 403 ResetTest(); |
393 // Verify that when data reduction proxy was used but load event start is | 404 // Verify that when data reduction proxy was used but load event start is |
394 // unset, SendPingback is not called. | 405 // unset, SendPingback is not called. |
395 timing_.load_event_start = base::nullopt; | 406 timing_.load_event_start = base::nullopt; |
396 RunTestAndNavigateToUntrackedUrl(true, false); | 407 RunTestAndNavigateToUntrackedUrl(true, false); |
397 ValidateTimes(); | 408 ValidateTimes(); |
| 409 ValidateLoFiInPingback(false); |
| 410 |
| 411 ResetTest(); |
| 412 |
| 413 std::unique_ptr<DataReductionProxyData> data = |
| 414 base::MakeUnique<DataReductionProxyData>(); |
| 415 data->set_used_data_reduction_proxy(true); |
| 416 data->set_lofi_received(true); |
| 417 |
| 418 // Verify LoFi is tracked when a LoFi response is received. |
| 419 page_load_metrics::ExtraRequestInfo resource = { |
| 420 true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 421 0 /* original_network_content_length */, std::move(data)}; |
| 422 |
| 423 RunTest(true, false); |
| 424 SimulateLoadedResource(resource); |
| 425 NavigateToUntrackedUrl(); |
| 426 ValidateTimes(); |
| 427 ValidateLoFiInPingback(true); |
398 | 428 |
399 ResetTest(); | 429 ResetTest(); |
400 // Verify that when data reduction proxy was not used, SendPingback is not | 430 // Verify that when data reduction proxy was not used, SendPingback is not |
401 // called. | 431 // called. |
402 RunTestAndNavigateToUntrackedUrl(false, false); | 432 RunTestAndNavigateToUntrackedUrl(false, false); |
403 EXPECT_FALSE(pingback_client_->send_pingback_called()); | 433 EXPECT_FALSE(pingback_client_->send_pingback_called()); |
404 | 434 |
405 ResetTest(); | 435 ResetTest(); |
406 // Verify that when the holdback experiment is enabled, no pingback is sent. | 436 // Verify that when the holdback experiment is enabled, no pingback is sent. |
407 base::FieldTrialList field_trial_list(nullptr); | 437 base::FieldTrialList field_trial_list(nullptr); |
408 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 438 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
409 "DataCompressionProxyHoldback", "Enabled")); | 439 "DataCompressionProxyHoldback", "Enabled")); |
410 RunTestAndNavigateToUntrackedUrl(true, false); | 440 RunTestAndNavigateToUntrackedUrl(true, false); |
411 EXPECT_FALSE(pingback_client_->send_pingback_called()); | 441 EXPECT_FALSE(pingback_client_->send_pingback_called()); |
412 } | 442 } |
413 | 443 |
414 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) { | 444 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) { |
415 ResetTest(); | 445 ResetTest(); |
416 | 446 |
417 RunTest(true, false); | 447 RunTest(true, false); |
418 | 448 |
| 449 std::unique_ptr<DataReductionProxyData> data = |
| 450 base::MakeUnique<DataReductionProxyData>(); |
| 451 data->set_used_data_reduction_proxy(true); |
| 452 |
419 // Prepare 4 resources of varying size and configurations. | 453 // Prepare 4 resources of varying size and configurations. |
420 page_load_metrics::ExtraRequestInfo resources[] = { | 454 page_load_metrics::ExtraRequestInfo resources[] = { |
421 // Cached request. | 455 // Cached request. |
422 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 456 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
423 false /* data_reduction_proxy_used*/, | 457 0 /* original_network_content_length */, |
424 0 /* original_network_content_length */}, | 458 nullptr /* data_reduction_proxy_data */}, |
425 // Uncached non-proxied request. | 459 // Uncached non-proxied request. |
426 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 460 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
427 false /* data_reduction_proxy_used*/, | 461 1024 * 40 /* original_network_content_length */, |
428 1024 * 40 /* original_network_content_length */}, | 462 nullptr /* data_reduction_proxy_data */}, |
429 // Uncached proxied request with .1 compression ratio. | 463 // Uncached proxied request with .1 compression ratio. |
430 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 464 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
431 true /* data_reduction_proxy_used*/, | 465 1024 * 40 * 10 /* original_network_content_length */, data->DeepCopy()}, |
432 1024 * 40 * 10 /* original_network_content_length */}, | |
433 // Uncached proxied request with .5 compression ratio. | 466 // Uncached proxied request with .5 compression ratio. |
434 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 467 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
435 true /* data_reduction_proxy_used*/, | 468 1024 * 40 * 5 /* original_network_content_length */, std::move(data)}, |
436 1024 * 40 * 5 /* original_network_content_length */}, | |
437 }; | 469 }; |
438 | 470 |
439 int network_resources = 0; | 471 int network_resources = 0; |
440 int drp_resources = 0; | 472 int drp_resources = 0; |
441 int64_t network_bytes = 0; | 473 int64_t network_bytes = 0; |
442 int64_t drp_bytes = 0; | 474 int64_t drp_bytes = 0; |
443 int64_t ocl_bytes = 0; | 475 int64_t ocl_bytes = 0; |
444 for (auto request : resources) { | 476 for (const auto& request : resources) { |
445 SimulateLoadedResource(request); | 477 SimulateLoadedResource(request); |
446 if (!request.was_cached) { | 478 if (!request.was_cached) { |
447 network_bytes += request.raw_body_bytes; | 479 network_bytes += request.raw_body_bytes; |
448 ocl_bytes += request.original_network_content_length; | 480 ocl_bytes += request.original_network_content_length; |
449 ++network_resources; | 481 ++network_resources; |
450 } | 482 } |
451 if (request.data_reduction_proxy_used) { | 483 if (request.data_reduction_proxy_data && |
| 484 request.data_reduction_proxy_data->used_data_reduction_proxy()) { |
452 drp_bytes += request.raw_body_bytes; | 485 drp_bytes += request.raw_body_bytes; |
453 ++drp_resources; | 486 ++drp_resources; |
454 } | 487 } |
455 } | 488 } |
456 | 489 |
457 NavigateToUntrackedUrl(); | 490 NavigateToUntrackedUrl(); |
458 | 491 |
459 ValidateDataHistograms(network_resources, drp_resources, network_bytes, | 492 ValidateDataHistograms(network_resources, drp_resources, network_bytes, |
460 drp_bytes, ocl_bytes); | 493 drp_bytes, ocl_bytes); |
461 } | 494 } |
462 | 495 |
463 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) { | 496 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) { |
464 ResetTest(); | 497 ResetTest(); |
465 | 498 |
466 RunTest(true, false); | 499 RunTest(true, false); |
467 | 500 |
| 501 std::unique_ptr<DataReductionProxyData> data = |
| 502 base::MakeUnique<DataReductionProxyData>(); |
| 503 data->set_used_data_reduction_proxy(true); |
| 504 |
468 // Prepare 4 resources of varying size and configurations. | 505 // Prepare 4 resources of varying size and configurations. |
469 page_load_metrics::ExtraRequestInfo resources[] = { | 506 page_load_metrics::ExtraRequestInfo resources[] = { |
470 // Cached request. | 507 // Cached request. |
471 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 508 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
472 false /* data_reduction_proxy_used*/, | 509 0 /* original_network_content_length */, |
473 0 /* original_network_content_length */}, | 510 nullptr /* data_reduction_proxy_data */}, |
474 // Uncached non-proxied request. | 511 // Uncached non-proxied request. |
475 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 512 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
476 false /* data_reduction_proxy_used*/, | 513 1024 * 40 /* original_network_content_length */, |
477 1024 * 40 /* original_network_content_length */}, | 514 nullptr /* data_reduction_proxy_data */}, |
478 // Uncached proxied request with .1 compression ratio. | 515 // Uncached proxied request with .1 compression ratio. |
479 {false /*was_cached*/, 1024 * 40 * 10 /* raw_body_bytes */, | 516 {false /*was_cached*/, 1024 * 40 * 10 /* raw_body_bytes */, |
480 true /* data_reduction_proxy_used*/, | 517 1024 * 40 /* original_network_content_length */, data->DeepCopy()}, |
481 1024 * 40 /* original_network_content_length */}, | |
482 // Uncached proxied request with .5 compression ratio. | 518 // Uncached proxied request with .5 compression ratio. |
483 {false /*was_cached*/, 1024 * 40 * 5 /* raw_body_bytes */, | 519 {false /*was_cached*/, 1024 * 40 * 5 /* raw_body_bytes */, |
484 true /* data_reduction_proxy_used*/, | 520 1024 * 40 /* original_network_content_length */, std::move(data)}, |
485 1024 * 40 /* original_network_content_length */}, | |
486 }; | 521 }; |
487 | 522 |
488 int network_resources = 0; | 523 int network_resources = 0; |
489 int drp_resources = 0; | 524 int drp_resources = 0; |
490 int64_t network_bytes = 0; | 525 int64_t network_bytes = 0; |
491 int64_t drp_bytes = 0; | 526 int64_t drp_bytes = 0; |
492 int64_t ocl_bytes = 0; | 527 int64_t ocl_bytes = 0; |
493 for (auto request : resources) { | 528 for (const auto& request : resources) { |
494 SimulateLoadedResource(request); | 529 SimulateLoadedResource(request); |
495 if (!request.was_cached) { | 530 if (!request.was_cached) { |
496 network_bytes += request.raw_body_bytes; | 531 network_bytes += request.raw_body_bytes; |
497 ocl_bytes += request.original_network_content_length; | 532 ocl_bytes += request.original_network_content_length; |
498 ++network_resources; | 533 ++network_resources; |
499 } | 534 } |
500 if (request.data_reduction_proxy_used) { | 535 if (request.data_reduction_proxy_data && |
| 536 request.data_reduction_proxy_data->used_data_reduction_proxy()) { |
501 drp_bytes += request.raw_body_bytes; | 537 drp_bytes += request.raw_body_bytes; |
502 ++drp_resources; | 538 ++drp_resources; |
503 } | 539 } |
504 } | 540 } |
505 | 541 |
506 NavigateToUntrackedUrl(); | 542 NavigateToUntrackedUrl(); |
507 | 543 |
508 ValidateDataHistograms(network_resources, drp_resources, network_bytes, | 544 ValidateDataHistograms(network_resources, drp_resources, network_bytes, |
509 drp_bytes, ocl_bytes); | 545 drp_bytes, ocl_bytes); |
510 } | 546 } |
511 | 547 |
512 } // namespace data_reduction_proxy | 548 } // namespace data_reduction_proxy |
OLD | NEW |