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

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

Issue 2671233003: NQE: Always read prefs in cronet (Closed)
Patch Set: ps Created 3 years, 10 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.support.test.filters.SmallTest; 13 import android.support.test.filters.SmallTest;
14 14
15 import org.json.JSONObject; 15 import org.json.JSONObject;
16 16
17 import static org.chromium.net.CronetEngine.Builder.HTTP_CACHE_IN_MEMORY; 17 import static org.chromium.net.CronetEngine.Builder.HTTP_CACHE_IN_MEMORY;
18 18
19 import org.chromium.base.FileUtils; 19 import org.chromium.base.FileUtils;
20 import org.chromium.base.Log; 20 import org.chromium.base.Log;
21 import org.chromium.base.PathUtils; 21 import org.chromium.base.PathUtils;
22 import org.chromium.base.annotations.JNINamespace; 22 import org.chromium.base.annotations.JNINamespace;
23 import org.chromium.base.annotations.SuppressFBWarnings; 23 import org.chromium.base.annotations.SuppressFBWarnings;
24 import org.chromium.base.test.util.Feature; 24 import org.chromium.base.test.util.Feature;
25 import org.chromium.base.test.util.MetricsUtils.HistogramDelta;
25 import org.chromium.net.MetricsTestUtil.TestExecutor; 26 import org.chromium.net.MetricsTestUtil.TestExecutor;
26 import org.chromium.net.TestUrlRequestCallback.ResponseStep; 27 import org.chromium.net.TestUrlRequestCallback.ResponseStep;
27 import org.chromium.net.impl.CronetEngineBase; 28 import org.chromium.net.impl.CronetEngineBase;
28 import org.chromium.net.impl.CronetEngineBuilderImpl; 29 import org.chromium.net.impl.CronetEngineBuilderImpl;
29 import org.chromium.net.impl.CronetLibraryLoader; 30 import org.chromium.net.impl.CronetLibraryLoader;
30 import org.chromium.net.impl.CronetUrlRequestContext; 31 import org.chromium.net.impl.CronetUrlRequestContext;
31 import org.chromium.net.test.EmbeddedTestServer; 32 import org.chromium.net.test.EmbeddedTestServer;
32 33
33 import java.io.BufferedReader; 34 import java.io.BufferedReader;
34 import java.io.File; 35 import java.io.File;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 mCronetEngineBuilder.enableNetworkQualityEstimator(true).enableHttp2(tru e).enableQuic( 317 mCronetEngineBuilder.enableNetworkQualityEstimator(true).enableHttp2(tru e).enableQuic(
317 false); 318 false);
318 mCronetEngineBuilder.setStoragePath(CronetTestFramework.getTestStorage(g etContext())); 319 mCronetEngineBuilder.setStoragePath(CronetTestFramework.getTestStorage(g etContext()));
319 final CronetTestFramework testFramework = 320 final CronetTestFramework testFramework =
320 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder); 321 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder);
321 testFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting(t rue, true, true); 322 testFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting(t rue, true, true);
322 323
323 testFramework.mCronetEngine.addRttListener(rttListener); 324 testFramework.mCronetEngine.addRttListener(rttListener);
324 testFramework.mCronetEngine.addThroughputListener(throughputListener); 325 testFramework.mCronetEngine.addThroughputListener(throughputListener);
325 326
327 HistogramDelta writeCountHistogram = new HistogramDelta("NQE.Prefs.Write Count", 1);
328 assertEquals(0, writeCountHistogram.getDelta()); // Sanity check.
329
330 HistogramDelta readCountHistogram = new HistogramDelta("NQE.Prefs.ReadCo unt", 1);
331 assertEquals(0, readCountHistogram.getDelta()); // Sanity check.
332
326 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 333 TestUrlRequestCallback callback = new TestUrlRequestCallback();
327 UrlRequest.Builder builder = testFramework.mCronetEngine.newUrlRequestBu ilder( 334 UrlRequest.Builder builder = testFramework.mCronetEngine.newUrlRequestBu ilder(
328 mUrl, callback, callback.getExecutor()); 335 mUrl, callback, callback.getExecutor());
329 UrlRequest urlRequest = builder.build(); 336 UrlRequest urlRequest = builder.build();
330 urlRequest.start(); 337 urlRequest.start();
331 callback.blockForDone(); 338 callback.blockForDone();
332 339
333 // Throughput observation is posted to the network quality estimator on the network thread 340 // Throughput observation is posted to the network quality estimator on the network thread
334 // after the UrlRequest is completed. The observations are then eventual ly posted to 341 // after the UrlRequest is completed. The observations are then eventual ly posted to
335 // throughput listeners on the executor provided to network quality. 342 // throughput listeners on the executor provided to network quality.
336 waitForThroughput.block(); 343 waitForThroughput.block();
337 assertTrue(throughputListener.throughputObservationCount() > 0); 344 assertTrue(throughputListener.throughputObservationCount() > 0);
338 345
346 // Prefs must be read at startup.
347 assertTrue(readCountHistogram.getDelta() > 0);
348
339 // Check RTT observation count after throughput observation has been rec eived. This ensures 349 // Check RTT observation count after throughput observation has been rec eived. This ensures
340 // that executor has finished posting the RTT observation to the RTT lis teners. 350 // that executor has finished posting the RTT observation to the RTT lis teners.
341 assertTrue(rttListener.rttObservationCount() > 0); 351 assertTrue(rttListener.rttObservationCount() > 0);
342 352
343 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST 353 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST
344 assertTrue(rttListener.rttObservationCount(0) > 0); 354 assertTrue(rttListener.rttObservationCount(0) > 0);
345 355
346 // NETWORK_QUALITY_OBSERVATION_SOURCE_TCP 356 // NETWORK_QUALITY_OBSERVATION_SOURCE_TCP
347 assertTrue(rttListener.rttObservationCount(1) > 0); 357 assertTrue(rttListener.rttObservationCount(1) > 0);
348 358
(...skipping 11 matching lines...) Expand all
360 370
361 // Verify that the HTTP RTT, transport RTT and downstream throughput 371 // Verify that the HTTP RTT, transport RTT and downstream throughput
362 // estimates are available. 372 // estimates are available.
363 assertTrue(testFramework.mCronetEngine.getHttpRttMs() >= 0); 373 assertTrue(testFramework.mCronetEngine.getHttpRttMs() >= 0);
364 assertTrue(testFramework.mCronetEngine.getTransportRttMs() >= 0); 374 assertTrue(testFramework.mCronetEngine.getTransportRttMs() >= 0);
365 assertTrue(testFramework.mCronetEngine.getDownstreamThroughputKbps() >= 0); 375 assertTrue(testFramework.mCronetEngine.getDownstreamThroughputKbps() >= 0);
366 376
367 // Verify that the cached estimates were written to the prefs. 377 // Verify that the cached estimates were written to the prefs.
368 while (true) { 378 while (true) {
369 Log.i(TAG, "Still waiting for pref file update....."); 379 Log.i(TAG, "Still waiting for pref file update.....");
370 Thread.sleep(10000); 380 Thread.sleep(12000);
371 try { 381 try {
372 if (fileContainsString("local_prefs.json", "network_qualities")) { 382 if (fileContainsString("local_prefs.json", "network_qualities")) {
373 break; 383 break;
374 } 384 }
375 } catch (FileNotFoundException e) { 385 } catch (FileNotFoundException e) {
376 // Ignored this exception since the file will only be created wh en updates are 386 // Ignored this exception since the file will only be created wh en updates are
377 // flushed to the disk. 387 // flushed to the disk.
378 } 388 }
379 } 389 }
380 assertTrue(fileContainsString("local_prefs.json", "network_qualities")); 390 assertTrue(fileContainsString("local_prefs.json", "network_qualities"));
381 391
382 testFramework.mCronetEngine.shutdown(); 392 testFramework.mCronetEngine.shutdown();
393 assertTrue(writeCountHistogram.getDelta() > 0);
383 } 394 }
384 395
385 @SmallTest 396 @SmallTest
386 @Feature({"Cronet"}) 397 @Feature({"Cronet"})
387 // TODO: Remove the annotation after fixing http://crbug.com/637979 & http:/ /crbug.com/637972 398 // TODO: Remove the annotation after fixing http://crbug.com/637979 & http:/ /crbug.com/637972
388 @OnlyRunNativeCronet 399 @OnlyRunNativeCronet
389 public void testShutdown() throws Exception { 400 public void testShutdown() throws Exception {
390 final CronetTestFramework testFramework = startCronetTestFramework(); 401 final CronetTestFramework testFramework = startCronetTestFramework();
391 ShutdownTestUrlRequestCallback callback = 402 ShutdownTestUrlRequestCallback callback =
392 new ShutdownTestUrlRequestCallback(testFramework.mCronetEngine); 403 new ShutdownTestUrlRequestCallback(testFramework.mCronetEngine);
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 1503 TestUrlRequestCallback callback = new TestUrlRequestCallback();
1493 URL requestUrl = 1504 URL requestUrl =
1494 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile()); 1505 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl .getFile());
1495 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder( 1506 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr lRequestBuilder(
1496 requestUrl.toString(), callback, callback.getExecutor()); 1507 requestUrl.toString(), callback, callback.getExecutor());
1497 urlRequestBuilder.build().start(); 1508 urlRequestBuilder.build().start();
1498 callback.blockForDone(); 1509 callback.blockForDone();
1499 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 1510 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
1500 } 1511 }
1501 } 1512 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698