| 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.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
| 9 import android.util.Pair; | 9 import android.util.Pair; |
| 10 | 10 |
| (...skipping 1513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1524 dataProvider.mUploadDataSink.onReadSucceeded(false); | 1524 dataProvider.mUploadDataSink.onReadSucceeded(false); |
| 1525 // Listener.onFailed will be called on request executor even though uplo
ad | 1525 // Listener.onFailed will be called on request executor even though uplo
ad |
| 1526 // executor is shutdown. | 1526 // executor is shutdown. |
| 1527 listener.blockForDone(); | 1527 listener.blockForDone(); |
| 1528 assertTrue(listener.isDone()); | 1528 assertTrue(listener.isDone()); |
| 1529 assertTrue(listener.mOnErrorCalled); | 1529 assertTrue(listener.mOnErrorCalled); |
| 1530 assertEquals("Exception received from UploadDataProvider", listener.mErr
or.getMessage()); | 1530 assertEquals("Exception received from UploadDataProvider", listener.mErr
or.getMessage()); |
| 1531 assertTrue(urlRequest.isDone()); | 1531 assertTrue(urlRequest.isDone()); |
| 1532 } | 1532 } |
| 1533 | 1533 |
| 1534 /** |
| 1535 * Verifies error codes are passed through correctly. |
| 1536 */ |
| 1537 @SmallTest |
| 1538 @Feature({"Cronet"}) |
| 1539 public void testErrorCodes() throws Exception { |
| 1540 checkSpecificErrorCode( |
| 1541 -105, UrlRequestException.ERROR_HOSTNAME_NOT_RESOLVED, "NAME_NOT
_RESOLVED", false); |
| 1542 checkSpecificErrorCode(-106, UrlRequestException.ERROR_INTERNET_DISCONNE
CTED, |
| 1543 "INTERNET_DISCONNECTED", false); |
| 1544 checkSpecificErrorCode( |
| 1545 -21, UrlRequestException.ERROR_NETWORK_CHANGED, "NETWORK_CHANGED
", true); |
| 1546 checkSpecificErrorCode( |
| 1547 -100, UrlRequestException.ERROR_CONNECTION_CLOSED, "CONNECTION_C
LOSED", true); |
| 1548 checkSpecificErrorCode( |
| 1549 -102, UrlRequestException.ERROR_CONNECTION_REFUSED, "CONNECTION_
REFUSED", false); |
| 1550 checkSpecificErrorCode( |
| 1551 -101, UrlRequestException.ERROR_CONNECTION_RESET, "CONNECTION_RE
SET", true); |
| 1552 checkSpecificErrorCode( |
| 1553 -118, UrlRequestException.ERROR_CONNECTION_TIMED_OUT, "CONNECTIO
N_TIMED_OUT", true); |
| 1554 checkSpecificErrorCode(-7, UrlRequestException.ERROR_TIMED_OUT, "TIMED_O
UT", true); |
| 1555 checkSpecificErrorCode( |
| 1556 -109, UrlRequestException.ERROR_ADDRESS_UNREACHABLE, "ADDRESS_UN
REACHABLE", false); |
| 1557 checkSpecificErrorCode(-2, UrlRequestException.ERROR_OTHER, "FAILED", fa
lse); |
| 1558 } |
| 1559 |
| 1560 private void checkSpecificErrorCode(int netError, int errorCode, String name
, |
| 1561 boolean immediatelyRetryable) throws Exception { |
| 1562 TestUrlRequestListener listener = startAndWaitForComplete( |
| 1563 MockUrlRequestJobFactory.getMockUrlWithFailure(FailurePhase.STAR
T, netError)); |
| 1564 assertNull(listener.mResponseInfo); |
| 1565 assertNotNull(listener.mError); |
| 1566 assertEquals(netError, listener.mError.netError()); |
| 1567 assertEquals(errorCode, listener.mError.getErrorCode()); |
| 1568 assertEquals( |
| 1569 "Exception in CronetUrlRequest: net::ERR_" + name, listener.mErr
or.getMessage()); |
| 1570 assertEquals(0, listener.mRedirectCount); |
| 1571 assertTrue(listener.mOnErrorCalled); |
| 1572 assertEquals(listener.mResponseStep, ResponseStep.NOTHING); |
| 1573 } |
| 1574 |
| 1534 // Returns the contents of byteBuffer, from its position() to its limit(), | 1575 // Returns the contents of byteBuffer, from its position() to its limit(), |
| 1535 // as a String. Does not modify byteBuffer's position(). | 1576 // as a String. Does not modify byteBuffer's position(). |
| 1536 private String bufferContentsToString(ByteBuffer byteBuffer, int start, | 1577 private String bufferContentsToString(ByteBuffer byteBuffer, int start, |
| 1537 int end) { | 1578 int end) { |
| 1538 // Use a duplicate to avoid modifying byteBuffer. | 1579 // Use a duplicate to avoid modifying byteBuffer. |
| 1539 ByteBuffer duplicate = byteBuffer.duplicate(); | 1580 ByteBuffer duplicate = byteBuffer.duplicate(); |
| 1540 duplicate.position(start); | 1581 duplicate.position(start); |
| 1541 duplicate.limit(end); | 1582 duplicate.limit(end); |
| 1542 byte[] contents = new byte[duplicate.remaining()]; | 1583 byte[] contents = new byte[duplicate.remaining()]; |
| 1543 duplicate.get(contents); | 1584 duplicate.get(contents); |
| 1544 return new String(contents); | 1585 return new String(contents); |
| 1545 } | 1586 } |
| 1546 } | 1587 } |
| OLD | NEW |