Flutter Engine
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 
11 namespace flutter {
12 namespace testing {
13 
14 TEST(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.label = "label";
22  node0.tooltip = "tooltip";
23  update.insert(std::make_pair(0, std::move(node0)));
24 
25  std::vector<uint8_t> expected_buffer(188);
26  std::vector<std::vector<uint8_t>> expected_string_attribute_args(0);
27  size_t position = 0;
28  int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
29  float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
30  std::vector<std::string> expected_strings;
31  buffer_int32[position++] = node0.id;
32  buffer_int32[position++] = node0.flags;
33  buffer_int32[position++] = node0.actions;
34  buffer_int32[position++] = node0.maxValueLength;
35  buffer_int32[position++] = node0.currentValueLength;
36  buffer_int32[position++] = node0.textSelectionBase;
37  buffer_int32[position++] = node0.textSelectionExtent;
38  buffer_int32[position++] = node0.platformViewId;
39  buffer_int32[position++] = node0.scrollChildren;
40  buffer_int32[position++] = node0.scrollIndex;
41  buffer_float32[position++] = static_cast<float>(node0.scrollPosition);
42  buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
43  buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
44  buffer_int32[position++] = expected_strings.size(); // node0.label
45  expected_strings.push_back(node0.label);
46  buffer_int32[position++] = -1; // node0.labelAttributes
47  buffer_int32[position++] = -1; // node0.value
48  buffer_int32[position++] = -1; // node0.valueAttributes
49  buffer_int32[position++] = -1; // node0.increasedValue
50  buffer_int32[position++] = -1; // node0.increasedValueAttributes
51  buffer_int32[position++] = -1; // node0.decreasedValue
52  buffer_int32[position++] = -1; // node0.decreasedValueAttributes
53  buffer_int32[position++] = -1; // node0.hint
54  buffer_int32[position++] = -1; // node0.hintAttributes
55  buffer_int32[position++] = expected_strings.size(); // node0.tooltip
56  expected_strings.push_back(node0.tooltip);
57  buffer_int32[position++] = node0.textDirection;
58  buffer_float32[position++] = node0.rect.left();
59  buffer_float32[position++] = node0.rect.top();
60  buffer_float32[position++] = node0.rect.right();
61  buffer_float32[position++] = node0.rect.bottom();
62  node0.transform.getColMajor(&buffer_float32[position]);
63  position += 16;
64  buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
65  buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
66  EXPECT_CALL(*jni_mock,
67  FlutterViewUpdateSemantics(expected_buffer, expected_strings,
68  expected_string_attribute_args));
69  // Creates empty custom actions.
71  delegate->UpdateSemantics(update, actions);
72 }
73 
74 TEST(PlatformViewShell,
75  UpdateSemanticsDoesFlutterViewUpdateSemanticsWithStringAttribtes) {
76  auto jni_mock = std::make_shared<JNIMock>();
77  auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
78 
81  std::shared_ptr<SpellOutStringAttribute> spell_out_attribute =
82  std::make_shared<SpellOutStringAttribute>();
83  spell_out_attribute->start = 2;
84  spell_out_attribute->end = 4;
85  spell_out_attribute->type = flutter::StringAttributeType::kSpellOut;
86  std::shared_ptr<LocaleStringAttribute> locale_attribute =
87  std::make_shared<LocaleStringAttribute>();
88  locale_attribute->start = 1;
89  locale_attribute->end = 3;
90  locale_attribute->type = flutter::StringAttributeType::kLocale;
91  locale_attribute->locale = "en-US";
92  node0.id = 0;
93  node0.label = "label";
94  node0.labelAttributes.push_back(spell_out_attribute);
95  node0.hint = "hint";
96  node0.hintAttributes.push_back(locale_attribute);
97  update.insert(std::make_pair(0, std::move(node0)));
98 
99  std::vector<uint8_t> expected_buffer(220);
100  std::vector<std::vector<uint8_t>> expected_string_attribute_args;
101  size_t position = 0;
102  int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&expected_buffer[0]);
103  float* buffer_float32 = reinterpret_cast<float*>(&expected_buffer[0]);
104  std::vector<std::string> expected_strings;
105  buffer_int32[position++] = node0.id;
106  buffer_int32[position++] = node0.flags;
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_float32[position++] = static_cast<float>(node0.scrollPosition);
116  buffer_float32[position++] = static_cast<float>(node0.scrollExtentMax);
117  buffer_float32[position++] = static_cast<float>(node0.scrollExtentMin);
118  buffer_int32[position++] = expected_strings.size(); // node0.label
119  expected_strings.push_back(node0.label);
120  buffer_int32[position++] = 1; // node0.labelAttributes
121  buffer_int32[position++] = 2; // node0.labelAttributes[0].start
122  buffer_int32[position++] = 4; // node0.labelAttributes[0].end
123  buffer_int32[position++] = 0; // node0.labelAttributes[0].type
124  buffer_int32[position++] = -1; // node0.labelAttributes[0].args
125  buffer_int32[position++] = -1; // node0.value
126  buffer_int32[position++] = -1; // node0.valueAttributes
127  buffer_int32[position++] = -1; // node0.increasedValue
128  buffer_int32[position++] = -1; // node0.increasedValueAttributes
129  buffer_int32[position++] = -1; // node0.decreasedValue
130  buffer_int32[position++] = -1; // node0.decreasedValueAttributes
131  buffer_int32[position++] = expected_strings.size(); // node0.hint
132  expected_strings.push_back(node0.hint);
133  buffer_int32[position++] = 1; // node0.hintAttributes
134  buffer_int32[position++] = 1; // node0.hintAttributes[0].start
135  buffer_int32[position++] = 3; // node0.hintAttributes[0].end
136  buffer_int32[position++] = 1; // node0.hintAttributes[0].type
137  buffer_int32[position++] =
138  expected_string_attribute_args.size(); // node0.hintAttributes[0].args
139  expected_string_attribute_args.push_back(
140  {locale_attribute->locale.begin(), locale_attribute->locale.end()});
141  buffer_int32[position++] = -1; // node0.tooltip
142  buffer_int32[position++] = node0.textDirection;
143  buffer_float32[position++] = node0.rect.left();
144  buffer_float32[position++] = node0.rect.top();
145  buffer_float32[position++] = node0.rect.right();
146  buffer_float32[position++] = node0.rect.bottom();
147  node0.transform.getColMajor(&buffer_float32[position]);
148  position += 16;
149  buffer_int32[position++] = 0; // node0.childrenInTraversalOrder.size();
150  buffer_int32[position++] = 0; // node0.customAccessibilityActions.size();
151  EXPECT_CALL(*jni_mock,
152  FlutterViewUpdateSemantics(expected_buffer, expected_strings,
153  expected_string_attribute_args));
154  // Creates empty custom actions.
156  delegate->UpdateSemantics(update, actions);
157 }
158 
159 TEST(PlatformViewShell,
160  UpdateSemanticsDoesFlutterViewUpdateCustomAccessibilityActions) {
161  auto jni_mock = std::make_shared<JNIMock>();
162  auto delegate = std::make_unique<PlatformViewAndroidDelegate>(jni_mock);
163 
166  action0.id = 0;
167  action0.overrideId = 1;
168  action0.label = "label";
169  action0.hint = "hint";
170  actions.insert(std::make_pair(0, std::move(action0)));
171 
172  std::vector<uint8_t> expected_actions_buffer(16);
173  int32_t* actions_buffer_int32 =
174  reinterpret_cast<int32_t*>(&expected_actions_buffer[0]);
175  std::vector<std::string> expected_action_strings;
176  actions_buffer_int32[0] = action0.id;
177  actions_buffer_int32[1] = action0.overrideId;
178  actions_buffer_int32[2] = expected_action_strings.size();
179  expected_action_strings.push_back(action0.label);
180  actions_buffer_int32[3] = expected_action_strings.size();
181  expected_action_strings.push_back(action0.hint);
182 
183  EXPECT_CALL(*jni_mock, FlutterViewUpdateCustomAccessibilityActions(
184  expected_actions_buffer, expected_action_strings));
185  // Creates empty update.
187  delegate->UpdateSemantics(update, actions);
188 }
189 
190 } // namespace testing
191 } // namespace flutter
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
StringAttributes hintAttributes
StringAttributes labelAttributes
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
TEST(DisplayListCanvas, DrawPaint)