| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/accessibility/ax_node.h" | 8 #include "ui/accessibility/ax_node.h" |
| 9 #include "ui/accessibility/ax_serializable_tree.h" | 9 #include "ui/accessibility/ax_serializable_tree.h" |
| 10 #include "ui/accessibility/ax_tree.h" | 10 #include "ui/accessibility/ax_tree.h" |
| 11 #include "ui/accessibility/ax_tree_serializer.h" | 11 #include "ui/accessibility/ax_tree_serializer.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 class FakeAXTreeDelegate : public AXTreeDelegate { | 17 class FakeAXTreeDelegate : public AXTreeDelegate { |
| 18 public: | 18 public: |
| 19 FakeAXTreeDelegate() : root_changed_(false) {} | 19 FakeAXTreeDelegate() |
| 20 : tree_data_changed_(false), |
| 21 root_changed_(false) {} |
| 22 |
| 23 void OnTreeDataChanged(AXTree* tree) override { |
| 24 tree_data_changed_ = true; |
| 25 } |
| 20 | 26 |
| 21 void OnNodeWillBeDeleted(AXTree* tree, AXNode* node) override { | 27 void OnNodeWillBeDeleted(AXTree* tree, AXNode* node) override { |
| 22 deleted_ids_.push_back(node->id()); | 28 deleted_ids_.push_back(node->id()); |
| 23 } | 29 } |
| 24 | 30 |
| 25 void OnSubtreeWillBeDeleted(AXTree* tree, AXNode* node) override { | 31 void OnSubtreeWillBeDeleted(AXTree* tree, AXNode* node) override { |
| 26 subtree_deleted_ids_.push_back(node->id()); | 32 subtree_deleted_ids_.push_back(node->id()); |
| 27 } | 33 } |
| 28 | 34 |
| 29 void OnNodeCreated(AXTree* tree, AXNode* node) override { | 35 void OnNodeCreated(AXTree* tree, AXNode* node) override { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 48 case SUBTREE_CREATED: | 54 case SUBTREE_CREATED: |
| 49 subtree_creation_finished_ids_.push_back(id); | 55 subtree_creation_finished_ids_.push_back(id); |
| 50 break; | 56 break; |
| 51 case NODE_CHANGED: | 57 case NODE_CHANGED: |
| 52 change_finished_ids_.push_back(id); | 58 change_finished_ids_.push_back(id); |
| 53 break; | 59 break; |
| 54 } | 60 } |
| 55 } | 61 } |
| 56 } | 62 } |
| 57 | 63 |
| 64 bool tree_data_changed() const { return tree_data_changed_; } |
| 58 bool root_changed() const { return root_changed_; } | 65 bool root_changed() const { return root_changed_; } |
| 59 const std::vector<int32>& deleted_ids() { return deleted_ids_; } | 66 const std::vector<int32>& deleted_ids() { return deleted_ids_; } |
| 60 const std::vector<int32>& subtree_deleted_ids() { | 67 const std::vector<int32>& subtree_deleted_ids() { |
| 61 return subtree_deleted_ids_; | 68 return subtree_deleted_ids_; |
| 62 } | 69 } |
| 63 const std::vector<int32>& created_ids() { return created_ids_; } | 70 const std::vector<int32>& created_ids() { return created_ids_; } |
| 64 const std::vector<int32>& node_creation_finished_ids() { | 71 const std::vector<int32>& node_creation_finished_ids() { |
| 65 return node_creation_finished_ids_; | 72 return node_creation_finished_ids_; |
| 66 } | 73 } |
| 67 const std::vector<int32>& subtree_creation_finished_ids() { | 74 const std::vector<int32>& subtree_creation_finished_ids() { |
| 68 return subtree_creation_finished_ids_; | 75 return subtree_creation_finished_ids_; |
| 69 } | 76 } |
| 70 const std::vector<int32>& change_finished_ids() { | 77 const std::vector<int32>& change_finished_ids() { |
| 71 return change_finished_ids_; | 78 return change_finished_ids_; |
| 72 } | 79 } |
| 73 | 80 |
| 74 private: | 81 private: |
| 82 bool tree_data_changed_; |
| 75 bool root_changed_; | 83 bool root_changed_; |
| 76 std::vector<int32> deleted_ids_; | 84 std::vector<int32> deleted_ids_; |
| 77 std::vector<int32> subtree_deleted_ids_; | 85 std::vector<int32> subtree_deleted_ids_; |
| 78 std::vector<int32> created_ids_; | 86 std::vector<int32> created_ids_; |
| 79 std::vector<int32> changed_ids_; | 87 std::vector<int32> changed_ids_; |
| 80 std::vector<int32> node_creation_finished_ids_; | 88 std::vector<int32> node_creation_finished_ids_; |
| 81 std::vector<int32> subtree_creation_finished_ids_; | 89 std::vector<int32> subtree_creation_finished_ids_; |
| 82 std::vector<int32> change_finished_ids_; | 90 std::vector<int32> change_finished_ids_; |
| 83 }; | 91 }; |
| 84 | 92 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 98 button.role = AX_ROLE_BUTTON; | 106 button.role = AX_ROLE_BUTTON; |
| 99 button.state = 0; | 107 button.state = 0; |
| 100 button.location = gfx::Rect(20, 20, 200, 30); | 108 button.location = gfx::Rect(20, 20, 200, 30); |
| 101 | 109 |
| 102 AXNodeData checkbox; | 110 AXNodeData checkbox; |
| 103 checkbox.id = 3; | 111 checkbox.id = 3; |
| 104 checkbox.role = AX_ROLE_CHECK_BOX; | 112 checkbox.role = AX_ROLE_CHECK_BOX; |
| 105 checkbox.state = 0; | 113 checkbox.state = 0; |
| 106 checkbox.location = gfx::Rect(20, 50, 200, 30); | 114 checkbox.location = gfx::Rect(20, 50, 200, 30); |
| 107 | 115 |
| 108 AXTreeUpdate<AXNodeData> initial_state; | 116 AXTreeUpdate initial_state; |
| 109 initial_state.nodes.push_back(root); | 117 initial_state.nodes.push_back(root); |
| 110 initial_state.nodes.push_back(button); | 118 initial_state.nodes.push_back(button); |
| 111 initial_state.nodes.push_back(checkbox); | 119 initial_state.nodes.push_back(checkbox); |
| 120 initial_state.has_tree_data = true; |
| 121 initial_state.tree_data.title = "Title"; |
| 112 AXSerializableTree src_tree(initial_state); | 122 AXSerializableTree src_tree(initial_state); |
| 113 | 123 |
| 114 scoped_ptr<AXTreeSource<const AXNode*, AXNodeData> > tree_source( | 124 scoped_ptr<AXTreeSource<const AXNode*, AXNodeData, AXTreeData> > tree_source( |
| 115 src_tree.CreateTreeSource()); | 125 src_tree.CreateTreeSource()); |
| 116 AXTreeSerializer<const AXNode*, AXNodeData> serializer( | 126 AXTreeSerializer<const AXNode*, AXNodeData, AXTreeData> serializer( |
| 117 tree_source.get()); | 127 tree_source.get()); |
| 118 AXTreeUpdate<AXNodeData> update; | 128 AXTreeUpdate update; |
| 119 serializer.SerializeChanges(src_tree.root(), &update); | 129 serializer.SerializeChanges(src_tree.root(), &update); |
| 120 | 130 |
| 121 AXTree dst_tree; | 131 AXTree dst_tree; |
| 122 ASSERT_TRUE(dst_tree.Unserialize(update)); | 132 ASSERT_TRUE(dst_tree.Unserialize(update)); |
| 123 | 133 |
| 124 const AXNode* root_node = dst_tree.root(); | 134 const AXNode* root_node = dst_tree.root(); |
| 125 ASSERT_TRUE(root_node != NULL); | 135 ASSERT_TRUE(root_node != NULL); |
| 126 EXPECT_EQ(root.id, root_node->id()); | 136 EXPECT_EQ(root.id, root_node->id()); |
| 127 EXPECT_EQ(root.role, root_node->data().role); | 137 EXPECT_EQ(root.role, root_node->data().role); |
| 128 | 138 |
| 129 ASSERT_EQ(2, root_node->child_count()); | 139 ASSERT_EQ(2, root_node->child_count()); |
| 130 | 140 |
| 131 const AXNode* button_node = root_node->ChildAtIndex(0); | 141 const AXNode* button_node = root_node->ChildAtIndex(0); |
| 132 EXPECT_EQ(button.id, button_node->id()); | 142 EXPECT_EQ(button.id, button_node->id()); |
| 133 EXPECT_EQ(button.role, button_node->data().role); | 143 EXPECT_EQ(button.role, button_node->data().role); |
| 134 | 144 |
| 135 const AXNode* checkbox_node = root_node->ChildAtIndex(1); | 145 const AXNode* checkbox_node = root_node->ChildAtIndex(1); |
| 136 EXPECT_EQ(checkbox.id, checkbox_node->id()); | 146 EXPECT_EQ(checkbox.id, checkbox_node->id()); |
| 137 EXPECT_EQ(checkbox.role, checkbox_node->data().role); | 147 EXPECT_EQ(checkbox.role, checkbox_node->data().role); |
| 138 | 148 |
| 139 EXPECT_EQ( | 149 EXPECT_EQ( |
| 150 "AXTree title=Title\n" |
| 140 "id=1 rootWebArea FOCUSABLE FOCUSED (0, 0)-(800, 600) child_ids=2,3\n" | 151 "id=1 rootWebArea FOCUSABLE FOCUSED (0, 0)-(800, 600) child_ids=2,3\n" |
| 141 " id=2 button (20, 20)-(200, 30)\n" | 152 " id=2 button (20, 20)-(200, 30)\n" |
| 142 " id=3 checkBox (20, 50)-(200, 30)\n", | 153 " id=3 checkBox (20, 50)-(200, 30)\n", |
| 143 dst_tree.ToString()); | 154 dst_tree.ToString()); |
| 144 } | 155 } |
| 145 | 156 |
| 146 TEST(AXTreeTest, SerializeAXTreeUpdate) { | 157 TEST(AXTreeTest, SerializeAXTreeUpdate) { |
| 147 AXNodeData list; | 158 AXNodeData list; |
| 148 list.id = 3; | 159 list.id = 3; |
| 149 list.role = AX_ROLE_LIST; | 160 list.role = AX_ROLE_LIST; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 160 AXNodeData list_item_3; | 171 AXNodeData list_item_3; |
| 161 list_item_3.id = 6; | 172 list_item_3.id = 6; |
| 162 list_item_3.role = AX_ROLE_LIST_ITEM; | 173 list_item_3.role = AX_ROLE_LIST_ITEM; |
| 163 list_item_3.state = 0; | 174 list_item_3.state = 0; |
| 164 | 175 |
| 165 AXNodeData button; | 176 AXNodeData button; |
| 166 button.id = 7; | 177 button.id = 7; |
| 167 button.role = AX_ROLE_BUTTON; | 178 button.role = AX_ROLE_BUTTON; |
| 168 button.state = 0; | 179 button.state = 0; |
| 169 | 180 |
| 170 AXTreeUpdate<AXNodeData> update; | 181 AXTreeUpdate update; |
| 171 update.nodes.push_back(list); | 182 update.nodes.push_back(list); |
| 172 update.nodes.push_back(list_item_2); | 183 update.nodes.push_back(list_item_2); |
| 173 update.nodes.push_back(list_item_3); | 184 update.nodes.push_back(list_item_3); |
| 174 update.nodes.push_back(button); | 185 update.nodes.push_back(button); |
| 175 | 186 |
| 176 EXPECT_EQ( | 187 EXPECT_EQ( |
| 177 "id=3 list (0, 0)-(0, 0) child_ids=4,5,6\n" | 188 "id=3 list (0, 0)-(0, 0) child_ids=4,5,6\n" |
| 178 " id=5 listItem (0, 0)-(0, 0)\n" | 189 " id=5 listItem (0, 0)-(0, 0)\n" |
| 179 " id=6 listItem (0, 0)-(0, 0)\n" | 190 " id=6 listItem (0, 0)-(0, 0)\n" |
| 180 "id=7 button (0, 0)-(0, 0)\n", | 191 "id=7 button (0, 0)-(0, 0)\n", |
| 181 update.ToString()); | 192 update.ToString()); |
| 182 } | 193 } |
| 183 | 194 |
| 184 TEST(AXTreeTest, DeleteUnknownSubtreeFails) { | 195 TEST(AXTreeTest, DeleteUnknownSubtreeFails) { |
| 185 AXNodeData root; | 196 AXNodeData root; |
| 186 root.id = 1; | 197 root.id = 1; |
| 187 root.role = AX_ROLE_ROOT_WEB_AREA; | 198 root.role = AX_ROLE_ROOT_WEB_AREA; |
| 188 | 199 |
| 189 AXTreeUpdate<AXNodeData> initial_state; | 200 AXTreeUpdate initial_state; |
| 190 initial_state.nodes.push_back(root); | 201 initial_state.nodes.push_back(root); |
| 191 AXTree tree(initial_state); | 202 AXTree tree(initial_state); |
| 192 | 203 |
| 193 // This should fail because we're asking it to delete | 204 // This should fail because we're asking it to delete |
| 194 // a subtree rooted at id=2, which doesn't exist. | 205 // a subtree rooted at id=2, which doesn't exist. |
| 195 AXTreeUpdate<AXNodeData> update; | 206 AXTreeUpdate update; |
| 196 update.node_id_to_clear = 2; | 207 update.node_id_to_clear = 2; |
| 197 update.nodes.resize(1); | 208 update.nodes.resize(1); |
| 198 update.nodes[0].id = 1; | 209 update.nodes[0].id = 1; |
| 199 update.nodes[0].id = AX_ROLE_ROOT_WEB_AREA; | 210 update.nodes[0].id = AX_ROLE_ROOT_WEB_AREA; |
| 200 EXPECT_FALSE(tree.Unserialize(update)); | 211 EXPECT_FALSE(tree.Unserialize(update)); |
| 201 ASSERT_EQ("Bad node_id_to_clear: 2", tree.error()); | 212 ASSERT_EQ("Bad node_id_to_clear: 2", tree.error()); |
| 202 } | 213 } |
| 203 | 214 |
| 204 TEST(AXTreeTest, LeaveOrphanedDeletedSubtreeFails) { | 215 TEST(AXTreeTest, LeaveOrphanedDeletedSubtreeFails) { |
| 205 AXTreeUpdate<AXNodeData> initial_state; | 216 AXTreeUpdate initial_state; |
| 206 initial_state.nodes.resize(3); | 217 initial_state.nodes.resize(3); |
| 207 initial_state.nodes[0].id = 1; | 218 initial_state.nodes[0].id = 1; |
| 208 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 219 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 209 initial_state.nodes[0].child_ids.push_back(2); | 220 initial_state.nodes[0].child_ids.push_back(2); |
| 210 initial_state.nodes[0].child_ids.push_back(3); | 221 initial_state.nodes[0].child_ids.push_back(3); |
| 211 initial_state.nodes[1].id = 2; | 222 initial_state.nodes[1].id = 2; |
| 212 initial_state.nodes[2].id = 3; | 223 initial_state.nodes[2].id = 3; |
| 213 AXTree tree(initial_state); | 224 AXTree tree(initial_state); |
| 214 | 225 |
| 215 // This should fail because we delete a subtree rooted at id=2 | 226 // This should fail because we delete a subtree rooted at id=2 |
| 216 // but never update it. | 227 // but never update it. |
| 217 AXTreeUpdate<AXNodeData> update; | 228 AXTreeUpdate update; |
| 218 update.node_id_to_clear = 2; | 229 update.node_id_to_clear = 2; |
| 219 update.nodes.resize(1); | 230 update.nodes.resize(1); |
| 220 update.nodes[0].id = 3; | 231 update.nodes[0].id = 3; |
| 221 EXPECT_FALSE(tree.Unserialize(update)); | 232 EXPECT_FALSE(tree.Unserialize(update)); |
| 222 ASSERT_EQ("Nodes left pending by the update: 2", tree.error()); | 233 ASSERT_EQ("Nodes left pending by the update: 2", tree.error()); |
| 223 } | 234 } |
| 224 | 235 |
| 225 TEST(AXTreeTest, LeaveOrphanedNewChildFails) { | 236 TEST(AXTreeTest, LeaveOrphanedNewChildFails) { |
| 226 AXTreeUpdate<AXNodeData> initial_state; | 237 AXTreeUpdate initial_state; |
| 227 initial_state.nodes.resize(1); | 238 initial_state.nodes.resize(1); |
| 228 initial_state.nodes[0].id = 1; | 239 initial_state.nodes[0].id = 1; |
| 229 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 240 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 230 AXTree tree(initial_state); | 241 AXTree tree(initial_state); |
| 231 | 242 |
| 232 // This should fail because we add a new child to the root node | 243 // This should fail because we add a new child to the root node |
| 233 // but never update it. | 244 // but never update it. |
| 234 AXTreeUpdate<AXNodeData> update; | 245 AXTreeUpdate update; |
| 235 update.nodes.resize(1); | 246 update.nodes.resize(1); |
| 236 update.nodes[0].id = 1; | 247 update.nodes[0].id = 1; |
| 237 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 248 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 238 update.nodes[0].child_ids.push_back(2); | 249 update.nodes[0].child_ids.push_back(2); |
| 239 EXPECT_FALSE(tree.Unserialize(update)); | 250 EXPECT_FALSE(tree.Unserialize(update)); |
| 240 ASSERT_EQ("Nodes left pending by the update: 2", tree.error()); | 251 ASSERT_EQ("Nodes left pending by the update: 2", tree.error()); |
| 241 } | 252 } |
| 242 | 253 |
| 243 TEST(AXTreeTest, DuplicateChildIdFails) { | 254 TEST(AXTreeTest, DuplicateChildIdFails) { |
| 244 AXTreeUpdate<AXNodeData> initial_state; | 255 AXTreeUpdate initial_state; |
| 245 initial_state.nodes.resize(1); | 256 initial_state.nodes.resize(1); |
| 246 initial_state.nodes[0].id = 1; | 257 initial_state.nodes[0].id = 1; |
| 247 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 258 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 248 AXTree tree(initial_state); | 259 AXTree tree(initial_state); |
| 249 | 260 |
| 250 // This should fail because a child id appears twice. | 261 // This should fail because a child id appears twice. |
| 251 AXTreeUpdate<AXNodeData> update; | 262 AXTreeUpdate update; |
| 252 update.nodes.resize(2); | 263 update.nodes.resize(2); |
| 253 update.nodes[0].id = 1; | 264 update.nodes[0].id = 1; |
| 254 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 265 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 255 update.nodes[0].child_ids.push_back(2); | 266 update.nodes[0].child_ids.push_back(2); |
| 256 update.nodes[0].child_ids.push_back(2); | 267 update.nodes[0].child_ids.push_back(2); |
| 257 update.nodes[1].id = 2; | 268 update.nodes[1].id = 2; |
| 258 EXPECT_FALSE(tree.Unserialize(update)); | 269 EXPECT_FALSE(tree.Unserialize(update)); |
| 259 ASSERT_EQ("Node 1 has duplicate child id 2", tree.error()); | 270 ASSERT_EQ("Node 1 has duplicate child id 2", tree.error()); |
| 260 } | 271 } |
| 261 | 272 |
| 262 TEST(AXTreeTest, InvalidReparentingFails) { | 273 TEST(AXTreeTest, InvalidReparentingFails) { |
| 263 AXTreeUpdate<AXNodeData> initial_state; | 274 AXTreeUpdate initial_state; |
| 264 initial_state.nodes.resize(3); | 275 initial_state.nodes.resize(3); |
| 265 initial_state.nodes[0].id = 1; | 276 initial_state.nodes[0].id = 1; |
| 266 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 277 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 267 initial_state.nodes[0].child_ids.push_back(2); | 278 initial_state.nodes[0].child_ids.push_back(2); |
| 268 initial_state.nodes[1].id = 2; | 279 initial_state.nodes[1].id = 2; |
| 269 initial_state.nodes[1].child_ids.push_back(3); | 280 initial_state.nodes[1].child_ids.push_back(3); |
| 270 initial_state.nodes[2].id = 3; | 281 initial_state.nodes[2].id = 3; |
| 271 | 282 |
| 272 AXTree tree(initial_state); | 283 AXTree tree(initial_state); |
| 273 | 284 |
| 274 // This should fail because node 3 is reparented from node 2 to node 1 | 285 // This should fail because node 3 is reparented from node 2 to node 1 |
| 275 // without deleting node 1's subtree first. | 286 // without deleting node 1's subtree first. |
| 276 AXTreeUpdate<AXNodeData> update; | 287 AXTreeUpdate update; |
| 277 update.nodes.resize(3); | 288 update.nodes.resize(3); |
| 278 update.nodes[0].id = 1; | 289 update.nodes[0].id = 1; |
| 279 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 290 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 280 update.nodes[0].child_ids.push_back(3); | 291 update.nodes[0].child_ids.push_back(3); |
| 281 update.nodes[0].child_ids.push_back(2); | 292 update.nodes[0].child_ids.push_back(2); |
| 282 update.nodes[1].id = 2; | 293 update.nodes[1].id = 2; |
| 283 update.nodes[2].id = 3; | 294 update.nodes[2].id = 3; |
| 284 EXPECT_FALSE(tree.Unserialize(update)); | 295 EXPECT_FALSE(tree.Unserialize(update)); |
| 285 ASSERT_EQ("Node 3 reparented from 2 to 1", tree.error()); | 296 ASSERT_EQ("Node 3 reparented from 2 to 1", tree.error()); |
| 286 } | 297 } |
| 287 | 298 |
| 288 TEST(AXTreeTest, TwoRootsFails) { | 299 TEST(AXTreeTest, TwoRootsFails) { |
| 289 AXTreeUpdate<AXNodeData> initial_state; | 300 AXTreeUpdate initial_state; |
| 290 initial_state.nodes.resize(1); | 301 initial_state.nodes.resize(1); |
| 291 initial_state.nodes[0].id = 1; | 302 initial_state.nodes[0].id = 1; |
| 292 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 303 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 293 AXTree tree(initial_state); | 304 AXTree tree(initial_state); |
| 294 | 305 |
| 295 // This should fail because there are two new roots. | 306 // This should fail because there are two new roots. |
| 296 AXTreeUpdate<AXNodeData> update; | 307 AXTreeUpdate update; |
| 297 update.nodes.resize(2); | 308 update.nodes.resize(2); |
| 298 update.nodes[0].id = 2; | 309 update.nodes[0].id = 2; |
| 299 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 310 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 300 update.nodes[1].id = 3; | 311 update.nodes[1].id = 3; |
| 301 update.nodes[1].role = AX_ROLE_ROOT_WEB_AREA; | 312 update.nodes[1].role = AX_ROLE_ROOT_WEB_AREA; |
| 302 EXPECT_FALSE(tree.Unserialize(update)); | 313 EXPECT_FALSE(tree.Unserialize(update)); |
| 303 ASSERT_EQ("Tree update contains two new roots", tree.error()); | 314 ASSERT_EQ("Tree update contains two new roots", tree.error()); |
| 304 } | 315 } |
| 305 | 316 |
| 306 TEST(AXTreeTest, TreeDelegateIsCalled) { | 317 TEST(AXTreeTest, TreeDelegateIsCalled) { |
| 307 AXTreeUpdate<AXNodeData> initial_state; | 318 AXTreeUpdate initial_state; |
| 308 initial_state.nodes.resize(2); | 319 initial_state.nodes.resize(2); |
| 309 initial_state.nodes[0].id = 1; | 320 initial_state.nodes[0].id = 1; |
| 310 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 321 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 311 initial_state.nodes[0].child_ids.push_back(2); | 322 initial_state.nodes[0].child_ids.push_back(2); |
| 312 initial_state.nodes[1].id = 2; | 323 initial_state.nodes[1].id = 2; |
| 313 | 324 |
| 314 AXTree tree(initial_state); | 325 AXTree tree(initial_state); |
| 315 AXTreeUpdate<AXNodeData> update; | 326 AXTreeUpdate update; |
| 316 update.node_id_to_clear = 1; | 327 update.node_id_to_clear = 1; |
| 317 update.nodes.resize(2); | 328 update.nodes.resize(2); |
| 318 update.nodes[0].id = 3; | 329 update.nodes[0].id = 3; |
| 319 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; | 330 update.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 320 update.nodes[0].child_ids.push_back(4); | 331 update.nodes[0].child_ids.push_back(4); |
| 321 update.nodes[1].id = 4; | 332 update.nodes[1].id = 4; |
| 322 | 333 |
| 323 FakeAXTreeDelegate fake_delegate; | 334 FakeAXTreeDelegate fake_delegate; |
| 324 tree.SetDelegate(&fake_delegate); | 335 tree.SetDelegate(&fake_delegate); |
| 325 | 336 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 340 EXPECT_EQ(3, fake_delegate.subtree_creation_finished_ids()[0]); | 351 EXPECT_EQ(3, fake_delegate.subtree_creation_finished_ids()[0]); |
| 341 | 352 |
| 342 ASSERT_EQ(1U, fake_delegate.node_creation_finished_ids().size()); | 353 ASSERT_EQ(1U, fake_delegate.node_creation_finished_ids().size()); |
| 343 EXPECT_EQ(4, fake_delegate.node_creation_finished_ids()[0]); | 354 EXPECT_EQ(4, fake_delegate.node_creation_finished_ids()[0]); |
| 344 | 355 |
| 345 ASSERT_EQ(true, fake_delegate.root_changed()); | 356 ASSERT_EQ(true, fake_delegate.root_changed()); |
| 346 | 357 |
| 347 tree.SetDelegate(NULL); | 358 tree.SetDelegate(NULL); |
| 348 } | 359 } |
| 349 | 360 |
| 361 TEST(AXTreeTest, TreeDelegateIsCalledForTreeDataChanges) { |
| 362 AXTreeUpdate initial_state; |
| 363 initial_state.nodes.resize(1); |
| 364 initial_state.nodes[0].id = 1; |
| 365 initial_state.nodes[0].role = AX_ROLE_ROOT_WEB_AREA; |
| 366 initial_state.has_tree_data = true; |
| 367 initial_state.tree_data.title = "Initial"; |
| 368 AXTree tree(initial_state); |
| 369 |
| 370 FakeAXTreeDelegate fake_delegate; |
| 371 tree.SetDelegate(&fake_delegate); |
| 372 |
| 373 // An empty update shouldn't change tree data. |
| 374 AXTreeUpdate empty_update; |
| 375 EXPECT_TRUE(tree.Unserialize(empty_update)); |
| 376 EXPECT_FALSE(fake_delegate.tree_data_changed()); |
| 377 EXPECT_EQ("Initial", tree.data().title); |
| 378 |
| 379 // An update with tree data shouldn't change tree data if |
| 380 // |has_tree_data| isn't set. |
| 381 AXTreeUpdate ignored_tree_data_update; |
| 382 ignored_tree_data_update.tree_data.title = "Ignore Me"; |
| 383 EXPECT_TRUE(tree.Unserialize(ignored_tree_data_update)); |
| 384 EXPECT_FALSE(fake_delegate.tree_data_changed()); |
| 385 EXPECT_EQ("Initial", tree.data().title); |
| 386 |
| 387 // An update with |has_tree_data| set should update the tree data. |
| 388 AXTreeUpdate tree_data_update; |
| 389 tree_data_update.has_tree_data = true; |
| 390 tree_data_update.tree_data.title = "New Title"; |
| 391 EXPECT_TRUE(tree.Unserialize(tree_data_update)); |
| 392 EXPECT_TRUE(fake_delegate.tree_data_changed()); |
| 393 EXPECT_EQ("New Title", tree.data().title); |
| 394 |
| 395 tree.SetDelegate(NULL); |
| 396 } |
| 397 |
| 350 } // namespace ui | 398 } // namespace ui |
| OLD | NEW |