Commit afbf221e authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Add mechanism to force ECT computation value in NQE

Add an API to Network Quality Estimator that can be called
to force the computed Effective Connection Type value.
This will be used in a subsequent CL.

Change-Id: I96d3dea84af0c87ba841cf1115269ce7709a6e0c
Bug: 819244
Reviewed-on: https://chromium-review.googlesource.com/1107489Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568922}
parent 775b2bd8
...@@ -1782,4 +1782,11 @@ bool NetworkQualityEstimator::ShouldSocketWatcherNotifyRTT( ...@@ -1782,4 +1782,11 @@ bool NetworkQualityEstimator::ShouldSocketWatcherNotifyRTT(
params_->socket_watchers_min_notification_interval()); params_->socket_watchers_min_notification_interval());
} }
void NetworkQualityEstimator::SimulateNetworkQualityChangeForTesting(
net::EffectiveConnectionType type) {
DCHECK(thread_checker_.CalledOnValidThread());
params_->SetForcedEffectiveConnectionTypeForTesting(type);
ComputeEffectiveConnectionType();
}
} // namespace net } // namespace net
...@@ -223,6 +223,13 @@ class NET_EXPORT NetworkQualityEstimator ...@@ -223,6 +223,13 @@ class NET_EXPORT NetworkQualityEstimator
void EnableGetNetworkIdAsynchronously(); void EnableGetNetworkIdAsynchronously();
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
// Forces the effective connection type to be recomputed as |type|. Once
// called, effective connection type would always be computed as |type|.
// Calling this also notifies all the observers of the effective connection
// type as |type|.
void SimulateNetworkQualityChangeForTesting(
net::EffectiveConnectionType type);
typedef nqe::internal::Observation Observation; typedef nqe::internal::Observation Observation;
typedef nqe::internal::ObservationBuffer ObservationBuffer; typedef nqe::internal::ObservationBuffer ObservationBuffer;
......
...@@ -516,6 +516,14 @@ bool NetworkQualityEstimatorParams::use_small_responses() const { ...@@ -516,6 +516,14 @@ bool NetworkQualityEstimatorParams::use_small_responses() const {
return use_small_responses_; return use_small_responses_;
}; };
void NetworkQualityEstimatorParams::SetForcedEffectiveConnectionTypeForTesting(
EffectiveConnectionType type) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!forced_effective_connection_type_);
DCHECK(!forced_effective_connection_type_on_cellular_only_);
forced_effective_connection_type_ = type;
}
base::Optional<EffectiveConnectionType> base::Optional<EffectiveConnectionType>
NetworkQualityEstimatorParams::GetForcedEffectiveConnectionType( NetworkQualityEstimatorParams::GetForcedEffectiveConnectionType(
NetworkChangeNotifier::ConnectionType connection_type) { NetworkChangeNotifier::ConnectionType connection_type) {
......
...@@ -214,6 +214,9 @@ class NET_EXPORT NetworkQualityEstimatorParams { ...@@ -214,6 +214,9 @@ class NET_EXPORT NetworkQualityEstimatorParams {
return socket_watchers_min_notification_interval_; return socket_watchers_min_notification_interval_;
} }
// Sets the forced effective connection type as |type|.
void SetForcedEffectiveConnectionTypeForTesting(EffectiveConnectionType type);
private: private:
// Map containing all field trial parameters related to // Map containing all field trial parameters related to
// NetworkQualityEstimator field trial. // NetworkQualityEstimator field trial.
......
...@@ -2335,6 +2335,31 @@ TEST_F(NetworkQualityEstimatorTest, ...@@ -2335,6 +2335,31 @@ TEST_F(NetworkQualityEstimatorTest,
} }
} }
// Tests that the value of the effective connection type can be forced after
// network quality estimator has been initialized.
TEST_F(NetworkQualityEstimatorTest, SimulateNetworkQualityChangeForTesting) {
for (int i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) {
EffectiveConnectionType ect_type = static_cast<EffectiveConnectionType>(i);
TestNetworkQualityEstimator estimator;
TestEffectiveConnectionTypeObserver ect_observer;
estimator.AddEffectiveConnectionTypeObserver(&ect_observer);
// |observer| may be notified as soon as it is added. Run the loop to so
// that the notification to |observer| is finished.
base::RunLoop().RunUntilIdle();
TestDelegate test_delegate;
TestURLRequestContext context(true);
context.set_network_quality_estimator(&estimator);
context.Init();
estimator.SimulateNetworkQualityChangeForTesting(ect_type);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(ect_type, ect_observer.effective_connection_types().back());
}
}
// Test that the typical network qualities are set correctly. // Test that the typical network qualities are set correctly.
TEST_F(NetworkQualityEstimatorTest, TypicalNetworkQualities) { TEST_F(NetworkQualityEstimatorTest, TypicalNetworkQualities) {
TestNetworkQualityEstimator estimator; TestNetworkQualityEstimator estimator;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment