Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Unified Diff: components/cronet/android/test/javatests/src/org/chromium/net/urlconnection/CronetHttpURLConnectionTest.java

Issue 972213002: [Cronet] Implement batch read in CronetInputStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Matt's comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e288299dedfeb9646214e9f95b0770a15c02e3f3 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
@@ -10,6 +10,7 @@ import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.test.util.Feature;
import org.chromium.net.CronetTestActivity;
import org.chromium.net.CronetTestBase;
+import org.chromium.net.MockUrlRequestJobFactory;
import org.chromium.net.NativeTestServer;
import org.chromium.net.UrlRequestContextConfig;
import org.chromium.net.UrlRequestException;
@@ -478,6 +479,53 @@ public class CronetHttpURLConnectionTest extends CronetTestBase {
}
}
+ /**
+ * Tests batch reading on CronetInputStream when
+ * {@link CronetHttpURLConnection#getMoreData} is called multiple times.
+ */
+ @SmallTest
+ @Feature({"Cronet"})
+ @OnlyRunCronetHttpURLConnection
+ public void testBigDataRead() throws Exception {
+ String data = "MyBigFunkyData";
+ int dataLength = data.length();
+ int repeatCount = 100000;
+ MockUrlRequestJobFactory mMockUrlRequestJobFactory = new MockUrlRequestJobFactory(
+ getInstrumentation().getTargetContext());
+ URL url = new URL(mMockUrlRequestJobFactory.getMockUrlForData(data,
+ repeatCount));
+ HttpURLConnection connection =
+ (HttpURLConnection) url.openConnection();
+ InputStream in = connection.getInputStream();
+ byte[] actualOutput = new byte[dataLength * repeatCount];
mmenke 2015/03/05 21:42:21 Suggest another test where we only have X body byt
xunjieli 2015/03/06 15:21:23 Is this the same as testInputStreamReadMoreBytesTh
mmenke 2015/03/06 16:42:16 Oops. Yea, it is.
+ int totalBytesRead = 0;
+ // Number of bytes to read each time. It is incremented by one from 0.
+ int numBytesToRead = 0;
+ while (totalBytesRead < actualOutput.length) {
+ if (actualOutput.length - totalBytesRead < numBytesToRead) {
+ // Do not read out of bound.
+ numBytesToRead = actualOutput.length - totalBytesRead;
+ }
+ int bytesRead = in.read(actualOutput, totalBytesRead, numBytesToRead);
+ assertTrue(bytesRead <= numBytesToRead);
+ totalBytesRead += bytesRead;
+ numBytesToRead++;
+ }
+
+ // All data has been read. Try reading beyond what is available should give -1.
+ assertEquals(0, in.read(actualOutput, 0, 0));
+ assertEquals(-1, in.read(actualOutput, 0, 1));
+
+ String responseData = new String(actualOutput);
+ for (int i = 0; i < repeatCount; ++i) {
+ assertEquals(data, responseData.substring(dataLength * i,
+ dataLength * (i + 1)));
+ }
+ // TODO(xunjieli): Enable after crbug.com/463720 is fixed.
+ // assertEquals(200, connection.getResponseCode());
+ // assertEquals("OK", connection.getResponseMessage());
+ }
+
@SmallTest
@Feature({"Cronet"})
@CompareDefaultWithCronet

Powered by Google App Engine
This is Rietveld 408576698