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

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

Issue 2339223002: Cronet API Refactoring (Closed)
Patch Set: Addressed Paul's comments + rebase Created 4 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.os.ConditionVariable; 7 import android.os.ConditionVariable;
8 import android.test.suitebuilder.annotation.LargeTest; 8 import android.test.suitebuilder.annotation.LargeTest;
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.chromium.net.CronetTestBase.OnlyRunNativeCronet;
14 import org.json.JSONObject; 13 import org.json.JSONObject;
15 14
16 import java.io.File; 15 import java.io.File;
17 import java.io.FileInputStream; 16 import java.io.FileInputStream;
18 import java.io.FileNotFoundException; 17 import java.io.FileNotFoundException;
19 import java.io.IOException; 18 import java.io.IOException;
20 import java.util.concurrent.Executors; 19 import java.util.concurrent.Executors;
21 20
22 /** 21 /**
23 * Tests making requests using QUIC. 22 * Tests making requests using QUIC.
24 */ 23 */
25 public class QuicTest extends CronetTestBase { 24 public class QuicTest extends CronetTestBase {
26 private static final String TAG = "cr.QuicTest"; 25 private static final String TAG = "cr.QuicTest";
27 private CronetTestFramework mTestFramework; 26 private CronetTestFramework mTestFramework;
28 private CronetEngine.Builder mBuilder; 27 private ExperimentalCronetEngine.Builder mBuilder;
29 28
30 @Override 29 @Override
31 protected void setUp() throws Exception { 30 protected void setUp() throws Exception {
32 super.setUp(); 31 super.setUp();
33 // Load library first, since we need the Quic test server's URL. 32 // Load library first, since we need the Quic test server's URL.
34 System.loadLibrary("cronet_tests"); 33 System.loadLibrary("cronet_tests");
35 QuicTestServer.startQuicTestServer(getContext()); 34 QuicTestServer.startQuicTestServer(getContext());
36 35
37 mBuilder = new CronetEngine.Builder(getContext()); 36 mBuilder = new ExperimentalCronetEngine.Builder(getContext());
38 mBuilder.enableQuic(true).enableNetworkQualityEstimator(true); 37 mBuilder.enableNetworkQualityEstimator(true).enableQuic(true);
39 mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getS erverPort(), 38 mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getS erverPort(),
40 QuicTestServer.getServerPort()); 39 QuicTestServer.getServerPort());
41 40
42 // TODO(mgersh): Enable connection migration once it works, see http://c rbug.com/634910 41 // TODO(mgersh): Enable connection migration once it works, see http://c rbug.com/634910
43 JSONObject quicParams = new JSONObject() 42 JSONObject quicParams = new JSONObject()
44 .put("connection_options", "PACE,IW10,FO O,DEADBEEF") 43 .put("connection_options", "PACE,IW10,FO O,DEADBEEF")
45 .put("host_whitelist", "test.example.com ") 44 .put("host_whitelist", "test.example.com ")
46 .put("max_server_configs_stored_in_prope rties", 2) 45 .put("max_server_configs_stored_in_prope rties", 2)
47 .put("delay_tcp_race", true) 46 .put("delay_tcp_race", true)
48 .put("idle_connection_timeout_seconds", 300) 47 .put("idle_connection_timeout_seconds", 300)
49 .put("close_sessions_on_ip_change", fals e) 48 .put("close_sessions_on_ip_change", fals e)
50 .put("migrate_sessions_on_network_change ", false) 49 .put("migrate_sessions_on_network_change ", false)
51 .put("migrate_sessions_early", false) 50 .put("migrate_sessions_early", false)
52 .put("race_cert_verification", true); 51 .put("race_cert_verification", true);
53 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules (); 52 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules ();
54 JSONObject experimentalOptions = new JSONObject() 53 JSONObject experimentalOptions = new JSONObject()
55 .put("QUIC", quicParams) 54 .put("QUIC", quicParams)
56 .put("HostResolverRules", hostR esolverParams); 55 .put("HostResolverRules", hostR esolverParams);
57 mBuilder.setExperimentalOptions(experimentalOptions.toString()); 56 mBuilder.setExperimentalOptions(experimentalOptions.toString());
58 mBuilder.setMockCertVerifierForTesting(QuicTestServer.createMockCertVeri fier());
59 mBuilder.setStoragePath(CronetTestFramework.getTestStorage(getContext()) ); 57 mBuilder.setStoragePath(CronetTestFramework.getTestStorage(getContext()) );
60 mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1 000 * 1024); 58 mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1 000 * 1024);
59 CronetTestUtil.setMockCertVerifierForTesting(
60 mBuilder, QuicTestServer.createMockCertVerifier());
61 } 61 }
62 62
63 @Override 63 @Override
64 protected void tearDown() throws Exception { 64 protected void tearDown() throws Exception {
65 QuicTestServer.shutdownQuicTestServer(); 65 QuicTestServer.shutdownQuicTestServer();
66 super.tearDown(); 66 super.tearDown();
67 } 67 }
68 68
69 @LargeTest 69 @LargeTest
70 @Feature({"Cronet"}) 70 @Feature({"Cronet"})
71 @OnlyRunNativeCronet 71 @OnlyRunNativeCronet
72 public void testQuicLoadUrl() throws Exception { 72 public void testQuicLoadUrl() throws Exception {
73 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder); 73 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder);
74 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 74 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
75 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 75 TestUrlRequestCallback callback = new TestUrlRequestCallback();
76 76
77 // Although the native stack races QUIC and SPDY for the first request, 77 // Although the native stack races QUIC and SPDY for the first request,
78 // since there is no http server running on the corresponding TCP port, 78 // since there is no http server running on the corresponding TCP port,
79 // QUIC will always succeed with a 200 (see 79 // QUIC will always succeed with a 200 (see
80 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 80 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
81 UrlRequest.Builder requestBuilder = new UrlRequest.Builder( 81 UrlRequest.Builder requestBuilder = mTestFramework.mCronetEngine.newUrlR equestBuilder(
82 quicURL, callback, callback.getExecutor(), mTestFramework.mCrone tEngine); 82 quicURL, callback, callback.getExecutor());
83 requestBuilder.build().start(); 83 requestBuilder.build().start();
84 callback.blockForDone(); 84 callback.blockForDone();
85 85
86 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 86 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
87 String expectedContent = "This is a simple text file served by QUIC.\n"; 87 String expectedContent = "This is a simple text file served by QUIC.\n";
88 assertEquals(expectedContent, callback.mResponseAsString); 88 assertEquals(expectedContent, callback.mResponseAsString);
89 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc ol()); 89 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc ol());
90 // The total received bytes should be larger than the content length, to account for 90 // The total received bytes should be larger than the content length, to account for
91 // headers. 91 // headers.
92 assertTrue(callback.mResponseInfo.getReceivedBytesCount() > expectedCont ent.length()); 92 assertTrue(callback.mResponseInfo.getReceivedBytesCount() > expectedCont ent.length());
93 // This test takes a long time, since the update will only be scheduled 93 // This test takes a long time, since the update will only be scheduled
94 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc. 94 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc.
95 while (true) { 95 while (true) {
96 Log.i(TAG, "Still waiting for pref file update....."); 96 Log.i(TAG, "Still waiting for pref file update.....");
97 Thread.sleep(10000); 97 Thread.sleep(10000);
98 boolean contains = false; 98 boolean contains = false;
99 try { 99 try {
100 if (fileContainsString("local_prefs.json", "quic")) break; 100 if (fileContainsString("local_prefs.json", "quic")) break;
101 } catch (FileNotFoundException e) { 101 } catch (FileNotFoundException e) {
102 // Ignored this exception since the file will only be created wh en updates are 102 // Ignored this exception since the file will only be created wh en updates are
103 // flushed to the disk. 103 // flushed to the disk.
104 } 104 }
105 } 105 }
106 assertTrue(fileContainsString("local_prefs.json", 106 assertTrue(fileContainsString("local_prefs.json",
107 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort())); 107 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort()));
108 mTestFramework.mCronetEngine.shutdown(); 108 mTestFramework.mCronetEngine.shutdown();
109 109
110 // Make another request using a new context but with no QUIC hints. 110 // Make another request using a new context but with no QUIC hints.
111 CronetEngine.Builder builder = new CronetEngine.Builder(getContext()); 111 ExperimentalCronetEngine.Builder builder =
112 new ExperimentalCronetEngine.Builder(getContext());
112 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ; 113 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ;
113 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4); 114 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4);
114 builder.enableQuic(true); 115 builder.enableQuic(true);
115 JSONObject quicParams = new JSONObject().put("host_whitelist", "test.exa mple.com"); 116 JSONObject quicParams = new JSONObject().put("host_whitelist", "test.exa mple.com");
116 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules (); 117 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules ();
117 JSONObject experimentalOptions = new JSONObject() 118 JSONObject experimentalOptions = new JSONObject()
118 .put("QUIC", quicParams) 119 .put("QUIC", quicParams)
119 .put("HostResolverRules", hostR esolverParams); 120 .put("HostResolverRules", hostR esolverParams);
120 builder.setExperimentalOptions(experimentalOptions.toString()); 121 builder.setExperimentalOptions(experimentalOptions.toString());
121 builder.setMockCertVerifierForTesting(QuicTestServer.createMockCertVerif ier()); 122 CronetTestUtil.setMockCertVerifierForTesting(
123 builder, QuicTestServer.createMockCertVerifier());
122 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, builder); 124 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, builder);
123 TestUrlRequestCallback callback2 = new TestUrlRequestCallback(); 125 TestUrlRequestCallback callback2 = new TestUrlRequestCallback();
124 requestBuilder = new UrlRequest.Builder( 126 requestBuilder = mTestFramework.mCronetEngine.newUrlRequestBuilder(
125 quicURL, callback2, callback2.getExecutor(), mTestFramework.mCro netEngine); 127 quicURL, callback2, callback2.getExecutor());
126 requestBuilder.build().start(); 128 requestBuilder.build().start();
127 callback2.blockForDone(); 129 callback2.blockForDone();
128 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode()); 130 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode());
129 assertEquals(expectedContent, callback2.mResponseAsString); 131 assertEquals(expectedContent, callback2.mResponseAsString);
130 assertEquals("quic/1+spdy/3", callback2.mResponseInfo.getNegotiatedProto col()); 132 assertEquals("quic/1+spdy/3", callback2.mResponseInfo.getNegotiatedProto col());
131 // The total received bytes should be larger than the content length, to account for 133 // The total received bytes should be larger than the content length, to account for
132 // headers. 134 // headers.
133 assertTrue(callback2.mResponseInfo.getReceivedBytesCount() > expectedCon tent.length()); 135 assertTrue(callback2.mResponseInfo.getReceivedBytesCount() > expectedCon tent.length());
134 } 136 }
135 137
(...skipping 27 matching lines...) Expand all
163 mTestFramework.mCronetEngine.addRttListener(rttListener); 165 mTestFramework.mCronetEngine.addRttListener(rttListener);
164 mTestFramework.mCronetEngine.addThroughputListener(throughputListener); 166 mTestFramework.mCronetEngine.addThroughputListener(throughputListener);
165 167
166 mTestFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting( true, true); 168 mTestFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting( true, true);
167 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 169 TestUrlRequestCallback callback = new TestUrlRequestCallback();
168 170
169 // Although the native stack races QUIC and SPDY for the first request, 171 // Although the native stack races QUIC and SPDY for the first request,
170 // since there is no http server running on the corresponding TCP port, 172 // since there is no http server running on the corresponding TCP port,
171 // QUIC will always succeed with a 200 (see 173 // QUIC will always succeed with a 200 (see
172 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 174 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
173 UrlRequest.Builder requestBuilder = new UrlRequest.Builder( 175 UrlRequest.Builder requestBuilder = mTestFramework.mCronetEngine.newUrlR equestBuilder(
174 quicURL, callback, callback.getExecutor(), mTestFramework.mCrone tEngine); 176 quicURL, callback, callback.getExecutor());
175 requestBuilder.build().start(); 177 requestBuilder.build().start();
176 callback.blockForDone(); 178 callback.blockForDone();
177 179
178 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 180 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
179 String expectedContent = "This is a simple text file served by QUIC.\n"; 181 String expectedContent = "This is a simple text file served by QUIC.\n";
180 assertEquals(expectedContent, callback.mResponseAsString); 182 assertEquals(expectedContent, callback.mResponseAsString);
181 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc ol()); 183 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc ol());
182 184
183 // Throughput observation is posted to the network quality estimator on the network thread 185 // Throughput observation is posted to the network quality estimator on the network thread
184 // after the UrlRequest is completed. The observations are then eventual ly posted to 186 // after the UrlRequest is completed. The observations are then eventual ly posted to
(...skipping 10 matching lines...) Expand all
195 assertTrue(rttListener.rttObservationCount(2) > 0); 197 assertTrue(rttListener.rttObservationCount(2) > 0);
196 198
197 // Verify that effective connection type callback is received and 199 // Verify that effective connection type callback is received and
198 // effective connection type is correctly set. 200 // effective connection type is correctly set.
199 assertTrue(mTestFramework.mCronetEngine.getEffectiveConnectionType() 201 assertTrue(mTestFramework.mCronetEngine.getEffectiveConnectionType()
200 != EffectiveConnectionType.TYPE_UNKNOWN); 202 != EffectiveConnectionType.TYPE_UNKNOWN);
201 203
202 mTestFramework.mCronetEngine.shutdown(); 204 mTestFramework.mCronetEngine.shutdown();
203 } 205 }
204 } 206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698