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

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

Issue 2351793003: Implement timing metrics for UrlRequest (Closed)
Patch Set: New test, and some rearranging things Created 4 years, 2 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 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 junit.framework.Assert.assertNotNull; 7 import static junit.framework.Assert.assertNotNull;
8 import static junit.framework.Assert.assertNull; 8 import static junit.framework.Assert.assertNull;
9 import static junit.framework.Assert.assertTrue;
9 10
11 import java.util.Date;
10 import java.util.LinkedList; 12 import java.util.LinkedList;
11 import java.util.NoSuchElementException; 13 import java.util.NoSuchElementException;
12 import java.util.concurrent.Executor; 14 import java.util.concurrent.Executor;
13 15
14 /** 16 /**
15 * Classes which are useful for testing Cronet's metrics implementation and are needed in more than 17 * Classes which are useful for testing Cronet's metrics implementation and are needed in more than
16 * one test file. 18 * one test file.
17 */ 19 */
18 public class MetricsTestUtil { 20 public class MetricsTestUtil {
19 /** 21 /**
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 public RequestFinishedInfo getRequestInfo() { 53 public RequestFinishedInfo getRequestInfo() {
52 return mRequestInfo; 54 return mRequestInfo;
53 } 55 }
54 56
55 @Override 57 @Override
56 public void onRequestFinished(RequestFinishedInfo requestInfo) { 58 public void onRequestFinished(RequestFinishedInfo requestInfo) {
57 assertNull("onRequestFinished called repeatedly", mRequestInfo); 59 assertNull("onRequestFinished called repeatedly", mRequestInfo);
58 assertNotNull(requestInfo); 60 assertNotNull(requestInfo);
59 mRequestInfo = requestInfo; 61 mRequestInfo = requestInfo;
60 } 62 }
63
64 public void reset() {
65 mRequestInfo = null;
66 }
67 }
68
69 /**
70 * Check existence of all the timing metrics that apply to most test request s,
71 * except those that come from net::LoadTimingInfo::ConnectTiming.
72 * Also check some timing differences, focusing on things we can't check wit h asserts in the
73 * CronetMetrics constructor.
74 * Don't check push times here.
75 */
76 public static void checkTimingMetrics(
77 RequestFinishedInfo.Metrics metrics, Date startTime, Date endTime) {
78 assertNotNull(metrics.getRequestStart());
79 assertTrue(metrics.getRequestStart().after(startTime));
80 assertNotNull(metrics.getSendingStart());
81 assertTrue(metrics.getSendingStart().after(startTime));
82 assertNotNull(metrics.getSendingEnd());
83 assertTrue(metrics.getSendingEnd().before(endTime));
84 assertNotNull(metrics.getResponseStart());
85 assertTrue(metrics.getResponseStart().after(startTime));
86 assertNotNull(metrics.getResponseEnd());
87 assertTrue(metrics.getResponseEnd().before(endTime));
88 // Entire request should take more than 0 ms
89 assertTrue(metrics.getResponseEnd().getTime() - metrics.getRequestStart( ).getTime() > 0);
90 }
91
92 /**
93 * Check that the timing metrics which come from net::LoadTimingInfo::Connec tTiming exist,
94 * except SSL times in the case of non-https requests.
95 */
96 public static void checkHasConnectTiming(
97 RequestFinishedInfo.Metrics metrics, Date startTime, Date endTime, b oolean isSsl) {
98 assertNotNull(metrics.getDnsStart());
99 assertTrue(metrics.getDnsStart().after(startTime));
100 assertNotNull(metrics.getDnsEnd());
101 assertTrue(metrics.getDnsEnd().before(endTime));
102 assertNotNull(metrics.getConnectStart());
103 assertTrue(metrics.getConnectStart().after(startTime));
104 assertNotNull(metrics.getConnectEnd());
105 assertTrue(metrics.getConnectEnd().before(endTime));
106 if (isSsl) {
107 assertNotNull(metrics.getSslStart());
108 assertTrue(metrics.getSslStart().after(startTime));
109 assertNotNull(metrics.getSslEnd());
110 assertTrue(metrics.getSslEnd().before(endTime));
111 } else {
112 assertNull(metrics.getSslStart());
113 assertNull(metrics.getSslEnd());
114 }
115 }
116
117 /**
118 * Check that the timing metrics from net::LoadTimingInfo::ConnectTiming don 't exist.
119 */
120 public static void checkNoConnectTiming(RequestFinishedInfo.Metrics metrics) {
121 assertNull(metrics.getDnsStart());
122 assertNull(metrics.getDnsEnd());
123 assertNull(metrics.getSslStart());
124 assertNull(metrics.getSslEnd());
125 assertNull(metrics.getConnectStart());
126 assertNull(metrics.getConnectEnd());
61 } 127 }
62 } 128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698