From 729cd3e4a9cb475cd26d7015224389a72935c572 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Thu, 23 Jun 2022 15:29:57 -0700 Subject: [PATCH] Revert "Bump Robolectric to 4.8.1 (#33024)" (flutter/engine#34263) This reverts commit aaa190f63293b61c0579642a4e979221bf6c5ba1. --- .../shell/platform/android/test/README.md | 2 +- .../platform/PlatformViewsControllerTest.java | 39 +------------------ .../platform/android/test_runner/build.gradle | 3 +- .../src/main/resources/robolectric.properties | 2 +- 4 files changed, 5 insertions(+), 41 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/test/README.md b/engine/src/flutter/shell/platform/android/test/README.md index 2bc4dd380a..ef203e012c 100644 --- a/engine/src/flutter/shell/platform/android/test/README.md +++ b/engine/src/flutter/shell/platform/android/test/README.md @@ -1,6 +1,6 @@ # Unit testing Java code -All Java code in the engine should now be able to be tested with Robolectric 4.8.1 +All Java code in the engine should now be able to be tested with Robolectric 4.7.3 and JUnit 4. The test suite has been added after the bulk of the Java code was first written, so most of these classes do not have existing tests. Ideally code after this point should be tested, either with unit tests here or with diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java index f2ca2f8940..d3fb9a8659 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java @@ -10,7 +10,6 @@ import static org.robolectric.Shadows.shadowOf; import android.content.Context; import android.content.MutableContextWrapper; import android.content.res.AssetManager; -import android.graphics.Canvas; import android.graphics.SurfaceTexture; import android.util.SparseArray; import android.view.MotionEvent; @@ -54,7 +53,6 @@ import org.mockito.ArgumentCaptor; import org.robolectric.annotation.Config; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; -import org.robolectric.shadows.ShadowSurface; import org.robolectric.shadows.ShadowSurfaceView; @Config(manifest = Config.NONE) @@ -649,12 +647,7 @@ public class PlatformViewsControllerTest { } @Test - @Config( - shadows = { - ShadowFlutterJNI.class, - ShadowReleasedSurface.class, - ShadowPlatformTaskQueue.class - }) + @Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class}) public void disposeNullAndroidView() { PlatformViewsController platformViewsController = new PlatformViewsController(); @@ -674,20 +667,6 @@ public class PlatformViewsControllerTest { attach(jni, platformViewsController); // Simulate create call from the framework. - // Before Robolectric 4.8, Surface#lockHardwareCanvas will throw exception at - // PlatformViewWrapper#setTexture, because Robolectric doesn't support to shadow - // Surface#lockHardwareCanvas, and it uses real Android logic with native pointer address is 0. - // This failure will ensure embeddedView's parent is null, because - // PlatformViewsController#createForTextureLayer will fail because of previous mentioned error, - // and PlatformViewsController#createForTextureLayer will not add embeddedView to wrapperView. - // So this test can pass. From Robolectric 4.8, it supports to shadow Surface#lockHardwareCanvas - // and it can pass with default true valid value, and - // PlatformViewsController#createForTextureLayer will run correctly and add embeddedView to - // wrapperView, and initializePlatformViewIfNeeded will fail because embeddedView's parent is - // not null. So adding a new shadow class called ShadowReleasedSurface to simulate previous - // Surface#lockHardwareCanvas failure to ensure this test can work with Robolectric 4.8 and - // later versions. But it is just a workaround, the root cause is this test case depends on - // just-failure behavior of Surface#lockHardwareCanvas in old Robolectric. createPlatformView( jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false); platformViewsController.initializePlatformViewIfNeeded(platformViewId); @@ -1316,22 +1295,6 @@ public class PlatformViewsControllerTest { } } - /** - * The shadow class of {@link Surface} to simulate released surface. - * - *

This shadow class's usage is restricted, not for normal purpose. - */ - @Implements(Surface.class) - public static class ShadowReleasedSurface extends ShadowSurface { - public ShadowReleasedSurface() {} - - @Implementation - @Override - protected Canvas lockHardwareCanvas() { - throw new IllegalStateException("Surface has already been released."); - } - } - @Implements(FlutterJNI.class) public static class ShadowFlutterJNI { private static SparseArray replies = new SparseArray<>(); diff --git a/engine/src/flutter/shell/platform/android/test_runner/build.gradle b/engine/src/flutter/shell/platform/android/test_runner/build.gradle index 52499d2cf4..5d6aca1b8d 100644 --- a/engine/src/flutter/shell/platform/android/test_runner/build.gradle +++ b/engine/src/flutter/shell/platform/android/test_runner/build.gradle @@ -69,7 +69,8 @@ android { implementation files(project.property("flutter_jar")) testImplementation "androidx.test:core:1.4.0" testImplementation "com.google.android.play:core:1.8.0" - testImplementation "org.robolectric:robolectric:4.8.1" + testImplementation "com.ibm.icu:icu4j:69.1" + testImplementation "org.robolectric:robolectric:4.7.3" testImplementation "junit:junit:4.13" testImplementation "androidx.test.ext:junit:1.1.3" diff --git a/engine/src/flutter/shell/platform/android/test_runner/src/main/resources/robolectric.properties b/engine/src/flutter/shell/platform/android/test_runner/src/main/resources/robolectric.properties index ac3b918cdd..ba72a7e57e 100644 --- a/engine/src/flutter/shell/platform/android/test_runner/src/main/resources/robolectric.properties +++ b/engine/src/flutter/shell/platform/android/test_runner/src/main/resources/robolectric.properties @@ -1,2 +1,2 @@ -sdk=32 +sdk=31 shadows=io.flutter.CustomShadowContextImpl