| 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( |
| 32 double max_bandwidth_mbps, |
| 33 net::NetworkChangeNotifier::ConnectionType type) override { |
| 32 max_bandwidth_notifications_count_++; | 34 max_bandwidth_notifications_count_++; |
| 33 } | 35 } |
| 34 | 36 |
| 35 int type_notifications_count() const { return type_notifications_count_; } | 37 int type_notifications_count() const { return type_notifications_count_; } |
| 36 int bandwidth_notifications_count() const { | 38 int bandwidth_notifications_count() const { |
| 37 return max_bandwidth_notifications_count_; | 39 return max_bandwidth_notifications_count_; |
| 38 } | 40 } |
| 39 | 41 |
| 40 private: | 42 private: |
| 41 int type_notifications_count_; | 43 int type_notifications_count_; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 &NetworkChangeNotifierObserver::notifications_count, | 243 &NetworkChangeNotifierObserver::notifications_count, |
| 242 base::Unretained(&connection_type_observer_)), | 244 base::Unretained(&connection_type_observer_)), |
| 243 base::Bind(&NetworkChangeNotifier::GetConnectionType)); | 245 base::Bind(&NetworkChangeNotifier::GetConnectionType)); |
| 244 // Check that *all* the observers are notified. | 246 // Check that *all* the observers are notified. |
| 245 EXPECT_EQ(connection_type_observer_.notifications_count(), | 247 EXPECT_EQ(connection_type_observer_.notifications_count(), |
| 246 other_connection_type_observer_.notifications_count()); | 248 other_connection_type_observer_.notifications_count()); |
| 247 } | 249 } |
| 248 | 250 |
| 249 TEST_F(NetworkChangeNotifierAndroidTest, MaxBandwidth) { | 251 TEST_F(NetworkChangeNotifierAndroidTest, MaxBandwidth) { |
| 250 SetOnline(); | 252 SetOnline(); |
| 251 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, | 253 double max_bandwidth_mbps = 0.0; |
| 252 notifier_->GetConnectionType()); | 254 NetworkChangeNotifier::ConnectionType connection_type = |
| 253 EXPECT_EQ(std::numeric_limits<double>::infinity(), | 255 NetworkChangeNotifier::CONNECTION_NONE; |
| 254 notifier_->GetMaxBandwidth()); | 256 notifier_->GetMaxBandwidthAndConnectionType(&max_bandwidth_mbps, |
| 257 &connection_type); |
| 258 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, connection_type); |
| 259 EXPECT_EQ(std::numeric_limits<double>::infinity(), max_bandwidth_mbps); |
| 255 SetOffline(); | 260 SetOffline(); |
| 256 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE, | 261 notifier_->GetMaxBandwidthAndConnectionType(&max_bandwidth_mbps, |
| 257 notifier_->GetConnectionType()); | 262 &connection_type); |
| 258 EXPECT_EQ(0.0, notifier_->GetMaxBandwidth()); | 263 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE, connection_type); |
| 264 EXPECT_EQ(0.0, max_bandwidth_mbps); |
| 259 } | 265 } |
| 260 | 266 |
| 261 TEST_F(NetworkChangeNotifierDelegateAndroidTest, | 267 TEST_F(NetworkChangeNotifierDelegateAndroidTest, |
| 262 MaxBandwidthNotifiedOnConnectionChange) { | 268 MaxBandwidthNotifiedOnConnectionChange) { |
| 263 EXPECT_EQ(0, delegate_observer_.bandwidth_notifications_count()); | 269 EXPECT_EQ(0, delegate_observer_.bandwidth_notifications_count()); |
| 264 SetOffline(); | 270 SetOffline(); |
| 265 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); | 271 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); |
| 266 SetOnline(); | 272 SetOnline(); |
| 267 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); | 273 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); |
| 268 SetOnline(); | 274 SetOnline(); |
| 269 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); | 275 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); |
| 270 } | 276 } |
| 271 | 277 |
| 272 TEST_F(NetworkChangeNotifierAndroidTest, InitialSignal) { | 278 TEST_F(NetworkChangeNotifierAndroidTest, InitialSignal) { |
| 273 DNSChangeObserver dns_change_observer; | 279 DNSChangeObserver dns_change_observer; |
| 274 NetworkChangeNotifier::AddDNSObserver(&dns_change_observer); | 280 NetworkChangeNotifier::AddDNSObserver(&dns_change_observer); |
| 275 base::MessageLoop::current()->Run(); | 281 base::MessageLoop::current()->Run(); |
| 276 EXPECT_EQ(1, dns_change_observer.initial_notifications_count()); | 282 EXPECT_EQ(1, dns_change_observer.initial_notifications_count()); |
| 277 EXPECT_EQ(0, dns_change_observer.change_notifications_count()); | 283 EXPECT_EQ(0, dns_change_observer.change_notifications_count()); |
| 278 NetworkChangeNotifier::RemoveDNSObserver(&dns_change_observer); | 284 NetworkChangeNotifier::RemoveDNSObserver(&dns_change_observer); |
| 279 } | 285 } |
| 280 | 286 |
| 281 } // namespace net | 287 } // namespace net |
| OLD | NEW |