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

Unified Diff: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java

Issue 1393713005: [Cronet] Add error code and immediatelyRetryable() to UrlRequestException (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java
index 8c33d769de6fe6d93dd73e96ed7744d482804f0c..80cf0a62f8f867bf34816960424482d04d63ab30 100644
--- a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java
+++ b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestTest.java
@@ -1531,6 +1531,47 @@ public class CronetUrlRequestTest extends CronetTestBase {
assertTrue(urlRequest.isDone());
}
+ /**
+ * Verifies error codes are passed through correctly.
+ */
+ @SmallTest
+ @Feature({"Cronet"})
+ public void testErrorCodes() throws Exception {
+ checkSpecificErrorCode(
+ -105, UrlRequestException.ERROR_HOSTNAME_NOT_RESOLVED, "NAME_NOT_RESOLVED", false);
+ checkSpecificErrorCode(-106, UrlRequestException.ERROR_INTERNET_DISCONNECTED,
+ "INTERNET_DISCONNECTED", false);
+ checkSpecificErrorCode(
+ -21, UrlRequestException.ERROR_NETWORK_CHANGED, "NETWORK_CHANGED", true);
+ checkSpecificErrorCode(
+ -100, UrlRequestException.ERROR_CONNECTION_CLOSED, "CONNECTION_CLOSED", true);
+ checkSpecificErrorCode(
+ -102, UrlRequestException.ERROR_CONNECTION_REFUSED, "CONNECTION_REFUSED", false);
+ checkSpecificErrorCode(
+ -101, UrlRequestException.ERROR_CONNECTION_RESET, "CONNECTION_RESET", true);
+ checkSpecificErrorCode(
+ -118, UrlRequestException.ERROR_CONNECTION_TIMED_OUT, "CONNECTION_TIMED_OUT", true);
+ checkSpecificErrorCode(-7, UrlRequestException.ERROR_TIMED_OUT, "TIMED_OUT", true);
+ checkSpecificErrorCode(
+ -109, UrlRequestException.ERROR_ADDRESS_UNREACHABLE, "ADDRESS_UNREACHABLE", false);
+ checkSpecificErrorCode(-2, UrlRequestException.ERROR_OTHER, "FAILED", false);
+ }
+
+ private void checkSpecificErrorCode(int netError, int errorCode, String name,
+ boolean immediatelyRetryable) throws Exception {
+ TestUrlRequestListener listener = startAndWaitForComplete(
+ MockUrlRequestJobFactory.getMockUrlWithFailure(FailurePhase.START, netError));
+ assertNull(listener.mResponseInfo);
+ assertNotNull(listener.mError);
+ assertEquals(netError, listener.mError.netError());
+ assertEquals(errorCode, listener.mError.getErrorCode());
+ assertEquals(
+ "Exception in CronetUrlRequest: net::ERR_" + name, listener.mError.getMessage());
+ assertEquals(0, listener.mRedirectCount);
+ assertTrue(listener.mOnErrorCalled);
+ assertEquals(listener.mResponseStep, ResponseStep.NOTHING);
+ }
+
// Returns the contents of byteBuffer, from its position() to its limit(),
// as a String. Does not modify byteBuffer's position().
private String bufferContentsToString(ByteBuffer byteBuffer, int start,

Powered by Google App Engine
This is Rietveld 408576698