| 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" |
| 11 #include "base/run_loop.h" |
| 11 #include "net/android/network_change_notifier_android.h" | 12 #include "net/android/network_change_notifier_android.h" |
| 12 #include "net/android/network_change_notifier_delegate_android.h" | 13 #include "net/android/network_change_notifier_delegate_android.h" |
| 13 #include "net/base/ip_address.h" | 14 #include "net/base/ip_address.h" |
| 14 #include "net/base/network_change_notifier.h" | 15 #include "net/base/network_change_notifier.h" |
| 15 #include "net/dns/dns_config_service.h" | 16 #include "net/dns/dns_config_service.h" |
| 16 #include "net/dns/dns_protocol.h" | 17 #include "net/dns/dns_protocol.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 SetOnline(); | 208 SetOnline(); |
| 208 EXPECT_EQ(2, notifications_count_getter.Run()); | 209 EXPECT_EQ(2, notifications_count_getter.Run()); |
| 209 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, | 210 EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, |
| 210 connection_type_getter.Run()); | 211 connection_type_getter.Run()); |
| 211 } | 212 } |
| 212 | 213 |
| 213 void SetOnline() { | 214 void SetOnline() { |
| 214 delegate_.SetOnline(); | 215 delegate_.SetOnline(); |
| 215 // Note that this is needed because base::ObserverListThreadSafe uses | 216 // Note that this is needed because base::ObserverListThreadSafe uses |
| 216 // PostTask(). | 217 // PostTask(). |
| 217 base::MessageLoop::current()->RunUntilIdle(); | 218 base::RunLoop().RunUntilIdle(); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void SetOffline() { | 221 void SetOffline() { |
| 221 delegate_.SetOffline(); | 222 delegate_.SetOffline(); |
| 222 // See comment above. | 223 // See comment above. |
| 223 base::MessageLoop::current()->RunUntilIdle(); | 224 base::RunLoop().RunUntilIdle(); |
| 224 } | 225 } |
| 225 | 226 |
| 226 void FakeMaxBandwidthChange(double max_bandwidth_mbps) { | 227 void FakeMaxBandwidthChange(double max_bandwidth_mbps) { |
| 227 delegate_.FakeMaxBandwidthChanged(max_bandwidth_mbps); | 228 delegate_.FakeMaxBandwidthChanged(max_bandwidth_mbps); |
| 228 base::MessageLoop::current()->RunUntilIdle(); | 229 base::RunLoop().RunUntilIdle(); |
| 229 } | 230 } |
| 230 | 231 |
| 231 void FakeNetworkChange(ChangeType change, | 232 void FakeNetworkChange(ChangeType change, |
| 232 NetworkChangeNotifier::NetworkHandle network, | 233 NetworkChangeNotifier::NetworkHandle network, |
| 233 ConnectionType type) { | 234 ConnectionType type) { |
| 234 switch (change) { | 235 switch (change) { |
| 235 case CONNECTED: | 236 case CONNECTED: |
| 236 delegate_.FakeNetworkConnected(network, type); | 237 delegate_.FakeNetworkConnected(network, type); |
| 237 break; | 238 break; |
| 238 case SOON_TO_DISCONNECT: | 239 case SOON_TO_DISCONNECT: |
| 239 delegate_.FakeNetworkSoonToBeDisconnected(network); | 240 delegate_.FakeNetworkSoonToBeDisconnected(network); |
| 240 break; | 241 break; |
| 241 case DISCONNECTED: | 242 case DISCONNECTED: |
| 242 delegate_.FakeNetworkDisconnected(network); | 243 delegate_.FakeNetworkDisconnected(network); |
| 243 break; | 244 break; |
| 244 case MADE_DEFAULT: | 245 case MADE_DEFAULT: |
| 245 delegate_.FakeDefaultNetwork(network, type); | 246 delegate_.FakeDefaultNetwork(network, type); |
| 246 break; | 247 break; |
| 247 case NONE: | 248 case NONE: |
| 248 NOTREACHED(); | 249 NOTREACHED(); |
| 249 break; | 250 break; |
| 250 } | 251 } |
| 251 // See comment above. | 252 // See comment above. |
| 252 base::MessageLoop::current()->RunUntilIdle(); | 253 base::RunLoop().RunUntilIdle(); |
| 253 } | 254 } |
| 254 | 255 |
| 255 void FakePurgeActiveNetworkList(NetworkChangeNotifier::NetworkList networks) { | 256 void FakePurgeActiveNetworkList(NetworkChangeNotifier::NetworkList networks) { |
| 256 delegate_.FakePurgeActiveNetworkList(networks); | 257 delegate_.FakePurgeActiveNetworkList(networks); |
| 257 // See comment above. | 258 // See comment above. |
| 258 base::MessageLoop::current()->RunUntilIdle(); | 259 base::RunLoop().RunUntilIdle(); |
| 259 } | 260 } |
| 260 | 261 |
| 261 NetworkChangeNotifierDelegateAndroid delegate_; | 262 NetworkChangeNotifierDelegateAndroid delegate_; |
| 262 }; | 263 }; |
| 263 | 264 |
| 264 // Tests that NetworkChangeNotifierDelegateAndroid is initialized with the | 265 // Tests that NetworkChangeNotifierDelegateAndroid is initialized with the |
| 265 // actual connection type rather than a hardcoded one (e.g. | 266 // actual connection type rather than a hardcoded one (e.g. |
| 266 // CONNECTION_UNKNOWN). Initializing the connection type to CONNECTION_UNKNOWN | 267 // CONNECTION_UNKNOWN). Initializing the connection type to CONNECTION_UNKNOWN |
| 267 // and relying on the first network change notification to set it correctly can | 268 // and relying on the first network change notification to set it correctly can |
| 268 // be problematic in case there is a long delay between the delegate's | 269 // be problematic in case there is a long delay between the delegate's |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); | 416 EXPECT_EQ(1, delegate_observer_.bandwidth_notifications_count()); |
| 416 SetOnline(); | 417 SetOnline(); |
| 417 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); | 418 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); |
| 418 SetOnline(); | 419 SetOnline(); |
| 419 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); | 420 EXPECT_EQ(2, delegate_observer_.bandwidth_notifications_count()); |
| 420 } | 421 } |
| 421 | 422 |
| 422 TEST_F(NetworkChangeNotifierAndroidTest, InitialSignal) { | 423 TEST_F(NetworkChangeNotifierAndroidTest, InitialSignal) { |
| 423 DNSChangeObserver dns_change_observer; | 424 DNSChangeObserver dns_change_observer; |
| 424 NetworkChangeNotifier::AddDNSObserver(&dns_change_observer); | 425 NetworkChangeNotifier::AddDNSObserver(&dns_change_observer); |
| 425 base::MessageLoop::current()->Run(); | 426 base::RunLoop().Run(); |
| 426 EXPECT_EQ(1, dns_change_observer.initial_notifications_count()); | 427 EXPECT_EQ(1, dns_change_observer.initial_notifications_count()); |
| 427 EXPECT_EQ(0, dns_change_observer.change_notifications_count()); | 428 EXPECT_EQ(0, dns_change_observer.change_notifications_count()); |
| 428 NetworkChangeNotifier::RemoveDNSObserver(&dns_change_observer); | 429 NetworkChangeNotifier::RemoveDNSObserver(&dns_change_observer); |
| 429 } | 430 } |
| 430 | 431 |
| 431 TEST_F(NetworkChangeNotifierAndroidTest, NetworkCallbacks) { | 432 TEST_F(NetworkChangeNotifierAndroidTest, NetworkCallbacks) { |
| 432 ForceNetworkHandlesSupportedForTesting(); | 433 ForceNetworkHandlesSupportedForTesting(); |
| 433 | 434 |
| 434 TestNetworkObserver network_observer; | 435 TestNetworkObserver network_observer; |
| 435 NetworkChangeNotifier::AddNetworkObserver(&network_observer); | 436 NetworkChangeNotifier::AddNetworkObserver(&network_observer); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 NetworkChangeNotifier::GetConnectedNetworks(&network_list); | 520 NetworkChangeNotifier::GetConnectedNetworks(&network_list); |
| 520 EXPECT_EQ(1u, network_list.size()); | 521 EXPECT_EQ(1u, network_list.size()); |
| 521 EXPECT_EQ(100, network_list[0]); | 522 EXPECT_EQ(100, network_list[0]); |
| 522 EXPECT_EQ(NetworkChangeNotifier::kInvalidNetworkHandle, | 523 EXPECT_EQ(NetworkChangeNotifier::kInvalidNetworkHandle, |
| 523 NetworkChangeNotifier::GetDefaultNetwork()); | 524 NetworkChangeNotifier::GetDefaultNetwork()); |
| 524 | 525 |
| 525 NetworkChangeNotifier::RemoveNetworkObserver(&network_observer); | 526 NetworkChangeNotifier::RemoveNetworkObserver(&network_observer); |
| 526 } | 527 } |
| 527 | 528 |
| 528 } // namespace net | 529 } // namespace net |
| OLD | NEW |