| Index: components/cronet/android/test/javatests/src/org/chromium/net/urlconnection/CronetHttpURLConnectionTest.java
|
| diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/urlconnection/CronetHttpURLConnectionTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/urlconnection/CronetHttpURLConnectionTest.java
|
| index 083c0f869bccdbbd8c27aea4b3caaae324aa989a..4d3f0aab05d589f75aabd44ed835c6e54e061037 100644
|
| --- a/components/cronet/android/test/javatests/src/org/chromium/net/urlconnection/CronetHttpURLConnectionTest.java
|
| +++ b/components/cronet/android/test/javatests/src/org/chromium/net/urlconnection/CronetHttpURLConnectionTest.java
|
| @@ -20,6 +20,8 @@ import java.io.ByteArrayOutputStream;
|
| import java.io.FileNotFoundException;
|
| import java.io.IOException;
|
| import java.io.InputStream;
|
| +import java.io.OutputStream;
|
| +import java.lang.reflect.Method;
|
| import java.net.HttpURLConnection;
|
| import java.net.MalformedURLException;
|
| import java.net.URL;
|
| @@ -75,6 +77,51 @@ public class CronetHttpURLConnectionTest extends CronetTestBase {
|
| urlConnection.disconnect();
|
| }
|
|
|
| + /**
|
| + * Tests that using reflection to find {@code fixedContentLengthLong} works.
|
| + */
|
| + @SmallTest
|
| + @Feature({"Cronet"})
|
| + @OnlyRunCronetHttpURLConnection
|
| + public void testSetFixedLengthStreamingModeLong() throws Exception {
|
| + URL url = new URL(NativeTestServer.getEchoBodyURL());
|
| + HttpURLConnection connection =
|
| + (HttpURLConnection) url.openConnection();
|
| + connection.setDoOutput(true);
|
| + connection.setRequestMethod("POST");
|
| + if (Build.VERSION.SDK_INT >= 19) {
|
| + String dataString = "some very important data";
|
| + byte[] data = dataString.getBytes();
|
| + Class<?> c = connection.getClass();
|
| + Method method = c.getMethod("setFixedLengthStreamingMode",
|
| + new Class[] {long.class});
|
| + method.invoke(connection, (long) data.length);
|
| + OutputStream out = connection.getOutputStream();
|
| + out.write(data);
|
| + assertEquals(200, connection.getResponseCode());
|
| + assertEquals("OK", connection.getResponseMessage());
|
| + assertEquals(dataString, getResponseAsString(connection));
|
| + connection.disconnect();
|
| + }
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Cronet"})
|
| + @OnlyRunCronetHttpURLConnection
|
| + // TODO(xunjieli): Change the test after chunked support is added.
|
| + public void testPostChunked() throws Exception {
|
| + URL url = new URL(NativeTestServer.getEchoBodyURL());
|
| + HttpURLConnection connection =
|
| + (HttpURLConnection) url.openConnection();
|
| + connection.setDoOutput(true);
|
| + connection.setRequestMethod("POST");
|
| + try {
|
| + connection.setChunkedStreamingMode(0);
|
| + } catch (UnsupportedOperationException e) {
|
| + assertEquals("Chunked mode not supported yet", e.getMessage());
|
| + }
|
| + }
|
| +
|
| @SmallTest
|
| @Feature({"Cronet"})
|
| @CompareDefaultWithCronet
|
| @@ -226,6 +273,22 @@ public class CronetHttpURLConnectionTest extends CronetTestBase {
|
| @SmallTest
|
| @Feature({"Cronet"})
|
| @CompareDefaultWithCronet
|
| + public void testMultipleDisconnect() throws Exception {
|
| + URL url = new URL(NativeTestServer.getEchoMethodURL());
|
| + HttpURLConnection urlConnection =
|
| + (HttpURLConnection) url.openConnection();
|
| + assertEquals(200, urlConnection.getResponseCode());
|
| + assertEquals("OK", urlConnection.getResponseMessage());
|
| + assertEquals("GET", getResponseAsString(urlConnection));
|
| + // Disconnect multiple times should be fine.
|
| + for (int i = 0; i < 10; i++) {
|
| + urlConnection.disconnect();
|
| + }
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Cronet"})
|
| + @CompareDefaultWithCronet
|
| public void testAddRequestProperty() throws Exception {
|
| URL url = new URL(NativeTestServer.getEchoAllHeadersURL());
|
| HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|