use of com.google.mockwebserver.MockResponse in project j2objc by google.
the class URLConnectionTest method testClientConfiguredCustomContentEncoding.
// JVM failure.
// /**
// * This test checks whether connections are gzipped by default. This
// * behavior in not required by the API, so a failure of this test does not
// * imply a bug in the implementation.
// */
// public void testGzipEncodingEnabledByDefault() throws IOException, InterruptedException {
// server.enqueue(new MockResponse()
// .setBody(gzip("ABCABCABC".getBytes("UTF-8")))
// .addHeader("Content-Encoding: gzip"));
// server.play();
//
// URLConnection connection = server.getUrl("/").openConnection();
// assertEquals("ABCABCABC", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
// assertNull(connection.getContentEncoding());
// assertEquals(-1, connection.getContentLength());
//
// RecordedRequest request = server.takeRequest();
// assertContains(request.getHeaders(), "Accept-Encoding: gzip");
// }
// TODO(tball): b/28067294
// public void testClientConfiguredGzipContentEncoding() throws Exception {
// byte[] bodyBytes = gzip("ABCDEFGHIJKLMNOPQRSTUVWXYZ".getBytes("UTF-8"));
// server.enqueue(new MockResponse()
// .setBody(bodyBytes)
// .addHeader("Content-Encoding: gzip")
// .addHeader("Content-Length: " + bodyBytes.length));
// server.play();
//
// URLConnection connection = server.getUrl("/").openConnection();
// connection.addRequestProperty("Accept-Encoding", "gzip");
// InputStream gunzippedIn = new GZIPInputStream(connection.getInputStream());
// assertEquals("ABCDEFGHIJKLMNOPQRSTUVWXYZ", readAscii(gunzippedIn, Integer.MAX_VALUE));
// assertEquals(bodyBytes.length, connection.getContentLength());
//
// RecordedRequest request = server.takeRequest();
// assertContains(request.getHeaders(), "Accept-Encoding: gzip");
// assertEquals("gzip", connection.getContentEncoding());
// }
// TODO(tball): b/28067294
// public void testGzipAndConnectionReuseWithFixedLength() throws Exception {
// testClientConfiguredGzipContentEncodingAndConnectionReuse(TransferKind.FIXED_LENGTH);
// }
// TODO(tball): b/28067294
// public void testGzipAndConnectionReuseWithChunkedEncoding() throws Exception {
// testClientConfiguredGzipContentEncodingAndConnectionReuse(TransferKind.CHUNKED);
// }
public void testClientConfiguredCustomContentEncoding() throws Exception {
server.enqueue(new MockResponse().setBody("ABCDE").addHeader("Content-Encoding: custom"));
server.play();
URLConnection connection = server.getUrl("/").openConnection();
connection.addRequestProperty("Accept-Encoding", "custom");
assertEquals("ABCDE", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
RecordedRequest request = server.takeRequest();
assertContains(request.getHeaders(), "Accept-Encoding: custom");
}
use of com.google.mockwebserver.MockResponse in project android_frameworks_base by DirtyUnicorns.
the class DownloadManagerBaseTest method buildResponse.
/**
* Helper to build a response from the MockWebServer with no body.
*
* @param status The HTTP status code to return for this response
* @return Returns the mock web server response that was queued (which can be modified)
*/
protected MockResponse buildResponse(int status) {
MockResponse response = new MockResponse().setResponseCode(status);
response.setHeader("Content-type", mFileType);
return response;
}
use of com.google.mockwebserver.MockResponse in project android_frameworks_base by DirtyUnicorns.
the class DownloadManagerFunctionalTest method testServerDropConnection_body.
/**
* Tests that we get an error code when the server drops the connection during a download.
*/
@LargeTest
public void testServerDropConnection_body() throws Exception {
// file size = 25000 bytes
byte[] blobData = generateData(25000, DataType.TEXT);
final MockResponse resp = buildResponse(HTTP_OK, blobData);
resp.setHeader("Content-Length", "50000");
enqueueResponse(resp);
long dlRequest = doCommonStandardEnqueue();
waitForDownloadOrTimeout(dlRequest);
Cursor cursor = getCursor(dlRequest);
try {
verifyInt(cursor, DownloadManager.COLUMN_STATUS, DownloadManager.STATUS_FAILED);
verifyInt(cursor, DownloadManager.COLUMN_REASON, DownloadManager.ERROR_CANNOT_RESUME);
} finally {
cursor.close();
}
// Even tho the server drops the connection, we should still get a completed notification
assertEquals(1, mReceiver.numDownloadsCompleted());
}
use of com.google.mockwebserver.MockResponse in project android_frameworks_base by DirtyUnicorns.
the class DownloadManagerFunctionalTest method testErrorTooManyRedirects.
/**
* Tests the download failure error after too many redirects (>5).
*/
@LargeTest
public void testErrorTooManyRedirects() throws Exception {
Uri uri = getServerUri(DEFAULT_FILENAME);
// force 6 redirects
for (int i = 0; i < 6; ++i) {
final MockResponse resp = buildResponse(HTTP_REDIRECT);
resp.setHeader("Location", uri.toString());
enqueueResponse(resp);
}
doErrorTest(uri, DownloadManager.ERROR_TOO_MANY_REDIRECTS);
}
use of com.google.mockwebserver.MockResponse in project android_frameworks_base by DirtyUnicorns.
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());
}
Aggregations