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

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

Issue 1138493002: [Cronet] Added a unit test in QuicTest to test async API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/cronet/android/test/quic_test_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.test.suitebuilder.annotation.SmallTest; 7 import android.test.suitebuilder.annotation.SmallTest;
8 8
9 import org.chromium.base.test.util.Feature; 9 import org.chromium.base.test.util.Feature;
10 10
11 import java.util.HashMap; 11 import java.util.HashMap;
12 12
13 /** 13 /**
14 * Tests making requests using QUIC. 14 * Tests making requests using QUIC.
15 */ 15 */
16 public class QuicTest extends CronetTestBase { 16 public class QuicTest extends CronetTestBase {
17 17
18 private CronetTestActivity mActivity; 18 private CronetTestActivity mActivity;
19 19
20 @Override 20 @Override
21 protected void setUp() throws Exception { 21 protected void setUp() throws Exception {
22 super.setUp(); 22 super.setUp();
23 mActivity = launchCronetTestApp(); 23 // Load library first, since we need the Quic test server's URL.
24 QuicTestServer.startQuicTestServer(mActivity.getApplicationContext()); 24 System.loadLibrary("cronet_tests");
25 QuicTestServer.startQuicTestServer(getInstrumentation().getTargetContext ());
26 UrlRequestContextConfig config = new UrlRequestContextConfig();
27 config.enableQUIC(true);
28 config.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSer verPort(),
29 QuicTestServer.getServerPort());
30 config.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF");
31
32 String[] commandLineArgs = {CronetTestActivity.CONFIG_KEY, config.toStri ng(),
33 CronetTestActivity.CACHE_KEY, CronetTestActivity.CACHE_DISK_NO_H TTP};
34 mActivity = launchCronetTestAppWithUrlAndCommandLineArgs(null, commandLi neArgs);
25 } 35 }
26 36
27 @Override 37 @Override
28 protected void tearDown() throws Exception { 38 protected void tearDown() throws Exception {
29 QuicTestServer.shutdownQuicTestServer(); 39 QuicTestServer.shutdownQuicTestServer();
30 super.tearDown(); 40 super.tearDown();
31 } 41 }
32 42
33 @SmallTest 43 @SmallTest
34 @Feature({"Cronet"}) 44 @Feature({"Cronet"})
35 public void testQuicLoadUrl() throws Exception { 45 public void testQuicLoadUrl_LegacyAPI() throws Exception {
36 HttpUrlRequestFactoryConfig config = new HttpUrlRequestFactoryConfig();
37 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 46 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
38 config.enableQUIC(true);
39 config.setLibraryName("cronet_tests");
40 config.addQuicHint(QuicTestServer.getServerHost(),
41 QuicTestServer.getServerPort(), QuicTestServer.getServerPort());
42 config.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF");
43
44 HttpUrlRequestFactory factory = HttpUrlRequestFactory.createFactory(
45 mActivity.getApplicationContext(), config);
46 47
47 HashMap<String, String> headers = new HashMap<String, String>(); 48 HashMap<String, String> headers = new HashMap<String, String>();
48 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); 49 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
49 50
50 // Quic always races the first request with SPDY, but the second request 51 // Although the native stack races QUIC and SPDY for the first request,
51 // should go through Quic. 52 // since there is no http server running on the corresponding TCP port,
52 for (int i = 0; i < 2; i++) { 53 // QUIC will always succeed with a 200 (see
53 HttpUrlRequest request = 54 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
54 factory.createRequest( 55 HttpUrlRequest request = mActivity.mRequestFactory.createRequest(
55 quicURL, 56 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er);
56 HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, 57 request.start();
57 headers, 58 listener.blockForComplete();
58 listener);
59 request.start();
60 listener.blockForComplete();
61 if (listener.mHttpStatusCode == 200) break;
62 }
63 assertEquals(200, listener.mHttpStatusCode); 59 assertEquals(200, listener.mHttpStatusCode);
64 assertEquals( 60 assertEquals(
65 "This is a simple text file served by QUIC.\n", 61 "This is a simple text file served by QUIC.\n",
66 listener.mResponseAsString); 62 listener.mResponseAsString);
67 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol); 63 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol);
68 } 64 }
65
66 @SmallTest
67 @Feature({"Cronet"})
68 public void testQuicLoadUrl() throws Exception {
69 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
70 TestUrlRequestListener listener = new TestUrlRequestListener();
71
72 // Although the native stack races QUIC and SPDY for the first request,
73 // since there is no http server running on the corresponding TCP port,
74 // QUIC will always succeed with a 200 (see
75 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
76 UrlRequest request = mActivity.mUrlRequestContext.createRequest(
77 quicURL, listener, listener.getExecutor());
78 request.start();
79 listener.blockForDone();
80
81 assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
82 assertEquals("This is a simple text file served by QUIC.\n", listener.mR esponseAsString);
83 assertEquals("quic/1+spdy/3", listener.mResponseInfo.getNegotiatedProtoc ol());
84 }
69 } 85 }
OLDNEW
« no previous file with comments | « no previous file | components/cronet/android/test/quic_test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698