| Index: components/cronet/android/test/javatests/src/org/chromium/net/urlconnection/CronetChunkedOutputStreamTest.java
|
| diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/urlconnection/CronetChunkedOutputStreamTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/urlconnection/CronetChunkedOutputStreamTest.java
|
| index d48acabf8869a9385fbcebcd9169d28360d51e28..a7df1c01f2a3dea60c23d53761d1f5080fb7438f 100644
|
| --- a/components/cronet/android/test/javatests/src/org/chromium/net/urlconnection/CronetChunkedOutputStreamTest.java
|
| +++ b/components/cronet/android/test/javatests/src/org/chromium/net/urlconnection/CronetChunkedOutputStreamTest.java
|
| @@ -11,9 +11,7 @@ import org.chromium.net.CronetTestBase;
|
| import org.chromium.net.CronetTestFramework;
|
| import org.chromium.net.NativeTestServer;
|
|
|
| -import java.io.ByteArrayOutputStream;
|
| import java.io.IOException;
|
| -import java.io.InputStream;
|
| import java.io.OutputStream;
|
| import java.net.HttpURLConnection;
|
| import java.net.ProtocolException;
|
| @@ -99,7 +97,7 @@ public class CronetChunkedOutputStreamTest extends CronetTestBase {
|
| out.write(UPLOAD_DATA);
|
| assertEquals(200, connection.getResponseCode());
|
| assertEquals("OK", connection.getResponseMessage());
|
| - assertEquals(UPLOAD_DATA_STRING, getResponseAsString(connection));
|
| + assertEquals(UPLOAD_DATA_STRING, TestUtil.getResponseAsString(connection));
|
| connection.disconnect();
|
| }
|
|
|
| @@ -116,7 +114,7 @@ public class CronetChunkedOutputStreamTest extends CronetTestBase {
|
| out.write(UPLOAD_DATA);
|
| assertEquals(200, connection.getResponseCode());
|
| assertEquals("OK", connection.getResponseMessage());
|
| - assertEquals("chunked", getResponseAsString(connection));
|
| + assertEquals("chunked", TestUtil.getResponseAsString(connection));
|
| connection.disconnect();
|
| }
|
|
|
| @@ -130,11 +128,11 @@ public class CronetChunkedOutputStreamTest extends CronetTestBase {
|
| connection.setRequestMethod("POST");
|
| connection.setChunkedStreamingMode(0);
|
| OutputStream out = connection.getOutputStream();
|
| - byte[] largeData = getLargeData();
|
| + byte[] largeData = TestUtil.getLargeData();
|
| out.write(largeData);
|
| assertEquals(200, connection.getResponseCode());
|
| assertEquals("OK", connection.getResponseMessage());
|
| - checkLargeData(getResponseAsString(connection));
|
| + TestUtil.checkLargeData(TestUtil.getResponseAsString(connection));
|
| connection.disconnect();
|
| }
|
|
|
| @@ -153,7 +151,7 @@ public class CronetChunkedOutputStreamTest extends CronetTestBase {
|
| }
|
| assertEquals(200, connection.getResponseCode());
|
| assertEquals("OK", connection.getResponseMessage());
|
| - assertEquals(UPLOAD_DATA_STRING, getResponseAsString(connection));
|
| + assertEquals(UPLOAD_DATA_STRING, TestUtil.getResponseAsString(connection));
|
| connection.disconnect();
|
| }
|
|
|
| @@ -167,13 +165,13 @@ public class CronetChunkedOutputStreamTest extends CronetTestBase {
|
| connection.setRequestMethod("POST");
|
| connection.setChunkedStreamingMode(0);
|
| OutputStream out = connection.getOutputStream();
|
| - byte[] largeData = getLargeData();
|
| + byte[] largeData = TestUtil.getLargeData();
|
| for (int i = 0; i < largeData.length; i++) {
|
| out.write(largeData[i]);
|
| }
|
| assertEquals(200, connection.getResponseCode());
|
| assertEquals("OK", connection.getResponseMessage());
|
| - checkLargeData(getResponseAsString(connection));
|
| + TestUtil.checkLargeData(TestUtil.getResponseAsString(connection));
|
| connection.disconnect();
|
| }
|
|
|
| @@ -192,49 +190,11 @@ public class CronetChunkedOutputStreamTest extends CronetTestBase {
|
| assertEquals(0, totalSize % chunkSize);
|
| connection.setChunkedStreamingMode(chunkSize);
|
| OutputStream out = connection.getOutputStream();
|
| - byte[] largeData = getLargeData();
|
| + byte[] largeData = TestUtil.getLargeData();
|
| out.write(largeData);
|
| assertEquals(200, connection.getResponseCode());
|
| assertEquals("OK", connection.getResponseMessage());
|
| - checkLargeData(getResponseAsString(connection));
|
| + TestUtil.checkLargeData(TestUtil.getResponseAsString(connection));
|
| connection.disconnect();
|
| }
|
| -
|
| - /**
|
| - * Helper method to extract response body as a string for testing.
|
| - */
|
| - private static String getResponseAsString(HttpURLConnection connection) throws Exception {
|
| - InputStream in = connection.getInputStream();
|
| - ByteArrayOutputStream out = new ByteArrayOutputStream();
|
| - int b;
|
| - while ((b = in.read()) != -1) {
|
| - out.write(b);
|
| - }
|
| - return out.toString();
|
| - }
|
| -
|
| - /**
|
| - * Produces a byte array that contains {@code REPEAT_COUNT} of
|
| - * {@code UPLOAD_DATA_STRING}.
|
| - */
|
| - private static byte[] getLargeData() {
|
| - byte[] largeData = new byte[REPEAT_COUNT * UPLOAD_DATA.length];
|
| - for (int i = 0; i < REPEAT_COUNT; i++) {
|
| - for (int j = 0; j < UPLOAD_DATA.length; j++) {
|
| - largeData[i * UPLOAD_DATA.length + j] = UPLOAD_DATA[j];
|
| - }
|
| - }
|
| - return largeData;
|
| - }
|
| -
|
| - /**
|
| - * Helper function to check whether {@code data} is a concatenation of
|
| - * {@code REPEAT_COUNT} {@code UPLOAD_DATA_STRING} strings.
|
| - */
|
| - private static void checkLargeData(String data) {
|
| - for (int i = 0; i < REPEAT_COUNT; i++) {
|
| - assertEquals(UPLOAD_DATA_STRING, data.substring(UPLOAD_DATA_STRING.length() * i,
|
| - UPLOAD_DATA_STRING.length() * (i + 1)));
|
| - }
|
| - }
|
| }
|
|
|