Flutter Engine
 
Loading...
Searching...
No Matches
platform_view_android_delegate_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
6
8#include "gmock/gmock.h"
9#include "gtest/gtest.h"
10
11namespace flutter {
12namespace testing {
13
14TEST(PlatformViewShell, UpdateSemanticsDoesFlutterViewUpdateSemantics) {
15 auto jni_mock = std::make_shared<JNIMock>();
16 auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
17
20 node0.id = 0;
21 node0.identifier = "identifier";
22 node0.label = "label";
23 node0.tooltip = "tooltip";
24 update.insert(std::make_pair(0, node0));
25
26 std::vector<uint8_t> expected_buffer(
28 std::vector<std::vector<uint8_t>> expected_string_attribute_args(0);
29 size_t position = 0;
30 int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
31 float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
32 std::vector<std::string> expected_strings;
33 buffer_int32[position++] = node0.id;
34 std::memcpy(&buffer_int32[position], &node0.flags, 2);
35 position += 2;
36 buffer_int32[position++] = node0.actions;
37 buffer_int32[position++] = node0.maxValueLength;
38 buffer_int32[position++] = node0.currentValueLength;
39 buffer_int32[position++] = node0.textSelectionBase;
40 buffer_int32[position++] = node0.textSelectionExtent;
41 buffer_int32[position++] = node0.platformViewId;
42 buffer_int32[position++] = node0.scrollChildren;
43 buffer_int32[position++] = node0.scrollIndex;
44 buffer_float32[position++] = static_cast<float>(node0.scrollPosition);
45 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
46 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
47 buffer_int32[position++] = expected_strings.size(); // node0.identifier
48 expected_strings.push_back(node0.identifier);
49 buffer_int32[position++] = expected_strings.size(); // node0.label
50 expected_strings.push_back(node0.label);
51 buffer_int32[position++] = -1; // node0.labelAttributes
52 buffer_int32[position++] = -1; // node0.value
53 buffer_int32[position++] = -1; // node0.valueAttributes
54 buffer_int32[position++] = -1; // node0.increasedValue
55 buffer_int32[position++] = -1; // node0.increasedValueAttributes
56 buffer_int32[position++] = -1; // node0.decreasedValue
57 buffer_int32[position++] = -1; // node0.decreasedValueAttributes
58 buffer_int32[position++] = -1; // node0.hint
59 buffer_int32[position++] = -1; // node0.hintAttributes
60 buffer_int32[position++] = expected_strings.size(); // node0.tooltip
61 expected_strings.push_back(node0.tooltip);
62 buffer_int32[position++] = -1; // node0.linkUrl
63 buffer_int32[position++] = -1; // node0.locale
64 buffer_int32[position++] = node0.headingLevel;
65 buffer_int32[position++] = node0.textDirection;
66 buffer_float32[position++] = node0.rect.left();
67 buffer_float32[position++] = node0.rect.top();
68 buffer_float32[position++] = node0.rect.right();
69 buffer_float32[position++] = node0.rect.bottom();
70 node0.transform.getColMajor(&buffer_float32[position]);
71 position += 16;
72 buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
73 buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
74 EXPECT_CALL(*jni_mock,
75 FlutterViewUpdateSemantics(expected_buffer, expected_strings,
76 expected_string_attribute_args));
77 // Creates empty custom actions.
79 delegate->UpdateSemantics(update, actions);
80}
81
82TEST(PlatformViewShell, UpdateSemanticsDoesUpdateLinkUrl) {
83 auto jni_mock = std::make_shared<JNIMock>();
84 auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
85
88 node0.id = 0;
89 node0.identifier = "identifier";
90 node0.label = "label";
91 node0.linkUrl = "url";
92 update.insert(std::make_pair(0, node0));
93
94 std::vector<uint8_t> expected_buffer(
96 std::vector<std::vector<uint8_t>> expected_string_attribute_args(0);
97 size_t position = 0;
98 int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
99 float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
100 std::vector<std::string> expected_strings;
101 buffer_int32[position++] = node0.id;
102 std::memcpy(&buffer_int32[position], &node0.flags, 2);
103 position += 2;
104 buffer_int32[position++] = node0.actions;
105 buffer_int32[position++] = node0.maxValueLength;
106 buffer_int32[position++] = node0.currentValueLength;
107 buffer_int32[position++] = node0.textSelectionBase;
108 buffer_int32[position++] = node0.textSelectionExtent;
109 buffer_int32[position++] = node0.platformViewId;
110 buffer_int32[position++] = node0.scrollChildren;
111 buffer_int32[position++] = node0.scrollIndex;
112 buffer_float32[position++] = static_cast<float>(node0.scrollPosition);
113 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
114 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
115 buffer_int32[position++] = expected_strings.size(); // node0.identifier
116 expected_strings.push_back(node0.identifier);
117 buffer_int32[position++] = expected_strings.size(); // node0.label
118 expected_strings.push_back(node0.label);
119 buffer_int32[position++] = -1; // node0.labelAttributes
120 buffer_int32[position++] = -1; // node0.value
121 buffer_int32[position++] = -1; // node0.valueAttributes
122 buffer_int32[position++] = -1; // node0.increasedValue
123 buffer_int32[position++] = -1; // node0.increasedValueAttributes
124 buffer_int32[position++] = -1; // node0.decreasedValue
125 buffer_int32[position++] = -1; // node0.decreasedValueAttributes
126 buffer_int32[position++] = -1; // node0.hint
127 buffer_int32[position++] = -1; // node0.hintAttributes
128 buffer_int32[position++] = -1; // node0.tooltip
129 buffer_int32[position++] = expected_strings.size(); // node0.linkUrl
130 expected_strings.push_back(node0.linkUrl);
131 buffer_int32[position++] = -1; // node0.locale
132 buffer_int32[position++] = node0.headingLevel;
133 buffer_int32[position++] = node0.textDirection;
134 buffer_float32[position++] = node0.rect.left();
135 buffer_float32[position++] = node0.rect.top();
136 buffer_float32[position++] = node0.rect.right();
137 buffer_float32[position++] = node0.rect.bottom();
138 node0.transform.getColMajor(&buffer_float32[position]);
139 position += 16;
140 buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
141 buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
142 EXPECT_CALL(*jni_mock,
143 FlutterViewUpdateSemantics(expected_buffer, expected_strings,
144 expected_string_attribute_args));
145 // Creates empty custom actions.
147 delegate->UpdateSemantics(update, actions);
148}
149
150TEST(PlatformViewShell, UpdateSemanticsDoesUpdateLocale) {
151 auto jni_mock = std::make_shared<JNIMock>();
152 auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
153
156 node0.id = 0;
157 node0.identifier = "identifier";
158 node0.label = "label";
159 node0.locale = "es-MX";
160 update.insert(std::make_pair(0, node0));
161
162 std::vector<uint8_t> expected_buffer(
164 std::vector<std::vector<uint8_t>> expected_string_attribute_args(0);
165 size_t position = 0;
166 int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
167 float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
168 std::vector<std::string> expected_strings;
169 buffer_int32[position++] = node0.id;
170 std::memcpy(&buffer_int32[position], &node0.flags, 2);
171 position += 2;
172 buffer_int32[position++] = node0.actions;
173 buffer_int32[position++] = node0.maxValueLength;
174 buffer_int32[position++] = node0.currentValueLength;
175 buffer_int32[position++] = node0.textSelectionBase;
176 buffer_int32[position++] = node0.textSelectionExtent;
177 buffer_int32[position++] = node0.platformViewId;
178 buffer_int32[position++] = node0.scrollChildren;
179 buffer_int32[position++] = node0.scrollIndex;
180 buffer_float32[position++] = static_cast<float>(node0.scrollPosition);
181 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
182 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
183 buffer_int32[position++] = expected_strings.size(); // node0.identifier
184 expected_strings.push_back(node0.identifier);
185 buffer_int32[position++] = expected_strings.size(); // node0.label
186 expected_strings.push_back(node0.label);
187 buffer_int32[position++] = -1; // node0.labelAttributes
188 buffer_int32[position++] = -1; // node0.value
189 buffer_int32[position++] = -1; // node0.valueAttributes
190 buffer_int32[position++] = -1; // node0.increasedValue
191 buffer_int32[position++] = -1; // node0.increasedValueAttributes
192 buffer_int32[position++] = -1; // node0.decreasedValue
193 buffer_int32[position++] = -1; // node0.decreasedValueAttributes
194 buffer_int32[position++] = -1; // node0.hint
195 buffer_int32[position++] = -1; // node0.hintAttributes
196 buffer_int32[position++] = -1; // node0.tooltip
197 buffer_int32[position++] = -1; // node0.linkUrl
198 buffer_int32[position++] = expected_strings.size();
199 expected_strings.push_back(node0.locale); // node0.locale
200 buffer_int32[position++] = node0.headingLevel;
201 buffer_int32[position++] = node0.textDirection;
202 buffer_float32[position++] = node0.rect.left();
203 buffer_float32[position++] = node0.rect.top();
204 buffer_float32[position++] = node0.rect.right();
205 buffer_float32[position++] = node0.rect.bottom();
206 node0.transform.getColMajor(&buffer_float32[position]);
207 position += 16;
208 buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
209 buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
210 EXPECT_CALL(*jni_mock,
211 FlutterViewUpdateSemantics(expected_buffer, expected_strings,
212 expected_string_attribute_args));
213 // Creates empty custom actions.
215 delegate->UpdateSemantics(update, actions);
216}
217
218TEST(PlatformViewShell,
219 UpdateSemanticsDoesFlutterViewUpdateSemanticsWithStringAttribtes) {
220 auto jni_mock = std::make_shared<JNIMock>();
221 auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
222
225 std::shared_ptr<SpellOutStringAttribute> spell_out_attribute =
226 std::make_shared<SpellOutStringAttribute>();
227 spell_out_attribute->start = 2;
228 spell_out_attribute->end = 4;
229 spell_out_attribute->type = flutter::StringAttributeType::kSpellOut;
230 std::shared_ptr<LocaleStringAttribute> locale_attribute =
231 std::make_shared<LocaleStringAttribute>();
232 locale_attribute->start = 1;
233 locale_attribute->end = 3;
234 locale_attribute->type = flutter::StringAttributeType::kLocale;
235 locale_attribute->locale = "en-US";
236 node0.id = 0;
237 node0.identifier = "identifier";
238 node0.label = "label";
239 node0.labelAttributes.push_back(spell_out_attribute);
240 node0.hint = "hint";
241 node0.hintAttributes.push_back(locale_attribute);
242 update.insert(std::make_pair(0, node0));
243
244 std::vector<uint8_t> expected_buffer(
246 // 1 label attribute + 1 hint attribute.
248 std::vector<std::vector<uint8_t>> expected_string_attribute_args;
249 size_t position = 0;
250 int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
251 float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
252 std::vector<std::string> expected_strings;
253 buffer_int32[position++] = node0.id;
254 std::memcpy(&buffer_int32[position], &node0.flags, 2);
255 position += 2;
256 buffer_int32[position++] = node0.actions;
257 buffer_int32[position++] = node0.maxValueLength;
258 buffer_int32[position++] = node0.currentValueLength;
259 buffer_int32[position++] = node0.textSelectionBase;
260 buffer_int32[position++] = node0.textSelectionExtent;
261 buffer_int32[position++] = node0.platformViewId;
262 buffer_int32[position++] = node0.scrollChildren;
263 buffer_int32[position++] = node0.scrollIndex;
264 buffer_float32[position++] = static_cast<float>(node0.scrollPosition);
265 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
266 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
267 buffer_int32[position++] = expected_strings.size(); // node0.identifier
268 expected_strings.push_back(node0.identifier);
269 buffer_int32[position++] = expected_strings.size(); // node0.label
270 expected_strings.push_back(node0.label);
271 buffer_int32[position++] = 1; // node0.labelAttributes
272 buffer_int32[position++] = 2; // node0.labelAttributes[0].start
273 buffer_int32[position++] = 4; // node0.labelAttributes[0].end
274 buffer_int32[position++] = 0; // node0.labelAttributes[0].type
275 buffer_int32[position++] = -1; // node0.labelAttributes[0].args
276 buffer_int32[position++] = -1; // node0.value
277 buffer_int32[position++] = -1; // node0.valueAttributes
278 buffer_int32[position++] = -1; // node0.increasedValue
279 buffer_int32[position++] = -1; // node0.increasedValueAttributes
280 buffer_int32[position++] = -1; // node0.decreasedValue
281 buffer_int32[position++] = -1; // node0.decreasedValueAttributes
282 buffer_int32[position++] = expected_strings.size(); // node0.hint
283 expected_strings.push_back(node0.hint);
284 buffer_int32[position++] = 1; // node0.hintAttributes
285 buffer_int32[position++] = 1; // node0.hintAttributes[0].start
286 buffer_int32[position++] = 3; // node0.hintAttributes[0].end
287 buffer_int32[position++] = 1; // node0.hintAttributes[0].type
288 buffer_int32[position++] =
289 expected_string_attribute_args.size(); // node0.hintAttributes[0].args
290 expected_string_attribute_args.push_back(
291 {locale_attribute->locale.begin(), locale_attribute->locale.end()});
292 buffer_int32[position++] = -1; // node0.tooltip
293 buffer_int32[position++] = -1; // node0.linkUrl
294 buffer_int32[position++] = -1; // node0.locale
295 buffer_int32[position++] = node0.headingLevel;
296 buffer_int32[position++] = node0.textDirection;
297 buffer_float32[position++] = node0.rect.left();
298 buffer_float32[position++] = node0.rect.top();
299 buffer_float32[position++] = node0.rect.right();
300 buffer_float32[position++] = node0.rect.bottom();
301 node0.transform.getColMajor(&buffer_float32[position]);
302 position += 16;
303 buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
304 buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
305 EXPECT_CALL(*jni_mock,
306 FlutterViewUpdateSemantics(expected_buffer, expected_strings,
307 expected_string_attribute_args));
308 // Creates empty custom actions.
310 delegate->UpdateSemantics(update, actions);
311}
312
313TEST(PlatformViewShell,
314 UpdateSemanticsDoesFlutterViewUpdateCustomAccessibilityActions) {
315 auto jni_mock = std::make_shared<JNIMock>();
316 auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
317
320 action0.id = 0;
321 action0.overrideId = 1;
322 action0.label = "label";
323 action0.hint = "hint";
324 actions.insert(std::make_pair(0, action0));
325
326 std::vector<uint8_t> expected_actions_buffer(
328 int32_t* actions_buffer_int32 =
329 reinterpret_cast<int32_t*>(&expected_actions_buffer[0]);
330 std::vector<std::string> expected_action_strings;
331 actions_buffer_int32[0] = action0.id;
332 actions_buffer_int32[1] = action0.overrideId;
333 actions_buffer_int32[2] = expected_action_strings.size();
334 expected_action_strings.push_back(action0.label);
335 actions_buffer_int32[3] = expected_action_strings.size();
336 expected_action_strings.push_back(action0.hint);
337
338 EXPECT_CALL(*jni_mock, FlutterViewUpdateCustomAccessibilityActions(
339 expected_actions_buffer, expected_action_strings));
340 // Creates empty update.
342 delegate->UpdateSemantics(update, actions);
343}
344
345} // namespace testing
346} // namespace flutter
TEST(NativeAssetsManagerTest, NoAvailableAssets)
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
StringAttributes hintAttributes
StringAttributes labelAttributes