Migrate most of core networking tests to junit4
This patch is a batch of mechanical changes to test classes to migrate away from AndroidTestCase and TestCase. Bug: 62918393 Test: runtest frameworks-net Change-Id: I74134609e511f22c4d9ecd65780e981f9ba7ae3f
This commit is contained in:
@@ -24,12 +24,15 @@ import static android.net.NetworkStats.SET_FOREGROUND;
|
||||
import static android.net.NetworkStats.TAG_NONE;
|
||||
import static android.net.NetworkStats.UID_ALL;
|
||||
import static com.android.server.NetworkManagementSocketTagger.kernelToTag;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.net.NetworkStats;
|
||||
import android.net.TrafficStats;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.frameworks.tests.net.R;
|
||||
|
||||
@@ -42,19 +45,23 @@ import java.io.OutputStream;
|
||||
import libcore.io.IoUtils;
|
||||
import libcore.io.Streams;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for {@link NetworkStatsFactory}.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class NetworkStatsFactoryTest extends AndroidTestCase {
|
||||
public class NetworkStatsFactoryTest {
|
||||
private File mTestProc;
|
||||
private NetworkStatsFactory mFactory;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
mTestProc = new File(getContext().getFilesDir(), "proc");
|
||||
mTestProc = new File(InstrumentationRegistry.getContext().getFilesDir(), "proc");
|
||||
if (mTestProc.exists()) {
|
||||
IoUtils.deleteContents(mTestProc);
|
||||
}
|
||||
@@ -62,17 +69,16 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
||||
mFactory = new NetworkStatsFactory(mTestProc);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
mFactory = null;
|
||||
|
||||
if (mTestProc.exists()) {
|
||||
IoUtils.deleteContents(mTestProc);
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNetworkStatsDetail() throws Exception {
|
||||
final NetworkStats stats = parseDetailedStats(R.raw.xt_qtaguid_typical);
|
||||
|
||||
@@ -84,6 +90,7 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
||||
assertStatsEntry(stats, "rmnet2", 10001, SET_DEFAULT, 0x0, 1125899906842624L, 984L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKernelTags() throws Exception {
|
||||
assertEquals(0, kernelToTag("0x0000000000000000"));
|
||||
assertEquals(0x32, kernelToTag("0x0000003200000000"));
|
||||
@@ -98,6 +105,7 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
||||
assertEquals(TrafficStats.TAG_SYSTEM_DOWNLOAD, kernelToTag("0xffffff0100000000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNetworkStatsWithSet() throws Exception {
|
||||
final NetworkStats stats = parseDetailedStats(R.raw.xt_qtaguid_typical);
|
||||
assertEquals(70, stats.size());
|
||||
@@ -106,6 +114,7 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
||||
assertStatsEntry(stats, "rmnet1", 10021, SET_FOREGROUND, 0x30100000, 742L, 3L, 1265L, 3L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNetworkStatsSingle() throws Exception {
|
||||
stageFile(R.raw.xt_qtaguid_iface_typical, file("net/xt_qtaguid/iface_stat_all"));
|
||||
|
||||
@@ -116,6 +125,7 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
||||
assertStatsEntry(stats, "test2", UID_ALL, SET_ALL, TAG_NONE, 1L, 2L, 3L, 4L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNetworkStatsXt() throws Exception {
|
||||
stageFile(R.raw.xt_qtaguid_iface_fmt_typical, file("net/xt_qtaguid/iface_stat_fmt"));
|
||||
|
||||
@@ -127,6 +137,7 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
||||
assertStatsEntry(stats, "rmnet2", UID_ALL, SET_ALL, TAG_NONE, 4968L, 35L, 3081L, 39L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleClatAccounting() throws Exception {
|
||||
NetworkStatsFactory.noteStackedIface("v4-wlan0", "wlan0");
|
||||
|
||||
@@ -161,6 +172,7 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
||||
NetworkStatsFactory.noteStackedIface("v4-wlan0", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleClatAccounting100MBDownload() throws Exception {
|
||||
// Downloading 100mb from an ipv4 only destination in a foreground activity
|
||||
|
||||
@@ -197,7 +209,7 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
in = getContext().getResources().openRawResource(rawId);
|
||||
in = InstrumentationRegistry.getContext().getResources().openRawResource(rawId);
|
||||
out = new FileOutputStream(file);
|
||||
Streams.copy(in, out);
|
||||
} finally {
|
||||
@@ -251,5 +263,4 @@ public class NetworkStatsFactoryTest extends AndroidTestCase {
|
||||
assertEquals("unexpected txBytes", txBytes, entry.txBytes);
|
||||
assertEquals("unexpected txPackets", txPackets, entry.txPackets);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,13 @@ import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.net.ConnectivityManager.getNetworkTypeName;
|
||||
import static android.net.NetworkCapabilities.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static com.android.internal.util.TestUtils.waitForIdleHandler;
|
||||
|
||||
import static org.mockito.Mockito.anyBoolean;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.eq;
|
||||
@@ -87,9 +92,10 @@ import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.mock.MockContentResolver;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
@@ -105,7 +111,11 @@ import com.android.server.connectivity.NetworkMonitor.CaptivePortalProbeResult;
|
||||
import com.android.server.net.NetworkPinner;
|
||||
import com.android.server.net.NetworkPolicyManagerInternal;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.mockito.Spy;
|
||||
@@ -123,13 +133,16 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for {@link ConnectivityService}.
|
||||
*
|
||||
* Build, install and run with:
|
||||
* runtest frameworks-net -c com.android.server.ConnectivityServiceTest
|
||||
*/
|
||||
public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class ConnectivityServiceTest {
|
||||
private static final String TAG = "ConnectivityServiceTest";
|
||||
|
||||
private static final int TIMEOUT_MS = 500;
|
||||
@@ -141,6 +154,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
private MockNetworkAgent mWiFiNetworkAgent;
|
||||
private MockNetworkAgent mCellNetworkAgent;
|
||||
private MockNetworkAgent mEthernetNetworkAgent;
|
||||
private Context mContext;
|
||||
|
||||
// This class exists to test bindProcessToNetwork and getBoundNetworkForProcess. These methods
|
||||
// do not go through ConnectivityService but talk to netd directly, so they don't automatically
|
||||
@@ -242,7 +256,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
waitForIdle(TIMEOUT_MS);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testWaitForIdle() {
|
||||
final int attempts = 50; // Causes the test to take about 200ms on bullhead-eng.
|
||||
|
||||
@@ -743,7 +757,8 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
|
||||
// Don't overlap test NetIDs with real NetIDs as binding sockets to real networks
|
||||
// can have odd side-effects, like network validations succeeding.
|
||||
final Network[] networks = ConnectivityManager.from(getContext()).getAllNetworks();
|
||||
Context context = InstrumentationRegistry.getContext();
|
||||
final Network[] networks = ConnectivityManager.from(context).getAllNetworks();
|
||||
boolean overlaps = false;
|
||||
for (Network network : networks) {
|
||||
if (netId == network.netId) {
|
||||
@@ -814,9 +829,9 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
fail("ConditionVariable was blocked for more than " + TIMEOUT_MS + "ms");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mContext = InstrumentationRegistry.getContext();
|
||||
|
||||
// InstrumentationTestRunner prepares a looper, but AndroidJUnitRunner does not.
|
||||
// http://b/25897652 .
|
||||
@@ -824,7 +839,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
Looper.prepare();
|
||||
}
|
||||
|
||||
mServiceContext = new MockContext(getContext());
|
||||
mServiceContext = new MockContext(InstrumentationRegistry.getContext());
|
||||
LocalServices.removeServiceForTest(NetworkPolicyManagerInternal.class);
|
||||
LocalServices.addService(
|
||||
NetworkPolicyManagerInternal.class, mock(NetworkPolicyManagerInternal.class));
|
||||
@@ -835,7 +850,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
mock(IpConnectivityLog.class));
|
||||
|
||||
mService.systemReady();
|
||||
mCm = new WrappedConnectivityManager(getContext(), mService);
|
||||
mCm = new WrappedConnectivityManager(InstrumentationRegistry.getContext(), mService);
|
||||
mCm.bindProcessToNetwork(null);
|
||||
|
||||
// Ensure that the default setting for Captive Portals is used for most tests
|
||||
@@ -843,6 +858,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
setMobileDataAlwaysOn(false);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
setMobileDataAlwaysOn(false);
|
||||
if (mCellNetworkAgent != null) {
|
||||
@@ -857,7 +873,6 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
mEthernetNetworkAgent.disconnect();
|
||||
mEthernetNetworkAgent = null;
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private static int transportToLegacyType(int transport) {
|
||||
@@ -931,6 +946,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
return cv;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNetworkTypes() {
|
||||
// Ensure that our mocks for the networkAttributes config variable work as expected. If they
|
||||
// don't, then tests that depend on CONNECTIVITY_ACTION broadcasts for these network types
|
||||
@@ -946,7 +962,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
assertTrue(mCm.isNetworkSupported(TYPE_ETHERNET));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testLingering() throws Exception {
|
||||
verifyNoNetwork();
|
||||
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
||||
@@ -987,7 +1003,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
verifyNoNetwork();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testValidatedCellularOutscoresUnvalidatedWiFi() throws Exception {
|
||||
// Test bringing up unvalidated WiFi
|
||||
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
||||
@@ -1022,7 +1038,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
verifyNoNetwork();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testUnvalidatedWifiOutscoresUnvalidatedCellular() throws Exception {
|
||||
// Test bringing up unvalidated cellular.
|
||||
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
||||
@@ -1048,7 +1064,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
verifyNoNetwork();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testUnlingeringDoesNotValidate() throws Exception {
|
||||
// Test bringing up unvalidated WiFi.
|
||||
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
||||
@@ -1076,7 +1092,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
NET_CAPABILITY_VALIDATED));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testCellularOutscoresWeakWifi() throws Exception {
|
||||
// Test bringing up validated cellular.
|
||||
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
||||
@@ -1102,7 +1118,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
verifyActiveNetwork(TRANSPORT_WIFI);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testReapingNetwork() throws Exception {
|
||||
// Test bringing up WiFi without NET_CAPABILITY_INTERNET.
|
||||
// Expect it to be torn down immediately because it satisfies no requests.
|
||||
@@ -1135,7 +1151,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
waitFor(cv);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testCellularFallback() throws Exception {
|
||||
// Test bringing up validated cellular.
|
||||
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
||||
@@ -1173,7 +1189,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
verifyActiveNetwork(TRANSPORT_WIFI);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testWiFiFallback() throws Exception {
|
||||
// Test bringing up unvalidated WiFi.
|
||||
mWiFiNetworkAgent = new MockNetworkAgent(TRANSPORT_WIFI);
|
||||
@@ -1387,7 +1403,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testStateChangeNetworkCallbacks() throws Exception {
|
||||
final TestNetworkCallback genericNetworkCallback = new TestNetworkCallback();
|
||||
final TestNetworkCallback wifiNetworkCallback = new TestNetworkCallback();
|
||||
@@ -1477,7 +1493,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
assertNoCallbacks(genericNetworkCallback, wifiNetworkCallback, cellNetworkCallback);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testMultipleLingering() {
|
||||
NetworkRequest request = new NetworkRequest.Builder()
|
||||
.clearCapabilities().addCapability(NET_CAPABILITY_NOT_METERED)
|
||||
@@ -1705,7 +1721,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
mCm.unregisterNetworkCallback(trackDefaultCallback);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testExplicitlySelected() {
|
||||
NetworkRequest request = new NetworkRequest.Builder()
|
||||
.clearCapabilities().addCapability(NET_CAPABILITY_INTERNET)
|
||||
@@ -1872,7 +1888,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
handlerThread.quit();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNetworkFactoryRequests() throws Exception {
|
||||
tryNetworkFactoryRequests(NET_CAPABILITY_MMS);
|
||||
tryNetworkFactoryRequests(NET_CAPABILITY_SUPL);
|
||||
@@ -1892,7 +1908,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
// Skipping VALIDATED and CAPTIVE_PORTAL as they're disallowed.
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNoMutableNetworkRequests() throws Exception {
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, new Intent("a"), 0);
|
||||
NetworkRequest request1 = new NetworkRequest.Builder()
|
||||
@@ -1909,7 +1925,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
assertException(() -> { mCm.requestNetwork(request2, pendingIntent); }, expected);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testMMSonWiFi() throws Exception {
|
||||
// Test bringing up cellular without MMS NetworkRequest gets reaped
|
||||
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
||||
@@ -1948,7 +1964,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
verifyActiveNetwork(TRANSPORT_WIFI);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testMMSonCell() throws Exception {
|
||||
// Test bringing up cellular without MMS
|
||||
mCellNetworkAgent = new MockNetworkAgent(TRANSPORT_CELLULAR);
|
||||
@@ -1977,7 +1993,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
verifyActiveNetwork(TRANSPORT_CELLULAR);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testCaptivePortal() {
|
||||
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
||||
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
||||
@@ -2028,7 +2044,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
validatedCallback.expectCallback(CallbackState.LOST, mWiFiNetworkAgent);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testCaptivePortalApp() {
|
||||
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
||||
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
||||
@@ -2074,7 +2090,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
mCm.unregisterNetworkCallback(captivePortalCallback);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testAvoidOrIgnoreCaptivePortals() {
|
||||
final TestNetworkCallback captivePortalCallback = new TestNetworkCallback();
|
||||
final NetworkRequest captivePortalRequest = new NetworkRequest.Builder()
|
||||
@@ -2119,7 +2135,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
return new NetworkRequest.Builder().addTransportType(TRANSPORT_WIFI);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNetworkSpecifier() {
|
||||
NetworkRequest rEmpty1 = newWifiRequestBuilder().build();
|
||||
NetworkRequest rEmpty2 = newWifiRequestBuilder().setNetworkSpecifier((String) null).build();
|
||||
@@ -2180,7 +2196,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
assertNoCallbacks(cEmpty1, cEmpty2, cEmpty3, cFoo, cBar);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testInvalidNetworkSpecifier() {
|
||||
try {
|
||||
NetworkRequest.Builder builder = new NetworkRequest.Builder();
|
||||
@@ -2241,7 +2257,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNetworkSpecifierUidSpoofSecurityException() {
|
||||
class UidAwareNetworkSpecifier extends NetworkSpecifier implements Parcelable {
|
||||
@Override
|
||||
@@ -2275,7 +2291,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testRegisterDefaultNetworkCallback() throws Exception {
|
||||
final TestNetworkCallback defaultNetworkCallback = new TestNetworkCallback();
|
||||
mCm.registerDefaultNetworkCallback(defaultNetworkCallback);
|
||||
@@ -2324,7 +2340,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
defaultNetworkCallback.expectCallback(CallbackState.LOST, mCellNetworkAgent);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testAdditionalStateCallbacks() throws Exception {
|
||||
// File a network request for mobile.
|
||||
final TestNetworkCallback cellNetworkCallback = new TestNetworkCallback();
|
||||
@@ -2385,7 +2401,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
return nc.hasCapability(NET_CAPABILITY_FOREGROUND);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testBackgroundNetworks() throws Exception {
|
||||
// Create a background request. We can't do this ourselves because ConnectivityService
|
||||
// doesn't have an API for it. So just turn on mobile data always on.
|
||||
@@ -2554,7 +2570,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testMobileDataAlwaysOn() throws Exception {
|
||||
final TestNetworkCallback cellNetworkCallback = new TestNetworkCallback();
|
||||
final NetworkRequest cellRequest = new NetworkRequest.Builder()
|
||||
@@ -2619,7 +2635,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
handlerThread.quit();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testAvoidBadWifiSetting() throws Exception {
|
||||
final ContentResolver cr = mServiceContext.getContentResolver();
|
||||
final WrappedMultinetworkPolicyTracker tracker = mService.getMultinetworkPolicyTracker();
|
||||
@@ -2657,7 +2673,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
assertTrue(tracker.shouldNotifyWifiUnvalidated());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testAvoidBadWifi() throws Exception {
|
||||
final ContentResolver cr = mServiceContext.getContentResolver();
|
||||
final WrappedMultinetworkPolicyTracker tracker = mService.getMultinetworkPolicyTracker();
|
||||
@@ -2784,7 +2800,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
mCm.unregisterNetworkCallback(defaultCallback);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testMeteredMultipathPreferenceSetting() throws Exception {
|
||||
final ContentResolver cr = mServiceContext.getContentResolver();
|
||||
final WrappedMultinetworkPolicyTracker tracker = mService.getMultinetworkPolicyTracker();
|
||||
@@ -2808,7 +2824,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
* Validate that a satisfied network request does not trigger onUnavailable() once the
|
||||
* time-out period expires.
|
||||
*/
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testSatisfiedNetworkRequestDoesNotTriggerOnUnavailable() {
|
||||
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
||||
NetworkCapabilities.TRANSPORT_WIFI).build();
|
||||
@@ -2828,7 +2844,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
* Validate that a satisfied network request followed by a disconnected (lost) network does
|
||||
* not trigger onUnavailable() once the time-out period expires.
|
||||
*/
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testSatisfiedThenLostNetworkRequestDoesNotTriggerOnUnavailable() {
|
||||
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
||||
NetworkCapabilities.TRANSPORT_WIFI).build();
|
||||
@@ -2852,7 +2868,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
* callback is called when time-out expires. Then validate that if network request is
|
||||
* (somehow) satisfied - the callback isn't called later.
|
||||
*/
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testTimedoutNetworkRequest() {
|
||||
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
||||
NetworkCapabilities.TRANSPORT_WIFI).build();
|
||||
@@ -2873,7 +2889,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
* Validate that when a network request is unregistered (cancelled), no posterior event can
|
||||
* trigger the callback.
|
||||
*/
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNoCallbackAfterUnregisteredNetworkRequest() {
|
||||
NetworkRequest nr = new NetworkRequest.Builder().addTransportType(
|
||||
NetworkCapabilities.TRANSPORT_WIFI).build();
|
||||
@@ -2981,7 +2997,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
return mWiFiNetworkAgent.getNetwork();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testPacketKeepalives() throws Exception {
|
||||
InetAddress myIPv4 = InetAddress.getByName("192.0.2.129");
|
||||
InetAddress notMyIPv4 = InetAddress.getByName("192.0.2.35");
|
||||
@@ -3105,7 +3121,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
callback3.expectStopped();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testGetCaptivePortalServerUrl() throws Exception {
|
||||
String url = mCm.getCaptivePortalServerUrl();
|
||||
assertEquals("http://connectivitycheck.gstatic.com/generate_204", url);
|
||||
@@ -3150,7 +3166,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
assertEquals(mCellNetworkAgent.getNetwork(), mCm.getActiveNetwork());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNetworkPinner() {
|
||||
NetworkRequest wifiRequest = new NetworkRequest.Builder()
|
||||
.addTransportType(TRANSPORT_WIFI)
|
||||
@@ -3210,7 +3226,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
assertPinnedToWifiWithCellDefault();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNetworkCallbackMaximum() {
|
||||
final int MAX_REQUESTS = 100;
|
||||
final int CALLBACKS = 90;
|
||||
@@ -3302,7 +3318,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNetworkInfoOfTypeNone() {
|
||||
ConditionVariable broadcastCV = waitForConnectivityBroadcasts(1);
|
||||
|
||||
@@ -3342,7 +3358,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testDeprecatedAndUnsupportedOperations() throws Exception {
|
||||
final int TYPE_NONE = ConnectivityManager.TYPE_NONE;
|
||||
assertNull(mCm.getNetworkInfo(TYPE_NONE));
|
||||
@@ -3363,7 +3379,7 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
||||
assertException(() -> { mCm.requestRouteToHostAddress(TYPE_NONE, null); }, unsupported);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testLinkPropertiesEnsuresDirectlyConnectedRoutes() {
|
||||
final NetworkRequest networkRequest = new NetworkRequest.Builder()
|
||||
.addTransportType(TRANSPORT_WIFI).build();
|
||||
|
||||
@@ -36,6 +36,7 @@ import android.net.IpSecUdpEncapResponse;
|
||||
import android.os.Binder;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
|
||||
@@ -48,11 +49,10 @@ import java.net.UnknownHostException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link IpSecService}. */
|
||||
@SmallTest
|
||||
@RunWith(JUnit4.class)
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class IpSecServiceTest {
|
||||
|
||||
private static final int DROID_SPI = 0xD1201D;
|
||||
|
||||
@@ -16,24 +16,8 @@
|
||||
|
||||
package com.android.server.connectivity;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkMisc;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.text.format.DateUtils;
|
||||
import com.android.internal.R;
|
||||
import com.android.server.ConnectivityService;
|
||||
import com.android.server.connectivity.NetworkNotificationManager;
|
||||
import com.android.server.connectivity.NetworkNotificationManager.NotificationType;
|
||||
import junit.framework.TestCase;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.anyBoolean;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
@@ -44,7 +28,32 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.reset;
|
||||
|
||||
public class LingerMonitorTest extends TestCase {
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.NetworkMisc;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.text.format.DateUtils;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.server.ConnectivityService;
|
||||
import com.android.server.connectivity.NetworkNotificationManager;
|
||||
import com.android.server.connectivity.NetworkNotificationManager.NotificationType;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class LingerMonitorTest {
|
||||
static final String CELLULAR = "CELLULAR";
|
||||
static final String WIFI = "WIFI";
|
||||
|
||||
@@ -62,6 +71,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
@Mock NetworkNotificationManager mNotifier;
|
||||
@Mock Resources mResources;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mCtx.getResources()).thenReturn(mResources);
|
||||
@@ -71,7 +81,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
mMonitor = new TestableLingerMonitor(mCtx, mNotifier, HIGH_DAILY_LIMIT, HIGH_RATE_LIMIT);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testTransitions() {
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
NetworkAgentInfo nai1 = wifiNai(100);
|
||||
@@ -81,7 +91,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
assertFalse(mMonitor.isNotificationEnabled(nai2, nai1));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNotificationOnLinger() {
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
|
||||
@@ -92,7 +102,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verifyNotification(from, to);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testToastOnLinger() {
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
|
||||
@@ -103,7 +113,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verifyToast(from, to);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNotificationClearedAfterDisconnect() {
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
|
||||
@@ -117,7 +127,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verify(mNotifier, times(1)).clearNotification(100);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNotificationClearedAfterSwitchingBack() {
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
|
||||
@@ -131,7 +141,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verify(mNotifier, times(1)).clearNotification(100);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testUniqueToast() {
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
|
||||
@@ -149,7 +159,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verifyNoNotifications();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testMultipleNotifications() {
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
|
||||
@@ -168,7 +178,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verifyNotification(wifi2, cell);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testRateLimiting() throws InterruptedException {
|
||||
mMonitor = new TestableLingerMonitor(mCtx, mNotifier, HIGH_DAILY_LIMIT, LOW_RATE_LIMIT);
|
||||
|
||||
@@ -194,7 +204,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verifyNoNotifications();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testDailyLimiting() throws InterruptedException {
|
||||
mMonitor = new TestableLingerMonitor(mCtx, mNotifier, LOW_DAILY_LIMIT, HIGH_RATE_LIMIT);
|
||||
|
||||
@@ -221,7 +231,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verifyNoNotifications();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testUniqueNotification() {
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION);
|
||||
@@ -238,7 +248,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verifyNotification(from, to);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testIgnoreNeverValidatedNetworks() {
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
@@ -250,7 +260,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verifyNoNotifications();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testIgnoreCurrentlyValidatedNetworks() {
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
@@ -262,7 +272,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verifyNoNotifications();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNoNotificationType() {
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
|
||||
setNotificationSwitch();
|
||||
@@ -273,7 +283,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verifyNoNotifications();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNoTransitionToNotify() {
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_NONE);
|
||||
setNotificationSwitch(transition(WIFI, CELLULAR));
|
||||
@@ -284,7 +294,7 @@ public class LingerMonitorTest extends TestCase {
|
||||
verifyNoNotifications();
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testDifferentTransitionToNotify() {
|
||||
setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST);
|
||||
setNotificationSwitch(transition(CELLULAR, WIFI));
|
||||
|
||||
@@ -34,20 +34,29 @@ import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import com.android.server.connectivity.NetworkNotificationManager.NotificationType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
public class NetworkNotificationManagerTest extends TestCase {
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class NetworkNotificationManagerTest {
|
||||
|
||||
static final NetworkCapabilities CELL_CAPABILITIES = new NetworkCapabilities();
|
||||
static final NetworkCapabilities WIFI_CAPABILITIES = new NetworkCapabilities();
|
||||
@@ -71,6 +80,7 @@ public class NetworkNotificationManagerTest extends TestCase {
|
||||
|
||||
NetworkNotificationManager mManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mCaptor = ArgumentCaptor.forClass(Notification.class);
|
||||
@@ -87,7 +97,7 @@ public class NetworkNotificationManagerTest extends TestCase {
|
||||
mManager = new NetworkNotificationManager(mCtx, mTelephonyManager, mNotificationManager);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNotificationsShownAndCleared() {
|
||||
final int NETWORK_ID_BASE = 100;
|
||||
List<NotificationType> types = Arrays.asList(NotificationType.values());
|
||||
@@ -117,7 +127,7 @@ public class NetworkNotificationManagerTest extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNoInternetNotificationsNotShownForCellular() {
|
||||
mManager.showNotification(100, NO_INTERNET, mCellNai, mWifiNai, null, false);
|
||||
mManager.showNotification(101, LOST_INTERNET, mCellNai, mWifiNai, null, false);
|
||||
@@ -131,7 +141,7 @@ public class NetworkNotificationManagerTest extends TestCase {
|
||||
verify(mNotificationManager, times(1)).notifyAsUser(eq(tag), eq(eventId), any(), any());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNotificationsNotShownIfNoInternetCapability() {
|
||||
mWifiNai.networkCapabilities = new NetworkCapabilities();
|
||||
mWifiNai.networkCapabilities .addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
|
||||
@@ -142,7 +152,7 @@ public class NetworkNotificationManagerTest extends TestCase {
|
||||
verify(mNotificationManager, never()).notifyAsUser(any(), anyInt(), any(), any());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testDuplicatedNotificationsNoInternetThenSignIn() {
|
||||
final int id = 101;
|
||||
final String tag = NetworkNotificationManager.tagFor(id);
|
||||
@@ -164,7 +174,7 @@ public class NetworkNotificationManagerTest extends TestCase {
|
||||
verify(mNotificationManager, times(1)).cancelAsUser(eq(tag), eq(SIGN_IN.eventId), any());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testDuplicatedNotificationsSignInThenNoInternet() {
|
||||
final int id = 101;
|
||||
final String tag = NetworkNotificationManager.tagFor(id);
|
||||
|
||||
@@ -20,6 +20,9 @@ import static android.content.pm.UserInfo.FLAG_ADMIN;
|
||||
import static android.content.pm.UserInfo.FLAG_MANAGED_PROFILE;
|
||||
import static android.content.pm.UserInfo.FLAG_PRIMARY;
|
||||
import static android.content.pm.UserInfo.FLAG_RESTRICTED;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.AdditionalMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -42,14 +45,17 @@ import android.os.INetworkManagementService;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.net.VpnConfig;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
@@ -61,13 +67,16 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for {@link Vpn}.
|
||||
*
|
||||
* Build, install and run with:
|
||||
* runtest --path java/com/android/server/connectivity/VpnTest.java
|
||||
* runtest frameworks-net -c com.android.server.connectivity.VpnTest
|
||||
*/
|
||||
public class VpnTest extends AndroidTestCase {
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class VpnTest {
|
||||
private static final String TAG = "VpnTest";
|
||||
|
||||
// Mock users
|
||||
@@ -106,7 +115,7 @@ public class VpnTest extends AndroidTestCase {
|
||||
@Mock private NotificationManager mNotificationManager;
|
||||
@Mock private Vpn.SystemServices mSystemServices;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
@@ -130,7 +139,7 @@ public class VpnTest extends AndroidTestCase {
|
||||
doNothing().when(mNetService).registerObserver(any());
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testRestrictedProfilesAreAddedToVpn() {
|
||||
setMockedUsers(primaryUser, secondaryUser, restrictedProfileA, restrictedProfileB);
|
||||
|
||||
@@ -144,7 +153,7 @@ public class VpnTest extends AndroidTestCase {
|
||||
})), ranges);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testManagedProfilesAreNotAddedToVpn() {
|
||||
setMockedUsers(primaryUser, managedProfileA);
|
||||
|
||||
@@ -157,7 +166,7 @@ public class VpnTest extends AndroidTestCase {
|
||||
})), ranges);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testAddUserToVpnOnlyAddsOneUser() {
|
||||
setMockedUsers(primaryUser, restrictedProfileA, managedProfileA);
|
||||
|
||||
@@ -170,7 +179,7 @@ public class VpnTest extends AndroidTestCase {
|
||||
})), ranges);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testUidWhiteAndBlacklist() throws Exception {
|
||||
final Vpn vpn = createVpn(primaryUser.id);
|
||||
final UidRange user = UidRange.createForUser(primaryUser.id);
|
||||
@@ -195,7 +204,7 @@ public class VpnTest extends AndroidTestCase {
|
||||
})), disallow);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testLockdownChangingPackage() throws Exception {
|
||||
final Vpn vpn = createVpn(primaryUser.id);
|
||||
final UidRange user = UidRange.createForUser(primaryUser.id);
|
||||
@@ -230,7 +239,7 @@ public class VpnTest extends AndroidTestCase {
|
||||
assertUnblocked(vpn, user.start + PKG_UIDS[3]);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testLockdownAddingAProfile() throws Exception {
|
||||
final Vpn vpn = createVpn(primaryUser.id);
|
||||
setMockedUsers(primaryUser);
|
||||
@@ -270,7 +279,7 @@ public class VpnTest extends AndroidTestCase {
|
||||
}));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testLockdownRuleRepeatability() throws Exception {
|
||||
final Vpn vpn = createVpn(primaryUser.id);
|
||||
|
||||
@@ -293,7 +302,7 @@ public class VpnTest extends AndroidTestCase {
|
||||
verify(mNetService, times(2)).setAllowOnlyVpnForUids(anyBoolean(), any(UidRange[].class));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testLockdownRuleReversibility() throws Exception {
|
||||
final Vpn vpn = createVpn(primaryUser.id);
|
||||
|
||||
@@ -322,7 +331,7 @@ public class VpnTest extends AndroidTestCase {
|
||||
order.verify(mNetService).setAllowOnlyVpnForUids(eq(true), aryEq(entireUser));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testIsAlwaysOnPackageSupported() throws Exception {
|
||||
final Vpn vpn = createVpn(primaryUser.id);
|
||||
|
||||
@@ -356,7 +365,7 @@ public class VpnTest extends AndroidTestCase {
|
||||
assertFalse(vpn.isAlwaysOnPackageSupported(PKGS[0]));
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
@Test
|
||||
public void testNotificationShownForAlwaysOnApp() {
|
||||
final UserHandle userHandle = UserHandle.of(primaryUser.id);
|
||||
final Vpn vpn = createVpn(primaryUser.id);
|
||||
|
||||
Reference in New Issue
Block a user