| Index: net/android/network_change_notifier_android_unittest.cc
|
| diff --git a/net/android/network_change_notifier_android_unittest.cc b/net/android/network_change_notifier_android_unittest.cc
|
| index b66d6474c025720fb9996e0a86d2eefad9ba0407..9feebaa1435a8abd99c7b16bbe4c9797739e8727 100644
|
| --- a/net/android/network_change_notifier_android_unittest.cc
|
| +++ b/net/android/network_change_notifier_android_unittest.cc
|
| @@ -32,6 +32,8 @@ class ObserverImpl : public BaseObserver {
|
| // BaseObserver:
|
| virtual void OnConnectionTypeChanged(
|
| NetworkChangeNotifier::ConnectionType type) OVERRIDE {
|
| + if (type == current_connection_)
|
| + return;
|
| times_connection_type_changed_++;
|
| current_connection_ = type;
|
| }
|
| @@ -82,16 +84,45 @@ class BaseNetworkChangeNotifierAndroidTest : public testing::Test {
|
| connection_type_getter.Run());
|
| }
|
|
|
| + void AddObserverToDelegate(
|
| + NetworkChangeNotifierDelegateAndroid::Observer* observer) {
|
| + delegate_.AddObserver(observer);
|
| + // Note that this is needed because ObserverListThreadSafe uses PostTask().
|
| + MessageLoop::current()->RunUntilIdle();
|
| + }
|
| +
|
| void ForceConnectivityState(
|
| NetworkChangeNotifierDelegateAndroid::ConnectivityState state) {
|
| delegate_.ForceConnectivityState(state);
|
| - // Note that this is needed because ObserverListThreadSafe uses PostTask().
|
| + // See AddObserverToDelegate() above.
|
| MessageLoop::current()->RunUntilIdle();
|
| }
|
|
|
| NetworkChangeNotifierDelegateAndroid delegate_;
|
| };
|
|
|
| +// Tests that a notification is fired when
|
| +// a NetworkChangeNotifierDelegateAndroid's observer registers. This validates
|
| +// that NetworkChangeNotifierAndroid (the observer used in production) is
|
| +// initialized with the actual connection type rather than CONNECTION_UNKNOWN.
|
| +TEST_F(BaseNetworkChangeNotifierAndroidTest,
|
| + NotifierIsInitializedWithCurrentDelegateConnectionType) {
|
| + ObserverImpl<NetworkChangeNotifierDelegateAndroid::Observer> observer;
|
| +
|
| + ASSERT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN,
|
| + delegate_.GetConnectionType(NULL, NULL));
|
| +
|
| + ForceConnectivityState(NetworkChangeNotifierDelegateAndroid::OFFLINE);
|
| + ASSERT_EQ(NetworkChangeNotifier::CONNECTION_NONE,
|
| + delegate_.GetConnectionType(NULL, NULL));
|
| +
|
| + AddObserverToDelegate(&observer);
|
| + EXPECT_EQ(1, observer.times_connection_type_changed());
|
| + EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE,
|
| + observer.current_connection());
|
| + delegate_.RemoveObserver(&observer);
|
| +}
|
| +
|
| class NetworkChangeNotifierDelegateAndroidTest
|
| : public BaseNetworkChangeNotifierAndroidTest {
|
| protected:
|
| @@ -99,8 +130,8 @@ class NetworkChangeNotifierDelegateAndroidTest
|
| NetworkChangeNotifierDelegateAndroid::Observer> TestDelegateObserver;
|
|
|
| NetworkChangeNotifierDelegateAndroidTest() {
|
| - delegate_.AddObserver(&delegate_observer_);
|
| - delegate_.AddObserver(&other_delegate_observer_);
|
| + AddObserverToDelegate(&delegate_observer_);
|
| + AddObserverToDelegate(&other_delegate_observer_);
|
| }
|
|
|
| virtual ~NetworkChangeNotifierDelegateAndroidTest() {
|
|
|