Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Unified Diff: net/android/network_change_notifier_android_unittest.cc

Issue 11628008: Provide NetworkChangeNotifierAndroid with the actual initial connection type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try another approach Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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() {

Powered by Google App Engine
This is Rietveld 408576698