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

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: Pass ownership to storage and keep a raw ptr Created 5 years, 5 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..db634c1dabde5d8b01639c679d28ec9a2985485f 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.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
import java.util.HashMap;
/**
* Tests making requests using QUIC.
*/
public class QuicTest extends CronetTestBase {
-
+ private static final String TAG = "cr.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,47 @@ 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.
+ while (true) {
+ Log.i(TAG, "Still waiting for pref file update.....");
+ Thread.sleep(10000);
+ boolean contains = false;
+ try {
+ if (fileContainsString("local_prefs.json", "quic")) break;
+ } catch (FileNotFoundException e) {
+ // Ignored this exception since the file will only be created when updates are
+ // flushed to the disk.
+ }
+ }
+ assertTrue(fileContainsString("local_prefs.json",
+ QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerPort()));
+ mActivity.mUrlRequestContext.shutdown();
+
+ // Make another request using a new context but with no quic hints.
mmenke 2015/07/09 19:08:10 nit: QUIC
xunjieli 2015/07/09 19:37:02 Done.
+ 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 {
+ File file = new File(mActivity.getTestStorage() + "/" + filename);
+ FileInputStream fileInputStream = new FileInputStream(file);
+ byte[] data = new byte[(int) file.length()];
+ fileInputStream.read(data);
+ fileInputStream.close();
+ return new String(data, "UTF-8").contains(content);
}
}

Powered by Google App Engine
This is Rietveld 408576698