| OLD | NEW |
| 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; |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 callback.blockForDone(); | 548 callback.blockForDone(); |
| 549 assertTrue(callback.mOnErrorCalled); | 549 assertTrue(callback.mOnErrorCalled); |
| 550 callback.blockForCallbackToComplete(); | 550 callback.blockForCallbackToComplete(); |
| 551 callback.shutdownExecutor(); | 551 callback.shutdownExecutor(); |
| 552 } | 552 } |
| 553 | 553 |
| 554 @SmallTest | 554 @SmallTest |
| 555 @Feature({"Cronet"}) | 555 @Feature({"Cronet"}) |
| 556 public void testShutdownAfterCancel() throws Exception { | 556 public void testShutdownAfterCancel() throws Exception { |
| 557 final CronetTestFramework testFramework = startCronetTestFramework(); | 557 final CronetTestFramework testFramework = startCronetTestFramework(); |
| 558 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 558 final ConditionVariable waitForOnCanceled = new ConditionVariable(); |
| 559 TestUrlRequestCallback callback = new TestUrlRequestCallback() { |
| 560 @Override |
| 561 public void onCanceled(UrlRequest request, UrlResponseInfo info) { |
| 562 testFramework.mCronetEngine.shutdown(); |
| 563 waitForOnCanceled.open(); |
| 564 } |
| 565 }; |
| 559 // Block callback when response starts to verify that shutdown fails | 566 // Block callback when response starts to verify that shutdown fails |
| 560 // if there are active requests. | 567 // if there are active requests. |
| 561 callback.setAutoAdvance(false); | 568 callback.setAutoAdvance(false); |
| 562 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr
lRequestBuilder( | 569 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr
lRequestBuilder( |
| 563 mUrl, callback, callback.getExecutor()); | 570 mUrl, callback, callback.getExecutor()); |
| 564 UrlRequest urlRequest = urlRequestBuilder.build(); | 571 UrlRequest urlRequest = urlRequestBuilder.build(); |
| 565 urlRequest.start(); | 572 urlRequest.start(); |
| 566 try { | 573 try { |
| 567 testFramework.mCronetEngine.shutdown(); | 574 testFramework.mCronetEngine.shutdown(); |
| 568 fail("Should throw an exception"); | 575 fail("Should throw an exception"); |
| 569 } catch (Exception e) { | 576 } catch (Exception e) { |
| 570 assertEquals("Cannot shutdown with active requests.", | 577 assertEquals("Cannot shutdown with active requests.", |
| 571 e.getMessage()); | 578 e.getMessage()); |
| 572 } | 579 } |
| 573 callback.waitForNextStep(); | 580 callback.waitForNextStep(); |
| 574 assertEquals(ResponseStep.ON_RESPONSE_STARTED, callback.mResponseStep); | 581 assertEquals(ResponseStep.ON_RESPONSE_STARTED, callback.mResponseStep); |
| 575 urlRequest.cancel(); | 582 urlRequest.cancel(); |
| 576 testFramework.mCronetEngine.shutdown(); | 583 // With crbug.com/710877, embedder can only shut down cronet engine |
| 584 // after onCanceled() callback is called. |
| 585 waitForOnCanceled.block(); |
| 577 } | 586 } |
| 578 | 587 |
| 579 @SmallTest | 588 @SmallTest |
| 580 @Feature({"Cronet"}) | 589 @Feature({"Cronet"}) |
| 581 @OnlyRunNativeCronet // No netlogs for pure java impl | 590 @OnlyRunNativeCronet // No netlogs for pure java impl |
| 582 public void testNetLog() throws Exception { | 591 public void testNetLog() throws Exception { |
| 583 Context context = getContext(); | 592 Context context = getContext(); |
| 584 File directory = new File(PathUtils.getDataDirectory()); | 593 File directory = new File(PathUtils.getDataDirectory()); |
| 585 File file = File.createTempFile("cronet", "json", directory); | 594 File file = File.createTempFile("cronet", "json", directory); |
| 586 CronetEngine cronetEngine = new CronetEngine.Builder(context).build(); | 595 CronetEngine cronetEngine = new CronetEngine.Builder(context).build(); |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1505 TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 1514 TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
| 1506 URL requestUrl = | 1515 URL requestUrl = |
| 1507 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl
.getFile()); | 1516 new URL("http", resolverTestHostname, testUrl.getPort(), testUrl
.getFile()); |
| 1508 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr
lRequestBuilder( | 1517 UrlRequest.Builder urlRequestBuilder = testFramework.mCronetEngine.newUr
lRequestBuilder( |
| 1509 requestUrl.toString(), callback, callback.getExecutor()); | 1518 requestUrl.toString(), callback, callback.getExecutor()); |
| 1510 urlRequestBuilder.build().start(); | 1519 urlRequestBuilder.build().start(); |
| 1511 callback.blockForDone(); | 1520 callback.blockForDone(); |
| 1512 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 1521 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
| 1513 } | 1522 } |
| 1514 } | 1523 } |
| OLD | NEW |