summaryrefslogtreecommitdiffstats
path: root/net/android/javatests/src/org
diff options
context:
space:
mode:
authorpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-04 12:34:34 +0000
committerpliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-04 12:34:34 +0000
commit18eab2d146b6d158992fa6ddc6a266a2a5264c81 (patch)
tree8af2175525100b4eba14d47fa0d5361012be048b /net/android/javatests/src/org
parent697f88738e456b0eb4291c297095a72f40bdb7b4 (diff)
downloadchromium_src-18eab2d146b6d158992fa6ddc6a266a2a5264c81.zip
chromium_src-18eab2d146b6d158992fa6ddc6a266a2a5264c81.tar.gz
chromium_src-18eab2d146b6d158992fa6ddc6a266a2a5264c81.tar.bz2
Provide NetworkChangeNotifierAndroid with the actual initial connection type.
The Android NetworkChangeNotifier is initialized with connection_type = CONNECTION_UNKNOWN. This means that the result returned by NetworkChangeNotifier::IsOffline() is inaccurate until the first network change happens. This can happen for the whole initialization path if the user starts Chrome after he explicitly disabled WiFi and 3G. This CL updates NetworkChangeNotifier.java to support multiple native observers. This can happen in case NetworkChangeNotifierDelegateAndroid is instantiated multiple times (e.g. when multiple factories are instantiated). Still on the Java side, NetworkChangeNotifier.java was also changed to fetch the actual connection type as soon as the auto-detector (interacting with the Android platform) is enabled. On the native side, NetworkChangeNotifierDelegateAndroid now fetches at construction time the current connection type from the Java side singleton through a direct JNI function call (possible since the delegate is constructed on the JNI thread). NetworkChangeNotifierAndroid::GetCurrentConnectionType() is now a simple wrapper around the delegate's GetCurrentConnectionType() method (which is thread-safe). BUG=166883 Review URL: https://codereview.chromium.org/11628008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175138 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/android/javatests/src/org')
-rw-r--r--net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java12
1 files changed, 6 insertions, 6 deletions
diff --git a/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java b/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
index 9bc6332..0bea726 100644
--- a/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
+++ b/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
@@ -40,15 +40,16 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
private int mNetworkType;
private int mNetworkSubtype;
- MockConnectivityManagerDelegate() {
- super(null);
- }
-
@Override
boolean activeNetworkExists() {
return mActiveNetworkExists;
}
+ @Override
+ boolean isConnected() {
+ return getNetworkType() != NetworkChangeNotifier.CONNECTION_NONE;
+ }
+
void setActiveNetworkExists(boolean networkExists) {
mActiveNetworkExists = networkExists;
}
@@ -82,7 +83,7 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
public void testNetworkChangeNotifierJavaObservers() throws InterruptedException {
// Create a new notifier that doesn't have a native-side counterpart.
Context context = getInstrumentation().getTargetContext();
- NetworkChangeNotifier.createInstance(context, 0);
+ NetworkChangeNotifier.resetInstanceForTests(context);
NetworkChangeNotifier.setAutoDetectConnectivityState(true);
NetworkChangeNotifierAutoDetect receiver = NetworkChangeNotifier.getAutoDetectorForTest();
@@ -109,7 +110,6 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
connectivityDelegate.setActiveNetworkExists(false);
connectivityDelegate.setNetworkType(NetworkChangeNotifier.CONNECTION_NONE);
Intent noConnectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
- noConnectivityIntent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
receiver.onReceive(getInstrumentation().getTargetContext(), noConnectivityIntent);
assertTrue(observer.hasReceivedNotification());
}