OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014, Google Inc. All rights reserved. | 2 * Copyright (c) 2014, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "platform/network/NetworkStateNotifier.h" | 31 #include "platform/network/NetworkStateNotifier.h" |
32 | 32 |
33 #include "platform/scheduler/test/fake_web_task_runner.h" | 33 #include "platform/scheduler/test/fake_web_task_runner.h" |
34 #include "platform/testing/UnitTestHelpers.h" | 34 #include "platform/testing/UnitTestHelpers.h" |
35 #include "platform/wtf/Functional.h" | 35 #include "platform/wtf/Functional.h" |
| 36 #include "platform/wtf/Optional.h" |
| 37 #include "platform/wtf/Time.h" |
36 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
37 #include "public/platform/WebConnectionType.h" | 39 #include "public/platform/WebConnectionType.h" |
38 #include "public/platform/WebThread.h" | 40 #include "public/platform/WebThread.h" |
39 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
40 | 42 |
41 namespace blink { | 43 namespace blink { |
42 | 44 |
43 using scheduler::FakeWebTaskRunner; | 45 using scheduler::FakeWebTaskRunner; |
44 | 46 |
45 namespace { | 47 namespace { |
46 const double kNoneMaxBandwidthMbps = 0.0; | 48 const double kNoneMaxBandwidthMbps = 0.0; |
47 const double kBluetoothMaxBandwidthMbps = 1.0; | 49 const double kBluetoothMaxBandwidthMbps = 1.0; |
48 const double kEthernetMaxBandwidthMbps = 2.0; | 50 const double kEthernetMaxBandwidthMbps = 2.0; |
| 51 const Optional<TimeDelta> kEthernetHttpRtt(TimeDelta::FromMilliseconds(50)); |
| 52 const Optional<TimeDelta> kEthernetTransportRtt( |
| 53 TimeDelta::FromMilliseconds(25)); |
| 54 const Optional<double> kEthernetThroughputMbps(75.0); |
| 55 const Optional<TimeDelta> kUnknownRtt; |
| 56 const Optional<double> kUnknownThroughputMbps; |
49 } | 57 } |
50 | 58 |
51 class StateObserver : public NetworkStateNotifier::NetworkStateObserver { | 59 class StateObserver : public NetworkStateNotifier::NetworkStateObserver { |
52 public: | 60 public: |
53 StateObserver() | 61 StateObserver() |
54 : observed_type_(kWebConnectionTypeNone), | 62 : observed_type_(kWebConnectionTypeNone), |
55 observed_max_bandwidth_mbps_(0.0), | 63 observed_max_bandwidth_mbps_(0.0), |
| 64 observed_http_rtt_(kUnknownRtt), |
| 65 observed_transport_rtt_(kUnknownRtt), |
| 66 observed_downlink_throughput_mbps_(kUnknownThroughputMbps), |
56 observed_on_line_state_(false), | 67 observed_on_line_state_(false), |
57 callback_count_(0) {} | 68 callback_count_(0) {} |
58 | 69 |
59 virtual void ConnectionChange(WebConnectionType type, | 70 virtual void ConnectionChange( |
60 double max_bandwidth_mbps) { | 71 WebConnectionType type, |
| 72 double max_bandwidth_mbps, |
| 73 const Optional<TimeDelta>& http_rtt, |
| 74 const Optional<TimeDelta>& transport_rtt, |
| 75 const Optional<double>& downlink_throughput_mbps) { |
61 observed_type_ = type; | 76 observed_type_ = type; |
62 observed_max_bandwidth_mbps_ = max_bandwidth_mbps; | 77 observed_max_bandwidth_mbps_ = max_bandwidth_mbps; |
| 78 observed_http_rtt_ = http_rtt; |
| 79 observed_transport_rtt_ = transport_rtt; |
| 80 observed_downlink_throughput_mbps_ = downlink_throughput_mbps; |
63 callback_count_ += 1; | 81 callback_count_ += 1; |
64 | 82 |
65 if (closure_) | 83 if (closure_) |
66 (*closure_)(); | 84 (*closure_)(); |
67 } | 85 } |
68 | 86 |
69 virtual void OnLineStateChange(bool on_line) { | 87 virtual void OnLineStateChange(bool on_line) { |
70 observed_on_line_state_ = on_line; | 88 observed_on_line_state_ = on_line; |
71 callback_count_ += 1; | 89 callback_count_ += 1; |
72 | 90 |
73 if (closure_) | 91 if (closure_) |
74 (*closure_)(); | 92 (*closure_)(); |
75 } | 93 } |
76 | 94 |
77 WebConnectionType ObservedType() const { return observed_type_; } | 95 WebConnectionType ObservedType() const { return observed_type_; } |
78 double ObservedMaxBandwidth() const { return observed_max_bandwidth_mbps_; } | 96 double ObservedMaxBandwidth() const { return observed_max_bandwidth_mbps_; } |
| 97 Optional<TimeDelta> ObservedHttpRtt() const { return observed_http_rtt_; } |
| 98 Optional<TimeDelta> ObservedTransportRtt() const { |
| 99 return observed_transport_rtt_; |
| 100 } |
| 101 Optional<double> ObservedDownlinkThroughputMbps() const { |
| 102 return observed_downlink_throughput_mbps_; |
| 103 } |
79 bool ObservedOnLineState() const { return observed_on_line_state_; } | 104 bool ObservedOnLineState() const { return observed_on_line_state_; } |
80 int CallbackCount() const { return callback_count_; } | 105 int CallbackCount() const { return callback_count_; } |
81 | 106 |
82 void SetNotificationCallback(std::unique_ptr<WTF::Closure> closure) { | 107 void SetNotificationCallback(std::unique_ptr<WTF::Closure> closure) { |
83 closure_ = std::move(closure); | 108 closure_ = std::move(closure); |
84 } | 109 } |
85 | 110 |
86 private: | 111 private: |
87 std::unique_ptr<WTF::Closure> closure_; | 112 std::unique_ptr<WTF::Closure> closure_; |
88 WebConnectionType observed_type_; | 113 WebConnectionType observed_type_; |
89 double observed_max_bandwidth_mbps_; | 114 double observed_max_bandwidth_mbps_; |
| 115 Optional<TimeDelta> observed_http_rtt_; |
| 116 Optional<TimeDelta> observed_transport_rtt_; |
| 117 Optional<double> observed_downlink_throughput_mbps_; |
90 bool observed_on_line_state_; | 118 bool observed_on_line_state_; |
91 int callback_count_; | 119 int callback_count_; |
92 }; | 120 }; |
93 | 121 |
94 class NetworkStateNotifierTest : public ::testing::Test { | 122 class NetworkStateNotifierTest : public ::testing::Test { |
95 public: | 123 public: |
96 NetworkStateNotifierTest() | 124 NetworkStateNotifierTest() |
97 : task_runner_(AdoptRef(new FakeWebTaskRunner())), | 125 : task_runner_(AdoptRef(new FakeWebTaskRunner())), |
98 task_runner2_(AdoptRef(new FakeWebTaskRunner())) { | 126 task_runner2_(AdoptRef(new FakeWebTaskRunner())) { |
99 // Initialize connection, so that future calls to setWebConnection issue | 127 // Initialize connection, so that future calls to setWebConnection issue |
(...skipping 10 matching lines...) Expand all Loading... |
110 task_runner_ = nullptr; | 138 task_runner_ = nullptr; |
111 task_runner2_ = nullptr; | 139 task_runner2_ = nullptr; |
112 } | 140 } |
113 | 141 |
114 protected: | 142 protected: |
115 void RunPendingTasks() { | 143 void RunPendingTasks() { |
116 task_runner_->RunUntilIdle(); | 144 task_runner_->RunUntilIdle(); |
117 task_runner2_->RunUntilIdle(); | 145 task_runner2_->RunUntilIdle(); |
118 } | 146 } |
119 | 147 |
120 void SetConnection(WebConnectionType type, double max_bandwidth_mbps) { | 148 void SetConnection(WebConnectionType type, |
| 149 double max_bandwidth_mbps, |
| 150 const Optional<TimeDelta>& http_rtt, |
| 151 const Optional<TimeDelta>& transport_rtt, |
| 152 const Optional<double>& downlink_throughput_mbps) { |
121 notifier_.SetWebConnection(type, max_bandwidth_mbps); | 153 notifier_.SetWebConnection(type, max_bandwidth_mbps); |
| 154 notifier_.SetWebNetworkQuality( |
| 155 http_rtt.has_value() ? http_rtt.value().InMilliseconds() : -1, |
| 156 transport_rtt.has_value() ? transport_rtt.value().InMilliseconds() : -1, |
| 157 downlink_throughput_mbps.has_value() |
| 158 ? downlink_throughput_mbps.value() * 1000 |
| 159 : -1); |
122 RunPendingTasks(); | 160 RunPendingTasks(); |
123 } | 161 } |
124 void SetOnLine(bool on_line) { | 162 void SetOnLine(bool on_line) { |
125 notifier_.SetOnLine(on_line); | 163 notifier_.SetOnLine(on_line); |
126 RunPendingTasks(); | 164 RunPendingTasks(); |
127 } | 165 } |
128 | 166 |
129 void AddObserverOnNotification(StateObserver* observer, | 167 void AddObserverOnNotification(StateObserver* observer, |
130 StateObserver* observer_to_add) { | 168 StateObserver* observer_to_add) { |
131 observer->SetNotificationCallback( | 169 observer->SetNotificationCallback( |
132 Bind(&NetworkStateNotifier::AddConnectionObserver, | 170 Bind(&NetworkStateNotifier::AddConnectionObserver, |
133 WTF::Unretained(¬ifier_), WTF::Unretained(observer_to_add), | 171 WTF::Unretained(¬ifier_), WTF::Unretained(observer_to_add), |
134 WTF::Unretained(GetTaskRunner()))); | 172 WTF::Unretained(GetTaskRunner()))); |
135 } | 173 } |
136 | 174 |
137 void RemoveObserverOnNotification(StateObserver* observer, | 175 void RemoveObserverOnNotification(StateObserver* observer, |
138 StateObserver* observer_to_remove) { | 176 StateObserver* observer_to_remove) { |
139 observer->SetNotificationCallback( | 177 observer->SetNotificationCallback( |
140 Bind(&NetworkStateNotifier::RemoveConnectionObserver, | 178 Bind(&NetworkStateNotifier::RemoveConnectionObserver, |
141 WTF::Unretained(¬ifier_), WTF::Unretained(observer_to_remove), | 179 WTF::Unretained(¬ifier_), WTF::Unretained(observer_to_remove), |
142 WTF::Unretained(GetTaskRunner()))); | 180 WTF::Unretained(GetTaskRunner()))); |
143 } | 181 } |
144 | 182 |
145 bool VerifyObservations(const StateObserver& observer, | 183 bool VerifyObservations( |
146 WebConnectionType type, | 184 const StateObserver& observer, |
147 double max_bandwidth_mbps) { | 185 WebConnectionType type, |
148 EXPECT_EQ(observer.ObservedType(), type); | 186 double max_bandwidth_mbps, |
149 EXPECT_EQ(observer.ObservedMaxBandwidth(), max_bandwidth_mbps); | 187 const Optional<TimeDelta>& http_rtt, |
| 188 const Optional<TimeDelta>& transport_rtt, |
| 189 const Optional<double>& downlink_throughput_mbps) const { |
| 190 EXPECT_EQ(type, observer.ObservedType()); |
| 191 EXPECT_EQ(max_bandwidth_mbps, observer.ObservedMaxBandwidth()); |
| 192 EXPECT_EQ(http_rtt, observer.ObservedHttpRtt()); |
| 193 EXPECT_EQ(transport_rtt, observer.ObservedTransportRtt()); |
| 194 EXPECT_EQ(downlink_throughput_mbps, |
| 195 observer.ObservedDownlinkThroughputMbps()); |
| 196 |
150 return observer.ObservedType() == type && | 197 return observer.ObservedType() == type && |
151 observer.ObservedMaxBandwidth() == max_bandwidth_mbps; | 198 observer.ObservedMaxBandwidth() == max_bandwidth_mbps && |
| 199 observer.ObservedHttpRtt() == http_rtt && |
| 200 observer.ObservedTransportRtt() == transport_rtt && |
| 201 observer.ObservedDownlinkThroughputMbps() == |
| 202 downlink_throughput_mbps; |
152 } | 203 } |
153 | 204 |
154 RefPtr<FakeWebTaskRunner> task_runner_; | 205 RefPtr<FakeWebTaskRunner> task_runner_; |
155 RefPtr<FakeWebTaskRunner> task_runner2_; | 206 RefPtr<FakeWebTaskRunner> task_runner2_; |
156 NetworkStateNotifier notifier_; | 207 NetworkStateNotifier notifier_; |
157 }; | 208 }; |
158 | 209 |
159 TEST_F(NetworkStateNotifierTest, AddObserver) { | 210 TEST_F(NetworkStateNotifierTest, AddObserver) { |
160 StateObserver observer; | 211 StateObserver observer; |
161 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); | 212 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); |
162 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone, | 213 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone, |
163 kNoneMaxBandwidthMbps)); | 214 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 215 kUnknownRtt, kUnknownThroughputMbps)); |
164 | 216 |
165 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 217 // Change max. bandwidth and the network quality estimates. |
166 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, | 218 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
167 kBluetoothMaxBandwidthMbps)); | 219 kEthernetHttpRtt, kEthernetTransportRtt, |
168 EXPECT_EQ(observer.CallbackCount(), 1); | 220 kEthernetThroughputMbps); |
| 221 EXPECT_TRUE(VerifyObservations( |
| 222 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 223 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 224 EXPECT_EQ(observer.CallbackCount(), 2); |
| 225 |
| 226 // Only change the connection type. |
| 227 SetConnection(kWebConnectionTypeEthernet, kBluetoothMaxBandwidthMbps, |
| 228 kEthernetHttpRtt, kEthernetTransportRtt, |
| 229 kEthernetThroughputMbps); |
| 230 EXPECT_TRUE(VerifyObservations( |
| 231 observer, kWebConnectionTypeEthernet, kBluetoothMaxBandwidthMbps, |
| 232 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 233 EXPECT_EQ(observer.CallbackCount(), 3); |
| 234 |
| 235 // Only change the max. bandwidth. |
| 236 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 237 kEthernetHttpRtt, kEthernetTransportRtt, |
| 238 kEthernetThroughputMbps); |
| 239 EXPECT_TRUE(VerifyObservations( |
| 240 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 241 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 242 EXPECT_EQ(observer.CallbackCount(), 4); |
| 243 |
| 244 // Only change the transport RTT. |
| 245 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 246 kEthernetHttpRtt, kEthernetTransportRtt.value() * 2, |
| 247 kEthernetThroughputMbps); |
| 248 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, |
| 249 kEthernetMaxBandwidthMbps, kEthernetHttpRtt, |
| 250 kEthernetTransportRtt.value() * 2, |
| 251 kEthernetThroughputMbps)); |
| 252 EXPECT_EQ(observer.CallbackCount(), 5); |
| 253 |
169 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); | 254 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); |
170 } | 255 } |
171 | 256 |
172 TEST_F(NetworkStateNotifierTest, RemoveObserver) { | 257 TEST_F(NetworkStateNotifierTest, RemoveObserver) { |
173 StateObserver observer1, observer2; | 258 StateObserver observer1, observer2; |
174 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 259 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
175 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 260 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
176 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); | 261 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); |
177 | 262 |
178 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 263 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 264 kEthernetHttpRtt, kEthernetTransportRtt, |
| 265 kEthernetThroughputMbps); |
| 266 |
179 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, | 267 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, |
180 kNoneMaxBandwidthMbps)); | 268 kNoneMaxBandwidthMbps, kUnknownRtt, |
181 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, | 269 kUnknownRtt, kUnknownThroughputMbps)); |
182 kBluetoothMaxBandwidthMbps)); | 270 EXPECT_TRUE(VerifyObservations( |
| 271 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 272 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
183 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 273 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
184 } | 274 } |
185 | 275 |
186 TEST_F(NetworkStateNotifierTest, RemoveSoleObserver) { | 276 TEST_F(NetworkStateNotifierTest, RemoveSoleObserver) { |
187 StateObserver observer1; | 277 StateObserver observer1; |
188 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 278 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
189 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 279 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
190 | 280 |
191 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 281 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 282 kEthernetHttpRtt, kEthernetTransportRtt, |
| 283 kEthernetThroughputMbps); |
192 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, | 284 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, |
193 kNoneMaxBandwidthMbps)); | 285 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 286 kUnknownRtt, kUnknownThroughputMbps)); |
194 } | 287 } |
195 | 288 |
196 TEST_F(NetworkStateNotifierTest, AddObserverWhileNotifying) { | 289 TEST_F(NetworkStateNotifierTest, AddObserverWhileNotifying) { |
197 StateObserver observer1, observer2; | 290 StateObserver observer1, observer2; |
198 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 291 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
199 AddObserverOnNotification(&observer1, &observer2); | 292 AddObserverOnNotification(&observer1, &observer2); |
200 | 293 |
201 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 294 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 295 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
202 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 296 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
203 kBluetoothMaxBandwidthMbps)); | 297 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 298 kUnknownRtt, kUnknownThroughputMbps)); |
204 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, | 299 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, |
205 kBluetoothMaxBandwidthMbps)); | 300 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 301 kUnknownRtt, kUnknownThroughputMbps)); |
206 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 302 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
207 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 303 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
208 } | 304 } |
209 | 305 |
210 TEST_F(NetworkStateNotifierTest, RemoveSoleObserverWhileNotifying) { | 306 TEST_F(NetworkStateNotifierTest, RemoveSoleObserverWhileNotifying) { |
211 StateObserver observer1; | 307 StateObserver observer1; |
212 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 308 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
213 RemoveObserverOnNotification(&observer1, &observer1); | 309 RemoveObserverOnNotification(&observer1, &observer1); |
214 | 310 |
215 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 311 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 312 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
216 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 313 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
217 kBluetoothMaxBandwidthMbps)); | 314 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 315 kUnknownRtt, kUnknownThroughputMbps)); |
218 | 316 |
219 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | 317 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 318 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
220 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 319 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
221 kBluetoothMaxBandwidthMbps)); | 320 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 321 kUnknownRtt, kUnknownThroughputMbps)); |
222 } | 322 } |
223 | 323 |
224 TEST_F(NetworkStateNotifierTest, RemoveCurrentObserverWhileNotifying) { | 324 TEST_F(NetworkStateNotifierTest, RemoveCurrentObserverWhileNotifying) { |
225 StateObserver observer1, observer2; | 325 StateObserver observer1, observer2; |
226 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 326 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
227 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); | 327 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); |
228 RemoveObserverOnNotification(&observer1, &observer1); | 328 RemoveObserverOnNotification(&observer1, &observer1); |
229 | 329 |
230 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 330 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 331 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
231 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 332 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
232 kBluetoothMaxBandwidthMbps)); | 333 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 334 kUnknownRtt, kUnknownThroughputMbps)); |
233 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, | 335 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, |
234 kBluetoothMaxBandwidthMbps)); | 336 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 337 kUnknownRtt, kUnknownThroughputMbps)); |
235 | 338 |
236 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | 339 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 340 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
237 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 341 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
238 kBluetoothMaxBandwidthMbps)); | 342 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 343 kUnknownRtt, kUnknownThroughputMbps)); |
239 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, | 344 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, |
240 kEthernetMaxBandwidthMbps)); | 345 kEthernetMaxBandwidthMbps, kUnknownRtt, |
| 346 kUnknownRtt, kUnknownThroughputMbps)); |
241 | 347 |
242 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 348 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
243 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 349 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
244 } | 350 } |
245 | 351 |
246 TEST_F(NetworkStateNotifierTest, RemovePastObserverWhileNotifying) { | 352 TEST_F(NetworkStateNotifierTest, RemovePastObserverWhileNotifying) { |
247 StateObserver observer1, observer2; | 353 StateObserver observer1, observer2; |
248 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 354 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
249 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); | 355 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); |
250 RemoveObserverOnNotification(&observer2, &observer1); | 356 RemoveObserverOnNotification(&observer2, &observer1); |
251 | 357 |
252 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 358 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 359 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
253 EXPECT_EQ(observer1.ObservedType(), kWebConnectionTypeBluetooth); | 360 EXPECT_EQ(observer1.ObservedType(), kWebConnectionTypeBluetooth); |
254 EXPECT_EQ(observer2.ObservedType(), kWebConnectionTypeBluetooth); | 361 EXPECT_EQ(observer2.ObservedType(), kWebConnectionTypeBluetooth); |
255 | 362 |
256 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | 363 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 364 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
257 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 365 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
258 kBluetoothMaxBandwidthMbps)); | 366 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 367 kUnknownRtt, kUnknownThroughputMbps)); |
259 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, | 368 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, |
260 kEthernetMaxBandwidthMbps)); | 369 kEthernetMaxBandwidthMbps, kUnknownRtt, |
| 370 kUnknownRtt, kUnknownThroughputMbps)); |
261 | 371 |
262 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 372 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
263 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 373 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
264 } | 374 } |
265 | 375 |
266 TEST_F(NetworkStateNotifierTest, RemoveFutureObserverWhileNotifying) { | 376 TEST_F(NetworkStateNotifierTest, RemoveFutureObserverWhileNotifying) { |
267 StateObserver observer1, observer2, observer3; | 377 StateObserver observer1, observer2, observer3; |
268 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 378 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
269 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); | 379 notifier_.AddConnectionObserver(&observer2, GetTaskRunner()); |
270 notifier_.AddConnectionObserver(&observer3, GetTaskRunner()); | 380 notifier_.AddConnectionObserver(&observer3, GetTaskRunner()); |
271 RemoveObserverOnNotification(&observer1, &observer2); | 381 RemoveObserverOnNotification(&observer1, &observer2); |
272 | 382 |
273 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 383 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 384 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
274 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 385 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, |
275 kBluetoothMaxBandwidthMbps)); | 386 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 387 kUnknownRtt, kUnknownThroughputMbps)); |
276 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, | 388 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, |
277 kNoneMaxBandwidthMbps)); | 389 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 390 kUnknownRtt, kUnknownThroughputMbps)); |
278 EXPECT_TRUE(VerifyObservations(observer3, kWebConnectionTypeBluetooth, | 391 EXPECT_TRUE(VerifyObservations(observer3, kWebConnectionTypeBluetooth, |
279 kBluetoothMaxBandwidthMbps)); | 392 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 393 kUnknownRtt, kUnknownThroughputMbps)); |
280 | 394 |
281 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 395 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
282 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 396 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
283 notifier_.RemoveConnectionObserver(&observer3, GetTaskRunner()); | 397 notifier_.RemoveConnectionObserver(&observer3, GetTaskRunner()); |
284 } | 398 } |
285 | 399 |
286 TEST_F(NetworkStateNotifierTest, MultipleContextsAddObserver) { | 400 TEST_F(NetworkStateNotifierTest, MultipleContextsAddObserver) { |
287 StateObserver observer1, observer2; | 401 StateObserver observer1, observer2; |
288 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 402 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
289 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); | 403 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); |
290 | 404 |
291 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 405 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
292 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 406 kEthernetHttpRtt, kEthernetTransportRtt, |
293 kBluetoothMaxBandwidthMbps)); | 407 kEthernetThroughputMbps); |
294 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeBluetooth, | 408 EXPECT_TRUE(VerifyObservations( |
295 kBluetoothMaxBandwidthMbps)); | 409 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 410 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 411 EXPECT_TRUE(VerifyObservations( |
| 412 observer2, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 413 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
296 | 414 |
297 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 415 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
298 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); | 416 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); |
299 } | 417 } |
300 | 418 |
301 TEST_F(NetworkStateNotifierTest, RemoveContext) { | 419 TEST_F(NetworkStateNotifierTest, RemoveContext) { |
302 StateObserver observer1, observer2; | 420 StateObserver observer1, observer2; |
303 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 421 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
304 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); | 422 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); |
305 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); | 423 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); |
306 | 424 |
307 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 425 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
308 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeBluetooth, | 426 kEthernetHttpRtt, kEthernetTransportRtt, |
309 kBluetoothMaxBandwidthMbps)); | 427 kEthernetThroughputMbps); |
| 428 EXPECT_TRUE(VerifyObservations( |
| 429 observer1, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 430 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
310 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, | 431 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, |
311 kNoneMaxBandwidthMbps)); | 432 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 433 kUnknownRtt, kUnknownThroughputMbps)); |
312 | 434 |
313 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 435 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
314 } | 436 } |
315 | 437 |
316 TEST_F(NetworkStateNotifierTest, RemoveAllContexts) { | 438 TEST_F(NetworkStateNotifierTest, RemoveAllContexts) { |
317 StateObserver observer1, observer2; | 439 StateObserver observer1, observer2; |
318 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); | 440 notifier_.AddConnectionObserver(&observer1, GetTaskRunner()); |
319 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); | 441 notifier_.AddConnectionObserver(&observer2, GetTaskRunner2()); |
320 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 442 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
321 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); | 443 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner2()); |
322 | 444 |
323 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 445 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 446 kEthernetHttpRtt, kEthernetTransportRtt, |
| 447 kEthernetThroughputMbps); |
324 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, | 448 EXPECT_TRUE(VerifyObservations(observer1, kWebConnectionTypeNone, |
325 kNoneMaxBandwidthMbps)); | 449 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 450 kUnknownRtt, kUnknownThroughputMbps)); |
326 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, | 451 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeNone, |
327 kNoneMaxBandwidthMbps)); | 452 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 453 kUnknownRtt, kUnknownThroughputMbps)); |
328 } | 454 } |
329 | 455 |
330 TEST_F(NetworkStateNotifierTest, SetOverride) { | 456 TEST_F(NetworkStateNotifierTest, SetOverride) { |
331 StateObserver observer; | 457 StateObserver observer; |
332 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); | 458 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); |
333 | 459 |
334 notifier_.SetOnLine(true); | 460 notifier_.SetOnLine(true); |
335 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 461 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 462 kUnknownRtt, kUnknownRtt, kUnknownThroughputMbps); |
336 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, | 463 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, |
337 kBluetoothMaxBandwidthMbps)); | 464 kBluetoothMaxBandwidthMbps, kUnknownRtt, |
| 465 kUnknownRtt, kUnknownThroughputMbps)); |
338 EXPECT_TRUE(notifier_.OnLine()); | 466 EXPECT_TRUE(notifier_.OnLine()); |
339 EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType()); | 467 EXPECT_EQ(kWebConnectionTypeBluetooth, notifier_.ConnectionType()); |
340 EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth()); | 468 EXPECT_EQ(kBluetoothMaxBandwidthMbps, notifier_.MaxBandwidth()); |
341 | 469 |
342 notifier_.SetOverride(true, kWebConnectionTypeEthernet, | 470 notifier_.SetOverride(true, kWebConnectionTypeEthernet, |
343 kEthernetMaxBandwidthMbps); | 471 kEthernetMaxBandwidthMbps); |
344 RunPendingTasks(); | 472 RunPendingTasks(); |
345 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, | 473 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, |
346 kEthernetMaxBandwidthMbps)); | 474 kEthernetMaxBandwidthMbps, kUnknownRtt, |
| 475 kUnknownRtt, kUnknownThroughputMbps)); |
347 EXPECT_TRUE(notifier_.OnLine()); | 476 EXPECT_TRUE(notifier_.OnLine()); |
348 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); | 477 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); |
349 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); | 478 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); |
350 | 479 |
351 // When override is active, calls to setOnLine and setConnection are temporary | 480 // When override is active, calls to setOnLine and setConnection are temporary |
352 // ignored. | 481 // ignored. |
353 notifier_.SetOnLine(false); | 482 notifier_.SetOnLine(false); |
354 SetConnection(kWebConnectionTypeNone, kNoneMaxBandwidthMbps); | 483 SetConnection(kWebConnectionTypeNone, kNoneMaxBandwidthMbps, kUnknownRtt, |
| 484 kUnknownRtt, kUnknownThroughputMbps); |
355 RunPendingTasks(); | 485 RunPendingTasks(); |
356 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, | 486 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, |
357 kEthernetMaxBandwidthMbps)); | 487 kEthernetMaxBandwidthMbps, kUnknownRtt, |
| 488 kUnknownRtt, kUnknownThroughputMbps)); |
358 EXPECT_TRUE(notifier_.OnLine()); | 489 EXPECT_TRUE(notifier_.OnLine()); |
359 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); | 490 EXPECT_EQ(kWebConnectionTypeEthernet, notifier_.ConnectionType()); |
360 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); | 491 EXPECT_EQ(kEthernetMaxBandwidthMbps, notifier_.MaxBandwidth()); |
361 | 492 |
362 notifier_.ClearOverride(); | 493 notifier_.ClearOverride(); |
363 RunPendingTasks(); | 494 RunPendingTasks(); |
364 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone, | 495 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeNone, |
365 kNoneMaxBandwidthMbps)); | 496 kNoneMaxBandwidthMbps, kUnknownRtt, |
| 497 kUnknownRtt, kUnknownThroughputMbps)); |
366 EXPECT_FALSE(notifier_.OnLine()); | 498 EXPECT_FALSE(notifier_.OnLine()); |
367 EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType()); | 499 EXPECT_EQ(kWebConnectionTypeNone, notifier_.ConnectionType()); |
368 EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth()); | 500 EXPECT_EQ(kNoneMaxBandwidthMbps, notifier_.MaxBandwidth()); |
369 | 501 |
370 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); | 502 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); |
371 } | 503 } |
372 | 504 |
373 TEST_F(NetworkStateNotifierTest, NoExtraNotifications) { | 505 TEST_F(NetworkStateNotifierTest, NoExtraNotifications) { |
374 StateObserver observer; | 506 StateObserver observer; |
375 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); | 507 notifier_.AddConnectionObserver(&observer, GetTaskRunner()); |
376 | 508 |
377 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 509 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
378 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, | 510 kEthernetHttpRtt, kEthernetTransportRtt, |
379 kBluetoothMaxBandwidthMbps)); | 511 kEthernetThroughputMbps); |
380 EXPECT_EQ(observer.CallbackCount(), 1); | 512 EXPECT_TRUE(VerifyObservations( |
381 | 513 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
382 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 514 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
383 EXPECT_EQ(observer.CallbackCount(), 1); | |
384 | |
385 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | |
386 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeEthernet, | |
387 kEthernetMaxBandwidthMbps)); | |
388 EXPECT_EQ(observer.CallbackCount(), 2); | 515 EXPECT_EQ(observer.CallbackCount(), 2); |
389 | 516 |
390 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps); | 517 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 518 kEthernetHttpRtt, kEthernetTransportRtt, |
| 519 kEthernetThroughputMbps); |
391 EXPECT_EQ(observer.CallbackCount(), 2); | 520 EXPECT_EQ(observer.CallbackCount(), 2); |
392 | 521 |
393 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps); | 522 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
394 EXPECT_TRUE(VerifyObservations(observer, kWebConnectionTypeBluetooth, | 523 kEthernetHttpRtt.value() * 2, kEthernetTransportRtt.value() * 2, |
395 kBluetoothMaxBandwidthMbps)); | 524 kEthernetThroughputMbps.value() * 2); |
396 EXPECT_EQ(observer.CallbackCount(), 3); | 525 EXPECT_TRUE(VerifyObservations( |
| 526 observer, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 527 kEthernetHttpRtt.value() * 2, kEthernetTransportRtt.value() * 2, |
| 528 kEthernetThroughputMbps.value() * 2)); |
| 529 EXPECT_EQ(observer.CallbackCount(), 4); |
| 530 |
| 531 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 532 kEthernetHttpRtt.value() * 2, kEthernetTransportRtt.value() * 2, |
| 533 kEthernetThroughputMbps.value() * 2); |
| 534 EXPECT_EQ(observer.CallbackCount(), 4); |
| 535 |
| 536 SetConnection(kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 537 kEthernetHttpRtt, kEthernetTransportRtt, |
| 538 kEthernetThroughputMbps); |
| 539 EXPECT_TRUE(VerifyObservations( |
| 540 observer, kWebConnectionTypeBluetooth, kBluetoothMaxBandwidthMbps, |
| 541 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
| 542 EXPECT_EQ(observer.CallbackCount(), 6); |
397 | 543 |
398 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); | 544 notifier_.RemoveConnectionObserver(&observer, GetTaskRunner()); |
399 } | 545 } |
400 | 546 |
401 TEST_F(NetworkStateNotifierTest, NoNotificationOnInitialization) { | 547 TEST_F(NetworkStateNotifierTest, NoNotificationOnInitialization) { |
402 NetworkStateNotifier notifier; | 548 NetworkStateNotifier notifier; |
403 StateObserver observer; | 549 StateObserver observer; |
404 | 550 |
405 notifier.AddConnectionObserver(&observer, GetTaskRunner()); | 551 notifier.AddConnectionObserver(&observer, GetTaskRunner()); |
406 notifier.AddOnLineObserver(&observer, GetTaskRunner()); | 552 notifier.AddOnLineObserver(&observer, GetTaskRunner()); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 EXPECT_EQ(observer2.CallbackCount(), 1); | 615 EXPECT_EQ(observer2.CallbackCount(), 1); |
470 | 616 |
471 notifier_.SetOnLine(false); | 617 notifier_.SetOnLine(false); |
472 RunPendingTasks(); | 618 RunPendingTasks(); |
473 EXPECT_FALSE(observer1.ObservedOnLineState()); | 619 EXPECT_FALSE(observer1.ObservedOnLineState()); |
474 EXPECT_FALSE(observer2.ObservedOnLineState()); | 620 EXPECT_FALSE(observer2.ObservedOnLineState()); |
475 EXPECT_EQ(observer1.CallbackCount(), 2); | 621 EXPECT_EQ(observer1.CallbackCount(), 2); |
476 EXPECT_EQ(observer2.CallbackCount(), 2); | 622 EXPECT_EQ(observer2.CallbackCount(), 2); |
477 | 623 |
478 notifier_.SetOnLine(true); | 624 notifier_.SetOnLine(true); |
479 notifier_.SetWebConnection(kWebConnectionTypeEthernet, | 625 SetConnection(kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
480 kEthernetMaxBandwidthMbps); | 626 kEthernetHttpRtt, kEthernetTransportRtt, |
481 RunPendingTasks(); | 627 kEthernetThroughputMbps); |
| 628 |
482 EXPECT_TRUE(observer1.ObservedOnLineState()); | 629 EXPECT_TRUE(observer1.ObservedOnLineState()); |
483 EXPECT_TRUE(observer2.ObservedOnLineState()); | 630 EXPECT_TRUE(observer2.ObservedOnLineState()); |
484 EXPECT_TRUE(VerifyObservations(observer2, kWebConnectionTypeEthernet, | 631 EXPECT_TRUE(VerifyObservations( |
485 kEthernetMaxBandwidthMbps)); | 632 observer2, kWebConnectionTypeEthernet, kEthernetMaxBandwidthMbps, |
| 633 kEthernetHttpRtt, kEthernetTransportRtt, kEthernetThroughputMbps)); |
486 EXPECT_EQ(observer1.CallbackCount(), 3); | 634 EXPECT_EQ(observer1.CallbackCount(), 3); |
487 EXPECT_EQ(observer2.CallbackCount(), 4); | 635 EXPECT_EQ(observer2.CallbackCount(), 5); |
488 | 636 |
489 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); | 637 notifier_.RemoveConnectionObserver(&observer1, GetTaskRunner()); |
490 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); | 638 notifier_.RemoveConnectionObserver(&observer2, GetTaskRunner()); |
491 } | 639 } |
492 | 640 |
493 } // namespace blink | 641 } // namespace blink |
OLD | NEW |