Flutter Engine
The 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
5#include "flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate.h"
6
7#include "flutter/shell/platform/android/jni/jni_mock.h"
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(192);
27 std::vector<std::vector<uint8_t>> expected_string_attribute_args(0);
28 size_t position = 0;
29 int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
30 float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
31 std::vector<std::string> expected_strings;
32 buffer_int32[position++] = node0.id;
33 buffer_int32[position++] = node0.flags;
34 buffer_int32[position++] = node0.actions;
35 buffer_int32[position++] = node0.maxValueLength;
36 buffer_int32[position++] = node0.currentValueLength;
37 buffer_int32[position++] = node0.textSelectionBase;
38 buffer_int32[position++] = node0.textSelectionExtent;
39 buffer_int32[position++] = node0.platformViewId;
40 buffer_int32[position++] = node0.scrollChildren;
41 buffer_int32[position++] = node0.scrollIndex;
42 buffer_float32[position++] = static_cast<float>(node0.scrollPosition);
43 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
44 buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
45 buffer_int32[position++] = expected_strings.size(); // node0.identifier
46 expected_strings.push_back(node0.identifier);
47 buffer_int32[position++] = expected_strings.size(); // node0.label
48 expected_strings.push_back(node0.label);
49 buffer_int32[position++] = -1; // node0.labelAttributes
50 buffer_int32[position++] = -1; // node0.value
51 buffer_int32[position++] = -1; // node0.valueAttributes
52 buffer_int32[position++] = -1; // node0.increasedValue
53 buffer_int32[position++] = -1; // node0.increasedValueAttributes
54 buffer_int32[position++] = -1; // node0.decreasedValue
55 buffer_int32[position++] = -1; // node0.decreasedValueAttributes
56 buffer_int32[position++] = -1; // node0.hint
57 buffer_int32[position++] = -1; // node0.hintAttributes
58 buffer_int32[position++] = expected_strings.size(); // node0.tooltip
59 expected_strings.push_back(node0.tooltip);
60 buffer_int32[position++] = node0.textDirection;
61 buffer_float32[position++] = node0.rect.left();
62 buffer_float32[position++] = node0.rect.top();
63 buffer_float32[position++] = node0.rect.right();
64 buffer_float32[position++] = node0.rect.bottom();
65 node0.transform.getColMajor(&buffer_float32[position]);
66 position += 16;
67 buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
68 buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
69 EXPECT_CALL(*jni_mock,
70 FlutterViewUpdateSemantics(expected_buffer, expected_strings,
71 expected_string_attribute_args));
72 // Creates empty custom actions.
74 delegate->UpdateSemantics(update, actions);
75}
76
77TEST(PlatformViewShell,
78 UpdateSemanticsDoesFlutterViewUpdateSemanticsWithStringAttribtes) {
79 auto jni_mock = std::make_shared<JNIMock>();
80 auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
81
84 std::shared_ptr<SpellOutStringAttribute> spell_out_attribute =
85 std::make_shared<SpellOutStringAttribute>();
86 spell_out_attribute->start = 2;
87 spell_out_attribute->end = 4;
88 spell_out_attribute->type = flutter::StringAttributeType::kSpellOut;
89 std::shared_ptr<LocaleStringAttribute> locale_attribute =
90 std::make_shared<LocaleStringAttribute>();
91 locale_attribute->start = 1;
92 locale_attribute->end = 3;
93 locale_attribute->type = flutter::StringAttributeType::kLocale;
94 locale_attribute->locale = "en-US";
95 node0.id = 0;
96 node0.identifier = "identifier";
97 node0.label = "label";
98 node0.labelAttributes.push_back(spell_out_attribute);
99 node0.hint = "hint";
100 node0.hintAttributes.push_back(locale_attribute);
101 update.insert(std::make_pair(0, node0));
102
103 std::vector<uint8_t> expected_buffer(224);
104 std::vector<std::vector<uint8_t>> expected_string_attribute_args;
105 size_t position = 0;
106 int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
107 float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
108 std::vector<std::string> expected_strings;
109 buffer_int32[position++] = node0.id;
110 buffer_int32[position++] = node0.flags;
111 buffer_int32[position++] = node0.actions;
112 buffer_int32[position++] = node0.maxValueLength;
113 buffer_int32[position++] = node0.currentValueLength;
114 buffer_int32[position++] = node0.textSelectionBase;
115 buffer_int32[position++] = node0.textSelectionExtent;
116 buffer_int32[position++] = node0.platformViewId;
117 buffer_int32[position++] = node0.scrollChildren;
118 buffer_int32[position++] = node0.scrollIndex;
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++] = expected_strings.size(); // node0.identifier
123 expected_strings.push_back(node0.identifier);
124 buffer_int32[position++] = expected_strings.size(); // node0.label
125 expected_strings.push_back(node0.label);
126 buffer_int32[position++] = 1; // node0.labelAttributes
127 buffer_int32[position++] = 2; // node0.labelAttributes[0].start
128 buffer_int32[position++] = 4; // node0.labelAttributes[0].end
129 buffer_int32[position++] = 0; // node0.labelAttributes[0].type
130 buffer_int32[position++] = -1; // node0.labelAttributes[0].args
131 buffer_int32[position++] = -1; // node0.value
132 buffer_int32[position++] = -1; // node0.valueAttributes
133 buffer_int32[position++] = -1; // node0.increasedValue
134 buffer_int32[position++] = -1; // node0.increasedValueAttributes
135 buffer_int32[position++] = -1; // node0.decreasedValue
136 buffer_int32[position++] = -1; // node0.decreasedValueAttributes
137 buffer_int32[position++] = expected_strings.size(); // node0.hint
138 expected_strings.push_back(node0.hint);
139 buffer_int32[position++] = 1; // node0.hintAttributes
140 buffer_int32[position++] = 1; // node0.hintAttributes[0].start
141 buffer_int32[position++] = 3; // node0.hintAttributes[0].end
142 buffer_int32[position++] = 1; // node0.hintAttributes[0].type
143 buffer_int32[position++] =
144 expected_string_attribute_args.size(); // node0.hintAttributes[0].args
145 expected_string_attribute_args.push_back(
146 {locale_attribute->locale.begin(), locale_attribute->locale.end()});
147 buffer_int32[position++] = -1; // node0.tooltip
148 buffer_int32[position++] = node0.textDirection;
149 buffer_float32[position++] = node0.rect.left();
150 buffer_float32[position++] = node0.rect.top();
151 buffer_float32[position++] = node0.rect.right();
152 buffer_float32[position++] = node0.rect.bottom();
153 node0.transform.getColMajor(&buffer_float32[position]);
154 position += 16;
155 buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
156 buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
157 EXPECT_CALL(*jni_mock,
158 FlutterViewUpdateSemantics(expected_buffer, expected_strings,
159 expected_string_attribute_args));
160 // Creates empty custom actions.
162 delegate->UpdateSemantics(update, actions);
163}
164
165TEST(PlatformViewShell,
166 UpdateSemanticsDoesFlutterViewUpdateCustomAccessibilityActions) {
167 auto jni_mock = std::make_shared<JNIMock>();
168 auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
169
172 action0.id = 0;
173 action0.overrideId = 1;
174 action0.label = "label";
175 action0.hint = "hint";
176 actions.insert(std::make_pair(0, action0));
177
178 std::vector<uint8_t> expected_actions_buffer(16);
179 int32_t* actions_buffer_int32 =
180 reinterpret_cast<int32_t*>(&expected_actions_buffer[0]);
181 std::vector<std::string> expected_action_strings;
182 actions_buffer_int32[0] = action0.id;
183 actions_buffer_int32[1] = action0.overrideId;
184 actions_buffer_int32[2] = expected_action_strings.size();
185 expected_action_strings.push_back(action0.label);
186 actions_buffer_int32[3] = expected_action_strings.size();
187 expected_action_strings.push_back(action0.hint);
188
189 EXPECT_CALL(*jni_mock, FlutterViewUpdateCustomAccessibilityActions(
190 expected_actions_buffer, expected_action_strings));
191 // Creates empty update.
193 delegate->UpdateSemantics(update, actions);
194}
195
196} // namespace testing
197} // namespace flutter
#define TEST(S, s, D, expected)
void getColMajor(SkScalar v[]) const
Definition SkM44.h:256
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
constexpr float left() const
Definition SkRect.h:734
constexpr float top() const
Definition SkRect.h:741
constexpr float right() const
Definition SkRect.h:748
constexpr float bottom() const
Definition SkRect.h:755
StringAttributes hintAttributes
StringAttributes labelAttributes