diff options
author | Jesse Wilson <jessewilson@google.com> | 2010-12-16 12:06:32 -0800 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2010-12-16 12:06:32 -0800 |
commit | bf1df887d4b87f7da69cd4fe9306eb0d19166d52 (patch) | |
tree | 779f337940416da73b6b499e8e355bcc772ced20 /core/tests | |
parent | 80bc16f7dfd9f46e0201ec6386dcf1436ec020d7 (diff) | |
download | frameworks_base-bf1df887d4b87f7da69cd4fe9306eb0d19166d52.zip frameworks_base-bf1df887d4b87f7da69cd4fe9306eb0d19166d52.tar.gz frameworks_base-bf1df887d4b87f7da69cd4fe9306eb0d19166d52.tar.bz2 |
New tests for AndroidHttpClient with a proxy server.
Change-Id: I03ec2f1257824c8675156dd80f6045512d1a36fe
http://b/3254717
Diffstat (limited to 'core/tests')
-rw-r--r-- | core/tests/coretests/src/android/net/http/AbstractProxyTest.java (renamed from core/tests/coretests/src/android/net/http/ProxyTest.java) | 30 | ||||
-rw-r--r-- | core/tests/coretests/src/android/net/http/AndroidHttpClientProxyTest.java | 26 | ||||
-rw-r--r-- | core/tests/coretests/src/android/net/http/DefaultHttpClientProxyTest.java | 27 |
3 files changed, 71 insertions, 12 deletions
diff --git a/core/tests/coretests/src/android/net/http/ProxyTest.java b/core/tests/coretests/src/android/net/http/AbstractProxyTest.java index 8175531..2fb833c 100644 --- a/core/tests/coretests/src/android/net/http/ProxyTest.java +++ b/core/tests/coretests/src/android/net/http/AbstractProxyTest.java @@ -33,15 +33,16 @@ import org.apache.http.conn.params.ConnRouteParams; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.ssl.AllowAllHostnameVerifier; import org.apache.http.conn.ssl.SSLSocketFactory; -import org.apache.http.impl.client.DefaultHttpClient; import tests.http.MockResponse; import tests.http.MockWebServer; import tests.http.RecordedRequest; -public class ProxyTest extends TestCase { +public abstract class AbstractProxyTest extends TestCase { private MockWebServer server = new MockWebServer(); + protected abstract HttpClient newHttpClient(); + @Override protected void tearDown() throws Exception { System.clearProperty("proxyHost"); System.clearProperty("proxyPort"); @@ -54,7 +55,7 @@ public class ProxyTest extends TestCase { super.tearDown(); } - public void testConnectToHttps() throws IOException, InterruptedException { + public void testConnectToHttps() throws Exception { TestSSLContext testSSLContext = TestSSLContext.create(); server.useHttps(testSSLContext.serverContext.getSocketFactory(), false); @@ -63,9 +64,9 @@ public class ProxyTest extends TestCase { .setBody("this response comes via HTTPS")); server.play(); - HttpClient httpClient = new DefaultHttpClient(); - SSLSocketFactory sslSocketFactory = new SSLSocketFactory( - testSSLContext.clientContext.getSocketFactory()); + HttpClient httpClient = newHttpClient(); + + SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext); sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier()); httpClient.getConnectionManager().getSchemeRegistry() .register(new Scheme("https", sslSocketFactory, server.getPort())); @@ -78,6 +79,12 @@ public class ProxyTest extends TestCase { assertEquals("GET /foo HTTP/1.1", request.getRequestLine()); } + private SSLSocketFactory newSslSocketFactory(TestSSLContext testSSLContext) throws Exception { + // call through to Apache HTTP's non-public SSLSocketFactory constructor + return SSLSocketFactory.class.getConstructor(javax.net.ssl.SSLSocketFactory.class) + .newInstance(testSSLContext.clientContext.getSocketFactory()); + } + /** * We had bugs where proxy system properties weren't being honored. * http://b/3254717 @@ -108,7 +115,7 @@ public class ProxyTest extends TestCase { server.enqueue(mockResponse); server.play(); - HttpClient httpProxyClient = new DefaultHttpClient(); + HttpClient httpProxyClient = newHttpClient(); HttpGet request = new HttpGet("http://android.com/foo"); proxyConfig.configure(server, httpProxyClient, request); @@ -150,9 +157,8 @@ public class ProxyTest extends TestCase { .setBody("this response comes via a secure proxy")); server.play(); - HttpClient httpProxyClient = new DefaultHttpClient(); - SSLSocketFactory sslSocketFactory = new SSLSocketFactory( - testSSLContext.clientContext.getSocketFactory()); + HttpClient httpProxyClient = newHttpClient(); + SSLSocketFactory sslSocketFactory = newSslSocketFactory(testSSLContext); sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier()); httpProxyClient.getConnectionManager().getSchemeRegistry() .register(new Scheme("https", sslSocketFactory, 443)); @@ -187,7 +193,7 @@ public class ProxyTest extends TestCase { System.setProperty("http.proxyHost", "proxy.foo"); System.setProperty("http.proxyPort", "8080"); - HttpClient client = new DefaultHttpClient(); + HttpClient client = newHttpClient(); HttpGet request = new HttpGet("http://origin.foo/bar"); proxyConfig.configure(server, client, request); HttpResponse response = client.execute(request); @@ -203,7 +209,7 @@ public class ProxyTest extends TestCase { System.setProperty("http.proxyHost", "proxy.foo"); System.setProperty("http.proxyPort", "8080"); - HttpClient client = new DefaultHttpClient(); + HttpClient client = newHttpClient(); HttpGet request = new HttpGet(server.getUrl("/bar").toURI()); request.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, ConnRouteParams.NO_HOST); HttpResponse response = client.execute(request); diff --git a/core/tests/coretests/src/android/net/http/AndroidHttpClientProxyTest.java b/core/tests/coretests/src/android/net/http/AndroidHttpClientProxyTest.java new file mode 100644 index 0000000..b33bdb8 --- /dev/null +++ b/core/tests/coretests/src/android/net/http/AndroidHttpClientProxyTest.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2010 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 android.net.http; + +import org.apache.http.client.HttpClient; + +public final class AndroidHttpClientProxyTest extends AbstractProxyTest { + + @Override protected HttpClient newHttpClient() { + return AndroidHttpClient.newInstance(AbstractProxyTest.class.getName()); + } +} diff --git a/core/tests/coretests/src/android/net/http/DefaultHttpClientProxyTest.java b/core/tests/coretests/src/android/net/http/DefaultHttpClientProxyTest.java new file mode 100644 index 0000000..d6313ec --- /dev/null +++ b/core/tests/coretests/src/android/net/http/DefaultHttpClientProxyTest.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2010 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 android.net.http; + +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.DefaultHttpClient; + +public final class DefaultHttpClientProxyTest extends AbstractProxyTest { + + @Override protected HttpClient newHttpClient() { + return new DefaultHttpClient(); + } +} |