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 */, nullptr}, |
426 0 /* original_network_content_length */}, | |
427 // Uncached non-proxied request. | 460 // Uncached non-proxied request. |
428 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 461 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
429 false /* data_reduction_proxy_used*/, | 462 1024 * 40 /* original_network_content_length */, nullptr}, |
430 1024 * 40 /* original_network_content_length */}, | |
431 // Uncached proxied request with .1 compression ratio. | 463 // Uncached proxied request with .1 compression ratio. |
432 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 464 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
433 true /* data_reduction_proxy_used*/, | 465 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. | 466 // Uncached proxied request with .5 compression ratio. |
436 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 467 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
437 true /* data_reduction_proxy_used*/, | 468 1024 * 40 * 5 /* original_network_content_length */, std::move(data)}, |
438 1024 * 40 * 5 /* original_network_content_length */}, | |
439 }; | 469 }; |
440 | 470 |
441 int network_resources = 0; | 471 int network_resources = 0; |
442 int drp_resources = 0; | 472 int drp_resources = 0; |
443 int64_t network_bytes = 0; | 473 int64_t network_bytes = 0; |
444 int64_t drp_bytes = 0; | 474 int64_t drp_bytes = 0; |
445 int64_t ocl_bytes = 0; | 475 int64_t ocl_bytes = 0; |
446 for (auto request : resources) { | 476 for (const auto& request : resources) { |
447 SimulateLoadedResource(request); | 477 SimulateLoadedResource(request); |
448 if (!request.was_cached) { | 478 if (!request.was_cached) { |
449 network_bytes += request.raw_body_bytes; | 479 network_bytes += request.raw_body_bytes; |
450 ocl_bytes += request.original_network_content_length; | 480 ocl_bytes += request.original_network_content_length; |
451 ++network_resources; | 481 ++network_resources; |
452 } | 482 } |
453 if (request.data_reduction_proxy_used) { | 483 if (request.data_reduction_proxy_data && |
| 484 request.data_reduction_proxy_data->used_data_reduction_proxy()) { |
454 drp_bytes += request.raw_body_bytes; | 485 drp_bytes += request.raw_body_bytes; |
455 ++drp_resources; | 486 ++drp_resources; |
456 } | 487 } |
457 } | 488 } |
458 | 489 |
459 NavigateToUntrackedUrl(); | 490 NavigateToUntrackedUrl(); |
460 | 491 |
461 ValidateDataHistograms(network_resources, drp_resources, network_bytes, | 492 ValidateDataHistograms(network_resources, drp_resources, network_bytes, |
462 drp_bytes, ocl_bytes); | 493 drp_bytes, ocl_bytes); |
463 } | 494 } |
464 | 495 |
465 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) { | 496 TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) { |
466 ResetTest(); | 497 ResetTest(); |
467 | 498 |
468 RunTest(true, false); | 499 RunTest(true, false); |
469 | 500 |
| 501 std::unique_ptr<DataReductionProxyData> data = |
| 502 base::MakeUnique<DataReductionProxyData>(); |
| 503 data->set_used_data_reduction_proxy(true); |
| 504 |
470 // Prepare 4 resources of varying size and configurations. | 505 // Prepare 4 resources of varying size and configurations. |
471 page_load_metrics::ExtraRequestInfo resources[] = { | 506 page_load_metrics::ExtraRequestInfo resources[] = { |
472 // Cached request. | 507 // Cached request. |
473 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 508 {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
474 false /* data_reduction_proxy_used*/, | 509 0 /* original_network_content_length */, nullptr}, |
475 0 /* original_network_content_length */}, | |
476 // Uncached non-proxied request. | 510 // Uncached non-proxied request. |
477 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | 511 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
478 false /* data_reduction_proxy_used*/, | 512 1024 * 40 /* original_network_content_length */, nullptr}, |
479 1024 * 40 /* original_network_content_length */}, | |
480 // Uncached proxied request with .1 compression ratio. | 513 // Uncached proxied request with .1 compression ratio. |
481 {false /*was_cached*/, 1024 * 40 * 10 /* raw_body_bytes */, | 514 {false /*was_cached*/, 1024 * 40 * 10 /* raw_body_bytes */, |
482 true /* data_reduction_proxy_used*/, | 515 1024 * 40 /* original_network_content_length */, data->DeepCopy()}, |
483 1024 * 40 /* original_network_content_length */}, | |
484 // Uncached proxied request with .5 compression ratio. | 516 // Uncached proxied request with .5 compression ratio. |
485 {false /*was_cached*/, 1024 * 40 * 5 /* raw_body_bytes */, | 517 {false /*was_cached*/, 1024 * 40 * 5 /* raw_body_bytes */, |
486 true /* data_reduction_proxy_used*/, | 518 1024 * 40 /* original_network_content_length */, std::move(data)}, |
487 1024 * 40 /* original_network_content_length */}, | |
488 }; | 519 }; |
489 | 520 |
490 int network_resources = 0; | 521 int network_resources = 0; |
491 int drp_resources = 0; | 522 int drp_resources = 0; |
492 int64_t network_bytes = 0; | 523 int64_t network_bytes = 0; |
493 int64_t drp_bytes = 0; | 524 int64_t drp_bytes = 0; |
494 int64_t ocl_bytes = 0; | 525 int64_t ocl_bytes = 0; |
495 for (auto request : resources) { | 526 for (const auto& request : resources) { |
496 SimulateLoadedResource(request); | 527 SimulateLoadedResource(request); |
497 if (!request.was_cached) { | 528 if (!request.was_cached) { |
498 network_bytes += request.raw_body_bytes; | 529 network_bytes += request.raw_body_bytes; |
499 ocl_bytes += request.original_network_content_length; | 530 ocl_bytes += request.original_network_content_length; |
500 ++network_resources; | 531 ++network_resources; |
501 } | 532 } |
502 if (request.data_reduction_proxy_used) { | 533 if (request.data_reduction_proxy_data && |
| 534 request.data_reduction_proxy_data->used_data_reduction_proxy()) { |
503 drp_bytes += request.raw_body_bytes; | 535 drp_bytes += request.raw_body_bytes; |
504 ++drp_resources; | 536 ++drp_resources; |
505 } | 537 } |
506 } | 538 } |
507 | 539 |
508 NavigateToUntrackedUrl(); | 540 NavigateToUntrackedUrl(); |
509 | 541 |
510 ValidateDataHistograms(network_resources, drp_resources, network_bytes, | 542 ValidateDataHistograms(network_resources, drp_resources, network_bytes, |
511 drp_bytes, ocl_bytes); | 543 drp_bytes, ocl_bytes); |
512 } | 544 } |
513 | 545 |
514 } // namespace data_reduction_proxy | 546 } // namespace data_reduction_proxy |
OLD | NEW |