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

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

Issue 1175733002: [Cronet] Set up HttpServerPropertiesManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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/QuicTest.java
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/QuicTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/QuicTest.java
index ae2cf2fd9aa9b332ce1ef3efbe37e233f6885cf0..4a5970c1680d8418e768a9e22e8d0dad4f5e83a7 100644
--- a/components/cronet/android/test/javatests/src/org/chromium/net/QuicTest.java
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/QuicTest.java
@@ -4,17 +4,23 @@
package org.chromium.net;
+import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
+import org.chromium.base.Log;
import org.chromium.base.test.util.Feature;
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
import java.util.HashMap;
/**
* Tests making requests using QUIC.
*/
public class QuicTest extends CronetTestBase {
-
+ private static final String TAG = Log.makeTag("QuicTest");
private CronetTestActivity mActivity;
@Override
@@ -63,7 +69,7 @@ public class QuicTest extends CronetTestBase {
assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol);
}
- @SmallTest
+ @LargeTest
@Feature({"Cronet"})
public void testQuicLoadUrl() throws Exception {
String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
@@ -81,5 +87,56 @@ public class QuicTest extends CronetTestBase {
assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
assertEquals("This is a simple text file served by QUIC.\n", listener.mResponseAsString);
assertEquals("quic/1+spdy/3", listener.mResponseInfo.getNegotiatedProtocol());
+
+ // This test takes a long time, since the update will only be scheduled
+ // after kUpdatePrefsDelayMs in http_server_properties_manager.cc.
pauljensen 2015/06/15 15:57:42 Yikes, this will pause a full minute. Other tests
xunjieli 2015/06/15 18:41:36 Acknowledged. Yea. This is pretty ugly.
+ while (true) {
+ Log.i(TAG, "Still waiting for pref file update.....");
+ Thread.sleep(10000);
+ boolean contains = false;
+ try {
+ contains = fileContainsString("local_prefs.json", "quic");
pauljensen 2015/06/15 15:57:42 This seems prone to failure. Is there a more robu
xunjieli 2015/06/15 18:41:36 Yes to the second part. There is no documentation
+ } catch (FileNotFoundException e) {
+ // Ignored this exception since file will only be created when updated is flushed to
+ // disk.
+ }
+ if (contains) {
+ break;
+ }
+ }
+ assertTrue(fileContainsString("local_prefs.json",
+ QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerPort()));
+ mActivity.mUrlRequestContext.shutdown();
+
+ // Make another request using a new context but with no quic hints.
+ UrlRequestContextConfig config = new UrlRequestContextConfig();
+ config.setStoragePath(mActivity.getTestStorage());
+ config.enableHttpCache(UrlRequestContextConfig.HttpCache.DISK, 1000 * 1024);
+ config.enableQUIC(true);
+ CronetUrlRequestContext newContext =
+ new CronetUrlRequestContext(getInstrumentation().getTargetContext(), config);
+ TestUrlRequestListener listener2 = new TestUrlRequestListener();
+ UrlRequest request2 = newContext.createRequest(quicURL, listener2, listener2.getExecutor());
+ request2.start();
+ listener2.blockForDone();
+ assertEquals(200, listener2.mResponseInfo.getHttpStatusCode());
+ assertEquals("This is a simple text file served by QUIC.\n", listener2.mResponseAsString);
+ assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProtocol());
+ }
+
+ // Returns whether a file contains a particular string.
+ private boolean fileContainsString(String filename, String content) throws IOException {
+ BufferedReader reader =
+ new BufferedReader(new FileReader(mActivity.getTestStorage() + "/" + filename));
+ String line;
+ while ((line = reader.readLine()) != null) {
pauljensen 2015/06/15 15:57:42 Rather than looping, could we just read it all? F
xunjieli 2015/06/15 18:41:36 Done. That is indeed cleaner.
+ if (line.contains(content)) {
+ reader.close();
+ return true;
+ }
+ Log.i(TAG, "Pref file line:%s", line);
pauljensen 2015/06/15 15:57:42 This seems like it might produce an exorbitant amo
xunjieli 2015/06/15 18:41:36 Done. The file turns out to be pretty small. I add
+ }
+ reader.close();
+ return false;
}
}

Powered by Google App Engine
This is Rietveld 408576698