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

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

Issue 1472693003: [Cronet] Clear mock cert verifier reference in CronetEngine.Builder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Misha's comments Created 5 years 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 import org.json.JSONObject; 13 import org.json.JSONObject;
14 14
15 import java.io.File; 15 import java.io.File;
16 import java.io.FileInputStream; 16 import java.io.FileInputStream;
17 import java.io.FileNotFoundException; 17 import java.io.FileNotFoundException;
18 import java.io.IOException; 18 import java.io.IOException;
19 import java.util.HashMap; 19 import java.util.HashMap;
20 20
21 /** 21 /**
22 * Tests making requests using QUIC. 22 * Tests making requests using QUIC.
23 */ 23 */
24 public class QuicTest extends CronetTestBase { 24 public class QuicTest extends CronetTestBase {
25 private static final String TAG = "cr.QuicTest"; 25 private static final String TAG = "cr.QuicTest";
26 private static final String[] CERTS_USED = {"quic_test.example.com.crt"}; 26 private static final String[] CERTS_USED = {"quic_test.example.com.crt"};
27 private CronetTestFramework mTestFramework; 27 private CronetTestFramework mTestFramework;
28 private CronetEngine.Builder mBuilder;
28 29
29 @Override 30 @Override
30 protected void setUp() throws Exception { 31 protected void setUp() throws Exception {
31 super.setUp(); 32 super.setUp();
32 // Load library first, since we need the Quic test server's URL. 33 // Load library first, since we need the Quic test server's URL.
33 System.loadLibrary("cronet_tests"); 34 System.loadLibrary("cronet_tests");
34 QuicTestServer.startQuicTestServer(getContext()); 35 QuicTestServer.startQuicTestServer(getContext());
35 36
36 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); 37 mBuilder = new CronetEngine.Builder(getContext());
37 builder.enableQUIC(true); 38 mBuilder.enableQUIC(true);
38 builder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getSe rverPort(), 39 mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getS erverPort(),
39 QuicTestServer.getServerPort()); 40 QuicTestServer.getServerPort());
40 41
41 JSONObject quicParams = new JSONObject() 42 JSONObject quicParams = new JSONObject()
42 .put("connection_options", "PACE,IW10,FO O,DEADBEEF") 43 .put("connection_options", "PACE,IW10,FO O,DEADBEEF")
43 .put("store_server_configs_in_properties ", true) 44 .put("store_server_configs_in_properties ", true)
44 .put("delay_tcp_race", true) 45 .put("delay_tcp_race", true)
45 .put("max_number_of_lossy_connections", 10) 46 .put("max_number_of_lossy_connections", 10)
46 .put("packet_loss_threshold", 0.5); 47 .put("packet_loss_threshold", 0.5);
47 JSONObject experimentalOptions = new JSONObject().put("QUIC", quicParams ); 48 JSONObject experimentalOptions = new JSONObject().put("QUIC", quicParams );
48 builder.setExperimentalOptions(experimentalOptions.toString()); 49 mBuilder.setExperimentalOptions(experimentalOptions.toString());
49 50
50 builder.setMockCertVerifierForTesting(MockCertVerifier.createMockCertVer ifier(CERTS_USED)); 51 mBuilder.setMockCertVerifierForTesting(MockCertVerifier.createMockCertVe rifier(CERTS_USED));
51 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ; 52 mBuilder.setStoragePath(CronetTestFramework.getTestStorage(getContext()) );
52 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 10 00 * 1024); 53 mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1 000 * 1024);
53
54 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, builder);
55 } 54 }
56 55
57 @Override 56 @Override
58 protected void tearDown() throws Exception { 57 protected void tearDown() throws Exception {
59 QuicTestServer.shutdownQuicTestServer(); 58 QuicTestServer.shutdownQuicTestServer();
60 super.tearDown(); 59 super.tearDown();
61 } 60 }
62 61
63 @SmallTest 62 @SmallTest
64 @Feature({"Cronet"}) 63 @Feature({"Cronet"})
65 @SuppressWarnings("deprecation") 64 @SuppressWarnings("deprecation")
66 public void testQuicLoadUrl_LegacyAPI() throws Exception { 65 public void testQuicLoadUrl_LegacyAPI() throws Exception {
66 String[] commandLineArgs = {
67 CronetTestFramework.LIBRARY_INIT_KEY, CronetTestFramework.Librar yInitType.LEGACY};
68 mTestFramework = new CronetTestFramework(null, commandLineArgs, getConte xt(), mBuilder);
69
67 long urlRequestContextAdapter = ((ChromiumUrlRequestFactory) mTestFramew ork.mRequestFactory) 70 long urlRequestContextAdapter = ((ChromiumUrlRequestFactory) mTestFramew ork.mRequestFactory)
68 .getRequestContext() 71 .getRequestContext()
69 .getUrlRequestContextAdapter(); 72 .getUrlRequestContextAdapter();
70 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, true ); 73 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, true );
71 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 74 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
72 75
73 HashMap<String, String> headers = new HashMap<String, String>(); 76 HashMap<String, String> headers = new HashMap<String, String>();
74 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener(); 77 TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
75 78
76 // Although the native stack races QUIC and SPDY for the first request, 79 // Although the native stack races QUIC and SPDY for the first request,
77 // since there is no http server running on the corresponding TCP port, 80 // since there is no http server running on the corresponding TCP port,
78 // QUIC will always succeed with a 200 (see 81 // QUIC will always succeed with a 200 (see
79 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 82 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
80 HttpUrlRequest request = mTestFramework.mRequestFactory.createRequest( 83 HttpUrlRequest request = mTestFramework.mRequestFactory.createRequest(
81 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er); 84 quicURL, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listen er);
82 request.start(); 85 request.start();
83 listener.blockForComplete(); 86 listener.blockForComplete();
84 assertEquals(200, listener.mHttpStatusCode); 87 assertEquals(200, listener.mHttpStatusCode);
85 assertEquals( 88 assertEquals(
86 "This is a simple text file served by QUIC.\n", 89 "This is a simple text file served by QUIC.\n",
87 listener.mResponseAsString); 90 listener.mResponseAsString);
88 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol); 91 assertEquals("quic/1+spdy/3", listener.mNegotiatedProtocol);
89 } 92 }
90 93
91 @LargeTest 94 @LargeTest
92 @Feature({"Cronet"}) 95 @Feature({"Cronet"})
93 public void testQuicLoadUrl() throws Exception { 96 public void testQuicLoadUrl() throws Exception {
97 String[] commandLineArgs = {
98 CronetTestFramework.LIBRARY_INIT_KEY, CronetTestFramework.Librar yInitType.CRONET};
99 mTestFramework = new CronetTestFramework(null, commandLineArgs, getConte xt(), mBuilder);
100
94 long urlRequestContextAdapter = ((CronetUrlRequestContext) mTestFramewor k.mCronetEngine) 101 long urlRequestContextAdapter = ((CronetUrlRequestContext) mTestFramewor k.mCronetEngine)
95 .getUrlRequestContextAdapter(); 102 .getUrlRequestContextAdapter();
96 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, fals e); 103 NativeTestServer.registerHostResolverProc(urlRequestContextAdapter, fals e);
97 104
98 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 105 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
99 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 106 TestUrlRequestCallback callback = new TestUrlRequestCallback();
100 107
101 // Although the native stack races QUIC and SPDY for the first request, 108 // Although the native stack races QUIC and SPDY for the first request,
102 // since there is no http server running on the corresponding TCP port, 109 // since there is no http server running on the corresponding TCP port,
103 // QUIC will always succeed with a 200 (see 110 // QUIC will always succeed with a 200 (see
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") 166 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
160 private boolean fileContainsString(String filename, String content) throws I OException { 167 private boolean fileContainsString(String filename, String content) throws I OException {
161 File file = new File(CronetTestFramework.getTestStorage(getContext()) + "/" + filename); 168 File file = new File(CronetTestFramework.getTestStorage(getContext()) + "/" + filename);
162 FileInputStream fileInputStream = new FileInputStream(file); 169 FileInputStream fileInputStream = new FileInputStream(file);
163 byte[] data = new byte[(int) file.length()]; 170 byte[] data = new byte[(int) file.length()];
164 fileInputStream.read(data); 171 fileInputStream.read(data);
165 fileInputStream.close(); 172 fileInputStream.close();
166 return new String(data, "UTF-8").contains(content); 173 return new String(data, "UTF-8").contains(content);
167 } 174 }
168 } 175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698