| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 static org.chromium.base.CollectionUtil.newHashSet; | 7 import static org.chromium.base.CollectionUtil.newHashSet; |
| 8 | 8 |
| 9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
| 10 | 10 |
| 11 import org.chromium.base.test.util.Feature; | 11 import org.chromium.base.test.util.Feature; |
| 12 import org.chromium.net.test.EmbeddedTestServer; | 12 import org.chromium.net.test.EmbeddedTestServer; |
| 13 | 13 |
| 14 import java.util.ArrayList; | 14 import java.util.ArrayList; |
| 15 import java.util.Date; |
| 15 import java.util.HashSet; | 16 import java.util.HashSet; |
| 16 import java.util.LinkedList; | 17 import java.util.LinkedList; |
| 17 import java.util.List; | 18 import java.util.List; |
| 18 import java.util.NoSuchElementException; | 19 import java.util.NoSuchElementException; |
| 19 import java.util.concurrent.Executor; | 20 import java.util.concurrent.Executor; |
| 20 | 21 |
| 21 /** | 22 /** |
| 22 * Test RequestFinishedInfo.Listener and the metrics information it provides. | 23 * Test RequestFinishedInfo.Listener and the metrics information it provides. |
| 23 */ | 24 */ |
| 24 public class RequestFinishedInfoTest extends CronetTestBase { | 25 public class RequestFinishedInfoTest extends CronetTestBase { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( | 253 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( |
| 253 mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEn
gine); | 254 mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEn
gine); |
| 254 urlRequestBuilder.build().start(); | 255 urlRequestBuilder.build().start(); |
| 255 callback.blockForDone(); | 256 callback.blockForDone(); |
| 256 testExecutor.runAllTasks(); | 257 testExecutor.runAllTasks(); |
| 257 | 258 |
| 258 assertNull("RequestFinishedInfo.Listener must not be called", | 259 assertNull("RequestFinishedInfo.Listener must not be called", |
| 259 requestFinishedListener.mRequestInfo); | 260 requestFinishedListener.mRequestInfo); |
| 260 mTestFramework.mCronetEngine.shutdown(); | 261 mTestFramework.mCronetEngine.shutdown(); |
| 261 } | 262 } |
| 263 |
| 264 @SmallTest |
| 265 @Feature({"Cronet"}) |
| 266 public void testMetricsGetters() throws Exception { |
| 267 long proxyStart = 0; |
| 268 long proxyEnd = 1; |
| 269 long dnsStart = 2; |
| 270 long dnsEnd = 3; |
| 271 long connectStart = 4; |
| 272 long connectEnd = 5; |
| 273 long sslStart = 6; |
| 274 long sslEnd = 7; |
| 275 long sendingStart = 8; |
| 276 long sendingEnd = 9; |
| 277 long pushStart = 10; |
| 278 long pushEnd = 11; |
| 279 long responseStart = 12; |
| 280 long responseEnd = 13; |
| 281 boolean socketReused = true; |
| 282 long sentBytesCount = 14; |
| 283 long receivedBytesCount = 15; |
| 284 // Make sure nothing gets reordered inside the Metrics class |
| 285 RequestFinishedInfo.Metrics metrics = new RequestFinishedInfo.Metrics(pr
oxyStart, proxyEnd, |
| 286 dnsStart, dnsEnd, connectStart, connectEnd, sslStart, sslEnd, se
ndingStart, |
| 287 sendingEnd, pushStart, pushEnd, responseStart, responseEnd, sock
etReused, |
| 288 sentBytesCount, receivedBytesCount); |
| 289 // 0 timestamp should translate to null, not 1/1/1970 |
| 290 assertNull(metrics.getProxyStart()); |
| 291 assertEquals(new Date(proxyEnd), metrics.getProxyEnd()); |
| 292 assertEquals(new Date(dnsStart), metrics.getDnsStart()); |
| 293 assertEquals(new Date(dnsEnd), metrics.getDnsEnd()); |
| 294 assertEquals(new Date(connectStart), metrics.getConnectStart()); |
| 295 assertEquals(new Date(connectEnd), metrics.getConnectEnd()); |
| 296 assertEquals(new Date(sslStart), metrics.getSslStart()); |
| 297 assertEquals(new Date(sslEnd), metrics.getSslEnd()); |
| 298 assertEquals(new Date(pushStart), metrics.getPushStart()); |
| 299 assertEquals(new Date(pushEnd), metrics.getPushEnd()); |
| 300 assertEquals(new Date(responseStart), metrics.getResponseStart()); |
| 301 assertEquals(new Date(responseEnd), metrics.getResponseEnd()); |
| 302 assertEquals(socketReused, metrics.getSocketReused()); |
| 303 assertEquals(sentBytesCount, (long) metrics.getSentBytesCount()); |
| 304 assertEquals(receivedBytesCount, (long) metrics.getReceivedBytesCount())
; |
| 305 } |
| 262 } | 306 } |
| OLD | NEW |