| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "net/nqe/network_quality_estimator.h" | 5 #include "net/nqe/network_quality_estimator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "net/http/http_status_code.h" | 33 #include "net/http/http_status_code.h" |
| 34 #include "net/log/test_net_log.h" | 34 #include "net/log/test_net_log.h" |
| 35 #include "net/nqe/effective_connection_type.h" | 35 #include "net/nqe/effective_connection_type.h" |
| 36 #include "net/nqe/external_estimate_provider.h" | 36 #include "net/nqe/external_estimate_provider.h" |
| 37 #include "net/nqe/network_quality_estimator_test_util.h" | 37 #include "net/nqe/network_quality_estimator_test_util.h" |
| 38 #include "net/nqe/network_quality_observation.h" | 38 #include "net/nqe/network_quality_observation.h" |
| 39 #include "net/nqe/network_quality_observation_source.h" | 39 #include "net/nqe/network_quality_observation_source.h" |
| 40 #include "net/nqe/observation_buffer.h" | 40 #include "net/nqe/observation_buffer.h" |
| 41 #include "net/socket/socket_performance_watcher.h" | 41 #include "net/socket/socket_performance_watcher.h" |
| 42 #include "net/socket/socket_performance_watcher_factory.h" | 42 #include "net/socket/socket_performance_watcher_factory.h" |
| 43 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 43 #include "net/url_request/url_request.h" | 44 #include "net/url_request/url_request.h" |
| 44 #include "net/url_request/url_request_test_util.h" | 45 #include "net/url_request/url_request_test_util.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
| 46 #include "url/gurl.h" | 47 #include "url/gurl.h" |
| 47 | 48 |
| 48 namespace { | 49 namespace { |
| 49 | 50 |
| 50 // Verifies that the number of samples in the bucket with minimum value | 51 // Verifies that the number of samples in the bucket with minimum value |
| 51 // |bucket_min| in |histogram| are at least |expected_min_count_samples|. | 52 // |bucket_min| in |histogram| are at least |expected_min_count_samples|. |
| 52 void ExpectBucketCountAtLeast(base::HistogramTester* histogram_tester, | 53 void ExpectBucketCountAtLeast(base::HistogramTester* histogram_tester, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 int32_t kbps; | 204 int32_t kbps; |
| 204 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 205 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 205 EXPECT_FALSE( | 206 EXPECT_FALSE( |
| 206 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 207 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 207 | 208 |
| 208 TestDelegate test_delegate; | 209 TestDelegate test_delegate; |
| 209 TestURLRequestContext context(true); | 210 TestURLRequestContext context(true); |
| 210 context.set_network_quality_estimator(&estimator); | 211 context.set_network_quality_estimator(&estimator); |
| 211 context.Init(); | 212 context.Init(); |
| 212 | 213 |
| 213 std::unique_ptr<URLRequest> request(context.CreateRequest( | 214 std::unique_ptr<URLRequest> request( |
| 214 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 215 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 216 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 215 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 217 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 216 request->Start(); | 218 request->Start(); |
| 217 base::RunLoop().Run(); | 219 base::RunLoop().Run(); |
| 218 | 220 |
| 219 // Both RTT and downstream throughput should be updated. | 221 // Both RTT and downstream throughput should be updated. |
| 220 base::TimeDelta http_rtt; | 222 base::TimeDelta http_rtt; |
| 221 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &http_rtt)); | 223 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &http_rtt)); |
| 222 EXPECT_TRUE( | 224 EXPECT_TRUE( |
| 223 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 225 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 224 base::TimeDelta transport_rtt; | 226 base::TimeDelta transport_rtt; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 EXPECT_LE(1u, | 258 EXPECT_LE(1u, |
| 257 histogram_tester.GetAllSamples("NQE.RTT.OnECTComputation").size()); | 259 histogram_tester.GetAllSamples("NQE.RTT.OnECTComputation").size()); |
| 258 EXPECT_LE(1u, | 260 EXPECT_LE(1u, |
| 259 histogram_tester.GetAllSamples("NQE.Kbps.OnECTComputation").size()); | 261 histogram_tester.GetAllSamples("NQE.Kbps.OnECTComputation").size()); |
| 260 | 262 |
| 261 histogram_tester.ExpectBucketCount( | 263 histogram_tester.ExpectBucketCount( |
| 262 "NQE.RTT.ObservationSource", NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, 1); | 264 "NQE.RTT.ObservationSource", NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, 1); |
| 263 histogram_tester.ExpectBucketCount( | 265 histogram_tester.ExpectBucketCount( |
| 264 "NQE.Kbps.ObservationSource", NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, 1); | 266 "NQE.Kbps.ObservationSource", NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, 1); |
| 265 | 267 |
| 266 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 268 std::unique_ptr<URLRequest> request2( |
| 267 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 269 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 270 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 268 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 271 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 269 request2->Start(); | 272 request2->Start(); |
| 270 base::RunLoop().Run(); | 273 base::RunLoop().Run(); |
| 271 histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType", 2); | 274 histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType", 2); |
| 272 histogram_tester.ExpectTotalCount( | 275 histogram_tester.ExpectTotalCount( |
| 273 "NQE.MainFrame.EffectiveConnectionType.Unknown", 2); | 276 "NQE.MainFrame.EffectiveConnectionType.Unknown", 2); |
| 274 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 1, | 277 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 1, |
| 275 1); | 278 1); |
| 276 histogram_tester.ExpectUniqueSample( | 279 histogram_tester.ExpectUniqueSample( |
| 277 "NQE.EstimateAvailable.MainFrame.TransportRTT", 0, 2); | 280 "NQE.EstimateAvailable.MainFrame.TransportRTT", 0, 2); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, std::string()); | 320 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, std::string()); |
| 318 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", | 321 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", |
| 319 false, 2); | 322 false, 2); |
| 320 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); | 323 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); |
| 321 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); | 324 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); |
| 322 | 325 |
| 323 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 326 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 324 EXPECT_FALSE( | 327 EXPECT_FALSE( |
| 325 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 328 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 326 | 329 |
| 327 std::unique_ptr<URLRequest> request3(context.CreateRequest( | 330 std::unique_ptr<URLRequest> request3( |
| 328 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 331 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 332 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 329 request3->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 333 request3->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 330 request3->Start(); | 334 request3->Start(); |
| 331 base::RunLoop().Run(); | 335 base::RunLoop().Run(); |
| 332 histogram_tester.ExpectUniqueSample( | 336 histogram_tester.ExpectUniqueSample( |
| 333 "NQE.MainFrame.EffectiveConnectionType.WiFi", | 337 "NQE.MainFrame.EffectiveConnectionType.WiFi", |
| 334 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); | 338 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); |
| 335 histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType", 3); | 339 histogram_tester.ExpectTotalCount("NQE.MainFrame.EffectiveConnectionType", 3); |
| 336 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 0, | 340 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 0, |
| 337 2); | 341 2); |
| 338 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 1, | 342 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.RTT", 1, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 377 |
| 374 TestDelegate test_delegate; | 378 TestDelegate test_delegate; |
| 375 TestURLRequestContext context(true); | 379 TestURLRequestContext context(true); |
| 376 context.set_network_quality_estimator(&estimator); | 380 context.set_network_quality_estimator(&estimator); |
| 377 context.Init(); | 381 context.Init(); |
| 378 | 382 |
| 379 // Start two requests so that the network quality is added to cache store at | 383 // Start two requests so that the network quality is added to cache store at |
| 380 // the beginning of the second request from the network traffic observed from | 384 // the beginning of the second request from the network traffic observed from |
| 381 // the first request. | 385 // the first request. |
| 382 for (size_t i = 0; i < 2; ++i) { | 386 for (size_t i = 0; i < 2; ++i) { |
| 383 std::unique_ptr<URLRequest> request(context.CreateRequest( | 387 std::unique_ptr<URLRequest> request( |
| 384 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 388 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 389 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 385 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 390 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 386 request->Start(); | 391 request->Start(); |
| 387 base::RunLoop().Run(); | 392 base::RunLoop().Run(); |
| 388 } | 393 } |
| 389 | 394 |
| 390 base::RunLoop().RunUntilIdle(); | 395 base::RunLoop().RunUntilIdle(); |
| 391 | 396 |
| 392 // Both RTT and downstream throughput should be updated. | 397 // Both RTT and downstream throughput should be updated. |
| 393 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 398 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 394 EXPECT_TRUE( | 399 EXPECT_TRUE( |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 483 |
| 479 TestDelegate test_delegate; | 484 TestDelegate test_delegate; |
| 480 TestURLRequestContext context(true); | 485 TestURLRequestContext context(true); |
| 481 context.set_network_quality_estimator(&estimator); | 486 context.set_network_quality_estimator(&estimator); |
| 482 context.Init(); | 487 context.Init(); |
| 483 | 488 |
| 484 // Start two requests so that the network quality is added to cache store at | 489 // Start two requests so that the network quality is added to cache store at |
| 485 // the beginning of the second request from the network traffic observed from | 490 // the beginning of the second request from the network traffic observed from |
| 486 // the first request. | 491 // the first request. |
| 487 for (size_t i = 0; i < 2; ++i) { | 492 for (size_t i = 0; i < 2; ++i) { |
| 488 std::unique_ptr<URLRequest> request(context.CreateRequest( | 493 std::unique_ptr<URLRequest> request( |
| 489 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 494 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 495 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 490 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 496 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 491 request->Start(); | 497 request->Start(); |
| 492 base::RunLoop().Run(); | 498 base::RunLoop().Run(); |
| 493 } | 499 } |
| 494 | 500 |
| 495 base::RunLoop().RunUntilIdle(); | 501 base::RunLoop().RunUntilIdle(); |
| 496 | 502 |
| 497 // Both RTT and downstream throughput should be updated. | 503 // Both RTT and downstream throughput should be updated. |
| 498 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 504 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 499 EXPECT_TRUE( | 505 EXPECT_TRUE( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 EXPECT_FALSE( | 553 EXPECT_FALSE( |
| 548 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 554 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 549 | 555 |
| 550 TestDelegate test_delegate; | 556 TestDelegate test_delegate; |
| 551 TestURLRequestContext context(true); | 557 TestURLRequestContext context(true); |
| 552 context.set_network_quality_estimator(&estimator); | 558 context.set_network_quality_estimator(&estimator); |
| 553 context.Init(); | 559 context.Init(); |
| 554 | 560 |
| 555 const size_t kMaxObservations = 10; | 561 const size_t kMaxObservations = 10; |
| 556 for (size_t i = 0; i < kMaxObservations; ++i) { | 562 for (size_t i = 0; i < kMaxObservations; ++i) { |
| 557 std::unique_ptr<URLRequest> request(context.CreateRequest( | 563 std::unique_ptr<URLRequest> request( |
| 558 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 564 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 565 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 559 request->Start(); | 566 request->Start(); |
| 560 base::RunLoop().Run(); | 567 base::RunLoop().Run(); |
| 561 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 568 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 562 EXPECT_TRUE( | 569 EXPECT_TRUE( |
| 563 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 570 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 564 } | 571 } |
| 565 | 572 |
| 566 // Verify that the stored observations are cleared on network change. | 573 // Verify that the stored observations are cleared on network change. |
| 567 estimator.SimulateNetworkChange( | 574 estimator.SimulateNetworkChange( |
| 568 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-2"); | 575 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-2"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 590 EXPECT_EQ(nqe::internal::kInvalidThroughput, | 597 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 591 estimator.GetDownlinkThroughputKbpsEstimateInternal( | 598 estimator.GetDownlinkThroughputKbpsEstimateInternal( |
| 592 base::TimeTicks(), 100)); | 599 base::TimeTicks(), 100)); |
| 593 | 600 |
| 594 TestDelegate test_delegate; | 601 TestDelegate test_delegate; |
| 595 TestURLRequestContext context(true); | 602 TestURLRequestContext context(true); |
| 596 context.set_network_quality_estimator(&estimator); | 603 context.set_network_quality_estimator(&estimator); |
| 597 context.Init(); | 604 context.Init(); |
| 598 | 605 |
| 599 for (size_t i = 0; i < 10U; ++i) { | 606 for (size_t i = 0; i < 10U; ++i) { |
| 600 std::unique_ptr<URLRequest> request(context.CreateRequest( | 607 std::unique_ptr<URLRequest> request( |
| 601 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 608 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 609 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 602 request->Start(); | 610 request->Start(); |
| 603 base::RunLoop().Run(); | 611 base::RunLoop().Run(); |
| 604 } | 612 } |
| 605 | 613 |
| 606 // Verify the percentiles through simple tests. | 614 // Verify the percentiles through simple tests. |
| 607 for (int i = 0; i <= 100; ++i) { | 615 for (int i = 0; i <= 100; ++i) { |
| 608 EXPECT_GT(estimator.GetDownlinkThroughputKbpsEstimateInternal( | 616 EXPECT_GT(estimator.GetDownlinkThroughputKbpsEstimateInternal( |
| 609 base::TimeTicks(), i), | 617 base::TimeTicks(), i), |
| 610 0); | 618 0); |
| 611 EXPECT_LT(estimator.GetRTTEstimateInternal( | 619 EXPECT_LT(estimator.GetRTTEstimateInternal( |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1630 | 1638 |
| 1631 TestDelegate test_delegate; | 1639 TestDelegate test_delegate; |
| 1632 TestURLRequestContext context(true); | 1640 TestURLRequestContext context(true); |
| 1633 context.set_network_quality_estimator(&estimator); | 1641 context.set_network_quality_estimator(&estimator); |
| 1634 context.Init(); | 1642 context.Init(); |
| 1635 | 1643 |
| 1636 for (size_t i = 0; i < 2; ++i) { | 1644 for (size_t i = 0; i < 2; ++i) { |
| 1637 // Start 2 requests to ensure that the RTT estimate computed by the network | 1645 // Start 2 requests to ensure that the RTT estimate computed by the network |
| 1638 // quality estimator takes into account the RTT observations from the | 1646 // quality estimator takes into account the RTT observations from the |
| 1639 // external estimate provider as well as organic observations. | 1647 // external estimate provider as well as organic observations. |
| 1640 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1648 std::unique_ptr<URLRequest> request( |
| 1641 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1649 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 1650 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1642 request->Start(); | 1651 request->Start(); |
| 1643 base::RunLoop().Run(); | 1652 base::RunLoop().Run(); |
| 1644 } | 1653 } |
| 1645 | 1654 |
| 1646 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1655 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1647 EXPECT_NE(external_estimate_provider_rtt, rtt); | 1656 EXPECT_NE(external_estimate_provider_rtt, rtt); |
| 1648 | 1657 |
| 1649 EXPECT_TRUE( | 1658 EXPECT_TRUE( |
| 1650 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 1659 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1651 EXPECT_NE(external_estimate_provider_downstream_throughput, kbps); | 1660 EXPECT_NE(external_estimate_provider_downstream_throughput, kbps); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1679 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1688 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1680 int32_t kbps; | 1689 int32_t kbps; |
| 1681 EXPECT_FALSE( | 1690 EXPECT_FALSE( |
| 1682 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 1691 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1683 | 1692 |
| 1684 TestDelegate test_delegate; | 1693 TestDelegate test_delegate; |
| 1685 TestURLRequestContext context(true); | 1694 TestURLRequestContext context(true); |
| 1686 context.set_network_quality_estimator(&estimator); | 1695 context.set_network_quality_estimator(&estimator); |
| 1687 context.Init(); | 1696 context.Init(); |
| 1688 | 1697 |
| 1689 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1698 std::unique_ptr<URLRequest> request( |
| 1690 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1699 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 1700 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1691 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1701 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1692 request->Start(); | 1702 request->Start(); |
| 1693 base::RunLoop().Run(); | 1703 base::RunLoop().Run(); |
| 1694 | 1704 |
| 1695 EXPECT_EQ(test.allow_small_localhost_requests, | 1705 EXPECT_EQ(test.allow_small_localhost_requests, |
| 1696 estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1706 estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1697 EXPECT_EQ( | 1707 EXPECT_EQ( |
| 1698 test.allow_small_localhost_requests, | 1708 test.allow_small_localhost_requests, |
| 1699 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 1709 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1700 } | 1710 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1731 context.Init(); | 1741 context.Init(); |
| 1732 | 1742 |
| 1733 EXPECT_EQ(0U, observer.effective_connection_types().size()); | 1743 EXPECT_EQ(0U, observer.effective_connection_types().size()); |
| 1734 | 1744 |
| 1735 estimator.set_start_time_null_http_rtt( | 1745 estimator.set_start_time_null_http_rtt( |
| 1736 base::TimeDelta::FromMilliseconds(1500)); | 1746 base::TimeDelta::FromMilliseconds(1500)); |
| 1737 estimator.set_start_time_null_downlink_throughput_kbps(100000); | 1747 estimator.set_start_time_null_downlink_throughput_kbps(100000); |
| 1738 | 1748 |
| 1739 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); | 1749 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| 1740 | 1750 |
| 1741 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1751 std::unique_ptr<URLRequest> request( |
| 1742 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1752 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 1753 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1743 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1754 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1744 request->Start(); | 1755 request->Start(); |
| 1745 base::RunLoop().Run(); | 1756 base::RunLoop().Run(); |
| 1746 EXPECT_EQ(1U, observer.effective_connection_types().size()); | 1757 EXPECT_EQ(1U, observer.effective_connection_types().size()); |
| 1747 EXPECT_LE( | 1758 EXPECT_LE( |
| 1748 1, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); | 1759 1, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); |
| 1749 | 1760 |
| 1750 // Verify the contents of the net log. | 1761 // Verify the contents of the net log. |
| 1751 EXPECT_EQ(GetNameForEffectiveConnectionType(EFFECTIVE_CONNECTION_TYPE_2G), | 1762 EXPECT_EQ(GetNameForEffectiveConnectionType(EFFECTIVE_CONNECTION_TYPE_2G), |
| 1752 estimator.GetNetLogLastStringValue( | 1763 estimator.GetNetLogLastStringValue( |
| 1753 NetLogEventType::NETWORK_QUALITY_CHANGED, | 1764 NetLogEventType::NETWORK_QUALITY_CHANGED, |
| 1754 "effective_connection_type")); | 1765 "effective_connection_type")); |
| 1755 EXPECT_EQ(1500, estimator.GetNetLogLastIntegerValue( | 1766 EXPECT_EQ(1500, estimator.GetNetLogLastIntegerValue( |
| 1756 NetLogEventType::NETWORK_QUALITY_CHANGED, "http_rtt_ms")); | 1767 NetLogEventType::NETWORK_QUALITY_CHANGED, "http_rtt_ms")); |
| 1757 EXPECT_EQ(-1, | 1768 EXPECT_EQ(-1, |
| 1758 estimator.GetNetLogLastIntegerValue( | 1769 estimator.GetNetLogLastIntegerValue( |
| 1759 NetLogEventType::NETWORK_QUALITY_CHANGED, "transport_rtt_ms")); | 1770 NetLogEventType::NETWORK_QUALITY_CHANGED, "transport_rtt_ms")); |
| 1760 EXPECT_EQ(100000, estimator.GetNetLogLastIntegerValue( | 1771 EXPECT_EQ(100000, estimator.GetNetLogLastIntegerValue( |
| 1761 NetLogEventType::NETWORK_QUALITY_CHANGED, | 1772 NetLogEventType::NETWORK_QUALITY_CHANGED, |
| 1762 "downstream_throughput_kbps")); | 1773 "downstream_throughput_kbps")); |
| 1763 | 1774 |
| 1764 histogram_tester.ExpectUniqueSample("NQE.MainFrame.EffectiveConnectionType", | 1775 histogram_tester.ExpectUniqueSample("NQE.MainFrame.EffectiveConnectionType", |
| 1765 EFFECTIVE_CONNECTION_TYPE_2G, 1); | 1776 EFFECTIVE_CONNECTION_TYPE_2G, 1); |
| 1766 histogram_tester.ExpectUniqueSample( | 1777 histogram_tester.ExpectUniqueSample( |
| 1767 "NQE.MainFrame.EffectiveConnectionType.Unknown", | 1778 "NQE.MainFrame.EffectiveConnectionType.Unknown", |
| 1768 EFFECTIVE_CONNECTION_TYPE_2G, 1); | 1779 EFFECTIVE_CONNECTION_TYPE_2G, 1); |
| 1769 | 1780 |
| 1770 // Next request should not trigger recomputation of effective connection type | 1781 // Next request should not trigger recomputation of effective connection type |
| 1771 // since there has been no change in the clock. | 1782 // since there has been no change in the clock. |
| 1772 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 1783 std::unique_ptr<URLRequest> request2( |
| 1773 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1784 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 1785 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1774 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1786 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1775 request2->Start(); | 1787 request2->Start(); |
| 1776 base::RunLoop().Run(); | 1788 base::RunLoop().Run(); |
| 1777 EXPECT_EQ(1U, observer.effective_connection_types().size()); | 1789 EXPECT_EQ(1U, observer.effective_connection_types().size()); |
| 1778 | 1790 |
| 1779 // Change in connection type should send out notification to the observers. | 1791 // Change in connection type should send out notification to the observers. |
| 1780 estimator.set_start_time_null_http_rtt( | 1792 estimator.set_start_time_null_http_rtt( |
| 1781 base::TimeDelta::FromMilliseconds(500)); | 1793 base::TimeDelta::FromMilliseconds(500)); |
| 1782 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, | 1794 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, |
| 1783 "test"); | 1795 "test"); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1834 | 1846 |
| 1835 base::TimeDelta http_rtt(base::TimeDelta::FromMilliseconds(100)); | 1847 base::TimeDelta http_rtt(base::TimeDelta::FromMilliseconds(100)); |
| 1836 base::TimeDelta transport_rtt(base::TimeDelta::FromMilliseconds(200)); | 1848 base::TimeDelta transport_rtt(base::TimeDelta::FromMilliseconds(200)); |
| 1837 int32_t downstream_throughput_kbps(300); | 1849 int32_t downstream_throughput_kbps(300); |
| 1838 estimator.set_start_time_null_http_rtt(http_rtt); | 1850 estimator.set_start_time_null_http_rtt(http_rtt); |
| 1839 estimator.set_start_time_null_transport_rtt(transport_rtt); | 1851 estimator.set_start_time_null_transport_rtt(transport_rtt); |
| 1840 estimator.set_start_time_null_downlink_throughput_kbps( | 1852 estimator.set_start_time_null_downlink_throughput_kbps( |
| 1841 downstream_throughput_kbps); | 1853 downstream_throughput_kbps); |
| 1842 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); | 1854 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| 1843 | 1855 |
| 1844 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1856 std::unique_ptr<URLRequest> request( |
| 1845 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1857 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 1858 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1846 request->Start(); | 1859 request->Start(); |
| 1847 base::RunLoop().Run(); | 1860 base::RunLoop().Run(); |
| 1848 EXPECT_EQ(http_rtt, observer.http_rtt()); | 1861 EXPECT_EQ(http_rtt, observer.http_rtt()); |
| 1849 EXPECT_EQ(transport_rtt, observer.transport_rtt()); | 1862 EXPECT_EQ(transport_rtt, observer.transport_rtt()); |
| 1850 EXPECT_EQ(downstream_throughput_kbps, observer.downstream_throughput_kbps()); | 1863 EXPECT_EQ(downstream_throughput_kbps, observer.downstream_throughput_kbps()); |
| 1851 EXPECT_LE(1, observer.notifications_received() - notifications_received); | 1864 EXPECT_LE(1, observer.notifications_received() - notifications_received); |
| 1852 notifications_received = observer.notifications_received(); | 1865 notifications_received = observer.notifications_received(); |
| 1853 | 1866 |
| 1854 // The next request should not trigger recomputation of RTT or throughput | 1867 // The next request should not trigger recomputation of RTT or throughput |
| 1855 // since there has been no change in the clock. | 1868 // since there has been no change in the clock. |
| 1856 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 1869 std::unique_ptr<URLRequest> request2( |
| 1857 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1870 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 1871 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1858 request2->Start(); | 1872 request2->Start(); |
| 1859 base::RunLoop().Run(); | 1873 base::RunLoop().Run(); |
| 1860 EXPECT_LE(1, observer.notifications_received() - notifications_received); | 1874 EXPECT_LE(1, observer.notifications_received() - notifications_received); |
| 1861 notifications_received = observer.notifications_received(); | 1875 notifications_received = observer.notifications_received(); |
| 1862 | 1876 |
| 1863 // A change in the connection type should send out notification to the | 1877 // A change in the connection type should send out notification to the |
| 1864 // observers. | 1878 // observers. |
| 1865 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, | 1879 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, |
| 1866 "test"); | 1880 "test"); |
| 1867 EXPECT_EQ(http_rtt, observer.http_rtt()); | 1881 EXPECT_EQ(http_rtt, observer.http_rtt()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1972 TestDelegate test_delegate; | 1986 TestDelegate test_delegate; |
| 1973 TestURLRequestContext context(true); | 1987 TestURLRequestContext context(true); |
| 1974 context.set_network_quality_estimator(&estimator); | 1988 context.set_network_quality_estimator(&estimator); |
| 1975 context.Init(); | 1989 context.Init(); |
| 1976 | 1990 |
| 1977 EXPECT_EQ(0U, observer.effective_connection_types().size()); | 1991 EXPECT_EQ(0U, observer.effective_connection_types().size()); |
| 1978 | 1992 |
| 1979 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); | 1993 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
| 1980 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); | 1994 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| 1981 | 1995 |
| 1982 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1996 std::unique_ptr<URLRequest> request( |
| 1983 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1997 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 1998 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1984 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1999 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1985 request->Start(); | 2000 request->Start(); |
| 1986 base::RunLoop().Run(); | 2001 base::RunLoop().Run(); |
| 1987 EXPECT_EQ(1U, observer.effective_connection_types().size()); | 2002 EXPECT_EQ(1U, observer.effective_connection_types().size()); |
| 1988 histogram_tester.ExpectUniqueSample("NQE.MainFrame.EffectiveConnectionType", | 2003 histogram_tester.ExpectUniqueSample("NQE.MainFrame.EffectiveConnectionType", |
| 1989 EFFECTIVE_CONNECTION_TYPE_2G, 1); | 2004 EFFECTIVE_CONNECTION_TYPE_2G, 1); |
| 1990 histogram_tester.ExpectUniqueSample( | 2005 histogram_tester.ExpectUniqueSample( |
| 1991 "NQE.MainFrame.EffectiveConnectionType.WiFi", | 2006 "NQE.MainFrame.EffectiveConnectionType.WiFi", |
| 1992 EFFECTIVE_CONNECTION_TYPE_2G, 1); | 2007 EFFECTIVE_CONNECTION_TYPE_2G, 1); |
| 1993 histogram_tester.ExpectUniqueSample("NQE.EstimateAvailable.MainFrame.RTT", 0, | 2008 histogram_tester.ExpectUniqueSample("NQE.EstimateAvailable.MainFrame.RTT", 0, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2056 | 2071 |
| 2057 TestDelegate test_delegate; | 2072 TestDelegate test_delegate; |
| 2058 TestURLRequestContext context(true); | 2073 TestURLRequestContext context(true); |
| 2059 context.set_network_quality_estimator(&estimator); | 2074 context.set_network_quality_estimator(&estimator); |
| 2060 context.Init(); | 2075 context.Init(); |
| 2061 | 2076 |
| 2062 EXPECT_EQ(0U, rtt_observer.observations().size()); | 2077 EXPECT_EQ(0U, rtt_observer.observations().size()); |
| 2063 EXPECT_EQ(0U, throughput_observer.observations().size()); | 2078 EXPECT_EQ(0U, throughput_observer.observations().size()); |
| 2064 base::TimeTicks then = base::TimeTicks::Now(); | 2079 base::TimeTicks then = base::TimeTicks::Now(); |
| 2065 | 2080 |
| 2066 std::unique_ptr<URLRequest> request(context.CreateRequest( | 2081 std::unique_ptr<URLRequest> request( |
| 2067 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 2082 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 2083 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2068 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 2084 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 2069 request->Start(); | 2085 request->Start(); |
| 2070 base::RunLoop().Run(); | 2086 base::RunLoop().Run(); |
| 2071 | 2087 |
| 2072 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 2088 std::unique_ptr<URLRequest> request2( |
| 2073 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 2089 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 2090 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2074 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 2091 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 2075 request2->Start(); | 2092 request2->Start(); |
| 2076 base::RunLoop().Run(); | 2093 base::RunLoop().Run(); |
| 2077 | 2094 |
| 2078 // Both RTT and downstream throughput should be updated. | 2095 // Both RTT and downstream throughput should be updated. |
| 2079 base::TimeDelta rtt; | 2096 base::TimeDelta rtt; |
| 2080 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 2097 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 2081 | 2098 |
| 2082 int32_t throughput; | 2099 int32_t throughput; |
| 2083 EXPECT_TRUE(estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), | 2100 EXPECT_TRUE(estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2174 // Send two requests. Verify that the completion of each request generates at | 2191 // Send two requests. Verify that the completion of each request generates at |
| 2175 // least one TCP RTT observation. | 2192 // least one TCP RTT observation. |
| 2176 const size_t num_requests = 2; | 2193 const size_t num_requests = 2; |
| 2177 for (size_t i = 0; i < num_requests; ++i) { | 2194 for (size_t i = 0; i < num_requests; ++i) { |
| 2178 size_t before_count_tcp_rtt_observations = 0; | 2195 size_t before_count_tcp_rtt_observations = 0; |
| 2179 for (const auto& observation : rtt_observer.observations()) { | 2196 for (const auto& observation : rtt_observer.observations()) { |
| 2180 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) | 2197 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) |
| 2181 ++before_count_tcp_rtt_observations; | 2198 ++before_count_tcp_rtt_observations; |
| 2182 } | 2199 } |
| 2183 | 2200 |
| 2184 std::unique_ptr<URLRequest> request(context.CreateRequest( | 2201 std::unique_ptr<URLRequest> request( |
| 2185 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 2202 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 2203 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2186 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 2204 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 2187 request->Start(); | 2205 request->Start(); |
| 2188 base::RunLoop().Run(); | 2206 base::RunLoop().Run(); |
| 2189 | 2207 |
| 2190 size_t after_count_tcp_rtt_observations = 0; | 2208 size_t after_count_tcp_rtt_observations = 0; |
| 2191 for (const auto& observation : rtt_observer.observations()) { | 2209 for (const auto& observation : rtt_observer.observations()) { |
| 2192 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) | 2210 if (observation.source == NETWORK_QUALITY_OBSERVATION_SOURCE_TCP) |
| 2193 ++after_count_tcp_rtt_observations; | 2211 ++after_count_tcp_rtt_observations; |
| 2194 } | 2212 } |
| 2195 // At least one notification should be received per socket performance | 2213 // At least one notification should be received per socket performance |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2334 | 2352 |
| 2335 base::HistogramTester histogram_tester; | 2353 base::HistogramTester histogram_tester; |
| 2336 | 2354 |
| 2337 TestDelegate test_delegate; | 2355 TestDelegate test_delegate; |
| 2338 TestURLRequestContext context(true); | 2356 TestURLRequestContext context(true); |
| 2339 context.set_network_quality_estimator(&estimator); | 2357 context.set_network_quality_estimator(&estimator); |
| 2340 context.Init(); | 2358 context.Init(); |
| 2341 | 2359 |
| 2342 // Start a main-frame request which should cause network quality estimator | 2360 // Start a main-frame request which should cause network quality estimator |
| 2343 // to record accuracy UMA. | 2361 // to record accuracy UMA. |
| 2344 std::unique_ptr<URLRequest> request(context.CreateRequest( | 2362 std::unique_ptr<URLRequest> request( |
| 2345 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 2363 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 2364 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2346 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 2365 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 2347 request->Start(); | 2366 request->Start(); |
| 2348 base::RunLoop().Run(); | 2367 base::RunLoop().Run(); |
| 2349 | 2368 |
| 2350 if (accuracy_recording_delay != base::TimeDelta()) { | 2369 if (accuracy_recording_delay != base::TimeDelta()) { |
| 2351 tick_clock_ptr->Advance(accuracy_recording_delay); | 2370 tick_clock_ptr->Advance(accuracy_recording_delay); |
| 2352 | 2371 |
| 2353 // Sleep for some time to ensure that the delayed task is posted. | 2372 // Sleep for some time to ensure that the delayed task is posted. |
| 2354 base::PlatformThread::Sleep(accuracy_recording_delay * 2); | 2373 base::PlatformThread::Sleep(accuracy_recording_delay * 2); |
| 2355 base::RunLoop().RunUntilIdle(); | 2374 base::RunLoop().RunUntilIdle(); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2602 TestDelegate test_delegate; | 2621 TestDelegate test_delegate; |
| 2603 TestURLRequestContext context(true); | 2622 TestURLRequestContext context(true); |
| 2604 context.set_network_quality_estimator(&estimator); | 2623 context.set_network_quality_estimator(&estimator); |
| 2605 context.Init(); | 2624 context.Init(); |
| 2606 | 2625 |
| 2607 histogram_tester.ExpectTotalCount( | 2626 histogram_tester.ExpectTotalCount( |
| 2608 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); | 2627 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); |
| 2609 | 2628 |
| 2610 // Start a main-frame request that should cause network quality estimator to | 2629 // Start a main-frame request that should cause network quality estimator to |
| 2611 // record the network quality at the last main frame request. | 2630 // record the network quality at the last main frame request. |
| 2612 std::unique_ptr<URLRequest> request_1(context.CreateRequest( | 2631 std::unique_ptr<URLRequest> request_1( |
| 2613 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 2632 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 2633 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2614 request_1->SetLoadFlags(request_1->load_flags() | | 2634 request_1->SetLoadFlags(request_1->load_flags() | |
| 2615 LOAD_MAIN_FRAME_DEPRECATED); | 2635 LOAD_MAIN_FRAME_DEPRECATED); |
| 2616 request_1->Start(); | 2636 request_1->Start(); |
| 2617 base::RunLoop().Run(); | 2637 base::RunLoop().Run(); |
| 2618 | 2638 |
| 2619 if (test.rand_double >= test.correlation_logging_probability) { | 2639 if (test.rand_double >= test.correlation_logging_probability) { |
| 2620 histogram_tester.ExpectTotalCount( | 2640 histogram_tester.ExpectTotalCount( |
| 2621 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); | 2641 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); |
| 2622 continue; | 2642 continue; |
| 2623 } | 2643 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 (buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric) % 128); | 2680 (buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric) % 128); |
| 2661 | 2681 |
| 2662 // Get the bits at index 18-24 which contain the resource fetch time. | 2682 // Get the bits at index 18-24 which contain the resource fetch time. |
| 2663 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128); | 2683 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128); |
| 2664 | 2684 |
| 2665 // Get the bits at index 25-31 which contain the resource load size. | 2685 // Get the bits at index 25-31 which contain the resource load size. |
| 2666 EXPECT_LE(0, (buckets.at(0).min) % 128); | 2686 EXPECT_LE(0, (buckets.at(0).min) % 128); |
| 2667 | 2687 |
| 2668 // Start another main-frame request which is redirected to an HTTPS URL. | 2688 // Start another main-frame request which is redirected to an HTTPS URL. |
| 2669 // Redirection should not cause any crashes. | 2689 // Redirection should not cause any crashes. |
| 2670 std::unique_ptr<URLRequest> request_3(context.CreateRequest( | 2690 std::unique_ptr<URLRequest> request_3( |
| 2671 estimator.GetRedirectURL(), DEFAULT_PRIORITY, &test_delegate)); | 2691 context.CreateRequest(estimator.GetRedirectURL(), DEFAULT_PRIORITY, |
| 2692 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2672 request_3->Start(); | 2693 request_3->Start(); |
| 2673 base::RunLoop().Run(); | 2694 base::RunLoop().Run(); |
| 2674 EXPECT_FALSE(request_3->original_url().SchemeIsCryptographic()); | 2695 EXPECT_FALSE(request_3->original_url().SchemeIsCryptographic()); |
| 2675 EXPECT_TRUE(request_3->url().SchemeIsCryptographic()); | 2696 EXPECT_TRUE(request_3->url().SchemeIsCryptographic()); |
| 2676 EXPECT_TRUE(!request_3->response_info().headers.get() || | 2697 EXPECT_TRUE(!request_3->response_info().headers.get() || |
| 2677 request_3->response_info().headers->response_code() != HTTP_OK); | 2698 request_3->response_info().headers->response_code() != HTTP_OK); |
| 2678 // Correlation metric should not be logged for redirected requests. | 2699 // Correlation metric should not be logged for redirected requests. |
| 2679 histogram_tester.ExpectTotalCount( | 2700 histogram_tester.ExpectTotalCount( |
| 2680 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 1); | 2701 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 1); |
| 2681 } | 2702 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2776 // that the notification to |observer| is finished. | 2797 // that the notification to |observer| is finished. |
| 2777 base::RunLoop().RunUntilIdle(); | 2798 base::RunLoop().RunUntilIdle(); |
| 2778 | 2799 |
| 2779 TestDelegate test_delegate; | 2800 TestDelegate test_delegate; |
| 2780 TestURLRequestContext context(true); | 2801 TestURLRequestContext context(true); |
| 2781 context.set_network_quality_estimator(&estimator); | 2802 context.set_network_quality_estimator(&estimator); |
| 2782 context.Init(); | 2803 context.Init(); |
| 2783 | 2804 |
| 2784 EXPECT_EQ(0U, observer.effective_connection_types().size()); | 2805 EXPECT_EQ(0U, observer.effective_connection_types().size()); |
| 2785 | 2806 |
| 2786 std::unique_ptr<URLRequest> request(context.CreateRequest( | 2807 std::unique_ptr<URLRequest> request( |
| 2787 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 2808 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 2809 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2788 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 2810 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 2789 request->Start(); | 2811 request->Start(); |
| 2790 base::RunLoop().Run(); | 2812 base::RunLoop().Run(); |
| 2791 | 2813 |
| 2792 EXPECT_EQ(i, estimator.GetEffectiveConnectionType()); | 2814 EXPECT_EQ(i, estimator.GetEffectiveConnectionType()); |
| 2793 | 2815 |
| 2794 size_t expected_count = static_cast<EffectiveConnectionType>(i) == | 2816 size_t expected_count = static_cast<EffectiveConnectionType>(i) == |
| 2795 EFFECTIVE_CONNECTION_TYPE_UNKNOWN | 2817 EFFECTIVE_CONNECTION_TYPE_UNKNOWN |
| 2796 ? 0 | 2818 ? 0 |
| 2797 : 1; | 2819 : 1; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2896 estimator.set_start_time_null_http_rtt( | 2918 estimator.set_start_time_null_http_rtt( |
| 2897 estimator.typical_network_quality_[effective_connection_type] | 2919 estimator.typical_network_quality_[effective_connection_type] |
| 2898 .http_rtt()); | 2920 .http_rtt()); |
| 2899 estimator.set_start_time_null_transport_rtt( | 2921 estimator.set_start_time_null_transport_rtt( |
| 2900 estimator.typical_network_quality_[effective_connection_type] | 2922 estimator.typical_network_quality_[effective_connection_type] |
| 2901 .transport_rtt()); | 2923 .transport_rtt()); |
| 2902 estimator.set_start_time_null_downlink_throughput_kbps(INT32_MAX); | 2924 estimator.set_start_time_null_downlink_throughput_kbps(INT32_MAX); |
| 2903 | 2925 |
| 2904 // Force recomputation of effective connection type by starting a main | 2926 // Force recomputation of effective connection type by starting a main |
| 2905 // frame request. | 2927 // frame request. |
| 2906 std::unique_ptr<URLRequest> request(context.CreateRequest( | 2928 std::unique_ptr<URLRequest> request( |
| 2907 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 2929 context.CreateRequest(estimator.GetEchoURL(), DEFAULT_PRIORITY, |
| 2930 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2908 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 2931 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 2909 request->Start(); | 2932 request->Start(); |
| 2910 base::RunLoop().Run(); | 2933 base::RunLoop().Run(); |
| 2911 | 2934 |
| 2912 EXPECT_EQ(effective_connection_type, | 2935 EXPECT_EQ(effective_connection_type, |
| 2913 estimator.GetEffectiveConnectionType()); | 2936 estimator.GetEffectiveConnectionType()); |
| 2914 } | 2937 } |
| 2915 } | 2938 } |
| 2916 } | 2939 } |
| 2917 | 2940 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3117 | 3140 |
| 3118 // Cleanup. | 3141 // Cleanup. |
| 3119 estimator.RemoveRTTObserver(&rtt_observer); | 3142 estimator.RemoveRTTObserver(&rtt_observer); |
| 3120 estimator.RemoveThroughputObserver(&throughput_observer); | 3143 estimator.RemoveThroughputObserver(&throughput_observer); |
| 3121 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); | 3144 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); |
| 3122 estimator.RemoveEffectiveConnectionTypeObserver( | 3145 estimator.RemoveEffectiveConnectionTypeObserver( |
| 3123 &effective_connection_type_observer); | 3146 &effective_connection_type_observer); |
| 3124 } | 3147 } |
| 3125 | 3148 |
| 3126 } // namespace net | 3149 } // namespace net |
| OLD | NEW |