Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Bump Robolectric to 4.8.1 #33024

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shell/platform/android/test/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Unit testing Java code

All Java code in the engine should now be able to be tested with Robolectric 4.7.3
All Java code in the engine should now be able to be tested with Robolectric 4.8.1
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Canvas;
import android.graphics.SurfaceTexture;
import android.util.SparseArray;
import android.view.MotionEvent;
Expand Down Expand Up @@ -51,6 +52,7 @@
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)
Expand Down Expand Up @@ -469,7 +471,12 @@ public void disposeAndroidView__hybridComposition() {
}

@Test
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
@Config(
shadows = {
ShadowFlutterJNI.class,
ShadowReleasedSurface.class,
ShadowPlatformTaskQueue.class
})
public void disposeNullAndroidView() {
PlatformViewsController platformViewsController = new PlatformViewsController();

Expand All @@ -489,6 +496,20 @@ public void disposeNullAndroidView() {
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);
Expand Down Expand Up @@ -1110,6 +1131,22 @@ public void dispatch(Runnable runnable) {
}
}

/**
* The shadow class of {@link Surface} to simulate released surface.
*
* <p>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<ByteBuffer> replies = new SparseArray<>();
Expand Down
3 changes: 1 addition & 2 deletions shell/platform/android/test_runner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ android {
implementation files(project.property("flutter_jar"))
testImplementation "androidx.test:core:1.4.0"
testImplementation "com.google.android.play:core:1.8.0"
testImplementation "com.ibm.icu:icu4j:69.1"
testImplementation "org.robolectric:robolectric:4.7.3"
testImplementation "org.robolectric:robolectric:4.8.1"
testImplementation "junit:junit:4.13"
testImplementation "androidx.test.ext:junit:1.1.3"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sdk=31
sdk=32
shadows=io.flutter.CustomShadowContextImpl