Permalink
Browse files

Remove WebWorker support from NetworkingModule

Reviewed By: AaaChiuuu

Differential Revision: D4929251

fbshipit-source-id: fa07bfea64e6f79fd7b8c19889a26caec03cd421
  • Loading branch information...
javache authored and facebook-github-bot committed Apr 25, 2017
1 parent 3e08a28 commit ea93577ff22ffd99a021a8f82d7c2567305435e1
@@ -22,7 +22,6 @@
import android.util.Base64;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ExecutorToken;
import com.facebook.react.bridge.GuardedAsyncTask;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
@@ -52,7 +51,7 @@
/**
* Implements the XMLHttpRequest JavaScript interface.
*/
@ReactModule(name = NetworkingModule.NAME, supportsWebWorkers = true)
@ReactModule(name = NetworkingModule.NAME)
public final class NetworkingModule extends ReactContextBaseJavaModule {
protected static final String NAME = "Networking";
@@ -160,7 +159,6 @@ public void onCatalystInstanceDestroy() {
* @param timeout value of 0 results in no timeout
*/
public void sendRequest(
final ExecutorToken executorToken,
String method,
String url,
final int requestId,
@@ -176,7 +174,7 @@ public void sendRequest(
requestBuilder.tag(requestId);
}
final RCTDeviceEventEmitter eventEmitter = getEventEmitter(executorToken);
final RCTDeviceEventEmitter eventEmitter = getEventEmitter();
OkHttpClient.Builder clientBuilder = mClient.newBuilder();
if (!withCredentials) {
@@ -303,7 +301,7 @@ public void onProgress(long bytesWritten, long contentLength, boolean done) {
}
ReadableArray parts = data.getArray(REQUEST_BODY_KEY_FORMDATA);
MultipartBody.Builder multipartBuilder =
constructMultipartBody(executorToken, parts, contentType, requestId);
constructMultipartBody(parts, contentType, requestId);
if (multipartBuilder == null) {
return;
}
@@ -448,7 +446,7 @@ private static WritableMap translateHeaders(Headers headers) {
}
@ReactMethod
public void abortRequest(ExecutorToken executorToken, final int requestId) {
public void abortRequest(final int requestId) {
cancelRequest(requestId);
removeRequest(requestId);
}
@@ -465,23 +463,15 @@ protected void doInBackgroundGuarded(Void... params) {
}
@ReactMethod
public void clearCookies(
ExecutorToken executorToken,
com.facebook.react.bridge.Callback callback) {
public void clearCookies(com.facebook.react.bridge.Callback callback) {
mCookieHandler.clearCookies(callback);
}
@Override
public boolean supportsWebWorkers() {
return true;
}
private @Nullable MultipartBody.Builder constructMultipartBody(
ExecutorToken ExecutorToken,
ReadableArray body,
String contentType,
int requestId) {
RCTDeviceEventEmitter eventEmitter = getEventEmitter(ExecutorToken);
RCTDeviceEventEmitter eventEmitter = getEventEmitter();
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MediaType.parse(contentType));
@@ -574,8 +564,7 @@ public boolean supportsWebWorkers() {
return headersBuilder.build();
}
private RCTDeviceEventEmitter getEventEmitter(ExecutorToken ExecutorToken) {
return getReactApplicationContext()
.getJSModule(ExecutorToken, RCTDeviceEventEmitter.class);
private RCTDeviceEventEmitter getEventEmitter() {
return getReactApplicationContext().getJSModule(RCTDeviceEventEmitter.class);
}
}
@@ -14,7 +14,6 @@
import java.util.List;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ExecutorToken;
import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.ReactApplicationContext;
@@ -92,7 +91,6 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"GET",
"http://somedomain/foo",
/* requestId */ 0,
@@ -115,7 +113,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
public void testFailGetWithInvalidHeadersStruct() throws Exception {
RCTDeviceEventEmitter emitter = mock(RCTDeviceEventEmitter.class);
ReactApplicationContext context = mock(ReactApplicationContext.class);
when(context.getJSModule(any(ExecutorToken.class), any(Class.class))).thenReturn(emitter);
when(context.getJSModule(any(Class.class))).thenReturn(emitter);
OkHttpClient httpClient = mock(OkHttpClient.class);
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
@@ -128,7 +126,6 @@ public void testFailGetWithInvalidHeadersStruct() throws Exception {
mockEvents();
networkingModule.sendRequest(
mock(ExecutorToken.class),
"GET",
"http://somedoman/foo",
/* requestId */ 0,
@@ -146,7 +143,7 @@ public void testFailGetWithInvalidHeadersStruct() throws Exception {
public void testFailPostWithoutContentType() throws Exception {
RCTDeviceEventEmitter emitter = mock(RCTDeviceEventEmitter.class);
ReactApplicationContext context = mock(ReactApplicationContext.class);
when(context.getJSModule(any(ExecutorToken.class), any(Class.class))).thenReturn(emitter);
when(context.getJSModule(any(Class.class))).thenReturn(emitter);
OkHttpClient httpClient = mock(OkHttpClient.class);
OkHttpClient.Builder clientBuilder = mock(OkHttpClient.Builder.class);
@@ -160,7 +157,6 @@ public void testFailPostWithoutContentType() throws Exception {
mockEvents();
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://somedomain/bar",
0,
@@ -222,7 +218,6 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
body.putString("string", "This is request body");
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://somedomain/bar",
0,
@@ -266,7 +261,6 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
JavaOnlyArray.of("User-Agent", "React test agent/1.0"));
networkingModule.sendRequest(
mock(ExecutorToken.class),
"GET",
"http://someurl/baz",
0,
@@ -321,7 +315,6 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://someurl/uploadFoo",
0,
@@ -387,7 +380,6 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://someurl/uploadFoo",
0,
@@ -491,7 +483,6 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://someurl/uploadFoo",
0,
@@ -556,7 +547,6 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
for (int idx = 0; idx < requests; idx++) {
networkingModule.sendRequest(
mock(ExecutorToken.class),
"GET",
"http://somedomain/foo",
idx + 1,
@@ -607,7 +597,6 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
for (int idx = 0; idx < requests; idx++) {
networkingModule.sendRequest(
mock(ExecutorToken.class),
"GET",
"http://somedomain/foo",
idx + 1,
@@ -620,7 +609,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
}
verify(httpClient, times(3)).newCall(any(Request.class));
networkingModule.abortRequest(mock(ExecutorToken.class), requests);
networkingModule.abortRequest(requests);
PowerMockito.verifyStatic(times(1));
ArgumentCaptor<OkHttpClient> clientArguments = ArgumentCaptor.forClass(OkHttpClient.class);
ArgumentCaptor<Integer> requestIdArguments = ArgumentCaptor.forClass(Integer.class);

0 comments on commit ea93577

Please sign in to comment.