| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 timing_.paint_timing.first_meaningful_paint, | 194 timing_.paint_timing.first_meaningful_paint, |
| 189 pingback_client_->timing()->experimental_first_meaningful_paint); | 195 pingback_client_->timing()->experimental_first_meaningful_paint); |
| 190 ExpectEqualOrUnset(timing_.response_start, | 196 ExpectEqualOrUnset(timing_.response_start, |
| 191 pingback_client_->timing()->response_start); | 197 pingback_client_->timing()->response_start); |
| 192 ExpectEqualOrUnset(timing_.document_timing.load_event_start, | 198 ExpectEqualOrUnset(timing_.document_timing.load_event_start, |
| 193 pingback_client_->timing()->load_event_start); | 199 pingback_client_->timing()->load_event_start); |
| 194 ExpectEqualOrUnset(timing_.paint_timing.first_image_paint, | 200 ExpectEqualOrUnset(timing_.paint_timing.first_image_paint, |
| 195 pingback_client_->timing()->first_image_paint); | 201 pingback_client_->timing()->first_image_paint); |
| 196 } | 202 } |
| 197 | 203 |
| 204 void ValidateLoFiInPingback(bool lofi_expected) { |
| 205 EXPECT_TRUE(pingback_client_->send_pingback_called()); |
| 206 EXPECT_EQ(lofi_expected, pingback_client_->data().lofi_received()); |
| 207 } |
| 208 |
| 198 void ValidateHistograms() { | 209 void ValidateHistograms() { |
| 199 ValidateHistogramsForSuffix( | 210 ValidateHistogramsForSuffix( |
| 200 internal::kHistogramDOMContentLoadedEventFiredSuffix, | 211 internal::kHistogramDOMContentLoadedEventFiredSuffix, |
| 201 timing_.document_timing.dom_content_loaded_event_start); | 212 timing_.document_timing.dom_content_loaded_event_start); |
| 202 ValidateHistogramsForSuffix(internal::kHistogramFirstLayoutSuffix, | 213 ValidateHistogramsForSuffix(internal::kHistogramFirstLayoutSuffix, |
| 203 timing_.document_timing.first_layout); | 214 timing_.document_timing.first_layout); |
| 204 ValidateHistogramsForSuffix(internal::kHistogramLoadEventFiredSuffix, | 215 ValidateHistogramsForSuffix(internal::kHistogramLoadEventFiredSuffix, |
| 205 timing_.document_timing.load_event_start); | 216 timing_.document_timing.load_event_start); |
| 206 ValidateHistogramsForSuffix(internal::kHistogramFirstContentfulPaintSuffix, | 217 ValidateHistogramsForSuffix(internal::kHistogramFirstContentfulPaintSuffix, |
| 207 timing_.paint_timing.first_contentful_paint); | 218 timing_.paint_timing.first_contentful_paint); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 timing_.paint_timing.first_meaningful_paint = base::nullopt; | 401 timing_.paint_timing.first_meaningful_paint = base::nullopt; |
| 391 RunTestAndNavigateToUntrackedUrl(true, false); | 402 RunTestAndNavigateToUntrackedUrl(true, false); |
| 392 ValidateTimes(); | 403 ValidateTimes(); |
| 393 | 404 |
| 394 ResetTest(); | 405 ResetTest(); |
| 395 // Verify that when data reduction proxy was used but load event start is | 406 // Verify that when data reduction proxy was used but load event start is |
| 396 // unset, SendPingback is not called. | 407 // unset, SendPingback is not called. |
| 397 timing_.document_timing.load_event_start = base::nullopt; | 408 timing_.document_timing.load_event_start = base::nullopt; |
| 398 RunTestAndNavigateToUntrackedUrl(true, false); | 409 RunTestAndNavigateToUntrackedUrl(true, false); |
| 399 ValidateTimes(); | 410 ValidateTimes(); |
| 411 ValidateLoFiInPingback(false); |
| 412 |
| 413 ResetTest(); |
| 414 |
| 415 std::unique_ptr<DataReductionProxyData> data = |
| 416 base::MakeUnique<DataReductionProxyData>(); |
| 417 data->set_used_data_reduction_proxy(true); |
| 418 data->set_lofi_received(true); |
| 419 |
| 420 // Verify LoFi is tracked when a LoFi response is received. |
| 421 page_load_metrics::ExtraRequestInfo resource = { |
| 422 true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 423 0 /* original_network_content_length */, std::move(data)}; |
| 424 |
| 425 RunTest(true, false); |
| 426 SimulateLoadedResource(resource); |
| 427 NavigateToUntrackedUrl(); |
| 428 ValidateTimes(); |
| 429 ValidateLoFiInPingback(true); |
| 400 | 430 |
| 401 ResetTest(); | 431 ResetTest(); |
| 402 // Verify that when data reduction proxy was not used, SendPingback is not | 432 // Verify that when data reduction proxy was not used, SendPingback is not |
| 403 // called. | 433 // called. |
| 404 RunTestAndNavigateToUntrackedUrl(false, false); | 434 RunTestAndNavigateToUntrackedUrl(false, false); |
| 405 EXPECT_FALSE(pingback_client_->send_pingback_called()); | 435 EXPECT_FALSE(pingback_client_->send_pingback_called()); |
| 406 | 436 |
| 407 ResetTest(); | 437 ResetTest(); |
| 408 // Verify that when the holdback experiment is enabled, no pingback is sent. | 438 // Verify that when the holdback experiment is enabled, no pingback is sent. |
| 409 base::FieldTrialList field_trial_list(nullptr); | 439 base::FieldTrialList field_trial_list(nullptr); |
| 410 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 440 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 411 "DataCompressionProxyHoldback", "Enabled")); | 441 "DataCompressionProxyHoldback", "Enabled")); |
| 412 RunTestAndNavigateToUntrackedUrl(true, false); | 442 RunTestAndNavigateToUntrackedUrl(true, false); |
| 413 EXPECT_FALSE(pingback_client_->send_pingback_called()); | 443 EXPECT_FALSE(pingback_client_->send_pingback_called()); |
| 414 } | 444 } |
| 415 | 445 |
| 416 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) { | 446 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) { |
| 417 ResetTest(); | 447 ResetTest(); |
| 418 | 448 |
| 419 RunTest(true, false); | 449 RunTest(true, false); |
| 420 | 450 |
| 451 std::unique_ptr<DataReductionProxyData> data = |
| 452 base::MakeUnique<DataReductionProxyData>(); |
| 453 data->set_used_data_reduction_proxy(true); |
| 454 |
| 421 // Prepare 4 resources of varying size and configurations. | 455 // Prepare 4 resources of varying size and configurations. |
| 422 page_load_metrics::ExtraRequestInfo resources[] = { | 456 page_load_metrics::ExtraRequestInfo resources[] = { |
| 423 // Cached request. | 457 // Cached request. |
| 424 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 458 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 425 false /* data_reduction_proxy_used*/, | 459 0 /* original_network_content_length */, |
| 426 0 /* original_network_content_length */}, | 460 nullptr /* data_reduction_proxy_data */}, |
| 427 // Uncached non-proxied request. | 461 // Uncached non-proxied request. |
| 428 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 462 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 429 false /* data_reduction_proxy_used*/, | 463 1024 * 40 /* original_network_content_length */, |
| 430 1024 * 40 /* original_network_content_length */}, | 464 nullptr /* data_reduction_proxy_data */}, |
| 431 // Uncached proxied request with .1 compression ratio. | 465 // Uncached proxied request with .1 compression ratio. |
| 432 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 466 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 433 true /* data_reduction_proxy_used*/, | 467 1024 * 40 * 10 /* original_network_content_length */, data->DeepCopy()}, |
| 434 1024 * 40 * 10 /* original_network_content_length */}, | |
| 435 // Uncached proxied request with .5 compression ratio. | 468 // Uncached proxied request with .5 compression ratio. |
| 436 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 469 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 437 true /* data_reduction_proxy_used*/, | 470 1024 * 40 * 5 /* original_network_content_length */, std::move(data)}, |
| 438 1024 * 40 * 5 /* original_network_content_length */}, | |
| 439 }; | 471 }; |
| 440 | 472 |
| 441 int network_resources = 0; | 473 int network_resources = 0; |
| 442 int drp_resources = 0; | 474 int drp_resources = 0; |
| 443 int64_t network_bytes = 0; | 475 int64_t network_bytes = 0; |
| 444 int64_t drp_bytes = 0; | 476 int64_t drp_bytes = 0; |
| 445 int64_t ocl_bytes = 0; | 477 int64_t ocl_bytes = 0; |
| 446 for (auto request : resources) { | 478 for (const auto& request : resources) { |
| 447 SimulateLoadedResource(request); | 479 SimulateLoadedResource(request); |
| 448 if (!request.was_cached) { | 480 if (!request.was_cached) { |
| 449 network_bytes += request.raw_body_bytes; | 481 network_bytes += request.raw_body_bytes; |
| 450 ocl_bytes += request.original_network_content_length; | 482 ocl_bytes += request.original_network_content_length; |
| 451 ++network_resources; | 483 ++network_resources; |
| 452 } | 484 } |
| 453 if (request.data_reduction_proxy_used) { | 485 if (request.data_reduction_proxy_data && |
| 486 request.data_reduction_proxy_data->used_data_reduction_proxy()) { |
| 454 drp_bytes += request.raw_body_bytes; | 487 drp_bytes += request.raw_body_bytes; |
| 455 ++drp_resources; | 488 ++drp_resources; |
| 456 } | 489 } |
| 457 } | 490 } |
| 458 | 491 |
| 459 NavigateToUntrackedUrl(); | 492 NavigateToUntrackedUrl(); |
| 460 | 493 |
| 461 ValidateDataHistograms(network_resources, drp_resources, network_bytes, | 494 ValidateDataHistograms(network_resources, drp_resources, network_bytes, |
| 462 drp_bytes, ocl_bytes); | 495 drp_bytes, ocl_bytes); |
| 463 } | 496 } |
| 464 | 497 |
| 465 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) { | 498 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) { |
| 466 ResetTest(); | 499 ResetTest(); |
| 467 | 500 |
| 468 RunTest(true, false); | 501 RunTest(true, false); |
| 469 | 502 |
| 503 std::unique_ptr<DataReductionProxyData> data = |
| 504 base::MakeUnique<DataReductionProxyData>(); |
| 505 data->set_used_data_reduction_proxy(true); |
| 506 |
| 470 // Prepare 4 resources of varying size and configurations. | 507 // Prepare 4 resources of varying size and configurations. |
| 471 page_load_metrics::ExtraRequestInfo resources[] = { | 508 page_load_metrics::ExtraRequestInfo resources[] = { |
| 472 // Cached request. | 509 // Cached request. |
| 473 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 510 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 474 false /* data_reduction_proxy_used*/, | 511 0 /* original_network_content_length */, |
| 475 0 /* original_network_content_length */}, | 512 nullptr /* data_reduction_proxy_data */}, |
| 476 // Uncached non-proxied request. | 513 // Uncached non-proxied request. |
| 477 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 514 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 478 false /* data_reduction_proxy_used*/, | 515 1024 * 40 /* original_network_content_length */, |
| 479 1024 * 40 /* original_network_content_length */}, | 516 nullptr /* data_reduction_proxy_data */}, |
| 480 // Uncached proxied request with .1 compression ratio. | 517 // Uncached proxied request with .1 compression ratio. |
| 481 {false /*was_cached*/, 1024 * 40 * 10 /* raw_body_bytes */, | 518 {false /*was_cached*/, 1024 * 40 * 10 /* raw_body_bytes */, |
| 482 true /* data_reduction_proxy_used*/, | 519 1024 * 40 /* original_network_content_length */, data->DeepCopy()}, |
| 483 1024 * 40 /* original_network_content_length */}, | |
| 484 // Uncached proxied request with .5 compression ratio. | 520 // Uncached proxied request with .5 compression ratio. |
| 485 {false /*was_cached*/, 1024 * 40 * 5 /* raw_body_bytes */, | 521 {false /*was_cached*/, 1024 * 40 * 5 /* raw_body_bytes */, |
| 486 true /* data_reduction_proxy_used*/, | 522 1024 * 40 /* original_network_content_length */, std::move(data)}, |
| 487 1024 * 40 /* original_network_content_length */}, | |
| 488 }; | 523 }; |
| 489 | 524 |
| 490 int network_resources = 0; | 525 int network_resources = 0; |
| 491 int drp_resources = 0; | 526 int drp_resources = 0; |
| 492 int64_t network_bytes = 0; | 527 int64_t network_bytes = 0; |
| 493 int64_t drp_bytes = 0; | 528 int64_t drp_bytes = 0; |
| 494 int64_t ocl_bytes = 0; | 529 int64_t ocl_bytes = 0; |
| 495 for (auto request : resources) { | 530 for (const auto& request : resources) { |
| 496 SimulateLoadedResource(request); | 531 SimulateLoadedResource(request); |
| 497 if (!request.was_cached) { | 532 if (!request.was_cached) { |
| 498 network_bytes += request.raw_body_bytes; | 533 network_bytes += request.raw_body_bytes; |
| 499 ocl_bytes += request.original_network_content_length; | 534 ocl_bytes += request.original_network_content_length; |
| 500 ++network_resources; | 535 ++network_resources; |
| 501 } | 536 } |
| 502 if (request.data_reduction_proxy_used) { | 537 if (request.data_reduction_proxy_data && |
| 538 request.data_reduction_proxy_data->used_data_reduction_proxy()) { |
| 503 drp_bytes += request.raw_body_bytes; | 539 drp_bytes += request.raw_body_bytes; |
| 504 ++drp_resources; | 540 ++drp_resources; |
| 505 } | 541 } |
| 506 } | 542 } |
| 507 | 543 |
| 508 NavigateToUntrackedUrl(); | 544 NavigateToUntrackedUrl(); |
| 509 | 545 |
| 510 ValidateDataHistograms(network_resources, drp_resources, network_bytes, | 546 ValidateDataHistograms(network_resources, drp_resources, network_bytes, |
| 511 drp_bytes, ocl_bytes); | 547 drp_bytes, ocl_bytes); |
| 512 } | 548 } |
| 513 | 549 |
| 514 } // namespace data_reduction_proxy | 550 } // namespace data_reduction_proxy |
| OLD | NEW |