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

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

Issue 2351793003: Implement timing metrics for UrlRequest (Closed)
Patch Set: Created 4 years, 3 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 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
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(requestInfo.getMetrics(), sta rtTime, endTime);
267 assertNotNull(metrics.getSslStart());
268 assertTrue(metrics.getSslStart().after(startTime));
269 assertNotNull(metrics.getSslEnd());
270 assertTrue(metrics.getSslEnd().before(endTime));
xunjieli 2016/09/20 14:32:46 Suggest having util functions equivalent to "Expec
mgersh 2016/09/20 20:48:25 Done.
271
272 mTestFramework.mCronetEngine.shutdown();
273 }
234 } 274 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698