Chromium Code Reviews| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 return data; | 45 return data; |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Pingback client responsible for recording the timing information it receives | 48 // Pingback client responsible for recording the timing information it receives |
| 49 // from a SendPingback call. | 49 // from a SendPingback call. |
| 50 class TestPingbackClient | 50 class TestPingbackClient |
| 51 : public data_reduction_proxy::DataReductionProxyPingbackClient { | 51 : public data_reduction_proxy::DataReductionProxyPingbackClient { |
| 52 public: | 52 public: |
| 53 TestPingbackClient() | 53 TestPingbackClient() |
| 54 : data_reduction_proxy::DataReductionProxyPingbackClient(nullptr), | 54 : data_reduction_proxy::DataReductionProxyPingbackClient(nullptr), |
| 55 tab_identifier_key_(nullptr), | |
| 55 send_pingback_called_(false) {} | 56 send_pingback_called_(false) {} |
| 56 ~TestPingbackClient() override {} | 57 ~TestPingbackClient() override {} |
| 57 | 58 |
| 58 void SendPingback( | 59 void SendPingback( |
| 59 const data_reduction_proxy::DataReductionProxyData& data, | 60 const data_reduction_proxy::DataReductionProxyData& data, |
| 60 const data_reduction_proxy::DataReductionProxyPageLoadTiming& timing) | 61 const data_reduction_proxy::DataReductionProxyPageLoadTiming& timing, |
| 61 override { | 62 const void* tab_identifier_key) override { |
| 62 timing_.reset( | 63 timing_.reset( |
| 63 new data_reduction_proxy::DataReductionProxyPageLoadTiming(timing)); | 64 new data_reduction_proxy::DataReductionProxyPageLoadTiming(timing)); |
| 64 send_pingback_called_ = true; | 65 send_pingback_called_ = true; |
| 66 data_ = data.DeepCopy(); | |
| 67 tab_identifier_key_ = tab_identifier_key; | |
|
bengr
2017/04/20 17:36:18
Which cases will have no tab identifier key? Docum
RyanSturm
2017/04/20 20:25:44
Acknowledged.
| |
| 65 } | 68 } |
| 66 | 69 |
| 67 data_reduction_proxy::DataReductionProxyPageLoadTiming* timing() const { | 70 data_reduction_proxy::DataReductionProxyPageLoadTiming* timing() const { |
| 68 return timing_.get(); | 71 return timing_.get(); |
| 69 } | 72 } |
| 70 | 73 |
| 74 const data_reduction_proxy::DataReductionProxyData& data() const { | |
| 75 return *data_; | |
| 76 } | |
| 77 | |
| 78 const void* tab_identifier_key() const { return tab_identifier_key_; } | |
| 79 | |
| 71 bool send_pingback_called() const { return send_pingback_called_; } | 80 bool send_pingback_called() const { return send_pingback_called_; } |
| 72 | 81 |
| 73 void Reset() { | 82 void Reset() { |
| 74 send_pingback_called_ = false; | 83 send_pingback_called_ = false; |
| 75 timing_.reset(); | 84 timing_.reset(); |
| 76 } | 85 } |
| 77 | 86 |
| 78 private: | 87 private: |
| 79 std::unique_ptr<data_reduction_proxy::DataReductionProxyPageLoadTiming> | 88 std::unique_ptr<data_reduction_proxy::DataReductionProxyPageLoadTiming> |
| 80 timing_; | 89 timing_; |
| 90 std::unique_ptr<data_reduction_proxy::DataReductionProxyData> data_; | |
| 91 const void* tab_identifier_key_; | |
| 81 bool send_pingback_called_; | 92 bool send_pingback_called_; |
| 82 | 93 |
| 83 DISALLOW_COPY_AND_ASSIGN(TestPingbackClient); | 94 DISALLOW_COPY_AND_ASSIGN(TestPingbackClient); |
| 84 }; | 95 }; |
| 85 | 96 |
| 86 } // namespace | 97 } // namespace |
| 87 | 98 |
| 88 // DataReductionProxyMetricsObserver responsible for modifying data about the | 99 // DataReductionProxyMetricsObserver responsible for modifying data about the |
| 89 // navigation in OnCommit. It is also responsible for using a passed in | 100 // navigation in OnCommit. It is also responsible for using a passed in |
| 90 // DataReductionProxyPingbackClient instead of the default. | 101 // DataReductionProxyPingbackClient instead of the default. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 if (expected && actual) { | 182 if (expected && actual) { |
| 172 EXPECT_EQ(expected.value(), actual.value()); | 183 EXPECT_EQ(expected.value(), actual.value()); |
| 173 } else { | 184 } else { |
| 174 EXPECT_TRUE(!expected); | 185 EXPECT_TRUE(!expected); |
| 175 EXPECT_TRUE(!actual); | 186 EXPECT_TRUE(!actual); |
| 176 } | 187 } |
| 177 } | 188 } |
| 178 | 189 |
| 179 void ValidateTimes() { | 190 void ValidateTimes() { |
| 180 EXPECT_TRUE(pingback_client_->send_pingback_called()); | 191 EXPECT_TRUE(pingback_client_->send_pingback_called()); |
| 192 EXPECT_EQ(static_cast<void*>(web_contents()), | |
| 193 pingback_client_->tab_identifier_key()); | |
| 181 EXPECT_EQ(timing_.navigation_start, | 194 EXPECT_EQ(timing_.navigation_start, |
| 182 pingback_client_->timing()->navigation_start); | 195 pingback_client_->timing()->navigation_start); |
| 183 ExpectEqualOrUnset(timing_.first_contentful_paint, | 196 ExpectEqualOrUnset(timing_.first_contentful_paint, |
| 184 pingback_client_->timing()->first_contentful_paint); | 197 pingback_client_->timing()->first_contentful_paint); |
| 185 ExpectEqualOrUnset( | 198 ExpectEqualOrUnset( |
| 186 timing_.first_meaningful_paint, | 199 timing_.first_meaningful_paint, |
| 187 pingback_client_->timing()->experimental_first_meaningful_paint); | 200 pingback_client_->timing()->experimental_first_meaningful_paint); |
| 188 ExpectEqualOrUnset(timing_.response_start, | 201 ExpectEqualOrUnset(timing_.response_start, |
| 189 pingback_client_->timing()->response_start); | 202 pingback_client_->timing()->response_start); |
| 190 ExpectEqualOrUnset(timing_.load_event_start, | 203 ExpectEqualOrUnset(timing_.load_event_start, |
| 191 pingback_client_->timing()->load_event_start); | 204 pingback_client_->timing()->load_event_start); |
| 192 ExpectEqualOrUnset(timing_.first_image_paint, | 205 ExpectEqualOrUnset(timing_.first_image_paint, |
| 193 pingback_client_->timing()->first_image_paint); | 206 pingback_client_->timing()->first_image_paint); |
| 194 } | 207 } |
| 195 | 208 |
| 209 void ValidateLoFiInPingback(bool lofi_expected) { | |
| 210 EXPECT_TRUE(pingback_client_->send_pingback_called()); | |
| 211 EXPECT_EQ(lofi_expected, pingback_client_->data().lofi_received()); | |
| 212 } | |
| 213 | |
| 196 void ValidateHistograms() { | 214 void ValidateHistograms() { |
| 197 ValidateHistogramsForSuffix( | 215 ValidateHistogramsForSuffix( |
| 198 internal::kHistogramDOMContentLoadedEventFiredSuffix, | 216 internal::kHistogramDOMContentLoadedEventFiredSuffix, |
| 199 timing_.dom_content_loaded_event_start); | 217 timing_.dom_content_loaded_event_start); |
| 200 ValidateHistogramsForSuffix(internal::kHistogramFirstLayoutSuffix, | 218 ValidateHistogramsForSuffix(internal::kHistogramFirstLayoutSuffix, |
| 201 timing_.first_layout); | 219 timing_.first_layout); |
| 202 ValidateHistogramsForSuffix(internal::kHistogramLoadEventFiredSuffix, | 220 ValidateHistogramsForSuffix(internal::kHistogramLoadEventFiredSuffix, |
| 203 timing_.load_event_start); | 221 timing_.load_event_start); |
| 204 ValidateHistogramsForSuffix(internal::kHistogramFirstContentfulPaintSuffix, | 222 ValidateHistogramsForSuffix(internal::kHistogramFirstContentfulPaintSuffix, |
| 205 timing_.first_contentful_paint); | 223 timing_.first_contentful_paint); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 timing_.first_meaningful_paint = base::nullopt; | 406 timing_.first_meaningful_paint = base::nullopt; |
| 389 RunTestAndNavigateToUntrackedUrl(true, false); | 407 RunTestAndNavigateToUntrackedUrl(true, false); |
| 390 ValidateTimes(); | 408 ValidateTimes(); |
| 391 | 409 |
| 392 ResetTest(); | 410 ResetTest(); |
| 393 // Verify that when data reduction proxy was used but load event start is | 411 // Verify that when data reduction proxy was used but load event start is |
| 394 // unset, SendPingback is not called. | 412 // unset, SendPingback is not called. |
| 395 timing_.load_event_start = base::nullopt; | 413 timing_.load_event_start = base::nullopt; |
| 396 RunTestAndNavigateToUntrackedUrl(true, false); | 414 RunTestAndNavigateToUntrackedUrl(true, false); |
| 397 ValidateTimes(); | 415 ValidateTimes(); |
| 416 ValidateLoFiInPingback(false); | |
| 417 | |
| 418 ResetTest(); | |
| 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 false /* data_reduction_proxy_used*/, true /* was_lofi_response */, | |
| 424 0 /* original_network_content_length */}; | |
| 425 | |
| 426 RunTest(true, false); | |
| 427 SimulateLoadedResource(resource); | |
| 428 NavigateToUntrackedUrl(); | |
| 429 ValidateTimes(); | |
| 430 ValidateLoFiInPingback(true); | |
| 398 | 431 |
| 399 ResetTest(); | 432 ResetTest(); |
| 400 // Verify that when data reduction proxy was not used, SendPingback is not | 433 // Verify that when data reduction proxy was not used, SendPingback is not |
| 401 // called. | 434 // called. |
| 402 RunTestAndNavigateToUntrackedUrl(false, false); | 435 RunTestAndNavigateToUntrackedUrl(false, false); |
| 403 EXPECT_FALSE(pingback_client_->send_pingback_called()); | 436 EXPECT_FALSE(pingback_client_->send_pingback_called()); |
| 404 | 437 |
| 405 ResetTest(); | 438 ResetTest(); |
| 406 // Verify that when the holdback experiment is enabled, no pingback is sent. | 439 // Verify that when the holdback experiment is enabled, no pingback is sent. |
| 407 base::FieldTrialList field_trial_list(nullptr); | 440 base::FieldTrialList field_trial_list(nullptr); |
| 408 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 441 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 409 "DataCompressionProxyHoldback", "Enabled")); | 442 "DataCompressionProxyHoldback", "Enabled")); |
| 410 RunTestAndNavigateToUntrackedUrl(true, false); | 443 RunTestAndNavigateToUntrackedUrl(true, false); |
| 411 EXPECT_FALSE(pingback_client_->send_pingback_called()); | 444 EXPECT_FALSE(pingback_client_->send_pingback_called()); |
| 412 } | 445 } |
| 413 | 446 |
| 414 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) { | 447 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) { |
| 415 ResetTest(); | 448 ResetTest(); |
| 416 | 449 |
| 417 RunTest(true, false); | 450 RunTest(true, false); |
| 418 | 451 |
| 419 // Prepare 4 resources of varying size and configurations. | 452 // Prepare 4 resources of varying size and configurations. |
| 420 page_load_metrics::ExtraRequestInfo resources[] = { | 453 page_load_metrics::ExtraRequestInfo resources[] = { |
| 421 // Cached request. | 454 // Cached request. |
| 422 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 455 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 423 false /* data_reduction_proxy_used*/, | 456 false /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
|
bengr
2017/04/20 17:36:18
you have two spaces after /*
RyanSturm
2017/04/20 20:25:44
Acknowledged.
| |
| 424 0 /* original_network_content_length */}, | 457 0 /* original_network_content_length */}, |
| 425 // Uncached non-proxied request. | 458 // Uncached non-proxied request. |
| 426 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 459 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 427 false /* data_reduction_proxy_used*/, | 460 false /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 428 1024 * 40 /* original_network_content_length */}, | 461 1024 * 40 /* original_network_content_length */}, |
| 429 // Uncached proxied request with .1 compression ratio. | 462 // Uncached proxied request with .1 compression ratio. |
| 430 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 463 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 431 true /* data_reduction_proxy_used*/, | 464 true /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 432 1024 * 40 * 10 /* original_network_content_length */}, | 465 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 true /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 436 1024 * 40 * 5 /* original_network_content_length */}, | 469 1024 * 40 * 5 /* original_network_content_length */}, |
| 437 }; | 470 }; |
| 438 | 471 |
| 439 int network_resources = 0; | 472 int network_resources = 0; |
| 440 int drp_resources = 0; | 473 int drp_resources = 0; |
| 441 int64_t network_bytes = 0; | 474 int64_t network_bytes = 0; |
| 442 int64_t drp_bytes = 0; | 475 int64_t drp_bytes = 0; |
| 443 int64_t ocl_bytes = 0; | 476 int64_t ocl_bytes = 0; |
| 444 for (auto request : resources) { | 477 for (auto request : resources) { |
| 445 SimulateLoadedResource(request); | 478 SimulateLoadedResource(request); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 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 |
| 468 // Prepare 4 resources of varying size and configurations. | 501 // Prepare 4 resources of varying size and configurations. |
| 469 page_load_metrics::ExtraRequestInfo resources[] = { | 502 page_load_metrics::ExtraRequestInfo resources[] = { |
| 470 // Cached request. | 503 // Cached request. |
| 471 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 504 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 472 false /* data_reduction_proxy_used*/, | 505 false /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 473 0 /* original_network_content_length */}, | 506 0 /* original_network_content_length */}, |
| 474 // Uncached non-proxied request. | 507 // Uncached non-proxied request. |
| 475 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 508 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| 476 false /* data_reduction_proxy_used*/, | 509 false /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 477 1024 * 40 /* original_network_content_length */}, | 510 1024 * 40 /* original_network_content_length */}, |
| 478 // Uncached proxied request with .1 compression ratio. | 511 // Uncached proxied request with .1 compression ratio. |
| 479 {false /*was_cached*/, 1024 * 40 * 10 /* raw_body_bytes */, | 512 {false /*was_cached*/, 1024 * 40 * 10 /* raw_body_bytes */, |
| 480 true /* data_reduction_proxy_used*/, | 513 true /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 481 1024 * 40 /* original_network_content_length */}, | 514 1024 * 40 /* original_network_content_length */}, |
| 482 // Uncached proxied request with .5 compression ratio. | 515 // Uncached proxied request with .5 compression ratio. |
| 483 {false /*was_cached*/, 1024 * 40 * 5 /* raw_body_bytes */, | 516 {false /*was_cached*/, 1024 * 40 * 5 /* raw_body_bytes */, |
| 484 true /* data_reduction_proxy_used*/, | 517 true /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 485 1024 * 40 /* original_network_content_length */}, | 518 1024 * 40 /* original_network_content_length */}, |
| 486 }; | 519 }; |
| 487 | 520 |
| 488 int network_resources = 0; | 521 int network_resources = 0; |
| 489 int drp_resources = 0; | 522 int drp_resources = 0; |
| 490 int64_t network_bytes = 0; | 523 int64_t network_bytes = 0; |
| 491 int64_t drp_bytes = 0; | 524 int64_t drp_bytes = 0; |
| 492 int64_t ocl_bytes = 0; | 525 int64_t ocl_bytes = 0; |
| 493 for (auto request : resources) { | 526 for (auto request : resources) { |
| 494 SimulateLoadedResource(request); | 527 SimulateLoadedResource(request); |
| 495 if (!request.was_cached) { | 528 if (!request.was_cached) { |
| 496 network_bytes += request.raw_body_bytes; | 529 network_bytes += request.raw_body_bytes; |
| 497 ocl_bytes += request.original_network_content_length; | 530 ocl_bytes += request.original_network_content_length; |
| 498 ++network_resources; | 531 ++network_resources; |
| 499 } | 532 } |
| 500 if (request.data_reduction_proxy_used) { | 533 if (request.data_reduction_proxy_used) { |
| 501 drp_bytes += request.raw_body_bytes; | 534 drp_bytes += request.raw_body_bytes; |
| 502 ++drp_resources; | 535 ++drp_resources; |
| 503 } | 536 } |
| 504 } | 537 } |
| 505 | 538 |
| 506 NavigateToUntrackedUrl(); | 539 NavigateToUntrackedUrl(); |
| 507 | 540 |
| 508 ValidateDataHistograms(network_resources, drp_resources, network_bytes, | 541 ValidateDataHistograms(network_resources, drp_resources, network_bytes, |
| 509 drp_bytes, ocl_bytes); | 542 drp_bytes, ocl_bytes); |
| 510 } | 543 } |
| 511 | 544 |
| 512 } // namespace data_reduction_proxy | 545 } // namespace data_reduction_proxy |
| OLD | NEW |