Flutter Engine
The Flutter Engine
android_shell_holder_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <memory>
6
7#include "flutter/shell/platform/android/android_shell_holder.h"
8#include "gmock/gmock.h"
9#include "gtest/gtest.h"
11
12namespace flutter {
13namespace testing {
14namespace {
15class MockPlatformViewAndroidJNI : public PlatformViewAndroidJNI {
16 public:
17 MOCK_METHOD(void,
18 FlutterViewHandlePlatformMessage,
19 (std::unique_ptr<flutter::PlatformMessage> message,
20 int responseId),
21 (override));
22 MOCK_METHOD(void,
23 FlutterViewHandlePlatformMessageResponse,
24 (int responseId, std::unique_ptr<fml::Mapping> data),
25 (override));
26 MOCK_METHOD(void,
27 FlutterViewUpdateSemantics,
28 (std::vector<uint8_t> buffer,
29 std::vector<std::string> strings,
30 std::vector<std::vector<uint8_t>> string_attribute_args),
31 (override));
32 MOCK_METHOD(void,
33 FlutterViewUpdateCustomAccessibilityActions,
34 (std::vector<uint8_t> actions_buffer,
35 std::vector<std::string> strings),
36 (override));
37 MOCK_METHOD(void, FlutterViewOnFirstFrame, (), (override));
38 MOCK_METHOD(void, FlutterViewOnPreEngineRestart, (), (override));
39 MOCK_METHOD(void,
40 SurfaceTextureAttachToGLContext,
41 (JavaLocalRef surface_texture, int textureId),
42 (override));
43 MOCK_METHOD(bool,
44 SurfaceTextureShouldUpdate,
45 (JavaLocalRef surface_texture),
46 (override));
47 MOCK_METHOD(void,
48 SurfaceTextureUpdateTexImage,
49 (JavaLocalRef surface_texture),
50 (override));
51 MOCK_METHOD(void,
52 SurfaceTextureGetTransformMatrix,
53 (JavaLocalRef surface_texture, SkMatrix& transform),
54 (override));
55 MOCK_METHOD(void,
56 SurfaceTextureDetachFromGLContext,
57 (JavaLocalRef surface_texture),
58 (override));
59 MOCK_METHOD(JavaLocalRef,
60 ImageProducerTextureEntryAcquireLatestImage,
61 (JavaLocalRef image_texture_entry),
62 (override));
63 MOCK_METHOD(JavaLocalRef,
64 ImageGetHardwareBuffer,
66 (override));
67 MOCK_METHOD(void, ImageClose, (JavaLocalRef image), (override));
68 MOCK_METHOD(void,
69 HardwareBufferClose,
70 (JavaLocalRef hardware_buffer),
71 (override));
72 MOCK_METHOD(void,
73 FlutterViewOnDisplayPlatformView,
74 (int view_id,
75 int x,
76 int y,
77 int width,
78 int height,
79 int viewWidth,
80 int viewHeight,
81 MutatorsStack mutators_stack),
82 (override));
83 MOCK_METHOD(void,
84 FlutterViewDisplayOverlaySurface,
85 (int surface_id, int x, int y, int width, int height),
86 (override));
87 MOCK_METHOD(void, FlutterViewBeginFrame, (), (override));
88 MOCK_METHOD(void, FlutterViewEndFrame, (), (override));
89 MOCK_METHOD(std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata>,
90 FlutterViewCreateOverlaySurface,
91 (),
92 (override));
93 MOCK_METHOD(void, FlutterViewDestroyOverlaySurfaces, (), (override));
94 MOCK_METHOD(std::unique_ptr<std::vector<std::string>>,
95 FlutterViewComputePlatformResolvedLocale,
96 (std::vector<std::string> supported_locales_data),
97 (override));
98 MOCK_METHOD(double, GetDisplayRefreshRate, (), (override));
99 MOCK_METHOD(double, GetDisplayWidth, (), (override));
100 MOCK_METHOD(double, GetDisplayHeight, (), (override));
101 MOCK_METHOD(double, GetDisplayDensity, (), (override));
102 MOCK_METHOD(bool,
103 RequestDartDeferredLibrary,
104 (int loading_unit_id),
105 (override));
106 MOCK_METHOD(double,
107 FlutterViewGetScaledFontSize,
108 (double font_size, int configuration_id),
109 (const, override));
110};
111
112class MockPlatformMessageResponse : public PlatformMessageResponse {
113 public:
115 return fml::AdoptRef(new MockPlatformMessageResponse());
116 }
117 MOCK_METHOD(void, Complete, (std::unique_ptr<fml::Mapping> data), (override));
118 MOCK_METHOD(void, CompleteEmpty, (), (override));
119};
120} // namespace
121
124 settings.enable_software_rendering = false;
125 auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
126 auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
127 EXPECT_NE(holder.get(), nullptr);
128 EXPECT_TRUE(holder->IsValid());
129 EXPECT_NE(holder->GetPlatformView().get(), nullptr);
130 auto window = fml::MakeRefCounted<AndroidNativeWindow>(
131 nullptr, /*is_fake_window=*/true);
132 holder->GetPlatformView()->NotifyCreated(window);
133}
134
135TEST(AndroidShellHolder, HandlePlatformMessage) {
137 settings.enable_software_rendering = false;
138 auto jni = std::make_shared<MockPlatformViewAndroidJNI>();
139 auto holder = std::make_unique<AndroidShellHolder>(settings, jni);
140 EXPECT_NE(holder.get(), nullptr);
141 EXPECT_TRUE(holder->IsValid());
142 EXPECT_NE(holder->GetPlatformView().get(), nullptr);
143 auto window = fml::MakeRefCounted<AndroidNativeWindow>(
144 nullptr, /*is_fake_window=*/true);
145 holder->GetPlatformView()->NotifyCreated(window);
146 EXPECT_TRUE(holder->GetPlatformMessageHandler());
147 size_t data_size = 4;
148 fml::MallocMapping bytes =
149 fml::MallocMapping(static_cast<uint8_t*>(malloc(data_size)), data_size);
152 auto message = std::make_unique<PlatformMessage>(
153 /*channel=*/"foo", /*data=*/std::move(bytes), /*response=*/response);
154 int response_id = 1;
155 EXPECT_CALL(*jni,
156 FlutterViewHandlePlatformMessage(::testing::_, response_id));
157 EXPECT_CALL(*response, CompleteEmpty());
158 holder->GetPlatformMessageHandler()->HandlePlatformMessage(
159 std::move(message));
160 holder->GetPlatformMessageHandler()
161 ->InvokePlatformMessageEmptyResponseCallback(response_id);
162}
163} // namespace testing
164} // namespace flutter
static sk_sp< Effect > Create()
Definition: RefCntTest.cpp:117
This is the Android owner of the core engine Shell.
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition: mapping.h:144
SkScalar font_size
GLFWwindow * window
Definition: main.cc:45
Win32Message message
double y
double x
sk_sp< const SkImage > image
Definition: SkRecords.h:269
void * malloc(size_t size)
Definition: allocation.cc:19
TEST(DisplayListComplexity, EmptyDisplayList)
std::nullptr_t JavaLocalRef
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition: switches.h:41
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
Definition: switches.h:126
RefPtr< T > AdoptRef(T *ptr)
Definition: ref_ptr.h:222
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
int32_t height
int32_t width
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678