| 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 "ui/accessibility/ax_tree.h" | 5 #include "ui/accessibility/ax_tree.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 std::vector<int32_t> node_reparented_finished_ids_; | 203 std::vector<int32_t> node_reparented_finished_ids_; |
| 204 std::vector<int32_t> subtree_reparented_finished_ids_; | 204 std::vector<int32_t> subtree_reparented_finished_ids_; |
| 205 std::vector<int32_t> change_finished_ids_; | 205 std::vector<int32_t> change_finished_ids_; |
| 206 std::vector<std::string> attribute_change_log_; | 206 std::vector<std::string> attribute_change_log_; |
| 207 }; | 207 }; |
| 208 | 208 |
| 209 } // namespace | 209 } // namespace |
| 210 | 210 |
| 211 TEST(AXTreeTest, SerializeSimpleAXTree) { | 211 TEST(AXTreeTest, SerializeSimpleAXTree) { |
| 212 AXNodeData root; | 212 AXNodeData root; |
| 213 root.ClearBitfields(); |
| 213 root.id = 1; | 214 root.id = 1; |
| 214 root.role = AX_ROLE_DIALOG; | 215 root.role = AX_ROLE_DIALOG; |
| 215 root.state = 1 << AX_STATE_FOCUSABLE; | 216 root.AddState(AX_STATE_FOCUSABLE); |
| 216 root.location = gfx::RectF(0, 0, 800, 600); | 217 root.location = gfx::RectF(0, 0, 800, 600); |
| 217 root.child_ids.push_back(2); | 218 root.child_ids.push_back(2); |
| 218 root.child_ids.push_back(3); | 219 root.child_ids.push_back(3); |
| 219 | 220 |
| 220 AXNodeData button; | 221 AXNodeData button; |
| 222 button.ClearBitfields(); |
| 221 button.id = 2; | 223 button.id = 2; |
| 222 button.role = AX_ROLE_BUTTON; | 224 button.role = AX_ROLE_BUTTON; |
| 223 button.state = 0; | |
| 224 button.location = gfx::RectF(20, 20, 200, 30); | 225 button.location = gfx::RectF(20, 20, 200, 30); |
| 225 | 226 |
| 226 AXNodeData checkbox; | 227 AXNodeData checkbox; |
| 228 checkbox.ClearBitfields(); |
| 227 checkbox.id = 3; | 229 checkbox.id = 3; |
| 228 checkbox.role = AX_ROLE_CHECK_BOX; | 230 checkbox.role = AX_ROLE_CHECK_BOX; |
| 229 checkbox.state = 0; | |
| 230 checkbox.location = gfx::RectF(20, 50, 200, 30); | 231 checkbox.location = gfx::RectF(20, 50, 200, 30); |
| 231 | 232 |
| 232 AXTreeUpdate initial_state; | 233 AXTreeUpdate initial_state; |
| 233 initial_state.root_id = 1; | 234 initial_state.root_id = 1; |
| 234 initial_state.nodes.push_back(root); | 235 initial_state.nodes.push_back(root); |
| 235 initial_state.nodes.push_back(button); | 236 initial_state.nodes.push_back(button); |
| 236 initial_state.nodes.push_back(checkbox); | 237 initial_state.nodes.push_back(checkbox); |
| 237 initial_state.has_tree_data = true; | 238 initial_state.has_tree_data = true; |
| 238 initial_state.tree_data.title = "Title"; | 239 initial_state.tree_data.title = "Title"; |
| 239 AXSerializableTree src_tree(initial_state); | 240 AXSerializableTree src_tree(initial_state); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 266 EXPECT_EQ( | 267 EXPECT_EQ( |
| 267 "AXTree title=Title\n" | 268 "AXTree title=Title\n" |
| 268 "id=1 dialog FOCUSABLE (0, 0)-(800, 600) child_ids=2,3\n" | 269 "id=1 dialog FOCUSABLE (0, 0)-(800, 600) child_ids=2,3\n" |
| 269 " id=2 button (20, 20)-(200, 30)\n" | 270 " id=2 button (20, 20)-(200, 30)\n" |
| 270 " id=3 checkBox (20, 50)-(200, 30)\n", | 271 " id=3 checkBox (20, 50)-(200, 30)\n", |
| 271 dst_tree.ToString()); | 272 dst_tree.ToString()); |
| 272 } | 273 } |
| 273 | 274 |
| 274 TEST(AXTreeTest, SerializeAXTreeUpdate) { | 275 TEST(AXTreeTest, SerializeAXTreeUpdate) { |
| 275 AXNodeData list; | 276 AXNodeData list; |
| 277 list.ClearBitfields(); |
| 276 list.id = 3; | 278 list.id = 3; |
| 277 list.role = AX_ROLE_LIST; | 279 list.role = AX_ROLE_LIST; |
| 278 list.state = 0; | |
| 279 list.child_ids.push_back(4); | 280 list.child_ids.push_back(4); |
| 280 list.child_ids.push_back(5); | 281 list.child_ids.push_back(5); |
| 281 list.child_ids.push_back(6); | 282 list.child_ids.push_back(6); |
| 282 | 283 |
| 283 AXNodeData list_item_2; | 284 AXNodeData list_item_2; |
| 285 list_item_2.ClearBitfields(); |
| 284 list_item_2.id = 5; | 286 list_item_2.id = 5; |
| 285 list_item_2.role = AX_ROLE_LIST_ITEM; | 287 list_item_2.role = AX_ROLE_LIST_ITEM; |
| 286 list_item_2.state = 0; | |
| 287 | 288 |
| 288 AXNodeData list_item_3; | 289 AXNodeData list_item_3; |
| 290 list_item_3.ClearBitfields(); |
| 289 list_item_3.id = 6; | 291 list_item_3.id = 6; |
| 290 list_item_3.role = AX_ROLE_LIST_ITEM; | 292 list_item_3.role = AX_ROLE_LIST_ITEM; |
| 291 list_item_3.state = 0; | |
| 292 | 293 |
| 293 AXNodeData button; | 294 AXNodeData button; |
| 295 button.ClearBitfields(); |
| 294 button.id = 7; | 296 button.id = 7; |
| 295 button.role = AX_ROLE_BUTTON; | 297 button.role = AX_ROLE_BUTTON; |
| 296 button.state = 0; | |
| 297 | 298 |
| 298 AXTreeUpdate update; | 299 AXTreeUpdate update; |
| 299 update.root_id = 3; | 300 update.root_id = 3; |
| 300 update.nodes.push_back(list); | 301 update.nodes.push_back(list); |
| 301 update.nodes.push_back(list_item_2); | 302 update.nodes.push_back(list_item_2); |
| 302 update.nodes.push_back(list_item_3); | 303 update.nodes.push_back(list_item_3); |
| 303 update.nodes.push_back(button); | 304 update.nodes.push_back(button); |
| 304 | 305 |
| 305 EXPECT_EQ( | 306 EXPECT_EQ( |
| 306 "AXTreeUpdate: root id 3\n" | 307 "AXTreeUpdate: root id 3\n" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 | 569 |
| 569 ASSERT_EQ(true, fake_delegate.root_changed()); | 570 ASSERT_EQ(true, fake_delegate.root_changed()); |
| 570 | 571 |
| 571 tree.SetDelegate(NULL); | 572 tree.SetDelegate(NULL); |
| 572 } | 573 } |
| 573 | 574 |
| 574 // UAF caught by ax_tree_fuzzer | 575 // UAF caught by ax_tree_fuzzer |
| 575 TEST(AXTreeTest, BogusAXTree) { | 576 TEST(AXTreeTest, BogusAXTree) { |
| 576 AXTreeUpdate initial_state; | 577 AXTreeUpdate initial_state; |
| 577 AXNodeData node; | 578 AXNodeData node; |
| 579 node.ClearBitfields(); |
| 578 node.id = 0; | 580 node.id = 0; |
| 579 node.state = 0; | |
| 580 initial_state.nodes.push_back(node); | 581 initial_state.nodes.push_back(node); |
| 581 initial_state.nodes.push_back(node); | 582 initial_state.nodes.push_back(node); |
| 582 ui::AXTree tree; | 583 ui::AXTree tree; |
| 583 tree.Unserialize(initial_state); | 584 tree.Unserialize(initial_state); |
| 584 } | 585 } |
| 585 | 586 |
| 586 // UAF caught by ax_tree_fuzzer | 587 // UAF caught by ax_tree_fuzzer |
| 587 TEST(AXTreeTest, BogusAXTree2) { | 588 TEST(AXTreeTest, BogusAXTree2) { |
| 588 AXTreeUpdate initial_state; | 589 AXTreeUpdate initial_state; |
| 589 AXNodeData node; | 590 AXNodeData node; |
| 591 node.ClearBitfields(); |
| 590 node.id = 0; | 592 node.id = 0; |
| 591 node.state = 0; | |
| 592 initial_state.nodes.push_back(node); | 593 initial_state.nodes.push_back(node); |
| 593 AXNodeData node2; | 594 AXNodeData node2; |
| 595 node2.ClearBitfields(); |
| 594 node2.id = 0; | 596 node2.id = 0; |
| 595 node2.state = 0; | |
| 596 node2.child_ids.push_back(0); | 597 node2.child_ids.push_back(0); |
| 597 node2.child_ids.push_back(0); | 598 node2.child_ids.push_back(0); |
| 598 initial_state.nodes.push_back(node2); | 599 initial_state.nodes.push_back(node2); |
| 599 ui::AXTree tree; | 600 ui::AXTree tree; |
| 600 tree.Unserialize(initial_state); | 601 tree.Unserialize(initial_state); |
| 601 } | 602 } |
| 602 | 603 |
| 603 // UAF caught by ax_tree_fuzzer | 604 // UAF caught by ax_tree_fuzzer |
| 604 TEST(AXTreeTest, BogusAXTree3) { | 605 TEST(AXTreeTest, BogusAXTree3) { |
| 605 AXTreeUpdate initial_state; | 606 AXTreeUpdate initial_state; |
| 606 AXNodeData node; | 607 AXNodeData node; |
| 608 node.ClearBitfields(); |
| 607 node.id = 0; | 609 node.id = 0; |
| 608 node.state = 0; | |
| 609 node.child_ids.push_back(1); | 610 node.child_ids.push_back(1); |
| 610 initial_state.nodes.push_back(node); | 611 initial_state.nodes.push_back(node); |
| 611 | 612 |
| 612 AXNodeData node2; | 613 AXNodeData node2; |
| 614 node2.ClearBitfields(); |
| 613 node2.id = 1; | 615 node2.id = 1; |
| 614 node2.state = 0; | |
| 615 node2.child_ids.push_back(1); | 616 node2.child_ids.push_back(1); |
| 616 node2.child_ids.push_back(1); | 617 node2.child_ids.push_back(1); |
| 617 initial_state.nodes.push_back(node2); | 618 initial_state.nodes.push_back(node2); |
| 618 | 619 |
| 619 ui::AXTree tree; | 620 ui::AXTree tree; |
| 620 tree.Unserialize(initial_state); | 621 tree.Unserialize(initial_state); |
| 621 } | 622 } |
| 622 | 623 |
| 623 TEST(AXTreeTest, RoleAndStateChangeCallbacks) { | 624 TEST(AXTreeTest, RoleAndStateChangeCallbacks) { |
| 624 AXTreeUpdate initial_state; | 625 AXTreeUpdate initial_state; |
| 625 initial_state.root_id = 1; | 626 initial_state.root_id = 1; |
| 626 initial_state.nodes.resize(1); | 627 initial_state.nodes.resize(1); |
| 627 initial_state.nodes[0].id = 1; | 628 initial_state.nodes[0].id = 1; |
| 628 initial_state.nodes[0].role = AX_ROLE_BUTTON; | 629 initial_state.nodes[0].role = AX_ROLE_BUTTON; |
| 629 initial_state.nodes[0].state = 0; | |
| 630 initial_state.nodes[0].AddIntAttribute(ui::AX_ATTR_CHECKED_STATE, | 630 initial_state.nodes[0].AddIntAttribute(ui::AX_ATTR_CHECKED_STATE, |
| 631 ui::AX_CHECKED_STATE_TRUE); | 631 ui::AX_CHECKED_STATE_TRUE); |
| 632 initial_state.nodes[0].AddStateFlag(AX_STATE_FOCUSABLE); | 632 initial_state.nodes[0].ClearBitfields(); |
| 633 initial_state.nodes[0].AddState(AX_STATE_FOCUSABLE); |
| 633 AXTree tree(initial_state); | 634 AXTree tree(initial_state); |
| 634 | 635 |
| 635 FakeAXTreeDelegate fake_delegate; | 636 FakeAXTreeDelegate fake_delegate; |
| 636 tree.SetDelegate(&fake_delegate); | 637 tree.SetDelegate(&fake_delegate); |
| 637 | 638 |
| 638 // Change the role and state. | 639 // Change the role and state. |
| 639 AXTreeUpdate update; | 640 AXTreeUpdate update; |
| 640 update.root_id = 1; | 641 update.root_id = 1; |
| 641 update.nodes.resize(1); | 642 update.nodes.resize(1); |
| 642 update.nodes[0].id = 1; | 643 update.nodes[0].id = 1; |
| 643 update.nodes[0].role = AX_ROLE_CHECK_BOX; | 644 update.nodes[0].role = AX_ROLE_CHECK_BOX; |
| 644 update.nodes[0].state = 0; | |
| 645 update.nodes[0].AddIntAttribute(ui::AX_ATTR_CHECKED_STATE, | 645 update.nodes[0].AddIntAttribute(ui::AX_ATTR_CHECKED_STATE, |
| 646 ui::AX_CHECKED_STATE_FALSE); | 646 ui::AX_CHECKED_STATE_FALSE); |
| 647 update.nodes[0].AddStateFlag(AX_STATE_FOCUSABLE); | 647 update.nodes[0].ClearBitfields(); |
| 648 update.nodes[0].AddStateFlag(AX_STATE_VISITED); | 648 update.nodes[0].AddState(AX_STATE_FOCUSABLE); |
| 649 update.nodes[0].AddState(AX_STATE_VISITED); |
| 649 EXPECT_TRUE(tree.Unserialize(update)); | 650 EXPECT_TRUE(tree.Unserialize(update)); |
| 650 | 651 |
| 651 const std::vector<std::string>& change_log = | 652 const std::vector<std::string>& change_log = |
| 652 fake_delegate.attribute_change_log(); | 653 fake_delegate.attribute_change_log(); |
| 653 ASSERT_EQ(3U, change_log.size()); | 654 ASSERT_EQ(3U, change_log.size()); |
| 654 EXPECT_EQ("Role changed from button to checkBox", change_log[0]); | 655 EXPECT_EQ("Role changed from button to checkBox", change_log[0]); |
| 655 EXPECT_EQ("visited changed to true", change_log[1]); | 656 EXPECT_EQ("visited changed to true", change_log[1]); |
| 656 EXPECT_EQ("checkedState changed from 2 to 1", change_log[2]); | 657 EXPECT_EQ("checkedState changed from 2 to 1", change_log[2]); |
| 657 | 658 |
| 658 tree.SetDelegate(NULL); | 659 tree.SetDelegate(NULL); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 fake_delegate2.attribute_change_log(); | 791 fake_delegate2.attribute_change_log(); |
| 791 ASSERT_EQ(3U, change_log2.size()); | 792 ASSERT_EQ(3U, change_log2.size()); |
| 792 EXPECT_EQ("controlsIds changed from 2,2 to ", change_log2[0]); | 793 EXPECT_EQ("controlsIds changed from 2,2 to ", change_log2[0]); |
| 793 EXPECT_EQ("detailsIds changed from 3 to 2,2", change_log2[1]); | 794 EXPECT_EQ("detailsIds changed from 3 to 2,2", change_log2[1]); |
| 794 EXPECT_EQ("flowtoIds changed from to 3", change_log2[2]); | 795 EXPECT_EQ("flowtoIds changed from to 3", change_log2[2]); |
| 795 | 796 |
| 796 tree.SetDelegate(NULL); | 797 tree.SetDelegate(NULL); |
| 797 } | 798 } |
| 798 | 799 |
| 799 } // namespace ui | 800 } // namespace ui |
| OLD | NEW |