Chromium Code Reviews| Index: net/nqe/network_quality_estimator_unittest.cc |
| diff --git a/net/nqe/network_quality_estimator_unittest.cc b/net/nqe/network_quality_estimator_unittest.cc |
| index 0280fbcc6f5b0e302033d49f07b52d30490b5be3..8b338febaf748579029063de3fd1aea25390b8bb 100644 |
| --- a/net/nqe/network_quality_estimator_unittest.cc |
| +++ b/net/nqe/network_quality_estimator_unittest.cc |
| @@ -1534,6 +1534,128 @@ TEST(NetworkQualityEstimatorTest, TestEffectiveConnectionTypeObserver) { |
| EXPECT_EQ(2U, observer.effective_connection_types().size()); |
| } |
| +// Tests that the effective connection type is computed on every RTT |
| +// observation if the last computed effective connection type was unknown. |
| +TEST(NetworkQualityEstimatorTest, UnknownEffectiveConnectionType) { |
| + std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| + new base::SimpleTestTickClock()); |
| + base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| + |
| + TestEffectiveConnectionTypeObserver observer; |
| + std::map<std::string, std::string> variation_params; |
| + TestNetworkQualityEstimator estimator(variation_params); |
| + estimator.SetTickClockForTesting(std::move(tick_clock)); |
| + estimator.AddEffectiveConnectionTypeObserver(&observer); |
| + tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| + |
| + size_t expected_effective_connection_type_notifications = 0; |
| + estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_UNKNOWN); |
| + estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| + "test"); |
| + |
| + NetworkQualityEstimator::RttObservation rtt_observation( |
| + base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), |
| + NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST); |
| + |
| + for (size_t i = 0; i < 10; ++i) { |
| + estimator.NotifyObserversOfRTT(rtt_observation); |
| + EXPECT_EQ(expected_effective_connection_type_notifications, |
| + observer.effective_connection_types().size()); |
| + } |
| + estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
| + // Even though there are 10 RTT samples already available, addition of one |
|
bengr
2016/08/09 21:29:06
addition -> the addition
tbansal1
2016/08/10 00:13:12
Done.
|
| + // more RTT sample should trigger recomputation of effective connection type |
|
bengr
2016/08/09 21:29:06
of -> of the
tbansal1
2016/08/10 00:13:12
Done.
|
| + // since the last computed effective connection type was unknown. |
| + estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation( |
| + base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), |
| + NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| + ++expected_effective_connection_type_notifications; |
| + EXPECT_EQ(expected_effective_connection_type_notifications, |
| + observer.effective_connection_types().size()); |
| +} |
| + |
| +// Tests that the effective connection type is computed regularly depending |
| +// on the number of RTT and bandwidth samples. |
| +TEST(NetworkQualityEstimatorTest, |
| + AdaptiveRecomputationEffectiveConnectionType) { |
| + base::HistogramTester histogram_tester; |
| + std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
| + new base::SimpleTestTickClock()); |
| + base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| + |
| + TestEffectiveConnectionTypeObserver observer; |
| + std::map<std::string, std::string> variation_params; |
| + TestNetworkQualityEstimator estimator(variation_params); |
| + estimator.SetTickClockForTesting(std::move(tick_clock)); |
| + estimator.SimulateNetworkChangeTo(NetworkChangeNotifier::CONNECTION_WIFI, |
| + "test"); |
| + estimator.AddEffectiveConnectionTypeObserver(&observer); |
| + |
| + TestDelegate test_delegate; |
| + TestURLRequestContext context(true); |
| + context.set_network_quality_estimator(&estimator); |
| + context.Init(); |
| + |
| + EXPECT_EQ(0U, observer.effective_connection_types().size()); |
| + |
| + estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
| + tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| + |
| + std::unique_ptr<URLRequest> request(context.CreateRequest( |
| + estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| + request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); |
| + request->Start(); |
| + base::RunLoop().Run(); |
| + EXPECT_EQ(1U, observer.effective_connection_types().size()); |
| + histogram_tester.ExpectUniqueSample( |
| + "NQE.MainFrame.EffectiveConnectionType.WiFi", |
| + EFFECTIVE_CONNECTION_TYPE_2G, 1); |
| + |
| + size_t expected_effective_connection_type_notifications = 1; |
| + EXPECT_EQ(expected_effective_connection_type_notifications, |
| + observer.effective_connection_types().size()); |
| + |
| + EXPECT_EQ(expected_effective_connection_type_notifications, |
| + estimator.rtt_observations_.Size()); |
| + |
| + // Increase the number of RTT observations. Every time the number of RTT |
| + // observations are more than doubled, effective connection type must be |
|
bengr
2016/08/09 21:29:06
are -> is
tbansal1
2016/08/10 00:13:12
Done.
|
| + // recomputed, and notified to observers. |
|
bengr
2016/08/09 21:29:06
recomputed, -> recomputed
tbansal1
2016/08/10 00:13:12
Done.
|
| + for (size_t repetition = 0; repetition < 2; ++repetition) { |
| + // Change the effective connection type so that the observers are |
| + // notified when the effective connection type is recomputed. |
| + if (repetition % 2 == 0) { |
| + estimator.set_effective_connection_type( |
| + EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
| + } else { |
| + estimator.set_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_3G); |
| + } |
| + size_t rtt_observations_count = estimator.rtt_observations_.Size(); |
| + // Increase the number of RTT observations to more than twice the number |
|
bengr
2016/08/09 21:29:06
Do you also test that not increasing the number do
tbansal1
2016/08/10 00:13:12
I am not sure if I understand this comment. I am c
bengr
2016/08/12 18:52:36
Never mind. I see you covered the case I was worri
|
| + // of current observations. This should trigger recomputation of |
| + // effective connection type. |
| + for (size_t i = 0; i < rtt_observations_count + 1; ++i) { |
| + estimator.rtt_observations_.AddObservation( |
| + NetworkQualityEstimator::RttObservation( |
| + base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), |
| + NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| + |
| + estimator.NotifyObserversOfRTT(NetworkQualityEstimator::RttObservation( |
| + base::TimeDelta::FromSeconds(5), tick_clock_ptr->NowTicks(), |
| + NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST)); |
| + |
| + if (i == rtt_observations_count) { |
| + // Effective connection type must be recomputed since the number of RTT |
| + // samples are now more than twice the number of RTT samples that were |
| + // available when effective connection type was last computed. |
| + ++expected_effective_connection_type_notifications; |
| + } |
| + EXPECT_EQ(expected_effective_connection_type_notifications, |
| + observer.effective_connection_types().size()); |
| + } |
| + } |
| +} |
| + |
| TEST(NetworkQualityEstimatorTest, TestRttThroughputObservers) { |
| TestRTTObserver rtt_observer; |
| TestThroughputObserver throughput_observer; |