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