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());
}
use of com.google.mockwebserver.MockResponse in project android_frameworks_base by DirtyUnicorns.
the class CookiesTest method testCookiesWithNonMatchingCase.
/**
* Test that cookies aren't case-sensitive with respect to hostname.
* http://b/3167208
*/
public void testCookiesWithNonMatchingCase() throws Exception {
// use a proxy so we can manipulate the origin server's host name
server = new MockWebServer();
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=first; Domain=my.t-mobile.com").addHeader("Set-Cookie: b=second; Domain=.T-mobile.com").addHeader("Set-Cookie: c=third; Domain=.t-mobile.com").setBody("This response sets some cookies."));
server.enqueue(new MockResponse().setBody("This response gets those cookies back."));
server.play();
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("localhost", server.getPort()));
HttpResponse getCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
getCookies.getEntity().consumeContent();
server.takeRequest();
HttpResponse sendCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
sendCookies.getEntity().consumeContent();
RecordedRequest sendCookiesRequest = server.takeRequest();
assertContains(sendCookiesRequest.getHeaders(), "Cookie: a=first; b=second; c=third");
}
use of com.google.mockwebserver.MockResponse in project android_frameworks_base by AOSPA.
the class CookiesTest method testCookiesWithNonMatchingCase.
/**
* Test that cookies aren't case-sensitive with respect to hostname.
* http://b/3167208
*/
public void testCookiesWithNonMatchingCase() throws Exception {
// use a proxy so we can manipulate the origin server's host name
server = new MockWebServer();
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=first; Domain=my.t-mobile.com").addHeader("Set-Cookie: b=second; Domain=.T-mobile.com").addHeader("Set-Cookie: c=third; Domain=.t-mobile.com").setBody("This response sets some cookies."));
server.enqueue(new MockResponse().setBody("This response gets those cookies back."));
server.play();
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("localhost", server.getPort()));
HttpResponse getCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
getCookies.getEntity().consumeContent();
server.takeRequest();
HttpResponse sendCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
sendCookies.getEntity().consumeContent();
RecordedRequest sendCookiesRequest = server.takeRequest();
assertContains(sendCookiesRequest.getHeaders(), "Cookie: a=first; b=second; c=third");
}
use of com.google.mockwebserver.MockResponse in project android_frameworks_base by AOSPA.
the class DefaultHttpClientTest method testServerClosesOutput.
private void testServerClosesOutput(SocketPolicy socketPolicy) throws Exception {
server.enqueue(new MockResponse().setBody("This connection won't pool properly").setSocketPolicy(socketPolicy));
server.enqueue(new MockResponse().setBody("This comes after a busted connection"));
server.play();
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse a = client.execute(new HttpGet(server.getUrl("/a").toURI()));
assertEquals("This connection won't pool properly", contentToString(a));
assertEquals(0, server.takeRequest().getSequenceNumber());
HttpResponse b = client.execute(new HttpGet(server.getUrl("/b").toURI()));
assertEquals("This comes after a busted connection", contentToString(b));
// sequence number 0 means the HTTP socket connection was not reused
assertEquals(0, server.takeRequest().getSequenceNumber());
}
Aggregations