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.os.ConditionVariable; | 7 import android.os.ConditionVariable; |
8 import android.test.suitebuilder.annotation.LargeTest; | 8 import android.test.suitebuilder.annotation.LargeTest; |
9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
10 | 10 |
11 import org.chromium.base.Log; | 11 import org.chromium.base.Log; |
12 import org.chromium.base.annotations.SuppressFBWarnings; | 12 import org.chromium.base.annotations.SuppressFBWarnings; |
13 import org.chromium.base.test.util.Feature; | 13 import org.chromium.base.test.util.Feature; |
14 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet; | 14 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet; |
15 import org.json.JSONObject; | 15 import org.json.JSONObject; |
16 | 16 |
17 import java.io.File; | 17 import java.io.File; |
18 import java.io.FileInputStream; | 18 import java.io.FileInputStream; |
19 import java.io.FileNotFoundException; | 19 import java.io.FileNotFoundException; |
20 import java.io.IOException; | 20 import java.io.IOException; |
| 21 import java.util.Date; |
21 import java.util.HashMap; | 22 import java.util.HashMap; |
22 import java.util.concurrent.Executors; | 23 import java.util.concurrent.Executors; |
23 | 24 |
24 /** | 25 /** |
25 * Tests making requests using QUIC. | 26 * Tests making requests using QUIC. |
26 */ | 27 */ |
27 public class QuicTest extends CronetTestBase { | 28 public class QuicTest extends CronetTestBase { |
28 private static final String TAG = "cr.QuicTest"; | 29 private static final String TAG = "cr.QuicTest"; |
29 private CronetTestFramework mTestFramework; | 30 private CronetTestFramework mTestFramework; |
30 private CronetEngine.Builder mBuilder; | 31 private CronetEngine.Builder mBuilder; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC | 225 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC |
225 assertTrue(rttListener.rttObservationCount(2) > 0); | 226 assertTrue(rttListener.rttObservationCount(2) > 0); |
226 | 227 |
227 // Verify that effective connection type callback is received and | 228 // Verify that effective connection type callback is received and |
228 // effective connection type is correctly set. | 229 // effective connection type is correctly set. |
229 assertTrue(mTestFramework.mCronetEngine.getEffectiveConnectionType() | 230 assertTrue(mTestFramework.mCronetEngine.getEffectiveConnectionType() |
230 != EffectiveConnectionType.TYPE_UNKNOWN); | 231 != EffectiveConnectionType.TYPE_UNKNOWN); |
231 | 232 |
232 mTestFramework.mCronetEngine.shutdown(); | 233 mTestFramework.mCronetEngine.shutdown(); |
233 } | 234 } |
| 235 |
| 236 @SmallTest |
| 237 @OnlyRunNativeCronet |
| 238 @Feature({"Cronet"}) |
| 239 public void testMetricsWithQuic() throws Exception { |
| 240 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n
ull, mBuilder); |
| 241 RequestFinishedInfoTest.TestExecutor testExecutor = |
| 242 new RequestFinishedInfoTest.TestExecutor(); |
| 243 RequestFinishedInfoTest.TestRequestFinishedListener requestFinishedListe
ner = |
| 244 new RequestFinishedInfoTest.TestRequestFinishedListener(testExec
utor); |
| 245 mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedL
istener); |
| 246 |
| 247 String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; |
| 248 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
| 249 |
| 250 UrlRequest.Builder requestBuilder = new UrlRequest.Builder( |
| 251 quicURL, callback, callback.getExecutor(), mTestFramework.mCrone
tEngine); |
| 252 Date startTime = new Date(); |
| 253 requestBuilder.build().start(); |
| 254 callback.blockForDone(); |
| 255 Date endTime = new Date(); |
| 256 testExecutor.runAllTasks(); |
| 257 |
| 258 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
| 259 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); |
| 260 |
| 261 RequestFinishedInfo requestInfo = requestFinishedListener.mRequestInfo; |
| 262 assertNotNull(requestInfo); |
| 263 RequestFinishedInfo.Metrics metrics = requestInfo.getMetrics(); |
| 264 assertNotNull(metrics); |
| 265 |
| 266 RequestFinishedInfoTest.checkTimingMetrics(metrics, startTime, endTime); |
| 267 RequestFinishedInfoTest.checkHasConnectTiming(metrics, startTime, endTim
e, true); |
| 268 |
| 269 // Second request should use the same connection and not have ConnectTim
ing numbers |
| 270 callback = new TestUrlRequestCallback(); |
| 271 requestFinishedListener.reset(); |
| 272 requestBuilder = new UrlRequest.Builder( |
| 273 quicURL, callback, callback.getExecutor(), mTestFramework.mCrone
tEngine); |
| 274 startTime = new Date(); |
| 275 requestBuilder.build().start(); |
| 276 callback.blockForDone(); |
| 277 endTime = new Date(); |
| 278 testExecutor.runAllTasks(); |
| 279 |
| 280 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
| 281 assertEquals("quic/1+spdy/3", callback.mResponseInfo.getNegotiatedProtoc
ol()); |
| 282 |
| 283 requestInfo = requestFinishedListener.mRequestInfo; |
| 284 assertNotNull(requestInfo); |
| 285 metrics = requestInfo.getMetrics(); |
| 286 assertNotNull(metrics); |
| 287 |
| 288 RequestFinishedInfoTest.checkTimingMetrics(metrics, startTime, endTime); |
| 289 RequestFinishedInfoTest.checkNoConnectTiming(metrics); |
| 290 |
| 291 mTestFramework.mCronetEngine.shutdown(); |
| 292 } |
234 } | 293 } |
OLD | NEW |