Remove WebWorker support from NetworkingModule

Reviewed By: AaaChiuuu

Differential Revision: D4929251

fbshipit-source-id: fa07bfea64e6f79fd7b8c19889a26caec03cd421
This commit is contained in:
Pieter De Baets 2017-04-25 05:29:43 -07:00 committed by Facebook Github Bot
parent 3e08a28987
commit ea93577ff2
2 changed files with 11 additions and 33 deletions

View File

@ -22,7 +22,6 @@ import java.util.concurrent.TimeUnit;
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 @@ import okio.ByteString;
/**
* 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 final class NetworkingModule extends ReactContextBaseJavaModule {
* @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 final class NetworkingModule extends ReactContextBaseJavaModule {
requestBuilder.tag(requestId);
}
final RCTDeviceEventEmitter eventEmitter = getEventEmitter(executorToken);
final RCTDeviceEventEmitter eventEmitter = getEventEmitter();
OkHttpClient.Builder clientBuilder = mClient.newBuilder();
if (!withCredentials) {
@ -303,7 +301,7 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
}
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 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
}
@ReactMethod
public void abortRequest(ExecutorToken executorToken, final int requestId) {
public void abortRequest(final int requestId) {
cancelRequest(requestId);
removeRequest(requestId);
}
@ -465,23 +463,15 @@ public final class NetworkingModule extends ReactContextBaseJavaModule {
}
@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 final class NetworkingModule extends ReactContextBaseJavaModule {
return headersBuilder.build();
}
private RCTDeviceEventEmitter getEventEmitter(ExecutorToken ExecutorToken) {
return getReactApplicationContext()
.getJSModule(ExecutorToken, RCTDeviceEventEmitter.class);
private RCTDeviceEventEmitter getEventEmitter() {
return getReactApplicationContext().getJSModule(RCTDeviceEventEmitter.class);
}
}

View File

@ -14,7 +14,6 @@ import java.util.Arrays;
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 class NetworkingModuleTest {
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"GET",
"http://somedomain/foo",
/* requestId */ 0,
@ -115,7 +113,7 @@ public class NetworkingModuleTest {
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 class NetworkingModuleTest {
mockEvents();
networkingModule.sendRequest(
mock(ExecutorToken.class),
"GET",
"http://somedoman/foo",
/* requestId */ 0,
@ -146,7 +143,7 @@ public class NetworkingModuleTest {
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 class NetworkingModuleTest {
mockEvents();
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://somedomain/bar",
0,
@ -222,7 +218,6 @@ public class NetworkingModuleTest {
body.putString("string", "This is request body");
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://somedomain/bar",
0,
@ -266,7 +261,6 @@ public class NetworkingModuleTest {
JavaOnlyArray.of("User-Agent", "React test agent/1.0"));
networkingModule.sendRequest(
mock(ExecutorToken.class),
"GET",
"http://someurl/baz",
0,
@ -321,7 +315,6 @@ public class NetworkingModuleTest {
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://someurl/uploadFoo",
0,
@ -387,7 +380,6 @@ public class NetworkingModuleTest {
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://someurl/uploadFoo",
0,
@ -491,7 +483,6 @@ public class NetworkingModuleTest {
NetworkingModule networkingModule =
new NetworkingModule(mock(ReactApplicationContext.class), "", httpClient);
networkingModule.sendRequest(
mock(ExecutorToken.class),
"POST",
"http://someurl/uploadFoo",
0,
@ -556,7 +547,6 @@ public class NetworkingModuleTest {
for (int idx = 0; idx < requests; idx++) {
networkingModule.sendRequest(
mock(ExecutorToken.class),
"GET",
"http://somedomain/foo",
idx + 1,
@ -607,7 +597,6 @@ public class NetworkingModuleTest {
for (int idx = 0; idx < requests; idx++) {
networkingModule.sendRequest(
mock(ExecutorToken.class),
"GET",
"http://somedomain/foo",
idx + 1,
@ -620,7 +609,7 @@ public class NetworkingModuleTest {
}
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);