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