Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
io.flutter.plugin.platform.PlatformViewsControllerTest Class Reference

Classes

class  CountingPlatformView
 
class  ShadowFlutterJNI
 
class  ShadowFlutterSurfaceView
 
class  ShadowPlatformTaskQueue
 
class  ShadowPresentation
 

Public Member Functions

void itRemovesPlatformViewBeforeDiposeIsCalled ()
 
void itNotifiesPlatformViewsOfEngineAttachmentAndDetachment ()
 
void itCancelsOldPresentationOnResize ()
 
void virtualDisplay_handlesResizeResponseWithoutContext ()
 
void virtualDisplay_ensureDisposeVirtualDisplayController ()
 
void itUsesActionEventTypeFromFrameworkEventForVirtualDisplays ()
 
void itUsesActionEventTypeFromFrameworkEventAsActionChanged ()
 
void toMotionEvent_returnsSameCoordsForVdAndNonVd ()
 
void getPlatformViewById_hybridComposition ()
 
void createPlatformViewMessage_initializesAndroidView ()
 
void createPlatformViewMessage_wrapsContextForVirtualDisplay ()
 
void createPlatformViewMessage_doesNotWrapContextForHybrid ()
 
void createPlatformViewMessage_setsAndroidViewLayoutDirection ()
 
void createPlatformViewMessage_setsAndroidViewSize ()
 
void createPlatformViewMessage_disablesAccessibility ()
 
void createPlatformViewMessage_throwsIfViewIsNull ()
 
void createHybridPlatformViewMessage_throwsIfViewIsNull ()
 
void onDetachedFromJNI_clearsPlatformViewContext ()
 
void onPreEngineRestart_clearsPlatformViewContext ()
 
void createPlatformViewMessage_throwsIfViewHasParent ()
 
void createHybridPlatformViewMessage_throwsIfViewHasParent ()
 
void setPlatformViewDirection_throwIfPlatformViewNotFound ()
 
void resizeAndroidView ()
 
void disposeAndroidView_hybridComposition ()
 
void disposeNullAndroidView ()
 
void onEndFrame_destroysOverlaySurfaceAfterFrameOnFlutterSurfaceView ()
 
void onEndFrame_removesPlatformView ()
 
void onEndFrame_removesPlatformViewParent ()
 
void detach_destroysOverlaySurfaces ()
 
void detachFromView_removesAndDestroysOverlayViews ()
 
void destroyOverlaySurfaces_doesNotThrowIfFlutterViewIsDetached ()
 
void destroyOverlaySurfaces_doesNotRemoveOverlayView ()
 
void checkInputConnectionProxy_falseIfViewIsNull ()
 
void convertPlatformViewRenderSurfaceAsDefault ()
 
void dontConverRenderSurfaceWhenFlagIsTrue ()
 
void reattachToFlutterView ()
 
void revertImageViewAndRemoveImageView ()
 

Detailed Description

Definition at line 71 of file PlatformViewsControllerTest.java.

Member Function Documentation

◆ checkInputConnectionProxy_falseIfViewIsNull()

void io.flutter.plugin.platform.PlatformViewsControllerTest.checkInputConnectionProxy_falseIfViewIsNull ( )
inline

Definition at line 1264 of file PlatformViewsControllerTest.java.

1264 {
1265 final PlatformViewsController platformViewsController = new PlatformViewsController();
1266 boolean shouldProxying = platformViewsController.checkInputConnectionProxy(null);
1267 assertFalse(shouldProxying);
1268 }

◆ convertPlatformViewRenderSurfaceAsDefault()

void io.flutter.plugin.platform.PlatformViewsControllerTest.convertPlatformViewRenderSurfaceAsDefault ( )
inline

Definition at line 1272 of file PlatformViewsControllerTest.java.

1272 {
1273 final PlatformViewsController platformViewsController = new PlatformViewsController();
1274
1275 final int platformViewId = 0;
1276 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1277
1278 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1279 final PlatformView platformView = mock(PlatformView.class);
1280 final View androidView = mock(View.class);
1281 when(platformView.getView()).thenReturn(androidView);
1282 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1283
1284 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1285
1286 final FlutterJNI jni = new FlutterJNI();
1287 jni.attachToNative();
1288 final FlutterView flutterView = attach(jni, platformViewsController);
1289
1290 jni.onFirstFrame();
1291
1292 // Simulate create call from the framework.
1293 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1294
1295 // Produce a frame that displays a platform view and an overlay surface.
1296 platformViewsController.onBeginFrame();
1297 platformViewsController.onDisplayPlatformView(
1298 platformViewId,
1299 /* x=*/ 0,
1300 /* y=*/ 0,
1301 /* width=*/ 10,
1302 /* height=*/ 10,
1303 /* viewWidth=*/ 10,
1304 /* viewHeight=*/ 10,
1305 /* mutatorsStack=*/ new FlutterMutatorsStack());
1306
1307 assertEquals(flutterView.getChildCount(), 3);
1308
1309 final View view = flutterView.getChildAt(1);
1310 assertTrue(view instanceof FlutterImageView);
1311
1312 // Simulate dispose call from the framework.
1313 disposePlatformView(jni, platformViewsController, platformViewId);
1314 }
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
Definition: M44Test.cpp:18
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530

◆ createHybridPlatformViewMessage_throwsIfViewHasParent()

void io.flutter.plugin.platform.PlatformViewsControllerTest.createHybridPlatformViewMessage_throwsIfViewHasParent ( )
inline

Definition at line 782 of file PlatformViewsControllerTest.java.

782 {
783 PlatformViewsController platformViewsController = new PlatformViewsController();
784
785 int platformViewId = 0;
786 assertNull(platformViewsController.getPlatformViewById(platformViewId));
787
788 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
789 PlatformView platformView = mock(PlatformView.class);
790 View androidView = mock(View.class);
791 when(androidView.getParent()).thenReturn(mock(ViewParent.class));
792 when(platformView.getView()).thenReturn(androidView);
793 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
794 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
795
796 FlutterJNI jni = new FlutterJNI();
797 attach(jni, platformViewsController);
798
799 // Simulate create call from the framework.
800 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
801 assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
802
803 assertThrows(
804 IllegalStateException.class,
805 () -> {
806 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
807 });
808 }

◆ createHybridPlatformViewMessage_throwsIfViewIsNull()

void io.flutter.plugin.platform.PlatformViewsControllerTest.createHybridPlatformViewMessage_throwsIfViewIsNull ( )
inline

Definition at line 659 of file PlatformViewsControllerTest.java.

659 {
660 PlatformViewsController platformViewsController = new PlatformViewsController();
661
662 int platformViewId = 0;
663 assertNull(platformViewsController.getPlatformViewById(platformViewId));
664
665 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
666 PlatformView platformView = mock(PlatformView.class);
667 when(platformView.getView()).thenReturn(null);
668 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
669 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
670
671 FlutterJNI jni = new FlutterJNI();
672 attach(jni, platformViewsController);
673
674 // Simulate create call from the framework.
675 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
676 assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
677
678 assertThrows(
679 IllegalStateException.class,
680 () -> {
681 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
682 });
683 }

◆ createPlatformViewMessage_disablesAccessibility()

void io.flutter.plugin.platform.PlatformViewsControllerTest.createPlatformViewMessage_disablesAccessibility ( )
inline

Definition at line 603 of file PlatformViewsControllerTest.java.

603 {
604 PlatformViewsController platformViewsController = new PlatformViewsController();
605 platformViewsController.setSoftwareRendering(true);
606
607 int platformViewId = 0;
608 assertNull(platformViewsController.getPlatformViewById(platformViewId));
609
610 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
611 PlatformView platformView = mock(PlatformView.class);
612
613 View androidView = mock(View.class);
614 when(platformView.getView()).thenReturn(androidView);
615 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
616 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
617
618 FlutterJNI jni = new FlutterJNI();
619 attach(jni, platformViewsController);
620
621 // Simulate create call from the framework.
622 createPlatformView(
623 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
624 verify(androidView, times(1))
625 .setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
626 }
static SkISize times(const SkISize &size, float factor)

◆ createPlatformViewMessage_doesNotWrapContextForHybrid()

void io.flutter.plugin.platform.PlatformViewsControllerTest.createPlatformViewMessage_doesNotWrapContextForHybrid ( )
inline

Definition at line 520 of file PlatformViewsControllerTest.java.

520 {
521 PlatformViewsController platformViewsController = new PlatformViewsController();
522
523 int platformViewId = 0;
524 assertNull(platformViewsController.getPlatformViewById(platformViewId));
525
526 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
527 PlatformView platformView = mock(PlatformView.class);
528 when(platformView.getView()).thenReturn(mock(View.class));
529 ArgumentCaptor<Context> passedContext = ArgumentCaptor.forClass(Context.class);
530 when(viewFactory.create(passedContext.capture(), eq(platformViewId), any()))
531 .thenReturn(platformView);
532 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
533
534 FlutterJNI jni = new FlutterJNI();
535 attach(jni, platformViewsController);
536
537 // Simulate create call from the framework.
538 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
539 assertFalse(passedContext.getValue() instanceof MutableContextWrapper);
540 }

◆ createPlatformViewMessage_initializesAndroidView()

void io.flutter.plugin.platform.PlatformViewsControllerTest.createPlatformViewMessage_initializesAndroidView ( )
inline

Definition at line 473 of file PlatformViewsControllerTest.java.

473 {
474 PlatformViewsController platformViewsController = new PlatformViewsController();
475
476 int platformViewId = 0;
477 assertNull(platformViewsController.getPlatformViewById(platformViewId));
478
479 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
480 PlatformView platformView = mock(PlatformView.class);
481 when(platformView.getView()).thenReturn(mock(View.class));
482 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
483 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
484
485 FlutterJNI jni = new FlutterJNI();
486 attach(jni, platformViewsController);
487
488 // Simulate create call from the framework.
489 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
490 verify(viewFactory, times(1)).create(any(), eq(platformViewId), any());
491 }

◆ createPlatformViewMessage_setsAndroidViewLayoutDirection()

void io.flutter.plugin.platform.PlatformViewsControllerTest.createPlatformViewMessage_setsAndroidViewLayoutDirection ( )
inline

Definition at line 544 of file PlatformViewsControllerTest.java.

544 {
545 PlatformViewsController platformViewsController = new PlatformViewsController();
546 platformViewsController.setSoftwareRendering(true);
547
548 int platformViewId = 0;
549 assertNull(platformViewsController.getPlatformViewById(platformViewId));
550
551 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
552 PlatformView platformView = mock(PlatformView.class);
553
554 View androidView = mock(View.class);
555 when(platformView.getView()).thenReturn(androidView);
556 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
557 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
558
559 FlutterJNI jni = new FlutterJNI();
560 attach(jni, platformViewsController);
561
562 // Simulate create call from the framework.
563 createPlatformView(
564 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
565 verify(androidView, times(1)).setLayoutDirection(0);
566 }

◆ createPlatformViewMessage_setsAndroidViewSize()

void io.flutter.plugin.platform.PlatformViewsControllerTest.createPlatformViewMessage_setsAndroidViewSize ( )
inline

Definition at line 570 of file PlatformViewsControllerTest.java.

570 {
571 PlatformViewsController platformViewsController = new PlatformViewsController();
572 platformViewsController.setSoftwareRendering(true);
573
574 int platformViewId = 0;
575 assertNull(platformViewsController.getPlatformViewById(platformViewId));
576
577 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
578 PlatformView platformView = mock(PlatformView.class);
579
580 View androidView = mock(View.class);
581 when(platformView.getView()).thenReturn(androidView);
582 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
583 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
584
585 FlutterJNI jni = new FlutterJNI();
586 attach(jni, platformViewsController);
587
588 // Simulate create call from the framework.
589 createPlatformView(
590 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
591
592 ArgumentCaptor<FrameLayout.LayoutParams> layoutParamsCaptor =
593 ArgumentCaptor.forClass(FrameLayout.LayoutParams.class);
594 verify(androidView, times(2)).setLayoutParams(layoutParamsCaptor.capture());
595
596 List<FrameLayout.LayoutParams> capturedLayoutParams = layoutParamsCaptor.getAllValues();
597 assertEquals(capturedLayoutParams.get(0).width, 1);
598 assertEquals(capturedLayoutParams.get(0).height, 1);
599 }

◆ createPlatformViewMessage_throwsIfViewHasParent()

void io.flutter.plugin.platform.PlatformViewsControllerTest.createPlatformViewMessage_throwsIfViewHasParent ( )
inline

Definition at line 751 of file PlatformViewsControllerTest.java.

751 {
752 PlatformViewsController platformViewsController = new PlatformViewsController();
753
754 int platformViewId = 0;
755 assertNull(platformViewsController.getPlatformViewById(platformViewId));
756
757 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
758 PlatformView platformView = mock(PlatformView.class);
759 View androidView = mock(View.class);
760 when(androidView.getParent()).thenReturn(mock(ViewParent.class));
761 when(platformView.getView()).thenReturn(androidView);
762 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
763 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
764
765 FlutterJNI jni = new FlutterJNI();
766 attach(jni, platformViewsController);
767
768 // Simulate create call from the framework.
769 createPlatformView(
770 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
771 assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
772
773 assertThrows(
774 IllegalStateException.class,
775 () -> {
776 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
777 });
778 }

◆ createPlatformViewMessage_throwsIfViewIsNull()

void io.flutter.plugin.platform.PlatformViewsControllerTest.createPlatformViewMessage_throwsIfViewIsNull ( )
inline

Definition at line 630 of file PlatformViewsControllerTest.java.

630 {
631 PlatformViewsController platformViewsController = new PlatformViewsController();
632
633 int platformViewId = 0;
634 assertNull(platformViewsController.getPlatformViewById(platformViewId));
635
636 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
637 PlatformView platformView = mock(PlatformView.class);
638 when(platformView.getView()).thenReturn(null);
639 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
640 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
641
642 FlutterJNI jni = new FlutterJNI();
643 attach(jni, platformViewsController);
644
645 // Simulate create call from the framework.
646 createPlatformView(
647 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
648 assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
649
650 assertThrows(
651 IllegalStateException.class,
652 () -> {
653 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
654 });
655 }

◆ createPlatformViewMessage_wrapsContextForVirtualDisplay()

void io.flutter.plugin.platform.PlatformViewsControllerTest.createPlatformViewMessage_wrapsContextForVirtualDisplay ( )
inline

Definition at line 495 of file PlatformViewsControllerTest.java.

495 {
496 PlatformViewsController platformViewsController = new PlatformViewsController();
497
498 int platformViewId = 0;
499 assertNull(platformViewsController.getPlatformViewById(platformViewId));
500
501 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
502 PlatformView platformView = mock(PlatformView.class);
503 when(platformView.getView()).thenReturn(mock(View.class));
504 ArgumentCaptor<Context> passedContext = ArgumentCaptor.forClass(Context.class);
505 when(viewFactory.create(passedContext.capture(), eq(platformViewId), any()))
506 .thenReturn(platformView);
507 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
508
509 FlutterJNI jni = new FlutterJNI();
510 attach(jni, platformViewsController);
511
512 // Simulate create call from the framework.
513 createPlatformView(
514 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
515 assertTrue(passedContext.getValue() instanceof MutableContextWrapper);
516 }

◆ destroyOverlaySurfaces_doesNotRemoveOverlayView()

void io.flutter.plugin.platform.PlatformViewsControllerTest.destroyOverlaySurfaces_doesNotRemoveOverlayView ( )
inline

Definition at line 1230 of file PlatformViewsControllerTest.java.

1230 {
1231 final PlatformViewsController platformViewsController = new PlatformViewsController();
1232
1233 final int platformViewId = 0;
1234 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1235
1236 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1237 final PlatformView platformView = mock(PlatformView.class);
1238 when(platformView.getView()).thenReturn(mock(View.class));
1239 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1240
1241 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1242
1243 final FlutterJNI jni = new FlutterJNI();
1244 jni.attachToNative();
1245 attach(jni, platformViewsController);
1246
1247 final FlutterView flutterView = mock(FlutterView.class);
1248 platformViewsController.attachToView(flutterView);
1249
1250 final PlatformOverlayView overlayImageView = mock(PlatformOverlayView.class);
1251 when(overlayImageView.acquireLatestImage()).thenReturn(true);
1252
1253 final FlutterOverlaySurface overlaySurface =
1254 platformViewsController.createOverlaySurface(overlayImageView);
1255
1256 platformViewsController.onDisplayOverlaySurface(
1257 overlaySurface.getId(), /* x=*/ 0, /* y=*/ 0, /* width=*/ 10, /* height=*/ 10);
1258
1259 platformViewsController.destroyOverlaySurfaces();
1260 verify(flutterView, never()).removeView(overlayImageView);
1261 }

◆ destroyOverlaySurfaces_doesNotThrowIfFlutterViewIsDetached()

void io.flutter.plugin.platform.PlatformViewsControllerTest.destroyOverlaySurfaces_doesNotThrowIfFlutterViewIsDetached ( )
inline

Definition at line 1192 of file PlatformViewsControllerTest.java.

1192 {
1193 final PlatformViewsController platformViewsController = new PlatformViewsController();
1194
1195 final int platformViewId = 0;
1196 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1197
1198 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1199 final PlatformView platformView = mock(PlatformView.class);
1200 when(platformView.getView()).thenReturn(mock(View.class));
1201 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1202
1203 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1204
1205 final FlutterJNI jni = new FlutterJNI();
1206 jni.attachToNative();
1207 attach(jni, platformViewsController);
1208
1209 final FlutterView flutterView = mock(FlutterView.class);
1210 platformViewsController.attachToView(flutterView);
1211
1212 final PlatformOverlayView overlayImageView = mock(PlatformOverlayView.class);
1213 when(overlayImageView.acquireLatestImage()).thenReturn(true);
1214
1215 final FlutterOverlaySurface overlaySurface =
1216 platformViewsController.createOverlaySurface(overlayImageView);
1217
1218 platformViewsController.onDisplayOverlaySurface(
1219 overlaySurface.getId(), /* x=*/ 0, /* y=*/ 0, /* width=*/ 10, /* height=*/ 10);
1220
1221 platformViewsController.detachFromView();
1222
1223 platformViewsController.destroyOverlaySurfaces();
1224 verify(overlayImageView, times(1)).closeImageReader();
1225 verify(overlayImageView, times(1)).detachFromRenderer();
1226 }

◆ detach_destroysOverlaySurfaces()

void io.flutter.plugin.platform.PlatformViewsControllerTest.detach_destroysOverlaySurfaces ( )
inline

Definition at line 1103 of file PlatformViewsControllerTest.java.

1103 {
1104 final PlatformViewsController platformViewsController = new PlatformViewsController();
1105
1106 final int platformViewId = 0;
1107 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1108
1109 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1110 final PlatformView platformView = mock(PlatformView.class);
1111 when(platformView.getView()).thenReturn(mock(View.class));
1112 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1113
1114 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1115
1116 final FlutterJNI jni = new FlutterJNI();
1117 jni.attachToNative();
1118 attach(jni, platformViewsController);
1119
1120 jni.onFirstFrame();
1121
1122 // Simulate create call from the framework.
1123 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1124
1125 // Produce a frame that displays a platform view and an overlay surface.
1126 platformViewsController.onBeginFrame();
1127 platformViewsController.onDisplayPlatformView(
1128 platformViewId,
1129 /* x=*/ 0,
1130 /* y=*/ 0,
1131 /* width=*/ 10,
1132 /* height=*/ 10,
1133 /* viewWidth=*/ 10,
1134 /* viewHeight=*/ 10,
1135 /* mutatorsStack=*/ new FlutterMutatorsStack());
1136
1137 final PlatformOverlayView overlayImageView = mock(PlatformOverlayView.class);
1138 when(overlayImageView.acquireLatestImage()).thenReturn(true);
1139
1140 final FlutterOverlaySurface overlaySurface =
1141 platformViewsController.createOverlaySurface(overlayImageView);
1142 // This is OK.
1143 platformViewsController.onDisplayOverlaySurface(
1144 overlaySurface.getId(), /* x=*/ 0, /* y=*/ 0, /* width=*/ 10, /* height=*/ 10);
1145
1146 platformViewsController.detach();
1147
1148 verify(overlayImageView, times(1)).closeImageReader();
1149 verify(overlayImageView, times(1)).detachFromRenderer();
1150 }

◆ detachFromView_removesAndDestroysOverlayViews()

void io.flutter.plugin.platform.PlatformViewsControllerTest.detachFromView_removesAndDestroysOverlayViews ( )
inline

Definition at line 1154 of file PlatformViewsControllerTest.java.

1154 {
1155 final PlatformViewsController platformViewsController = new PlatformViewsController();
1156
1157 final int platformViewId = 0;
1158 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1159
1160 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1161 final PlatformView platformView = mock(PlatformView.class);
1162 when(platformView.getView()).thenReturn(mock(View.class));
1163 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1164
1165 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1166
1167 final FlutterJNI jni = new FlutterJNI();
1168 jni.attachToNative();
1169 attach(jni, platformViewsController);
1170
1171 final FlutterView flutterView = mock(FlutterView.class);
1172 platformViewsController.attachToView(flutterView);
1173
1174 final PlatformOverlayView overlayImageView = mock(PlatformOverlayView.class);
1175 when(overlayImageView.acquireLatestImage()).thenReturn(true);
1176
1177 final FlutterOverlaySurface overlaySurface =
1178 platformViewsController.createOverlaySurface(overlayImageView);
1179
1180 platformViewsController.onDisplayOverlaySurface(
1181 overlaySurface.getId(), /* x=*/ 0, /* y=*/ 0, /* width=*/ 10, /* height=*/ 10);
1182
1183 platformViewsController.detachFromView();
1184
1185 verify(overlayImageView, times(1)).closeImageReader();
1186 verify(overlayImageView, times(1)).detachFromRenderer();
1187 verify(flutterView, times(1)).removeView(overlayImageView);
1188 }

◆ disposeAndroidView_hybridComposition()

void io.flutter.plugin.platform.PlatformViewsControllerTest.disposeAndroidView_hybridComposition ( )
inline

Definition at line 883 of file PlatformViewsControllerTest.java.

883 {
884 PlatformViewsController platformViewsController = new PlatformViewsController();
885
886 int platformViewId = 0;
887 assertNull(platformViewsController.getPlatformViewById(platformViewId));
888
889 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
890 PlatformView platformView = mock(PlatformView.class);
891
892 Context context = ApplicationProvider.getApplicationContext();
893 View androidView = new View(context);
894
895 when(platformView.getView()).thenReturn(androidView);
896 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
897 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
898
899 FlutterJNI jni = new FlutterJNI();
900 attach(jni, platformViewsController);
901
902 // Simulate create call from the framework.
903 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
904 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
905
906 assertNotNull(androidView.getParent());
907 assertTrue(androidView.getParent() instanceof FlutterMutatorView);
908
909 // Simulate dispose call from the framework.
910 disposePlatformView(jni, platformViewsController, platformViewId);
911 assertNull(androidView.getParent());
912
913 // Simulate create call from the framework.
914 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
915 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
916
917 assertNotNull(androidView.getParent());
918 assertTrue(androidView.getParent() instanceof FlutterMutatorView);
919 verify(platformView, times(1)).dispose();
920 }

◆ disposeNullAndroidView()

void io.flutter.plugin.platform.PlatformViewsControllerTest.disposeNullAndroidView ( )
inline

Definition at line 924 of file PlatformViewsControllerTest.java.

924 {
925 PlatformViewsController platformViewsController = new PlatformViewsController();
926
927 int platformViewId = 0;
928 assertNull(platformViewsController.getPlatformViewById(platformViewId));
929
930 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
931 PlatformView platformView = mock(PlatformView.class);
932
933 View androidView = mock(View.class);
934 when(platformView.getView()).thenReturn(androidView);
935 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
936 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
937
938 FlutterJNI jni = new FlutterJNI();
939 attach(jni, platformViewsController);
940
941 // Simulate create call from the framework.
942 createPlatformView(
943 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
944 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
945
946 when(platformView.getView()).thenReturn(null);
947
948 // Simulate dispose call from the framework.
949 disposePlatformView(jni, platformViewsController, platformViewId);
950 verify(platformView, times(1)).dispose();
951 }

◆ dontConverRenderSurfaceWhenFlagIsTrue()

void io.flutter.plugin.platform.PlatformViewsControllerTest.dontConverRenderSurfaceWhenFlagIsTrue ( )
inline

Definition at line 1318 of file PlatformViewsControllerTest.java.

1318 {
1319 final PlatformViewsController platformViewsController = new PlatformViewsController();
1320
1321 final int platformViewId = 0;
1322 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1323
1324 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1325 final PlatformView platformView = mock(PlatformView.class);
1326 final View androidView = mock(View.class);
1327 when(platformView.getView()).thenReturn(androidView);
1328 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1329
1330 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1331
1332 final FlutterJNI jni = new FlutterJNI();
1333 jni.attachToNative();
1334 final FlutterView flutterView = attach(jni, platformViewsController);
1335
1336 jni.onFirstFrame();
1337
1338 // Simulate setting render surface conversion flag.
1339 synchronizeToNativeViewHierarchy(jni, platformViewsController, false);
1340
1341 // Simulate create call from the framework.
1342 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1343
1344 // Produce a frame that displays a platform view and an overlay surface.
1345 platformViewsController.onBeginFrame();
1346 platformViewsController.onDisplayPlatformView(
1347 platformViewId,
1348 /* x=*/ 0,
1349 /* y=*/ 0,
1350 /* width=*/ 10,
1351 /* height=*/ 10,
1352 /* viewWidth=*/ 10,
1353 /* viewHeight=*/ 10,
1354 /* mutatorsStack=*/ new FlutterMutatorsStack());
1355
1356 assertEquals(flutterView.getChildCount(), 2);
1357 assertTrue(!(flutterView.getChildAt(0) instanceof PlatformOverlayView));
1358 assertTrue(flutterView.getChildAt(1) instanceof FlutterMutatorView);
1359
1360 // Simulate dispose call from the framework.
1361 disposePlatformView(jni, platformViewsController, platformViewId);
1362 }

◆ getPlatformViewById_hybridComposition()

void io.flutter.plugin.platform.PlatformViewsControllerTest.getPlatformViewById_hybridComposition ( )
inline

Definition at line 445 of file PlatformViewsControllerTest.java.

445 {
446 PlatformViewsController platformViewsController = new PlatformViewsController();
447
448 int platformViewId = 0;
449 assertNull(platformViewsController.getPlatformViewById(platformViewId));
450
451 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
452 PlatformView platformView = mock(PlatformView.class);
453 View androidView = mock(View.class);
454 when(platformView.getView()).thenReturn(androidView);
455 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
456 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
457
458 FlutterJNI jni = new FlutterJNI();
459 attach(jni, platformViewsController);
460
461 // Simulate create call from the framework.
462 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
463
464 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
465
466 View resultAndroidView = platformViewsController.getPlatformViewById(platformViewId);
467 assertNotNull(resultAndroidView);
468 assertEquals(resultAndroidView, androidView);
469 }

◆ itCancelsOldPresentationOnResize()

void io.flutter.plugin.platform.PlatformViewsControllerTest.itCancelsOldPresentationOnResize ( )
inline

Definition at line 194 of file PlatformViewsControllerTest.java.

194 {
195 // Setup test structure.
196 // Create a fake View that represents the View that renders a Flutter UI.
197 View fakeFlutterView = new View(ApplicationProvider.getApplicationContext());
198
199 // Create fake VirtualDisplayControllers. This requires internal knowledge of
200 // PlatformViewsController. We know that all PlatformViewsController does is
201 // forward view attachment/detachment calls to it's VirtualDisplayControllers.
202 //
203 // TODO(mattcarroll): once PlatformViewsController is refactored into testable
204 // pieces, remove this test and avoid verifying private behavior.
205 VirtualDisplayController fakeVdController1 = mock(VirtualDisplayController.class);
206
207 SingleViewPresentation presentation = fakeVdController1.presentation;
208
209 fakeVdController1.resize(10, 10, null);
210
211 assertEquals(fakeVdController1.presentation != presentation, true);
212 assertEquals(presentation.isShowing(), false);
213 }

◆ itNotifiesPlatformViewsOfEngineAttachmentAndDetachment()

void io.flutter.plugin.platform.PlatformViewsControllerTest.itNotifiesPlatformViewsOfEngineAttachmentAndDetachment ( )
inline

Definition at line 150 of file PlatformViewsControllerTest.java.

150 {
151 PlatformViewsController platformViewsController = new PlatformViewsController();
152 FlutterJNI jni = new FlutterJNI();
153 attach(jni, platformViewsController);
154 // Get the platform view registry.
155 PlatformViewRegistry registry = platformViewsController.getRegistry();
156
157 // Register a factory for our platform view.
158 registry.registerViewFactory(
159 CountingPlatformView.VIEW_TYPE_ID,
160 new PlatformViewFactory(StandardMessageCodec.INSTANCE) {
161 @Override
162 public PlatformView create(Context context, int viewId, Object args) {
163 return new CountingPlatformView(context);
164 }
165 });
166
167 // Create the platform view.
168 int viewId = 0;
169 final PlatformViewsChannel.PlatformViewCreationRequest request =
170 new PlatformViewsChannel.PlatformViewCreationRequest(
171 viewId,
172 CountingPlatformView.VIEW_TYPE_ID,
173 0,
174 0,
175 128,
176 128,
177 View.LAYOUT_DIRECTION_LTR,
178 null);
179 PlatformView pView = platformViewsController.createPlatformView(request, true);
180 assertTrue(pView instanceof CountingPlatformView);
181 CountingPlatformView cpv = (CountingPlatformView) pView;
182 assertEquals(1, cpv.attachCalls);
183 assertEquals(0, cpv.detachCalls);
184 assertEquals(0, cpv.disposeCalls);
185 platformViewsController.detachFromView();
186 assertEquals(1, cpv.attachCalls);
187 assertEquals(1, cpv.detachCalls);
188 assertEquals(0, cpv.disposeCalls);
189 platformViewsController.disposePlatformView(viewId);
190 }

◆ itRemovesPlatformViewBeforeDiposeIsCalled()

void io.flutter.plugin.platform.PlatformViewsControllerTest.itRemovesPlatformViewBeforeDiposeIsCalled ( )
inline

Definition at line 110 of file PlatformViewsControllerTest.java.

110 {
111 PlatformViewsController platformViewsController = new PlatformViewsController();
112 FlutterJNI jni = new FlutterJNI();
113 attach(jni, platformViewsController);
114 // Get the platform view registry.
115 PlatformViewRegistry registry = platformViewsController.getRegistry();
116
117 // Register a factory for our platform view.
118 registry.registerViewFactory(
119 CountingPlatformView.VIEW_TYPE_ID,
120 new PlatformViewFactory(StandardMessageCodec.INSTANCE) {
121 @Override
122 public PlatformView create(Context context, int viewId, Object args) {
123 return new CountingPlatformView(context);
124 }
125 });
126
127 // Create the platform view.
128 int viewId = 0;
129 final PlatformViewsChannel.PlatformViewCreationRequest request =
130 new PlatformViewsChannel.PlatformViewCreationRequest(
131 viewId,
132 CountingPlatformView.VIEW_TYPE_ID,
133 0,
134 0,
135 128,
136 128,
137 View.LAYOUT_DIRECTION_LTR,
138 null);
139 PlatformView pView = platformViewsController.createPlatformView(request, true);
140 assertTrue(pView instanceof CountingPlatformView);
141 CountingPlatformView cpv = (CountingPlatformView) pView;
142 platformViewsController.configureForTextureLayerComposition(pView, request);
143 assertEquals(0, cpv.disposeCalls);
144 platformViewsController.disposePlatformView(viewId);
145 assertEquals(1, cpv.disposeCalls);
146 }

◆ itUsesActionEventTypeFromFrameworkEventAsActionChanged()

void io.flutter.plugin.platform.PlatformViewsControllerTest.itUsesActionEventTypeFromFrameworkEventAsActionChanged ( )
inline

Definition at line 320 of file PlatformViewsControllerTest.java.

320 {
321 MotionEventTracker motionEventTracker = MotionEventTracker.getInstance();
322 PlatformViewsController platformViewsController = new PlatformViewsController();
323
324 MotionEvent original =
325 MotionEvent.obtain(
326 10, // downTime
327 10, // eventTime
328 261, // action
329 0, // x
330 0, // y
331 0 // metaState
332 );
333
334 MotionEventTracker.MotionEventId motionEventId = motionEventTracker.track(original);
335
336 PlatformViewTouch frameWorkTouch =
337 new PlatformViewTouch(
338 0, // viewId
339 original.getDownTime(),
340 original.getEventTime(),
341 0, // action
342 1, // pointerCount
343 Arrays.asList(Arrays.asList(0, 0)), // pointer properties
344 Arrays.asList(Arrays.asList(0., 1., 2., 3., 4., 5., 6., 7., 8.)), // pointer coords
345 original.getMetaState(),
346 original.getButtonState(),
347 original.getXPrecision(),
348 original.getYPrecision(),
349 original.getDeviceId(),
350 original.getEdgeFlags(),
351 original.getSource(),
352 original.getFlags(),
353 motionEventId.getId());
354 MotionEvent resolvedEvent =
355 platformViewsController.toMotionEvent(
356 1, // density
357 frameWorkTouch,
358 false // usingVirtualDisplays
359 );
360 assertEquals(resolvedEvent.getAction(), original.getAction());
361 assertNotEquals(resolvedEvent.getAction(), frameWorkTouch.action);
362 }

◆ itUsesActionEventTypeFromFrameworkEventForVirtualDisplays()

void io.flutter.plugin.platform.PlatformViewsControllerTest.itUsesActionEventTypeFromFrameworkEventForVirtualDisplays ( )
inline

Definition at line 272 of file PlatformViewsControllerTest.java.

272 {
273 MotionEventTracker motionEventTracker = MotionEventTracker.getInstance();
274 PlatformViewsController platformViewsController = new PlatformViewsController();
275
276 MotionEvent original =
277 MotionEvent.obtain(
278 100, // downTime
279 100, // eventTime
280 1, // action
281 0, // x
282 0, // y
283 0 // metaState
284 );
285
286 // track an event that will later get passed to us from framework
287 MotionEventTracker.MotionEventId motionEventId = motionEventTracker.track(original);
288
289 PlatformViewTouch frameWorkTouch =
290 new PlatformViewTouch(
291 0, // viewId
292 original.getDownTime(),
293 original.getEventTime(),
294 2, // action
295 1, // pointerCount
296 Arrays.asList(Arrays.asList(0, 0)), // pointer properties
297 Arrays.asList(Arrays.asList(0., 1., 2., 3., 4., 5., 6., 7., 8.)), // pointer coords
298 original.getMetaState(),
299 original.getButtonState(),
300 original.getXPrecision(),
301 original.getYPrecision(),
302 original.getDeviceId(),
303 original.getEdgeFlags(),
304 original.getSource(),
305 original.getFlags(),
306 motionEventId.getId());
307
308 MotionEvent resolvedEvent =
309 platformViewsController.toMotionEvent(
310 1, // density
311 frameWorkTouch,
312 true // usingVirtualDisplays
313 );
314
315 assertEquals(resolvedEvent.getAction(), frameWorkTouch.action);
316 assertNotEquals(resolvedEvent.getAction(), original.getAction());
317 }

◆ onDetachedFromJNI_clearsPlatformViewContext()

void io.flutter.plugin.platform.PlatformViewsControllerTest.onDetachedFromJNI_clearsPlatformViewContext ( )
inline

Definition at line 688 of file PlatformViewsControllerTest.java.

688 {
689 PlatformViewsController platformViewsController = new PlatformViewsController();
690
691 int platformViewId = 0;
692 assertNull(platformViewsController.getPlatformViewById(platformViewId));
693
694 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
695 PlatformView platformView = mock(PlatformView.class);
696
697 SurfaceView pv = mock(SurfaceView.class);
698 when(pv.getContext()).thenReturn(mock(MutableContextWrapper.class));
699 when(pv.getLayoutParams()).thenReturn(new LayoutParams(1, 1));
700
701 when(platformView.getView()).thenReturn(pv);
702 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
703 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
704
705 FlutterJNI jni = new FlutterJNI();
706 attach(jni, platformViewsController);
707
708 // Simulate create call from the framework.
709 createPlatformView(
710 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
711
712 assertFalse(platformViewsController.contextToEmbeddedView.isEmpty());
713 platformViewsController.onDetachedFromJNI();
714 assertTrue(platformViewsController.contextToEmbeddedView.isEmpty());
715 }

◆ onEndFrame_destroysOverlaySurfaceAfterFrameOnFlutterSurfaceView()

void io.flutter.plugin.platform.PlatformViewsControllerTest.onEndFrame_destroysOverlaySurfaceAfterFrameOnFlutterSurfaceView ( )
inline

Definition at line 960 of file PlatformViewsControllerTest.java.

960 {
961 final PlatformViewsController platformViewsController = new PlatformViewsController();
962
963 final int platformViewId = 0;
964 assertNull(platformViewsController.getPlatformViewById(platformViewId));
965
966 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
967 final PlatformView platformView = mock(PlatformView.class);
968 when(platformView.getView()).thenReturn(mock(View.class));
969 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
970
971 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
972
973 final FlutterJNI jni = new FlutterJNI();
974 jni.attachToNative();
975 attach(jni, platformViewsController);
976
977 jni.onFirstFrame();
978
979 // Simulate create call from the framework.
980 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
981
982 // Produce a frame that displays a platform view and an overlay surface.
983 platformViewsController.onBeginFrame();
984 platformViewsController.onDisplayPlatformView(
985 platformViewId,
986 /* x=*/ 0,
987 /* y=*/ 0,
988 /* width=*/ 10,
989 /* height=*/ 10,
990 /* viewWidth=*/ 10,
991 /* viewHeight=*/ 10,
992 /* mutatorsStack=*/ new FlutterMutatorsStack());
993
994 final PlatformOverlayView overlayImageView = mock(PlatformOverlayView.class);
995 when(overlayImageView.acquireLatestImage()).thenReturn(true);
996
997 final FlutterOverlaySurface overlaySurface =
998 platformViewsController.createOverlaySurface(overlayImageView);
999 platformViewsController.onDisplayOverlaySurface(
1000 overlaySurface.getId(), /* x=*/ 0, /* y=*/ 0, /* width=*/ 10, /* height=*/ 10);
1001
1002 platformViewsController.onEndFrame();
1003
1004 // Simulate first frame from the framework.
1005 jni.onFirstFrame();
1006
1007 verify(overlayImageView, never()).detachFromRenderer();
1008
1009 // Produce a frame that doesn't display platform views.
1010 platformViewsController.onBeginFrame();
1011 platformViewsController.onEndFrame();
1012
1013 shadowOf(getMainLooper()).idle();
1014 verify(overlayImageView, times(1)).detachFromRenderer();
1015 }

◆ onEndFrame_removesPlatformView()

void io.flutter.plugin.platform.PlatformViewsControllerTest.onEndFrame_removesPlatformView ( )
inline

Definition at line 1019 of file PlatformViewsControllerTest.java.

1019 {
1020 final PlatformViewsController platformViewsController = new PlatformViewsController();
1021
1022 final int platformViewId = 0;
1023 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1024
1025 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1026 final PlatformView platformView = mock(PlatformView.class);
1027 final View androidView = mock(View.class);
1028 when(platformView.getView()).thenReturn(androidView);
1029 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1030
1031 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1032
1033 final FlutterJNI jni = new FlutterJNI();
1034 jni.attachToNative();
1035 attach(jni, platformViewsController);
1036
1037 jni.onFirstFrame();
1038
1039 // Simulate create call from the framework.
1040 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1041
1042 // Simulate first frame from the framework.
1043 jni.onFirstFrame();
1044 platformViewsController.onBeginFrame();
1045
1046 platformViewsController.onEndFrame();
1047 verify(androidView, never()).setVisibility(View.GONE);
1048
1049 final ViewParent parentView = mock(ViewParent.class);
1050 when(androidView.getParent()).thenReturn(parentView);
1051 }

◆ onEndFrame_removesPlatformViewParent()

void io.flutter.plugin.platform.PlatformViewsControllerTest.onEndFrame_removesPlatformViewParent ( )
inline

Definition at line 1060 of file PlatformViewsControllerTest.java.

1060 {
1061 final PlatformViewsController platformViewsController = new PlatformViewsController();
1062
1063 final int platformViewId = 0;
1064 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1065
1066 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1067 final PlatformView platformView = mock(PlatformView.class);
1068 final View androidView = mock(View.class);
1069 when(platformView.getView()).thenReturn(androidView);
1070 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1071
1072 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1073
1074 final FlutterJNI jni = new FlutterJNI();
1075 jni.attachToNative();
1076
1077 final FlutterView flutterView = attach(jni, platformViewsController);
1078
1079 jni.onFirstFrame();
1080
1081 // Simulate create call from the framework.
1082 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1083 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
1084 assertEquals(flutterView.getChildCount(), 2);
1085
1086 // Simulate first frame from the framework.
1087 jni.onFirstFrame();
1088 platformViewsController.onBeginFrame();
1089 platformViewsController.onEndFrame();
1090
1091 // Simulate dispose call from the framework.
1092 disposePlatformView(jni, platformViewsController, platformViewId);
1093 assertEquals(flutterView.getChildCount(), 1);
1094 }

◆ onPreEngineRestart_clearsPlatformViewContext()

void io.flutter.plugin.platform.PlatformViewsControllerTest.onPreEngineRestart_clearsPlatformViewContext ( )
inline

Definition at line 720 of file PlatformViewsControllerTest.java.

720 {
721 PlatformViewsController platformViewsController = new PlatformViewsController();
722
723 int platformViewId = 0;
724 assertNull(platformViewsController.getPlatformViewById(platformViewId));
725
726 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
727 PlatformView platformView = mock(PlatformView.class);
728
729 SurfaceView pv = mock(SurfaceView.class);
730 when(pv.getContext()).thenReturn(mock(MutableContextWrapper.class));
731 when(pv.getLayoutParams()).thenReturn(new LayoutParams(1, 1));
732
733 when(platformView.getView()).thenReturn(pv);
734 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
735 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
736
737 FlutterJNI jni = new FlutterJNI();
738 attach(jni, platformViewsController);
739
740 // Simulate create call from the framework.
741 createPlatformView(
742 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
743
744 assertFalse(platformViewsController.contextToEmbeddedView.isEmpty());
745 platformViewsController.onDetachedFromJNI();
746 assertTrue(platformViewsController.contextToEmbeddedView.isEmpty());
747 }

◆ reattachToFlutterView()

void io.flutter.plugin.platform.PlatformViewsControllerTest.reattachToFlutterView ( )
inline

Definition at line 1366 of file PlatformViewsControllerTest.java.

1366 {
1367 PlatformViewsController platformViewsController = new PlatformViewsController();
1368 platformViewsController.setSoftwareRendering(true);
1369
1370 int platformViewId = 100;
1371 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1372
1373 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1374 PlatformView platformView = mock(PlatformView.class);
1375 View androidView = mock(View.class);
1376 when(platformView.getView()).thenReturn(androidView);
1377 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1378 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1379
1380 FlutterJNI jni = new FlutterJNI();
1381 FlutterView initFlutterView = mock(FlutterView.class);
1382 attachToFlutterView(jni, platformViewsController, initFlutterView);
1383
1384 createPlatformView(
1385 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
1386 verify(initFlutterView, times(1)).addView(any(PlatformViewWrapper.class));
1387
1388 platformViewsController.detachFromView();
1389 verify(initFlutterView, times(1)).removeView(any(PlatformViewWrapper.class));
1390
1391 FlutterView newFlutterView = mock(FlutterView.class);
1392 platformViewsController.attachToView(newFlutterView);
1393 verify(newFlutterView, times(1)).addView(any(PlatformViewWrapper.class));
1394 }

◆ resizeAndroidView()

void io.flutter.plugin.platform.PlatformViewsControllerTest.resizeAndroidView ( )
inline

Definition at line 846 of file PlatformViewsControllerTest.java.

846 {
847 PlatformViewsController platformViewsController = new PlatformViewsController();
848 platformViewsController.setSoftwareRendering(true);
849
850 int platformViewId = 0;
851 assertNull(platformViewsController.getPlatformViewById(platformViewId));
852
853 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
854 PlatformView platformView = mock(PlatformView.class);
855 final View androidView = mock(View.class);
856 when(platformView.getView()).thenReturn(androidView);
857 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
858 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
859
860 FlutterJNI jni = new FlutterJNI();
861 attach(jni, platformViewsController);
862
863 // Simulate create call from the framework.
864 createPlatformView(
865 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
866
867 reset(androidView);
868 when(androidView.getLayoutParams()).thenReturn(new FrameLayout.LayoutParams(0, 0));
869
870 // Simulate a resize call from the framework.
871 resize(jni, platformViewsController, platformViewId, 10.0, 20.0);
872
873 ArgumentCaptor<FrameLayout.LayoutParams> layoutParamsCaptor =
874 ArgumentCaptor.forClass(FrameLayout.LayoutParams.class);
875 verify(androidView, times(1)).setLayoutParams(layoutParamsCaptor.capture());
876
877 assertEquals(layoutParamsCaptor.getValue().width, 10);
878 assertEquals(layoutParamsCaptor.getValue().height, 20);
879 }
m reset()

◆ revertImageViewAndRemoveImageView()

void io.flutter.plugin.platform.PlatformViewsControllerTest.revertImageViewAndRemoveImageView ( )
inline

Definition at line 1402 of file PlatformViewsControllerTest.java.

1402 {
1403 final PlatformViewsController platformViewsController = new PlatformViewsController();
1404
1405 final int platformViewId = 0;
1406 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1407
1408 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1409 final PlatformView platformView = mock(PlatformView.class);
1410 final View androidView = mock(View.class);
1411 when(platformView.getView()).thenReturn(androidView);
1412 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1413
1414 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1415
1416 final FlutterJNI jni = new FlutterJNI();
1417 jni.attachToNative();
1418
1419 final FlutterView flutterView = attach(jni, platformViewsController);
1420
1421 jni.onFirstFrame();
1422
1423 // Simulate create call from the framework.
1424 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1425
1426 // The simulation creates an Overlay on top of the PlatformView
1427 // This is going to be called `flutterView.convertToImageView`
1428 platformViewsController.createOverlaySurface();
1429 platformViewsController.onDisplayOverlaySurface(platformViewId, 0, 0, 10, 10);
1430
1431 // This will contain three views: Background ImageView、PlatformView、Overlay ImageView
1432 assertEquals(flutterView.getChildCount(), 3);
1433
1434 FlutterImageView imageView = flutterView.getCurrentImageSurface();
1435
1436 // Make sure the ImageView is inside the current FlutterView.
1437 assertTrue(imageView != null);
1438 assertTrue(flutterView.indexOfChild(imageView) != -1);
1439
1440 // Make sure the overlayView is inside the current FlutterView
1441 assertTrue(platformViewsController.getOverlayLayerViews().size() != 0);
1442 PlatformOverlayView overlayView = platformViewsController.getOverlayLayerViews().get(0);
1443 assertTrue(overlayView != null);
1444 assertTrue(flutterView.indexOfChild(overlayView) != -1);
1445
1446 // Simulate in a new frame, there's no PlatformView, which is called
1447 // `flutterView.revertImageView`. And register a `FlutterUiDisplayListener` callback.
1448 // During callback execution it will invoke `flutterImageView.detachFromRenderer()`.
1449 platformViewsController.onBeginFrame();
1450 platformViewsController.onEndFrame();
1451
1452 // Invoke all registered `FlutterUiDisplayListener` callback
1453 jni.onFirstFrame();
1454
1455 assertEquals(null, flutterView.getCurrentImageSurface());
1456
1457 // Make sure the background ImageVIew is not in the FlutterView
1458 assertTrue(flutterView.indexOfChild(imageView) == -1);
1459
1460 // Make sure the overlay ImageVIew is not in the FlutterView
1461 assertTrue(flutterView.indexOfChild(overlayView) == -1);
1462 }

◆ setPlatformViewDirection_throwIfPlatformViewNotFound()

void io.flutter.plugin.platform.PlatformViewsControllerTest.setPlatformViewDirection_throwIfPlatformViewNotFound ( )
inline

Definition at line 812 of file PlatformViewsControllerTest.java.

812 {
813 PlatformViewsController platformViewsController = new PlatformViewsController();
814
815 int platformViewId = 0;
816 assertNull(platformViewsController.getPlatformViewById(platformViewId));
817
818 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
819 PlatformView platformView = mock(PlatformView.class);
820 final View androidView = mock(View.class);
821 when(platformView.getView()).thenReturn(androidView);
822 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
823 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
824
825 FlutterJNI jni = new FlutterJNI();
826 attach(jni, platformViewsController);
827
828 verify(androidView, never()).setLayoutDirection(anyInt());
829
830 // Simulate create call from the framework.
831 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
832 assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
833
834 // Simulate set direction call from the framework.
835 setLayoutDirection(jni, platformViewsController, platformViewId, 1);
836 verify(androidView, times(1)).setLayoutDirection(1);
837
838 // The limit value of reply message will be equal to 2 if the layout direction is set
839 // successfully, otherwise it will be much more than 2 due to the reply message contains
840 // an error message wrapped with exception detail information.
841 assertEquals(ShadowFlutterJNI.getResponses().get(0).limit(), 2);
842 }

◆ toMotionEvent_returnsSameCoordsForVdAndNonVd()

void io.flutter.plugin.platform.PlatformViewsControllerTest.toMotionEvent_returnsSameCoordsForVdAndNonVd ( )
inline

Definition at line 416 of file PlatformViewsControllerTest.java.

416 {
417 MotionEventTracker motionEventTracker = MotionEventTracker.getInstance();
418 PlatformViewsController platformViewsController = new PlatformViewsController();
419
420 MotionEvent original =
421 MotionEvent.obtain(
422 10, // downTime
423 10, // eventTime
424 261, // action
425 1, // x
426 1, // y
427 0 // metaState
428 );
429
430 MotionEvent resolvedNonVdEvent =
431 makePlatformViewTouchAndInvokeToMotionEvent(
432 platformViewsController, motionEventTracker, original, false);
433
434 MotionEvent resolvedVdEvent =
435 makePlatformViewTouchAndInvokeToMotionEvent(
436 platformViewsController, motionEventTracker, original, true);
437
438 assertEquals(resolvedVdEvent.getEventTime(), resolvedNonVdEvent.getEventTime());
439 assertEquals(resolvedVdEvent.getX(), resolvedNonVdEvent.getX(), 0.001f);
440 assertEquals(resolvedVdEvent.getY(), resolvedNonVdEvent.getY(), 0.001f);
441 }

◆ virtualDisplay_ensureDisposeVirtualDisplayController()

void io.flutter.plugin.platform.PlatformViewsControllerTest.virtualDisplay_ensureDisposeVirtualDisplayController ( )
inline

Definition at line 243 of file PlatformViewsControllerTest.java.

243 {
244 final int platformViewId = 0;
245 FlutterView fakeFlutterView = new FlutterView(ApplicationProvider.getApplicationContext());
246 VirtualDisplayController fakeVdController = mock(VirtualDisplayController.class);
247 PlatformViewsController platformViewsController = new PlatformViewsController();
248 FlutterJNI jni = new FlutterJNI();
249 attach(jni, platformViewsController);
250 platformViewsController.attachToView(fakeFlutterView);
251
252 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
253 PlatformView platformView = mock(PlatformView.class);
254 Context context = ApplicationProvider.getApplicationContext();
255 View androidView = new View(context);
256 when(platformView.getView()).thenReturn(androidView);
257 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
258 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
259 createPlatformView(
260 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
261
262 platformViewsController.vdControllers.put(platformViewId, fakeVdController);
263
264 // Simulate dispose call from the framework.
265 disposePlatformView(jni, platformViewsController, platformViewId);
266
267 // Ensure VirtualDisplayController.dispose() is called
268 verify(fakeVdController, times(1)).dispose();
269 }

◆ virtualDisplay_handlesResizeResponseWithoutContext()

void io.flutter.plugin.platform.PlatformViewsControllerTest.virtualDisplay_handlesResizeResponseWithoutContext ( )
inline

Definition at line 217 of file PlatformViewsControllerTest.java.

217 {
218 final int platformViewId = 0;
219 FlutterView fakeFlutterView = new FlutterView(ApplicationProvider.getApplicationContext());
220 VirtualDisplayController fakeVdController = mock(VirtualDisplayController.class);
221 PlatformViewsController platformViewsController = new PlatformViewsController();
222 platformViewsController.vdControllers.put(platformViewId, fakeVdController);
223
224 platformViewsController.attachToView(fakeFlutterView);
225
226 FlutterJNI jni = new FlutterJNI();
227 attach(jni, platformViewsController);
228
229 resize(jni, platformViewsController, platformViewId, 10.0, 20.0);
230
231 ArgumentCaptor<Runnable> resizeCallbackCaptor = ArgumentCaptor.forClass(Runnable.class);
232 verify(fakeVdController, times(1)).resize(anyInt(), anyInt(), resizeCallbackCaptor.capture());
233
234 // Simulate a detach call before the resize completes.
235 platformViewsController.detach();
236
237 // Trigger the callback to ensure that it doesn't crash.
238 resizeCallbackCaptor.getValue().run();
239 }

The documentation for this class was generated from the following file: