7#define FML_USED_ON_EMBEDDER
11#include "flutter/fml/macros.h"
12#include "flutter/fml/message_loop.h"
13#include "flutter/fml/synchronization/waitable_event.h"
14#include "flutter/lib/ui/semantics/semantics_node.h"
15#include "flutter/shell/platform/embedder/embedder.h"
16#include "flutter/shell/platform/embedder/tests/embedder_config_builder.h"
17#include "flutter/testing/testing.h"
20#include "gmock/gmock.h"
21#include "gtest/gtest.h"
30using ::testing::ElementsAre;
38 builder.SetSoftwareRendererConfig();
39 builder.GetProjectArgs().update_semantics_callback =
41 builder.GetProjectArgs().update_semantics_callback2 =
44 ASSERT_FALSE(
engine.is_valid());
51 builder.SetSoftwareRendererConfig();
52 builder.GetProjectArgs().update_semantics_callback2 =
54 builder.GetProjectArgs().update_semantics_node_callback =
56 builder.GetProjectArgs().update_semantics_custom_action_callback =
59 ASSERT_FALSE(
engine.is_valid());
66 builder.SetSoftwareRendererConfig();
67 builder.GetProjectArgs().update_semantics_callback =
69 builder.GetProjectArgs().update_semantics_node_callback =
71 builder.GetProjectArgs().update_semantics_custom_action_callback =
74 ASSERT_FALSE(
engine.is_valid());
81 builder.SetSoftwareRendererConfig();
82 builder.GetProjectArgs().update_semantics_callback2 =
84 builder.GetProjectArgs().update_semantics_callback =
86 builder.GetProjectArgs().update_semantics_node_callback =
88 builder.GetProjectArgs().update_semantics_custom_action_callback =
91 ASSERT_FALSE(
engine.is_valid());
97#if defined(OS_FUCHSIA)
98 GTEST_SKIP() <<
"This test crashes on Fuchsia. https://fxbug.dev/87493 ";
107 context.AddNativeCallback(
110 signal_native_latch.
Signal();
115 context.AddNativeCallback(
116 "NotifySemanticsEnabled",
119 ASSERT_NE(notify_semantics_enabled_callback,
nullptr);
120 notify_semantics_enabled_callback(
args);
123 NativeEntry notify_accessibility_features_callback;
124 context.AddNativeCallback(
125 "NotifyAccessibilityFeatures",
128 ASSERT_NE(notify_accessibility_features_callback,
nullptr);
129 notify_accessibility_features_callback(
args);
133 context.AddNativeCallback(
134 "NotifySemanticsAction",
137 ASSERT_NE(notify_semantics_action_callback,
nullptr);
138 notify_semantics_action_callback(
args);
142 context.SetSemanticsUpdateCallback2(
144 ASSERT_EQ(
size_t(4),
update->node_count);
145 ASSERT_EQ(
size_t(1),
update->custom_action_count);
147 for (
size_t i = 0;
i <
update->node_count;
i++) {
162 if (node->
id == 128) {
170 semantics_update_latch.
Signal();
174 builder.SetSoftwareRendererConfig();
175 builder.SetDartEntrypoint(
"a11y_main");
178 ASSERT_TRUE(
engine.is_valid());
186 ASSERT_FALSE(enabled);
187 notify_semantics_enabled_latch.
Signal();
189 notify_semantics_enabled_latch.
Wait();
197 ASSERT_FALSE(enabled);
198 notify_features_latch.
Signal();
207 ASSERT_TRUE(enabled);
208 notify_semantics_enabled_latch_2.
Signal();
212 notify_semantics_enabled_latch_2.
Wait();
215 notify_features_latch.
Wait();
223 ASSERT_TRUE(enabled);
224 notify_features_latch_2.
Signal();
229 notify_features_latch_2.
Wait();
232 signal_native_latch.
Wait();
234 semantics_update_latch.
Wait();
242 ASSERT_EQ(42, node_id);
248 std::vector<int64_t> semantic_args =
251 ASSERT_THAT(semantic_args, ElementsAre(2, 1));
252 notify_semantics_action_latch.
Signal();
254 std::vector<uint8_t> bytes({2, 1});
258 notify_semantics_action_latch.
Wait();
266 ASSERT_FALSE(enabled);
267 notify_semantics_enabled_latch_3.
Signal();
271 notify_semantics_enabled_latch_3.
Wait();
276#if defined(OS_FUCHSIA)
277 GTEST_SKIP() <<
"This test crashes on Fuchsia. https://fxbug.dev/87493 ";
286 context.AddNativeCallback(
289 signal_native_latch.
Signal();
293 context.SetSemanticsUpdateCallback2(
295 ASSERT_EQ(
update->node_count,
size_t(1));
296 ASSERT_EQ(
update->custom_action_count,
size_t(0));
298 auto node =
update->nodes[0];
302 ASSERT_EQ(std::string(node->label),
"What is the meaning of life?");
303 ASSERT_EQ(node->label_attribute_count,
size_t(2));
305 ASSERT_EQ(node->label_attributes[0]->start,
size_t(0));
306 ASSERT_EQ(node->label_attributes[0]->end,
size_t(28));
307 ASSERT_EQ(node->label_attributes[0]->type,
309 ASSERT_EQ(std::string(node->label_attributes[0]->locale->locale),
312 ASSERT_EQ(node->label_attributes[1]->start,
size_t(0));
313 ASSERT_EQ(node->label_attributes[1]->end,
size_t(1));
314 ASSERT_EQ(node->label_attributes[1]->type,
320 ASSERT_EQ(std::string(node->hint),
"It's a number");
321 ASSERT_EQ(node->hint_attribute_count,
size_t(2));
323 ASSERT_EQ(node->hint_attributes[0]->start,
size_t(0));
324 ASSERT_EQ(node->hint_attributes[0]->end,
size_t(1));
325 ASSERT_EQ(node->hint_attributes[0]->type,
327 ASSERT_EQ(std::string(node->hint_attributes[0]->locale->locale),
330 ASSERT_EQ(node->hint_attributes[1]->start,
size_t(2));
331 ASSERT_EQ(node->hint_attributes[1]->end,
size_t(3));
332 ASSERT_EQ(node->hint_attributes[1]->type,
334 ASSERT_EQ(std::string(node->hint_attributes[1]->locale->locale),
340 ASSERT_EQ(std::string(node->value),
"42");
341 ASSERT_EQ(node->value_attribute_count,
size_t(1));
343 ASSERT_EQ(node->value_attributes[0]->start,
size_t(0));
344 ASSERT_EQ(node->value_attributes[0]->end,
size_t(2));
345 ASSERT_EQ(node->value_attributes[0]->type,
347 ASSERT_EQ(std::string(node->value_attributes[0]->locale->locale),
353 ASSERT_EQ(std::string(node->increased_value),
"43");
354 ASSERT_EQ(node->increased_value_attribute_count,
size_t(2));
356 ASSERT_EQ(node->increased_value_attributes[0]->start,
size_t(0));
357 ASSERT_EQ(node->increased_value_attributes[0]->end,
size_t(1));
358 ASSERT_EQ(node->increased_value_attributes[0]->type,
361 ASSERT_EQ(node->increased_value_attributes[1]->start,
size_t(1));
362 ASSERT_EQ(node->increased_value_attributes[1]->end,
size_t(2));
363 ASSERT_EQ(node->increased_value_attributes[1]->type,
369 ASSERT_EQ(std::string(node->decreased_value),
"41");
370 ASSERT_EQ(node->decreased_value_attribute_count,
size_t(0));
371 ASSERT_EQ(node->decreased_value_attributes,
nullptr);
374 semantics_update_latch.
Signal();
378 builder.SetSoftwareRendererConfig();
379 builder.SetDartEntrypoint(
"a11y_string_attributes");
382 ASSERT_TRUE(
engine.is_valid());
389 signal_native_latch.
Wait();
391 semantics_update_latch.
Wait();
396#if defined(OS_FUCHSIA)
397 GTEST_SKIP() <<
"This test crashes on Fuchsia. https://fxbug.dev/87493 ";
406 context.AddNativeCallback(
409 signal_native_latch.
Signal();
414 context.AddNativeCallback(
415 "NotifySemanticsEnabled",
418 ASSERT_NE(notify_semantics_enabled_callback,
nullptr);
419 notify_semantics_enabled_callback(
args);
422 NativeEntry notify_accessibility_features_callback;
423 context.AddNativeCallback(
424 "NotifyAccessibilityFeatures",
427 ASSERT_NE(notify_accessibility_features_callback,
nullptr);
428 notify_accessibility_features_callback(
args);
432 context.AddNativeCallback(
433 "NotifySemanticsAction",
436 ASSERT_NE(notify_semantics_action_callback,
nullptr);
437 notify_semantics_action_callback(
args);
442 ASSERT_EQ(
size_t(4),
update->nodes_count);
443 ASSERT_EQ(
size_t(1),
update->custom_actions_count);
445 for (
size_t i = 0;
i <
update->nodes_count;
i++) {
459 if (node->
id == 128) {
467 semantics_update_latch.
Signal();
471 builder.SetSoftwareRendererConfig();
472 builder.SetDartEntrypoint(
"a11y_main");
475 ASSERT_TRUE(
engine.is_valid());
483 ASSERT_FALSE(enabled);
484 notify_semantics_enabled_latch.
Signal();
486 notify_semantics_enabled_latch.
Wait();
494 ASSERT_FALSE(enabled);
495 notify_features_latch.
Signal();
504 ASSERT_TRUE(enabled);
505 notify_semantics_enabled_latch_2.
Signal();
509 notify_semantics_enabled_latch_2.
Wait();
512 notify_features_latch.
Wait();
520 ASSERT_TRUE(enabled);
521 notify_features_latch_2.
Signal();
526 notify_features_latch_2.
Wait();
529 signal_native_latch.
Wait();
531 semantics_update_latch.
Wait();
539 ASSERT_EQ(42, node_id);
545 std::vector<int64_t> semantic_args =
548 ASSERT_THAT(semantic_args, ElementsAre(2, 1));
549 notify_semantics_action_latch.
Signal();
551 std::vector<uint8_t> bytes({2, 1});
555 notify_semantics_action_latch.
Wait();
563 ASSERT_FALSE(enabled);
564 notify_semantics_enabled_latch_3.
Signal();
568 notify_semantics_enabled_latch_3.
Wait();
579 context.AddNativeCallback(
582 signal_native_latch.
Signal();
587 context.AddNativeCallback(
588 "NotifySemanticsEnabled",
591 ASSERT_NE(notify_semantics_enabled_callback,
nullptr);
592 notify_semantics_enabled_callback(
args);
595 NativeEntry notify_accessibility_features_callback;
596 context.AddNativeCallback(
597 "NotifyAccessibilityFeatures",
600 ASSERT_NE(notify_accessibility_features_callback,
nullptr);
601 notify_accessibility_features_callback(
args);
605 context.AddNativeCallback(
606 "NotifySemanticsAction",
609 ASSERT_NE(notify_semantics_action_callback,
nullptr);
610 notify_semantics_action_callback(
args);
616 int node_batch_end_count = 0;
617 int action_batch_end_count = 0;
622 ++node_batch_end_count;
623 semantics_node_latch.
Signal();
626 ASSERT_EQ(0, node_batch_end_count);
627 ASSERT_EQ(0, action_batch_end_count);
641 if (node->
id == 128) {
649 int action_count = 0;
650 context.SetSemanticsCustomActionCallback(
653 ++action_batch_end_count;
654 semantics_action_latch.
Signal();
657 ASSERT_EQ(0, node_batch_end_count);
658 ASSERT_EQ(0, action_batch_end_count);
665 builder.SetSoftwareRendererConfig();
666 builder.SetDartEntrypoint(
"a11y_main");
669 ASSERT_TRUE(
engine.is_valid());
677 ASSERT_FALSE(enabled);
678 notify_semantics_enabled_latch.
Signal();
680 notify_semantics_enabled_latch.
Wait();
688 ASSERT_FALSE(enabled);
689 notify_features_latch.
Signal();
698 ASSERT_TRUE(enabled);
699 notify_semantics_enabled_latch_2.
Signal();
703 notify_semantics_enabled_latch_2.
Wait();
706 notify_features_latch.
Wait();
714 ASSERT_TRUE(enabled);
715 notify_features_latch_2.
Signal();
720 notify_features_latch_2.
Wait();
723 signal_native_latch.
Wait();
725 semantics_node_latch.
Wait();
726 semantics_action_latch.
Wait();
727 ASSERT_EQ(4, node_count);
728 ASSERT_EQ(1, node_batch_end_count);
729 ASSERT_EQ(1, action_count);
730 ASSERT_EQ(1, action_batch_end_count);
738 ASSERT_EQ(42, node_id);
744 std::vector<int64_t> semantic_args =
747 ASSERT_THAT(semantic_args, ElementsAre(2, 1));
748 notify_semantics_action_latch.
Signal();
750 std::vector<uint8_t> bytes({2, 1});
754 notify_semantics_action_latch.
Wait();
762 ASSERT_FALSE(enabled);
763 notify_semantics_enabled_latch_3.
Signal();
767 notify_semantics_enabled_latch_3.
Wait();
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
void RunExpiredTasksNow()
struct _Dart_Handle * Dart_Handle
struct _Dart_NativeArguments * Dart_NativeArguments
const int32_t kFlutterSemanticsNodeIdBatchEnd
const int32_t kFlutterSemanticsCustomActionIdBatchEnd
FlutterEngineResult FlutterEngineDispatchSemanticsAction(FLUTTER_API_SYMBOL(FlutterEngine) engine, uint64_t node_id, FlutterSemanticsAction action, const uint8_t *data, size_t data_length)
Dispatch a semantics action to the specified semantics node.
FlutterEngineResult FlutterEngineUpdateAccessibilityFeatures(FLUTTER_API_SYMBOL(FlutterEngine) engine, FlutterAccessibilityFeature flags)
Sets additional accessibility features.
FlutterEngineResult FlutterEngineUpdateSemanticsEnabled(FLUTTER_API_SYMBOL(FlutterEngine) engine, bool enabled)
Enable or disable accessibility semantics.
@ kFlutterAccessibilityFeatureReduceMotion
@ kFlutterSemanticsActionTap
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
TEST_F(DisplayListTest, Defaults)
testing::EmbedderTest EmbedderTest
static constexpr char kTooltip[]
std::function< void(Dart_NativeArguments)> NativeEntry
const char * tooltip
A textual tooltip attached to the node.
FlutterPlatformViewIdentifier platform_view_id
int32_t id
The unique identifier for this node.
FlutterTransformation transform
FlutterTransformation transform
const char * tooltip
A textual tooltip attached to the node.
FlutterPlatformViewIdentifier platform_view_id
int32_t id
The unique identifier for this node.
A batch of updates to semantics nodes and custom actions.
#define CREATE_NATIVE_ENTRY(native_entry)