|
2 | 2 |
|
3 | 3 | import static android.os.Looper.getMainLooper;
|
4 | 4 | import static io.flutter.embedding.engine.systemchannels.PlatformViewsChannel.PlatformViewTouch;
|
| 5 | +import static junit.framework.Assert.assertEquals; |
| 6 | +import static junit.framework.Assert.assertTrue; |
5 | 7 | import static org.junit.Assert.*;
|
6 | 8 | import static org.mockito.ArgumentMatchers.*;
|
7 | 9 | import static org.mockito.Mockito.*;
|
@@ -1240,6 +1242,74 @@ public void reattachToFlutterView() {
|
1240 | 1242 | verify(newFlutterView, times(1)).addView(any(PlatformViewWrapper.class));
|
1241 | 1243 | }
|
1242 | 1244 |
|
| 1245 | + @Config( |
| 1246 | + shadows = { |
| 1247 | + ShadowFlutterSurfaceView.class, |
| 1248 | + ShadowFlutterJNI.class, |
| 1249 | + ShadowPlatformTaskQueue.class |
| 1250 | + }) |
| 1251 | + public void revertImageViewAndRemoveImageView() { |
| 1252 | + final PlatformViewsController platformViewsController = new PlatformViewsController(); |
| 1253 | + |
| 1254 | + final int platformViewId = 0; |
| 1255 | + assertNull(platformViewsController.getPlatformViewById(platformViewId)); |
| 1256 | + |
| 1257 | + final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class); |
| 1258 | + final PlatformView platformView = mock(PlatformView.class); |
| 1259 | + final View androidView = mock(View.class); |
| 1260 | + when(platformView.getView()).thenReturn(androidView); |
| 1261 | + when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView); |
| 1262 | + |
| 1263 | + platformViewsController.getRegistry().registerViewFactory("testType", viewFactory); |
| 1264 | + |
| 1265 | + final FlutterJNI jni = new FlutterJNI(); |
| 1266 | + jni.attachToNative(); |
| 1267 | + |
| 1268 | + final FlutterView flutterView = attach(jni, platformViewsController); |
| 1269 | + |
| 1270 | + jni.onFirstFrame(); |
| 1271 | + |
| 1272 | + // Simulate create call from the framework. |
| 1273 | + createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true); |
| 1274 | + |
| 1275 | + // The simulation creates an Overlay on top of the PlatformView |
| 1276 | + // This is going to be called `flutterView.convertToImageView` |
| 1277 | + platformViewsController.createOverlaySurface(); |
| 1278 | + platformViewsController.onDisplayOverlaySurface(platformViewId, 0, 0, 10, 10); |
| 1279 | + |
| 1280 | + // This will contain three views: Background ImageView、PlatformView、Overlay ImageView |
| 1281 | + assertEquals(flutterView.getChildCount(), 3); |
| 1282 | + |
| 1283 | + FlutterImageView imageView = flutterView.getCurrentImageSurface(); |
| 1284 | + |
| 1285 | + // Make sure the ImageView is inside the current FlutterView. |
| 1286 | + assertTrue(imageView != null); |
| 1287 | + assertTrue(flutterView.indexOfChild(imageView) != -1); |
| 1288 | + |
| 1289 | + // Make sure the overlayView is inside the current FlutterView |
| 1290 | + assertTrue(platformViewsController.getOverlayLayerViews().size() != 0); |
| 1291 | + PlatformOverlayView overlayView = platformViewsController.getOverlayLayerViews().get(0); |
| 1292 | + assertTrue(overlayView != null); |
| 1293 | + assertTrue(flutterView.indexOfChild(overlayView) != -1); |
| 1294 | + |
| 1295 | + // Simulate in a new frame, there's no PlatformView, which is called |
| 1296 | + // `flutterView.revertImageView`. And register a `FlutterUiDisplayListener` callback. |
| 1297 | + // During callback execution it will invoke `flutterImageView.detachFromRenderer()`. |
| 1298 | + platformViewsController.onBeginFrame(); |
| 1299 | + platformViewsController.onEndFrame(); |
| 1300 | + |
| 1301 | + // Invoke all registered `FlutterUiDisplayListener` callback |
| 1302 | + jni.onFirstFrame(); |
| 1303 | + |
| 1304 | + assertEquals(null, flutterView.getCurrentImageSurface()); |
| 1305 | + |
| 1306 | + // Make sure the background ImageVIew is not in the FlutterView |
| 1307 | + assertTrue(flutterView.indexOfChild(imageView) == -1); |
| 1308 | + |
| 1309 | + // Make sure the overlay ImageVIew is not in the FlutterView |
| 1310 | + assertTrue(flutterView.indexOfChild(overlayView) == -1); |
| 1311 | + } |
| 1312 | + |
1243 | 1313 | private static ByteBuffer encodeMethodCall(MethodCall call) {
|
1244 | 1314 | final ByteBuffer buffer = StandardMethodCodec.INSTANCE.encodeMethodCall(call);
|
1245 | 1315 | buffer.rewind();
|
|
0 commit comments