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

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 Misha'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
33 CronetEngine.Builder builder = new CronetEngine.Builder(mActivity); 35 CronetEngine.Builder builder = new CronetEngine.Builder(mActivity);
34 builder.enableQUIC(true); 36 builder.enableQUIC(true);
35 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe rverPort(), 37 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe rverPort(),
36 QuicTestServer.getServerPort()); 38 QuicTestServer.getServerPort());
37 builder.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF"); 39 builder.setExperimentalQuicConnectionOptions("PACE,IW10,FOO,DEADBEEF");
40 builder.setMockCertVerifierForTesting(MockCertVerifier.createMockCertVer ifier(CERTS_USED));
38 41
39 String[] commandLineArgs = {CronetTestActivity.CONFIG_KEY, builder.toStr ing(), 42 String[] commandLineArgs = {CronetTestActivity.CONFIG_KEY, builder.toStr ing(),
40 CronetTestActivity.CACHE_KEY, CronetTestActivity.CACHE_DISK_NO_H TTP}; 43 CronetTestActivity.CACHE_KEY, CronetTestActivity.CACHE_DISK_NO_H TTP};
41 mActivity = launchCronetTestAppWithUrlAndCommandLineArgs(null, commandLi neArgs); 44 mActivity = launchCronetTestAppWithUrlAndCommandLineArgs(null, commandLi neArgs);
42 } 45 }
43 46
44 @Override 47 @Override
45 protected void tearDown() throws Exception { 48 protected void tearDown() throws Exception {
46 QuicTestServer.shutdownQuicTestServer(); 49 QuicTestServer.shutdownQuicTestServer();
47 super.tearDown(); 50 super.tearDown();
48 } 51 }
49 52
50 @SmallTest 53 @SmallTest
51 @Feature({"Cronet"}) 54 @Feature({"Cronet"})
52 public void testQuicLoadUrl_LegacyAPI() throws Exception { 55 public void testQuicLoadUrl_LegacyAPI() throws Exception {
56 long urlRequestContextAdapter = ((ChromiumUrlRequestFactory) mActivity.m RequestFactory)
57 .getRequestContext()
58 .getUrlRequestContextAdapter();
59 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, true );
53 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 60 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
54 61
55 HashMap<String, String> headers = new HashMap<String, String>(); 62 HashMap<String, String> headers = new HashMap<String, String>();
56 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); 63 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
57 64
58 // Although the native stack races QUIC and SPDY for the first request, 65 // 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, 66 // since there is no http server running on the corresponding TCP port,
60 // QUIC will always succeed with a 200 (see 67 // QUIC will always succeed with a 200 (see
61 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 68 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
62 HttpUrlRequest request = mActivity.mRequestFactory.createRequest( 69 HttpUrlRequest request = mActivity.mRequestFactory.createRequest(
63 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er); 70 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er);
64 request.start(); 71 request.start();
65 listener.blockForComplete(); 72 listener.blockForComplete();
66 assertEquals(200, listener.mHttpStatusCode); 73 assertEquals(200, listener.mHttpStatusCode);
67 assertEquals( 74 assertEquals(
68 "This is a simple text file served by QUIC.\n", 75 "This is a simple text file served by QUIC.\n",
69 listener.mResponseAsString); 76 listener.mResponseAsString);
70 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol); 77 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol);
71 } 78 }
72 79
73 @LargeTest 80 @LargeTest
74 @Feature({"Cronet"}) 81 @Feature({"Cronet"})
75 public void testQuicLoadUrl() throws Exception { 82 public void testQuicLoadUrl() throws Exception {
83 long urlRequestContextAdapter =
84 ((CronetUrlRequestContext) mActivity.mCronetEngine).getUrlReques tContextAdapter();
85 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, fals e);
86
76 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 87 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
77 TestUrlRequestListener listener = new TestUrlRequestListener(); 88 TestUrlRequestListener listener = new TestUrlRequestListener();
78 89
79 // Although the native stack races QUIC and SPDY for the first request, 90 // 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, 91 // since there is no http server running on the corresponding TCP port,
81 // QUIC will always succeed with a 200 (see 92 // QUIC will always succeed with a 200 (see
82 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 93 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
83 UrlRequest.Builder requestBuilder = new UrlRequest.Builder( 94 UrlRequest.Builder requestBuilder = new UrlRequest.Builder(
84 quicURL, listener, listener.getExecutor(), mActivity.mCronetEngi ne); 95 quicURL, listener, listener.getExecutor(), mActivity.mCronetEngi ne);
85 requestBuilder.build().start(); 96 requestBuilder.build().start();
(...skipping 23 matching lines...) Expand all
109 assertTrue(fileContainsString("local_prefs.json", 120 assertTrue(fileContainsString("local_prefs.json",
110 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort())); 121 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort()));
111 mActivity.mCronetEngine.shutdown(); 122 mActivity.mCronetEngine.shutdown();
112 123
113 // Make another request using a new context but with no QUIC hints. 124 // Make another request using a new context but with no QUIC hints.
114 CronetEngine.Builder builder = 125 CronetEngine.Builder builder =
115 new CronetEngine.Builder(getInstrumentation().getTargetContext() ); 126 new CronetEngine.Builder(getInstrumentation().getTargetContext() );
116 builder.setStoragePath(mActivity.getTestStorage()); 127 builder.setStoragePath(mActivity.getTestStorage());
117 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4); 128 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4);
118 builder.enableQUIC(true); 129 builder.enableQUIC(true);
130 builder.setMockCertVerifierForTesting(MockCertVerifier.createMockCertVer ifier(CERTS_USED));
119 CronetEngine newEngine = new CronetUrlRequestContext(builder); 131 CronetEngine newEngine = new CronetUrlRequestContext(builder);
132 long newUrlRequestContextAdapter =
133 ((CronetUrlRequestContext) newEngine).getUrlRequestContextAdapte r();
134 NativeTestServer.registerHostResolverProc(newUrlRequestContextAdapter, f alse);
120 TestUrlRequestListener listener2 = new TestUrlRequestListener(); 135 TestUrlRequestListener listener2 = new TestUrlRequestListener();
121 requestBuilder = 136 requestBuilder =
122 new UrlRequest.Builder(quicURL, listener2, listener2.getExecutor (), newEngine); 137 new UrlRequest.Builder(quicURL, listener2, listener2.getExecutor (), newEngine);
123 requestBuilder.build().start(); 138 requestBuilder.build().start();
124 listener2.blockForDone(); 139 listener2.blockForDone();
125 assertEquals(200, listener2.mResponseInfo.getHttpStatusCode()); 140 assertEquals(200, listener2.mResponseInfo.getHttpStatusCode());
126 assertEquals(expectedContent, listener2.mResponseAsString); 141 assertEquals(expectedContent, listener2.mResponseAsString);
127 assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProto col()); 142 assertEquals("quic/1+spdy/3", listener2.mResponseInfo.getNegotiatedProto col());
128 // The total received bytes should be larger than the content length, to account for 143 // The total received bytes should be larger than the content length, to account for
129 // headers. 144 // headers.
130 assertTrue(listener2.mResponseInfo.getReceivedBytesCount() > expectedCon tent.length()); 145 assertTrue(listener2.mResponseInfo.getReceivedBytesCount() > expectedCon tent.length());
131 } 146 }
132 147
133 // Returns whether a file contains a particular string. 148 // Returns whether a file contains a particular string.
134 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") 149 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
135 private boolean fileContainsString(String filename, String content) throws I OException { 150 private boolean fileContainsString(String filename, String content) throws I OException {
136 File file = new File(mActivity.getTestStorage() + "/" + filename); 151 File file = new File(mActivity.getTestStorage() + "/" + filename);
137 FileInputStream fileInputStream = new FileInputStream(file); 152 FileInputStream fileInputStream = new FileInputStream(file);
138 byte[] data = new byte[(int) file.length()]; 153 byte[] data = new byte[(int) file.length()];
139 fileInputStream.read(data); 154 fileInputStream.read(data);
140 fileInputStream.close(); 155 fileInputStream.close();
141 return new String(data, "UTF-8").contains(content); 156 return new String(data, "UTF-8").contains(content);
142 } 157 }
143 } 158 }
OLDNEW
« no previous file with comments | « components/cronet/android/test/cronet_test_jni.cc ('k') | components/cronet/android/test/mock_cert_verifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698