7#include "gmock/gmock.h"
8#include "gtest/gtest.h"
10#include "flutter/third_party/accessibility/ax/ax_tree_manager_map.h"
21 const std::vector<int32_t>* children =
nullptr) {
26 .text_selection_base = -1,
27 .text_selection_extent = -1,
31 .increased_value =
"",
32 .decreased_value =
"",
33 .child_count = children ? children->size() : 0,
34 .children_in_traversal_order = children ? children->data() :
nullptr,
35 .custom_accessibility_actions_count = 0,
41 std::shared_ptr<TestAccessibilityBridge> bridge =
42 std::make_shared<TestAccessibilityBridge>();
44 std::vector<int32_t> children{1, 2};
49 bridge->AddFlutterSemanticsNodeUpdate(
root);
50 bridge->AddFlutterSemanticsNodeUpdate(child1);
51 bridge->AddFlutterSemanticsNodeUpdate(child2);
52 bridge->CommitUpdates();
54 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
55 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
56 auto child2_node = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
57 EXPECT_EQ(root_node->GetChildCount(), 2);
58 EXPECT_EQ(root_node->GetData().child_ids[0], 1);
59 EXPECT_EQ(root_node->GetData().child_ids[1], 2);
60 EXPECT_EQ(root_node->GetName(),
"root");
62 EXPECT_EQ(child1_node->GetChildCount(), 0);
63 EXPECT_EQ(child1_node->GetName(),
"child 1");
65 EXPECT_EQ(child2_node->GetChildCount(), 0);
66 EXPECT_EQ(child2_node->GetName(),
"child 2");
73 std::shared_ptr<TestAccessibilityBridge> bridge =
74 std::make_shared<TestAccessibilityBridge>();
76 std::vector<int32_t> children{456, 789};
81 bridge->AddFlutterSemanticsNodeUpdate(
root);
82 bridge->AddFlutterSemanticsNodeUpdate(child1);
83 bridge->AddFlutterSemanticsNodeUpdate(child2);
84 bridge->CommitUpdates();
86 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(123).lock();
87 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(456).lock();
88 auto child2_node = bridge->GetFlutterPlatformNodeDelegateFromID(789).lock();
89 auto fake_delegate = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
91 EXPECT_EQ(bridge->GetRootAsAXNode()->id(), 123);
92 EXPECT_EQ(bridge->RootDelegate()->GetName(),
"root");
94 EXPECT_EQ(root_node->GetChildCount(), 2);
95 EXPECT_EQ(root_node->GetData().child_ids[0], 456);
96 EXPECT_EQ(root_node->GetData().child_ids[1], 789);
97 EXPECT_EQ(root_node->GetName(),
"root");
99 EXPECT_EQ(child1_node->GetChildCount(), 0);
100 EXPECT_EQ(child1_node->GetName(),
"child 1");
102 EXPECT_EQ(child2_node->GetChildCount(), 0);
103 EXPECT_EQ(child2_node->GetName(),
"child 2");
110 std::shared_ptr<TestAccessibilityBridge> bridge =
111 std::make_shared<TestAccessibilityBridge>();
113 std::vector<int32_t> root_children{34, 56};
114 std::vector<int32_t> child2_children{78};
115 std::vector<int32_t> child3_children{90};
124 bridge->AddFlutterSemanticsNodeUpdate(child3);
125 bridge->AddFlutterSemanticsNodeUpdate(child2);
126 bridge->AddFlutterSemanticsNodeUpdate(
root);
127 bridge->AddFlutterSemanticsNodeUpdate(child1);
128 bridge->AddFlutterSemanticsNodeUpdate(child4);
129 bridge->CommitUpdates();
131 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(12).lock();
132 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(34).lock();
133 auto child2_node = bridge->GetFlutterPlatformNodeDelegateFromID(56).lock();
134 auto child3_node = bridge->GetFlutterPlatformNodeDelegateFromID(78).lock();
135 auto child4_node = bridge->GetFlutterPlatformNodeDelegateFromID(90).lock();
137 EXPECT_EQ(bridge->GetRootAsAXNode()->id(), 12);
138 EXPECT_EQ(bridge->RootDelegate()->GetName(),
"root");
140 EXPECT_EQ(root_node->GetChildCount(), 2);
141 EXPECT_EQ(root_node->GetData().child_ids[0], 34);
142 EXPECT_EQ(root_node->GetData().child_ids[1], 56);
143 EXPECT_EQ(root_node->GetName(),
"root");
145 EXPECT_EQ(child1_node->GetChildCount(), 0);
146 EXPECT_EQ(child1_node->GetName(),
"child 1");
148 EXPECT_EQ(child2_node->GetChildCount(), 1);
149 EXPECT_EQ(child2_node->GetData().child_ids[0], 78);
150 EXPECT_EQ(child2_node->GetName(),
"child 2");
152 EXPECT_EQ(child3_node->GetChildCount(), 1);
153 EXPECT_EQ(child3_node->GetData().child_ids[0], 90);
154 EXPECT_EQ(child3_node->GetName(),
"child 3");
156 EXPECT_EQ(child4_node->GetChildCount(), 0);
157 EXPECT_EQ(child4_node->GetName(),
"child 4");
161 std::shared_ptr<TestAccessibilityBridge> bridge =
162 std::make_shared<TestAccessibilityBridge>();
164 std::vector<int32_t> children{1};
168 bridge->AddFlutterSemanticsNodeUpdate(
root);
169 bridge->AddFlutterSemanticsNodeUpdate(child1);
171 bridge->CommitUpdates();
173 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
174 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
175 EXPECT_EQ(root_node->GetChildCount(), 1);
176 EXPECT_EQ(root_node->GetData().child_ids[0], 1);
177 EXPECT_EQ(root_node->GetName(),
"root");
179 EXPECT_EQ(child1_node->GetChildCount(), 0);
180 EXPECT_EQ(child1_node->GetName(),
"child 1");
181 bridge->accessibility_events.clear();
184 root.child_count = 2;
185 int32_t new_children[] = {1, 2};
186 root.children_in_traversal_order = new_children;
190 bridge->AddFlutterSemanticsNodeUpdate(
root);
191 bridge->AddFlutterSemanticsNodeUpdate(child2);
192 bridge->CommitUpdates();
194 root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
196 EXPECT_EQ(root_node->GetChildCount(), 2);
197 EXPECT_EQ(root_node->GetData().child_ids[0], 1);
198 EXPECT_EQ(root_node->GetData().child_ids[1], 2);
199 EXPECT_EQ(bridge->accessibility_events.size(),
size_t{2});
200 std::set<ui::AXEventGenerator::Event> actual_event{
201 bridge->accessibility_events.begin(), bridge->accessibility_events.end()};
202 EXPECT_THAT(actual_event,
204 EXPECT_THAT(actual_event,
209 std::shared_ptr<TestAccessibilityBridge> bridge =
210 std::make_shared<TestAccessibilityBridge>();
215 bridge->AddFlutterSemanticsNodeUpdate(
root);
216 bridge->CommitUpdates();
220 bridge->accessibility_events.clear();
223 root.text_selection_base = 0;
224 root.text_selection_extent = 5;
225 bridge->AddFlutterSemanticsNodeUpdate(
root);
227 bridge->CommitUpdates();
233 ASSERT_EQ(bridge->accessibility_events.size(),
size_t{2});
234 EXPECT_EQ(bridge->accessibility_events[0],
236 EXPECT_EQ(bridge->accessibility_events[1],
241 std::shared_ptr<TestAccessibilityBridge> bridge =
242 std::make_shared<TestAccessibilityBridge>();
247 bridge->AddFlutterSemanticsNodeUpdate(
root);
248 bridge->CommitUpdates();
250 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
252 EXPECT_FALSE(root_node->GetData().GetBoolAttribute(
257 std::shared_ptr<TestAccessibilityBridge> bridge =
258 std::make_shared<TestAccessibilityBridge>();
264 bridge->AddFlutterSemanticsNodeUpdate(
root);
265 bridge->CommitUpdates();
267 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
272 std::shared_ptr<TestAccessibilityBridge> bridge =
273 std::make_shared<TestAccessibilityBridge>();
280 bridge->AddFlutterSemanticsNodeUpdate(
root);
281 bridge->CommitUpdates();
283 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
293 std::shared_ptr<TestAccessibilityBridge> bridge =
294 std::make_shared<TestAccessibilityBridge>();
299 bridge->AddFlutterSemanticsNodeUpdate(
root);
300 bridge->CommitUpdates();
302 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
304 EXPECT_EQ(root_node->GetData().GetCheckedState(),
310 std::shared_ptr<TestAccessibilityBridge> bridge =
311 std::make_shared<TestAccessibilityBridge>();
313 std::vector<int32_t> root_children{1};
314 std::vector<int32_t> child1_children{2};
320 bridge->AddFlutterSemanticsNodeUpdate(
root);
321 bridge->AddFlutterSemanticsNodeUpdate(child1);
322 bridge->AddFlutterSemanticsNodeUpdate(child2);
323 bridge->CommitUpdates();
324 bridge->accessibility_events.clear();
330 int32_t new_root_children[] = {1, 2};
331 root.child_count = 2;
332 root.children_in_traversal_order = new_root_children;
334 bridge->AddFlutterSemanticsNodeUpdate(
root);
335 bridge->AddFlutterSemanticsNodeUpdate(child1);
336 bridge->AddFlutterSemanticsNodeUpdate(child2);
337 bridge->CommitUpdates();
339 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(0).lock();
340 auto child1_node = bridge->GetFlutterPlatformNodeDelegateFromID(1).lock();
341 auto child2_node = bridge->GetFlutterPlatformNodeDelegateFromID(2).lock();
343 EXPECT_EQ(root_node->GetChildCount(), 2);
344 EXPECT_EQ(root_node->GetData().child_ids[0], 1);
345 EXPECT_EQ(root_node->GetData().child_ids[1], 2);
346 EXPECT_EQ(root_node->GetName(),
"root");
348 EXPECT_EQ(child1_node->GetChildCount(), 0);
349 EXPECT_EQ(child1_node->GetName(),
"child 1");
351 EXPECT_EQ(child2_node->GetChildCount(), 0);
352 EXPECT_EQ(child2_node->GetName(),
"child 2");
354 ASSERT_EQ(bridge->accessibility_events.size(),
size_t{5});
357 EXPECT_THAT(bridge->accessibility_events,
359 EXPECT_THAT(bridge->accessibility_events,
365 bridge->accessibility_events,
367 EXPECT_THAT(bridge->accessibility_events,
373 std::shared_ptr<TestAccessibilityBridge> bridge =
374 std::make_shared<TestAccessibilityBridge>();
377 int32_t intermediary1_id = 1;
378 int32_t intermediary2_id = 2;
379 int32_t leaf1_id = 3;
380 int32_t leaf2_id = 4;
381 int32_t leaf3_id = 5;
383 std::vector<int32_t> root_children{intermediary1_id, intermediary2_id};
384 std::vector<int32_t> intermediary1_children{leaf1_id};
385 std::vector<int32_t> intermediary2_children{leaf2_id, leaf3_id};
389 intermediary1_id,
"intermediary 1", &intermediary1_children);
391 intermediary2_id,
"intermediary 2", &intermediary2_children);
396 bridge->AddFlutterSemanticsNodeUpdate(
root);
397 bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
398 bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
399 bridge->AddFlutterSemanticsNodeUpdate(leaf1);
400 bridge->AddFlutterSemanticsNodeUpdate(leaf2);
401 bridge->AddFlutterSemanticsNodeUpdate(leaf3);
402 bridge->CommitUpdates();
403 bridge->accessibility_events.clear();
406 int32_t new_intermediary1_children[] = {leaf2_id, leaf3_id};
410 int32_t new_intermediary2_children[] = {leaf1_id};
414 bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
415 bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
416 bridge->AddFlutterSemanticsNodeUpdate(leaf1);
417 bridge->AddFlutterSemanticsNodeUpdate(leaf2);
418 bridge->AddFlutterSemanticsNodeUpdate(leaf3);
419 bridge->CommitUpdates();
421 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(root_id).lock();
422 auto intermediary1_node =
423 bridge->GetFlutterPlatformNodeDelegateFromID(intermediary1_id).lock();
424 auto intermediary2_node =
425 bridge->GetFlutterPlatformNodeDelegateFromID(intermediary2_id).lock();
427 bridge->GetFlutterPlatformNodeDelegateFromID(leaf1_id).lock();
429 bridge->GetFlutterPlatformNodeDelegateFromID(leaf2_id).lock();
431 bridge->GetFlutterPlatformNodeDelegateFromID(leaf3_id).lock();
433 EXPECT_EQ(root_node->GetChildCount(), 2);
434 EXPECT_EQ(root_node->GetData().child_ids[0], intermediary1_id);
435 EXPECT_EQ(root_node->GetData().child_ids[1], intermediary2_id);
436 EXPECT_EQ(root_node->GetName(),
"root");
438 EXPECT_EQ(intermediary1_node->GetChildCount(), 2);
439 EXPECT_EQ(intermediary1_node->GetData().child_ids[0], leaf2_id);
440 EXPECT_EQ(intermediary1_node->GetData().child_ids[1], leaf3_id);
441 EXPECT_EQ(intermediary1_node->GetName(),
"intermediary 1");
443 EXPECT_EQ(intermediary2_node->GetChildCount(), 1);
444 EXPECT_EQ(intermediary2_node->GetData().child_ids[0], leaf1_id);
445 EXPECT_EQ(intermediary2_node->GetName(),
"intermediary 2");
447 EXPECT_EQ(leaf1_node->GetChildCount(), 0);
448 EXPECT_EQ(leaf1_node->GetName(),
"leaf 1");
450 EXPECT_EQ(leaf2_node->GetChildCount(), 0);
451 EXPECT_EQ(leaf2_node->GetName(),
"leaf 2");
453 EXPECT_EQ(leaf3_node->GetChildCount(), 0);
454 EXPECT_EQ(leaf3_node->GetName(),
"leaf 3");
458 ASSERT_EQ(bridge->accessibility_events.size(),
size_t{5});
459 EXPECT_THAT(bridge->accessibility_events,
461 EXPECT_THAT(bridge->accessibility_events,
467 std::shared_ptr<TestAccessibilityBridge> bridge =
468 std::make_shared<TestAccessibilityBridge>();
471 int32_t intermediary1_id = 1;
472 int32_t intermediary2_id = 2;
473 int32_t leaf1_id = 3;
475 std::vector<int32_t> root_children{intermediary1_id, intermediary2_id};
476 std::vector<int32_t> intermediary1_children{leaf1_id};
480 intermediary1_id,
"intermediary 1", &intermediary1_children);
485 bridge->AddFlutterSemanticsNodeUpdate(
root);
486 bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
487 bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
488 bridge->AddFlutterSemanticsNodeUpdate(leaf1);
489 bridge->CommitUpdates();
490 bridge->accessibility_events.clear();
493 int32_t new_root_children[] = {intermediary2_id};
494 root.child_count = 1;
495 root.children_in_traversal_order = new_root_children;
497 int32_t new_intermediary2_children[] = {intermediary1_id};
501 bridge->AddFlutterSemanticsNodeUpdate(
root);
502 bridge->AddFlutterSemanticsNodeUpdate(intermediary1);
503 bridge->AddFlutterSemanticsNodeUpdate(intermediary2);
504 bridge->AddFlutterSemanticsNodeUpdate(leaf1);
505 bridge->CommitUpdates();
507 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(root_id).lock();
508 auto intermediary1_node =
509 bridge->GetFlutterPlatformNodeDelegateFromID(intermediary1_id).lock();
510 auto intermediary2_node =
511 bridge->GetFlutterPlatformNodeDelegateFromID(intermediary2_id).lock();
513 bridge->GetFlutterPlatformNodeDelegateFromID(leaf1_id).lock();
515 EXPECT_EQ(root_node->GetChildCount(), 1);
516 EXPECT_EQ(root_node->GetData().child_ids[0], intermediary2_id);
517 EXPECT_EQ(root_node->GetName(),
"root");
519 EXPECT_EQ(intermediary2_node->GetChildCount(), 1);
520 EXPECT_EQ(intermediary2_node->GetData().child_ids[0], intermediary1_id);
521 EXPECT_EQ(intermediary2_node->GetName(),
"intermediary 2");
523 EXPECT_EQ(intermediary1_node->GetChildCount(), 1);
524 EXPECT_EQ(intermediary1_node->GetData().child_ids[0], leaf1_id);
525 EXPECT_EQ(intermediary1_node->GetName(),
"intermediary 1");
527 EXPECT_EQ(leaf1_node->GetChildCount(), 0);
528 EXPECT_EQ(leaf1_node->GetName(),
"leaf 1");
530 ASSERT_EQ(bridge->accessibility_events.size(),
size_t{5});
532 EXPECT_THAT(bridge->accessibility_events,
534 EXPECT_THAT(bridge->accessibility_events,
540 bridge->accessibility_events,
542 EXPECT_THAT(bridge->accessibility_events,
547 std::shared_ptr<TestAccessibilityBridge> bridge =
548 std::make_shared<TestAccessibilityBridge>();
557 std::shared_ptr<TestAccessibilityBridge> bridge =
558 std::make_shared<TestAccessibilityBridge>();
560 const int32_t root_id = 0;
564 bridge->AddFlutterSemanticsNodeUpdate(
root);
565 bridge->CommitUpdates();
567 auto root_node = bridge->GetFlutterPlatformNodeDelegateFromID(root_id).lock();
568 auto root_data = root_node->GetData();
@ DOCUMENT_SELECTION_CHANGED
@ OTHER_ATTRIBUTE_CHANGED
static constexpr AXID kInvalidAXID
AXTreeManager * GetManager(AXTreeID tree_id)
static AXTreeManagerMap & GetInstance()
@ kFlutterSemanticsFlagIsSlider
Whether the semantics node represents a slider.
@ kFlutterSemanticsFlagHasToggledState
The semantics node has the quality of either being "on" or "off".
@ kFlutterSemanticsFlagIsChecked
Whether a semantics node is checked.
@ kFlutterSemanticsFlagIsReadOnly
@ kFlutterSemanticsFlagIsFocused
Whether the semantic node currently holds the user's focus.
@ kFlutterSemanticsFlagIsEnabled
Whether a semantic node that hasEnabledState is currently enabled.
@ kFlutterSemanticsFlagIsFocusable
Whether the semantic node can hold the user's focus.
@ kFlutterSemanticsFlagIsTextField
Whether the semantic node represents a text field.
@ kFlutterSemanticsFlagHasCheckedState
@ kFlutterSemanticsFlagHasEnabledState
bool Contains(const Container &container, const Value &value)
FlutterSemanticsNode2 CreateSemanticsNode(int32_t id, const char *label, const std::vector< int32_t > *children=nullptr)
TEST(DisplayListComplexity, EmptyDisplayList)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font manager
const int32_t * children_in_traversal_order
Array of child node IDs in traversal order. Has length child_count.
int32_t id
The unique identifier for this node.
size_t child_count
The number of children this node has.
AXNode::AXID sel_anchor_object_id
AXNode::AXID sel_focus_object_id
int32_t sel_anchor_offset
#define EXPECT_TRUE(handle)