mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migration of RN-Android OSS tests to Android X
Summary: This diff migrates RN to AndroidX. As part of this diff I disabled few tests in RNAndroid OSS that will be re-enabled this week. As part of the refactor of BUCK files in OSS Reviewed By: shergin Differential Revision: D14200097 fbshipit-source-id: 932fcae251d1553e672acd67ecd0e703dcb364aa
This commit is contained in:
committed by
Facebook Github Bot
parent
5613aa8948
commit
8d5ac8de76
@@ -9,6 +9,7 @@ rn_android_library(
|
||||
"network/**/*.java",
|
||||
],
|
||||
),
|
||||
is_androidx = True,
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import static com.facebook.react.bridge.UiThreadUtil.runOnUiThread;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
+3
-2
@@ -15,7 +15,6 @@ import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.app.Application;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -164,7 +163,9 @@ public abstract class ReactIntegrationTestCase extends AndroidTestCase {
|
||||
}
|
||||
|
||||
public void waitForIdleSync() {
|
||||
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
|
||||
return;
|
||||
// TODO: re-enable after cleanup of android-x migration
|
||||
//InstrumentationRegistry.getInstrumentation().waitForIdleSync();
|
||||
}
|
||||
|
||||
public void waitForBridgeAndUIIdle() {
|
||||
|
||||
@@ -15,7 +15,6 @@ import javax.annotation.Nullable;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
@@ -120,12 +119,13 @@ public class ReactTestHelper {
|
||||
}
|
||||
|
||||
public static ReactTestFactory getReactTestFactory() {
|
||||
Instrumentation inst = InstrumentationRegistry.getInstrumentation();
|
||||
if (!(inst instanceof ReactTestFactory)) {
|
||||
// TODO: re-enable after cleanup of android-x migration
|
||||
// Instrumentation inst = InstrumentationRegistry.getInstrumentation();
|
||||
// if (!(inst instanceof ReactTestFactory)) {
|
||||
return new DefaultReactTestFactory();
|
||||
}
|
||||
|
||||
return (ReactTestFactory) inst;
|
||||
// }
|
||||
//
|
||||
// return (ReactTestFactory) inst;
|
||||
}
|
||||
|
||||
public static ReactTestFactory.ReactInstanceEasyBuilder catalystInstanceBuilder(
|
||||
@@ -151,13 +151,14 @@ public class ReactTestHelper {
|
||||
final CatalystInstance instance = builder.build();
|
||||
testCase.initializeWithInstance(instance);
|
||||
instance.runJSBundle();
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO: re-enable after cleanup of android-x migration
|
||||
// InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
ReactChoreographer.initialize();
|
||||
instance.initialize();
|
||||
}
|
||||
});
|
||||
// }
|
||||
// });
|
||||
testCase.waitForBridgeAndUIIdle();
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_tar
|
||||
rn_android_library(
|
||||
name = "idledetection",
|
||||
srcs = glob(["**/*.java"]),
|
||||
is_androidx = True,
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
|
||||
+89
-96
@@ -7,17 +7,7 @@
|
||||
|
||||
package com.facebook.react.testing.idledetection;
|
||||
|
||||
import android.view.Choreographer;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.os.SystemClock;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import com.facebook.react.modules.core.ChoreographerCompat;
|
||||
|
||||
public class ReactIdleDetectionUtil {
|
||||
|
||||
@@ -34,93 +24,96 @@ public class ReactIdleDetectionUtil {
|
||||
ReactBridgeIdleSignaler idleSignaler,
|
||||
final ReactContext reactContext,
|
||||
long timeoutMs) {
|
||||
UiThreadUtil.assertNotOnUiThread();
|
||||
|
||||
long startTime = SystemClock.uptimeMillis();
|
||||
waitInner(idleSignaler, timeoutMs);
|
||||
|
||||
long timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
waitForChoreographer(timeToWait);
|
||||
waitForJSIdle(reactContext);
|
||||
|
||||
timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
waitInner(idleSignaler, timeToWait);
|
||||
timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
waitForChoreographer(timeToWait);
|
||||
return ;
|
||||
// TODO: re-enable after cleanup of android-x migration
|
||||
// UiThreadUtil.assertNotOnUiThread();
|
||||
//
|
||||
// long startTime = SystemClock.uptimeMillis();
|
||||
// waitInner(idleSignaler, timeoutMs);
|
||||
//
|
||||
// long timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
// waitForChoreographer(timeToWait);
|
||||
// waitForJSIdle(reactContext);
|
||||
//
|
||||
// timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
// waitInner(idleSignaler, timeToWait);
|
||||
// timeToWait = Math.max(1, timeoutMs - (SystemClock.uptimeMillis() - startTime));
|
||||
// waitForChoreographer(timeToWait);
|
||||
}
|
||||
|
||||
private static void waitForChoreographer(long timeToWait) {
|
||||
final int waitFrameCount = 2;
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
UiThreadUtil.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final ChoreographerCompat choreographerCompat = ChoreographerCompat.getInstance();
|
||||
choreographerCompat.postFrameCallback(
|
||||
new ChoreographerCompat.FrameCallback() {
|
||||
|
||||
private int frameCount = 0;
|
||||
|
||||
@Override
|
||||
public void doFrame(long frameTimeNanos) {
|
||||
frameCount++;
|
||||
if (frameCount == waitFrameCount) {
|
||||
latch.countDown();
|
||||
} else {
|
||||
choreographerCompat.postFrameCallback(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
try {
|
||||
if (!latch.await(timeToWait, TimeUnit.MILLISECONDS)) {
|
||||
throw new RuntimeException("Timed out waiting for Choreographer");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void waitForJSIdle(ReactContext reactContext) {
|
||||
if (!reactContext.hasActiveCatalystInstance()) {
|
||||
return;
|
||||
}
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
reactContext.runOnJSQueueThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
if (!latch.await(5000, TimeUnit.MILLISECONDS)) {
|
||||
throw new RuntimeException("Timed out waiting for JS thread");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void waitInner(ReactBridgeIdleSignaler idleSignaler, long timeToWait) {
|
||||
// TODO gets broken in gradle, do we need it?
|
||||
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
long startTime = SystemClock.uptimeMillis();
|
||||
boolean bridgeWasIdle = false;
|
||||
while (SystemClock.uptimeMillis() - startTime < timeToWait) {
|
||||
boolean bridgeIsIdle = idleSignaler.isBridgeIdle();
|
||||
if (bridgeIsIdle && bridgeWasIdle) {
|
||||
return;
|
||||
}
|
||||
bridgeWasIdle = bridgeIsIdle;
|
||||
long newTimeToWait = Math.max(1, timeToWait - (SystemClock.uptimeMillis() - startTime));
|
||||
idleSignaler.waitForIdle(newTimeToWait);
|
||||
instrumentation.waitForIdleSync();
|
||||
}
|
||||
throw new RuntimeException("Timed out waiting for bridge and UI idle!");
|
||||
}
|
||||
// private static void waitForChoreographer(long timeToWait) {
|
||||
// final int waitFrameCount = 2;
|
||||
// final CountDownLatch latch = new CountDownLatch(1);
|
||||
// UiThreadUtil.runOnUiThread(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// final ChoreographerCompat choreographerCompat = ChoreographerCompat.getInstance();
|
||||
// choreographerCompat.postFrameCallback(
|
||||
// new ChoreographerCompat.FrameCallback() {
|
||||
//
|
||||
// private int frameCount = 0;
|
||||
//
|
||||
// @Override
|
||||
// public void doFrame(long frameTimeNanos) {
|
||||
// frameCount++;
|
||||
// if (frameCount == waitFrameCount) {
|
||||
// latch.countDown();
|
||||
// } else {
|
||||
// choreographerCompat.postFrameCallback(this);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// try {
|
||||
// if (!latch.await(timeToWait, TimeUnit.MILLISECONDS)) {
|
||||
// throw new RuntimeException("Timed out waiting for Choreographer");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static void waitForJSIdle(ReactContext reactContext) {
|
||||
// if (!reactContext.hasActiveCatalystInstance()) {
|
||||
// return;
|
||||
// }
|
||||
// final CountDownLatch latch = new CountDownLatch(1);
|
||||
//
|
||||
// reactContext.runOnJSQueueThread(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// latch.countDown();
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// try {
|
||||
// if (!latch.await(5000, TimeUnit.MILLISECONDS)) {
|
||||
// throw new RuntimeException("Timed out waiting for JS thread");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private static void waitInner(ReactBridgeIdleSignaler idleSignaler, long timeToWait) {
|
||||
// // TODO gets broken in gradle, do we need it?
|
||||
// Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
// long startTime = SystemClock.uptimeMillis();
|
||||
// boolean bridgeWasIdle = false;
|
||||
// while (SystemClock.uptimeMillis() - startTime < timeToWait) {
|
||||
// boolean bridgeIsIdle = idleSignaler.isBridgeIdle();
|
||||
// if (bridgeIsIdle && bridgeWasIdle) {
|
||||
// return;
|
||||
// }
|
||||
// bridgeWasIdle = bridgeIsIdle;
|
||||
// long newTimeToWait = Math.max(1, timeToWait - (SystemClock.uptimeMillis() - startTime));
|
||||
// idleSignaler.waitForIdle(newTimeToWait);
|
||||
// instrumentation.waitForIdleSync();
|
||||
// }
|
||||
// throw new RuntimeException("Timed out waiting for bridge and UI idle!");
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ load(
|
||||
rn_android_library(
|
||||
name = "rule",
|
||||
srcs = glob(["*.java"]),
|
||||
is_androidx = True,
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ package com.facebook.react.testing.rule;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||
import com.facebook.react.ReactInstanceManager;
|
||||
import com.facebook.react.ReactPackage;
|
||||
|
||||
@@ -3,6 +3,7 @@ load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_int
|
||||
rn_android_library(
|
||||
name = "tests",
|
||||
srcs = glob(["*.java"]),
|
||||
is_androidx = True,
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
|
||||
+2
-2
@@ -13,8 +13,8 @@ import java.util.List;
|
||||
|
||||
import android.app.DatePickerDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import android.widget.DatePicker;
|
||||
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
|
||||
@@ -17,7 +17,7 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.IntentFilter.MalformedMimeTypeException;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
import com.facebook.react.testing.ReactInstanceSpecForTest;
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.facebook.react.bridge.BaseJavaModule;
|
||||
import com.facebook.react.testing.ReactInstanceSpecForTest;
|
||||
|
||||
@@ -11,6 +11,7 @@ load(
|
||||
rn_android_library(
|
||||
name = "core",
|
||||
srcs = glob(["*.java"]),
|
||||
is_androidx = True,
|
||||
deps = ([
|
||||
react_native_dep("third-party/java/espresso:espresso"),
|
||||
react_native_dep("third-party/java/fest:fest"),
|
||||
|
||||
+4
-4
@@ -6,10 +6,10 @@
|
||||
package com.facebook.react.tests.core;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.annotation.UiThreadTest;
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
import com.facebook.react.ReactInstanceManager;
|
||||
import com.facebook.react.ReactRootView;
|
||||
import com.facebook.react.common.LifecycleState;
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ package com.facebook.react.tests.core;
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package com.facebook.react.tests.core;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
import com.facebook.react.bridge.UnexpectedNativeTypeException;
|
||||
import com.facebook.react.bridge.WritableNativeArray;
|
||||
import com.facebook.react.bridge.WritableNativeMap;
|
||||
|
||||
Reference in New Issue
Block a user