OLD | NEW |
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 Loading... |
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()); |
42 mBuilder.enableNetworkQualityEstimator(true).enableQuic(true); | 41 mBuilder.enableNetworkQualityEstimator(true).enableQuic(true); |
43 mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getS
erverPort(), | 42 mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getS
erverPort(), |
44 QuicTestServer.getServerPort()); | 43 QuicTestServer.getServerPort()); |
45 | 44 |
46 // TODO(mgersh): Enable connection migration once it works, see http://c
rbug.com/634910 | 45 // TODO(mgersh): Enable connection migration once it works, see http://c
rbug.com/634910 |
47 JSONObject quicParams = new JSONObject() | 46 JSONObject quicParams = new JSONObject() |
48 .put("connection_options", "PACE,IW10,FO
O,DEADBEEF") | 47 .put("connection_options", "PACE,IW10,FO
O,DEADBEEF") |
49 .put("max_server_configs_stored_in_prope
rties", 2) | 48 .put("max_server_configs_stored_in_prope
rties", 2) |
50 .put("idle_connection_timeout_seconds",
300) | 49 .put("idle_connection_timeout_seconds",
300) |
51 .put("close_sessions_on_ip_change", fals
e) | 50 .put("close_sessions_on_ip_change", fals
e) |
52 .put("migrate_sessions_on_network_change
", false) | 51 .put("migrate_sessions_on_network_change
", false) |
53 .put("migrate_sessions_early", false) | 52 .put("migrate_sessions_early", false) |
54 .put("race_cert_verification", true); | 53 .put("race_cert_verification", true); |
55 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules
(); | 54 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules
(); |
56 JSONObject experimentalOptions = new JSONObject() | 55 JSONObject experimentalOptions = new JSONObject() |
57 .put("QUIC", quicParams) | 56 .put("QUIC", quicParams) |
58 .put("HostResolverRules", hostR
esolverParams); | 57 .put("HostResolverRules", hostR
esolverParams); |
59 mBuilder.setExperimentalOptions(experimentalOptions.toString()); | 58 mBuilder.setExperimentalOptions(experimentalOptions.toString()); |
60 mBuilder.setStoragePath(CronetTestFramework.getTestStorage(getContext())
); | 59 mBuilder.setStoragePath(getTestStorage(getContext())); |
61 mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1
000 * 1024); | 60 mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1
000 * 1024); |
62 CronetTestUtil.setMockCertVerifierForTesting( | 61 CronetTestUtil.setMockCertVerifierForTesting( |
63 mBuilder, QuicTestServer.createMockCertVerifier()); | 62 mBuilder, QuicTestServer.createMockCertVerifier()); |
64 } | 63 } |
65 | 64 |
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(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 |
139 // Returns whether a file contains a particular string. | 138 // Returns whether a file contains a particular string. |
140 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") | 139 @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") |
141 private boolean fileContainsString(String filename, String content) throws I
OException { | 140 private boolean fileContainsString(String filename, String content) throws I
OException { |
142 File file = | 141 File file = new File(getTestStorage(getContext()) + "/prefs/" + filename
); |
143 new File(CronetTestFramework.getTestStorage(getContext()) + "/pr
efs/" + filename); | |
144 FileInputStream fileInputStream = new FileInputStream(file); | 142 FileInputStream fileInputStream = new FileInputStream(file); |
145 byte[] data = new byte[(int) file.length()]; | 143 byte[] data = new byte[(int) file.length()]; |
146 fileInputStream.read(data); | 144 fileInputStream.read(data); |
147 fileInputStream.close(); | 145 fileInputStream.close(); |
148 return new String(data, "UTF-8").contains(content); | 146 return new String(data, "UTF-8").contains(content); |
149 } | 147 } |
150 | 148 |
151 /** | 149 /** |
152 * Tests that the network quality listeners are propoerly notified when QUIC
is enabled. | 150 * Tests that the network quality listeners are propoerly notified when QUIC
is enabled. |
153 */ | 151 */ |
154 @LargeTest | 152 @LargeTest |
155 @Feature({"Cronet"}) | 153 @Feature({"Cronet"}) |
156 @OnlyRunNativeCronet | 154 @OnlyRunNativeCronet |
157 @SuppressWarnings("deprecation") | 155 @SuppressWarnings("deprecation") |
158 public void testNQEWithQuic() throws Exception { | 156 public void testNQEWithQuic() throws Exception { |
159 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n
ull, mBuilder); | 157 ExperimentalCronetEngine cronetEngine = mBuilder.build(); |
160 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; | 158 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; |
161 | 159 |
162 TestNetworkQualityRttListener rttListener = | 160 TestNetworkQualityRttListener rttListener = |
163 new TestNetworkQualityRttListener(Executors.newSingleThreadExecu
tor()); | 161 new TestNetworkQualityRttListener(Executors.newSingleThreadExecu
tor()); |
164 TestNetworkQualityThroughputListener throughputListener = | 162 TestNetworkQualityThroughputListener throughputListener = |
165 new TestNetworkQualityThroughputListener(Executors.newSingleThre
adExecutor()); | 163 new TestNetworkQualityThroughputListener(Executors.newSingleThre
adExecutor()); |
166 | 164 |
167 mTestFramework.mCronetEngine.addRttListener(rttListener); | 165 cronetEngine.addRttListener(rttListener); |
168 mTestFramework.mCronetEngine.addThroughputListener(throughputListener); | 166 cronetEngine.addThroughputListener(throughputListener); |
169 | 167 |
170 mTestFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting(
true, true, true); | 168 cronetEngine.configureNetworkQualityEstimatorForTesting(true, true, true
); |
171 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 169 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
172 | 170 |
173 // 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, |
174 // 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, |
175 // QUIC will always succeed with a 200 (see | 173 // QUIC will always succeed with a 200 (see |
176 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). | 174 // net::HttpStreamFactoryImpl::Request::OnStreamFailed). |
177 UrlRequest.Builder requestBuilder = mTestFramework.mCronetEngine.newUrlR
equestBuilder( | 175 UrlRequest.Builder requestBuilder = |
178 quicURL, callback, callback.getExecutor()); | 176 cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.ge
tExecutor()); |
179 requestBuilder.build().start(); | 177 requestBuilder.build().start(); |
180 callback.blockForDone(); | 178 callback.blockForDone(); |
181 | 179 |
182 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 180 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
183 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"; |
184 assertEquals(expectedContent, callback.mResponseAsString); | 182 assertEquals(expectedContent, callback.mResponseAsString); |
185 assertIsQuic(callback.mResponseInfo); | 183 assertIsQuic(callback.mResponseInfo); |
186 | 184 |
187 // 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 |
188 // 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 |
189 // throughput listeners on the executor provided to network quality. | 187 // throughput listeners on the executor provided to network quality. |
190 throughputListener.waitUntilFirstThroughputObservationReceived(); | 188 throughputListener.waitUntilFirstThroughputObservationReceived(); |
191 | 189 |
192 // Wait for RTT observation (at the URL request layer) to be posted. | 190 // Wait for RTT observation (at the URL request layer) to be posted. |
193 rttListener.waitUntilFirstUrlRequestRTTReceived(); | 191 rttListener.waitUntilFirstUrlRequestRTTReceived(); |
194 | 192 |
195 assertTrue(throughputListener.throughputObservationCount() > 0); | 193 assertTrue(throughputListener.throughputObservationCount() > 0); |
196 | 194 |
197 // Check RTT observation count after throughput observation has been rec
eived. This ensures | 195 // 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. | 196 // that executor has finished posting the RTT observation to the RTT lis
teners. |
199 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST | 197 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST |
200 assertTrue(rttListener.rttObservationCount(0) > 0); | 198 assertTrue(rttListener.rttObservationCount(0) > 0); |
201 | 199 |
202 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC | 200 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC |
203 assertTrue(rttListener.rttObservationCount(2) > 0); | 201 assertTrue(rttListener.rttObservationCount(2) > 0); |
204 | 202 |
205 // Verify that effective connection type callback is received and | 203 // Verify that effective connection type callback is received and |
206 // effective connection type is correctly set. | 204 // effective connection type is correctly set. |
207 assertTrue(mTestFramework.mCronetEngine.getEffectiveConnectionType() | 205 assertTrue( |
208 != EffectiveConnectionType.TYPE_UNKNOWN); | 206 cronetEngine.getEffectiveConnectionType() != EffectiveConnection
Type.TYPE_UNKNOWN); |
209 | 207 |
210 // Verify that the HTTP RTT, transport RTT and downstream throughput | 208 // Verify that the HTTP RTT, transport RTT and downstream throughput |
211 // estimates are available. | 209 // estimates are available. |
212 assertTrue(mTestFramework.mCronetEngine.getHttpRttMs() >= 0); | 210 assertTrue(cronetEngine.getHttpRttMs() >= 0); |
213 assertTrue(mTestFramework.mCronetEngine.getTransportRttMs() >= 0); | 211 assertTrue(cronetEngine.getTransportRttMs() >= 0); |
214 assertTrue(mTestFramework.mCronetEngine.getDownstreamThroughputKbps() >=
0); | 212 assertTrue(cronetEngine.getDownstreamThroughputKbps() >= 0); |
215 | 213 |
216 // Verify that the cached estimates were written to the prefs. | 214 // Verify that the cached estimates were written to the prefs. |
217 while (true) { | 215 while (true) { |
218 Log.i(TAG, "Still waiting for pref file update....."); | 216 Log.i(TAG, "Still waiting for pref file update....."); |
219 Thread.sleep(10000); | 217 Thread.sleep(10000); |
220 try { | 218 try { |
221 if (fileContainsString("local_prefs.json", "network_qualities"))
{ | 219 if (fileContainsString("local_prefs.json", "network_qualities"))
{ |
222 break; | 220 break; |
223 } | 221 } |
224 } catch (FileNotFoundException e) { | 222 } catch (FileNotFoundException e) { |
225 // Ignored this exception since the file will only be created wh
en updates are | 223 // Ignored this exception since the file will only be created wh
en updates are |
226 // flushed to the disk. | 224 // flushed to the disk. |
227 } | 225 } |
228 } | 226 } |
229 assertTrue(fileContainsString("local_prefs.json", "network_qualities")); | 227 assertTrue(fileContainsString("local_prefs.json", "network_qualities")); |
230 mTestFramework.mCronetEngine.shutdown(); | 228 cronetEngine.shutdown(); |
231 } | 229 } |
232 | 230 |
233 @SmallTest | 231 @SmallTest |
234 @OnlyRunNativeCronet | 232 @OnlyRunNativeCronet |
235 @Feature({"Cronet"}) | 233 @Feature({"Cronet"}) |
236 public void testMetricsWithQuic() throws Exception { | 234 public void testMetricsWithQuic() throws Exception { |
237 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n
ull, mBuilder); | 235 ExperimentalCronetEngine cronetEngine = mBuilder.build(); |
238 TestRequestFinishedListener requestFinishedListener = new TestRequestFin
ishedListener(); | 236 TestRequestFinishedListener requestFinishedListener = new TestRequestFin
ishedListener(); |
239 mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedL
istener); | 237 cronetEngine.addRequestFinishedListener(requestFinishedListener); |
240 | 238 |
241 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; | 239 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; |
242 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 240 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
243 | 241 |
244 UrlRequest.Builder requestBuilder = mTestFramework.mCronetEngine.newUrlR
equestBuilder( | 242 UrlRequest.Builder requestBuilder = |
245 quicURL, callback, callback.getExecutor()); | 243 cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.ge
tExecutor()); |
246 Date startTime = new Date(); | 244 Date startTime = new Date(); |
247 requestBuilder.build().start(); | 245 requestBuilder.build().start(); |
248 callback.blockForDone(); | 246 callback.blockForDone(); |
249 requestFinishedListener.blockUntilDone(); | 247 requestFinishedListener.blockUntilDone(); |
250 Date endTime = new Date(); | 248 Date endTime = new Date(); |
251 | 249 |
252 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 250 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
253 assertIsQuic(callback.mResponseInfo); | 251 assertIsQuic(callback.mResponseInfo); |
254 | 252 |
255 RequestFinishedInfo requestInfo = requestFinishedListener.getRequestInfo
(); | 253 RequestFinishedInfo requestInfo = requestFinishedListener.getRequestInfo
(); |
256 MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime
, endTime); | 254 MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime
, endTime); |
257 assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReaso
n()); | 255 assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReaso
n()); |
258 MetricsTestUtil.checkHasConnectTiming(requestInfo.getMetrics(), startTim
e, endTime, true); | 256 MetricsTestUtil.checkHasConnectTiming(requestInfo.getMetrics(), startTim
e, endTime, true); |
259 | 257 |
260 // Second request should use the same connection and not have ConnectTim
ing numbers | 258 // Second request should use the same connection and not have ConnectTim
ing numbers |
261 callback = new TestUrlRequestCallback(); | 259 callback = new TestUrlRequestCallback(); |
262 requestFinishedListener.reset(); | 260 requestFinishedListener.reset(); |
263 requestBuilder = mTestFramework.mCronetEngine.newUrlRequestBuilder( | 261 requestBuilder = |
264 quicURL, callback, callback.getExecutor()); | 262 cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.ge
tExecutor()); |
265 startTime = new Date(); | 263 startTime = new Date(); |
266 requestBuilder.build().start(); | 264 requestBuilder.build().start(); |
267 callback.blockForDone(); | 265 callback.blockForDone(); |
268 requestFinishedListener.blockUntilDone(); | 266 requestFinishedListener.blockUntilDone(); |
269 endTime = new Date(); | 267 endTime = new Date(); |
270 | 268 |
271 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 269 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
272 assertIsQuic(callback.mResponseInfo); | 270 assertIsQuic(callback.mResponseInfo); |
273 | 271 |
274 requestInfo = requestFinishedListener.getRequestInfo(); | 272 requestInfo = requestFinishedListener.getRequestInfo(); |
275 MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime
, endTime); | 273 MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime
, endTime); |
276 assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReaso
n()); | 274 assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReaso
n()); |
277 MetricsTestUtil.checkNoConnectTiming(requestInfo.getMetrics()); | 275 MetricsTestUtil.checkNoConnectTiming(requestInfo.getMetrics()); |
278 | 276 |
279 mTestFramework.mCronetEngine.shutdown(); | 277 cronetEngine.shutdown(); |
280 } | 278 } |
281 | 279 |
282 // Helper method to assert that the request is negotiated over QUIC. | 280 // Helper method to assert that the request is negotiated over QUIC. |
283 private void assertIsQuic(UrlResponseInfo responseInfo) { | 281 private void assertIsQuic(UrlResponseInfo responseInfo) { |
284 assertTrue(responseInfo.getNegotiatedProtocol().startsWith(QUIC_PROTOCOL
_STRING_PREFIX)); | 282 assertTrue(responseInfo.getNegotiatedProtocol().startsWith(QUIC_PROTOCOL
_STRING_PREFIX)); |
285 } | 283 } |
286 } | 284 } |
OLD | NEW |