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

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

Issue 1389213003: [Cronet] Use Https for Quic Test Server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ryancl
Patch Set: Address Paul's comments Created 5 years, 2 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
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.LargeTest; 7 import android.test.suitebuilder.annotation.LargeTest;
8 import android.test.suitebuilder.annotation.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 9
10 import org.chromium.base.Log; 10 import org.chromium.base.Log;
11 import org.chromium.base.annotations.SuppressFBWarnings; 11 import org.chromium.base.annotations.SuppressFBWarnings;
12 import org.chromium.base.test.util.Feature; 12 import org.chromium.base.test.util.Feature;
13 13
14 import java.io.File; 14 import java.io.File;
15 import java.io.FileInputStream; 15 import java.io.FileInputStream;
16 import java.io.FileNotFoundException; 16 import java.io.FileNotFoundException;
17 import java.io.IOException; 17 import java.io.IOException;
18 import java.util.HashMap; 18 import java.util.HashMap;
19 19
20 /** 20 /**
21 * Tests making requests using QUIC. 21 * Tests making requests using QUIC.
22 */ 22 */
23 public class QuicTest extends CronetTestBase { 23 public class QuicTest extends CronetTestBase {
24 private static final String TAG = "cr.QuicTest"; 24 private static final String TAG = "cr.QuicTest";
25 private static final String[] CERTS_USED = {"quic_test.example.com.crt"};
25 private CronetTestActivity mActivity; 26 private CronetTestActivity mActivity;
26 27
27 @Override 28 @Override
28 protected void setUp() throws Exception { 29 protected void setUp() throws Exception {
29 super.setUp(); 30 super.setUp();
30 // Load library first, since we need the Quic test server's URL. 31 // Load library first, since we need the Quic test server's URL.
31 System.loadLibrary("cronet_tests"); 32 System.loadLibrary("cronet_tests");
32 QuicTestServer.startQuicTestServer(getInstrumentation().getTargetContext ()); 33 QuicTestServer.startQuicTestServer(getInstrumentation().getTargetContext ());
34
35 // Set up a MockCertVerifier to use in the tests.
36 MockCertVerifier certVerifier = new MockCertVerifier(CERTS_USED);
mef 2015/10/19 15:35:21 If certVerifier is created in test process, then i
xunjieli 2015/10/19 15:38:05 It turned out that they are in the same process. T
37
33 CronetEngine.Builder builder = new CronetEngine.Builder(mActivity); 38 CronetEngine.Builder builder = new CronetEngine.Builder(mActivity);
34 builder.enableQUIC(true); 39 builder.enableQUIC(true);
35 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe rverPort(), 40 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe rverPort(),
36 QuicTestServer.getServerPort()); 41 QuicTestServer.getServerPort());
37 builder.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF"); 42 builder.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF");
38 43
44 builder.setMockCertVerifierForTesting(certVerifier.getNativePointer());
45
39 String[] commandLineArgs = {CronetTestActivity.CONFIG_KEY, builder.toStr ing(), 46 String[] commandLineArgs = {CronetTestActivity.CONFIG_KEY, builder.toStr ing(),
40 CronetTestActivity.CACHE_KEY, CronetTestActivity.CACHE_DISK_NO_H TTP}; 47 CronetTestActivity.CACHE_KEY, CronetTestActivity.CACHE_DISK_NO_H TTP};
41 mActivity = launchCronetTestAppWithUrlAndCommandLineArgs(null, commandLi neArgs); 48 mActivity = launchCronetTestAppWithUrlAndCommandLineArgs(null, commandLi neArgs);
42 } 49 }
43 50
44 @Override 51 @Override
45 protected void tearDown() throws Exception { 52 protected void tearDown() throws Exception {
46 QuicTestServer.shutdownQuicTestServer(); 53 QuicTestServer.shutdownQuicTestServer();
47 super.tearDown(); 54 super.tearDown();
48 } 55 }
49 56
50 @SmallTest 57 @SmallTest
51 @Feature({"Cronet"}) 58 @Feature({"Cronet"})
52 public void testQuicLoadUrl_LegacyAPI() throws Exception { 59 public void testQuicLoadUrl_LegacyAPI() throws Exception {
60 long urlRequestContextAdapter = ((ChromiumUrlRequestFactory) mActivity.m RequestFactory)
61 .getRequestContext()
62 .getUrlRequestContextAdapter();
63 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, true );
53 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 64 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
54 65
55 HashMap<String, String> headers = new HashMap<String, String>(); 66 HashMap<String, String> headers = new HashMap<String, String>();
56 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); 67 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
57 68
58 // Although the native stack races QUIC and SPDY for the first request, 69 // Although the native stack races QUIC and SPDY for the first request,
59 // since there is no http server running on the corresponding TCP port, 70 // since there is no http server running on the corresponding TCP port,
60 // QUIC will always succeed with a 200 (see 71 // QUIC will always succeed with a 200 (see
61 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 72 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
62 HttpUrlRequest request = mActivity.mRequestFactory.createRequest( 73 HttpUrlRequest request = mActivity.mRequestFactory.createRequest(
63 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er); 74 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er);
64 request.start(); 75 request.start();
65 listener.blockForComplete(); 76 listener.blockForComplete();
66 assertEquals(200, listener.mHttpStatusCode); 77 assertEquals(200, listener.mHttpStatusCode);
67 assertEquals( 78 assertEquals(
68 "This is a simple text file served by QUIC.\n", 79 "This is a simple text file served by QUIC.\n",
69 listener.mResponseAsString); 80 listener.mResponseAsString);
70 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol); 81 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol);
71 } 82 }
72 83
73 @LargeTest 84 @LargeTest
74 @Feature({"Cronet"}) 85 @Feature({"Cronet"})
75 public void testQuicLoadUrl() throws Exception { 86 public void testQuicLoadUrl() throws Exception {
87 long urlRequestContextAdapter =
88 ((CronetUrlRequestContext) mActivity.mCronetEngine).getUrlReques tContextAdapter();
89 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, fals e);
90
76 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 91 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
77 TestUrlRequestListener listener = new TestUrlRequestListener(); 92 TestUrlRequestListener listener = new TestUrlRequestListener();
78 93
79 // Although the native stack races QUIC and SPDY for the first request, 94 // Although the native stack races QUIC and SPDY for the first request,
80 // since there is no http server running on the corresponding TCP port, 95 // since there is no http server running on the corresponding TCP port,
81 // QUIC will always succeed with a 200 (see 96 // QUIC will always succeed with a 200 (see
82 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 97 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
83 UrlRequest.Builder requestBuilder = new UrlRequest.Builder( 98 UrlRequest.Builder requestBuilder = new UrlRequest.Builder(
84 quicURL, listener, listener.getExecutor(), mActivity.mCronetEngi ne); 99 quicURL, listener, listener.getExecutor(), mActivity.mCronetEngi ne);
85 requestBuilder.build().start(); 100 requestBuilder.build().start();
(...skipping 24 matching lines...) Expand all
110 assertTrue(fileContainsString("local_prefs.json", 125 assertTrue(fileContainsString("local_prefs.json",
111 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort())); 126 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort()));
112 mActivity.mCronetEngine.shutdown(); 127 mActivity.mCronetEngine.shutdown();
113 128
114 // Make another request using a new context but with no QUIC hints. 129 // Make another request using a new context but with no QUIC hints.
115 CronetEngine.Builder builder = 130 CronetEngine.Builder builder =
116 new CronetEngine.Builder(getInstrumentation().getTargetContext() ); 131 new CronetEngine.Builder(getInstrumentation().getTargetContext() );
117 builder.setStoragePath(mActivity.getTestStorage()); 132 builder.setStoragePath(mActivity.getTestStorage());
118 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4); 133 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4);
119 builder.enableQUIC(true); 134 builder.enableQUIC(true);
135 MockCertVerifier newCertVerifier = new MockCertVerifier(CERTS_USED);
136 builder.setMockCertVerifierForTesting(newCertVerifier.getNativePointer() );
120 CronetEngine newEngine = new CronetUrlRequestContext(builder); 137 CronetEngine newEngine = new CronetUrlRequestContext(builder);
138 long newUrlRequestContextAdapter =
139 ((CronetUrlRequestContext) newEngine).getUrlRequestContextAdapte r();
140 NativeTestServer.registerHostResolverProc(newUrlRequestContextAdapter, f alse);
121 TestUrlRequestListener listener2 = new TestUrlRequestListener(); 141 TestUrlRequestListener listener2 = new TestUrlRequestListener();
122 requestBuilder = 142 requestBuilder =
123 new UrlRequest.Builder(quicURL, listener2, listener2.getExecutor (), newEngine); 143 new UrlRequest.Builder(quicURL, listener2, listener2.getExecutor (), newEngine);
124 requestBuilder.build().start(); 144 requestBuilder.build().start();
125 listener2.blockForDone(); 145 listener2.blockForDone();
126 assertEquals(200, listener2.mResponseInfo.getHttpStatusCode()); 146 assertEquals(200, listener2.mResponseInfo.getHttpStatusCode());
127 assertEquals(expectedContent, listener2.mResponseAsString); 147 assertEquals(expectedContent, listener2.mResponseAsString);
128 assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProto col()); 148 assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProto col());
129 // The total received bytes should be larger than the content length, to account for 149 // The total received bytes should be larger than the content length, to account for
130 // headers. 150 // headers.
131 assertTrue( 151 assertTrue(
132 listener2.mExtendedResponseInfo.getTotalReceivedBytes() > expect edContent.length()); 152 listener2.mExtendedResponseInfo.getTotalReceivedBytes() > expect edContent.length());
133 } 153 }
134 154
135 // Returns whether a file contains a particular string. 155 // Returns whether a file contains a particular string.
136 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") 156 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
137 private boolean fileContainsString(String filename, String content) throws I OException { 157 private boolean fileContainsString(String filename, String content) throws I OException {
138 File file = new File(mActivity.getTestStorage() + "/" + filename); 158 File file = new File(mActivity.getTestStorage() + "/" + filename);
139 FileInputStream fileInputStream = new FileInputStream(file); 159 FileInputStream fileInputStream = new FileInputStream(file);
140 byte[] data = new byte[(int) file.length()]; 160 byte[] data = new byte[(int) file.length()];
141 fileInputStream.read(data); 161 fileInputStream.read(data);
142 fileInputStream.close(); 162 fileInputStream.close();
143 return new String(data, "UTF-8").contains(content); 163 return new String(data, "UTF-8").contains(content);
144 } 164 }
145 } 165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698