Chromium Code Reviews| 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..af00a67491787a978354092baccf6be809e701f6 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,50 @@ 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/07/06 16:31:46
Does this mean that if your app is never allowed t
xunjieli
2015/07/06 19:40:03
In this our case, we can't easily flush the update
|
| + 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/07/06 16:31:46
can we remove |contains| and just use "if (blah) b
xunjieli
2015/07/06 19:40:03
Done.
|
| + } 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 { |
| + 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); |
| } |
| } |