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

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

Issue 2045703003: Enable NQE when Cronet Engine is built (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 static org.chromium.base.CollectionUtil.newHashSet; 7 import static org.chromium.base.CollectionUtil.newHashSet;
8 8
9 import android.content.Context; 9 import android.content.Context;
10 import android.content.ContextWrapper; 10 import android.content.ContextWrapper;
11 import android.os.ConditionVariable; 11 import android.os.ConditionVariable;
12 import android.os.Handler; 12 import android.os.Handler;
13 import android.os.Looper; 13 import android.os.Looper;
14 import android.test.suitebuilder.annotation.SmallTest; 14 import android.test.suitebuilder.annotation.SmallTest;
15 import android.util.SparseIntArray;
15 16
16 import org.chromium.base.PathUtils; 17 import org.chromium.base.PathUtils;
17 import org.chromium.base.annotations.JNINamespace; 18 import org.chromium.base.annotations.JNINamespace;
18 import org.chromium.base.test.util.Feature; 19 import org.chromium.base.test.util.Feature;
19 import org.chromium.base.test.util.FlakyTest; 20 import org.chromium.base.test.util.FlakyTest;
20 import org.chromium.net.CronetEngine.UrlRequestInfo; 21 import org.chromium.net.CronetEngine.UrlRequestInfo;
21 import org.chromium.net.TestUrlRequestCallback.ResponseStep; 22 import org.chromium.net.TestUrlRequestCallback.ResponseStep;
22 import org.chromium.net.test.EmbeddedTestServer; 23 import org.chromium.net.test.EmbeddedTestServer;
23 24
24 import java.io.BufferedReader; 25 import java.io.BufferedReader;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 126 }
126 } 127 }
127 128
128 static class TestNetworkQualityListener 129 static class TestNetworkQualityListener
129 implements NetworkQualityRttListener, NetworkQualityThroughputListen er { 130 implements NetworkQualityRttListener, NetworkQualityThroughputListen er {
130 // Lock to ensure that observation counts can be updated and read by dif ferent threads. 131 // Lock to ensure that observation counts can be updated and read by dif ferent threads.
131 private final Object mLock = new Object(); 132 private final Object mLock = new Object();
132 private final ConditionVariable mWaitForThroughput; 133 private final ConditionVariable mWaitForThroughput;
133 private int mRttObservationCount; 134 private int mRttObservationCount;
134 private int mThroughputObservationCount; 135 private int mThroughputObservationCount;
136 // Holds the RTT observations counts indexed by source.
137 private SparseIntArray mRttObservationCountBySource = new SparseIntArray ();
135 138
136 TestNetworkQualityListener(ConditionVariable waitForThroughput) { 139 TestNetworkQualityListener(ConditionVariable waitForThroughput) {
137 mWaitForThroughput = waitForThroughput; 140 mWaitForThroughput = waitForThroughput;
138 } 141 }
139 142
140 @Override 143 @Override
141 public void onRttObservation(int rttMs, long when, int source) { 144 public void onRttObservation(int rttMs, long when, int source) {
142 synchronized (mLock) { 145 synchronized (mLock) {
143 mRttObservationCount++; 146 mRttObservationCount++;
147 mRttObservationCountBySource.put(
148 source, mRttObservationCountBySource.get(source) + 1);
144 } 149 }
145 } 150 }
146 151
147 @Override 152 @Override
148 public void onThroughputObservation(int throughputKbps, long when, int s ource) { 153 public void onThroughputObservation(int throughputKbps, long when, int s ource) {
149 synchronized (mLock) { 154 synchronized (mLock) {
150 if (mWaitForThroughput != null) { 155 if (mWaitForThroughput != null) {
151 mWaitForThroughput.open(); 156 mWaitForThroughput.open();
152 } 157 }
153 mThroughputObservationCount++; 158 mThroughputObservationCount++;
154 } 159 }
155 } 160 }
156 161
157 public int rttObservationCount() { 162 public int rttObservationCount() {
158 synchronized (mLock) { 163 synchronized (mLock) {
159 return mRttObservationCount; 164 return mRttObservationCount;
160 } 165 }
161 } 166 }
162 167
168 public int rttObservationCount(int source) {
169 synchronized (mLock) {
170 return mRttObservationCountBySource.get(source);
171 }
172 }
173
163 public int throughputObservationCount() { 174 public int throughputObservationCount() {
164 synchronized (mLock) { 175 synchronized (mLock) {
165 return mThroughputObservationCount; 176 return mThroughputObservationCount;
166 } 177 }
167 } 178 }
168 } 179 }
169 180
170 @SmallTest 181 @SmallTest
171 @Feature({"Cronet"}) 182 @Feature({"Cronet"})
172 public void testConfigUserAgent() throws Exception { 183 public void testConfigUserAgent() throws Exception {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // Proxy logic configured to use the test server as its proxy. 244 // Proxy logic configured to use the test server as its proxy.
234 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); 245 assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
235 assertEquals(serverHostPort, callback.mResponseInfo.getProxyServer()); 246 assertEquals(serverHostPort, callback.mResponseInfo.getProxyServer());
236 assertEquals("http://DomainThatDoesnt.Resolve/datareductionproxysuccess. txt", 247 assertEquals("http://DomainThatDoesnt.Resolve/datareductionproxysuccess. txt",
237 callback.mResponseInfo.getUrl()); 248 callback.mResponseInfo.getUrl());
238 } 249 }
239 250
240 @SmallTest 251 @SmallTest
241 @Feature({"Cronet"}) 252 @Feature({"Cronet"})
242 public void testRealTimeNetworkQualityObservationsNotEnabled() throws Except ion { 253 public void testRealTimeNetworkQualityObservationsNotEnabled() throws Except ion {
254 CronetEngine.Builder mCronetEngineBuilder = new CronetEngine.Builder(get Context());
255 mCronetEngineBuilder.enableHTTP2(true).enableQUIC(false).enableNetworkQu alityEstimator(
bengr 2016/06/07 20:53:16 You shouldn't have to call enableNetworkQualityEst
tbansal1 2016/06/07 21:37:17 Done.
256 false, null);
257 mTestFramework =
258 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder);
259 TestNetworkQualityListener networkQualityListener = new TestNetworkQuali tyListener(null);
260 try {
261 mTestFramework.mCronetEngine.addRttListener(networkQualityListener);
262 fail("Should throw an exception.");
263 } catch (IllegalStateException e) {
264 }
265 try {
266 mTestFramework.mCronetEngine.addThroughputListener(networkQualityLis tener);
267 fail("Should throw an exception.");
268 } catch (IllegalStateException e) {
269 }
270 TestUrlRequestCallback callback = new TestUrlRequestCallback();
271 UrlRequest urlRequest =
272 mTestFramework.mCronetEngine.createRequest(mUrl, callback, callb ack.getExecutor());
273 urlRequest.start();
274 callback.blockForDone();
275 assertEquals(0, networkQualityListener.rttObservationCount());
276 assertEquals(0, networkQualityListener.throughputObservationCount());
277 mTestFramework.mCronetEngine.shutdown();
278 }
279
280 @SmallTest
281 @Feature({"Cronet"})
282 public void testRealTimeNetworkQualityObservationsNotEnabled_LegacyAPI() thr ows Exception {
243 mTestFramework = startCronetTestFramework(); 283 mTestFramework = startCronetTestFramework();
244 TestNetworkQualityListener networkQualityListener = new TestNetworkQuali tyListener(null); 284 TestNetworkQualityListener networkQualityListener = new TestNetworkQuali tyListener(null);
245 try { 285 try {
246 mTestFramework.mCronetEngine.addRttListener(networkQualityListener); 286 mTestFramework.mCronetEngine.addRttListener(networkQualityListener);
247 fail("Should throw an exception."); 287 fail("Should throw an exception.");
248 } catch (IllegalStateException e) { 288 } catch (IllegalStateException e) {
249 } 289 }
250 try { 290 try {
251 mTestFramework.mCronetEngine.addThroughputListener(networkQualityLis tener); 291 mTestFramework.mCronetEngine.addThroughputListener(networkQualityLis tener);
252 fail("Should throw an exception."); 292 fail("Should throw an exception.");
253 } catch (IllegalStateException e) { 293 } catch (IllegalStateException e) {
254 } 294 }
255 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 295 TestUrlRequestCallback callback = new TestUrlRequestCallback();
256 UrlRequest urlRequest = 296 UrlRequest urlRequest =
257 mTestFramework.mCronetEngine.createRequest(mUrl, callback, callb ack.getExecutor()); 297 mTestFramework.mCronetEngine.createRequest(mUrl, callback, callb ack.getExecutor());
258 urlRequest.start(); 298 urlRequest.start();
259 callback.blockForDone(); 299 callback.blockForDone();
260 assertEquals(0, networkQualityListener.rttObservationCount()); 300 assertEquals(0, networkQualityListener.rttObservationCount());
261 assertEquals(0, networkQualityListener.throughputObservationCount()); 301 assertEquals(0, networkQualityListener.throughputObservationCount());
262 mTestFramework.mCronetEngine.shutdown(); 302 mTestFramework.mCronetEngine.shutdown();
263 } 303 }
264 304
265 @SmallTest 305 @SmallTest
266 @Feature({"Cronet"}) 306 @Feature({"Cronet"})
267 public void testRealTimeNetworkQualityObservationsListenerRemoved() throws E xception { 307 public void testRealTimeNetworkQualityObservationsListenerRemoved() throws E xception {
308 CronetEngine.Builder mCronetEngineBuilder = new CronetEngine.Builder(get Context());
309 TestExecutor mNetworkQualityExecutor = new TestExecutor();
310 mCronetEngineBuilder.enableHTTP2(true).enableQUIC(false).enableNetworkQu alityEstimator(
311 true, mNetworkQualityExecutor);
312 mTestFramework =
313 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder);
314 TestNetworkQualityListener networkQualityListener = new TestNetworkQuali tyListener(null);
315 mTestFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting( true, true);
316 mTestFramework.mCronetEngine.addRttListener(networkQualityListener);
317 mTestFramework.mCronetEngine.addThroughputListener(networkQualityListene r);
318 mTestFramework.mCronetEngine.removeRttListener(networkQualityListener);
319 mTestFramework.mCronetEngine.removeThroughputListener(networkQualityList ener);
320 TestUrlRequestCallback callback = new TestUrlRequestCallback();
321 UrlRequest urlRequest =
322 mTestFramework.mCronetEngine.createRequest(mUrl, callback, callb ack.getExecutor());
323 urlRequest.start();
324 callback.blockForDone();
325 mNetworkQualityExecutor.runAllTasks();
326 assertEquals(0, networkQualityListener.rttObservationCount());
327 assertEquals(0, networkQualityListener.throughputObservationCount());
328 mTestFramework.mCronetEngine.shutdown();
329 }
330
331 @SmallTest
332 @Feature({"Cronet"})
333 public void testRealTimeNetworkQualityObservationsListenerRemoved_LegacyAPI( ) throws Exception {
268 mTestFramework = startCronetTestFramework(); 334 mTestFramework = startCronetTestFramework();
269 TestExecutor testExecutor = new TestExecutor(); 335 TestExecutor testExecutor = new TestExecutor();
270 TestNetworkQualityListener networkQualityListener = new TestNetworkQuali tyListener(null); 336 TestNetworkQualityListener networkQualityListener = new TestNetworkQuali tyListener(null);
271 mTestFramework.mCronetEngine.enableNetworkQualityEstimatorForTesting( 337 mTestFramework.mCronetEngine.enableNetworkQualityEstimator(testExecutor) ;
272 true, true, testExecutor); 338 mTestFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting( true, true);
273 mTestFramework.mCronetEngine.addRttListener(networkQualityListener); 339 mTestFramework.mCronetEngine.addRttListener(networkQualityListener);
274 mTestFramework.mCronetEngine.addThroughputListener(networkQualityListene r); 340 mTestFramework.mCronetEngine.addThroughputListener(networkQualityListene r);
275 mTestFramework.mCronetEngine.removeRttListener(networkQualityListener); 341 mTestFramework.mCronetEngine.removeRttListener(networkQualityListener);
276 mTestFramework.mCronetEngine.removeThroughputListener(networkQualityList ener); 342 mTestFramework.mCronetEngine.removeThroughputListener(networkQualityList ener);
277 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 343 TestUrlRequestCallback callback = new TestUrlRequestCallback();
278 UrlRequest urlRequest = 344 UrlRequest urlRequest =
279 mTestFramework.mCronetEngine.createRequest(mUrl, callback, callb ack.getExecutor()); 345 mTestFramework.mCronetEngine.createRequest(mUrl, callback, callb ack.getExecutor());
280 urlRequest.start(); 346 urlRequest.start();
281 callback.blockForDone(); 347 callback.blockForDone();
282 testExecutor.runAllTasks(); 348 testExecutor.runAllTasks();
283 assertEquals(0, networkQualityListener.rttObservationCount()); 349 assertEquals(0, networkQualityListener.rttObservationCount());
284 assertEquals(0, networkQualityListener.throughputObservationCount()); 350 assertEquals(0, networkQualityListener.throughputObservationCount());
285 mTestFramework.mCronetEngine.shutdown(); 351 mTestFramework.mCronetEngine.shutdown();
286 } 352 }
287 353
288 @SmallTest 354 @SmallTest
289 @Feature({"Cronet"}) 355 @Feature({"Cronet"})
290 public void testRealTimeNetworkQualityObservations() throws Exception { 356 public void testRealTimeNetworkQualityObservationsWithoutQuic() throws Excep tion {
357 CronetEngine.Builder mCronetEngineBuilder = new CronetEngine.Builder(get Context());
358 Executor networkQualityExecutor = Executors.newSingleThreadExecutor();
359 mCronetEngineBuilder.enableHTTP2(true).enableQUIC(false).enableNetworkQu alityEstimator(
360 true, networkQualityExecutor);
361 mTestFramework =
362 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder);
363 ConditionVariable waitForThroughput = new ConditionVariable();
364 TestNetworkQualityListener networkQualityListener =
365 new TestNetworkQualityListener(waitForThroughput);
366 mTestFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting( true, true);
367 mTestFramework.mCronetEngine.addRttListener(networkQualityListener);
368 mTestFramework.mCronetEngine.addThroughputListener(networkQualityListene r);
369 TestUrlRequestCallback callback = new TestUrlRequestCallback();
370 UrlRequest urlRequest =
371 mTestFramework.mCronetEngine.createRequest(mUrl, callback, callb ack.getExecutor());
372 urlRequest.start();
373 callback.blockForDone();
374
375 // Throughput observation is posted to the network quality estimator on the network thread
376 // after the UrlRequest is completed. The observations are then eventual ly posted to
377 // throughput listeners on the executor provided to network quality.
378 waitForThroughput.block();
379 assertTrue(networkQualityListener.throughputObservationCount() > 0);
380
381 // Check RTT observation count after throughput observation has been rec eived. This ensures
382 // that executor has finished posting the RTT observation to the RTT lis teners.
383 assertTrue(networkQualityListener.rttObservationCount() > 0);
384
385 // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST
386 assertTrue(networkQualityListener.rttObservationCount(0) > 0);
387
388 // NETWORK_QUALITY_OBSERVATION_SOURCE_TCP
389 assertTrue(networkQualityListener.rttObservationCount(1) > 0);
390
391 // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC
392 assertEquals(0, networkQualityListener.rttObservationCount(2));
393
394 mTestFramework.mCronetEngine.shutdown();
395 }
396
397 @SmallTest
398 @Feature({"Cronet"})
399 public void testRealTimeNetworkQualityObservations_LegacyAPI() throws Except ion {
291 mTestFramework = startCronetTestFramework(); 400 mTestFramework = startCronetTestFramework();
292 Executor executor = Executors.newSingleThreadExecutor(); 401 Executor executor = Executors.newSingleThreadExecutor();
293 ConditionVariable waitForThroughput = new ConditionVariable(); 402 ConditionVariable waitForThroughput = new ConditionVariable();
294 TestNetworkQualityListener networkQualityListener = 403 TestNetworkQualityListener networkQualityListener =
295 new TestNetworkQualityListener(waitForThroughput); 404 new TestNetworkQualityListener(waitForThroughput);
296 mTestFramework.mCronetEngine.enableNetworkQualityEstimatorForTesting(tru e, true, executor); 405 mTestFramework.mCronetEngine.enableNetworkQualityEstimator(executor);
406 mTestFramework.mCronetEngine.configureNetworkQualityEstimatorForTesting( true, true);
297 mTestFramework.mCronetEngine.addRttListener(networkQualityListener); 407 mTestFramework.mCronetEngine.addRttListener(networkQualityListener);
298 mTestFramework.mCronetEngine.addThroughputListener(networkQualityListene r); 408 mTestFramework.mCronetEngine.addThroughputListener(networkQualityListene r);
299 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 409 TestUrlRequestCallback callback = new TestUrlRequestCallback();
300 UrlRequest urlRequest = 410 UrlRequest urlRequest =
301 mTestFramework.mCronetEngine.createRequest(mUrl, callback, callb ack.getExecutor()); 411 mTestFramework.mCronetEngine.createRequest(mUrl, callback, callb ack.getExecutor());
302 urlRequest.start(); 412 urlRequest.start();
303 callback.blockForDone(); 413 callback.blockForDone();
304 414
305 // Throughput observation is posted to the network quality estimator on the network thread 415 // Throughput observation is posted to the network quality estimator on the network thread
306 // after the UrlRequest is completed. The observations are then eventual ly posted to 416 // after the UrlRequest is completed. The observations are then eventual ly posted to
(...skipping 17 matching lines...) Expand all
324 assertNull("onRequestFinished called repeatedly", mRequestInfo); 434 assertNull("onRequestFinished called repeatedly", mRequestInfo);
325 assertNotNull(requestInfo); 435 assertNotNull(requestInfo);
326 mRequestInfo = requestInfo; 436 mRequestInfo = requestInfo;
327 } 437 }
328 } 438 }
329 439
330 @SmallTest 440 @SmallTest
331 @Feature({"Cronet"}) 441 @Feature({"Cronet"})
332 @SuppressWarnings("deprecation") 442 @SuppressWarnings("deprecation")
333 public void testRequestFinishedListener() throws Exception { 443 public void testRequestFinishedListener() throws Exception {
444 CronetEngine.Builder mCronetEngineBuilder = new CronetEngine.Builder(get Context());
445 TestExecutor mNetworkQualityExecutor = new TestExecutor();
446 mCronetEngineBuilder.enableHTTP2(true).enableQUIC(false).enableNetworkQu alityEstimator(
447 true, mNetworkQualityExecutor);
448 mTestFramework =
449 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder);
450 TestRequestFinishedListener requestFinishedListener = new TestRequestFin ishedListener();
451 mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedL istener);
452 TestUrlRequestCallback callback = new TestUrlRequestCallback();
453 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
454 mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEn gine);
455 urlRequestBuilder.addRequestAnnotation("request annotation")
456 .addRequestAnnotation(this)
457 .build()
458 .start();
459 callback.blockForDone();
460 mNetworkQualityExecutor.runAllTasks();
461
462 CronetEngine.UrlRequestInfo requestInfo = requestFinishedListener.mReque stInfo;
463 assertNotNull("RequestFinishedListener must be called", requestInfo);
464 assertEquals(mUrl, requestInfo.getUrl());
465 assertNotNull(requestInfo.getResponseInfo());
466 assertEquals(newHashSet("request annotation", this), // Use sets for uno rdered comparison.
467 new HashSet<Object>(requestInfo.getAnnotations()));
468 CronetEngine.UrlRequestMetrics metrics = requestInfo.getMetrics();
469 assertNotNull("UrlRequestInfo.getMetrics() must not be null", metrics);
470 assertTrue(metrics.getTotalTimeMs() > 0);
471 assertTrue(metrics.getTotalTimeMs() >= metrics.getTtfbMs());
472 assertTrue(metrics.getReceivedBytesCount() > 0);
473 mTestFramework.mCronetEngine.shutdown();
474 }
475
476 @SmallTest
477 @Feature({"Cronet"})
478 @SuppressWarnings("deprecation")
479 public void testRequestFinishedListener_LegacyAPI() throws Exception {
334 mTestFramework = startCronetTestFramework(); 480 mTestFramework = startCronetTestFramework();
335 TestExecutor testExecutor = new TestExecutor(); 481 TestExecutor testExecutor = new TestExecutor();
336 TestRequestFinishedListener requestFinishedListener = new TestRequestFin ishedListener(); 482 TestRequestFinishedListener requestFinishedListener = new TestRequestFin ishedListener();
337 mTestFramework.mCronetEngine.enableNetworkQualityEstimator(testExecutor) ; 483 mTestFramework.mCronetEngine.enableNetworkQualityEstimator(testExecutor) ;
338 mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedL istener); 484 mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedL istener);
339 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 485 TestUrlRequestCallback callback = new TestUrlRequestCallback();
340 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( 486 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
341 mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEn gine); 487 mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEn gine);
342 urlRequestBuilder.addRequestAnnotation("request annotation") 488 urlRequestBuilder.addRequestAnnotation("request annotation")
343 .addRequestAnnotation(this) 489 .addRequestAnnotation(this)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 assertTrue(metrics.getTotalTimeMs() > 0); 536 assertTrue(metrics.getTotalTimeMs() > 0);
391 assertNull(metrics.getTtfbMs()); 537 assertNull(metrics.getTtfbMs());
392 assertTrue(metrics.getReceivedBytesCount() == null || metrics.getReceive dBytesCount() == 0); 538 assertTrue(metrics.getReceivedBytesCount() == null || metrics.getReceive dBytesCount() == 0);
393 mTestFramework.mCronetEngine.shutdown(); 539 mTestFramework.mCronetEngine.shutdown();
394 } 540 }
395 541
396 @SmallTest 542 @SmallTest
397 @Feature({"Cronet"}) 543 @Feature({"Cronet"})
398 @SuppressWarnings("deprecation") 544 @SuppressWarnings("deprecation")
399 public void testRequestFinishedListenerRemoved() throws Exception { 545 public void testRequestFinishedListenerRemoved() throws Exception {
546 CronetEngine.Builder mCronetEngineBuilder = new CronetEngine.Builder(get Context());
547 TestExecutor mNetworkQualityExecutor = new TestExecutor();
548 mCronetEngineBuilder.enableHTTP2(true).enableQUIC(false).enableNetworkQu alityEstimator(
549 true, mNetworkQualityExecutor);
550 mTestFramework =
551 startCronetTestFrameworkWithUrlAndCronetEngineBuilder(null, mCro netEngineBuilder);
552 TestRequestFinishedListener requestFinishedListener = new TestRequestFin ishedListener();
553 mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedL istener);
554 mTestFramework.mCronetEngine.removeRequestFinishedListener(requestFinish edListener);
555 TestUrlRequestCallback callback = new TestUrlRequestCallback();
556 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
557 mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEn gine);
558 urlRequestBuilder.build().start();
559 callback.blockForDone();
560 mNetworkQualityExecutor.runAllTasks();
561
562 assertNull(
563 "RequestFinishedListener must not be called", requestFinishedLis tener.mRequestInfo);
564 mTestFramework.mCronetEngine.shutdown();
565 }
566
567 @SmallTest
568 @Feature({"Cronet"})
569 @SuppressWarnings("deprecation")
570 public void testRequestFinishedListenerRemoved_LegacyAPI() throws Exception {
400 mTestFramework = startCronetTestFramework(); 571 mTestFramework = startCronetTestFramework();
401 TestExecutor testExecutor = new TestExecutor(); 572 TestExecutor testExecutor = new TestExecutor();
402 TestRequestFinishedListener requestFinishedListener = new TestRequestFin ishedListener(); 573 TestRequestFinishedListener requestFinishedListener = new TestRequestFin ishedListener();
403 mTestFramework.mCronetEngine.enableNetworkQualityEstimator(testExecutor) ; 574 mTestFramework.mCronetEngine.enableNetworkQualityEstimator(testExecutor) ;
404 mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedL istener); 575 mTestFramework.mCronetEngine.addRequestFinishedListener(requestFinishedL istener);
405 mTestFramework.mCronetEngine.removeRequestFinishedListener(requestFinish edListener); 576 mTestFramework.mCronetEngine.removeRequestFinishedListener(requestFinish edListener);
406 TestUrlRequestCallback callback = new TestUrlRequestCallback(); 577 TestUrlRequestCallback callback = new TestUrlRequestCallback();
407 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder( 578 UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(
408 mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEn gine); 579 mUrl, callback, callback.getExecutor(), mTestFramework.mCronetEn gine);
409 urlRequestBuilder.build().start(); 580 urlRequestBuilder.build().start();
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 } 1339 }
1169 }.start(); 1340 }.start();
1170 otherThreadDone.block(); 1341 otherThreadDone.block();
1171 builder.build().shutdown(); 1342 builder.build().shutdown();
1172 uiThreadDone.open(); 1343 uiThreadDone.open();
1173 } 1344 }
1174 }); 1345 });
1175 assertTrue(uiThreadDone.block(1000)); 1346 assertTrue(uiThreadDone.block(1000));
1176 } 1347 }
1177 } 1348 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698