|
|
|
|
@@ -7,9 +7,11 @@ 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;
|
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
|
import android.graphics.SurfaceTexture;
|
|
|
|
|
import android.util.SparseArray;
|
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
@@ -53,6 +55,8 @@ 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.ShadowSurface;
|
|
|
|
|
import org.robolectric.shadows.ShadowSurfaceView;
|
|
|
|
|
|
|
|
|
|
@Config(manifest = Config.NONE)
|
|
|
|
|
@@ -505,7 +509,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();
|
|
|
|
|
|
|
|
|
|
@@ -536,7 +541,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();
|
|
|
|
|
|
|
|
|
|
@@ -740,7 +746,12 @@ public class PlatformViewsControllerTest {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Config(shadows = {ShadowFlutterJNI.class, ShadowPlatformTaskQueue.class})
|
|
|
|
|
@Config(
|
|
|
|
|
shadows = {
|
|
|
|
|
ShadowFlutterJNI.class,
|
|
|
|
|
ShadowReleasedSurface.class,
|
|
|
|
|
ShadowPlatformTaskQueue.class
|
|
|
|
|
})
|
|
|
|
|
public void disposeNullAndroidView() {
|
|
|
|
|
PlatformViewsController platformViewsController = new PlatformViewsController();
|
|
|
|
|
|
|
|
|
|
@@ -760,6 +771,20 @@ 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);
|
|
|
|
|
@@ -1388,6 +1413,50 @@ public class PlatformViewsControllerTest {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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<>();
|
|
|
|
|
|