Skip to content

Commit

Permalink
Make NetworkChangeNotifier.isOnline() return true for UNKNOWN connect…
Browse files Browse the repository at this point in the history
…ion type.

CONNECTION_UNKNOWN still means the device is online so it should return true
for isOnline().

Review URL: https://codereview.chromium.org/1593803002

Cr-Commit-Position: refs/heads/master@{#370399}
  • Loading branch information
JensenPaul authored and Commit bot committed Jan 20, 2016
1 parent 974c761 commit 7b00c26
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ public static NetworkChangeNotifierAutoDetect getAutoDetectorForTest() {
*/
public static boolean isOnline() {
int connectionType = getInstance().getCurrentConnectionType();
return connectionType != ConnectionType.CONNECTION_UNKNOWN
&& connectionType != ConnectionType.CONNECTION_NONE;
return connectionType != ConnectionType.CONNECTION_NONE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -675,4 +675,25 @@ int getApplicationState() {
// Verify network list purged.
observer.assertLastChange(ChangeType.PURGE_LIST, NetId.INVALID);
}

/**
* Tests that isOnline() returns the correct result.
*/
@UiThreadTest
@MediumTest
@Feature({"Android-AppBase"})
public void testNetworkChangeNotifierIsOnline() throws InterruptedException {
NetworkChangeNotifier notifier = NetworkChangeNotifier.getInstance();
Intent intent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
// For any connection type it should return true.
for (int i = ConnectivityManager.TYPE_MOBILE; i < ConnectivityManager.TYPE_VPN; i++) {
mConnectivityDelegate.setActiveNetworkExists(true);
mConnectivityDelegate.setNetworkType(i);
mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
assertTrue(notifier.isOnline());
}
mConnectivityDelegate.setActiveNetworkExists(false);
mReceiver.onReceive(getInstrumentation().getTargetContext(), intent);
assertFalse(notifier.isOnline());
}
}

0 comments on commit 7b00c26

Please sign in to comment.