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

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

Issue 2892013002: [Cronet] Clean up tests (Closed)
Patch Set: fix Created 3 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
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.support.test.filters.LargeTest; 7 import android.support.test.filters.LargeTest;
8 import android.support.test.filters.SmallTest; 8 import android.support.test.filters.SmallTest;
9 9
10 import org.json.JSONObject; 10 import org.json.JSONObject;
(...skipping 10 matching lines...) Expand all
21 import java.io.IOException; 21 import java.io.IOException;
22 import java.util.Date; 22 import java.util.Date;
23 import java.util.concurrent.Executors; 23 import java.util.concurrent.Executors;
24 24
25 /** 25 /**
26 * Tests making requests using QUIC. 26 * Tests making requests using QUIC.
27 */ 27 */
28 public class QuicTest extends CronetTestBase { 28 public class QuicTest extends CronetTestBase {
29 private static final String TAG = QuicTest.class.getSimpleName(); 29 private static final String TAG = QuicTest.class.getSimpleName();
30 private static final String QUIC_PROTOCOL_STRING_PREFIX = "http/2+quic/"; 30 private static final String QUIC_PROTOCOL_STRING_PREFIX = "http/2+quic/";
31 private CronetTestFramework mTestFramework;
32 private ExperimentalCronetEngine.Builder mBuilder; 31 private ExperimentalCronetEngine.Builder mBuilder;
33 32
34 @Override 33 @Override
35 protected void setUp() throws Exception { 34 protected void setUp() throws Exception {
36 super.setUp(); 35 super.setUp();
37 // Load library first, since we need the Quic test server's URL. 36 // Load library first, since we need the Quic test server's URL.
38 System.loadLibrary("cronet_tests"); 37 System.loadLibrary("cronet_tests");
39 QuicTestServer.startQuicTestServer(getContext()); 38 QuicTestServer.startQuicTestServer(getContext());
40 39
41 mBuilder = new ExperimentalCronetEngine.Builder(getContext()); 40 mBuilder = new ExperimentalCronetEngine.Builder(getContext());
(...skipping 24 matching lines...) Expand all
66 @Override 65 @Override
67 protected void tearDown() throws Exception { 66 protected void tearDown() throws Exception {
68 QuicTestServer.shutdownQuicTestServer(); 67 QuicTestServer.shutdownQuicTestServer();
69 super.tearDown(); 68 super.tearDown();
70 } 69 }
71 70
72 @LargeTest 71 @LargeTest
73 @Feature({"Cronet"}) 72 @Feature({"Cronet"})
74 @OnlyRunNativeCronet 73 @OnlyRunNativeCronet
75 public void testQuicLoadUrl() throws Exception { 74 public void testQuicLoadUrl() throws Exception {
76 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder); 75 ExperimentalCronetEngine cronetEngine = mBuilder.build();
77 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 76 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
78 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 77 TestUrlRequestCallback callback = new TestUrlRequestCallback();
79 78
80 // 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,
81 // 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,
82 // QUIC will always succeed with a 200 (see 81 // QUIC will always succeed with a 200 (see
83 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 82 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
84 UrlRequest.Builder requestBuilder = mTestFramework.mCronetEngine.newUrlR equestBuilder( 83 UrlRequest.Builder requestBuilder =
85 quicURL, callback, callback.getExecutor()); 84 cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.ge tExecutor());
86 requestBuilder.build().start(); 85 requestBuilder.build().start();
87 callback.blockForDone(); 86 callback.blockForDone();
88 87
89 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 88 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
90 String expectedContent = "This is a simple text file served by QUIC.\n"; 89 String expectedContent = "This is a simple text file served by QUIC.\n";
91 assertEquals(expectedContent, callback.mResponseAsString); 90 assertEquals(expectedContent, callback.mResponseAsString);
92 assertIsQuic(callback.mResponseInfo); 91 assertIsQuic(callback.mResponseInfo);
93 // The total received bytes should be larger than the content length, to account for 92 // The total received bytes should be larger than the content length, to account for
94 // headers. 93 // headers.
95 assertTrue(callback.mResponseInfo.getReceivedByteCount() > expectedConte nt.length()); 94 assertTrue(callback.mResponseInfo.getReceivedByteCount() > expectedConte nt.length());
96 // This test takes a long time, since the update will only be scheduled 95 // This test takes a long time, since the update will only be scheduled
97 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc. 96 // after kUpdatePrefsDelayMs in http_server_properties_manager.cc.
98 while (true) { 97 while (true) {
99 Log.i(TAG, "Still waiting for pref file update....."); 98 Log.i(TAG, "Still waiting for pref file update.....");
100 Thread.sleep(10000); 99 Thread.sleep(10000);
101 boolean contains = false; 100 boolean contains = false;
102 try { 101 try {
103 if (fileContainsString("local_prefs.json", "quic")) break; 102 if (fileContainsString("local_prefs.json", "quic")) break;
104 } catch (FileNotFoundException e) { 103 } catch (FileNotFoundException e) {
105 // Ignored this exception since the file will only be created wh en updates are 104 // Ignored this exception since the file will only be created wh en updates are
106 // flushed to the disk. 105 // flushed to the disk.
107 } 106 }
108 } 107 }
109 assertTrue(fileContainsString("local_prefs.json", 108 assertTrue(fileContainsString("local_prefs.json",
110 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort())); 109 QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerP ort()));
111 mTestFramework.mCronetEngine.shutdown(); 110 cronetEngine.shutdown();
112 111
113 // Make another request using a new context but with no QUIC hints. 112 // Make another request using a new context but with no QUIC hints.
114 ExperimentalCronetEngine.Builder builder = 113 ExperimentalCronetEngine.Builder builder =
115 new ExperimentalCronetEngine.Builder(getContext()); 114 new ExperimentalCronetEngine.Builder(getContext());
116 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ; 115 builder.setStoragePath(CronetTestFramework.getTestStorage(getContext())) ;
117 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4); 116 builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 102 4);
118 builder.enableQuic(true); 117 builder.enableQuic(true);
119 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules (); 118 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules ();
120 JSONObject experimentalOptions = new JSONObject() 119 JSONObject experimentalOptions = new JSONObject()
121 .put("HostResolverRules", hostR esolverParams); 120 .put("HostResolverRules", hostR esolverParams);
122 builder.setExperimentalOptions(experimentalOptions.toString()); 121 builder.setExperimentalOptions(experimentalOptions.toString());
123 CronetTestUtil.setMockCertVerifierForTesting( 122 CronetTestUtil.setMockCertVerifierForTesting(
124 builder, QuicTestServer.createMockCertVerifier()); 123 builder, QuicTestServer.createMockCertVerifier());
125 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, builder); 124 cronetEngine = builder.build();
126 TestUrlRequestCallback callback2 = new TestUrlRequestCallback(); 125 TestUrlRequestCallback callback2 = new TestUrlRequestCallback();
127 requestBuilder = mTestFramework.mCronetEngine.newUrlRequestBuilder( 126 requestBuilder =
128 quicURL, callback2, callback2.getExecutor()); 127 cronetEngine.newUrlRequestBuilder(quicURL, callback2, callback2. getExecutor());
129 requestBuilder.build().start(); 128 requestBuilder.build().start();
130 callback2.blockForDone(); 129 callback2.blockForDone();
131 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode()); 130 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode());
132 assertEquals(expectedContent, callback2.mResponseAsString); 131 assertEquals(expectedContent, callback2.mResponseAsString);
133 assertIsQuic(callback.mResponseInfo); 132 assertIsQuic(callback.mResponseInfo);
134 // 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
135 // headers. 134 // headers.
136 assertTrue(callback2.mResponseInfo.getReceivedByteCount() > expectedCont ent.length()); 135 assertTrue(callback2.mResponseInfo.getReceivedByteCount() > expectedCont ent.length());
137 } 136 }
138 137
(...skipping 10 matching lines...) Expand all
149 } 148 }
150 149
151 /** 150 /**
152 * Tests that the network quality listeners are propoerly notified when QUIC is enabled. 151 * Tests that the network quality listeners are propoerly notified when QUIC is enabled.
153 */ 152 */
154 @LargeTest 153 @LargeTest
155 @Feature({"Cronet"}) 154 @Feature({"Cronet"})
156 @OnlyRunNativeCronet 155 @OnlyRunNativeCronet
157 @SuppressWarnings("deprecation") 156 @SuppressWarnings("deprecation")
158 public void testNQEWithQuic() throws Exception { 157 public void testNQEWithQuic() throws Exception {
159 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder); 158 ExperimentalCronetEngine cronetEngine = mBuilder.build();
160 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 159 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
161 160
162 TestNetworkQualityRttListener rttListener = 161 TestNetworkQualityRttListener rttListener =
163 new TestNetworkQualityRttListener(Executors.newSingleThreadExecu tor()); 162 new TestNetworkQualityRttListener(Executors.newSingleThreadExecu tor());
164 TestNetworkQualityThroughputListener throughputListener = 163 TestNetworkQualityThroughputListener throughputListener =
165 new TestNetworkQualityThroughputListener(Executors.newSingleThre adExecutor()); 164 new TestNetworkQualityThroughputListener(Executors.newSingleThre adExecutor());
166 165
167 mTestFramework.mCronetEngine.addRttListener(rttListener); 166 cronetEngine.addRttListener(rttListener);
168 mTestFramework.mCronetEngine.addThroughputListener(throughputListener); 167 cronetEngine.addThroughputListener(throughputListener);
169 168
170 mTestFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting( true, true, true); 169 cronetEngine.configureNetworkQualityEstimatorForTesting(true, true, true );
171 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 170 TestUrlRequestCallback callback = new TestUrlRequestCallback();
172 171
173 // Although the native stack races QUIC and SPDY for the first request, 172 // Although the native stack races QUIC and SPDY for the first request,
174 // since there is no http server running on the corresponding TCP port, 173 // since there is no http server running on the corresponding TCP port,
175 // QUIC will always succeed with a 200 (see 174 // QUIC will always succeed with a 200 (see
176 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). 175 // net::HttpStreamFactoryImpl::Request::OnStreamFailed).
177 UrlRequest.Builder requestBuilder = mTestFramework.mCronetEngine.newUrlR equestBuilder( 176 UrlRequest.Builder requestBuilder =
178 quicURL, callback, callback.getExecutor()); 177 cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.ge tExecutor());
179 requestBuilder.build().start(); 178 requestBuilder.build().start();
180 callback.blockForDone(); 179 callback.blockForDone();
181 180
182 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 181 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
183 String expectedContent = "This is a simple text file served by QUIC.\n"; 182 String expectedContent = "This is a simple text file served by QUIC.\n";
184 assertEquals(expectedContent, callback.mResponseAsString); 183 assertEquals(expectedContent, callback.mResponseAsString);
185 assertIsQuic(callback.mResponseInfo); 184 assertIsQuic(callback.mResponseInfo);
186 185
187 // Throughput observation is posted to the network quality estimator on the network thread 186 // Throughput observation is posted to the network quality estimator on the network thread
188 // after the UrlRequest is completed. The observations are then eventual ly posted to 187 // after the UrlRequest is completed. The observations are then eventual ly posted to
189 // throughput listeners on the executor provided to network quality. 188 // throughput listeners on the executor provided to network quality.
190 throughputListener.waitUntilFirstThroughputObservationReceived(); 189 throughputListener.waitUntilFirstThroughputObservationReceived();
191 190
192 // Wait for RTT observation (at the URL request layer) to be posted. 191 // Wait for RTT observation (at the URL request layer) to be posted.
193 rttListener.waitUntilFirstUrlRequestRTTReceived(); 192 rttListener.waitUntilFirstUrlRequestRTTReceived();
194 193
195 assertTrue(throughputListener.throughputObservationCount() > 0); 194 assertTrue(throughputListener.throughputObservationCount() > 0);
196 195
197 // Check RTT observation count after throughput observation has been rec eived. This ensures 196 // Check RTT observation count after throughput observation has been rec eived. This ensures
198 // that executor has finished posting the RTT observation to the RTT lis teners. 197 // that executor has finished posting the RTT observation to the RTT lis teners.
199 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST 198 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST
200 assertTrue(rttListener.rttObservationCount(0) > 0); 199 assertTrue(rttListener.rttObservationCount(0) > 0);
201 200
202 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC 201 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC
203 assertTrue(rttListener.rttObservationCount(2) > 0); 202 assertTrue(rttListener.rttObservationCount(2) > 0);
204 203
205 // Verify that effective connection type callback is received and 204 // Verify that effective connection type callback is received and
206 // effective connection type is correctly set. 205 // effective connection type is correctly set.
207 assertTrue(mTestFramework.mCronetEngine.getEffectiveConnectionType() 206 assertTrue(
208 != EffectiveConnectionType.TYPE_UNKNOWN); 207 cronetEngine.getEffectiveConnectionType() != EffectiveConnection Type.TYPE_UNKNOWN);
209 208
210 // Verify that the HTTP RTT, transport RTT and downstream throughput 209 // Verify that the HTTP RTT, transport RTT and downstream throughput
211 // estimates are available. 210 // estimates are available.
212 assertTrue(mTestFramework.mCronetEngine.getHttpRttMs() >= 0); 211 assertTrue(cronetEngine.getHttpRttMs() >= 0);
213 assertTrue(mTestFramework.mCronetEngine.getTransportRttMs() >= 0); 212 assertTrue(cronetEngine.getTransportRttMs() >= 0);
214 assertTrue(mTestFramework.mCronetEngine.getDownstreamThroughputKbps() >= 0); 213 assertTrue(cronetEngine.getDownstreamThroughputKbps() >= 0);
215 214
216 // Verify that the cached estimates were written to the prefs. 215 // Verify that the cached estimates were written to the prefs.
217 while (true) { 216 while (true) {
218 Log.i(TAG, "Still waiting for pref file update....."); 217 Log.i(TAG, "Still waiting for pref file update.....");
219 Thread.sleep(10000); 218 Thread.sleep(10000);
220 try { 219 try {
221 if (fileContainsString("local_prefs.json", "network_qualities")) { 220 if (fileContainsString("local_prefs.json", "network_qualities")) {
222 break; 221 break;
223 } 222 }
224 } catch (FileNotFoundException e) { 223 } catch (FileNotFoundException e) {
225 // Ignored this exception since the file will only be created wh en updates are 224 // Ignored this exception since the file will only be created wh en updates are
226 // flushed to the disk. 225 // flushed to the disk.
227 } 226 }
228 } 227 }
229 assertTrue(fileContainsString("local_prefs.json", "network_qualities")); 228 assertTrue(fileContainsString("local_prefs.json", "network_qualities"));
230 mTestFramework.mCronetEngine.shutdown(); 229 cronetEngine.shutdown();
231 } 230 }
232 231
233 @SmallTest 232 @SmallTest
234 @OnlyRunNativeCronet 233 @OnlyRunNativeCronet
235 @Feature({"Cronet"}) 234 @Feature({"Cronet"})
236 public void testMetricsWithQuic() throws Exception { 235 public void testMetricsWithQuic() throws Exception {
237 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n ull, mBuilder); 236 ExperimentalCronetEngine cronetEngine = mBuilder.build();
238 TestRequestFinishedListener requestFinishedListener = new TestRequestFin ishedListener(); 237 TestRequestFinishedListener requestFinishedListener = new TestRequestFin ishedListener();
239 mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedL istener); 238 cronetEngine.addRequestFinishedListener(requestFinishedListener);
240 239
241 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; 240 String quicURL = QuicTestServer.getServerURL() + "/simple.txt";
242 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 241 TestUrlRequestCallback callback = new TestUrlRequestCallback();
243 242
244 UrlRequest.Builder requestBuilder = mTestFramework.mCronetEngine.newUrlR equestBuilder( 243 UrlRequest.Builder requestBuilder =
245 quicURL, callback, callback.getExecutor()); 244 cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.ge tExecutor());
246 Date startTime = new Date(); 245 Date startTime = new Date();
247 requestBuilder.build().start(); 246 requestBuilder.build().start();
248 callback.blockForDone(); 247 callback.blockForDone();
249 requestFinishedListener.blockUntilDone(); 248 requestFinishedListener.blockUntilDone();
250 Date endTime = new Date(); 249 Date endTime = new Date();
251 250
252 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 251 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
253 assertIsQuic(callback.mResponseInfo); 252 assertIsQuic(callback.mResponseInfo);
254 253
255 RequestFinishedInfo requestInfo = requestFinishedListener.getRequestInfo (); 254 RequestFinishedInfo requestInfo = requestFinishedListener.getRequestInfo ();
256 MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime , endTime); 255 MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime , endTime);
257 assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReaso n()); 256 assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReaso n());
258 MetricsTestUtil.checkHasConnectTiming(requestInfo.getMetrics(), startTim e, endTime, true); 257 MetricsTestUtil.checkHasConnectTiming(requestInfo.getMetrics(), startTim e, endTime, true);
259 258
260 // Second request should use the same connection and not have ConnectTim ing numbers 259 // Second request should use the same connection and not have ConnectTim ing numbers
261 callback = new TestUrlRequestCallback(); 260 callback = new TestUrlRequestCallback();
262 requestFinishedListener.reset(); 261 requestFinishedListener.reset();
263 requestBuilder = mTestFramework.mCronetEngine.newUrlRequestBuilder( 262 requestBuilder =
264 quicURL, callback, callback.getExecutor()); 263 cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.ge tExecutor());
265 startTime = new Date(); 264 startTime = new Date();
266 requestBuilder.build().start(); 265 requestBuilder.build().start();
267 callback.blockForDone(); 266 callback.blockForDone();
268 requestFinishedListener.blockUntilDone(); 267 requestFinishedListener.blockUntilDone();
269 endTime = new Date(); 268 endTime = new Date();
270 269
271 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 270 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
272 assertIsQuic(callback.mResponseInfo); 271 assertIsQuic(callback.mResponseInfo);
273 272
274 requestInfo = requestFinishedListener.getRequestInfo(); 273 requestInfo = requestFinishedListener.getRequestInfo();
275 MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime , endTime); 274 MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime , endTime);
276 assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReaso n()); 275 assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReaso n());
277 MetricsTestUtil.checkNoConnectTiming(requestInfo.getMetrics()); 276 MetricsTestUtil.checkNoConnectTiming(requestInfo.getMetrics());
278 277
279 mTestFramework.mCronetEngine.shutdown(); 278 cronetEngine.shutdown();
280 } 279 }
281 280
282 // Helper method to assert that the request is negotiated over QUIC. 281 // Helper method to assert that the request is negotiated over QUIC.
283 private void assertIsQuic(UrlResponseInfo responseInfo) { 282 private void assertIsQuic(UrlResponseInfo responseInfo) {
284 assertTrue(responseInfo.getNegotiatedProtocol().startsWith(QUIC_PROTOCOL _STRING_PREFIX)); 283 assertTrue(responseInfo.getNegotiatedProtocol().startsWith(QUIC_PROTOCOL _STRING_PREFIX));
285 } 284 }
286 } 285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698