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

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

Issue 2585203003: Don't try to report metrics when there's no URLRequest (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « components/cronet/android/cronet_url_request_adapter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.os.ConditionVariable; 9 import android.os.ConditionVariable;
10 import android.test.suitebuilder.annotation.SmallTest; 10 import android.test.suitebuilder.annotation.SmallTest;
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 RequestFinishedInfo requestInfo = requestFinishedListener.getRequestInfo (); 285 RequestFinishedInfo requestInfo = requestFinishedListener.getRequestInfo ();
286 MetricsTestUtil.checkRequestFinishedInfo(requestInfo, mUrl, startTime, e ndTime); 286 MetricsTestUtil.checkRequestFinishedInfo(requestInfo, mUrl, startTime, e ndTime);
287 assertEquals(RequestFinishedInfo.CANCELED, requestInfo.getFinishedReason ()); 287 assertEquals(RequestFinishedInfo.CANCELED, requestInfo.getFinishedReason ());
288 MetricsTestUtil.checkHasConnectTiming(requestInfo.getMetrics(), startTim e, endTime, false); 288 MetricsTestUtil.checkHasConnectTiming(requestInfo.getMetrics(), startTim e, endTime, false);
289 289
290 assertEquals(newHashSet("request annotation", this), // Use sets for uno rdered comparison. 290 assertEquals(newHashSet("request annotation", this), // Use sets for uno rdered comparison.
291 new HashSet<Object>(requestInfo.getAnnotations())); 291 new HashSet<Object>(requestInfo.getAnnotations()));
292 mTestFramework.mCronetEngine.shutdown(); 292 mTestFramework.mCronetEngine.shutdown();
293 } 293 }
294 294
295 // Checks that CronetURLRequestAdapter::DestroyOnNetworkThread() doesn't cra sh when metrics
296 // collection is enabled and the URLRequest hasn't been created. See http:// crbug.com/675629.
297 @SmallTest
298 @OnlyRunNativeCronet
299 @Feature({"Cronet"})
300 public void testExceptionInRequestStart() throws Exception {
301 mTestFramework = startCronetTestFramework();
302 TestRequestFinishedListener requestFinishedListener = new TestRequestFin ishedListener();
303 mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedL istener);
304 TestUrlRequestCallback callback = new TestUrlRequestCallback();
305 ExperimentalUrlRequest.Builder urlRequestBuilder =
306 mTestFramework.mCronetEngine.newUrlRequestBuilder(
307 mUrl, callback, callback.getExecutor());
308 // Empty headers are invalid and will cause start() to throw an exceptio n.
309 UrlRequest request = urlRequestBuilder.addHeader("", "")
310 .addRequestAnnotation("request annotation")
311 .addRequestAnnotation(this)
312 .build();
313 try {
314 request.start();
315 fail("UrlRequest.start() should throw IllegalArgumentException");
316 } catch (IllegalArgumentException e) {
317 assertEquals("Invalid header =", e.getMessage());
318 }
319
320 // Now run a normal request and check that the listener only hears about this one.
321 callback = new TestUrlRequestCallback();
xunjieli 2016/12/19 18:52:09 Does the test not repro the crash if you only make
mgersh 2016/12/19 19:06:11 It does repro without this part. It's primarily he
xunjieli 2016/12/19 19:40:05 One thing confuses me is that TestRequestFinishedL
mgersh 2016/12/19 20:20:08 Done.
322 urlRequestBuilder =
323 (ExperimentalUrlRequest.Builder) mTestFramework.mCronetEngine.ne wUrlRequestBuilder(
324 mUrl, callback, callback.getExecutor());
325 Date startTime = new Date();
326 urlRequestBuilder.addRequestAnnotation("request annotation")
327 .addRequestAnnotation(this)
328 .build()
329 .start();
330 callback.blockForDone();
331 requestFinishedListener.blockUntilDone();
332 Date endTime = new Date();
333
334 RequestFinishedInfo requestInfo = requestFinishedListener.getRequestInfo ();
335 MetricsTestUtil.checkRequestFinishedInfo(requestInfo, mUrl, startTime, e ndTime);
336 assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReaso n());
337 MetricsTestUtil.checkHasConnectTiming(requestInfo.getMetrics(), startTim e, endTime, false);
338 assertEquals(newHashSet("request annotation", this), // Use sets for uno rdered comparison.
339 new HashSet<Object>(requestInfo.getAnnotations()));
340
341 mTestFramework.mCronetEngine.shutdown();
342 }
343
295 @SmallTest 344 @SmallTest
296 @Feature({"Cronet"}) 345 @Feature({"Cronet"})
297 public void testMetricsGetters() throws Exception { 346 public void testMetricsGetters() throws Exception {
298 long requestStart = 1; 347 long requestStart = 1;
299 long dnsStart = 2; 348 long dnsStart = 2;
300 long dnsEnd = -1; 349 long dnsEnd = -1;
301 long connectStart = 4; 350 long connectStart = 4;
302 long connectEnd = 5; 351 long connectEnd = 5;
303 long sslStart = 6; 352 long sslStart = 6;
304 long sslEnd = 7; 353 long sslEnd = 7;
(...skipping 20 matching lines...) Expand all
325 assertEquals(new Date(sslEnd), metrics.getSslEnd()); 374 assertEquals(new Date(sslEnd), metrics.getSslEnd());
326 assertEquals(new Date(pushStart), metrics.getPushStart()); 375 assertEquals(new Date(pushStart), metrics.getPushStart());
327 assertEquals(new Date(pushEnd), metrics.getPushEnd()); 376 assertEquals(new Date(pushEnd), metrics.getPushEnd());
328 assertEquals(new Date(responseStart), metrics.getResponseStart()); 377 assertEquals(new Date(responseStart), metrics.getResponseStart());
329 assertEquals(new Date(requestEnd), metrics.getRequestEnd()); 378 assertEquals(new Date(requestEnd), metrics.getRequestEnd());
330 assertEquals(socketReused, metrics.getSocketReused()); 379 assertEquals(socketReused, metrics.getSocketReused());
331 assertEquals(sentByteCount, (long) metrics.getSentByteCount()); 380 assertEquals(sentByteCount, (long) metrics.getSentByteCount());
332 assertEquals(receivedByteCount, (long) metrics.getReceivedByteCount()); 381 assertEquals(receivedByteCount, (long) metrics.getReceivedByteCount());
333 } 382 }
334 } 383 }
OLDNEW
« no previous file with comments | « components/cronet/android/cronet_url_request_adapter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698