use of com.google.mockwebserver.MockResponse in project android_frameworks_base by AOSPA.
the class AbstractProxyTest method testParamPreferredOverSystemProperty.
private void testParamPreferredOverSystemProperty(ProxyConfig proxyConfig) throws Exception {
server.enqueue(new MockResponse().setBody("Via request parameter proxy!"));
server.play();
System.setProperty("http.proxyHost", "proxy.foo");
System.setProperty("http.proxyPort", "8080");
HttpClient client = newHttpClient();
HttpGet request = new HttpGet("http://origin.foo/bar");
proxyConfig.configure(server, client, request);
HttpResponse response = client.execute(request);
assertEquals("Via request parameter proxy!", contentToString(response));
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("GET http://origin.foo/bar HTTP/1.1", recordedRequest.getRequestLine());
}
use of com.google.mockwebserver.MockResponse in project android_frameworks_base by AOSPA.
the class AbstractProxyTest method testConnectToHttps.
public void testConnectToHttps() throws Exception {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via HTTPS"));
server.play();
HttpClient httpClient = newHttpClient();
SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", sslSocketFactory, server.getPort()));
HttpResponse response = httpClient.execute(new HttpGet("https://localhost:" + server.getPort() + "/foo"));
assertEquals("this response comes via HTTPS", contentToString(response));
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}
use of com.google.mockwebserver.MockResponse in project android_frameworks_base by AOSPA.
the class AbstractProxyTest method testRetryWithProxy.
// http://b/5372438
public void testRetryWithProxy() throws Exception {
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AT_START));
server.play();
HttpClient httpProxyClient = newHttpClient();
HttpGet request = new HttpGet("http://android.com/foo");
ProxyConfig.REQUEST_PARAMETER.configure(server, httpProxyClient, request);
try {
httpProxyClient.execute(request);
fail();
} catch (IOException expected) {
}
}
use of com.google.mockwebserver.MockResponse in project android_frameworks_base by ResurrectionRemix.
the class DownloadManagerFunctionalTest method testRelativeRedirect.
/**
* Tests the download failure error from an unhandled HTTP status code
*/
@LargeTest
public void testRelativeRedirect() throws Exception {
Uri uri = getServerUri(DEFAULT_FILENAME);
final MockResponse resp = buildResponse(HTTP_REDIRECT);
resp.setHeader("Location", ":" + uri.getSchemeSpecificPart());
enqueueResponse(resp);
byte[] blobData = generateData(DEFAULT_FILE_SIZE, DataType.TEXT);
enqueueResponse(buildResponse(HTTP_OK, blobData));
Request request = new Request(uri);
request.setTitle(DEFAULT_FILENAME);
long dlRequest = mDownloadManager.enqueue(request);
waitForDownloadOrTimeout(dlRequest);
verifyAndCleanupSingleFileDownload(dlRequest, blobData);
assertEquals(1, mReceiver.numDownloadsCompleted());
}
use of com.google.mockwebserver.MockResponse in project android_frameworks_base by ResurrectionRemix.
the class AbstractProxyTest method testConnectToHttps.
public void testConnectToHttps() throws Exception {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
server.enqueue(new MockResponse().setResponseCode(200).setBody("this response comes via HTTPS"));
server.play();
HttpClient httpClient = newHttpClient();
SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext);
sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());
httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", sslSocketFactory, server.getPort()));
HttpResponse response = httpClient.execute(new HttpGet("https://localhost:" + server.getPort() + "/foo"));
assertEquals("this response comes via HTTPS", contentToString(response));
RecordedRequest request = server.takeRequest();
assertEquals("GET /foo HTTP/1.1", request.getRequestLine());
}
Aggregations