Chromium Code Reviews| Index: ui/accessibility/ax_tree_unittest.cc |
| diff --git a/ui/accessibility/ax_tree_unittest.cc b/ui/accessibility/ax_tree_unittest.cc |
| index 3f11899c8536c908997bf357a519edaef9307363..c22cf4857cea9728fa1c527f8fb3cfa347d5b279 100644 |
| --- a/ui/accessibility/ax_tree_unittest.cc |
| +++ b/ui/accessibility/ax_tree_unittest.cc |
| @@ -3,6 +3,7 @@ |
| // found in the LICENSE file. |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/accessibility/ax_node.h" |
| #include "ui/accessibility/ax_serializable_tree.h" |
| @@ -11,7 +12,7 @@ |
| namespace ui { |
| -TEST(AXTreeTest, TestSerialize) { |
| +TEST(AXTreeTest, SerializeSimpleAXTree) { |
| AXNodeData root; |
| root.id = 1; |
| root.role = AX_ROLE_ROOT_WEB_AREA; |
| @@ -58,4 +59,121 @@ TEST(AXTreeTest, TestSerialize) { |
| EXPECT_EQ(checkbox.role, checkbox_node->data().role); |
| } |
| +TEST(AXTreeTest, EmptyUpdateFails) { |
|
aboxhall
2013/12/02 17:18:08
This test doesn't assert anything?
dmazzoni
2013/12/03 08:35:04
Good catch, thanks. I actually changed my mind abo
|
| + AXNodeData root; |
| + root.id = 1; |
| + root.role = AX_ROLE_ROOT_WEB_AREA; |
| + |
| + AXTreeUpdate initial_state; |
| + initial_state.nodes.push_back(root); |
| + AXSerializableTree src_tree(initial_state); |
| + |
| + AXTreeUpdate update; |
| + update.node_id_to_clear = 2; |
| +} |
| + |
| +TEST(AXTreeTest, DeleteUnknownSubtreeFails) { |
| + AXNodeData root; |
| + root.id = 1; |
| + root.role = AX_ROLE_ROOT_WEB_AREA; |
| + |
| + AXTreeUpdate initial_state; |
| + initial_state.nodes.push_back(root); |
| + AXTree tree(initial_state); |
| + |
| + // This should fail because we're asking it to delete |
| + // a subtree rooted at id=2, which doesn't exist. |
| + AXTreeUpdate update; |
| + update.node_id_to_clear = 2; |
| + update.nodes.resize(1); |
| + update.nodes[0].id = 1; |
| + update.nodes[0].id = AX_ROLE_ROOT_WEB_AREA; |
| + EXPECT_FALSE(tree.Unserialize(update)); |
| + ASSERT_EQ("Bad node_id_to_clear: 2", tree.error()); |
| +} |
| + |
| +TEST(AXTreeTest, LeaveOrphanedDeletedSubtreeFails) { |
| + AXTreeUpdate initial_state; |
| + initial_state.nodes.resize(3); |
| + initial_state.nodes[0].id = 1; |
| + initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| + initial_state.nodes[0].child_ids.push_back(2); |
| + initial_state.nodes[0].child_ids.push_back(3); |
| + initial_state.nodes[1].id = 2; |
| + initial_state.nodes[2].id = 3; |
| + AXTree tree(initial_state); |
| + |
| + // This should fail because we delete a subtree rooted at id=2 |
| + // but never update it. |
| + AXTreeUpdate update; |
| + update.node_id_to_clear = 2; |
| + update.nodes.resize(1); |
| + update.nodes[0].id = 3; |
| + EXPECT_FALSE(tree.Unserialize(update)); |
| + ASSERT_EQ("Nodes left pending by the update: 2", tree.error()); |
| +} |
| + |
| +TEST(AXTreeTest, LeaveOrphanedNewChildFails) { |
| + AXTreeUpdate initial_state; |
| + initial_state.nodes.resize(1); |
| + initial_state.nodes[0].id = 1; |
| + initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| + AXTree tree(initial_state); |
| + |
| + // This should fail because we add a new child to the root node |
| + // but never update it. |
| + AXTreeUpdate update; |
| + update.nodes.resize(1); |
| + update.nodes[0].id = 1; |
| + update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| + update.nodes[0].child_ids.push_back(2); |
| + EXPECT_FALSE(tree.Unserialize(update)); |
| + ASSERT_EQ("Nodes left pending by the update: 2", tree.error()); |
| +} |
| + |
| +TEST(AXTreeTest, DuplicateChildIdFails) { |
| + AXTreeUpdate initial_state; |
| + initial_state.nodes.resize(1); |
| + initial_state.nodes[0].id = 1; |
| + initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| + AXTree tree(initial_state); |
| + |
| + // This should fail because a child id appears twice. |
| + AXTreeUpdate update; |
| + update.nodes.resize(2); |
| + update.nodes[0].id = 1; |
| + update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| + update.nodes[0].child_ids.push_back(2); |
| + update.nodes[0].child_ids.push_back(2); |
| + update.nodes[1].id = 2; |
| + EXPECT_FALSE(tree.Unserialize(update)); |
| + ASSERT_EQ("Node 1 has duplicate child id 2", tree.error()); |
| +} |
| + |
| +TEST(AXTreeTest, InvalidReparentingFails) { |
| + AXTreeUpdate initial_state; |
| + initial_state.nodes.resize(3); |
| + initial_state.nodes[0].id = 1; |
| + initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| + initial_state.nodes[0].child_ids.push_back(2); |
| + initial_state.nodes[1].id = 2; |
| + initial_state.nodes[1].child_ids.push_back(3); |
| + initial_state.nodes[2].id = 3; |
| + |
| + AXTree tree(initial_state); |
| + |
| + // This should fail because node 3 is reparented from node 2 to node 1 |
| + // without deleting node 1's subtree first. |
| + AXTreeUpdate update; |
| + update.nodes.resize(3); |
| + update.nodes[0].id = 1; |
| + update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| + update.nodes[0].child_ids.push_back(3); |
| + update.nodes[0].child_ids.push_back(2); |
| + update.nodes[1].id = 2; |
| + update.nodes[2].id = 3; |
| + EXPECT_FALSE(tree.Unserialize(update)); |
| + ASSERT_EQ("Node 3 reparented from 2 to 1", tree.error()); |
| +} |
| + |
| } // namespace ui |