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

Classes

class  FlutterActivityWithIntentBuilders
 
class  FlutterActivityWithProvidedEngine
 

Public Member Functions

void setUp ()
 
void tearDown ()
 
void flutterViewHasId ()
 
void itRegistersOnBackInvokedCallbackOnChangingFrameworkHandlesBack ()
 
void itUnregistersOnBackInvokedCallbackOnRelease ()
 
void onBackInvokedCallbackIsNullForSdk32OrLower ()
 
void onBackInvokedCallbackCallsOnBackPressedForSdk33 ()
 
void itHandlesOnBackAnimationCallbackAsExpectedForSdk34OrHigher ()
 
void itCreatesDefaultIntentWithExpectedDefaults ()
 
void itDestroysNewEngineWhenIntentIsMissingParameter ()
 
void itDoesNotDestroyFlutterEngineWhenProvidedByHost ()
 
void itCreatesNewEngineIntentWithRequestedSettings ()
 
void itCreatesNewEngineInGroupIntentWithRequestedSettings ()
 
void itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase1 () throws PackageManager.NameNotFoundException
 
void itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase2 () throws PackageManager.NameNotFoundException
 
void itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase3 () throws PackageManager.NameNotFoundException
 
void itCreatesCachedEngineIntentThatDoesNotDestroyTheEngine ()
 
void itCreatesCachedEngineIntentThatDestroysTheEngine ()
 
void itRegistersPluginsAtConfigurationTime ()
 
void itCanBeDetachedFromTheEngineAndStopSendingFurtherEvents ()
 
void itReturnsExclusiveAppComponent ()
 
void itDelaysDrawing ()
 
void itDoesNotDelayDrawingwhenUsingTextureRendering ()
 
void itRestoresPluginStateBeforePluginOnCreate ()
 
void itDoesNotRegisterPluginsTwiceWhenUsingACachedEngine ()
 
void itDoesNotReleaseEnginewhenDetachFromFlutterEngine ()
 
void itReleaseEngineWhenOnDestroy ()
 
void fullyDrawn_beforeAndroidQ ()
 
void fullyDrawn_fromAndroidQ ()
 

Package Attributes

boolean isDelegateAttached
 

Detailed Description

Definition at line 59 of file FlutterActivityTest.java.

Member Function Documentation

◆ flutterViewHasId()

void io.flutter.embedding.android.FlutterActivityTest.flutterViewHasId ( )
inline

Definition at line 82 of file FlutterActivityTest.java.

82 {
83 Intent intent = FlutterActivity.createDefaultIntent(ctx);
84 ActivityController<FlutterActivity> activityController =
85 Robolectric.buildActivity(FlutterActivity.class, intent);
86 FlutterActivity activity = activityController.get();
87
88 activity.onCreate(null);
89 assertNotNull(activity.findViewById(FlutterActivity.FLUTTER_VIEW_ID));
90 assertTrue(activity.findViewById(FlutterActivity.FLUTTER_VIEW_ID) instanceof FlutterView);
91 }

◆ fullyDrawn_beforeAndroidQ()

void io.flutter.embedding.android.FlutterActivityTest.fullyDrawn_beforeAndroidQ ( )
inline

Definition at line 558 of file FlutterActivityTest.java.

558 {
559 Intent intent = FlutterActivityWithReportFullyDrawn.createDefaultIntent(ctx);
560 ActivityController<FlutterActivityWithReportFullyDrawn> activityController =
561 Robolectric.buildActivity(FlutterActivityWithReportFullyDrawn.class, intent);
562 FlutterActivityWithReportFullyDrawn flutterActivity = activityController.get();
563
564 // See https://github.com/flutter/flutter/issues/46172, and
565 // https://github.com/flutter/flutter/issues/88767.
566 flutterActivity.onFlutterUiDisplayed();
567 assertFalse("reportFullyDrawn isn't used", flutterActivity.isFullyDrawn());
568 }

◆ fullyDrawn_fromAndroidQ()

void io.flutter.embedding.android.FlutterActivityTest.fullyDrawn_fromAndroidQ ( )
inline

Definition at line 572 of file FlutterActivityTest.java.

572 {
573 Intent intent = FlutterActivityWithReportFullyDrawn.createDefaultIntent(ctx);
574 ActivityController<FlutterActivityWithReportFullyDrawn> activityController =
575 Robolectric.buildActivity(FlutterActivityWithReportFullyDrawn.class, intent);
576 FlutterActivityWithReportFullyDrawn flutterActivity = activityController.get();
577
578 flutterActivity.onFlutterUiDisplayed();
579 assertTrue("reportFullyDrawn is used", flutterActivity.isFullyDrawn());
580 flutterActivity.resetFullyDrawn();
581 }

◆ itCanBeDetachedFromTheEngineAndStopSendingFurtherEvents()

void io.flutter.embedding.android.FlutterActivityTest.itCanBeDetachedFromTheEngineAndStopSendingFurtherEvents ( )
inline

Definition at line 388 of file FlutterActivityTest.java.

388 {
389 FlutterActivityAndFragmentDelegate mockDelegate =
390 mock(FlutterActivityAndFragmentDelegate.class);
391 FlutterEngine mockEngine = mock(FlutterEngine.class);
392 FlutterEngineCache.getInstance().put("my_cached_engine", mockEngine);
393
394 Intent intent = FlutterActivity.withCachedEngine("my_cached_engine").build(ctx);
395 ActivityController<FlutterActivity> activityController =
396 Robolectric.buildActivity(FlutterActivity.class, intent);
397 FlutterActivity flutterActivity = activityController.get();
398
399 isDelegateAttached = true;
400 when(mockDelegate.isAttached()).thenAnswer(invocation -> isDelegateAttached);
401 doAnswer(invocation -> isDelegateAttached = false).when(mockDelegate).onDetach();
402
403 flutterActivity.setDelegate(mockDelegate);
404 flutterActivity.onStart();
405 flutterActivity.onResume();
406
407 verify(mockDelegate, times(1)).onStart();
408 verify(mockDelegate, times(1)).onResume();
409
410 flutterActivity.onPause();
411 flutterActivity.detachFromFlutterEngine();
412 verify(mockDelegate, times(1)).onPause();
413 verify(mockDelegate, times(1)).onDestroyView();
414 verify(mockDelegate, times(1)).onDetach();
415
416 flutterActivity.onStop();
417 verify(mockDelegate, never()).onStop();
418
419 // Simulate the disconnected activity resuming again.
420 flutterActivity.onStart();
421 flutterActivity.onResume();
422 // Shouldn't send more events to the delegates as before and shouldn't crash.
423 verify(mockDelegate, times(1)).onStart();
424 verify(mockDelegate, times(1)).onResume();
425
426 flutterActivity.onDestroy();
427 // 1 time same as before.
428 verify(mockDelegate, times(1)).onDestroyView();
429 verify(mockDelegate, times(1)).onDetach();
430 verify(mockDelegate, times(1)).release();
431 }
static SkISize times(const SkISize &size, float factor)

◆ itCreatesCachedEngineIntentThatDestroysTheEngine()

void io.flutter.embedding.android.FlutterActivityTest.itCreatesCachedEngineIntentThatDestroysTheEngine ( )
inline

Definition at line 356 of file FlutterActivityTest.java.

356 {
357 Intent intent =
358 FlutterActivity.withCachedEngine("my_cached_engine")
359 .destroyEngineWithActivity(true)
360 .build(ctx);
361 ActivityController<FlutterActivity> activityController =
362 Robolectric.buildActivity(FlutterActivity.class, intent);
363 FlutterActivity flutterActivity = activityController.get();
364
365 assertArrayEquals(new String[] {}, flutterActivity.getFlutterShellArgs().toArray());
366 assertTrue(flutterActivity.shouldAttachEngineToActivity());
367 assertEquals("my_cached_engine", flutterActivity.getCachedEngineId());
368 assertTrue(flutterActivity.shouldDestroyEngineWithHost());
369 }

◆ itCreatesCachedEngineIntentThatDoesNotDestroyTheEngine()

void io.flutter.embedding.android.FlutterActivityTest.itCreatesCachedEngineIntentThatDoesNotDestroyTheEngine ( )
inline

Definition at line 340 of file FlutterActivityTest.java.

340 {
341 Intent intent =
342 FlutterActivity.withCachedEngine("my_cached_engine")
343 .destroyEngineWithActivity(false)
344 .build(ctx);
345 ActivityController<FlutterActivity> activityController =
346 Robolectric.buildActivity(FlutterActivity.class, intent);
347 FlutterActivity flutterActivity = activityController.get();
348
349 assertArrayEquals(new String[] {}, flutterActivity.getFlutterShellArgs().toArray());
350 assertTrue(flutterActivity.shouldAttachEngineToActivity());
351 assertEquals("my_cached_engine", flutterActivity.getCachedEngineId());
352 assertFalse(flutterActivity.shouldDestroyEngineWithHost());
353 }

◆ itCreatesDefaultIntentWithExpectedDefaults()

void io.flutter.embedding.android.FlutterActivityTest.itCreatesDefaultIntentWithExpectedDefaults ( )
inline

Definition at line 195 of file FlutterActivityTest.java.

195 {
196 Intent intent = FlutterActivity.createDefaultIntent(ctx);
197 ActivityController<FlutterActivity> activityController =
198 Robolectric.buildActivity(FlutterActivity.class, intent);
199 FlutterActivity flutterActivity = activityController.get();
200 flutterActivity.setDelegate(new FlutterActivityAndFragmentDelegate(flutterActivity));
201
202 assertEquals("main", flutterActivity.getDartEntrypointFunctionName());
203 assertNull(flutterActivity.getDartEntrypointLibraryUri());
204 assertNull(flutterActivity.getDartEntrypointArgs());
205 assertEquals("/", flutterActivity.getInitialRoute());
206 assertArrayEquals(new String[] {}, flutterActivity.getFlutterShellArgs().toArray());
207 assertTrue(flutterActivity.shouldAttachEngineToActivity());
208 assertNull(flutterActivity.getCachedEngineId());
209 assertTrue(flutterActivity.shouldDestroyEngineWithHost());
210 assertEquals(BackgroundMode.opaque, flutterActivity.getBackgroundMode());
211 assertEquals(RenderMode.surface, flutterActivity.getRenderMode());
212 assertEquals(TransparencyMode.opaque, flutterActivity.getTransparencyMode());
213 }

◆ itCreatesNewEngineInGroupIntentWithRequestedSettings()

void io.flutter.embedding.android.FlutterActivityTest.itCreatesNewEngineInGroupIntentWithRequestedSettings ( )
inline

Definition at line 269 of file FlutterActivityTest.java.

269 {
270 Intent intent =
271 FlutterActivity.withNewEngineInGroup("my_cached_engine_group")
272 .dartEntrypoint("custom_entrypoint")
273 .initialRoute("/custom/route")
274 .backgroundMode(BackgroundMode.transparent)
275 .build(ctx);
276 ActivityController<FlutterActivity> activityController =
277 Robolectric.buildActivity(FlutterActivity.class, intent);
278 FlutterActivity flutterActivity = activityController.get();
279 flutterActivity.setDelegate(new FlutterActivityAndFragmentDelegate(flutterActivity));
280
281 assertEquals("my_cached_engine_group", flutterActivity.getCachedEngineGroupId());
282 assertEquals("custom_entrypoint", flutterActivity.getDartEntrypointFunctionName());
283 assertEquals("/custom/route", flutterActivity.getInitialRoute());
284 assertArrayEquals(new String[] {}, flutterActivity.getFlutterShellArgs().toArray());
285 assertTrue(flutterActivity.shouldAttachEngineToActivity());
286 assertTrue(flutterActivity.shouldDestroyEngineWithHost());
287 assertNull(flutterActivity.getCachedEngineId());
288 assertEquals(BackgroundMode.transparent, flutterActivity.getBackgroundMode());
289 assertEquals(RenderMode.texture, flutterActivity.getRenderMode());
290 assertEquals(TransparencyMode.transparent, flutterActivity.getTransparencyMode());
291 }

◆ itCreatesNewEngineIntentWithRequestedSettings()

void io.flutter.embedding.android.FlutterActivityTest.itCreatesNewEngineIntentWithRequestedSettings ( )
inline

Definition at line 244 of file FlutterActivityTest.java.

244 {
245 Intent intent =
246 FlutterActivity.withNewEngine()
247 .initialRoute("/custom/route")
248 .dartEntrypointArgs(new ArrayList<String>(Arrays.asList("foo", "bar")))
249 .backgroundMode(BackgroundMode.transparent)
250 .build(ctx);
251 ActivityController<FlutterActivity> activityController =
252 Robolectric.buildActivity(FlutterActivity.class, intent);
253 FlutterActivity flutterActivity = activityController.get();
254 flutterActivity.setDelegate(new FlutterActivityAndFragmentDelegate(flutterActivity));
255
256 assertEquals("/custom/route", flutterActivity.getInitialRoute());
257 assertArrayEquals(
258 new String[] {"foo", "bar"}, flutterActivity.getDartEntrypointArgs().toArray());
259 assertArrayEquals(new String[] {}, flutterActivity.getFlutterShellArgs().toArray());
260 assertTrue(flutterActivity.shouldAttachEngineToActivity());
261 assertNull(flutterActivity.getCachedEngineId());
262 assertTrue(flutterActivity.shouldDestroyEngineWithHost());
263 assertEquals(BackgroundMode.transparent, flutterActivity.getBackgroundMode());
264 assertEquals(RenderMode.texture, flutterActivity.getRenderMode());
265 assertEquals(TransparencyMode.transparent, flutterActivity.getTransparencyMode());
266 }

◆ itDelaysDrawing()

void io.flutter.embedding.android.FlutterActivityTest.itDelaysDrawing ( )
inline

Definition at line 447 of file FlutterActivityTest.java.

447 {
448 Intent intent = FlutterActivity.createDefaultIntent(ctx);
449 ActivityController<FlutterActivity> activityController =
450 Robolectric.buildActivity(FlutterActivity.class, intent);
451 FlutterActivity flutterActivity = activityController.get();
452
453 flutterActivity.onCreate(null);
454
455 assertNotNull(flutterActivity.delegate.activePreDrawListener);
456 }

◆ itDestroysNewEngineWhenIntentIsMissingParameter()

void io.flutter.embedding.android.FlutterActivityTest.itDestroysNewEngineWhenIntentIsMissingParameter ( )
inline

Definition at line 216 of file FlutterActivityTest.java.

216 {
217 // All clients should use the static members of FlutterActivity to construct an
218 // Intent. Missing extras is an error. However, Flutter has number of tests that
219 // don't seem to use the static members of FlutterActivity to construct the
220 // launching Intent, so this test explicitly verifies that even illegal Intents
221 // result in the automatic destruction of a non-cached FlutterEngine, which prevents
222 // the breakage of memory usage benchmark tests.
223 Intent intent = new Intent(ctx, FlutterActivity.class);
224 ActivityController<FlutterActivity> activityController =
225 Robolectric.buildActivity(FlutterActivity.class, intent);
226 FlutterActivity flutterActivity = activityController.get();
227 flutterActivity.setDelegate(new FlutterActivityAndFragmentDelegate(flutterActivity));
228
229 assertTrue(flutterActivity.shouldDestroyEngineWithHost());
230 }

◆ itDoesNotDelayDrawingwhenUsingTextureRendering()

void io.flutter.embedding.android.FlutterActivityTest.itDoesNotDelayDrawingwhenUsingTextureRendering ( )
inline

Definition at line 459 of file FlutterActivityTest.java.

459 {
460 Intent intent = FlutterActivityWithTextureRendering.createDefaultIntent(ctx);
461 ActivityController<FlutterActivityWithTextureRendering> activityController =
462 Robolectric.buildActivity(FlutterActivityWithTextureRendering.class, intent);
463 FlutterActivityWithTextureRendering flutterActivity = activityController.get();
464
465 flutterActivity.onCreate(null);
466
467 assertNull(flutterActivity.delegate.activePreDrawListener);
468 }

◆ itDoesNotDestroyFlutterEngineWhenProvidedByHost()

void io.flutter.embedding.android.FlutterActivityTest.itDoesNotDestroyFlutterEngineWhenProvidedByHost ( )
inline

Definition at line 233 of file FlutterActivityTest.java.

233 {
234 Intent intent = new Intent(ctx, FlutterActivityWithProvidedEngine.class);
235 ActivityController<FlutterActivityWithProvidedEngine> activityController =
236 Robolectric.buildActivity(FlutterActivityWithProvidedEngine.class, intent);
237 activityController.create();
238 FlutterActivityWithProvidedEngine flutterActivity = activityController.get();
239
240 assertFalse(flutterActivity.shouldDestroyEngineWithHost());
241 }

◆ itDoesNotRegisterPluginsTwiceWhenUsingACachedEngine()

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

Definition at line 487 of file FlutterActivityTest.java.

487 {
488 Intent intent = new Intent(ctx, FlutterActivityWithProvidedEngine.class);
489 ActivityController<FlutterActivityWithProvidedEngine> activityController =
490 Robolectric.buildActivity(FlutterActivityWithProvidedEngine.class, intent);
491 activityController.create();
492 FlutterActivityWithProvidedEngine flutterActivity = activityController.get();
493 flutterActivity.configureFlutterEngine(flutterActivity.getFlutterEngine());
494
495 List<FlutterEngine> registeredEngines = GeneratedPluginRegistrant.getRegisteredEngines();
496 // This might cause the plugins to be registered twice, once by the FlutterEngine constructor,
497 // and once by the default FlutterActivity.configureFlutterEngine implementation.
498 // Test that it doesn't happen.
499 assertEquals(1, registeredEngines.size());
500 }

◆ itDoesNotReleaseEnginewhenDetachFromFlutterEngine()

void io.flutter.embedding.android.FlutterActivityTest.itDoesNotReleaseEnginewhenDetachFromFlutterEngine ( )
inline

Definition at line 503 of file FlutterActivityTest.java.

503 {
504 FlutterActivityAndFragmentDelegate mockDelegate =
505 mock(FlutterActivityAndFragmentDelegate.class);
506 isDelegateAttached = true;
507 when(mockDelegate.isAttached()).thenAnswer(invocation -> isDelegateAttached);
508 doAnswer(invocation -> isDelegateAttached = false).when(mockDelegate).onDetach();
509 FlutterEngine mockEngine = mock(FlutterEngine.class);
510 FlutterEngineCache.getInstance().put("my_cached_engine", mockEngine);
511
512 Intent intent = FlutterActivity.withCachedEngine("my_cached_engine").build(ctx);
513 ActivityController<FlutterActivity> activityController =
514 Robolectric.buildActivity(FlutterActivity.class, intent);
515 FlutterActivity flutterActivity = activityController.get();
516
517 flutterActivity.setDelegate(mockDelegate);
518 flutterActivity.onStart();
519 flutterActivity.onResume();
520 flutterActivity.onPause();
521
522 assertTrue(mockDelegate.isAttached());
523 flutterActivity.detachFromFlutterEngine();
524 verify(mockDelegate, times(1)).onDetach();
525 verify(mockDelegate, never()).release();
526 assertFalse(mockDelegate.isAttached());
527 }

◆ itHandlesOnBackAnimationCallbackAsExpectedForSdk34OrHigher()

void io.flutter.embedding.android.FlutterActivityTest.itHandlesOnBackAnimationCallbackAsExpectedForSdk34OrHigher ( )
inline

Definition at line 161 of file FlutterActivityTest.java.

161 {
162 Intent intent = FlutterActivityWithMockBackInvokedHandling.createDefaultIntent(ctx);
163 ActivityController<FlutterActivityWithMockBackInvokedHandling> activityController =
164 Robolectric.buildActivity(FlutterActivityWithMockBackInvokedHandling.class, intent);
165 FlutterActivityWithMockBackInvokedHandling activity = activityController.get();
166
167 assertTrue(
168 "onBackInvokedCallback should be an instance of OnBackAnimationCallback for SDK 34 or higher",
169 activity.getOnBackInvokedCallback() instanceof OnBackAnimationCallback);
170
171 OnBackAnimationCallback callback =
172 (OnBackAnimationCallback) activity.getOnBackInvokedCallback();
173
174 BackEvent mockBackEvent = mock(BackEvent.class);
175 callback.onBackStarted(mockBackEvent);
176 assertEquals(
177 "Expected startBackGesture to be called 1 times", 1, activity.startBackGestureCounter);
178
179 callback.onBackProgressed(mockBackEvent);
180 assertEquals(
181 "Expected updateBackGestureProgress to be called 1 times",
182 1,
183 activity.updateBackGestureProgressCounter);
184
185 callback.onBackInvoked();
186 assertEquals(
187 "Expected commitBackGesture to be called 1 times", 1, activity.commitBackGestureCounter);
188
189 callback.onBackCancelled();
190 assertEquals(
191 "Expected cancelBackGesture to be called 1 times", 1, activity.cancelBackGestureCounter);
192 }
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ itRegistersOnBackInvokedCallbackOnChangingFrameworkHandlesBack()

void io.flutter.embedding.android.FlutterActivityTest.itRegistersOnBackInvokedCallbackOnChangingFrameworkHandlesBack ( )
inline

Definition at line 97 of file FlutterActivityTest.java.

97 {
98 Intent intent = FlutterActivityWithReportFullyDrawn.createDefaultIntent(ctx);
99 ActivityController<FlutterActivityWithReportFullyDrawn> activityController =
100 Robolectric.buildActivity(FlutterActivityWithReportFullyDrawn.class, intent);
101 FlutterActivityWithReportFullyDrawn activity = spy(activityController.get());
102
103 activity.onCreate(null);
104
105 verify(activity, times(0)).registerOnBackInvokedCallback();
106
107 activity.setFrameworkHandlesBack(false);
108 verify(activity, times(0)).registerOnBackInvokedCallback();
109
110 activity.setFrameworkHandlesBack(true);
111 verify(activity, times(1)).registerOnBackInvokedCallback();
112 }

◆ itRegistersPluginsAtConfigurationTime()

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

Definition at line 372 of file FlutterActivityTest.java.

372 {
373 Intent intent = FlutterActivity.createDefaultIntent(ctx);
374 ActivityController<FlutterActivity> activityController =
375 Robolectric.buildActivity(FlutterActivity.class, intent);
376 FlutterActivity activity = activityController.get();
377
378 // This calls onAttach on FlutterActivityAndFragmentDelegate and subsequently
379 // configureFlutterEngine which registers the plugins.
380 activity.onCreate(null);
381
382 List<FlutterEngine> registeredEngines = GeneratedPluginRegistrant.getRegisteredEngines();
383 assertEquals(1, registeredEngines.size());
384 assertEquals(activity.getFlutterEngine(), registeredEngines.get(0));
385 }

◆ itReleaseEngineWhenOnDestroy()

void io.flutter.embedding.android.FlutterActivityTest.itReleaseEngineWhenOnDestroy ( )
inline

Definition at line 530 of file FlutterActivityTest.java.

530 {
531 FlutterActivityAndFragmentDelegate mockDelegate =
532 mock(FlutterActivityAndFragmentDelegate.class);
533 isDelegateAttached = true;
534 when(mockDelegate.isAttached()).thenAnswer(invocation -> isDelegateAttached);
535 doAnswer(invocation -> isDelegateAttached = false).when(mockDelegate).onDetach();
536 FlutterEngine mockEngine = mock(FlutterEngine.class);
537 FlutterEngineCache.getInstance().put("my_cached_engine", mockEngine);
538
539 Intent intent = FlutterActivity.withCachedEngine("my_cached_engine").build(ctx);
540 ActivityController<FlutterActivity> activityController =
541 Robolectric.buildActivity(FlutterActivity.class, intent);
542 FlutterActivity flutterActivity = activityController.get();
543
544 flutterActivity.setDelegate(mockDelegate);
545 flutterActivity.onStart();
546 flutterActivity.onResume();
547 flutterActivity.onPause();
548
549 assertTrue(mockDelegate.isAttached());
550 flutterActivity.onDestroy();
551 verify(mockDelegate, times(1)).onDetach();
552 verify(mockDelegate, times(1)).release();
553 assertFalse(mockDelegate.isAttached());
554 }

◆ itRestoresPluginStateBeforePluginOnCreate()

void io.flutter.embedding.android.FlutterActivityTest.itRestoresPluginStateBeforePluginOnCreate ( )
inline

Definition at line 471 of file FlutterActivityTest.java.

471 {
472 FlutterLoader mockFlutterLoader = mock(FlutterLoader.class);
473 FlutterJNI mockFlutterJni = mock(FlutterJNI.class);
474 when(mockFlutterJni.isAttached()).thenReturn(true);
475 FlutterEngine cachedEngine = new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni);
476 FakeFlutterPlugin fakeFlutterPlugin = new FakeFlutterPlugin();
477 cachedEngine.getPlugins().add(fakeFlutterPlugin);
478 FlutterEngineCache.getInstance().put("my_cached_engine", cachedEngine);
479
480 Intent intent = FlutterActivity.withCachedEngine("my_cached_engine").build(ctx);
481 Robolectric.buildActivity(FlutterActivity.class, intent).setup();
482 assertTrue(
483 "Expected FakeFlutterPlugin onCreateCalled to be true", fakeFlutterPlugin.onCreateCalled);
484 }

◆ itReturnsExclusiveAppComponent()

void io.flutter.embedding.android.FlutterActivityTest.itReturnsExclusiveAppComponent ( )
inline

Definition at line 434 of file FlutterActivityTest.java.

434 {
435 Intent intent = FlutterActivity.createDefaultIntent(ctx);
436 ActivityController<FlutterActivity> activityController =
437 Robolectric.buildActivity(FlutterActivity.class, intent);
438 FlutterActivity flutterActivity = activityController.get();
439 FlutterActivityAndFragmentDelegate delegate =
440 new FlutterActivityAndFragmentDelegate(flutterActivity);
441 flutterActivity.setDelegate(delegate);
442
443 assertEquals(flutterActivity.getExclusiveAppComponent(), delegate);
444 }

◆ itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase1()

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

Definition at line 294 of file FlutterActivityTest.java.

295 {
296 Intent intent =
297 FlutterActivity.withNewEngine().backgroundMode(BackgroundMode.transparent).build(ctx);
298 ActivityController<FlutterActivity> activityController =
299 Robolectric.buildActivity(FlutterActivity.class, intent);
300 FlutterActivity flutterActivity = activityController.get();
301 Bundle bundle = new Bundle();
302 bundle.putBoolean(HANDLE_DEEPLINKING_META_DATA_KEY, true);
303 FlutterActivity spyFlutterActivity = spy(flutterActivity);
304 when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
305 assertTrue(spyFlutterActivity.shouldHandleDeeplinking());
306 }

◆ itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase2()

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

Definition at line 309 of file FlutterActivityTest.java.

310 {
311 Intent intent =
312 FlutterActivity.withNewEngine().backgroundMode(BackgroundMode.transparent).build(ctx);
313 ActivityController<FlutterActivity> activityController =
314 Robolectric.buildActivity(FlutterActivity.class, intent);
315 FlutterActivity flutterActivity = activityController.get();
316 Bundle bundle = new Bundle();
317 bundle.putBoolean(HANDLE_DEEPLINKING_META_DATA_KEY, false);
318 FlutterActivity spyFlutterActivity = spy(flutterActivity);
319 when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
320 assertFalse(spyFlutterActivity.shouldHandleDeeplinking());
321 }

◆ itReturnsValueFromMetaDataWhenCallsShouldHandleDeepLinkingCase3()

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

Definition at line 324 of file FlutterActivityTest.java.

325 {
326 Intent intent =
327 FlutterActivity.withNewEngine().backgroundMode(BackgroundMode.transparent).build(ctx);
328 ActivityController<FlutterActivity> activityController =
329 Robolectric.buildActivity(FlutterActivity.class, intent);
330 FlutterActivity flutterActivity = activityController.get();
331 // Creates an empty bundle.
332 Bundle bundle = new Bundle();
333 FlutterActivity spyFlutterActivity = spy(flutterActivity);
334 when(spyFlutterActivity.getMetaData()).thenReturn(bundle);
335 // Empty bundle should return false.
336 assertFalse(spyFlutterActivity.shouldHandleDeeplinking());
337 }

◆ itUnregistersOnBackInvokedCallbackOnRelease()

void io.flutter.embedding.android.FlutterActivityTest.itUnregistersOnBackInvokedCallbackOnRelease ( )
inline

Definition at line 118 of file FlutterActivityTest.java.

118 {
119 Intent intent = FlutterActivityWithReportFullyDrawn.createDefaultIntent(ctx);
120 ActivityController<FlutterActivityWithReportFullyDrawn> activityController =
121 Robolectric.buildActivity(FlutterActivityWithReportFullyDrawn.class, intent);
122 FlutterActivityWithReportFullyDrawn activity = spy(activityController.get());
123
124 activity.release();
125
126 verify(activity, times(1)).unregisterOnBackInvokedCallback();
127 }

◆ onBackInvokedCallbackCallsOnBackPressedForSdk33()

void io.flutter.embedding.android.FlutterActivityTest.onBackInvokedCallbackCallsOnBackPressedForSdk33 ( )
inline

Definition at line 145 of file FlutterActivityTest.java.

145 {
146 Intent intent = FlutterActivityWithMockBackInvokedHandling.createDefaultIntent(ctx);
147 ActivityController<FlutterActivityWithMockBackInvokedHandling> activityController =
148 Robolectric.buildActivity(FlutterActivityWithMockBackInvokedHandling.class, intent);
149 FlutterActivityWithMockBackInvokedHandling activity = activityController.get();
150
151 OnBackInvokedCallback callback = activity.getOnBackInvokedCallback();
152 assertNotNull("onBackInvokedCallback should not be null for SDK 33", callback);
153
154 callback.onBackInvoked();
155 assertEquals("Expected onBackPressed to be called 1 times", 1, activity.onBackPressedCounter);
156 }

◆ onBackInvokedCallbackIsNullForSdk32OrLower()

void io.flutter.embedding.android.FlutterActivityTest.onBackInvokedCallbackIsNullForSdk32OrLower ( )
inline

Definition at line 131 of file FlutterActivityTest.java.

131 {
132 Intent intent = FlutterActivity.createDefaultIntent(ctx);
133 ActivityController<FlutterActivity> activityController =
134 Robolectric.buildActivity(FlutterActivity.class, intent);
135 FlutterActivity flutterActivity = activityController.get();
136
137 assertNull(
138 "onBackInvokedCallback should be null for SDK 32 or lower",
139 flutterActivity.getOnBackInvokedCallback());
140 }

◆ setUp()

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

Definition at line 64 of file FlutterActivityTest.java.

64 {
65 FlutterInjector.reset();
66 GeneratedPluginRegistrant.clearRegisteredEngines();
67 FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);
68 when(mockFlutterJNI.isAttached()).thenReturn(true);
69 FlutterJNI.Factory mockFlutterJNIFactory = mock(FlutterJNI.Factory.class);
70 when(mockFlutterJNIFactory.provideFlutterJNI()).thenReturn(mockFlutterJNI);
71 FlutterInjector.setInstance(
72 new FlutterInjector.Builder().setFlutterJNIFactory(mockFlutterJNIFactory).build());
73 }

◆ tearDown()

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

Definition at line 76 of file FlutterActivityTest.java.

76 {
77 GeneratedPluginRegistrant.clearRegisteredEngines();
78 FlutterInjector.reset();
79 }

Member Data Documentation

◆ isDelegateAttached

boolean io.flutter.embedding.android.FlutterActivityTest.isDelegateAttached
package

Definition at line 61 of file FlutterActivityTest.java.


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