Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
io.flutter.embedding.android.FlutterFragmentActivityTest Class Reference

Classes

class  FlutterFragmentActivityWithProvidedEngine
 

Public Member Functions

void setUp ()
 
void tearDown ()
 
void createFlutterFragment_defaultRenderModeSurface ()
 
void createFlutterFragment_defaultRenderModeTexture ()
 
void createFlutterFragment_customRenderMode ()
 
void createFlutterFragment_customDartEntrypointLibraryUri ()
 
void hasRootLayoutId ()
 
void itRegistersPluginsAtConfigurationTime ()
 
void itDoesNotRegisterPluginsTwiceWhenUsingACachedEngine ()
 
void itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase1 () throws PackageManager.NameNotFoundException
 
void itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase2 () throws PackageManager.NameNotFoundException
 
void itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase3 () throws PackageManager.NameNotFoundException
 
void itAllowsRootLayoutOverride ()
 
void itCreatesAValidFlutterFragment ()
 
void itRetrievesExistingFlutterFragmentWhenRecreated ()
 
void itHandlesNewFragmentRecreationDuringRestoreWhenActivityIsRecreated ()
 

Detailed Description

Definition at line 40 of file FlutterFragmentActivityTest.java.

Member Function Documentation

◆ createFlutterFragment_customDartEntrypointLibraryUri()

void io.flutter.embedding.android.FlutterFragmentActivityTest.createFlutterFragment_customDartEntrypointLibraryUri ( )
inline

Definition at line 92 of file FlutterFragmentActivityTest.java.

92 {
93 final FlutterFragmentActivity activity =
94 new FakeFlutterFragmentActivity() {
95 @Override
96 public String getDartEntrypointLibraryUri() {
97 return "package:foo/bar.dart";
98 }
99 };
100 assertEquals(
101 activity.createFlutterFragment().getDartEntrypointLibraryUri(), "package:foo/bar.dart");
102 }

◆ createFlutterFragment_customRenderMode()

void io.flutter.embedding.android.FlutterFragmentActivityTest.createFlutterFragment_customRenderMode ( )
inline

Definition at line 80 of file FlutterFragmentActivityTest.java.

80 {
81 final FlutterFragmentActivity activity =
82 new FakeFlutterFragmentActivity() {
83 @Override
84 protected RenderMode getRenderMode() {
85 return RenderMode.texture;
86 }
87 };
88 assertEquals(activity.createFlutterFragment().getRenderMode(), RenderMode.texture);
89 }

◆ createFlutterFragment_defaultRenderModeSurface()

void io.flutter.embedding.android.FlutterFragmentActivityTest.createFlutterFragment_defaultRenderModeSurface ( )
inline

Definition at line 62 of file FlutterFragmentActivityTest.java.

62 {
63 final FlutterFragmentActivity activity = new FakeFlutterFragmentActivity();
64 assertEquals(activity.createFlutterFragment().getRenderMode(), RenderMode.surface);
65 }

◆ createFlutterFragment_defaultRenderModeTexture()

void io.flutter.embedding.android.FlutterFragmentActivityTest.createFlutterFragment_defaultRenderModeTexture ( )
inline

Definition at line 68 of file FlutterFragmentActivityTest.java.

68 {
69 final FlutterFragmentActivity activity =
70 new FakeFlutterFragmentActivity() {
71 @Override
72 protected BackgroundMode getBackgroundMode() {
73 return BackgroundMode.transparent;
74 }
75 };
76 assertEquals(activity.createFlutterFragment().getRenderMode(), RenderMode.texture);
77 }

◆ hasRootLayoutId()

void io.flutter.embedding.android.FlutterFragmentActivityTest.hasRootLayoutId ( )
inline

Definition at line 105 of file FlutterFragmentActivityTest.java.

105 {
106 FlutterFragmentActivityWithRootLayout activity =
107 Robolectric.buildActivity(FlutterFragmentActivityWithRootLayout.class).get();
108 activity.onCreate(null);
109 assertNotNull(activity.FRAGMENT_CONTAINER_ID);
110 assertTrue(activity.FRAGMENT_CONTAINER_ID != View.NO_ID);
111 }

◆ itAllowsRootLayoutOverride()

void io.flutter.embedding.android.FlutterFragmentActivityTest.itAllowsRootLayoutOverride ( )
inline

Definition at line 188 of file FlutterFragmentActivityTest.java.

188 {
189 FlutterFragmentActivityWithRootLayout activity =
190 Robolectric.buildActivity(FlutterFragmentActivityWithRootLayout.class).get();
191
192 activity.onCreate(null);
193 ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
194 boolean foundCustomView = false;
195 for (int i = 0; i < contentView.getChildCount(); i++) {
196 foundCustomView =
197 contentView.getChildAt(i) instanceof FlutterFragmentActivityWithRootLayout.CustomLayout;
198 if (foundCustomView) {
199 break;
200 }
201 }
202 assertTrue(foundCustomView);
203 }

◆ itCreatesAValidFlutterFragment()

void io.flutter.embedding.android.FlutterFragmentActivityTest.itCreatesAValidFlutterFragment ( )
inline

Definition at line 206 of file FlutterFragmentActivityTest.java.

206 {
207 try (ActivityScenario<FlutterFragmentActivityWithProvidedEngine> scenario =
208 ActivityScenario.launch(FlutterFragmentActivityWithProvidedEngine.class)) {
209 scenario.onActivity(
210 activity -> {
211 assertNotNull(activity.getFlutterEngine());
212 assertEquals(1, activity.numberOfEnginesCreated);
213 });
214 }
215 }

◆ itDoesNotRegisterPluginsTwiceWhenUsingACachedEngine()

void io.flutter.embedding.android.FlutterFragmentActivityTest.itDoesNotRegisterPluginsTwiceWhenUsingACachedEngine ( )
inline

Definition at line 128 of file FlutterFragmentActivityTest.java.

128 {
129 try (ActivityScenario<FlutterFragmentActivity> scenario =
130 ActivityScenario.launch(FlutterFragmentActivity.class)) {
131 scenario.onActivity(
132 activity -> {
133 List<FlutterEngine> registeredEngines =
134 GeneratedPluginRegistrant.getRegisteredEngines();
135 assertEquals(1, registeredEngines.size());
136 assertEquals(activity.getFlutterEngine(), registeredEngines.get(0));
137 });
138 }
139
140 List<FlutterEngine> registeredEngines = GeneratedPluginRegistrant.getRegisteredEngines();
141 // This might cause the plugins to be registered twice, once by the FlutterEngine constructor,
142 // and once by the default FlutterFragmentActivity.configureFlutterEngine implementation.
143 // Test that it doesn't happen.
144 assertEquals(1, registeredEngines.size());
145 }

◆ itHandlesNewFragmentRecreationDuringRestoreWhenActivityIsRecreated()

void io.flutter.embedding.android.FlutterFragmentActivityTest.itHandlesNewFragmentRecreationDuringRestoreWhenActivityIsRecreated ( )
inline

Definition at line 234 of file FlutterFragmentActivityTest.java.

234 {
235 FlutterFragmentActivityWithProvidedEngine activity =
236 spy(Robolectric.buildActivity(FlutterFragmentActivityWithProvidedEngine.class).get());
237
238 FlutterFragment fragment = mock(FlutterFragment.class);
239 // Similar to the above case, except here, it's not just the activity that was destroyed and
240 // could have its fragment restored in the fragment manager. Here, both activity and fragment
241 // are destroyed. And the fragment manager recreated the fragment on activity recreate.
242 when(activity.retrieveExistingFlutterFragmentIfPossible()).thenReturn(null, fragment);
243
244 FlutterEngine engine = mock(FlutterEngine.class);
245 when(fragment.getFlutterEngine()).thenReturn(engine);
246
247 activity.onCreate(null);
248 // The framework would have recreated a new fragment but the fragment activity wouldn't have
249 // created a new one again.
250 assertEquals(0, activity.numberOfEnginesCreated);
251 }
FlutterEngine engine
Definition: main.cc:68

◆ itRegistersPluginsAtConfigurationTime()

void io.flutter.embedding.android.FlutterFragmentActivityTest.itRegistersPluginsAtConfigurationTime ( )
inline

Definition at line 114 of file FlutterFragmentActivityTest.java.

114 {
115 try (ActivityScenario<FlutterFragmentActivity> scenario =
116 ActivityScenario.launch(FlutterFragmentActivity.class)) {
117 scenario.onActivity(
118 activity -> {
119 List<FlutterEngine> registeredEngines =
120 GeneratedPluginRegistrant.getRegisteredEngines();
121 assertEquals(1, registeredEngines.size());
122 assertEquals(activity.getFlutterEngine(), registeredEngines.get(0));
123 });
124 }
125 }

◆ itRetrievesExistingFlutterFragmentWhenRecreated()

void io.flutter.embedding.android.FlutterFragmentActivityTest.itRetrievesExistingFlutterFragmentWhenRecreated ( )
inline

Definition at line 218 of file FlutterFragmentActivityTest.java.

218 {
219 FlutterFragmentActivityWithProvidedEngine activity =
220 spy(Robolectric.buildActivity(FlutterFragmentActivityWithProvidedEngine.class).get());
221
222 FlutterFragment fragment = mock(FlutterFragment.class);
223 when(activity.retrieveExistingFlutterFragmentIfPossible()).thenReturn(fragment);
224
225 FlutterEngine engine = mock(FlutterEngine.class);
226 when(fragment.getFlutterEngine()).thenReturn(engine);
227
228 activity.onCreate(null);
229 assertEquals(engine, activity.getFlutterEngine());
230 assertEquals(0, activity.numberOfEnginesCreated);
231 }

◆ itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase1()

void io.flutter.embedding.android.FlutterFragmentActivityTest.itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase1 ( ) throws PackageManager.NameNotFoundException
inline

Definition at line 148 of file FlutterFragmentActivityTest.java.

149 {
150 FlutterFragmentActivity activity =
151 Robolectric.buildActivity(FlutterFragmentActivityWithProvidedEngine.class).get();
152 assertTrue(GeneratedPluginRegistrant.getRegisteredEngines().isEmpty());
153 Bundle bundle = new Bundle();
154 bundle.putBoolean(HANDLE_DEEPLINKING_META_DATA_KEY, true);
155 FlutterFragmentActivity spyFlutterActivity = spy(activity);
156 when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
157 assertTrue(spyFlutterActivity.shouldHandleDeeplinking());
158 }

◆ itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase2()

void io.flutter.embedding.android.FlutterFragmentActivityTest.itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase2 ( ) throws PackageManager.NameNotFoundException
inline

Definition at line 161 of file FlutterFragmentActivityTest.java.

162 {
163 FlutterFragmentActivity activity =
164 Robolectric.buildActivity(FlutterFragmentActivityWithProvidedEngine.class).get();
165 assertTrue(GeneratedPluginRegistrant.getRegisteredEngines().isEmpty());
166 Bundle bundle = new Bundle();
167 bundle.putBoolean(HANDLE_DEEPLINKING_META_DATA_KEY, false);
168 FlutterFragmentActivity spyFlutterActivity = spy(activity);
169 when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
170 assertFalse(spyFlutterActivity.shouldHandleDeeplinking());
171 }

◆ itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase3()

void io.flutter.embedding.android.FlutterFragmentActivityTest.itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase3 ( ) throws PackageManager.NameNotFoundException
inline

Definition at line 174 of file FlutterFragmentActivityTest.java.

175 {
176 FlutterFragmentActivity activity =
177 Robolectric.buildActivity(FlutterFragmentActivityWithProvidedEngine.class).get();
178 assertTrue(GeneratedPluginRegistrant.getRegisteredEngines().isEmpty());
179 // Creates an empty bundle.
180 Bundle bundle = new Bundle();
181 FlutterFragmentActivity spyFlutterActivity = spy(activity);
182 when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
183 // Empty bundle should return false.
184 assertFalse(spyFlutterActivity.shouldHandleDeeplinking());
185 }

◆ setUp()

void io.flutter.embedding.android.FlutterFragmentActivityTest.setUp ( )
inline

Definition at line 44 of file FlutterFragmentActivityTest.java.

44 {
45 FlutterInjector.reset();
46 GeneratedPluginRegistrant.clearRegisteredEngines();
47 FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);
48 when(mockFlutterJNI.isAttached()).thenReturn(true);
49 FlutterJNI.Factory mockFlutterJNIFactory = mock(FlutterJNI.Factory.class);
50 when(mockFlutterJNIFactory.provideFlutterJNI()).thenReturn(mockFlutterJNI);
51 FlutterInjector.setInstance(
52 new FlutterInjector.Builder().setFlutterJNIFactory(mockFlutterJNIFactory).build());
53 }

◆ tearDown()

void io.flutter.embedding.android.FlutterFragmentActivityTest.tearDown ( )
inline

Definition at line 56 of file FlutterFragmentActivityTest.java.

56 {
57 GeneratedPluginRegistrant.clearRegisteredEngines();
58 FlutterInjector.reset();
59 }

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