Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 itUsesActionEventTypeFromMotionEventForHybridPlatformViews ()
 
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 1230 of file PlatformViewsControllerTest.java.

1230 {
1231 final PlatformViewsController platformViewsController = new PlatformViewsController();
1232 boolean shouldProxying = platformViewsController.checkInputConnectionProxy(null);
1233 assertFalse(shouldProxying);
1234 }

◆ convertPlatformViewRenderSurfaceAsDefault()

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

Definition at line 1238 of file PlatformViewsControllerTest.java.

1238 {
1239 final PlatformViewsController platformViewsController = new PlatformViewsController();
1240
1241 final int platformViewId = 0;
1242 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1243
1244 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1245 final PlatformView platformView = mock(PlatformView.class);
1246 final View androidView = mock(View.class);
1247 when(platformView.getView()).thenReturn(androidView);
1248 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1249
1250 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1251
1252 final FlutterJNI jni = new FlutterJNI();
1253 jni.attachToNative();
1254 final FlutterView flutterView = attach(jni, platformViewsController);
1255
1256 jni.onFirstFrame();
1257
1258 // Simulate create call from the framework.
1259 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1260
1261 // Produce a frame that displays a platform view and an overlay surface.
1262 platformViewsController.onBeginFrame();
1263 platformViewsController.onDisplayPlatformView(
1264 platformViewId,
1265 /* x=*/ 0,
1266 /* y=*/ 0,
1267 /* width=*/ 10,
1268 /* height=*/ 10,
1269 /* viewWidth=*/ 10,
1270 /* viewHeight=*/ 10,
1271 /* mutatorsStack=*/ new FlutterMutatorsStack());
1272
1273 assertEquals(flutterView.getChildCount(), 3);
1274
1275 final View view = flutterView.getChildAt(1);
1276 assertTrue(view instanceof FlutterImageView);
1277
1278 // Simulate dispose call from the framework.
1279 disposePlatformView(jni, platformViewsController, platformViewId);
1280 }
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 748 of file PlatformViewsControllerTest.java.

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

◆ createHybridPlatformViewMessage_throwsIfViewIsNull()

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

Definition at line 625 of file PlatformViewsControllerTest.java.

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

◆ createPlatformViewMessage_disablesAccessibility()

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

Definition at line 569 of file PlatformViewsControllerTest.java.

569 {
570 PlatformViewsController platformViewsController = new PlatformViewsController();
571 platformViewsController.setSoftwareRendering(true);
572
573 int platformViewId = 0;
574 assertNull(platformViewsController.getPlatformViewById(platformViewId));
575
576 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
577 PlatformView platformView = mock(PlatformView.class);
578
579 View androidView = mock(View.class);
580 when(platformView.getView()).thenReturn(androidView);
581 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
582 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
583
584 FlutterJNI jni = new FlutterJNI();
585 attach(jni, platformViewsController);
586
587 // Simulate create call from the framework.
588 createPlatformView(
589 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
590 verify(androidView, times(1))
591 .setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
592 }
static SkISize times(const SkISize &size, float factor)

◆ createPlatformViewMessage_doesNotWrapContextForHybrid()

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

Definition at line 486 of file PlatformViewsControllerTest.java.

486 {
487 PlatformViewsController platformViewsController = new PlatformViewsController();
488
489 int platformViewId = 0;
490 assertNull(platformViewsController.getPlatformViewById(platformViewId));
491
492 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
493 PlatformView platformView = mock(PlatformView.class);
494 when(platformView.getView()).thenReturn(mock(View.class));
495 ArgumentCaptor<Context> passedContext = ArgumentCaptor.forClass(Context.class);
496 when(viewFactory.create(passedContext.capture(), eq(platformViewId), any()))
497 .thenReturn(platformView);
498 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
499
500 FlutterJNI jni = new FlutterJNI();
501 attach(jni, platformViewsController);
502
503 // Simulate create call from the framework.
504 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
505 assertFalse(passedContext.getValue() instanceof MutableContextWrapper);
506 }

◆ createPlatformViewMessage_initializesAndroidView()

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

Definition at line 439 of file PlatformViewsControllerTest.java.

439 {
440 PlatformViewsController platformViewsController = new PlatformViewsController();
441
442 int platformViewId = 0;
443 assertNull(platformViewsController.getPlatformViewById(platformViewId));
444
445 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
446 PlatformView platformView = mock(PlatformView.class);
447 when(platformView.getView()).thenReturn(mock(View.class));
448 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
449 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
450
451 FlutterJNI jni = new FlutterJNI();
452 attach(jni, platformViewsController);
453
454 // Simulate create call from the framework.
455 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
456 verify(viewFactory, times(1)).create(any(), eq(platformViewId), any());
457 }

◆ createPlatformViewMessage_setsAndroidViewLayoutDirection()

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

Definition at line 510 of file PlatformViewsControllerTest.java.

510 {
511 PlatformViewsController platformViewsController = new PlatformViewsController();
512 platformViewsController.setSoftwareRendering(true);
513
514 int platformViewId = 0;
515 assertNull(platformViewsController.getPlatformViewById(platformViewId));
516
517 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
518 PlatformView platformView = mock(PlatformView.class);
519
520 View androidView = mock(View.class);
521 when(platformView.getView()).thenReturn(androidView);
522 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
523 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
524
525 FlutterJNI jni = new FlutterJNI();
526 attach(jni, platformViewsController);
527
528 // Simulate create call from the framework.
529 createPlatformView(
530 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
531 verify(androidView, times(1)).setLayoutDirection(0);
532 }

◆ createPlatformViewMessage_setsAndroidViewSize()

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

Definition at line 536 of file PlatformViewsControllerTest.java.

536 {
537 PlatformViewsController platformViewsController = new PlatformViewsController();
538 platformViewsController.setSoftwareRendering(true);
539
540 int platformViewId = 0;
541 assertNull(platformViewsController.getPlatformViewById(platformViewId));
542
543 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
544 PlatformView platformView = mock(PlatformView.class);
545
546 View androidView = mock(View.class);
547 when(platformView.getView()).thenReturn(androidView);
548 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
549 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
550
551 FlutterJNI jni = new FlutterJNI();
552 attach(jni, platformViewsController);
553
554 // Simulate create call from the framework.
555 createPlatformView(
556 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
557
558 ArgumentCaptor<FrameLayout.LayoutParams> layoutParamsCaptor =
559 ArgumentCaptor.forClass(FrameLayout.LayoutParams.class);
560 verify(androidView, times(2)).setLayoutParams(layoutParamsCaptor.capture());
561
562 List<FrameLayout.LayoutParams> capturedLayoutParams = layoutParamsCaptor.getAllValues();
563 assertEquals(capturedLayoutParams.get(0).width, 1);
564 assertEquals(capturedLayoutParams.get(0).height, 1);
565 }

◆ createPlatformViewMessage_throwsIfViewHasParent()

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

Definition at line 717 of file PlatformViewsControllerTest.java.

717 {
718 PlatformViewsController platformViewsController = new PlatformViewsController();
719
720 int platformViewId = 0;
721 assertNull(platformViewsController.getPlatformViewById(platformViewId));
722
723 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
724 PlatformView platformView = mock(PlatformView.class);
725 View androidView = mock(View.class);
726 when(androidView.getParent()).thenReturn(mock(ViewParent.class));
727 when(platformView.getView()).thenReturn(androidView);
728 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
729 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
730
731 FlutterJNI jni = new FlutterJNI();
732 attach(jni, platformViewsController);
733
734 // Simulate create call from the framework.
735 createPlatformView(
736 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
737 assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
738
739 assertThrows(
740 IllegalStateException.class,
741 () -> {
742 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
743 });
744 }

◆ createPlatformViewMessage_throwsIfViewIsNull()

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

Definition at line 596 of file PlatformViewsControllerTest.java.

596 {
597 PlatformViewsController platformViewsController = new PlatformViewsController();
598
599 int platformViewId = 0;
600 assertNull(platformViewsController.getPlatformViewById(platformViewId));
601
602 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
603 PlatformView platformView = mock(PlatformView.class);
604 when(platformView.getView()).thenReturn(null);
605 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
606 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
607
608 FlutterJNI jni = new FlutterJNI();
609 attach(jni, platformViewsController);
610
611 // Simulate create call from the framework.
612 createPlatformView(
613 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
614 assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
615
616 assertThrows(
617 IllegalStateException.class,
618 () -> {
619 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
620 });
621 }

◆ createPlatformViewMessage_wrapsContextForVirtualDisplay()

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

Definition at line 461 of file PlatformViewsControllerTest.java.

461 {
462 PlatformViewsController platformViewsController = new PlatformViewsController();
463
464 int platformViewId = 0;
465 assertNull(platformViewsController.getPlatformViewById(platformViewId));
466
467 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
468 PlatformView platformView = mock(PlatformView.class);
469 when(platformView.getView()).thenReturn(mock(View.class));
470 ArgumentCaptor<Context> passedContext = ArgumentCaptor.forClass(Context.class);
471 when(viewFactory.create(passedContext.capture(), eq(platformViewId), any()))
472 .thenReturn(platformView);
473 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
474
475 FlutterJNI jni = new FlutterJNI();
476 attach(jni, platformViewsController);
477
478 // Simulate create call from the framework.
479 createPlatformView(
480 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
481 assertTrue(passedContext.getValue() instanceof MutableContextWrapper);
482 }

◆ destroyOverlaySurfaces_doesNotRemoveOverlayView()

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

Definition at line 1196 of file PlatformViewsControllerTest.java.

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

◆ destroyOverlaySurfaces_doesNotThrowIfFlutterViewIsDetached()

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

Definition at line 1158 of file PlatformViewsControllerTest.java.

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

◆ detach_destroysOverlaySurfaces()

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

Definition at line 1069 of file PlatformViewsControllerTest.java.

1069 {
1070 final PlatformViewsController platformViewsController = new PlatformViewsController();
1071
1072 final int platformViewId = 0;
1073 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1074
1075 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1076 final PlatformView platformView = mock(PlatformView.class);
1077 when(platformView.getView()).thenReturn(mock(View.class));
1078 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1079
1080 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1081
1082 final FlutterJNI jni = new FlutterJNI();
1083 jni.attachToNative();
1084 attach(jni, platformViewsController);
1085
1086 jni.onFirstFrame();
1087
1088 // Simulate create call from the framework.
1089 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1090
1091 // Produce a frame that displays a platform view and an overlay surface.
1092 platformViewsController.onBeginFrame();
1093 platformViewsController.onDisplayPlatformView(
1094 platformViewId,
1095 /* x=*/ 0,
1096 /* y=*/ 0,
1097 /* width=*/ 10,
1098 /* height=*/ 10,
1099 /* viewWidth=*/ 10,
1100 /* viewHeight=*/ 10,
1101 /* mutatorsStack=*/ new FlutterMutatorsStack());
1102
1103 final PlatformOverlayView overlayImageView = mock(PlatformOverlayView.class);
1104 when(overlayImageView.acquireLatestImage()).thenReturn(true);
1105
1106 final FlutterOverlaySurface overlaySurface =
1107 platformViewsController.createOverlaySurface(overlayImageView);
1108 // This is OK.
1109 platformViewsController.onDisplayOverlaySurface(
1110 overlaySurface.getId(), /* x=*/ 0, /* y=*/ 0, /* width=*/ 10, /* height=*/ 10);
1111
1112 platformViewsController.detach();
1113
1114 verify(overlayImageView, times(1)).closeImageReader();
1115 verify(overlayImageView, times(1)).detachFromRenderer();
1116 }

◆ detachFromView_removesAndDestroysOverlayViews()

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

Definition at line 1120 of file PlatformViewsControllerTest.java.

1120 {
1121 final PlatformViewsController platformViewsController = new PlatformViewsController();
1122
1123 final int platformViewId = 0;
1124 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1125
1126 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1127 final PlatformView platformView = mock(PlatformView.class);
1128 when(platformView.getView()).thenReturn(mock(View.class));
1129 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1130
1131 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1132
1133 final FlutterJNI jni = new FlutterJNI();
1134 jni.attachToNative();
1135 attach(jni, platformViewsController);
1136
1137 final FlutterView flutterView = mock(FlutterView.class);
1138 platformViewsController.attachToView(flutterView);
1139
1140 final PlatformOverlayView overlayImageView = mock(PlatformOverlayView.class);
1141 when(overlayImageView.acquireLatestImage()).thenReturn(true);
1142
1143 final FlutterOverlaySurface overlaySurface =
1144 platformViewsController.createOverlaySurface(overlayImageView);
1145
1146 platformViewsController.onDisplayOverlaySurface(
1147 overlaySurface.getId(), /* x=*/ 0, /* y=*/ 0, /* width=*/ 10, /* height=*/ 10);
1148
1149 platformViewsController.detachFromView();
1150
1151 verify(overlayImageView, times(1)).closeImageReader();
1152 verify(overlayImageView, times(1)).detachFromRenderer();
1153 verify(flutterView, times(1)).removeView(overlayImageView);
1154 }

◆ disposeAndroidView_hybridComposition()

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

Definition at line 849 of file PlatformViewsControllerTest.java.

849 {
850 PlatformViewsController platformViewsController = new PlatformViewsController();
851
852 int platformViewId = 0;
853 assertNull(platformViewsController.getPlatformViewById(platformViewId));
854
855 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
856 PlatformView platformView = mock(PlatformView.class);
857
858 Context context = ApplicationProvider.getApplicationContext();
859 View androidView = new View(context);
860
861 when(platformView.getView()).thenReturn(androidView);
862 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
863 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
864
865 FlutterJNI jni = new FlutterJNI();
866 attach(jni, platformViewsController);
867
868 // Simulate create call from the framework.
869 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
870 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
871
872 assertNotNull(androidView.getParent());
873 assertTrue(androidView.getParent() instanceof FlutterMutatorView);
874
875 // Simulate dispose call from the framework.
876 disposePlatformView(jni, platformViewsController, platformViewId);
877 assertNull(androidView.getParent());
878
879 // Simulate create call from the framework.
880 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
881 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
882
883 assertNotNull(androidView.getParent());
884 assertTrue(androidView.getParent() instanceof FlutterMutatorView);
885 verify(platformView, times(1)).dispose();
886 }

◆ disposeNullAndroidView()

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

Definition at line 890 of file PlatformViewsControllerTest.java.

890 {
891 PlatformViewsController platformViewsController = new PlatformViewsController();
892
893 int platformViewId = 0;
894 assertNull(platformViewsController.getPlatformViewById(platformViewId));
895
896 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
897 PlatformView platformView = mock(PlatformView.class);
898
899 View androidView = mock(View.class);
900 when(platformView.getView()).thenReturn(androidView);
901 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
902 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
903
904 FlutterJNI jni = new FlutterJNI();
905 attach(jni, platformViewsController);
906
907 // Simulate create call from the framework.
908 createPlatformView(
909 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
910 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
911
912 when(platformView.getView()).thenReturn(null);
913
914 // Simulate dispose call from the framework.
915 disposePlatformView(jni, platformViewsController, platformViewId);
916 verify(platformView, times(1)).dispose();
917 }

◆ dontConverRenderSurfaceWhenFlagIsTrue()

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

Definition at line 1284 of file PlatformViewsControllerTest.java.

1284 {
1285 final PlatformViewsController platformViewsController = new PlatformViewsController();
1286
1287 final int platformViewId = 0;
1288 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1289
1290 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1291 final PlatformView platformView = mock(PlatformView.class);
1292 final View androidView = mock(View.class);
1293 when(platformView.getView()).thenReturn(androidView);
1294 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1295
1296 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1297
1298 final FlutterJNI jni = new FlutterJNI();
1299 jni.attachToNative();
1300 final FlutterView flutterView = attach(jni, platformViewsController);
1301
1302 jni.onFirstFrame();
1303
1304 // Simulate setting render surface conversion flag.
1305 synchronizeToNativeViewHierarchy(jni, platformViewsController, false);
1306
1307 // Simulate create call from the framework.
1308 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1309
1310 // Produce a frame that displays a platform view and an overlay surface.
1311 platformViewsController.onBeginFrame();
1312 platformViewsController.onDisplayPlatformView(
1313 platformViewId,
1314 /* x=*/ 0,
1315 /* y=*/ 0,
1316 /* width=*/ 10,
1317 /* height=*/ 10,
1318 /* viewWidth=*/ 10,
1319 /* viewHeight=*/ 10,
1320 /* mutatorsStack=*/ new FlutterMutatorsStack());
1321
1322 assertEquals(flutterView.getChildCount(), 2);
1323 assertTrue(!(flutterView.getChildAt(0) instanceof PlatformOverlayView));
1324 assertTrue(flutterView.getChildAt(1) instanceof FlutterMutatorView);
1325
1326 // Simulate dispose call from the framework.
1327 disposePlatformView(jni, platformViewsController, platformViewId);
1328 }

◆ getPlatformViewById_hybridComposition()

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

Definition at line 411 of file PlatformViewsControllerTest.java.

411 {
412 PlatformViewsController platformViewsController = new PlatformViewsController();
413
414 int platformViewId = 0;
415 assertNull(platformViewsController.getPlatformViewById(platformViewId));
416
417 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
418 PlatformView platformView = mock(PlatformView.class);
419 View androidView = mock(View.class);
420 when(platformView.getView()).thenReturn(androidView);
421 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
422 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
423
424 FlutterJNI jni = new FlutterJNI();
425 attach(jni, platformViewsController);
426
427 // Simulate create call from the framework.
428 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
429
430 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
431
432 View resultAndroidView = platformViewsController.getPlatformViewById(platformViewId);
433 assertNotNull(resultAndroidView);
434 assertEquals(resultAndroidView, androidView);
435 }

◆ 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 }

◆ itUsesActionEventTypeFromMotionEventForHybridPlatformViews()

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

Definition at line 366 of file PlatformViewsControllerTest.java.

366 {
367 MotionEventTracker motionEventTracker = MotionEventTracker.getInstance();
368 PlatformViewsController platformViewsController = new PlatformViewsController();
369
370 MotionEvent original =
371 MotionEvent.obtain(
372 100, // downTime
373 100, // eventTime
374 1, // action
375 0, // x
376 0, // y
377 0 // metaState
378 );
379
380 // track an event that will later get passed to us from framework
381 MotionEventTracker.MotionEventId motionEventId = motionEventTracker.track(original);
382
383 PlatformViewTouch frameWorkTouch =
384 new PlatformViewTouch(
385 0, // viewId
386 original.getDownTime(),
387 original.getEventTime(),
388 2, // action
389 1, // pointerCount
390 Arrays.asList(Arrays.asList(0, 0)), // pointer properties
391 Arrays.asList(Arrays.asList(0., 1., 2., 3., 4., 5., 6., 7., 8.)), // pointer coords
392 original.getMetaState(),
393 original.getButtonState(),
394 original.getXPrecision(),
395 original.getYPrecision(),
396 original.getDeviceId(),
397 original.getEdgeFlags(),
398 original.getSource(),
399 original.getFlags(),
400 motionEventId.getId());
401
402 MotionEvent resolvedEvent =
403 platformViewsController.toMotionEvent(
404 /*density=*/ 1, frameWorkTouch, /*usingVirtualDisplay=*/ false);
405
406 assertEquals(resolvedEvent.getAction(), frameWorkTouch.action);
407 }

◆ onDetachedFromJNI_clearsPlatformViewContext()

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

Definition at line 654 of file PlatformViewsControllerTest.java.

654 {
655 PlatformViewsController platformViewsController = new PlatformViewsController();
656
657 int platformViewId = 0;
658 assertNull(platformViewsController.getPlatformViewById(platformViewId));
659
660 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
661 PlatformView platformView = mock(PlatformView.class);
662
663 SurfaceView pv = mock(SurfaceView.class);
664 when(pv.getContext()).thenReturn(mock(MutableContextWrapper.class));
665 when(pv.getLayoutParams()).thenReturn(new LayoutParams(1, 1));
666
667 when(platformView.getView()).thenReturn(pv);
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(
676 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
677
678 assertFalse(platformViewsController.contextToEmbeddedView.isEmpty());
679 platformViewsController.onDetachedFromJNI();
680 assertTrue(platformViewsController.contextToEmbeddedView.isEmpty());
681 }

◆ onEndFrame_destroysOverlaySurfaceAfterFrameOnFlutterSurfaceView()

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

Definition at line 926 of file PlatformViewsControllerTest.java.

926 {
927 final PlatformViewsController platformViewsController = new PlatformViewsController();
928
929 final int platformViewId = 0;
930 assertNull(platformViewsController.getPlatformViewById(platformViewId));
931
932 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
933 final PlatformView platformView = mock(PlatformView.class);
934 when(platformView.getView()).thenReturn(mock(View.class));
935 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
936
937 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
938
939 final FlutterJNI jni = new FlutterJNI();
940 jni.attachToNative();
941 attach(jni, platformViewsController);
942
943 jni.onFirstFrame();
944
945 // Simulate create call from the framework.
946 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
947
948 // Produce a frame that displays a platform view and an overlay surface.
949 platformViewsController.onBeginFrame();
950 platformViewsController.onDisplayPlatformView(
951 platformViewId,
952 /* x=*/ 0,
953 /* y=*/ 0,
954 /* width=*/ 10,
955 /* height=*/ 10,
956 /* viewWidth=*/ 10,
957 /* viewHeight=*/ 10,
958 /* mutatorsStack=*/ new FlutterMutatorsStack());
959
960 final PlatformOverlayView overlayImageView = mock(PlatformOverlayView.class);
961 when(overlayImageView.acquireLatestImage()).thenReturn(true);
962
963 final FlutterOverlaySurface overlaySurface =
964 platformViewsController.createOverlaySurface(overlayImageView);
965 platformViewsController.onDisplayOverlaySurface(
966 overlaySurface.getId(), /* x=*/ 0, /* y=*/ 0, /* width=*/ 10, /* height=*/ 10);
967
968 platformViewsController.onEndFrame();
969
970 // Simulate first frame from the framework.
971 jni.onFirstFrame();
972
973 verify(overlayImageView, never()).detachFromRenderer();
974
975 // Produce a frame that doesn't display platform views.
976 platformViewsController.onBeginFrame();
977 platformViewsController.onEndFrame();
978
979 shadowOf(getMainLooper()).idle();
980 verify(overlayImageView, times(1)).detachFromRenderer();
981 }

◆ onEndFrame_removesPlatformView()

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

Definition at line 985 of file PlatformViewsControllerTest.java.

985 {
986 final PlatformViewsController platformViewsController = new PlatformViewsController();
987
988 final int platformViewId = 0;
989 assertNull(platformViewsController.getPlatformViewById(platformViewId));
990
991 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
992 final PlatformView platformView = mock(PlatformView.class);
993 final View androidView = mock(View.class);
994 when(platformView.getView()).thenReturn(androidView);
995 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
996
997 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
998
999 final FlutterJNI jni = new FlutterJNI();
1000 jni.attachToNative();
1001 attach(jni, platformViewsController);
1002
1003 jni.onFirstFrame();
1004
1005 // Simulate create call from the framework.
1006 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1007
1008 // Simulate first frame from the framework.
1009 jni.onFirstFrame();
1010 platformViewsController.onBeginFrame();
1011
1012 platformViewsController.onEndFrame();
1013 verify(androidView, never()).setVisibility(View.GONE);
1014
1015 final ViewParent parentView = mock(ViewParent.class);
1016 when(androidView.getParent()).thenReturn(parentView);
1017 }

◆ onEndFrame_removesPlatformViewParent()

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

Definition at line 1026 of file PlatformViewsControllerTest.java.

1026 {
1027 final PlatformViewsController platformViewsController = new PlatformViewsController();
1028
1029 final int platformViewId = 0;
1030 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1031
1032 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1033 final PlatformView platformView = mock(PlatformView.class);
1034 final View androidView = mock(View.class);
1035 when(platformView.getView()).thenReturn(androidView);
1036 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1037
1038 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1039
1040 final FlutterJNI jni = new FlutterJNI();
1041 jni.attachToNative();
1042
1043 final FlutterView flutterView = attach(jni, platformViewsController);
1044
1045 jni.onFirstFrame();
1046
1047 // Simulate create call from the framework.
1048 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1049 platformViewsController.initializePlatformViewIfNeeded(platformViewId);
1050 assertEquals(flutterView.getChildCount(), 2);
1051
1052 // Simulate first frame from the framework.
1053 jni.onFirstFrame();
1054 platformViewsController.onBeginFrame();
1055 platformViewsController.onEndFrame();
1056
1057 // Simulate dispose call from the framework.
1058 disposePlatformView(jni, platformViewsController, platformViewId);
1059 assertEquals(flutterView.getChildCount(), 1);
1060 }

◆ onPreEngineRestart_clearsPlatformViewContext()

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

Definition at line 686 of file PlatformViewsControllerTest.java.

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

◆ reattachToFlutterView()

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

Definition at line 1332 of file PlatformViewsControllerTest.java.

1332 {
1333 PlatformViewsController platformViewsController = new PlatformViewsController();
1334 platformViewsController.setSoftwareRendering(true);
1335
1336 int platformViewId = 100;
1337 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1338
1339 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1340 PlatformView platformView = mock(PlatformView.class);
1341 View androidView = mock(View.class);
1342 when(platformView.getView()).thenReturn(androidView);
1343 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1344 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1345
1346 FlutterJNI jni = new FlutterJNI();
1347 FlutterView initFlutterView = mock(FlutterView.class);
1348 attachToFlutterView(jni, platformViewsController, initFlutterView);
1349
1350 createPlatformView(
1351 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
1352 verify(initFlutterView, times(1)).addView(any(PlatformViewWrapper.class));
1353
1354 platformViewsController.detachFromView();
1355 verify(initFlutterView, times(1)).removeView(any(PlatformViewWrapper.class));
1356
1357 FlutterView newFlutterView = mock(FlutterView.class);
1358 platformViewsController.attachToView(newFlutterView);
1359 verify(newFlutterView, times(1)).addView(any(PlatformViewWrapper.class));
1360 }

◆ resizeAndroidView()

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

Definition at line 812 of file PlatformViewsControllerTest.java.

812 {
813 PlatformViewsController platformViewsController = new PlatformViewsController();
814 platformViewsController.setSoftwareRendering(true);
815
816 int platformViewId = 0;
817 assertNull(platformViewsController.getPlatformViewById(platformViewId));
818
819 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
820 PlatformView platformView = mock(PlatformView.class);
821 final View androidView = mock(View.class);
822 when(platformView.getView()).thenReturn(androidView);
823 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
824 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
825
826 FlutterJNI jni = new FlutterJNI();
827 attach(jni, platformViewsController);
828
829 // Simulate create call from the framework.
830 createPlatformView(
831 jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ false);
832
833 reset(androidView);
834 when(androidView.getLayoutParams()).thenReturn(new FrameLayout.LayoutParams(0, 0));
835
836 // Simulate a resize call from the framework.
837 resize(jni, platformViewsController, platformViewId, 10.0, 20.0);
838
839 ArgumentCaptor<FrameLayout.LayoutParams> layoutParamsCaptor =
840 ArgumentCaptor.forClass(FrameLayout.LayoutParams.class);
841 verify(androidView, times(1)).setLayoutParams(layoutParamsCaptor.capture());
842
843 assertEquals(layoutParamsCaptor.getValue().width, 10);
844 assertEquals(layoutParamsCaptor.getValue().height, 20);
845 }
m reset()

◆ revertImageViewAndRemoveImageView()

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

Definition at line 1368 of file PlatformViewsControllerTest.java.

1368 {
1369 final PlatformViewsController platformViewsController = new PlatformViewsController();
1370
1371 final int platformViewId = 0;
1372 assertNull(platformViewsController.getPlatformViewById(platformViewId));
1373
1374 final PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
1375 final PlatformView platformView = mock(PlatformView.class);
1376 final View androidView = mock(View.class);
1377 when(platformView.getView()).thenReturn(androidView);
1378 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
1379
1380 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
1381
1382 final FlutterJNI jni = new FlutterJNI();
1383 jni.attachToNative();
1384
1385 final FlutterView flutterView = attach(jni, platformViewsController);
1386
1387 jni.onFirstFrame();
1388
1389 // Simulate create call from the framework.
1390 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
1391
1392 // The simulation creates an Overlay on top of the PlatformView
1393 // This is going to be called `flutterView.convertToImageView`
1394 platformViewsController.createOverlaySurface();
1395 platformViewsController.onDisplayOverlaySurface(platformViewId, 0, 0, 10, 10);
1396
1397 // This will contain three views: Background ImageView、PlatformView、Overlay ImageView
1398 assertEquals(flutterView.getChildCount(), 3);
1399
1400 FlutterImageView imageView = flutterView.getCurrentImageSurface();
1401
1402 // Make sure the ImageView is inside the current FlutterView.
1403 assertTrue(imageView != null);
1404 assertTrue(flutterView.indexOfChild(imageView) != -1);
1405
1406 // Make sure the overlayView is inside the current FlutterView
1407 assertTrue(platformViewsController.getOverlayLayerViews().size() != 0);
1408 PlatformOverlayView overlayView = platformViewsController.getOverlayLayerViews().get(0);
1409 assertTrue(overlayView != null);
1410 assertTrue(flutterView.indexOfChild(overlayView) != -1);
1411
1412 // Simulate in a new frame, there's no PlatformView, which is called
1413 // `flutterView.revertImageView`. And register a `FlutterUiDisplayListener` callback.
1414 // During callback execution it will invoke `flutterImageView.detachFromRenderer()`.
1415 platformViewsController.onBeginFrame();
1416 platformViewsController.onEndFrame();
1417
1418 // Invoke all registered `FlutterUiDisplayListener` callback
1419 jni.onFirstFrame();
1420
1421 assertEquals(null, flutterView.getCurrentImageSurface());
1422
1423 // Make sure the background ImageVIew is not in the FlutterView
1424 assertTrue(flutterView.indexOfChild(imageView) == -1);
1425
1426 // Make sure the overlay ImageVIew is not in the FlutterView
1427 assertTrue(flutterView.indexOfChild(overlayView) == -1);
1428 }

◆ setPlatformViewDirection_throwIfPlatformViewNotFound()

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

Definition at line 778 of file PlatformViewsControllerTest.java.

778 {
779 PlatformViewsController platformViewsController = new PlatformViewsController();
780
781 int platformViewId = 0;
782 assertNull(platformViewsController.getPlatformViewById(platformViewId));
783
784 PlatformViewFactory viewFactory = mock(PlatformViewFactory.class);
785 PlatformView platformView = mock(PlatformView.class);
786 final View androidView = mock(View.class);
787 when(platformView.getView()).thenReturn(androidView);
788 when(viewFactory.create(any(), eq(platformViewId), any())).thenReturn(platformView);
789 platformViewsController.getRegistry().registerViewFactory("testType", viewFactory);
790
791 FlutterJNI jni = new FlutterJNI();
792 attach(jni, platformViewsController);
793
794 verify(androidView, never()).setLayoutDirection(anyInt());
795
796 // Simulate create call from the framework.
797 createPlatformView(jni, platformViewsController, platformViewId, "testType", /* hybrid=*/ true);
798 assertEquals(ShadowFlutterJNI.getResponses().size(), 1);
799
800 // Simulate set direction call from the framework.
801 setLayoutDirection(jni, platformViewsController, platformViewId, 1);
802 verify(androidView, times(1)).setLayoutDirection(1);
803
804 // The limit value of reply message will be equal to 2 if the layout direction is set
805 // successfully, otherwise it will be much more than 2 due to the reply message contains
806 // an error message wrapped with exception detail information.
807 assertEquals(ShadowFlutterJNI.getResponses().get(0).limit(), 2);
808 }

◆ 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: