| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 174 |
| 175 ChangeType last_change_type_; | 175 ChangeType last_change_type_; |
| 176 NetworkChangeNotifier::NetworkHandle last_network_changed_; | 176 NetworkChangeNotifier::NetworkHandle last_network_changed_; |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 } // namespace | 179 } // namespace |
| 180 | 180 |
| 181 class BaseNetworkChangeNotifierAndroidTest : public testing::Test { | 181 class BaseNetworkChangeNotifierAndroidTest : public testing::Test { |
| 182 protected: | 182 protected: |
| 183 typedef NetworkChangeNotifier::ConnectionType ConnectionType; | 183 typedef NetworkChangeNotifier::ConnectionType ConnectionType; |
| 184 typedef NetworkChangeNotifier::ConnectionSubtype ConnectionSubtype; |
| 184 | 185 |
| 185 ~BaseNetworkChangeNotifierAndroidTest() override {} | 186 ~BaseNetworkChangeNotifierAndroidTest() override {} |
| 186 | 187 |
| 187 void RunTest( | 188 void RunTest( |
| 188 const base::Callback<int(void)>& notifications_count_getter, | 189 const base::Callback<int(void)>& notifications_count_getter, |
| 189 const base::Callback<ConnectionType(void)>& connection_type_getter) { | 190 const base::Callback<ConnectionType(void)>& connection_type_getter) { |
| 190 EXPECT_EQ(0, notifications_count_getter.Run()); | 191 EXPECT_EQ(0, notifications_count_getter.Run()); |
| 191 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, | 192 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, |
| 192 connection_type_getter.Run()); | 193 connection_type_getter.Run()); |
| 193 | 194 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 217 // PostTask(). | 218 // PostTask(). |
| 218 base::RunLoop().RunUntilIdle(); | 219 base::RunLoop().RunUntilIdle(); |
| 219 } | 220 } |
| 220 | 221 |
| 221 void SetOffline() { | 222 void SetOffline() { |
| 222 delegate_.SetOffline(); | 223 delegate_.SetOffline(); |
| 223 // See comment above. | 224 // See comment above. |
| 224 base::RunLoop().RunUntilIdle(); | 225 base::RunLoop().RunUntilIdle(); |
| 225 } | 226 } |
| 226 | 227 |
| 227 void FakeMaxBandwidthChange(double max_bandwidth_mbps) { | 228 void FakeConnectionSubtypeChange(ConnectionSubtype subtype) { |
| 228 delegate_.FakeMaxBandwidthChanged(max_bandwidth_mbps); | 229 delegate_.FakeConnectionSubtypeChanged(subtype); |
| 229 base::RunLoop().RunUntilIdle(); | 230 base::RunLoop().RunUntilIdle(); |
| 230 } | 231 } |
| 231 | 232 |
| 232 void FakeNetworkChange(ChangeType change, | 233 void FakeNetworkChange(ChangeType change, |
| 233 NetworkChangeNotifier::NetworkHandle network, | 234 NetworkChangeNotifier::NetworkHandle network, |
| 234 ConnectionType type) { | 235 ConnectionType type) { |
| 235 switch (change) { | 236 switch (change) { |
| 236 case CONNECTED: | 237 case CONNECTED: |
| 237 delegate_.FakeNetworkConnected(network, type); | 238 delegate_.FakeNetworkConnected(network, type); |
| 238 break; | 239 break; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 SetOffline(); | 390 SetOffline(); |
| 390 notifier_->GetMaxBandwidthAndConnectionType(&max_bandwidth_mbps, | 391 notifier_->GetMaxBandwidthAndConnectionType(&max_bandwidth_mbps, |
| 391 &connection_type); | 392 &connection_type); |
| 392 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE, connection_type); | 393 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE, connection_type); |
| 393 EXPECT_EQ(0.0, max_bandwidth_mbps); | 394 EXPECT_EQ(0.0, max_bandwidth_mbps); |
| 394 } | 395 } |
| 395 | 396 |
| 396 TEST_F(NetworkChangeNotifierDelegateAndroidTest, MaxBandwidthCallbackNotifier) { | 397 TEST_F(NetworkChangeNotifierDelegateAndroidTest, MaxBandwidthCallbackNotifier) { |
| 397 // The bandwidth notification should always be forwarded, even if the value | 398 // The bandwidth notification should always be forwarded, even if the value |
| 398 // doesn't change (because the type might have changed). | 399 // doesn't change (because the type might have changed). |
| 399 FakeMaxBandwidthChange(100.0); | 400 FakeConnectionSubtypeChange(ConnectionSubtype::SUBTYPE_CDMA); |
| 400 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); | 401 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); |
| 401 EXPECT_EQ(1, max_bandwidth_observer_.notifications_count()); | 402 EXPECT_EQ(1, max_bandwidth_observer_.notifications_count()); |
| 402 | 403 |
| 403 FakeMaxBandwidthChange(100.0); | 404 FakeConnectionSubtypeChange(ConnectionSubtype::SUBTYPE_CDMA); |
| 404 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); | 405 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); |
| 405 EXPECT_EQ(2, max_bandwidth_observer_.notifications_count()); | 406 EXPECT_EQ(2, max_bandwidth_observer_.notifications_count()); |
| 406 | 407 |
| 407 FakeMaxBandwidthChange(101.0); | 408 FakeConnectionSubtypeChange(ConnectionSubtype::SUBTYPE_LTE); |
| 408 EXPECT_EQ(3, delegate_observer_.bandwidth_notifications_count()); | 409 EXPECT_EQ(3, delegate_observer_.bandwidth_notifications_count()); |
| 409 EXPECT_EQ(3, max_bandwidth_observer_.notifications_count()); | 410 EXPECT_EQ(3, max_bandwidth_observer_.notifications_count()); |
| 410 } | 411 } |
| 411 | 412 |
| 412 TEST_F(NetworkChangeNotifierDelegateAndroidTest, | 413 TEST_F(NetworkChangeNotifierDelegateAndroidTest, |
| 413 MaxBandwidthNotifiedOnConnectionChange) { | 414 MaxBandwidthNotifiedOnConnectionChange) { |
| 414 EXPECT_EQ(0, delegate_observer_.bandwidth_notifications_count()); | 415 EXPECT_EQ(0, delegate_observer_.bandwidth_notifications_count()); |
| 415 SetOffline(); | 416 SetOffline(); |
| 416 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); | 417 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); |
| 417 SetOnline(); | 418 SetOnline(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 NetworkChangeNotifier::GetConnectedNetworks(&network_list); | 521 NetworkChangeNotifier::GetConnectedNetworks(&network_list); |
| 521 EXPECT_EQ(1u, network_list.size()); | 522 EXPECT_EQ(1u, network_list.size()); |
| 522 EXPECT_EQ(100, network_list[0]); | 523 EXPECT_EQ(100, network_list[0]); |
| 523 EXPECT_EQ(NetworkChangeNotifier::kInvalidNetworkHandle, | 524 EXPECT_EQ(NetworkChangeNotifier::kInvalidNetworkHandle, |
| 524 NetworkChangeNotifier::GetDefaultNetwork()); | 525 NetworkChangeNotifier::GetDefaultNetwork()); |
| 525 | 526 |
| 526 NetworkChangeNotifier::RemoveNetworkObserver(&network_observer); | 527 NetworkChangeNotifier::RemoveNetworkObserver(&network_observer); |
| 527 } | 528 } |
| 528 | 529 |
| 529 } // namespace net | 530 } // namespace net |
| OLD | NEW |