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

Public Member Functions

void itDoesNotRegisterTheSamePluginTwice ()
 
void activityResultListenerCanBeRemovedFromListener ()
 
void softwareRendering ()
 

Detailed Description

Definition at line 28 of file FlutterEngineConnectionRegistryTest.java.

Member Function Documentation

◆ activityResultListenerCanBeRemovedFromListener()

void io.flutter.embedding.engine.FlutterEngineConnectionRegistryTest.activityResultListenerCanBeRemovedFromListener ( )
inline

Definition at line 68 of file FlutterEngineConnectionRegistryTest.java.

68 {
69 Context context = mock(Context.class);
70
71 FlutterEngine flutterEngine = mock(FlutterEngine.class);
72 PlatformViewsController platformViewsController = mock(PlatformViewsController.class);
73 when(flutterEngine.getPlatformViewsController()).thenReturn(platformViewsController);
74
75 FlutterLoader flutterLoader = mock(FlutterLoader.class);
76
77 ExclusiveAppComponent appComponent = mock(ExclusiveAppComponent.class);
78 Activity activity = mock(Activity.class);
79 when(appComponent.getAppComponent()).thenReturn(activity);
80
81 Intent intent = mock(Intent.class);
82 when(activity.getIntent()).thenReturn(intent);
83
84 Lifecycle lifecycle = mock(Lifecycle.class);
85 AtomicBoolean isFirstCall = new AtomicBoolean(true);
86
87 // Set up the environment to get the required internal data
88 FlutterEngineConnectionRegistry registry =
89 new FlutterEngineConnectionRegistry(context, flutterEngine, flutterLoader, null);
90 FakeActivityAwareFlutterPlugin fakePlugin = new FakeActivityAwareFlutterPlugin();
91 registry.add(fakePlugin);
92 registry.attachToActivity(appComponent, lifecycle);
93
94 // The binding is now available via `fakePlugin.binding`: Create and add the listeners
95 FakeActivityResultListener listener1 =
96 new FakeActivityResultListener(isFirstCall, fakePlugin.binding);
97 FakeActivityResultListener listener2 =
98 new FakeActivityResultListener(isFirstCall, fakePlugin.binding);
99
100 fakePlugin.binding.addActivityResultListener(listener1);
101 fakePlugin.binding.addActivityResultListener(listener2);
102
103 // fire the onActivityResult which should invoke both listeners
104 registry.onActivityResult(0, 0, intent);
105
106 assertEquals(1, listener1.callCount);
107 assertEquals(1, listener2.callCount);
108
109 // fire it again to check if the first called listener was removed
110 registry.onActivityResult(0, 0, intent);
111
112 // The order of the listeners in the HashSet is random: So just check the sum of calls
113 assertEquals(3, listener1.callCount + listener2.callCount);
114 }

◆ itDoesNotRegisterTheSamePluginTwice()

void io.flutter.embedding.engine.FlutterEngineConnectionRegistryTest.itDoesNotRegisterTheSamePluginTwice ( )
inline

Definition at line 30 of file FlutterEngineConnectionRegistryTest.java.

30 {
31 Context context = mock(Context.class);
32
33 FlutterEngine flutterEngine = mock(FlutterEngine.class);
34 PlatformViewsController platformViewsController = mock(PlatformViewsController.class);
35 when(flutterEngine.getPlatformViewsController()).thenReturn(platformViewsController);
36
37 FlutterLoader flutterLoader = mock(FlutterLoader.class);
38
39 FakeFlutterPlugin fakePlugin1 = new FakeFlutterPlugin();
40 FakeFlutterPlugin fakePlugin2 = new FakeFlutterPlugin();
41
42 FlutterEngineConnectionRegistry registry =
43 new FlutterEngineConnectionRegistry(context, flutterEngine, flutterLoader, null);
44
45 // Verify that the registry doesn't think it contains our plugin yet.
46 assertFalse(registry.has(fakePlugin1.getClass()));
47
48 // Add our plugin to the registry.
49 registry.add(fakePlugin1);
50
51 // Verify that the registry now thinks it contains our plugin.
52 assertTrue(registry.has(fakePlugin1.getClass()));
53 assertEquals(1, fakePlugin1.attachmentCallCount);
54
55 // Add a different instance of the same plugin class.
56 registry.add(fakePlugin2);
57
58 // Verify that the registry did not detach the 1st plugin, and
59 // it did not attach the 2nd plugin.
60 assertEquals(1, fakePlugin1.attachmentCallCount);
61 assertEquals(0, fakePlugin1.detachmentCallCount);
62
63 assertEquals(0, fakePlugin2.attachmentCallCount);
64 assertEquals(0, fakePlugin2.detachmentCallCount);
65 }

◆ softwareRendering()

void io.flutter.embedding.engine.FlutterEngineConnectionRegistryTest.softwareRendering ( )
inline

Definition at line 117 of file FlutterEngineConnectionRegistryTest.java.

117 {
118 Context context = mock(Context.class);
119
120 FlutterEngine flutterEngine = mock(FlutterEngine.class);
121 PlatformViewsController platformViewsController = mock(PlatformViewsController.class);
122 when(flutterEngine.getPlatformViewsController()).thenReturn(platformViewsController);
123
124 FlutterLoader flutterLoader = mock(FlutterLoader.class);
125
126 ExclusiveAppComponent appComponent = mock(ExclusiveAppComponent.class);
127 Activity activity = mock(Activity.class);
128 when(appComponent.getAppComponent()).thenReturn(activity);
129
130 // Test attachToActivity with an Activity that has no Intent.
131 FlutterEngineConnectionRegistry registry =
132 new FlutterEngineConnectionRegistry(context, flutterEngine, flutterLoader, null);
133 registry.attachToActivity(appComponent, mock(Lifecycle.class));
134 verify(platformViewsController).setSoftwareRendering(false);
135
136 Intent intent = mock(Intent.class);
137 when(intent.getBooleanExtra("enable-software-rendering", false)).thenReturn(false);
138 when(activity.getIntent()).thenReturn(intent);
139
140 registry.attachToActivity(appComponent, mock(Lifecycle.class));
141 verify(platformViewsController, times(2)).setSoftwareRendering(false);
142
143 when(intent.getBooleanExtra("enable-software-rendering", false)).thenReturn(true);
144
145 registry.attachToActivity(appComponent, mock(Lifecycle.class));
146 verify(platformViewsController).setSoftwareRendering(true);
147 }
static SkISize times(const SkISize &size, float factor)

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