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.os.ConditionVariable; | 7 import android.os.ConditionVariable; |
8 import android.os.StrictMode; | |
8 import android.test.MoreAsserts; | 9 import android.test.MoreAsserts; |
9 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
10 import android.util.Log; | 11 import android.util.Log; |
11 | 12 |
12 import org.chromium.base.test.util.Feature; | 13 import org.chromium.base.test.util.Feature; |
13 import org.chromium.net.TestUrlRequestCallback.FailureType; | 14 import org.chromium.net.TestUrlRequestCallback.FailureType; |
14 import org.chromium.net.TestUrlRequestCallback.ResponseStep; | 15 import org.chromium.net.TestUrlRequestCallback.ResponseStep; |
15 import org.chromium.net.impl.CronetUrlRequest; | 16 import org.chromium.net.impl.CronetUrlRequest; |
16 import org.chromium.net.test.FailurePhase; | 17 import org.chromium.net.test.FailurePhase; |
17 | 18 |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
821 callback.setAutoAdvance(true); | 822 callback.setAutoAdvance(true); |
822 ByteBuffer readBuffer = ByteBuffer.allocateDirect(5); | 823 ByteBuffer readBuffer = ByteBuffer.allocateDirect(5); |
823 urlRequest.read(readBuffer); | 824 urlRequest.read(readBuffer); |
824 callback.blockForDone(); | 825 callback.blockForDone(); |
825 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 826 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
826 assertEquals("GET", callback.mResponseAsString); | 827 assertEquals("GET", callback.mResponseAsString); |
827 } | 828 } |
828 | 829 |
829 @SmallTest | 830 @SmallTest |
830 @Feature({"Cronet"}) | 831 @Feature({"Cronet"}) |
832 public void testNoIoInCancel() throws Exception { | |
833 final TestUrlRequestCallback callback = new TestUrlRequestCallback(); | |
834 callback.setAutoAdvance(false); | |
835 final UrlRequest urlRequest = | |
836 new UrlRequest | |
837 .Builder(NativeTestServer.getEchoHeaderURL("blah-header" ), callback, | |
838 callback.getExecutor(), mTestFramework.mCronetEn gine) | |
839 .addHeader("blah-header", "blahblahblah") | |
840 .build(); | |
841 urlRequest.start(); | |
842 callback.waitForNextStep(); | |
843 callback.startNextRead(urlRequest, ByteBuffer.allocateDirect(4)); | |
844 callback.waitForNextStep(); | |
845 StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy(); | |
846 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() | |
847 .detectAll() | |
848 .penaltyDeath() | |
849 .penaltyLog() | |
850 .build()); | |
851 try { | |
852 urlRequest.cancel(); | |
mef
2016/08/25 22:23:54
Do you need to setup something to trigger IO on ca
Charles
2016/08/26 15:58:19
I do set up - this is in the middle of a request w
mef
2016/08/26 16:14:11
Acknowledged.
| |
853 } finally { | |
854 StrictMode.setThreadPolicy(oldPolicy); | |
855 } | |
856 callback.blockForDone(); | |
857 assertEquals(true, callback.mOnCanceledCalled); | |
858 } | |
859 | |
860 @SmallTest | |
861 @Feature({"Cronet"}) | |
831 public void testUnexpectedReads() throws Exception { | 862 public void testUnexpectedReads() throws Exception { |
832 final TestUrlRequestCallback callback = new TestUrlRequestCallback(); | 863 final TestUrlRequestCallback callback = new TestUrlRequestCallback(); |
833 callback.setAutoAdvance(false); | 864 callback.setAutoAdvance(false); |
834 final UrlRequest urlRequest = | 865 final UrlRequest urlRequest = |
835 new UrlRequest.Builder(NativeTestServer.getRedirectURL(), callba ck, | 866 new UrlRequest.Builder(NativeTestServer.getRedirectURL(), callba ck, |
836 callback.getExecutor(), mTestFramework.mCr onetEngine) | 867 callback.getExecutor(), mTestFramework.mCr onetEngine) |
837 .build(); | 868 .build(); |
838 | 869 |
839 // Try to read before starting request. | 870 // Try to read before starting request. |
840 try { | 871 try { |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1814 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int end) { | 1845 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int end) { |
1815 // Use a duplicate to avoid modifying byteBuffer. | 1846 // Use a duplicate to avoid modifying byteBuffer. |
1816 ByteBuffer duplicate = byteBuffer.duplicate(); | 1847 ByteBuffer duplicate = byteBuffer.duplicate(); |
1817 duplicate.position(start); | 1848 duplicate.position(start); |
1818 duplicate.limit(end); | 1849 duplicate.limit(end); |
1819 byte[] contents = new byte[duplicate.remaining()]; | 1850 byte[] contents = new byte[duplicate.remaining()]; |
1820 duplicate.get(contents); | 1851 duplicate.get(contents); |
1821 return new String(contents); | 1852 return new String(contents); |
1822 } | 1853 } |
1823 } | 1854 } |
OLD | NEW |