mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[android]: Make Robolectric tests work with SDK 33 (flutter/engine#42965)
Make Robolectric tests work with SDK 33. The Robolectric doesn't support create presentation window now, so this CL also adds a custom presentation shadow to hook showing state to make related tests work. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
parent
5a20ffdb0a
commit
23d3ca2e2b
@ -9,6 +9,7 @@ import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.app.Presentation;
|
||||
import android.content.Context;
|
||||
import android.content.MutableContextWrapper;
|
||||
import android.content.res.AssetManager;
|
||||
@ -57,6 +58,7 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.shadows.ShadowDialog;
|
||||
import org.robolectric.shadows.ShadowSurfaceView;
|
||||
|
||||
@Config(manifest = Config.NONE)
|
||||
@ -570,7 +572,8 @@ public class PlatformViewsControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
@Config(
|
||||
shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class, ShadowPresentation.class})
|
||||
public void onDetachedFromJNI_clearsPlatformViewContext() {
|
||||
PlatformViewsController platformViewsController = new PlatformViewsController();
|
||||
|
||||
@ -601,7 +604,8 @@ public class PlatformViewsControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
||||
@Config(
|
||||
shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class, ShadowPresentation.class})
|
||||
public void onPreEngineRestart_clearsPlatformViewContext() {
|
||||
PlatformViewsController platformViewsController = new PlatformViewsController();
|
||||
|
||||
@ -1521,6 +1525,34 @@ public class PlatformViewsControllerTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The shadow class of {@link Presentation} to simulate Presentation showing logic.
|
||||
*
|
||||
* <p>Robolectric doesn't support VirtualDisplay creating correctly now, so this shadow class is
|
||||
* used to simulate custom logic for Presentation.
|
||||
*/
|
||||
@Implements(Presentation.class)
|
||||
public static class ShadowPresentation extends ShadowDialog {
|
||||
private boolean isShowing = false;
|
||||
|
||||
public ShadowPresentation() {}
|
||||
|
||||
@Implementation
|
||||
protected void show() {
|
||||
isShowing = true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
protected void dismiss() {
|
||||
isShowing = false;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
protected boolean isShowing() {
|
||||
return isShowing;
|
||||
}
|
||||
}
|
||||
|
||||
@Implements(FlutterJNI.class)
|
||||
public static class ShadowFlutterJNI {
|
||||
private static SparseArray<ByteBuffer> replies = new SparseArray<>();
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
sdk=31
|
||||
sdk=33
|
||||
shadows=io.flutter.CustomShadowContextImpl
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user