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

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: Removed annotation 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;
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 RttThroughputValues.INVALID_RTT_THROUGHPUT < 0;
285
283 Executor listenersExecutor = Executors.newSingleThreadExecutor(new Execu torThreadFactory()); 286 Executor listenersExecutor = Executors.newSingleThreadExecutor(new Execu torThreadFactory());
284 ConditionVariable waitForThroughput = new ConditionVariable(); 287 ConditionVariable waitForThroughput = new ConditionVariable();
285 TestNetworkQualityRttListener rttListener = 288 TestNetworkQualityRttListener rttListener =
286 new TestNetworkQualityRttListener(listenersExecutor); 289 new TestNetworkQualityRttListener(listenersExecutor);
287 TestNetworkQualityThroughputListener throughputListener = 290 TestNetworkQualityThroughputListener throughputListener =
288 new TestNetworkQualityThroughputListener(listenersExecutor, wait ForThroughput); 291 new TestNetworkQualityThroughputListener(listenersExecutor, wait ForThroughput);
289 mCronetEngineBuilder.enableHttp2(true).enableQuic(false).enableNetworkQu alityEstimator( 292 mCronetEngineBuilder.enableHttp2(true).enableQuic(false).enableNetworkQu alityEstimator(
290 true); 293 true);
291 final CronetTestFramework testFramework = 294 final CronetTestFramework testFramework =
292 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder); 295 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder);
(...skipping 30 matching lines...) Expand all
323 326
324 // Verify that the listeners were notified on the expected thread. 327 // Verify that the listeners were notified on the expected thread.
325 assertEquals(mNetworkQualityThread, rttListener.getThread()); 328 assertEquals(mNetworkQualityThread, rttListener.getThread());
326 assertEquals(mNetworkQualityThread, throughputListener.getThread()); 329 assertEquals(mNetworkQualityThread, throughputListener.getThread());
327 330
328 // Verify that effective connection type callback is received and 331 // Verify that effective connection type callback is received and
329 // effective connection type is correctly set. 332 // effective connection type is correctly set.
330 assertTrue(testFramework.mCronetEngine.getEffectiveConnectionType() 333 assertTrue(testFramework.mCronetEngine.getEffectiveConnectionType()
331 != EffectiveConnectionType.TYPE_UNKNOWN); 334 != EffectiveConnectionType.TYPE_UNKNOWN);
332 335
336 // Verify that the HTTP RTT, transport RTT and downstream throughput
337 // estimates are available.
338 if (testFramework.mCronetEngine.getEffectiveConnectionType()
339 != EffectiveConnectionType.TYPE_OFFLINE) {
340 assertTrue(testFramework.mCronetEngine.getHttpRttMs() > 0);
341 assertTrue(testFramework.mCronetEngine.getTransportRttMs() > 0);
342 assertTrue(testFramework.mCronetEngine.getDownstreamThroughputKbps() > 0);
343 } else {
344 assertEquals(RttThroughputValues.INVALID_RTT_THROUGHPUT,
345 testFramework.mCronetEngine.getHttpRttMs());
346 assertEquals(RttThroughputValues.INVALID_RTT_THROUGHPUT,
347 testFramework.mCronetEngine.getTransportRttMs());
348 assertEquals(RttThroughputValues.INVALID_RTT_THROUGHPUT,
349 testFramework.mCronetEngine.getDownstreamThroughputKbps());
350 }
351
333 testFramework.mCronetEngine.shutdown(); 352 testFramework.mCronetEngine.shutdown();
334 } 353 }
335 354
336 @SmallTest 355 @SmallTest
337 @Feature({"Cronet"}) 356 @Feature({"Cronet"})
338 // TODO: Remove the annotation after fixing http://crbug.com/637979 & http:/ /crbug.com/637972 357 // TODO: Remove the annotation after fixing http://crbug.com/637979 & http:/ /crbug.com/637972
339 @OnlyRunNativeCronet 358 @OnlyRunNativeCronet
340 public void testShutdown() throws Exception { 359 public void testShutdown() throws Exception {
341 final CronetTestFramework testFramework = startCronetTestFramework(); 360 final CronetTestFramework testFramework = startCronetTestFramework();
342 ShutdownTestUrlRequestCallback callback = 361 ShutdownTestUrlRequestCallback callback =
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 1466 TestUrlRequestCallback callback = new TestUrlRequestCallback();
1448 URL requestUrl = 1467 URL requestUrl =
1449 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile()); 1468 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile());
1450 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(requestUrl .toString(), 1469 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(requestUrl .toString(),
1451 callback, callback.getExecutor(), testFramework.mCronetEngine); 1470 callback, callback.getExecutor(), testFramework.mCronetEngine);
1452 urlRequestBuilder.build().start(); 1471 urlRequestBuilder.build().start();
1453 callback.blockForDone(); 1472 callback.blockForDone();
1454 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 1473 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
1455 } 1474 }
1456 } 1475 }
OLDNEW
« no previous file with comments | « components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java ('k') | net/nqe/network_quality.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698