| 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 f4ff70cdb0c693ecf60c9f532007ec18eb8a7ffc..9799debcd2a128de3b73f5ddf65dc1c51eacc3ab 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
|
| @@ -18,6 +18,7 @@ import java.io.ByteArrayOutputStream;
|
| import java.io.FileNotFoundException;
|
| import java.io.IOException;
|
| import java.io.InputStream;
|
| +import java.io.OutputStream;
|
| import java.net.HttpURLConnection;
|
| import java.net.MalformedURLException;
|
| import java.net.URL;
|
| @@ -37,6 +38,7 @@ import java.util.regex.Pattern;
|
| * See {@link CronetTestBase#runTest()} for details.
|
| */
|
| public class CronetHttpURLConnectionTest extends CronetTestBase {
|
| + private static final String UPLOAD_DATA = "Nifty upload data!";
|
| private CronetTestActivity mActivity;
|
|
|
| @Override
|
| @@ -76,6 +78,121 @@ public class CronetHttpURLConnectionTest extends CronetTestBase {
|
| @SmallTest
|
| @Feature({"Cronet"})
|
| @CompareDefaultWithCronet
|
| + public void testPostAfterConnectionMade() throws Exception {
|
| + URL url = new URL(NativeTestServer.getEchoBodyURL());
|
| + HttpURLConnection connection =
|
| + (HttpURLConnection) url.openConnection();
|
| + connection.setDoOutput(true);
|
| + connection.setRequestMethod("POST");
|
| + assertEquals(200, connection.getResponseCode());
|
| +
|
| + try {
|
| + connection.getOutputStream();
|
| + fail();
|
| + } catch (java.net.ProtocolException e) {
|
| + // Expected.
|
| + }
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Cronet"})
|
| + @CompareDefaultWithCronet
|
| + public void testPostFixedLengthStreamingMode() throws Exception {
|
| + URL url = new URL(NativeTestServer.getEchoBodyURL());
|
| + HttpURLConnection connection =
|
| + (HttpURLConnection) url.openConnection();
|
| + connection.setDoOutput(true);
|
| + connection.setRequestMethod("POST");
|
| + byte[] data = UPLOAD_DATA.getBytes("UTF8");
|
| + connection.setFixedLengthStreamingMode(data.length);
|
| + OutputStream out = connection.getOutputStream();
|
| + out.write(data);
|
| + assertEquals(200, connection.getResponseCode());
|
| + assertEquals("OK", connection.getResponseMessage());
|
| + assertEquals(UPLOAD_DATA, getResponseAsString(connection));
|
| + connection.disconnect();
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Cronet"})
|
| + @CompareDefaultWithCronet
|
| + // This tests simulates large amount of data by making the internal buffer
|
| + // size of CronetOutputStream very small.
|
| + public void testPostFixedLengthStreamingModeLargeData() throws Exception {
|
| + URL url = new URL(NativeTestServer.getEchoBodyURL());
|
| + HttpURLConnection connection =
|
| + (HttpURLConnection) url.openConnection();
|
| + connection.setDoOutput(true);
|
| + connection.setRequestMethod("POST");
|
| + byte[] data = UPLOAD_DATA.getBytes("UTF8");
|
| + connection.setFixedLengthStreamingMode(data.length);
|
| + CronetOutputStream.setDefaultBufferLengthForTesting(3);
|
| + OutputStream out = connection.getOutputStream();
|
| + out.write(data);
|
| + assertEquals(200, connection.getResponseCode());
|
| + assertEquals("OK", connection.getResponseMessage());
|
| + assertEquals(UPLOAD_DATA, getResponseAsString(connection));
|
| + connection.disconnect();
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Cronet"})
|
| + @CompareDefaultWithCronet
|
| + public void testPostWithContentLength() throws Exception {
|
| + URL url = new URL(NativeTestServer.getEchoBodyURL());
|
| + HttpURLConnection connection =
|
| + (HttpURLConnection) url.openConnection();
|
| + connection.setDoOutput(true);
|
| + connection.setRequestMethod("POST");
|
| + byte[] data = UPLOAD_DATA.getBytes("UTF8");
|
| + connection.setRequestProperty("Content-Length",
|
| + Integer.toString(data.length));
|
| + OutputStream out = connection.getOutputStream();
|
| + out.write(data);
|
| + assertEquals(200, connection.getResponseCode());
|
| + assertEquals("OK", connection.getResponseMessage());
|
| + assertEquals(UPLOAD_DATA, getResponseAsString(connection));
|
| + connection.disconnect();
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Cronet"})
|
| + @CompareDefaultWithCronet
|
| + public void testPostWithoutContentLength() throws Exception {
|
| + URL url = new URL(NativeTestServer.getEchoBodyURL());
|
| + HttpURLConnection connection =
|
| + (HttpURLConnection) url.openConnection();
|
| + connection.setDoOutput(true);
|
| + connection.setRequestMethod("POST");
|
| + byte[] data = UPLOAD_DATA.getBytes("UTF8");
|
| + OutputStream out = connection.getOutputStream();
|
| + out.write(data);
|
| + assertEquals(200, connection.getResponseCode());
|
| + assertEquals("OK", connection.getResponseMessage());
|
| + assertEquals(UPLOAD_DATA, 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
|
| public void testNotFoundURLRequest() throws Exception {
|
| URL url = new URL(NativeTestServer.getFileURL("/notfound.html"));
|
| HttpURLConnection urlConnection =
|
|
|