| Index: net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
|
| diff --git a/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java b/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
|
| index d2229dca0322671393a3071e82056dff8858aed0..b59246e7f03c99175e5c2408387e6f86894687ee 100644
|
| --- a/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
|
| +++ b/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
|
| @@ -101,18 +101,31 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
|
| protected void setUp() throws Exception {
|
| super.setUp();
|
| LibraryLoader.ensureInitialized();
|
| - createTestNotifier();
|
| + createTestNotifier(WatchForChanges.ONLY_WHEN_APP_IN_FOREGROUND);
|
| }
|
|
|
| private NetworkChangeNotifierAutoDetect mReceiver;
|
| private MockConnectivityManagerDelegate mConnectivityDelegate;
|
| private MockWifiManagerDelegate mWifiDelegate;
|
|
|
| - private void createTestNotifier() {
|
| + private static enum WatchForChanges {
|
| + ALWAYS,
|
| + ONLY_WHEN_APP_IN_FOREGROUND,
|
| + }
|
| +
|
| + /**
|
| + * Helper method to create a notifier and delegates for testing.
|
| + * @param watchForChanges indicates whether app wants to watch for changes always or only when
|
| + * it is in the foreground.
|
| + */
|
| + private void createTestNotifier(WatchForChanges watchForChanges) {
|
| Context context = getInstrumentation().getTargetContext();
|
| NetworkChangeNotifier.resetInstanceForTests(context);
|
| - NetworkChangeNotifier.setAutoDetectConnectivityState(true);
|
| -
|
| + if (watchForChanges == WatchForChanges.ALWAYS) {
|
| + NetworkChangeNotifier.registerToReceiveNotificationsAlways();
|
| + } else {
|
| + NetworkChangeNotifier.setAutoDetectConnectivityState(true);
|
| + }
|
| mReceiver = NetworkChangeNotifier.getAutoDetectorForTest();
|
| assertNotNull(mReceiver);
|
|
|
| @@ -280,4 +293,21 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
|
| mReceiver.onApplicationStateChange(ApplicationState.HAS_RUNNING_ACTIVITIES);
|
| assertTrue(observer.hasReceivedNotification());
|
| }
|
| +
|
| + /**
|
| + * Tests that when setting {@code registerToReceiveNotificationsAlways()},
|
| + * a NetworkChangeNotifierAutoDetect object is successfully created.
|
| + */
|
| + @UiThreadTest
|
| + @MediumTest
|
| + @Feature({"Android-AppBase"})
|
| + public void testCreateNetworkChangeNotifierAlwaysWatchForChanges() throws InterruptedException {
|
| + createTestNotifier(WatchForChanges.ALWAYS);
|
| + // Make sure notifications can be received.
|
| + NetworkChangeNotifierTestObserver observer = new NetworkChangeNotifierTestObserver();
|
| + NetworkChangeNotifier.addConnectionTypeObserver(observer);
|
| + Intent connectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
|
| + mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
|
| + assertTrue(observer.hasReceivedNotification());
|
| + }
|
| }
|
|
|