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

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

Issue 2417643007: Expose RTT and throughput estimates from Cronet (Closed)
Patch Set: ps 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.content.Context; 7 import android.content.Context;
8 import android.content.ContextWrapper; 8 import android.content.ContextWrapper;
9 import android.os.ConditionVariable; 9 import android.os.ConditionVariable;
10 import android.os.Handler; 10 import android.os.Handler;
11 import android.os.Looper; 11 import android.os.Looper;
12 import android.os.StrictMode; 12 import android.os.StrictMode;
13 import android.test.suitebuilder.annotation.SmallTest; 13 import android.test.suitebuilder.annotation.SmallTest;
14 14
15 import org.json.JSONObject;
RyanSturm 2016/10/14 21:21:32 Should this import be alphabetical (i.e., after ja
tbansal1 2016/10/14 21:50:29 This is the new alphabetical order. See https://co
RyanSturm 2016/10/14 22:19:13 Acknowledged. This breaks my brain a little, but I
16
15 import org.chromium.base.FileUtils; 17 import org.chromium.base.FileUtils;
16 import org.chromium.base.PathUtils; 18 import org.chromium.base.PathUtils;
17 import org.chromium.base.annotations.JNINamespace; 19 import org.chromium.base.annotations.JNINamespace;
18 import org.chromium.base.test.util.Feature; 20 import org.chromium.base.test.util.Feature;
19 import org.chromium.net.MetricsTestUtil.TestExecutor; 21 import org.chromium.net.MetricsTestUtil.TestExecutor;
20 import org.chromium.net.TestUrlRequestCallback.ResponseStep; 22 import org.chromium.net.TestUrlRequestCallback.ResponseStep;
21 import org.chromium.net.impl.CronetLibraryLoader; 23 import org.chromium.net.impl.CronetLibraryLoader;
22 import org.chromium.net.impl.CronetUrlRequestContext; 24 import org.chromium.net.impl.CronetUrlRequestContext;
23 import org.chromium.net.test.EmbeddedTestServer; 25 import org.chromium.net.test.EmbeddedTestServer;
24 import org.json.JSONObject;
25 26
26 import java.io.BufferedReader; 27 import java.io.BufferedReader;
27 import java.io.File; 28 import java.io.File;
28 import java.io.FileReader; 29 import java.io.FileReader;
29 import java.net.URL; 30 import java.net.URL;
30 import java.util.Arrays; 31 import java.util.Arrays;
31 import java.util.concurrent.Executor; 32 import java.util.concurrent.Executor;
32 import java.util.concurrent.Executors; 33 import java.util.concurrent.Executors;
33 import java.util.concurrent.ThreadFactory; 34 import java.util.concurrent.ThreadFactory;
34 import java.util.concurrent.atomic.AtomicReference; 35 import java.util.concurrent.atomic.AtomicReference;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 callback.blockForDone(); 274 callback.blockForDone();
274 networkQualityExecutor.runAllTasks(); 275 networkQualityExecutor.runAllTasks();
275 assertEquals(0, rttListener.rttObservationCount()); 276 assertEquals(0, rttListener.rttObservationCount());
276 testFramework.mCronetEngine.shutdown(); 277 testFramework.mCronetEngine.shutdown();
277 } 278 }
278 279
279 @SmallTest 280 @SmallTest
280 @Feature({"Cronet"}) 281 @Feature({"Cronet"})
281 public void testRealTimeNetworkQualityObservationsQuicDisabled() throws Exce ption { 282 public void testRealTimeNetworkQualityObservationsQuicDisabled() throws Exce ption {
282 CronetEngine.Builder mCronetEngineBuilder = new CronetEngine.Builder(get Context()); 283 CronetEngine.Builder mCronetEngineBuilder = new CronetEngine.Builder(get Context());
284 assert CronetEngine.INVALID_RTT_THROUGHPUT < 0;
285
286 // The invalid value for the estimates used by Cronet should match the i nvalid value for
287 // the estimates used by the native.
288 assertEquals(CronetEngine.INVALID_RTT_THROUGHPUT,
289 RttThroughputValues.INVALID_RTT_THROUGHPUT_VALUE);
283 Executor listenersExecutor = Executors.newSingleThreadExecutor(new Execu torThreadFactory()); 290 Executor listenersExecutor = Executors.newSingleThreadExecutor(new Execu torThreadFactory());
284 ConditionVariable waitForThroughput = new ConditionVariable(); 291 ConditionVariable waitForThroughput = new ConditionVariable();
285 TestNetworkQualityRttListener rttListener = 292 TestNetworkQualityRttListener rttListener =
286 new TestNetworkQualityRttListener(listenersExecutor); 293 new TestNetworkQualityRttListener(listenersExecutor);
287 TestNetworkQualityThroughputListener throughputListener = 294 TestNetworkQualityThroughputListener throughputListener =
288 new TestNetworkQualityThroughputListener(listenersExecutor, wait ForThroughput); 295 new TestNetworkQualityThroughputListener(listenersExecutor, wait ForThroughput);
289 mCronetEngineBuilder.enableHttp2(true).enableQuic(false).enableNetworkQu alityEstimator( 296 mCronetEngineBuilder.enableHttp2(true).enableQuic(false).enableNetworkQu alityEstimator(
290 true); 297 true);
291 final CronetTestFramework testFramework = 298 final CronetTestFramework testFramework =
292 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder); 299 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder);
(...skipping 30 matching lines...) Expand all
323 330
324 // Verify that the listeners were notified on the expected thread. 331 // Verify that the listeners were notified on the expected thread.
325 assertEquals(mNetworkQualityThread, rttListener.getThread()); 332 assertEquals(mNetworkQualityThread, rttListener.getThread());
326 assertEquals(mNetworkQualityThread, throughputListener.getThread()); 333 assertEquals(mNetworkQualityThread, throughputListener.getThread());
327 334
328 // Verify that effective connection type callback is received and 335 // Verify that effective connection type callback is received and
329 // effective connection type is correctly set. 336 // effective connection type is correctly set.
330 assertTrue(testFramework.mCronetEngine.getEffectiveConnectionType() 337 assertTrue(testFramework.mCronetEngine.getEffectiveConnectionType()
331 != EffectiveConnectionType.TYPE_UNKNOWN); 338 != EffectiveConnectionType.TYPE_UNKNOWN);
332 339
340 // Verify that the HTTP RTT, transport RTT and downstream throughput
341 // estimates are available.
342 if (testFramework.mCronetEngine.getEffectiveConnectionType()
343 != EffectiveConnectionType.TYPE_OFFLINE) {
344 assertTrue(testFramework.mCronetEngine.getHttpRttMsec() > 0);
345 assertTrue(testFramework.mCronetEngine.getTransportRttMsec() > 0);
346 assertTrue(testFramework.mCronetEngine.getDownstreamThroughputKbps() > 0);
347 } else {
348 assertEquals(CronetEngine.INVALID_RTT_THROUGHPUT,
349 testFramework.mCronetEngine.getHttpRttMsec());
350 assertEquals(CronetEngine.INVALID_RTT_THROUGHPUT,
351 testFramework.mCronetEngine.getTransportRttMsec());
352 assertEquals(CronetEngine.INVALID_RTT_THROUGHPUT,
353 testFramework.mCronetEngine.getDownstreamThroughputKbps());
354 }
355
333 testFramework.mCronetEngine.shutdown(); 356 testFramework.mCronetEngine.shutdown();
334 } 357 }
335 358
336 @SmallTest 359 @SmallTest
337 @Feature({"Cronet"}) 360 @Feature({"Cronet"})
338 // TODO: Remove the annotation after fixing http://crbug.com/637979 & http:/ /crbug.com/637972 361 // TODO: Remove the annotation after fixing http://crbug.com/637979 & http:/ /crbug.com/637972
339 @OnlyRunNativeCronet 362 @OnlyRunNativeCronet
340 public void testShutdown() throws Exception { 363 public void testShutdown() throws Exception {
341 final CronetTestFramework testFramework = startCronetTestFramework(); 364 final CronetTestFramework testFramework = startCronetTestFramework();
342 ShutdownTestUrlRequestCallback callback = 365 ShutdownTestUrlRequestCallback callback =
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 1470 TestUrlRequestCallback callback = new TestUrlRequestCallback();
1448 URL requestUrl = 1471 URL requestUrl =
1449 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile()); 1472 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile());
1450 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(requestUrl .toString(), 1473 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(requestUrl .toString(),
1451 callback, callback.getExecutor(), testFramework.mCronetEngine); 1474 callback, callback.getExecutor(), testFramework.mCronetEngine);
1452 urlRequestBuilder.build().start(); 1475 urlRequestBuilder.build().start();
1453 callback.blockForDone(); 1476 callback.blockForDone();
1454 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 1477 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
1455 } 1478 }
1456 } 1479 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698