summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/OsuServerConnectionTest.java32
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java132
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataMessageTest.java1
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataResponseTest.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/soap/RedirectListenerTest.java172
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/soap/SoapParserTest.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/soap/SppResponseMessageTest.java3
7 files changed, 323 insertions, 23 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuServerConnectionTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuServerConnectionTest.java
index c91b1bcb5..8a123c2f2 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuServerConnectionTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuServerConnectionTest.java
@@ -16,9 +16,7 @@
package com.android.server.wifi.hotspot2;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isNull;
@@ -30,6 +28,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.net.Network;
+import android.os.test.TestLooper;
import android.support.test.filters.SmallTest;
import android.util.Pair;
@@ -78,6 +77,7 @@ public class OsuServerConnectionTest {
private static final int ENABLE_VERBOSE_LOGGING = 1;
private static final int TEST_SESSION_ID = 1;
+ private TestLooper mLooper = new TestLooper();
private OsuServerConnection mOsuServerConnection;
private URL mValidServerUrl;
private List<Pair<Locale, String>> mProviderIdentities = new ArrayList<>();
@@ -98,7 +98,7 @@ public class OsuServerConnectionTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mOsuServerConnection = new OsuServerConnection();
+ mOsuServerConnection = new OsuServerConnection(mLooper.getLooper());
mOsuServerConnection.enableVerboseLogging(ENABLE_VERBOSE_LOGGING);
mProviderIdentities.add(Pair.create(Locale.US, PROVIDER_NAME_VALID));
mValidServerUrl = new URL(TEST_VALID_URL);
@@ -249,16 +249,16 @@ public class OsuServerConnectionTest {
}
/**
- * Verifies {@code ExchangeSoapMessage} should return {@code null} if there is no connection.
+ * Verifies {@code ExchangeSoapMessage} should return {@code false} if there is no connection.
*/
@Test
public void verifyExchangeSoapMessageWithoutConnection() {
- assertNull(mOsuServerConnection.exchangeSoapMessage(
+ assertFalse(mOsuServerConnection.exchangeSoapMessage(
new SoapSerializationEnvelope(SoapEnvelope.VER12)));
}
/**
- * Verifies {@code ExchangeSoapMessage} should return {@code null} if {@code soapEnvelope} is
+ * Verifies {@code ExchangeSoapMessage} should return {@code false} if {@code soapEnvelope} is
* {@code null}
*/
@Test
@@ -267,12 +267,12 @@ public class OsuServerConnectionTest {
mOsuServerConnection.setEventCallback(mOsuServerCallbacks);
assertTrue(mOsuServerConnection.connect(mValidServerUrl, mNetwork));
- assertNull(mOsuServerConnection.exchangeSoapMessage(null));
+ assertFalse(mOsuServerConnection.exchangeSoapMessage(null));
}
/**
- * Verifies {@code ExchangeSoapMessage} should return {@code null} if exception occurs during
- * soap exchange.
+ * Verifies {@code ExchangeSoapMessage} should get {@code null} message if exception occurs
+ * during soap exchange.
*/
@Test
public void verifyExchangeSoapMessageWithException() throws Exception {
@@ -280,14 +280,19 @@ public class OsuServerConnectionTest {
MockitoSession session = ExtendedMockito.mockitoSession().mockStatic(
HttpsTransport.class).startMocking();
try {
+ mOsuServerConnection.init(mTlsContext, mDelegate);
+ mOsuServerConnection.setEventCallback(mOsuServerCallbacks);
when(HttpsTransport.createInstance(any(Network.class), any(URL.class))).thenReturn(
mHttpsTransport);
doThrow(new IOException()).when(mHttpsTransport).call(any(String.class),
any(SoapSerializationEnvelope.class));
assertTrue(mOsuServerConnection.connect(mValidServerUrl, mNetwork));
- assertNull(mOsuServerConnection.exchangeSoapMessage(
+ assertTrue(mOsuServerConnection.exchangeSoapMessage(
new SoapSerializationEnvelope(SoapEnvelope.VER12)));
+
+ mLooper.dispatchAll();
+ verify(mOsuServerCallbacks).onReceivedSoapMessage(anyInt(), isNull());
} finally {
session.finishMocking();
}
@@ -302,6 +307,8 @@ public class OsuServerConnectionTest {
MockitoSession session = ExtendedMockito.mockitoSession().mockStatic(
HttpsTransport.class).startMocking();
try {
+ mOsuServerConnection.init(mTlsContext, mDelegate);
+ mOsuServerConnection.setEventCallback(mOsuServerCallbacks);
when(HttpsTransport.createInstance(any(Network.class), any(URL.class))).thenReturn(
mHttpsTransport);
assertTrue(mOsuServerConnection.connect(mValidServerUrl, mNetwork));
@@ -314,7 +321,10 @@ public class OsuServerConnectionTest {
envelope.bodyIn = new SoapObject();
when(SoapParser.getResponse(any(SoapObject.class))).thenReturn(mSppResponseMessage);
- assertEquals(mSppResponseMessage, mOsuServerConnection.exchangeSoapMessage(envelope));
+ assertTrue(mOsuServerConnection.exchangeSoapMessage(envelope));
+
+ mLooper.dispatchAll();
+ verify(mOsuServerCallbacks).onReceivedSoapMessage(anyInt(), eq(mSppResponseMessage));
} finally {
session.finishMocking();
}
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java
index 161bd2a86..5e73cd652 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProvisionerTest.java
@@ -29,6 +29,11 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.net.Network;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiSsid;
@@ -42,19 +47,23 @@ import android.os.test.TestLooper;
import android.support.test.filters.SmallTest;
import android.telephony.TelephonyManager;
+import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.android.org.conscrypt.TrustManagerImpl;
import com.android.server.wifi.WifiNative;
import com.android.server.wifi.hotspot2.soap.PostDevDataResponse;
+import com.android.server.wifi.hotspot2.soap.RedirectListener;
import com.android.server.wifi.hotspot2.soap.SppResponseMessage;
import com.android.server.wifi.hotspot2.soap.command.BrowserUri;
import com.android.server.wifi.hotspot2.soap.command.SppCommand;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoSession;
import java.net.URL;
import java.security.KeyStore;
@@ -71,6 +80,7 @@ public class PasspointProvisionerTest {
private static final int STEP_INIT = 0;
private static final int STEP_AP_CONNECT = 1;
private static final int STEP_SERVER_CONNECT = 2;
+ private static final int STEP_WAIT_FOR_REDIRECT_RESPONSE = 3;
private static final String TEST_DEV_ID = "12312341";
private static final String TEST_MANUFACTURER = Build.MANUFACTURER;
@@ -84,20 +94,27 @@ public class PasspointProvisionerTest {
private static final String TEST_SW_VERSION = "Android Test 1.0";
private static final String TEST_FW_VERSION = "Test FW 1.0";
private static final String TEST_REDIRECT_URL = "http://127.0.0.1:12345/index.htm";
+ private static final String OSU_APP_PACKAGE = "com.android.hotspot2";
+ private static final String OSU_APP_NAME = "OsuLogin";
private PasspointProvisioner mPasspointProvisioner;
private TestLooper mLooper = new TestLooper();
private Handler mHandler;
private OsuNetworkConnection.Callbacks mOsuNetworkCallbacks;
private PasspointProvisioner.OsuServerCallbacks mOsuServerCallbacks;
+ private RedirectListener.RedirectCallback mRedirectReceivedListener;
private ArgumentCaptor<OsuNetworkConnection.Callbacks> mOsuNetworkCallbacksCaptor =
ArgumentCaptor.forClass(OsuNetworkConnection.Callbacks.class);
private ArgumentCaptor<PasspointProvisioner.OsuServerCallbacks> mOsuServerCallbacksCaptor =
ArgumentCaptor.forClass(PasspointProvisioner.OsuServerCallbacks.class);
+ private ArgumentCaptor<RedirectListener.RedirectCallback>
+ mOnRedirectReceivedArgumentCaptor =
+ ArgumentCaptor.forClass(RedirectListener.RedirectCallback.class);
private ArgumentCaptor<Handler> mHandlerCaptor = ArgumentCaptor.forClass(Handler.class);
private OsuProvider mOsuProvider;
private TrustManagerImpl mDelegate;
private URL mTestUrl;
+ private MockitoSession mSession;
@Mock PasspointObjectFactory mObjectFactory;
@Mock Context mContext;
@@ -110,17 +127,27 @@ public class PasspointProvisionerTest {
@Mock KeyStore mKeyStore;
@Mock SSLContext mTlsContext;
@Mock WifiNative mWifiNative;
- @Mock SoapSerializationEnvelope mSoapEnvelope;
@Mock PostDevDataResponse mSppResponseMessage;
@Mock SystemInfo mSystemInfo;
@Mock TelephonyManager mTelephonyManager;
@Mock SppCommand mSppCommand;
@Mock BrowserUri mBrowserUri;
+ @Mock RedirectListener mRedirectListener;
+ @Mock PackageManager mPackageManager;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mTestUrl = new URL(TEST_REDIRECT_URL);
+ mSession = ExtendedMockito.mockitoSession().mockStatic(
+ RedirectListener.class).startMocking();
+
+ when(RedirectListener.createInstance(mLooper.getLooper())).thenReturn(
+ mRedirectListener);
+ when(mRedirectListener.getServerUrl()).thenReturn(new URL(TEST_REDIRECT_URL));
+ when(mRedirectListener.startServer(
+ any(RedirectListener.RedirectCallback.class))).thenReturn(true);
+ when(mRedirectListener.isAlive()).thenReturn(true);
when(mWifiManager.isWifiEnabled()).thenReturn(true);
when(mObjectFactory.makeOsuNetworkConnection(any(Context.class)))
.thenReturn(mOsuNetworkConnection);
@@ -162,8 +189,20 @@ public class PasspointProvisionerTest {
when(mSppCommand.getCommandData()).thenReturn(mBrowserUri);
when(mBrowserUri.getUri()).thenReturn(TEST_URL);
when(mOsuServerConnection.exchangeSoapMessage(
- any(SoapSerializationEnvelope.class))).thenReturn(
- mSppResponseMessage);
+ any(SoapSerializationEnvelope.class))).thenReturn(true);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ ResolveInfo resolveInfo = new ResolveInfo();
+ resolveInfo.activityInfo = new ActivityInfo();
+ resolveInfo.activityInfo.applicationInfo = new ApplicationInfo();
+ resolveInfo.activityInfo.name = OSU_APP_NAME;
+ resolveInfo.activityInfo.applicationInfo.packageName = OSU_APP_PACKAGE;
+ when(mPackageManager.resolveActivity(any(Intent.class),
+ eq(PackageManager.MATCH_DEFAULT_ONLY))).thenReturn(resolveInfo);
+ }
+
+ @After
+ public void cleanUp() {
+ mSession.finishMocking();
}
private void initAndStartProvisioning() {
@@ -205,6 +244,30 @@ public class PasspointProvisionerTest {
} else if (step == STEP_SERVER_CONNECT) {
verify(mCallback).onProvisioningStatus(
ProvisioningCallback.OSU_STATUS_SERVER_CONNECTED);
+ } else if (step == STEP_WAIT_FOR_REDIRECT_RESPONSE) {
+ // Server validation passed
+ mOsuServerCallbacks.onServerValidationStatus(mOsuServerCallbacks.getSessionId(),
+ true);
+ mLooper.dispatchAll();
+
+ verify(mCallback).onProvisioningStatus(
+ ProvisioningCallback.OSU_STATUS_SERVER_VALIDATED);
+ verify(mCallback).onProvisioningStatus(
+ ProvisioningCallback.OSU_STATUS_SERVICE_PROVIDER_VERIFIED);
+ verify(mCallback).onProvisioningStatus(
+ ProvisioningCallback.OSU_STATUS_INIT_SOAP_EXCHANGE);
+
+ // Received soapMessageResponse
+ mOsuServerCallbacks.onReceivedSoapMessage(mOsuServerCallbacks.getSessionId(),
+ mSppResponseMessage);
+ mLooper.dispatchAll();
+
+ verify(mCallback).onProvisioningStatus(
+ ProvisioningCallback.OSU_STATUS_WAITING_FOR_REDIRECT_RESPONSE);
+ verify(mRedirectListener, atLeastOnce())
+ .startServer(mOnRedirectReceivedArgumentCaptor.capture());
+ mRedirectReceivedListener = mOnRedirectReceivedArgumentCaptor.getValue();
+ verifyNoMoreInteractions(mCallback);
}
}
}
@@ -426,7 +489,7 @@ public class PasspointProvisionerTest {
public void verifyExchangingSoapMessageFailure() throws RemoteException {
// Fail to exchange the SOAP message
when(mOsuServerConnection.exchangeSoapMessage(
- any(SoapSerializationEnvelope.class))).thenReturn(null);
+ any(SoapSerializationEnvelope.class))).thenReturn(false);
stopAfterStep(STEP_SERVER_CONNECT);
// Server validation passed
@@ -436,19 +499,21 @@ public class PasspointProvisionerTest {
verify(mCallback).onProvisioningStatus(ProvisioningCallback.OSU_STATUS_SERVER_VALIDATED);
verify(mCallback).onProvisioningStatus(
ProvisioningCallback.OSU_STATUS_SERVICE_PROVIDER_VERIFIED);
- verify(mCallback).onProvisioningStatus(ProvisioningCallback.OSU_STATUS_INIT_SOAP_EXCHANGE);
verify(mCallback).onProvisioningFailure(
ProvisioningCallback.OSU_FAILURE_SOAP_MESSAGE_EXCHANGE);
- // Osu provider verification is the last current step in the flow, no more runnables posted.
+ // No further runnables posted
verifyNoMoreInteractions(mCallback);
}
/**
- * Verifies that the right provisioning callbacks are invoked as the provisioner progresses
- * to the end as successful case.
+ * Verifies that the right provisioning callbacks are invoked when there is no OSU activity for
+ * the intent
*/
@Test
- public void verifyProvisioningFlowForSuccessfulCase() throws RemoteException {
+ public void verifyNoOsuActivityFoundFailure() throws RemoteException {
+ // There is no activity found for the intent
+ when(mPackageManager.resolveActivity(any(Intent.class),
+ eq(PackageManager.MATCH_DEFAULT_ONLY))).thenReturn(null);
stopAfterStep(STEP_SERVER_CONNECT);
// Server validation passed
@@ -459,8 +524,53 @@ public class PasspointProvisionerTest {
verify(mCallback).onProvisioningStatus(
ProvisioningCallback.OSU_STATUS_SERVICE_PROVIDER_VERIFIED);
verify(mCallback).onProvisioningStatus(ProvisioningCallback.OSU_STATUS_INIT_SOAP_EXCHANGE);
- // Osu provider verification is the last current step in the flow, no more runnables posted.
+
+ // Received soapMessageResponse
+ mOsuServerCallbacks.onReceivedSoapMessage(mOsuServerCallbacks.getSessionId(),
+ mSppResponseMessage);
+ mLooper.dispatchAll();
+
+ verify(mCallback).onProvisioningFailure(
+ ProvisioningCallback.OSU_FAILURE_NO_OSU_ACTIVITY_FOUND);
+ // No further runnables posted
verifyNoMoreInteractions(mCallback);
}
-}
+ /**
+ * Verifies that the right provisioning callbacks are invoked when timeout occurs for HTTP
+ * redirect response.
+ */
+ @Test
+ public void verifyRedirectResponseTimeout() throws RemoteException {
+ stopAfterStep(STEP_WAIT_FOR_REDIRECT_RESPONSE);
+
+ // Timed out for HTTP redirect response.
+ mRedirectReceivedListener.onRedirectTimedOut();
+ mLooper.dispatchAll();
+
+ verify(mRedirectListener, atLeastOnce()).stopServer();
+ verify(mCallback).onProvisioningFailure(
+ ProvisioningCallback.OSU_FAILURE_TIMED_OUT_REDIRECT_LISTENER);
+ // No further runnables posted
+ verifyNoMoreInteractions(mCallback);
+ }
+
+ /**
+ * Verifies that the right provisioning callbacks are invoked as the provisioner progresses
+ * to the end as successful case.
+ */
+ @Test
+ public void verifyProvisioningFlowForSuccessfulCase() throws RemoteException {
+ stopAfterStep(STEP_WAIT_FOR_REDIRECT_RESPONSE);
+
+ // Received HTTP redirect response.
+ mRedirectReceivedListener.onRedirectReceived();
+ mLooper.dispatchAll();
+
+ verify(mRedirectListener, atLeastOnce()).stopServer();
+ verify(mCallback).onProvisioningStatus(
+ ProvisioningCallback.OSU_STATUS_REDIRECT_RESPONSE_RECEIVED);
+ // No further runnables posted
+ verifyNoMoreInteractions(mCallback);
+ }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataMessageTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataMessageTest.java
index de95cc8ca..179ac68a6 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataMessageTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataMessageTest.java
@@ -43,7 +43,6 @@ import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.mockito.Mock;
-
/**
* Unit tests for {@link PostDevDataMessage}.
*/
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataResponseTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataResponseTest.java
index 25e91cba8..d5b827d8f 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataResponseTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/PostDevDataResponseTest.java
@@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.MockitoAnnotations.initMocks;
+import android.support.test.filters.SmallTest;
+
import com.android.server.wifi.hotspot2.soap.command.SppCommand;
import org.junit.Before;
@@ -30,6 +32,7 @@ import org.ksoap2.serialization.SoapObject;
/**
* Unit tests for {@link PostDevDataResponse}.
*/
+@SmallTest
public class PostDevDataResponseTest {
private static final String EXEC = "exec";
private static final String BROWSER_COMMAND = "launchBrowserToURI";
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/RedirectListenerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/RedirectListenerTest.java
new file mode 100644
index 000000000..c4fb3fd71
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/RedirectListenerTest.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi.hotspot2.soap;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import android.os.Looper;
+import android.os.test.TestLooper;
+import android.support.test.filters.SmallTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+import java.io.IOException;
+import java.net.URL;
+
+import fi.iki.elonen.NanoHTTPD;
+
+/**
+ * Unit tests for {@link RedirectListener}.
+ */
+@SmallTest
+public class RedirectListenerTest {
+ private static final int TEST_PORT = 1010;
+
+ private RedirectListenerSpy mRedirectListener;
+ private URL mServerUrl;
+ private TestLooper mLooper = new TestLooper();
+
+ @Mock RedirectListener.RedirectCallback mListener;
+ @Mock NanoHTTPD.IHTTPSession mIHTTPSession;
+
+ /** Spy class to avoid start/stop {@link NanoHTTPD} server */
+ private class RedirectListenerSpy extends RedirectListener {
+ boolean mIsStart = false;
+ RedirectListenerSpy(Looper looper, int port) throws IOException {
+ super(looper, looper, port);
+ }
+
+ @Override
+ public void start() {
+ mIsStart = true;
+ }
+
+ @Override
+ public void stop() {
+ mIsStart = false;
+ }
+
+ @Override
+ public boolean isServerAlive() {
+ return mIsStart;
+ }
+ }
+
+ /**
+ * Sets up test.
+ */
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+
+ mRedirectListener = new RedirectListenerSpy(mLooper.getLooper(), TEST_PORT);
+ mServerUrl = mRedirectListener.getServerUrl();
+ }
+
+ private void verifyStartServer() {
+ mRedirectListener.startServer(mListener);
+ mLooper.dispatchAll();
+
+ assertTrue(mRedirectListener.mIsStart);
+ }
+
+ private void verifyStopServer() {
+ mRedirectListener.stopServer();
+ mLooper.dispatchAll();
+
+ assertFalse(mRedirectListener.mIsStart);
+ }
+
+ /**
+ * Verifies that Timeout handler will be invoked when There is no a known GET request received
+ * in a {@link RedirectListener#USER_TIMEOUT_MILLIS}.
+ */
+ @Test
+ public void timeOutForKnownGetRequest() {
+ when(mIHTTPSession.getMethod()).thenReturn(NanoHTTPD.Method.PUT);
+ verifyStartServer();
+ mRedirectListener.serve(mIHTTPSession);
+
+ verify(mListener, never()).onRedirectReceived();
+
+ // Timeout has expired.
+ mLooper.moveTimeForward(RedirectListener.USER_TIMEOUT_MILLIS);
+ mLooper.dispatchAll();
+
+ verify(mListener).onRedirectTimedOut();
+ verifyStopServer();
+ }
+
+ /**
+ * Verifies that {@link RedirectListener.RedirectCallback#onRedirectReceived()} will not be
+ * invoked when receiving a GET request with an unexpected path.
+ */
+ @Test
+ public void receiveUnknownGetRequest() {
+ when(mIHTTPSession.getMethod()).thenReturn(NanoHTTPD.Method.GET);
+ when(mIHTTPSession.getUri()).thenReturn("/test");
+ verifyStartServer();
+
+ mRedirectListener.serve(mIHTTPSession);
+
+ verify(mListener, never()).onRedirectReceived();
+
+ // Timeout has expired.
+ mLooper.moveTimeForward(RedirectListener.USER_TIMEOUT_MILLIS);
+ mLooper.dispatchAll();
+
+ verify(mListener).onRedirectTimedOut();
+ verifyStopServer();
+ }
+
+ /**
+ * Verifies that a {@link RedirectListener.RedirectCallback#onRedirectReceived()} callback will
+ * be invoked when receiving a GET request with an expected path.
+ */
+ @Test
+ public void receiveKnownGetRequest() {
+ when(mIHTTPSession.getMethod()).thenReturn(NanoHTTPD.Method.GET);
+ when(mIHTTPSession.getUri()).thenReturn(mServerUrl.getPath());
+ verifyStartServer();
+
+ mRedirectListener.serve(mIHTTPSession);
+
+ verify(mListener).onRedirectReceived();
+
+ mLooper.moveTimeForward(RedirectListener.USER_TIMEOUT_MILLIS);
+ mLooper.dispatchAll();
+
+ // TimeoutTask is cancelled once receiving HTTP redirect response.
+ verify(mListener, never()).onRedirectTimedOut();
+ verifyStopServer();
+ }
+}
+
+
+
+
+
+
+
+
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/SoapParserTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/SoapParserTest.java
index 344d1f93f..3bb63a157 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/SoapParserTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/SoapParserTest.java
@@ -20,6 +20,8 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.MockitoAnnotations.initMocks;
+import android.support.test.filters.SmallTest;
+
import org.junit.Before;
import org.junit.Test;
import org.ksoap2.serialization.PropertyInfo;
@@ -28,6 +30,7 @@ import org.ksoap2.serialization.SoapObject;
/**
* Unit tests for {@link SoapParser}.
*/
+@SmallTest
public class SoapParserTest {
private static final String EXEC = "exec";
private static final String BROWSER_COMMAND = "launchBrowserToURI";
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/SppResponseMessageTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/SppResponseMessageTest.java
index 5253946b2..5e6ed070c 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/SppResponseMessageTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/soap/SppResponseMessageTest.java
@@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.MockitoAnnotations.initMocks;
+import android.support.test.filters.SmallTest;
+
import org.junit.Before;
import org.junit.Test;
import org.ksoap2.serialization.SoapObject;
@@ -30,6 +32,7 @@ import java.util.Map;
/**
* Unit tests for {@link SppResponseMessage}.
*/
+@SmallTest
public class SppResponseMessageTest {
private static final String TEST_STATUS = "OK";
private static final String TEST_ERROR_STATUS = "Error occurred";