| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 context.set_network_quality_estimator(&estimator); | 185 context.set_network_quality_estimator(&estimator); |
| 186 context.Init(); | 186 context.Init(); |
| 187 | 187 |
| 188 std::unique_ptr<URLRequest> request(context.CreateRequest( | 188 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 189 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 189 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 190 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 190 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 191 request->Start(); | 191 request->Start(); |
| 192 base::RunLoop().Run(); | 192 base::RunLoop().Run(); |
| 193 | 193 |
| 194 // Both RTT and downstream throughput should be updated. | 194 // Both RTT and downstream throughput should be updated. |
| 195 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 195 base::TimeDelta http_rtt; |
| 196 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &http_rtt)); |
| 196 EXPECT_TRUE( | 197 EXPECT_TRUE( |
| 197 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 198 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 198 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 199 base::TimeDelta transport_rtt; |
| 200 EXPECT_FALSE( |
| 201 estimator.GetRecentTransportRTT(base::TimeTicks(), &transport_rtt)); |
| 199 | 202 |
| 203 // Verify the contents of the net log. |
| 200 EXPECT_EQ( | 204 EXPECT_EQ( |
| 201 1, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); | 205 2, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); |
| 206 EXPECT_EQ(http_rtt.InMilliseconds(), |
| 207 estimator.GetNetLogLastIntegerValue( |
| 208 NetLogEventType::NETWORK_QUALITY_CHANGED, "http_rtt_ms")); |
| 209 EXPECT_EQ(-1, |
| 210 estimator.GetNetLogLastIntegerValue( |
| 211 NetLogEventType::NETWORK_QUALITY_CHANGED, "transport_rtt_ms")); |
| 212 EXPECT_EQ(kbps, estimator.GetNetLogLastIntegerValue( |
| 213 NetLogEventType::NETWORK_QUALITY_CHANGED, |
| 214 "downstream_throughput_kbps")); |
| 202 | 215 |
| 203 // Check UMA histograms. | 216 // Check UMA histograms. |
| 204 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); | 217 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); |
| 205 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); | 218 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); |
| 206 histogram_tester.ExpectUniqueSample( | 219 histogram_tester.ExpectUniqueSample( |
| 207 "NQE.MainFrame.EffectiveConnectionType", | 220 "NQE.MainFrame.EffectiveConnectionType", |
| 208 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); | 221 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); |
| 209 histogram_tester.ExpectUniqueSample( | 222 histogram_tester.ExpectUniqueSample( |
| 210 "NQE.MainFrame.EffectiveConnectionType.Unknown", | 223 "NQE.MainFrame.EffectiveConnectionType.Unknown", |
| 211 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); | 224 EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 1); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 estimator.AddEffectiveConnectionTypeObserver(&observer); | 367 estimator.AddEffectiveConnectionTypeObserver(&observer); |
| 355 TestRTTObserver rtt_observer; | 368 TestRTTObserver rtt_observer; |
| 356 estimator.AddRTTObserver(&rtt_observer); | 369 estimator.AddRTTObserver(&rtt_observer); |
| 357 TestThroughputObserver throughput_observer; | 370 TestThroughputObserver throughput_observer; |
| 358 estimator.AddThroughputObserver(&throughput_observer); | 371 estimator.AddThroughputObserver(&throughput_observer); |
| 359 | 372 |
| 360 // |observer| should be notified as soon as it is added. | 373 // |observer| should be notified as soon as it is added. |
| 361 base::RunLoop().RunUntilIdle(); | 374 base::RunLoop().RunUntilIdle(); |
| 362 EXPECT_EQ(1U, observer.effective_connection_types().size()); | 375 EXPECT_EQ(1U, observer.effective_connection_types().size()); |
| 363 EXPECT_EQ( | 376 EXPECT_EQ( |
| 364 1, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); | 377 2, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); |
| 365 | 378 |
| 366 estimator.SimulateNetworkChange( | 379 estimator.SimulateNetworkChange( |
| 367 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test"); | 380 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test"); |
| 368 | 381 |
| 382 // Verify the contents of the net log. |
| 369 EXPECT_LE( | 383 EXPECT_LE( |
| 370 2, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); | 384 3, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); |
| 385 EXPECT_NE(-1, estimator.GetNetLogLastIntegerValue( |
| 386 NetLogEventType::NETWORK_QUALITY_CHANGED, "http_rtt_ms")); |
| 387 EXPECT_EQ(-1, |
| 388 estimator.GetNetLogLastIntegerValue( |
| 389 NetLogEventType::NETWORK_QUALITY_CHANGED, "transport_rtt_ms")); |
| 390 EXPECT_NE(-1, estimator.GetNetLogLastIntegerValue( |
| 391 NetLogEventType::NETWORK_QUALITY_CHANGED, |
| 392 "downstream_throughput_kbps")); |
| 393 EXPECT_EQ( |
| 394 GetNameForEffectiveConnectionType(estimator.GetEffectiveConnectionType()), |
| 395 estimator.GetNetLogLastStringValue( |
| 396 NetLogEventType::NETWORK_QUALITY_CHANGED, |
| 397 "effective_connection_type")); |
| 398 |
| 371 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true, | 399 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true, |
| 372 1); | 400 1); |
| 373 histogram_tester.ExpectTotalCount("NQE.CachedNetworkQualityAvailable", 2); | 401 histogram_tester.ExpectTotalCount("NQE.CachedNetworkQualityAvailable", 2); |
| 374 base::RunLoop().RunUntilIdle(); | 402 base::RunLoop().RunUntilIdle(); |
| 375 | 403 |
| 376 // Verify that the cached network quality was read, and observers were | 404 // Verify that the cached network quality was read, and observers were |
| 377 // notified. |observer| must be notified once right after it was added, and | 405 // notified. |observer| must be notified once right after it was added, and |
| 378 // once again after the cached network quality was read. | 406 // once again after the cached network quality was read. |
| 379 EXPECT_LE(2U, observer.effective_connection_types().size()); | 407 EXPECT_LE(2U, observer.effective_connection_types().size()); |
| 380 EXPECT_EQ(estimator.GetEffectiveConnectionType(), | 408 EXPECT_EQ(estimator.GetEffectiveConnectionType(), |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 EXPECT_EQ(749, kbps); | 546 EXPECT_EQ(749, kbps); |
| 519 | 547 |
| 520 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | 548 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 521 estimator.GetEffectiveConnectionType()); | 549 estimator.GetEffectiveConnectionType()); |
| 522 EXPECT_EQ( | 550 EXPECT_EQ( |
| 523 1U, | 551 1U, |
| 524 effective_connection_type_observer.effective_connection_types().size()); | 552 effective_connection_type_observer.effective_connection_types().size()); |
| 525 EXPECT_NE( | 553 EXPECT_NE( |
| 526 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, | 554 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 527 effective_connection_type_observer.effective_connection_types().front()); | 555 effective_connection_type_observer.effective_connection_types().front()); |
| 528 EXPECT_EQ( | 556 |
| 529 2, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); | 557 // Verify the contents of the net log. |
| 558 EXPECT_LE( |
| 559 3, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); |
| 560 EXPECT_NE( |
| 561 GetNameForEffectiveConnectionType(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
| 562 estimator.GetNetLogLastStringValue( |
| 563 NetLogEventType::NETWORK_QUALITY_CHANGED, |
| 564 "effective_connection_type")); |
| 530 | 565 |
| 531 EXPECT_EQ(3, rtt_throughput_estimates_observer.notifications_received()); | 566 EXPECT_EQ(3, rtt_throughput_estimates_observer.notifications_received()); |
| 532 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), | 567 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), |
| 533 rtt_throughput_estimates_observer.http_rtt()); | 568 rtt_throughput_estimates_observer.http_rtt()); |
| 534 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), | 569 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), |
| 535 rtt_throughput_estimates_observer.transport_rtt()); | 570 rtt_throughput_estimates_observer.transport_rtt()); |
| 536 EXPECT_EQ(749, | 571 EXPECT_EQ(749, |
| 537 rtt_throughput_estimates_observer.downstream_throughput_kbps()); | 572 rtt_throughput_estimates_observer.downstream_throughput_kbps()); |
| 538 | 573 |
| 539 EXPECT_EQ(2U, rtt_observer.observations().size()); | 574 EXPECT_EQ(2U, rtt_observer.observations().size()); |
| (...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); | 1564 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| 1530 | 1565 |
| 1531 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1566 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1532 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1567 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1533 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1568 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1534 request->Start(); | 1569 request->Start(); |
| 1535 base::RunLoop().Run(); | 1570 base::RunLoop().Run(); |
| 1536 EXPECT_EQ(1U, observer.effective_connection_types().size()); | 1571 EXPECT_EQ(1U, observer.effective_connection_types().size()); |
| 1537 EXPECT_EQ( | 1572 EXPECT_EQ( |
| 1538 1, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); | 1573 1, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); |
| 1574 |
| 1575 // Verify the contents of the net log. |
| 1576 EXPECT_EQ(GetNameForEffectiveConnectionType(EFFECTIVE_CONNECTION_TYPE_2G), |
| 1577 estimator.GetNetLogLastStringValue( |
| 1578 NetLogEventType::NETWORK_QUALITY_CHANGED, |
| 1579 "effective_connection_type")); |
| 1580 EXPECT_EQ(1500, estimator.GetNetLogLastIntegerValue( |
| 1581 NetLogEventType::NETWORK_QUALITY_CHANGED, "http_rtt_ms")); |
| 1582 EXPECT_EQ(-1, |
| 1583 estimator.GetNetLogLastIntegerValue( |
| 1584 NetLogEventType::NETWORK_QUALITY_CHANGED, "transport_rtt_ms")); |
| 1585 EXPECT_EQ(100000, estimator.GetNetLogLastIntegerValue( |
| 1586 NetLogEventType::NETWORK_QUALITY_CHANGED, |
| 1587 "downstream_throughput_kbps")); |
| 1588 |
| 1539 histogram_tester.ExpectUniqueSample("NQE.MainFrame.EffectiveConnectionType", | 1589 histogram_tester.ExpectUniqueSample("NQE.MainFrame.EffectiveConnectionType", |
| 1540 EFFECTIVE_CONNECTION_TYPE_2G, 1); | 1590 EFFECTIVE_CONNECTION_TYPE_2G, 1); |
| 1541 histogram_tester.ExpectUniqueSample( | 1591 histogram_tester.ExpectUniqueSample( |
| 1542 "NQE.MainFrame.EffectiveConnectionType.Unknown", | 1592 "NQE.MainFrame.EffectiveConnectionType.Unknown", |
| 1543 EFFECTIVE_CONNECTION_TYPE_2G, 1); | 1593 EFFECTIVE_CONNECTION_TYPE_2G, 1); |
| 1544 | 1594 |
| 1545 // Next request should not trigger recomputation of effective connection type | 1595 // Next request should not trigger recomputation of effective connection type |
| 1546 // since there has been no change in the clock. | 1596 // since there has been no change in the clock. |
| 1547 std::unique_ptr<URLRequest> request2(context.CreateRequest( | 1597 std::unique_ptr<URLRequest> request2(context.CreateRequest( |
| 1548 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1598 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| (...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2707 | 2757 |
| 2708 // Cleanup. | 2758 // Cleanup. |
| 2709 estimator.RemoveRTTObserver(&rtt_observer); | 2759 estimator.RemoveRTTObserver(&rtt_observer); |
| 2710 estimator.RemoveThroughputObserver(&throughput_observer); | 2760 estimator.RemoveThroughputObserver(&throughput_observer); |
| 2711 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); | 2761 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); |
| 2712 estimator.RemoveEffectiveConnectionTypeObserver( | 2762 estimator.RemoveEffectiveConnectionTypeObserver( |
| 2713 &effective_connection_type_observer); | 2763 &effective_connection_type_observer); |
| 2714 } | 2764 } |
| 2715 | 2765 |
| 2716 } // namespace net | 2766 } // namespace net |
| OLD | NEW |