| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.net; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.net.ConnectivityManager; | 9 import android.net.ConnectivityManager; |
| 10 import android.net.wifi.WifiManager; | 10 import android.net.wifi.WifiManager; |
| 11 import android.telephony.TelephonyManager; | 11 import android.telephony.TelephonyManager; |
| 12 import android.test.InstrumentationTestCase; | 12 import android.test.InstrumentationTestCase; |
| 13 import android.test.UiThreadTest; | 13 import android.test.UiThreadTest; |
| 14 import android.test.suitebuilder.annotation.MediumTest; | 14 import android.test.suitebuilder.annotation.MediumTest; |
| 15 | 15 |
| 16 import org.chromium.base.ApplicationState; | 16 import org.chromium.base.ApplicationState; |
| 17 import org.chromium.base.library_loader.LibraryLoader; | 17 import org.chromium.base.library_loader.LibraryLoader; |
| 18 import org.chromium.base.library_loader.LibraryProcessType; |
| 18 import org.chromium.base.test.util.Feature; | 19 import org.chromium.base.test.util.Feature; |
| 19 import org.chromium.net.NetworkChangeNotifierAutoDetect.NetworkState; | 20 import org.chromium.net.NetworkChangeNotifierAutoDetect.NetworkState; |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * Tests for org.chromium.net.NetworkChangeNotifier. | 23 * Tests for org.chromium.net.NetworkChangeNotifier. |
| 23 */ | 24 */ |
| 24 public class NetworkChangeNotifierTest extends InstrumentationTestCase { | 25 public class NetworkChangeNotifierTest extends InstrumentationTestCase { |
| 25 /** | 26 /** |
| 26 * Listens for alerts fired by the NetworkChangeNotifier when network status
changes. | 27 * Listens for alerts fired by the NetworkChangeNotifier when network status
changes. |
| 27 */ | 28 */ |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 94 } |
| 94 | 95 |
| 95 void setLinkSpeedInMbps(int linkSpeedInMbps) { | 96 void setLinkSpeedInMbps(int linkSpeedInMbps) { |
| 96 mLinkSpeedMbps = linkSpeedInMbps; | 97 mLinkSpeedMbps = linkSpeedInMbps; |
| 97 } | 98 } |
| 98 } | 99 } |
| 99 | 100 |
| 100 @Override | 101 @Override |
| 101 protected void setUp() throws Exception { | 102 protected void setUp() throws Exception { |
| 102 super.setUp(); | 103 super.setUp(); |
| 103 LibraryLoader.ensureInitialized(); | 104 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized(
); |
| 104 createTestNotifier(WatchForChanges.ONLY_WHEN_APP_IN_FOREGROUND); | 105 createTestNotifier(WatchForChanges.ONLY_WHEN_APP_IN_FOREGROUND); |
| 105 } | 106 } |
| 106 | 107 |
| 107 private NetworkChangeNotifierAutoDetect mReceiver; | 108 private NetworkChangeNotifierAutoDetect mReceiver; |
| 108 private MockConnectivityManagerDelegate mConnectivityDelegate; | 109 private MockConnectivityManagerDelegate mConnectivityDelegate; |
| 109 private MockWifiManagerDelegate mWifiDelegate; | 110 private MockWifiManagerDelegate mWifiDelegate; |
| 110 | 111 |
| 111 private static enum WatchForChanges { | 112 private static enum WatchForChanges { |
| 112 ALWAYS, | 113 ALWAYS, |
| 113 ONLY_WHEN_APP_IN_FOREGROUND, | 114 ONLY_WHEN_APP_IN_FOREGROUND, |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 public void testCreateNetworkChangeNotifierAlwaysWatchForChanges() throws In
terruptedException { | 305 public void testCreateNetworkChangeNotifierAlwaysWatchForChanges() throws In
terruptedException { |
| 305 createTestNotifier(WatchForChanges.ALWAYS); | 306 createTestNotifier(WatchForChanges.ALWAYS); |
| 306 // Make sure notifications can be received. | 307 // Make sure notifications can be received. |
| 307 NetworkChangeNotifierTestObserver observer = new NetworkChangeNotifierTe
stObserver(); | 308 NetworkChangeNotifierTestObserver observer = new NetworkChangeNotifierTe
stObserver(); |
| 308 NetworkChangeNotifier.addConnectionTypeObserver(observer); | 309 NetworkChangeNotifier.addConnectionTypeObserver(observer); |
| 309 Intent connectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_
ACTION); | 310 Intent connectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_
ACTION); |
| 310 mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivit
yIntent); | 311 mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivit
yIntent); |
| 311 assertTrue(observer.hasReceivedNotification()); | 312 assertTrue(observer.hasReceivedNotification()); |
| 312 } | 313 } |
| 313 } | 314 } |
| OLD | NEW |