1package io.flutter.embedding.android;
3import static android.content.ComponentCallbacks2.*;
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertNotNull;
7import static org.junit.Assert.assertNull;
8import static org.junit.Assert.assertThrows;
9import static org.junit.Assert.assertTrue;
10import static org.mockito.ArgumentMatchers.any;
11import static org.mockito.ArgumentMatchers.eq;
12import static org.mockito.ArgumentMatchers.isNotNull;
13import static org.mockito.ArgumentMatchers.isNull;
14import static org.mockito.Mockito.mock;
15import static org.mockito.Mockito.never;
16import static org.mockito.Mockito.times;
17import static org.mockito.Mockito.verify;
18import static org.mockito.Mockito.when;
26import androidx.annotation.NonNull;
27import androidx.lifecycle.Lifecycle;
28import androidx.test.core.app.ApplicationProvider;
29import androidx.test.ext.junit.runners.AndroidJUnit4;
30import io.flutter.FlutterInjector;
31import io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.Host;
32import io.flutter.embedding.engine.FlutterEngine;
33import io.flutter.embedding.engine.FlutterEngineCache;
34import io.flutter.embedding.engine.FlutterEngineGroup;
35import io.flutter.embedding.engine.FlutterEngineGroupCache;
36import io.flutter.embedding.engine.FlutterShellArgs;
37import io.flutter.embedding.engine.dart.DartExecutor;
38import io.flutter.embedding.engine.loader.FlutterLoader;
39import io.flutter.embedding.engine.plugins.activity.ActivityControlSurface;
40import io.flutter.embedding.engine.renderer.FlutterRenderer;
41import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
42import io.flutter.embedding.engine.systemchannels.AccessibilityChannel;
43import io.flutter.embedding.engine.systemchannels.BackGestureChannel;
44import io.flutter.embedding.engine.systemchannels.LifecycleChannel;
45import io.flutter.embedding.engine.systemchannels.LocalizationChannel;
46import io.flutter.embedding.engine.systemchannels.MouseCursorChannel;
47import io.flutter.embedding.engine.systemchannels.NavigationChannel;
48import io.flutter.embedding.engine.systemchannels.SettingsChannel;
49import io.flutter.embedding.engine.systemchannels.SystemChannel;
50import io.flutter.embedding.engine.systemchannels.TextInputChannel;
51import io.flutter.plugin.localization.LocalizationPlugin;
52import io.flutter.plugin.platform.PlatformViewsController;
53import java.util.ArrayList;
54import java.util.Arrays;
56import org.junit.Before;
58import org.junit.runner.RunWith;
59import org.mockito.ArgumentCaptor;
60import org.robolectric.Robolectric;
61import org.robolectric.android.controller.ActivityController;
62import org.robolectric.annotation.Config;
65@RunWith(AndroidJUnit4.class)
67 private final Context ctx = ApplicationProvider.getApplicationContext();
69 private FlutterActivityAndFragmentDelegate.Host mockHost;
70 private FlutterActivityAndFragmentDelegate.Host mockHost2;
72 @SuppressWarnings(
"deprecation")
80 mockFlutterEngine = mockFlutterEngine();
84 when(mockHost.getContext()).thenReturn(ctx);
85 when(mockHost.getActivity()).thenReturn(Robolectric.setupActivity(Activity.class));
86 when(mockHost.getLifecycle()).thenReturn(mock(Lifecycle.class));
87 when(mockHost.getFlutterShellArgs()).thenReturn(
new FlutterShellArgs(
new String[] {}));
88 when(mockHost.getDartEntrypointFunctionName()).thenReturn(
"main");
89 when(mockHost.getDartEntrypointArgs()).thenReturn(
null);
90 when(mockHost.getAppBundlePath()).thenReturn(
"/fake/path");
91 when(mockHost.getInitialRoute()).thenReturn(
"/");
94 when(mockHost.provideFlutterEngine(any(
Context.class))).thenReturn(mockFlutterEngine);
95 when(mockHost.shouldAttachEngineToActivity()).thenReturn(
true);
96 when(mockHost.shouldHandleDeeplinking()).thenReturn(
false);
97 when(mockHost.shouldDestroyEngineWithHost()).thenReturn(
true);
98 when(mockHost.shouldDispatchAppLifecycleState()).thenReturn(
true);
99 when(mockHost.attachToEngineAutomatically()).thenReturn(
true);
102 when(mockHost2.getContext()).thenReturn(ctx);
103 when(mockHost2.getActivity()).thenReturn(Robolectric.setupActivity(Activity.class));
104 when(mockHost2.getLifecycle()).thenReturn(mock(Lifecycle.class));
105 when(mockHost2.getFlutterShellArgs()).thenReturn(
new FlutterShellArgs(
new String[] {}));
106 when(mockHost2.getDartEntrypointFunctionName()).thenReturn(
"main");
107 when(mockHost2.getDartEntrypointArgs()).thenReturn(
null);
108 when(mockHost2.getAppBundlePath()).thenReturn(
"/fake/path");
109 when(mockHost2.getInitialRoute()).thenReturn(
"/");
112 when(mockHost2.provideFlutterEngine(any(
Context.class))).thenReturn(mockFlutterEngine);
113 when(mockHost2.shouldAttachEngineToActivity()).thenReturn(
true);
114 when(mockHost2.shouldHandleDeeplinking()).thenReturn(
false);
115 when(mockHost2.shouldDestroyEngineWithHost()).thenReturn(
true);
116 when(mockHost2.shouldDispatchAppLifecycleState()).thenReturn(
true);
117 when(mockHost2.attachToEngineAutomatically()).thenReturn(
true);
135 verify(mockFlutterEngine.getLifecycleChannel(), never()).aWindowIsFocused();
136 verify(mockFlutterEngine.getLifecycleChannel(), never()).noWindowsAreFocused();
137 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsResumed();
138 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsInactive();
139 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsPaused();
140 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsDetached();
144 verify(mockFlutterEngine.getLifecycleChannel(), never()).aWindowIsFocused();
145 verify(mockFlutterEngine.getLifecycleChannel(), never()).noWindowsAreFocused();
146 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsResumed();
147 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsInactive();
148 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsPaused();
149 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsDetached();
154 verify(mockFlutterEngine.getLifecycleChannel(), never()).aWindowIsFocused();
155 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).noWindowsAreFocused();
156 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsResumed();
157 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsInactive();
158 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsPaused();
159 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsDetached();
163 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).aWindowIsFocused();
164 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).noWindowsAreFocused();
165 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsResumed();
166 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsInactive();
167 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsPaused();
168 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsDetached();
172 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).aWindowIsFocused();
173 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).noWindowsAreFocused();
174 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsResumed();
175 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsInactive();
176 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsPaused();
177 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsDetached();
183 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).aWindowIsFocused();
184 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).noWindowsAreFocused();
185 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsResumed();
186 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsInactive();
187 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsPaused();
188 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsDetached();
192 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).aWindowIsFocused();
193 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).noWindowsAreFocused();
194 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsResumed();
195 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsInactive();
196 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsPaused();
197 verify(mockFlutterEngine.getLifecycleChannel(),
times(1)).appIsDetached();
206 when(mockHost.shouldDispatchAppLifecycleState()).thenReturn(
false);
220 verify(mockFlutterEngine.getLifecycleChannel(), never()).aWindowIsFocused();
221 verify(mockFlutterEngine.getLifecycleChannel(), never()).noWindowsAreFocused();
222 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsResumed();
223 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsPaused();
224 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsInactive();
225 verify(mockFlutterEngine.getLifecycleChannel(), never()).appIsDetached();
239 verify(mockHost,
times(1)).provideFlutterEngine(any(
Context.class));
243 "The delegate failed to use the host's FlutterEngine.",
253 FlutterEngineCache.getInstance().put(
"my_flutter_engine", cachedEngine);
256 when(mockHost.getCachedEngineId()).thenReturn(
"my_flutter_engine");
270 verify(mockFlutterEngine.getDartExecutor(), never())
271 .executeDartEntrypoint(any(DartExecutor.DartEntrypoint.class));
275 verify(cachedEngine.getDartExecutor(), never())
276 .executeDartEntrypoint(any(DartExecutor.DartEntrypoint.class));
279 verify(cachedEngine.getLifecycleChannel(),
times(1)).appIsResumed();
282 @Test(expected = IllegalStateException.class)
283 public
void itThrowsExceptionIfCachedEngineDoesNotExist() {
286 when(mockHost.getCachedEngineId()).thenReturn(
"my_flutter_engine");
302 FlutterLoader mockFlutterLoader = mock(FlutterLoader.class);
303 Activity mockActivity = mock(Activity.class);
304 Intent mockIntent = mock(Intent.class);
305 when(mockFlutterLoader.findAppBundlePath()).thenReturn(
"default_flutter_assets/path");
309 FlutterEngineGroupCache.getInstance().put(
"my_flutter_engine_group", flutterEngineGroup);
312 entryPointArgs.
add(
"entrypoint-arg");
315 when(mockHost.getInitialRoute()).thenReturn(
null);
316 when(mockHost.getCachedEngineGroupId()).thenReturn(
"my_flutter_engine_group");
317 when(mockHost.provideFlutterEngine(any(
Context.class))).thenReturn(
null);
318 when(mockHost.shouldAttachEngineToActivity()).thenReturn(
false);
319 when(mockHost.getDartEntrypointArgs()).thenReturn(entryPointArgs);
320 when(mockHost.shouldHandleDeeplinking()).thenReturn(
true);
321 when(mockHost.getActivity()).thenReturn(mockActivity);
322 when(mockActivity.getIntent()).thenReturn(mockIntent);
323 when(mockIntent.getData()).thenReturn(Uri.parse(
"foo://example.com/initial_route"));
332 DartExecutor.DartEntrypoint entrypoint =
new DartExecutor.DartEntrypoint(
"/fake/path",
"main");
335 verify(flutterEngineGroup,
times(1)).createAndRunEngine(optionsCaptor.capture());
336 assertEquals(
"foo://example.com/initial_route", optionsCaptor.getValue().getInitialRoute());
342 FlutterLoader mockFlutterLoader = mock(FlutterLoader.class);
343 when(mockFlutterLoader.findAppBundlePath()).thenReturn(
"default_flutter_assets/path");
347 FlutterEngineGroupCache.getInstance().put(
"my_flutter_engine_group", flutterEngineGroup);
350 entryPointArgs.
add(
"entrypoint-arg");
353 when(mockHost.getCachedEngineGroupId()).thenReturn(
"my_flutter_engine_group");
354 when(mockHost.provideFlutterEngine(any(
Context.class))).thenReturn(
null);
355 when(mockHost.shouldAttachEngineToActivity()).thenReturn(
false);
356 when(mockHost.getDartEntrypointArgs()).thenReturn(entryPointArgs);
368 DartExecutor.DartEntrypoint entrypoint =
new DartExecutor.DartEntrypoint(
"/fake/path",
"main");
371 verify(flutterEngineGroup,
times(1)).createAndRunEngine(optionsCaptor.capture());
372 assertEquals(mockHost.getContext(), optionsCaptor.getValue().getContext());
373 assertEquals(entrypoint, optionsCaptor.getValue().getDartEntrypoint());
374 assertEquals(mockHost.getInitialRoute(), optionsCaptor.getValue().getInitialRoute());
375 assertNotNull(optionsCaptor.getValue().getDartEntrypointArgs());
376 assertEquals(1, optionsCaptor.getValue().getDartEntrypointArgs().size());
377 assertEquals(
"entrypoint-arg", optionsCaptor.getValue().getDartEntrypointArgs().get(0));
380 @Test(expected = IllegalStateException.class)
381 public
void itThrowsExceptionIfNewEngineInGroupNotExist() {
383 FlutterEngineGroupCache.getInstance().clear();
386 when(mockHost.getCachedEngineGroupId()).thenReturn(
"my_flutter_engine_group");
387 when(mockHost.getCachedEngineId()).thenReturn(
null);
388 when(mockHost.provideFlutterEngine(any(
Context.class))).thenReturn(
null);
389 when(mockHost.shouldAttachEngineToActivity()).thenReturn(
false);
412 verify(mockHost,
times(1)).configureFlutterEngine(mockFlutterEngine);
426 verify(mockHost,
times(1)).onFlutterSurfaceViewCreated(isNotNull());
429 @SuppressWarnings(
"deprecation")
435 Host customMockHost = mock(Host.class);
436 when(customMockHost.getContext()).thenReturn(ctx);
437 when(customMockHost.getActivity()).thenReturn(Robolectric.setupActivity(Activity.class));
438 when(customMockHost.getLifecycle()).thenReturn(mock(Lifecycle.class));
439 when(customMockHost.getFlutterShellArgs()).thenReturn(
new FlutterShellArgs(
new String[] {}));
440 when(customMockHost.getDartEntrypointFunctionName()).thenReturn(
"main");
441 when(customMockHost.getAppBundlePath()).thenReturn(
"/fake/path");
442 when(customMockHost.getInitialRoute()).thenReturn(
"/");
445 when(customMockHost.provideFlutterEngine(any(
Context.class))).thenReturn(mockFlutterEngine);
446 when(customMockHost.shouldAttachEngineToActivity()).thenReturn(
true);
447 when(customMockHost.shouldDestroyEngineWithHost()).thenReturn(
true);
458 verify(customMockHost,
times(1)).onFlutterTextureViewCreated(isNotNull());
473 verify(mockHost,
times(1)).cleanUpFlutterEngine(mockFlutterEngine);
480 when(mockHost.getInitialRoute()).thenReturn(
"/my/route");
492 verify(mockFlutterEngine.getNavigationChannel(),
times(1)).setInitialRoute(
"/my/route");
499 when(mockHost.getAppBundlePath()).thenReturn(
"/my/bundle/path");
500 when(mockHost.getDartEntrypointFunctionName()).thenReturn(
"myEntrypoint");
503 DartExecutor.DartEntrypoint dartEntrypoint =
504 new DartExecutor.DartEntrypoint(
"/my/bundle/path",
"myEntrypoint");
516 verify(mockFlutterEngine.getDartExecutor(),
times(1))
517 .executeDartEntrypoint(
eq(dartEntrypoint), isNull());
524 when(mockHost.getAppBundlePath()).thenReturn(
"/my/bundle/path");
525 when(mockHost.getDartEntrypointFunctionName()).thenReturn(
"myEntrypoint");
526 List<String> dartEntrypointArgs =
new ArrayList<String>(Arrays.asList(
"foo",
"bar"));
527 when(mockHost.getDartEntrypointArgs()).thenReturn(dartEntrypointArgs);
530 DartExecutor.DartEntrypoint dartEntrypoint =
531 new DartExecutor.DartEntrypoint(
"/my/bundle/path",
"myEntrypoint");
543 verify(mockFlutterEngine.getDartExecutor(),
times(1))
544 .executeDartEntrypoint(any(DartExecutor.DartEntrypoint.class),
eq(dartEntrypointArgs));
549 when(mockHost.getAppBundlePath()).thenReturn(
"/my/bundle/path");
550 when(mockHost.getDartEntrypointFunctionName()).thenReturn(
"myEntrypoint");
551 when(mockHost.getDartEntrypointLibraryUri()).thenReturn(
"package:foo/bar.dart");
553 DartExecutor.DartEntrypoint expectedEntrypoint =
554 new DartExecutor.DartEntrypoint(
"/my/bundle/path",
"package:foo/bar.dart",
"myEntrypoint");
562 verify(mockFlutterEngine.getDartExecutor(),
times(1))
563 .executeDartEntrypoint(
eq(expectedEntrypoint), isNull());
569 FlutterLoader mockFlutterLoader = mock(FlutterLoader.class);
570 when(mockFlutterLoader.findAppBundlePath()).thenReturn(
"default_flutter_assets/path");
575 when(mockHost.getAppBundlePath()).thenReturn(
null);
576 when(mockHost.getDartEntrypointFunctionName()).thenReturn(
"myEntrypoint");
579 DartExecutor.DartEntrypoint dartEntrypoint =
580 new DartExecutor.DartEntrypoint(
"default_flutter_assets/path",
"myEntrypoint");
592 verify(mockFlutterEngine.getDartExecutor(),
times(1))
593 .executeDartEntrypoint(
eq(dartEntrypoint), isNull());
603 when(mockHost.shouldAttachEngineToActivity()).thenReturn(
true);
613 verify(mockFlutterEngine.getActivityControlSurface(),
times(1))
620 verify(mockFlutterEngine.getActivityControlSurface(),
times(1)).detachFromActivity();
630 when(mockHost.shouldAttachEngineToActivity()).thenReturn(
false);
633 when(mockHost.getActivity()).thenReturn(
null);
655 verify(mockFlutterEngine.getActivityControlSurface(), never())
657 verify(mockFlutterEngine.getActivityControlSurface(), never()).detachFromActivity();
673 verify(mockFlutterEngine.getNavigationChannel(),
times(1)).popRoute();
686 BackEvent backEvent = mock(BackEvent.class);
690 verify(mockFlutterEngine.getBackGestureChannel(),
times(1)).startBackGesture(backEvent);
703 BackEvent backEvent = mock(BackEvent.class);
707 verify(mockFlutterEngine.getBackGestureChannel(),
times(1))
708 .updateBackGestureProgress(backEvent);
724 verify(mockFlutterEngine.getBackGestureChannel(),
times(1)).commitBackGesture();
740 verify(mockFlutterEngine.getBackGestureChannel(),
times(1)).cancelBackGesture();
756 verify(mockFlutterEngine.getActivityControlSurface(),
times(1))
757 .onRequestPermissionsResult(any(Integer.class), any(String[].
class), any(
int[].
class));
764 intent.setData(Uri.parse(
"http://myApp/custom/route?query=test"));
766 ActivityController<FlutterActivity> activityController =
770 when(mockHost.getActivity()).thenReturn(flutterActivity);
771 when(mockHost.getInitialRoute()).thenReturn(
null);
772 when(mockHost.shouldHandleDeeplinking()).thenReturn(
true);
784 verify(mockFlutterEngine.getNavigationChannel(),
times(1))
785 .setInitialRoute(
"http://myApp/custom/route?query=test");
792 intent.setData(Uri.parse(
"http://myApp/custom/route?query=test#fragment"));
794 ActivityController<FlutterActivity> activityController =
798 when(mockHost.getActivity()).thenReturn(flutterActivity);
799 when(mockHost.getInitialRoute()).thenReturn(
null);
800 when(mockHost.shouldHandleDeeplinking()).thenReturn(
true);
812 verify(mockFlutterEngine.getNavigationChannel(),
times(1))
813 .setInitialRoute(
"http://myApp/custom/route?query=test#fragment");
820 intent.setData(Uri.parse(
"http://myApp/custom/route#fragment"));
822 ActivityController<FlutterActivity> activityController =
826 when(mockHost.getActivity()).thenReturn(flutterActivity);
827 when(mockHost.getInitialRoute()).thenReturn(
null);
828 when(mockHost.shouldHandleDeeplinking()).thenReturn(
true);
840 verify(mockFlutterEngine.getNavigationChannel(),
times(1))
841 .setInitialRoute(
"http://myApp/custom/route#fragment");
848 intent.setData(Uri.parse(
"http://myApp/custom/route"));
850 ActivityController<FlutterActivity> activityController =
854 when(mockHost.getActivity()).thenReturn(flutterActivity);
855 when(mockHost.getInitialRoute()).thenReturn(
null);
856 when(mockHost.shouldHandleDeeplinking()).thenReturn(
true);
868 verify(mockFlutterEngine.getNavigationChannel(),
times(1))
869 .setInitialRoute(
"http://myApp/custom/route");
877 ActivityController<FlutterActivity> activityController =
881 when(mockHost.getActivity()).thenReturn(flutterActivity);
882 when(mockHost.getInitialRoute()).thenReturn(
null);
883 when(mockHost.shouldHandleDeeplinking()).thenReturn(
true);
895 verify(mockFlutterEngine.getNavigationChannel(),
times(1)).setInitialRoute(
"/");
900 when(mockHost.shouldHandleDeeplinking()).thenReturn(
true);
907 String expected =
"http://myApp/custom/route?query=test";
909 Intent mockIntent = mock(Intent.class);
910 when(mockIntent.getData()).thenReturn(Uri.parse(expected));
915 verify(mockFlutterEngine.getNavigationChannel(),
times(1)).pushRouteInformation(expected);
920 when(mockHost.shouldHandleDeeplinking()).thenReturn(
true);
928 Intent mockIntent = mock(Intent.class);
931 when(mockIntent.getData()).thenReturn(Uri.parse(
"mailto:test@test.com"));
937 verify(mockFlutterEngine.getNavigationChannel(),
times(1))
938 .pushRouteInformation(
"mailto:test@test.com");
943 when(mockHost.shouldHandleDeeplinking()).thenReturn(
true);
950 String expected =
"http://myApp/custom/route?query=test#fragment";
952 Intent mockIntent = mock(Intent.class);
953 when(mockIntent.getData()).thenReturn(Uri.parse(expected));
958 verify(mockFlutterEngine.getNavigationChannel(),
times(1)).pushRouteInformation(expected);
963 when(mockHost.shouldHandleDeeplinking()).thenReturn(
true);
970 String expected =
"http://myApp/custom/route#fragment";
972 Intent mockIntent = mock(Intent.class);
973 when(mockIntent.getData()).thenReturn(Uri.parse(expected));
978 verify(mockFlutterEngine.getNavigationChannel(),
times(1)).pushRouteInformation(expected);
983 when(mockHost.shouldHandleDeeplinking()).thenReturn(
true);
990 String expected =
"http://myApp/custom/route#fragment";
992 Intent mockIntent = mock(Intent.class);
993 when(mockIntent.getData()).thenReturn(Uri.parse(expected));
998 verify(mockFlutterEngine.getNavigationChannel(),
times(1)).pushRouteInformation(expected);
1014 verify(mockFlutterEngine.getActivityControlSurface(),
times(1)).onNewIntent(any(Intent.class));
1030 verify(mockFlutterEngine.getActivityControlSurface(),
times(1))
1031 .onActivityResult(any(Integer.class), any(Integer.class), isNull());
1047 verify(mockFlutterEngine.getActivityControlSurface(),
times(1)).onUserLeaveHint();
1060 verify(mockHost,
times(0)).onFlutterUiDisplayed();
1065 verify(mockFlutterEngine.getDartExecutor(),
times(0)).notifyLowMemoryWarning();
1066 verify(mockFlutterEngine.getSystemChannel(),
times(0)).sendMemoryPressureWarning();
1073 verify(mockFlutterEngine.getDartExecutor(),
times(0)).notifyLowMemoryWarning();
1074 verify(mockFlutterEngine.getSystemChannel(),
times(0)).sendMemoryPressureWarning();
1076 verify(mockHost,
times(0)).onFlutterUiDisplayed();
1080 ArgumentCaptor<FlutterUiDisplayListener> listenerCaptor =
1081 ArgumentCaptor.forClass(FlutterUiDisplayListener.class);
1083 verify(renderer,
times(2)).addIsDisplayingFlutterUiListener(listenerCaptor.capture());
1084 listenerCaptor.getValue().onFlutterUiDisplayed();
1086 verify(mockHost,
times(1)).onFlutterUiDisplayed();
1089 verify(mockFlutterEngine.getDartExecutor(),
times(0)).notifyLowMemoryWarning();
1090 verify(mockFlutterEngine.getSystemChannel(),
times(0)).sendMemoryPressureWarning();
1098 verify(mockFlutterEngine.getDartExecutor(),
times(6)).notifyLowMemoryWarning();
1099 verify(mockFlutterEngine.getSystemChannel(),
times(6)).sendMemoryPressureWarning();
1106 when(mockHost.shouldDestroyEngineWithHost()).thenReturn(
true);
1123 verify(mockFlutterEngine,
times(1)).destroy();
1130 when(mockHost.shouldDestroyEngineWithHost()).thenReturn(
false);
1147 verify(mockFlutterEngine, never()).destroy();
1155 FlutterEngineCache.getInstance().put(
"my_flutter_engine", cachedEngine);
1158 when(mockHost.getCachedEngineId()).thenReturn(
"my_flutter_engine");
1161 when(mockHost.shouldDestroyEngineWithHost()).thenReturn(
true);
1178 verify(cachedEngine,
times(1)).destroy();
1179 assertNull(FlutterEngineCache.getInstance().get(
"my_flutter_engine"));
1187 FlutterEngineCache.getInstance().put(
"my_flutter_engine", cachedEngine);
1190 when(mockHost.getCachedEngineId()).thenReturn(
"my_flutter_engine");
1193 when(mockHost.shouldDestroyEngineWithHost()).thenReturn(
false);
1210 verify(cachedEngine, never()).destroy();
1223 boolean shouldDelayFirstAndroidViewDraw =
true;
1224 delegate.
onCreateView(
null,
null,
null, 0, shouldDelayFirstAndroidViewDraw);
1239 boolean shouldDelayFirstAndroidViewDraw =
false;
1240 delegate.
onCreateView(
null,
null,
null, 0, shouldDelayFirstAndroidViewDraw);
1256 boolean shouldDelayFirstAndroidViewDraw =
true;
1258 IllegalArgumentException.class,
1260 delegate.onCreateView(null, null, null, 0, shouldDelayFirstAndroidViewDraw);
1275 assertEquals(View.VISIBLE, delegate.
flutterView.getVisibility());
1278 assertEquals(View.GONE, delegate.
flutterView.getVisibility());
1281 assertEquals(View.VISIBLE, delegate.
flutterView.getVisibility());
1283 delegate.
flutterView.setVisibility(View.INVISIBLE);
1286 assertEquals(View.GONE, delegate.
flutterView.getVisibility());
1289 assertEquals(View.INVISIBLE, delegate.
flutterView.getVisibility());
1294 assertEquals(View.GONE, delegate.
flutterView.getVisibility());
1297 assertEquals(View.GONE, delegate.
flutterView.getVisibility());
1316 assertEquals(View.GONE, surfaceView.getVisibility());
1319 assertEquals(View.VISIBLE, surfaceView.getVisibility());
1321 delegate.
flutterView.setVisibility(View.INVISIBLE);
1322 assertEquals(View.INVISIBLE, surfaceView.getVisibility());
1329 .thenReturn(mockFlutterEngine);
1330 FlutterActivityAndFragmentDelegate.Host host =
1332 when(mockHost.getContext()).thenReturn(ctx);
1338 assertEquals(engineUnderTest, mockFlutterEngine);
1350 assertTrue(delegate.
flutterView.isAttachedToFlutterEngine());
1357 when(mockHost.attachToEngineAutomatically()).thenReturn(
false);
1363 assertFalse(delegate.
flutterView.isAttachedToFlutterEngine());
1369 FlutterEngineCache.getInstance().put(
"my_flutter_engine", cachedEngine);
1372 when(mockHost.shouldDestroyEngineWithHost()).thenReturn(
false);
1373 when(mockHost2.shouldDestroyEngineWithHost()).thenReturn(
false);
1376 when(mockHost.getCachedEngineId()).thenReturn(
"my_flutter_engine");
1377 when(mockHost2.getCachedEngineId()).thenReturn(
"my_flutter_engine");
1415 verify(cachedEngine.getLifecycleChannel(),
times(1)).appIsDetached();
1421 verify(cachedEngine.getLifecycleChannel(),
times(1)).appIsResumed();
1422 verify(cachedEngine.getLifecycleChannel(),
times(1)).appIsDetached();
1429 verify(cachedEngine.getLifecycleChannel(),
times(1)).appIsDetached();
1445 SettingsChannel fakeSettingsChannel = mock(SettingsChannel.class);
1446 SettingsChannel.MessageBuilder fakeMessageBuilder = mock(SettingsChannel.MessageBuilder.class);
1447 when(fakeMessageBuilder.setPlatformBrightness(any(SettingsChannel.PlatformBrightness.class)))
1448 .thenReturn(fakeMessageBuilder);
1449 when(fakeMessageBuilder.setTextScaleFactor(any(Float.class))).thenReturn(fakeMessageBuilder);
1450 when(fakeMessageBuilder.setDisplayMetrics(any())).thenReturn(fakeMessageBuilder);
1451 when(fakeMessageBuilder.setNativeSpellCheckServiceDefined(any(Boolean.class)))
1452 .thenReturn(fakeMessageBuilder);
1453 when(fakeMessageBuilder.setBrieflyShowPassword(any(Boolean.class)))
1454 .thenReturn(fakeMessageBuilder);
1455 when(fakeMessageBuilder.setUse24HourFormat(any(Boolean.class))).thenReturn(fakeMessageBuilder);
1456 when(fakeSettingsChannel.startMessage()).thenReturn(fakeMessageBuilder);
1460 when(
engine.getAccessibilityChannel()).thenReturn(mock(AccessibilityChannel.class));
1461 when(
engine.getActivityControlSurface()).thenReturn(mock(ActivityControlSurface.class));
1462 when(
engine.getDartExecutor()).thenReturn(mock(DartExecutor.class));
1463 when(
engine.getLifecycleChannel()).thenReturn(mock(LifecycleChannel.class));
1464 when(
engine.getLocalizationChannel()).thenReturn(mock(LocalizationChannel.class));
1465 when(
engine.getLocalizationPlugin()).thenReturn(mock(LocalizationPlugin.class));
1466 when(
engine.getMouseCursorChannel()).thenReturn(mock(MouseCursorChannel.class));
1467 when(
engine.getNavigationChannel()).thenReturn(mock(NavigationChannel.class));
1468 when(
engine.getBackGestureChannel()).thenReturn(mock(BackGestureChannel.class));
1469 when(
engine.getPlatformViewsController()).thenReturn(mock(PlatformViewsController.class));
1472 when(
engine.getRenderer()).thenReturn(renderer);
1474 when(
engine.getSettingsChannel()).thenReturn(fakeSettingsChannel);
1475 when(
engine.getSystemChannel()).thenReturn(mock(SystemChannel.class));
1476 when(
engine.getTextInputChannel()).thenReturn(mock(TextInputChannel.class));
static SkISize times(const SkISize &size, float factor)
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
void add(sk_sp< SkIDChangeListener > listener) SK_EXCLUDES(fMutex)
Builder setFlutterLoader(@NonNull FlutterLoader flutterLoader)
static void setInstance(@NonNull FlutterInjector injector)
void itSendsInitialRouteToFlutter()
void itAttachesFlutterToTheActivityIfDesired()
void itDestroysItsOwnEngineIfHostRequestsIt()
void itGivesHostAnOpportunityToConfigureFlutterEngine()
void itDoesNotAttachFlutterToTheActivityIfNotDesired()
void itUsesNewEngineInGroupWhenProvided()
void itExecutesDartEntrypointProvidedByHost()
void itDefersToTheHostToProvideFlutterEngine()
void itSendsInitialRouteFromIntentOnStartIfNoInitialRouteFromActivityAndShouldHandleDeeplinkingWithQueryParameterAndFragment()
void itDoesSendPushRouteInformationMessageWhenOnNewIntentIsNonHierarchicalUri()
void itSendsPushRouteInformationMessageWhenOnNewIntent()
void itSendsLifecycleEventsToFlutter()
void itDoesNotDelayFirstDrawWhenNotRequested()
void itUsesDefaultFlutterLoaderAppBundlePathWhenUnspecified()
void itSendsPushRouteInformationMessageWhenOnNewIntentWithQueryParameterAndFragment()
void itSendsPushRouteInformationMessageWhenOnNewIntentWithFragmentNoQueryParameter()
void itDoesNotDestroyItsOwnEngineWhenHostSaysNotTo()
void itForwardsOnNewIntentToFlutterEngine()
void itDoesAttachFlutterViewToEngine()
void itSendsInitialRouteFromIntentOnStartIfNoInitialRouteFromActivityAndShouldHandleDeeplinking()
void usesFlutterEngineGroup()
void itDoesNotAttachFlutterViewToEngine()
void itDelaysFirstDrawWhenRequested()
void itChangesFlutterViewVisibilityWhenOnStartAndOnStop()
void itExecutesDartLibraryUriProvidedByHost()
void itForwardsCancelBackGestureToFlutter()
void itSendsInitialRouteFromIntentOnStartIfNoInitialRouteFromActivityAndShouldHandleDeeplinkingNoQueryParameter()
void itSendsPopRouteMessageToFlutterWhenHardwareBackButtonIsPressed()
void itSendsInitialRouteFromIntentOnStartIfNoInitialRouteFromActivityAndShouldHandleDeeplinkingWithFragmentNoQueryParameter()
void itExecutesDartEntrypointWithArgsProvidedByHost()
void itForwardsCommitBackGestureToFlutter()
void itForwardsUpdateBackGestureProgressToFlutter()
void itGivesHostAnOpportunityToConfigureFlutterTextureView()
void itUsesCachedEngineWhenProvided()
void itSendsPushRouteInformationMessageWhenOnNewIntentNoQueryParameter()
void flutterEngineGroupGetsInitialRouteFromIntent()
void itForwardsOnRequestPermissionsResultToFlutterEngine()
void itDoesNotSendsLifecycleEventsToFlutter()
void itForwardsOnActivityResultToFlutterEngine()
void itForwardsOnUserLeaveHintToFlutterEngine()
void itSendsdefaultInitialRouteOnStartIfNotDeepLinkingFromIntent()
void itDoesNotDestroyCachedEngineWhenHostSaysNotTo()
void flutterSurfaceViewVisibilityChangedWithFlutterView()
void itDestroysCachedEngineWhenHostRequestsIt()
void itThrowsWhenDelayingTheFirstDrawAndUsingATextureView()
void itDoesNotDetachTwice()
void itGivesHostAnOpportunityToCleanUpFlutterEngine()
void itForwardsStartBackGestureToFlutter()
void itGivesHostAnOpportunityToConfigureFlutterSurfaceView()
void itNotifiesDartExecutorAndSendsMessageOverSystemChannelWhenToldToTrimMemory()
View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState, int flutterViewId, boolean shouldDelayFirstAndroidViewDraw)
void onActivityResult(int requestCode, int resultCode, Intent data)
OnPreDrawListener activePreDrawListener
void updateBackGestureProgress(@NonNull BackEvent backEvent)
void onAttach(@NonNull Context context)
void startBackGesture(@NonNull BackEvent backEvent)
void onTrimMemory(int level)
void onWindowFocusChanged(boolean hasFocus)
void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
void onNewIntent(@NonNull Intent intent)
FlutterEngine getFlutterEngine()
static Intent createDefaultIntent(@NonNull Context launchContext)
RenderSurface renderSurface