Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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_int32[position++] = node0.traversalParent;
45 buffer_float32[position++] = static_cast<float>(node0.scrollPosition);
46 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
47 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
48 buffer_int32[position++] = static_cast<int32_t>(node0.role);
49 buffer_int32[position++] = expected_strings.size(); // node0.identifier
50 expected_strings.push_back(node0.identifier);
51 buffer_int32[position++] = expected_strings.size(); // node0.label
52 expected_strings.push_back(node0.label);
53 buffer_int32[position++] = -1; // node0.labelAttributes
54 buffer_int32[position++] = -1; // node0.value
55 buffer_int32[position++] = -1; // node0.valueAttributes
56 buffer_int32[position++] = -1; // node0.increasedValue
57 buffer_int32[position++] = -1; // node0.increasedValueAttributes
58 buffer_int32[position++] = -1; // node0.decreasedValue
59 buffer_int32[position++] = -1; // node0.decreasedValueAttributes
60 buffer_int32[position++] = -1; // node0.hint
61 buffer_int32[position++] = -1; // node0.hintAttributes
62 buffer_int32[position++] = expected_strings.size(); // node0.tooltip
63 expected_strings.push_back(node0.tooltip);
64 buffer_int32[position++] = -1; // node0.linkUrl
65 buffer_int32[position++] = -1; // node0.locale
66 buffer_int32[position++] = -1; // node0.minValue
67 buffer_int32[position++] = -1; // node0.maxValue
68 buffer_int32[position++] = node0.headingLevel;
69 buffer_int32[position++] = node0.textDirection;
70 buffer_float32[position++] = node0.rect.left();
71 buffer_float32[position++] = node0.rect.top();
72 buffer_float32[position++] = node0.rect.right();
73 buffer_float32[position++] = node0.rect.bottom();
74 node0.transform.getColMajor(&buffer_float32[position]);
75 position += 16;
76 node0.hitTestTransform.getColMajor(&buffer_float32[position]);
77 position += 16;
78 buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
79 buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
80 EXPECT_CALL(*jni_mock,
81 FlutterViewUpdateSemantics(expected_buffer, expected_strings,
82 expected_string_attribute_args));
83 // Creates empty custom actions.
85 delegate->UpdateSemantics(update, actions);
86}
87
88TEST(PlatformViewShell, UpdateSemanticsDoesUpdateLinkUrl) {
89 auto jni_mock = std::make_shared<JNIMock>();
90 auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
91
94 node0.id = 0;
95 node0.identifier = "identifier";
96 node0.label = "label";
97 node0.linkUrl = "url";
98 update.insert(std::make_pair(0, node0));
99
100 std::vector<uint8_t> expected_buffer(
102 std::vector<std::vector<uint8_t>> expected_string_attribute_args(0);
103 size_t position = 0;
104 int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
105 float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
106 std::vector<std::string> expected_strings;
107 buffer_int32[position++] = node0.id;
108 std::memcpy(&buffer_int32[position], &node0.flags, 2);
109 position += 2;
110 buffer_int32[position++] = node0.actions;
111 buffer_int32[position++] = node0.maxValueLength;
112 buffer_int32[position++] = node0.currentValueLength;
113 buffer_int32[position++] = node0.textSelectionBase;
114 buffer_int32[position++] = node0.textSelectionExtent;
115 buffer_int32[position++] = node0.platformViewId;
116 buffer_int32[position++] = node0.scrollChildren;
117 buffer_int32[position++] = node0.scrollIndex;
118 buffer_int32[position++] = node0.traversalParent;
119 buffer_float32[position++] = static_cast<float>(node0.scrollPosition);
120 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
121 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
122 buffer_int32[position++] = static_cast<int32_t>(node0.role);
123 buffer_int32[position++] = expected_strings.size(); // node0.identifier
124 expected_strings.push_back(node0.identifier);
125 buffer_int32[position++] = expected_strings.size(); // node0.label
126 expected_strings.push_back(node0.label);
127 buffer_int32[position++] = -1; // node0.labelAttributes
128 buffer_int32[position++] = -1; // node0.value
129 buffer_int32[position++] = -1; // node0.valueAttributes
130 buffer_int32[position++] = -1; // node0.increasedValue
131 buffer_int32[position++] = -1; // node0.increasedValueAttributes
132 buffer_int32[position++] = -1; // node0.decreasedValue
133 buffer_int32[position++] = -1; // node0.decreasedValueAttributes
134 buffer_int32[position++] = -1; // node0.hint
135 buffer_int32[position++] = -1; // node0.hintAttributes
136 buffer_int32[position++] = -1; // node0.tooltip
137 buffer_int32[position++] = expected_strings.size(); // node0.linkUrl
138 expected_strings.push_back(node0.linkUrl);
139 buffer_int32[position++] = -1; // node0.locale
140 buffer_int32[position++] = -1; // node0.minValue
141 buffer_int32[position++] = -1; // node0.maxValue
142 buffer_int32[position++] = node0.headingLevel;
143 buffer_int32[position++] = node0.textDirection;
144 buffer_float32[position++] = node0.rect.left();
145 buffer_float32[position++] = node0.rect.top();
146 buffer_float32[position++] = node0.rect.right();
147 buffer_float32[position++] = node0.rect.bottom();
148 node0.transform.getColMajor(&buffer_float32[position]);
149 position += 16;
150 node0.hitTestTransform.getColMajor(&buffer_float32[position]);
151 position += 16;
152 buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
153 buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
154 EXPECT_CALL(*jni_mock,
155 FlutterViewUpdateSemantics(expected_buffer, expected_strings,
156 expected_string_attribute_args));
157 // Creates empty custom actions.
159 delegate->UpdateSemantics(update, actions);
160}
161
162TEST(PlatformViewShell, UpdateSemanticsDoesUpdateLocale) {
163 auto jni_mock = std::make_shared<JNIMock>();
164 auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
165
168 node0.id = 0;
169 node0.identifier = "identifier";
170 node0.label = "label";
171 node0.locale = "es-MX";
172 node0.traversalParent = -1;
173 update.insert(std::make_pair(0, node0));
174
175 std::vector<uint8_t> expected_buffer(
177 std::vector<std::vector<uint8_t>> expected_string_attribute_args(0);
178 size_t position = 0;
179 int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
180 float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
181 std::vector<std::string> expected_strings;
182 buffer_int32[position++] = node0.id;
183 std::memcpy(&buffer_int32[position], &node0.flags, 2);
184 position += 2;
185 buffer_int32[position++] = node0.actions;
186 buffer_int32[position++] = node0.maxValueLength;
187 buffer_int32[position++] = node0.currentValueLength;
188 buffer_int32[position++] = node0.textSelectionBase;
189 buffer_int32[position++] = node0.textSelectionExtent;
190 buffer_int32[position++] = node0.platformViewId;
191 buffer_int32[position++] = node0.scrollChildren;
192 buffer_int32[position++] = node0.scrollIndex;
193 buffer_int32[position++] = node0.traversalParent;
194 buffer_float32[position++] = static_cast<float>(node0.scrollPosition);
195 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
196 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
197 buffer_int32[position++] = static_cast<int32_t>(node0.role);
198 buffer_int32[position++] = expected_strings.size(); // node0.identifier
199 expected_strings.push_back(node0.identifier);
200 buffer_int32[position++] = expected_strings.size(); // node0.label
201 expected_strings.push_back(node0.label);
202 buffer_int32[position++] = -1; // node0.labelAttributes
203 buffer_int32[position++] = -1; // node0.value
204 buffer_int32[position++] = -1; // node0.valueAttributes
205 buffer_int32[position++] = -1; // node0.increasedValue
206 buffer_int32[position++] = -1; // node0.increasedValueAttributes
207 buffer_int32[position++] = -1; // node0.decreasedValue
208 buffer_int32[position++] = -1; // node0.decreasedValueAttributes
209 buffer_int32[position++] = -1; // node0.hint
210 buffer_int32[position++] = -1; // node0.hintAttributes
211 buffer_int32[position++] = -1; // node0.tooltip
212 buffer_int32[position++] = -1; // node0.linkUrl
213 buffer_int32[position++] = expected_strings.size();
214 expected_strings.push_back(node0.locale); // node0.locale
215 buffer_int32[position++] = -1; // node0.minValue
216 buffer_int32[position++] = -1; // node0.maxValue
217 buffer_int32[position++] = node0.headingLevel;
218 buffer_int32[position++] = node0.textDirection;
219 buffer_float32[position++] = node0.rect.left();
220 buffer_float32[position++] = node0.rect.top();
221 buffer_float32[position++] = node0.rect.right();
222 buffer_float32[position++] = node0.rect.bottom();
223 node0.transform.getColMajor(&buffer_float32[position]);
224 position += 16;
225 node0.hitTestTransform.getColMajor(&buffer_float32[position]);
226 position += 16;
227 buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
228 buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
229 EXPECT_CALL(*jni_mock,
230 FlutterViewUpdateSemantics(expected_buffer, expected_strings,
231 expected_string_attribute_args));
232 // Creates empty custom actions.
234 delegate->UpdateSemantics(update, actions);
235}
236
237TEST(PlatformViewShell,
238 UpdateSemanticsDoesFlutterViewUpdateSemanticsWithStringAttribtes) {
239 auto jni_mock = std::make_shared<JNIMock>();
240 auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
241
244 std::shared_ptr<SpellOutStringAttribute> spell_out_attribute =
245 std::make_shared<SpellOutStringAttribute>();
246 spell_out_attribute->start = 2;
247 spell_out_attribute->end = 4;
248 spell_out_attribute->type = flutter::StringAttributeType::kSpellOut;
249 std::shared_ptr<LocaleStringAttribute> locale_attribute =
250 std::make_shared<LocaleStringAttribute>();
251 locale_attribute->start = 1;
252 locale_attribute->end = 3;
253 locale_attribute->type = flutter::StringAttributeType::kLocale;
254 locale_attribute->locale = "en-US";
255 node0.id = 0;
256 node0.identifier = "identifier";
257 node0.label = "label";
258 node0.labelAttributes.push_back(spell_out_attribute);
259 node0.hint = "hint";
260 node0.hintAttributes.push_back(locale_attribute);
261 update.insert(std::make_pair(0, node0));
262
263 std::vector<uint8_t> expected_buffer(
265 // 1 label attribute + 1 hint attribute.
267 std::vector<std::vector<uint8_t>> expected_string_attribute_args;
268 size_t position = 0;
269 int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
270 float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
271 std::vector<std::string> expected_strings;
272 buffer_int32[position++] = node0.id;
273 std::memcpy(&buffer_int32[position], &node0.flags, 2);
274 position += 2;
275 buffer_int32[position++] = node0.actions;
276 buffer_int32[position++] = node0.maxValueLength;
277 buffer_int32[position++] = node0.currentValueLength;
278 buffer_int32[position++] = node0.textSelectionBase;
279 buffer_int32[position++] = node0.textSelectionExtent;
280 buffer_int32[position++] = node0.platformViewId;
281 buffer_int32[position++] = node0.scrollChildren;
282 buffer_int32[position++] = node0.scrollIndex;
283 buffer_int32[position++] = node0.traversalParent;
284 buffer_float32[position++] = static_cast<float>(node0.scrollPosition);
285 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
286 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
287 buffer_int32[position++] = static_cast<int32_t>(node0.role);
288 buffer_int32[position++] = expected_strings.size(); // node0.identifier
289 expected_strings.push_back(node0.identifier);
290 buffer_int32[position++] = expected_strings.size(); // node0.label
291 expected_strings.push_back(node0.label);
292 buffer_int32[position++] = 1; // node0.labelAttributes
293 buffer_int32[position++] = 2; // node0.labelAttributes[0].start
294 buffer_int32[position++] = 4; // node0.labelAttributes[0].end
295 buffer_int32[position++] = 0; // node0.labelAttributes[0].type
296 buffer_int32[position++] = -1; // node0.labelAttributes[0].args
297 buffer_int32[position++] = -1; // node0.value
298 buffer_int32[position++] = -1; // node0.valueAttributes
299 buffer_int32[position++] = -1; // node0.increasedValue
300 buffer_int32[position++] = -1; // node0.increasedValueAttributes
301 buffer_int32[position++] = -1; // node0.decreasedValue
302 buffer_int32[position++] = -1; // node0.decreasedValueAttributes
303 buffer_int32[position++] = expected_strings.size(); // node0.hint
304 expected_strings.push_back(node0.hint);
305 buffer_int32[position++] = 1; // node0.hintAttributes
306 buffer_int32[position++] = 1; // node0.hintAttributes[0].start
307 buffer_int32[position++] = 3; // node0.hintAttributes[0].end
308 buffer_int32[position++] = 1; // node0.hintAttributes[0].type
309 buffer_int32[position++] =
310 expected_string_attribute_args.size(); // node0.hintAttributes[0].args
311 expected_string_attribute_args.push_back(
312 {locale_attribute->locale.begin(), locale_attribute->locale.end()});
313 buffer_int32[position++] = -1; // node0.tooltip
314 buffer_int32[position++] = -1; // node0.linkUrl
315 buffer_int32[position++] = -1; // node0.locale
316 buffer_int32[position++] = -1; // node0.minValue
317 buffer_int32[position++] = -1; // node0.maxValue
318 buffer_int32[position++] = node0.headingLevel;
319 buffer_int32[position++] = node0.textDirection;
320 buffer_float32[position++] = node0.rect.left();
321 buffer_float32[position++] = node0.rect.top();
322 buffer_float32[position++] = node0.rect.right();
323 buffer_float32[position++] = node0.rect.bottom();
324 node0.transform.getColMajor(&buffer_float32[position]);
325 position += 16;
326 node0.hitTestTransform.getColMajor(&buffer_float32[position]);
327 position += 16;
328 buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
329 buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
330 EXPECT_CALL(*jni_mock,
331 FlutterViewUpdateSemantics(expected_buffer, expected_strings,
332 expected_string_attribute_args));
333 // Creates empty custom actions.
335 delegate->UpdateSemantics(update, actions);
336}
337
338TEST(PlatformViewShell,
339 UpdateSemanticsDoesFlutterViewUpdateCustomAccessibilityActions) {
340 auto jni_mock = std::make_shared<JNIMock>();
341 auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
342
345 action0.id = 0;
346 action0.overrideId = 1;
347 action0.label = "label";
348 action0.hint = "hint";
349 actions.insert(std::make_pair(0, action0));
350
351 std::vector<uint8_t> expected_actions_buffer(
353 int32_t* actions_buffer_int32 =
354 reinterpret_cast<int32_t*>(&expected_actions_buffer[0]);
355 std::vector<std::string> expected_action_strings;
356 actions_buffer_int32[0] = action0.id;
357 actions_buffer_int32[1] = action0.overrideId;
358 actions_buffer_int32[2] = expected_action_strings.size();
359 expected_action_strings.push_back(action0.label);
360 actions_buffer_int32[3] = expected_action_strings.size();
361 expected_action_strings.push_back(action0.hint);
362
363 EXPECT_CALL(*jni_mock, FlutterViewUpdateCustomAccessibilityActions(
364 expected_actions_buffer, expected_action_strings));
365 // Creates empty update.
367 delegate->UpdateSemantics(update, actions);
368}
369
370} // namespace testing
371} // namespace flutter
TEST(NativeAssetsManagerTest, NoAvailableAssets)
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
StringAttributes hintAttributes
StringAttributes labelAttributes