1package io.flutter.embedding.engine;
3import static io.flutter.Build.API_LEVELS;
4import static org.junit.Assert.assertEquals;
5import static org.mockito.Mockito.mock;
6import static org.mockito.Mockito.spy;
7import static org.mockito.Mockito.times;
8import static org.mockito.Mockito.verify;
9import static org.mockito.Mockito.when;
11import android.annotation.TargetApi;
13import android.content.res.Configuration;
14import android.content.res.Resources;
16import androidx.test.ext.junit.runners.AndroidJUnit4;
17import io.flutter.embedding.engine.dart.DartExecutor;
18import io.flutter.embedding.engine.mutatorsstack.FlutterMutatorsStack;
19import io.flutter.embedding.engine.renderer.FlutterUiDisplayListener;
20import io.flutter.embedding.engine.systemchannels.LocalizationChannel;
21import io.flutter.plugin.localization.LocalizationPlugin;
22import io.flutter.plugin.platform.PlatformViewsController;
23import java.nio.ByteBuffer;
24import java.util.Locale;
25import java.util.concurrent.atomic.AtomicInteger;
27import org.junit.runner.RunWith;
28import org.robolectric.annotation.Config;
31@RunWith(AndroidJUnit4.class)
32@TargetApi(API_LEVELS.API_24)
39 AtomicInteger callbackInvocationCount =
new AtomicInteger(0);
43 public void onFlutterUiDisplayed() {
44 callbackInvocationCount.incrementAndGet();
49 public void onFlutterUiNoLongerDisplayed() {}
57 assertEquals(1, callbackInvocationCount.get());
64 assertEquals(1, callbackInvocationCount.get());
72 Context context = mock(Context.class);
73 Resources resources = mock(Resources.class);
74 Configuration config = mock(Configuration.class);
76 LocaleList localeList =
77 new LocaleList(
new Locale(
"es",
"MX"),
new Locale(
"zh",
"CN"),
new Locale(
"en",
"US"));
78 when(context.getResources()).thenReturn(resources);
79 when(resources.getConfiguration()).thenReturn(config);
80 when(config.getLocales()).thenReturn(localeList);
84 String[] supportedLocales =
91 assertEquals(
result.length, 3);
92 assertEquals(
result[0],
"zh");
93 assertEquals(
result[1],
"");
94 assertEquals(
result[2],
"");
103 assertEquals(
result.length, 3);
104 assertEquals(
result[0],
"en");
105 assertEquals(
result[1],
"CA");
106 assertEquals(
result[2],
"");
115 assertEquals(
result.length, 3);
116 assertEquals(
result[0],
"en");
117 assertEquals(
result[1],
"US");
118 assertEquals(
result[2],
"");
127 assertEquals(
result.length, 3);
128 assertEquals(
result[0],
"es");
129 assertEquals(
result[1],
"MX");
130 assertEquals(
result[2],
"");
133 supportedLocales =
new String[] {};
135 assertEquals(
result.length, 0);
144 localeList =
new LocaleList();
145 when(config.getLocales()).thenReturn(localeList);
148 assertEquals(
result.length, 3);
149 assertEquals(
result[0],
"fr");
150 assertEquals(
result[1],
"FR");
151 assertEquals(
result[2],
"");
172 verify(platformViewsController,
times(1))
173 .onDisplayPlatformView(
193 1, 10, 20, 100, 200);
196 verify(platformViewsController,
times(1))
197 .onDisplayOverlaySurface( 1, 10, 20, 100, 200);
212 verify(platformViewsController,
times(1)).onBeginFrame();
227 verify(platformViewsController,
times(1)).onEndFrame();
241 verify(platformViewsController,
times(1)).createOverlaySurface();
244 @Test(expected = IllegalArgumentException.class)
245 public
void invokePlatformMessageResponseCallback_wantsDirectBuffer() {
247 ByteBuffer
buffer = ByteBuffer.allocate(4);
257 verify(flutterJNI,
times(1)).updateRefreshRate();
static SkISize times(const SkISize &size, float factor)
void computePlatformResolvedLocaleCallsLocalizationPluginProperly()
void setRefreshRateFPS_callsUpdateRefreshRate()
void onEndFrame_callsPlatformViewsController()
void itAllowsFirstFrameListenersToRemoveThemselvesInline()
void onDisplayPlatformView_callsPlatformViewsController()
void createOverlaySurface_callsPlatformViewsController()
void onDisplayOverlaySurface_callsPlatformViewsController()
void onBeginFrame_callsPlatformViewsController()
void addIsDisplayingFlutterUiListener(@NonNull FlutterUiDisplayListener listener)
void setPlatformViewsController(@NonNull PlatformViewsController platformViewsController)
void setLocalizationPlugin(@Nullable LocalizationPlugin localizationPlugin)
FlutterOverlaySurface createOverlaySurface()
void setRefreshRateFPS(float refreshRateFPS)
void removeIsDisplayingFlutterUiListener(@NonNull FlutterUiDisplayListener listener)
void onDisplayOverlaySurface(int id, int x, int y, int width, int height)
void invokePlatformMessageResponseCallback(int responseId, @NonNull ByteBuffer message, int position)
String[] computePlatformResolvedLocale(@NonNull String[] strings)
void onDisplayPlatformView(int viewId, int x, int y, int width, int height, int viewWidth, int viewHeight, FlutterMutatorsStack mutatorsStack)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer