Skip to content

Commit

Permalink
[Cronet] Replace usage of deprecated UrlRequestException with CronetE…
Browse files Browse the repository at this point in the history
…xception.

Errors reported by native stack use org.chromium.net.NetworkException class.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=143475649
  • Loading branch information
efimki authored and ojw28 committed Jan 4, 2017
1 parent b7c45ce commit 1cd6b93
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import org.chromium.net.CronetEngine;
import org.chromium.net.NetworkException;
import org.chromium.net.UrlRequest;
import org.chromium.net.UrlRequestException;
import org.chromium.net.UrlResponseInfo;
import org.chromium.net.impl.UrlResponseInfoImpl;
import org.junit.Before;
Expand Down Expand Up @@ -99,7 +99,7 @@ public final class CronetDataSourceTest {
@Mock
private Executor mockExecutor;
@Mock
private UrlRequestException mockUrlRequestException;
private NetworkException mockNetworkException;
@Mock private CronetEngine mockCronetEngine;

private CronetDataSource dataSourceUnderTest;
Expand Down Expand Up @@ -172,7 +172,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
dataSourceUnderTest.onFailed(
mockUrlRequest,
testUrlResponseInfo,
mockUrlRequestException);
mockNetworkException);
dataSourceUnderTest.onResponseStarted(
mockUrlRequest2,
testUrlResponseInfo);
Expand Down Expand Up @@ -245,8 +245,8 @@ public void testRequestOpenFail() {
@Test
public void testRequestOpenFailDueToDnsFailure() {
mockResponseStartFailure();
when(mockUrlRequestException.getErrorCode()).thenReturn(
UrlRequestException.ERROR_HOSTNAME_NOT_RESOLVED);
when(mockNetworkException.getErrorCode()).thenReturn(
NetworkException.ERROR_HOSTNAME_NOT_RESOLVED);

try {
dataSourceUnderTest.open(testDataSpec);
Expand Down Expand Up @@ -726,7 +726,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
dataSourceUnderTest.onFailed(
mockUrlRequest,
createUrlResponseInfo(500), // statusCode
mockUrlRequestException);
mockNetworkException);
return null;
}
}).when(mockUrlRequest).start();
Expand Down Expand Up @@ -762,7 +762,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
dataSourceUnderTest.onFailed(
mockUrlRequest,
createUrlResponseInfo(500), // statusCode
mockUrlRequestException);
mockNetworkException);
return null;
}
}).when(mockUrlRequest).read(any(ByteBuffer.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.chromium.net.CronetEngine;
import org.chromium.net.CronetException;
import org.chromium.net.NetworkException;
import org.chromium.net.UrlRequest;
import org.chromium.net.UrlRequest.Status;
import org.chromium.net.UrlRequestException;
import org.chromium.net.UrlResponseInfo;

/**
Expand Down Expand Up @@ -394,12 +395,17 @@ public synchronized void onSucceeded(UrlRequest request, UrlResponseInfo info) {

@Override
public synchronized void onFailed(UrlRequest request, UrlResponseInfo info,
UrlRequestException error) {
CronetException error) {
if (request != currentUrlRequest) {
return;
}
exception = error.getErrorCode() == UrlRequestException.ERROR_HOSTNAME_NOT_RESOLVED
? new UnknownHostException() : error;
if (error instanceof NetworkException
&& ((NetworkException) error).getErrorCode()
== NetworkException.ERROR_HOSTNAME_NOT_RESOLVED) {
exception = new UnknownHostException();
} else {
exception = error;
}
operation.open();
}

Expand Down

0 comments on commit 1cd6b93

Please sign in to comment.