| 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.test.MoreAsserts; | 8 import android.test.MoreAsserts; |
| 9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
| 10 import android.util.Log; | 10 import android.util.Log; |
| (...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 assertEquals("A=B", callback.mResponseInfo.getAllHeaders().get("Set-Cook
ie").get(0)); | 1772 assertEquals("A=B", callback.mResponseInfo.getAllHeaders().get("Set-Cook
ie").get(0)); |
| 1773 | 1773 |
| 1774 // Make a request that check that cookie header isn't sent. | 1774 // Make a request that check that cookie header isn't sent. |
| 1775 String headerName = "Cookie"; | 1775 String headerName = "Cookie"; |
| 1776 String url2 = NativeTestServer.getEchoHeaderURL(headerName); | 1776 String url2 = NativeTestServer.getEchoHeaderURL(headerName); |
| 1777 TestUrlRequestCallback callback2 = startAndWaitForComplete(url2); | 1777 TestUrlRequestCallback callback2 = startAndWaitForComplete(url2); |
| 1778 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode()); | 1778 assertEquals(200, callback2.mResponseInfo.getHttpStatusCode()); |
| 1779 assertEquals("Header not found. :(", callback2.mResponseAsString); | 1779 assertEquals("Header not found. :(", callback2.mResponseAsString); |
| 1780 } | 1780 } |
| 1781 | 1781 |
| 1782 @SmallTest |
| 1783 @Feature({"Cronet"}) |
| 1784 @OnlyRunNativeCronet |
| 1785 public void testQuicErrorCode() throws Exception { |
| 1786 TestUrlRequestCallback callback = |
| 1787 startAndWaitForComplete(MockUrlRequestJobFactory.getMockUrlWithF
ailure( |
| 1788 FailurePhase.START, NetError.ERR_QUIC_PROTOCOL_ERROR)); |
| 1789 assertNull(callback.mResponseInfo); |
| 1790 assertNotNull(callback.mError); |
| 1791 assertEquals( |
| 1792 UrlRequestException.ERROR_QUIC_PROTOCOL_FAILED, callback.mError.
getErrorCode()); |
| 1793 assertTrue(callback.mError instanceof QuicException); |
| 1794 QuicException quicException = (QuicException) callback.mError; |
| 1795 // 1 is QUIC_INTERNAL_ERROR |
| 1796 assertEquals(1, quicException.getQuicDetailedErrorCode()); |
| 1797 } |
| 1798 |
| 1782 private void checkSpecificErrorCode(int netError, int errorCode, String name
, | 1799 private void checkSpecificErrorCode(int netError, int errorCode, String name
, |
| 1783 boolean immediatelyRetryable) throws Exception { | 1800 boolean immediatelyRetryable) throws Exception { |
| 1784 TestUrlRequestCallback callback = startAndWaitForComplete( | 1801 TestUrlRequestCallback callback = startAndWaitForComplete( |
| 1785 MockUrlRequestJobFactory.getMockUrlWithFailure(FailurePhase.STAR
T, netError)); | 1802 MockUrlRequestJobFactory.getMockUrlWithFailure(FailurePhase.STAR
T, netError)); |
| 1786 assertNull(callback.mResponseInfo); | 1803 assertNull(callback.mResponseInfo); |
| 1787 assertNotNull(callback.mError); | 1804 assertNotNull(callback.mError); |
| 1788 assertEquals(netError, callback.mError.getCronetInternalErrorCode()); | 1805 assertEquals(netError, callback.mError.getCronetInternalErrorCode()); |
| 1789 assertEquals(errorCode, callback.mError.getErrorCode()); | 1806 assertEquals(errorCode, callback.mError.getErrorCode()); |
| 1790 assertEquals( | 1807 assertEquals( |
| 1791 "Exception in CronetUrlRequest: net::ERR_" + name, callback.mErr
or.getMessage()); | 1808 "Exception in CronetUrlRequest: net::ERR_" + name, callback.mErr
or.getMessage()); |
| 1792 assertEquals(0, callback.mRedirectCount); | 1809 assertEquals(0, callback.mRedirectCount); |
| 1793 assertTrue(callback.mOnErrorCalled); | 1810 assertTrue(callback.mOnErrorCalled); |
| 1794 assertEquals(callback.mResponseStep, ResponseStep.NOTHING); | 1811 assertEquals(callback.mResponseStep, ResponseStep.NOTHING); |
| 1795 } | 1812 } |
| 1796 | 1813 |
| 1797 // Returns the contents of byteBuffer, from its position() to its limit(), | 1814 // Returns the contents of byteBuffer, from its position() to its limit(), |
| 1798 // as a String. Does not modify byteBuffer's position(). | 1815 // as a String. Does not modify byteBuffer's position(). |
| 1799 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int
end) { | 1816 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int
end) { |
| 1800 // Use a duplicate to avoid modifying byteBuffer. | 1817 // Use a duplicate to avoid modifying byteBuffer. |
| 1801 ByteBuffer duplicate = byteBuffer.duplicate(); | 1818 ByteBuffer duplicate = byteBuffer.duplicate(); |
| 1802 duplicate.position(start); | 1819 duplicate.position(start); |
| 1803 duplicate.limit(end); | 1820 duplicate.limit(end); |
| 1804 byte[] contents = new byte[duplicate.remaining()]; | 1821 byte[] contents = new byte[duplicate.remaining()]; |
| 1805 duplicate.get(contents); | 1822 duplicate.get(contents); |
| 1806 return new String(contents); | 1823 return new String(contents); |
| 1807 } | 1824 } |
| 1808 } | 1825 } |
| OLD | NEW |