summaryrefslogtreecommitdiff
path: root/chromium/ui/accessibility/ax_tree_unittest.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-03-11 11:32:04 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-03-18 13:40:17 +0000
commit31ccca0778db85c159634478b4ec7997f6704860 (patch)
tree3d33fc3afd9d5ec95541e1bbe074a9cf8da12a0e /chromium/ui/accessibility/ax_tree_unittest.cc
parent248b70b82a40964d5594eb04feca0fa36716185d (diff)
downloadqtwebengine-chromium-31ccca0778db85c159634478b4ec7997f6704860.tar.gz
BASELINE: Update Chromium to 80.0.3987.136
Change-Id: I98e1649aafae85ba3a83e67af00bb27ef301db7b Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'chromium/ui/accessibility/ax_tree_unittest.cc')
-rw-r--r--chromium/ui/accessibility/ax_tree_unittest.cc110
1 files changed, 109 insertions, 1 deletions
diff --git a/chromium/ui/accessibility/ax_tree_unittest.cc b/chromium/ui/accessibility/ax_tree_unittest.cc
index bdb044921f4..84952172938 100644
--- a/chromium/ui/accessibility/ax_tree_unittest.cc
+++ b/chromium/ui/accessibility/ax_tree_unittest.cc
@@ -95,7 +95,10 @@ class TestAXTreeObserver : public AXTreeObserver {
base::Optional<AXNode::AXID> unignored_parent_id_before_node_deleted;
void OnNodeWillBeDeleted(AXTree* tree, AXNode* node) override {
- deleted_ids_.push_back(node->id());
+ // When this observer function is called in an update, the actual node
+ // deletion has not happened yet. Verify that node still exists in the tree.
+ ASSERT_NE(nullptr, tree->GetFromId(node->id()));
+
if (unignored_parent_id_before_node_deleted) {
ASSERT_NE(nullptr, node->GetUnignoredParent());
ASSERT_EQ(*unignored_parent_id_before_node_deleted,
@@ -119,6 +122,13 @@ class TestAXTreeObserver : public AXTreeObserver {
created_ids_.push_back(node->id());
}
+ void OnNodeDeleted(AXTree* tree, int32_t node_id) override {
+ // When this observer function is called in an update, node has already been
+ // deleted from the tree. Verify that the node is absent from the tree.
+ ASSERT_EQ(nullptr, tree->GetFromId(node_id));
+ deleted_ids_.push_back(node_id);
+ }
+
void OnNodeReparented(AXTree* tree, AXNode* node) override {
node_reparented_ids_.push_back(node->id());
}
@@ -3567,6 +3577,53 @@ TEST(AXTreeTest, OnNodeWillBeDeletedHasValidUnignoredParent) {
ASSERT_TRUE(tree.Unserialize(tree_update));
}
+TEST(AXTreeTest, OnNodeHasBeenDeleted) {
+ AXTreeUpdate initial_state;
+
+ initial_state.root_id = 1;
+ initial_state.nodes.resize(6);
+ initial_state.nodes[0].id = 1;
+ initial_state.nodes[0].role = ax::mojom::Role::kRootWebArea;
+ initial_state.nodes[0].child_ids = {2};
+ initial_state.nodes[1].id = 2;
+ initial_state.nodes[1].role = ax::mojom::Role::kButton;
+ initial_state.nodes[1].child_ids = {3, 4};
+ initial_state.nodes[2].id = 3;
+ initial_state.nodes[2].role = ax::mojom::Role::kCheckBox;
+ initial_state.nodes[3].id = 4;
+ initial_state.nodes[3].role = ax::mojom::Role::kStaticText;
+ initial_state.nodes[3].child_ids = {5, 6};
+ initial_state.nodes[4].id = 5;
+ initial_state.nodes[4].role = ax::mojom::Role::kInlineTextBox;
+ initial_state.nodes[5].id = 6;
+ initial_state.nodes[5].role = ax::mojom::Role::kInlineTextBox;
+
+ AXTree tree(initial_state);
+
+ AXTreeUpdate update;
+ update.nodes.resize(2);
+ update.nodes[0] = initial_state.nodes[1];
+ update.nodes[0].child_ids = {4};
+ update.nodes[1] = initial_state.nodes[3];
+ update.nodes[1].child_ids = {};
+
+ TestAXTreeObserver test_observer(&tree);
+ ASSERT_TRUE(tree.Unserialize(update));
+
+ EXPECT_EQ(3U, test_observer.deleted_ids().size());
+ EXPECT_EQ(3, test_observer.deleted_ids()[0]);
+ EXPECT_EQ(5, test_observer.deleted_ids()[1]);
+ EXPECT_EQ(6, test_observer.deleted_ids()[2]);
+
+ // Verify that the nodes we intend to delete in the update are actually
+ // absent from the tree.
+ for (auto id : test_observer.deleted_ids()) {
+ SCOPED_TRACE(testing::Message()
+ << "Node with id=" << id << ", should not exist in the tree");
+ EXPECT_EQ(nullptr, tree.GetFromId(id));
+ }
+}
+
// Tests a fringe scenario that may happen if multiple AXTreeUpdates are merged.
// Make sure that we correctly Unserialize if a newly created node is deleted,
// and possibly recreated later.
@@ -3802,4 +3859,55 @@ TEST(AXTreeTest, SingleUpdateTogglesIgnoredStateBeforeDestroyingNode) {
tree.ToString());
}
+// Tests that the IsInListMarker() method returns true if the current node is a
+// list marker or if it's a descendant node of a list marker..
+TEST(AXTreeTest, TestIsInListMarker) {
+ // This test uses the template of a list of one element: "1. List item"
+ AXTreeUpdate tree_update;
+ tree_update.root_id = 1;
+ tree_update.nodes.resize(8);
+ tree_update.nodes[0].id = 1;
+ tree_update.nodes[0].role = ax::mojom::Role::kList;
+ tree_update.nodes[0].child_ids = {2, 3};
+ tree_update.nodes[1].id = 2;
+ tree_update.nodes[1].role = ax::mojom::Role::kListItem;
+ tree_update.nodes[2].id = 3;
+ tree_update.nodes[2].child_ids = {4, 7};
+ tree_update.nodes[3].id = 4;
+ tree_update.nodes[3].role = ax::mojom::Role::kListMarker;
+ tree_update.nodes[3].child_ids = {5};
+ tree_update.nodes[4].id = 5;
+ tree_update.nodes[4].role = ax::mojom::Role::kStaticText; // "1. "
+ tree_update.nodes[4].child_ids = {6};
+ tree_update.nodes[5].id = 6;
+ tree_update.nodes[5].role = ax::mojom::Role::kInlineTextBox; // "1. "
+ tree_update.nodes[6].id = 7;
+ tree_update.nodes[6].role = ax::mojom::Role::kStaticText; // "List item"
+ tree_update.nodes[6].child_ids = {8};
+ tree_update.nodes[7].id = 8;
+ tree_update.nodes[7].role = ax::mojom::Role::kInlineTextBox; // "List item"
+ AXTree tree(tree_update);
+
+ AXNode* list_node = tree.GetFromId(1);
+ ASSERT_EQ(false, list_node->IsInListMarker());
+
+ AXNode* list_item_node = tree.GetFromId(2);
+ ASSERT_EQ(false, list_item_node->IsInListMarker());
+
+ AXNode* list_marker1 = tree.GetFromId(4);
+ ASSERT_EQ(true, list_marker1->IsInListMarker());
+
+ AXNode* static_node1 = tree.GetFromId(5);
+ ASSERT_EQ(true, static_node1->IsInListMarker());
+
+ AXNode* inline_node1 = tree.GetFromId(6);
+ ASSERT_EQ(true, inline_node1->IsInListMarker());
+
+ AXNode* static_node2 = tree.GetFromId(7);
+ ASSERT_EQ(false, static_node2->IsInListMarker());
+
+ AXNode* inline_node2 = tree.GetFromId(8);
+ ASSERT_EQ(false, inline_node2->IsInListMarker());
+}
+
} // namespace ui