| 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..d00fa2d991c7d130f94be151bd41a0f9eafcdc38 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,24 @@
|
|
|
| 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.annotations.SuppressFBWarnings;
|
| 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 +70,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 +88,48 @@ 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.
|
| + 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.
|
| + @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
|
| + 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);
|
| }
|
| }
|
|
|