OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // See network_change_notifier_android.h for design explanations. | 5 // See network_change_notifier_android.h for design explanations. |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 class NetworkChangeNotifierDelegateAndroidObserver | 22 class NetworkChangeNotifierDelegateAndroidObserver |
23 : public NetworkChangeNotifierDelegateAndroid::Observer { | 23 : public NetworkChangeNotifierDelegateAndroid::Observer { |
24 public: | 24 public: |
25 NetworkChangeNotifierDelegateAndroidObserver() | 25 NetworkChangeNotifierDelegateAndroidObserver() |
26 : type_notifications_count_(0), max_bandwidth_notifications_count_(0) {} | 26 : type_notifications_count_(0), max_bandwidth_notifications_count_(0) {} |
27 | 27 |
28 // NetworkChangeNotifierDelegateAndroid::Observer: | 28 // NetworkChangeNotifierDelegateAndroid::Observer: |
29 void OnConnectionTypeChanged() override { type_notifications_count_++; } | 29 void OnConnectionTypeChanged() override { type_notifications_count_++; } |
30 | 30 |
31 void OnMaxBandwidthChanged(double max_bandwidth_mbps) override { | 31 void OnMaxBandwidthChanged(net::NetworkChangeNotifier::ConnectionType type, |
| 32 double max_bandwidth_mbps) override { |
32 max_bandwidth_notifications_count_++; | 33 max_bandwidth_notifications_count_++; |
33 } | 34 } |
34 | 35 |
35 int type_notifications_count() const { return type_notifications_count_; } | 36 int type_notifications_count() const { return type_notifications_count_; } |
36 int bandwidth_notifications_count() const { | 37 int bandwidth_notifications_count() const { |
37 return max_bandwidth_notifications_count_; | 38 return max_bandwidth_notifications_count_; |
38 } | 39 } |
39 | 40 |
40 private: | 41 private: |
41 int type_notifications_count_; | 42 int type_notifications_count_; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 &NetworkChangeNotifierObserver::notifications_count, | 242 &NetworkChangeNotifierObserver::notifications_count, |
242 base::Unretained(&connection_type_observer_)), | 243 base::Unretained(&connection_type_observer_)), |
243 base::Bind(&NetworkChangeNotifier::GetConnectionType)); | 244 base::Bind(&NetworkChangeNotifier::GetConnectionType)); |
244 // Check that *all* the observers are notified. | 245 // Check that *all* the observers are notified. |
245 EXPECT_EQ(connection_type_observer_.notifications_count(), | 246 EXPECT_EQ(connection_type_observer_.notifications_count(), |
246 other_connection_type_observer_.notifications_count()); | 247 other_connection_type_observer_.notifications_count()); |
247 } | 248 } |
248 | 249 |
249 TEST_F(NetworkChangeNotifierAndroidTest, MaxBandwidth) { | 250 TEST_F(NetworkChangeNotifierAndroidTest, MaxBandwidth) { |
250 SetOnline(); | 251 SetOnline(); |
251 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, | 252 double max_bandwidth_mbps = 0.0; |
252 notifier_->GetConnectionType()); | 253 NetworkChangeNotifier::ConnectionType connection_type = |
253 EXPECT_EQ(std::numeric_limits<double>::infinity(), | 254 NetworkChangeNotifier::CONNECTION_NONE; |
254 notifier_->GetMaxBandwidth()); | 255 notifier_->GetMaxBandwidthAndConnectionType(&max_bandwidth_mbps, |
| 256 &connection_type); |
| 257 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, connection_type); |
| 258 EXPECT_EQ(std::numeric_limits<double>::infinity(), max_bandwidth_mbps); |
255 SetOffline(); | 259 SetOffline(); |
256 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE, | 260 notifier_->GetMaxBandwidthAndConnectionType(&max_bandwidth_mbps, |
257 notifier_->GetConnectionType()); | 261 &connection_type); |
258 EXPECT_EQ(0.0, notifier_->GetMaxBandwidth()); | 262 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE, connection_type); |
| 263 EXPECT_EQ(0.0, max_bandwidth_mbps); |
259 } | 264 } |
260 | 265 |
261 TEST_F(NetworkChangeNotifierDelegateAndroidTest, | 266 TEST_F(NetworkChangeNotifierDelegateAndroidTest, |
262 MaxBandwidthNotifiedOnConnectionChange) { | 267 MaxBandwidthNotifiedOnConnectionChange) { |
263 EXPECT_EQ(0, delegate_observer_.bandwidth_notifications_count()); | 268 EXPECT_EQ(0, delegate_observer_.bandwidth_notifications_count()); |
264 SetOffline(); | 269 SetOffline(); |
265 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); | 270 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); |
266 SetOnline(); | 271 SetOnline(); |
267 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); | 272 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); |
268 SetOnline(); | 273 SetOnline(); |
269 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); | 274 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); |
270 } | 275 } |
271 | 276 |
272 TEST_F(NetworkChangeNotifierAndroidTest, InitialSignal) { | 277 TEST_F(NetworkChangeNotifierAndroidTest, InitialSignal) { |
273 DNSChangeObserver dns_change_observer; | 278 DNSChangeObserver dns_change_observer; |
274 NetworkChangeNotifier::AddDNSObserver(&dns_change_observer); | 279 NetworkChangeNotifier::AddDNSObserver(&dns_change_observer); |
275 base::MessageLoop::current()->Run(); | 280 base::MessageLoop::current()->Run(); |
276 EXPECT_EQ(1, dns_change_observer.initial_notifications_count()); | 281 EXPECT_EQ(1, dns_change_observer.initial_notifications_count()); |
277 EXPECT_EQ(0, dns_change_observer.change_notifications_count()); | 282 EXPECT_EQ(0, dns_change_observer.change_notifications_count()); |
278 NetworkChangeNotifier::RemoveDNSObserver(&dns_change_observer); | 283 NetworkChangeNotifier::RemoveDNSObserver(&dns_change_observer); |
279 } | 284 } |
280 | 285 |
281 } // namespace net | 286 } // namespace net |
OLD | NEW |