Flutter Engine
 
Loading...
Searching...
No Matches
semantics_update_builder_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
7
8#include "gtest/gtest.h"
9
10namespace flutter {
11namespace testing {
12
14
15TEST_F(SemanticsUpdateBuilderTest, CanHandleAttributedStrings) {
16 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
17
18 auto nativeSemanticsUpdate = [message_latch](Dart_NativeArguments args) {
19 auto handle = Dart_GetNativeArgument(args, 0);
20 intptr_t peer = 0;
21 Dart_Handle result = Dart_GetNativeInstanceField(
23 ASSERT_FALSE(Dart_IsError(result));
24 SemanticsUpdate* update = reinterpret_cast<SemanticsUpdate*>(peer);
25 SemanticsNodeUpdates nodes = update->takeNodes();
26 ASSERT_EQ(nodes.size(), static_cast<size_t>(1));
27 auto found = nodes.find(0);
28 ASSERT_NE(found, nodes.end());
29 SemanticsNode node = found->second;
30 // Should match the updateNode in ui_test.dart.
31 ASSERT_EQ(node.label, "label");
32 ASSERT_EQ(node.labelAttributes.size(), static_cast<size_t>(1));
33 ASSERT_EQ(node.labelAttributes[0]->start, 1);
34 ASSERT_EQ(node.labelAttributes[0]->end, 2);
35 ASSERT_EQ(node.labelAttributes[0]->type, StringAttributeType::kSpellOut);
36
37 ASSERT_EQ(node.value, "value");
38 ASSERT_EQ(node.valueAttributes.size(), static_cast<size_t>(1));
39 ASSERT_EQ(node.valueAttributes[0]->start, 2);
40 ASSERT_EQ(node.valueAttributes[0]->end, 3);
41 ASSERT_EQ(node.valueAttributes[0]->type, StringAttributeType::kSpellOut);
42
43 ASSERT_EQ(node.hint, "hint");
44 ASSERT_EQ(node.hintAttributes.size(), static_cast<size_t>(1));
45 ASSERT_EQ(node.hintAttributes[0]->start, 0);
46 ASSERT_EQ(node.hintAttributes[0]->end, 1);
47 ASSERT_EQ(node.hintAttributes[0]->type, StringAttributeType::kLocale);
48 auto local_attribute =
49 std::static_pointer_cast<LocaleStringAttribute>(node.hintAttributes[0]);
50 ASSERT_EQ(local_attribute->locale, "en-MX");
51
52 ASSERT_EQ(node.increasedValue, "increasedValue");
53 ASSERT_EQ(node.increasedValueAttributes.size(), static_cast<size_t>(1));
54 ASSERT_EQ(node.increasedValueAttributes[0]->start, 4);
55 ASSERT_EQ(node.increasedValueAttributes[0]->end, 5);
56 ASSERT_EQ(node.increasedValueAttributes[0]->type,
58
59 ASSERT_EQ(node.decreasedValue, "decreasedValue");
60 ASSERT_EQ(node.decreasedValueAttributes.size(), static_cast<size_t>(1));
61 ASSERT_EQ(node.decreasedValueAttributes[0]->start, 5);
62 ASSERT_EQ(node.decreasedValueAttributes[0]->end, 6);
63 ASSERT_EQ(node.decreasedValueAttributes[0]->type,
65 message_latch->Signal();
66 };
67
68 Settings settings = CreateSettingsForFixture();
69 TaskRunners task_runners("test", // label
70 GetCurrentTaskRunner(), // platform
71 CreateNewThread(), // raster
72 CreateNewThread(), // ui
73 CreateNewThread() // io
74 );
75
76 AddNativeCallback("SemanticsUpdate",
77 CREATE_NATIVE_ENTRY(nativeSemanticsUpdate));
78
79 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
80
81 ASSERT_TRUE(shell->IsSetup());
82 auto configuration = RunConfiguration::InferFromSettings(settings);
83 configuration.SetEntrypoint("sendSemanticsUpdate");
84
85 shell->RunEngine(std::move(configuration), [](auto result) {
86 ASSERT_EQ(result, Engine::RunStatus::Success);
87 });
88
89 message_latch->Wait();
90 DestroyShell(std::move(shell), task_runners);
91}
92
93TEST_F(SemanticsUpdateBuilderTest, CanHandleSemanticsRole) {
94 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
95
96 auto nativeSemanticsUpdate = [message_latch](Dart_NativeArguments args) {
97 auto handle = Dart_GetNativeArgument(args, 0);
98 intptr_t peer = 0;
99 Dart_Handle result = Dart_GetNativeInstanceField(
100 handle, tonic::DartWrappable::kPeerIndex, &peer);
101 ASSERT_FALSE(Dart_IsError(result));
102 SemanticsUpdate* update = reinterpret_cast<SemanticsUpdate*>(peer);
103 SemanticsNodeUpdates nodes = update->takeNodes();
104 auto found = nodes.find(0);
105 ASSERT_NE(found, nodes.end());
106 SemanticsNode node = found->second;
107 // Should match the updateNode in ui_test.dart.
108 ASSERT_EQ(node.role, SemanticsRole::kTab);
109 message_latch->Signal();
110 };
111
112 Settings settings = CreateSettingsForFixture();
113 TaskRunners task_runners("test", // label
114 GetCurrentTaskRunner(), // platform
115 CreateNewThread(), // raster
116 CreateNewThread(), // ui
117 CreateNewThread() // io
118 );
119
120 AddNativeCallback("SemanticsUpdate",
121 CREATE_NATIVE_ENTRY(nativeSemanticsUpdate));
122
123 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
124
125 ASSERT_TRUE(shell->IsSetup());
126 auto configuration = RunConfiguration::InferFromSettings(settings);
127 configuration.SetEntrypoint("sendSemanticsUpdateWithRole");
128
129 shell->RunEngine(std::move(configuration), [](Engine::RunStatus result) {
130 ASSERT_EQ(result, Engine::RunStatus::Success);
131 });
132
133 message_latch->Wait();
134 DestroyShell(std::move(shell), task_runners);
135}
136
137TEST_F(SemanticsUpdateBuilderTest, CanHandleSemanticsLocale) {
138 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
139
140 auto nativeSemanticsUpdate = [message_latch](Dart_NativeArguments args) {
141 auto handle = Dart_GetNativeArgument(args, 0);
142 intptr_t peer = 0;
143 Dart_Handle result = Dart_GetNativeInstanceField(
144 handle, tonic::DartWrappable::kPeerIndex, &peer);
145 ASSERT_FALSE(Dart_IsError(result));
146 SemanticsUpdate* update = reinterpret_cast<SemanticsUpdate*>(peer);
147 SemanticsNodeUpdates nodes = update->takeNodes();
148 ASSERT_EQ(nodes.size(), static_cast<size_t>(1));
149 auto found = nodes.find(0);
150 ASSERT_NE(found, nodes.end());
151 SemanticsNode node = found->second;
152 // Should match the updateNode in ui_test.dart.
153 ASSERT_EQ(node.locale, "es-MX");
154 message_latch->Signal();
155 };
156
157 Settings settings = CreateSettingsForFixture();
158 TaskRunners task_runners("test", // label
159 GetCurrentTaskRunner(), // platform
160 CreateNewThread(), // raster
161 CreateNewThread(), // ui
162 CreateNewThread() // io
163 );
164
165 AddNativeCallback("SemanticsUpdate",
166 CREATE_NATIVE_ENTRY(nativeSemanticsUpdate));
167
168 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
169
170 ASSERT_TRUE(shell->IsSetup());
171 auto configuration = RunConfiguration::InferFromSettings(settings);
172 configuration.SetEntrypoint("sendSemanticsUpdateWithLocale");
173
174 shell->RunEngine(std::move(configuration), [](Engine::RunStatus result) {
175 ASSERT_EQ(result, Engine::RunStatus::Success);
176 });
177
178 message_latch->Wait();
179 DestroyShell(std::move(shell), task_runners);
180}
181
183 auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
184
185 auto nativeSemanticsUpdate = [message_latch](Dart_NativeArguments args) {
186 auto handle = Dart_GetNativeArgument(args, 0);
187 intptr_t peer = 0;
188 Dart_Handle result = Dart_GetNativeInstanceField(
189 handle, tonic::DartWrappable::kPeerIndex, &peer);
190 ASSERT_FALSE(Dart_IsError(result));
191 SemanticsUpdate* update = reinterpret_cast<SemanticsUpdate*>(peer);
192 SemanticsNodeUpdates nodes = update->takeNodes();
193 ASSERT_EQ(nodes.size(), static_cast<size_t>(1));
194 auto found = nodes.find(0);
195 ASSERT_NE(found, nodes.end());
196 SemanticsNode node = found->second;
197 // Should match the updateNode in ui_test.dart.
198 ASSERT_TRUE(node.flags.isLink);
199 message_latch->Signal();
200 };
201
202 Settings settings = CreateSettingsForFixture();
203 TaskRunners task_runners("test", // label
204 GetCurrentTaskRunner(), // platform
205 CreateNewThread(), // raster
206 CreateNewThread(), // ui
207 CreateNewThread() // io
208 );
209
210 AddNativeCallback("SemanticsUpdate",
211 CREATE_NATIVE_ENTRY(nativeSemanticsUpdate));
212
213 std::unique_ptr<Shell> shell = CreateShell(settings, task_runners);
214
215 ASSERT_TRUE(shell->IsSetup());
216 auto configuration = RunConfiguration::InferFromSettings(settings);
217 configuration.SetEntrypoint("sendSemanticsUpdateWithIsLink");
218
219 shell->RunEngine(std::move(configuration), [](Engine::RunStatus result) {
220 ASSERT_EQ(result, Engine::RunStatus::Success);
221 });
222
223 message_latch->Wait();
224 DestroyShell(std::move(shell), task_runners);
225}
226
227} // namespace testing
228} // namespace flutter
RunStatus
Indicates the result of the call to Engine::Run.
Definition engine.h:74
static RunConfiguration InferFromSettings(const Settings &settings, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
SemanticsNodeUpdates takeNodes()
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
TEST_F(DisplayListTest, Defaults)
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
StringAttributes decreasedValueAttributes
StringAttributes hintAttributes
StringAttributes increasedValueAttributes
StringAttributes valueAttributes
StringAttributes labelAttributes
#define CREATE_NATIVE_ENTRY(native_entry)