| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(), | 711 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(), |
| 712 static_text_accessible->GetLocalBoundsForRange(0, 13).ToString()); | 712 static_text_accessible->GetLocalBoundsForRange(0, 13).ToString()); |
| 713 | 713 |
| 714 // Note that each child in the parent element is represented by a single | 714 // Note that each child in the parent element is represented by a single |
| 715 // embedded object character and not by its text. | 715 // embedded object character and not by its text. |
| 716 // TODO(nektar): Investigate failure on Linux. | 716 // TODO(nektar): Investigate failure on Linux. |
| 717 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(), | 717 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(), |
| 718 root_accessible->GetLocalBoundsForRange(0, 13).ToString()); | 718 root_accessible->GetLocalBoundsForRange(0, 13).ToString()); |
| 719 } | 719 } |
| 720 | 720 |
| 721 TEST(BrowserAccessibilityManagerTest, BoundsForRangeMultiElement) { |
| 722 ui::AXNodeData root; |
| 723 root.id = 1; |
| 724 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 725 |
| 726 ui::AXNodeData static_text; |
| 727 static_text.id = 2; |
| 728 static_text.SetName("ABC"); |
| 729 static_text.role = ui::AX_ROLE_STATIC_TEXT; |
| 730 static_text.location = gfx::RectF(0, 20, 33, 9); |
| 731 root.child_ids.push_back(2); |
| 732 |
| 733 ui::AXNodeData inline_text1; |
| 734 inline_text1.id = 3; |
| 735 inline_text1.SetName("ABC"); |
| 736 inline_text1.role = ui::AX_ROLE_INLINE_TEXT_BOX; |
| 737 inline_text1.location = gfx::RectF(0, 20, 33, 9); |
| 738 inline_text1.AddIntAttribute(ui::AX_ATTR_TEXT_DIRECTION, |
| 739 ui::AX_TEXT_DIRECTION_LTR); |
| 740 std::vector<int32_t> character_offsets { 10, 21, 33 }; |
| 741 inline_text1.AddIntListAttribute( |
| 742 ui::AX_ATTR_CHARACTER_OFFSETS, character_offsets); |
| 743 static_text.child_ids.push_back(3); |
| 744 |
| 745 ui::AXNodeData static_text2; |
| 746 static_text2.id = 4; |
| 747 static_text2.SetName("ABC"); |
| 748 static_text2.role = ui::AX_ROLE_STATIC_TEXT; |
| 749 static_text2.location = gfx::RectF(10, 40, 33, 9); |
| 750 root.child_ids.push_back(4); |
| 751 |
| 752 ui::AXNodeData inline_text2; |
| 753 inline_text2.id = 5; |
| 754 inline_text2.SetName("ABC"); |
| 755 inline_text2.role = ui::AX_ROLE_INLINE_TEXT_BOX; |
| 756 inline_text2.location = gfx::RectF(10, 40, 33, 9); |
| 757 inline_text2.AddIntAttribute(ui::AX_ATTR_TEXT_DIRECTION, |
| 758 ui::AX_TEXT_DIRECTION_LTR); |
| 759 inline_text2.AddIntListAttribute( |
| 760 ui::AX_ATTR_CHARACTER_OFFSETS, character_offsets); |
| 761 static_text2.child_ids.push_back(5); |
| 762 |
| 763 std::unique_ptr<BrowserAccessibilityManager> manager( |
| 764 BrowserAccessibilityManager::Create( |
| 765 MakeAXTreeUpdate( |
| 766 root, static_text, inline_text1, static_text2, inline_text2), |
| 767 nullptr, new CountedBrowserAccessibilityFactory())); |
| 768 |
| 769 BrowserAccessibility* root_accessible = manager->GetRoot(); |
| 770 ASSERT_NE(nullptr, root_accessible); |
| 771 BrowserAccessibility* static_text_accessible = |
| 772 root_accessible->PlatformGetChild(0); |
| 773 ASSERT_NE(nullptr, static_text_accessible); |
| 774 BrowserAccessibility* static_text_accessible2 = |
| 775 root_accessible->PlatformGetChild(1); |
| 776 ASSERT_NE(nullptr, static_text_accessible); |
| 777 |
| 778 // The first line. |
| 779 EXPECT_EQ(gfx::Rect(0, 20, 33, 9).ToString(), |
| 780 manager->GetLocalBoundsForRange( |
| 781 *static_text_accessible, 0, |
| 782 *static_text_accessible, 3).ToString()); |
| 783 |
| 784 // Part of the first line. |
| 785 EXPECT_EQ(gfx::Rect(0, 20, 21, 9).ToString(), |
| 786 manager->GetLocalBoundsForRange( |
| 787 *static_text_accessible, 0, |
| 788 *static_text_accessible, 2).ToString()); |
| 789 |
| 790 // Part of the first line. |
| 791 EXPECT_EQ(gfx::Rect(10, 20, 23, 9).ToString(), |
| 792 manager->GetLocalBoundsForRange( |
| 793 *static_text_accessible, 1, |
| 794 *static_text_accessible, 3).ToString()); |
| 795 |
| 796 // The second line. |
| 797 EXPECT_EQ(gfx::Rect(10, 40, 33, 9).ToString(), |
| 798 manager->GetLocalBoundsForRange( |
| 799 *static_text_accessible2, 0, |
| 800 *static_text_accessible2, 3).ToString()); |
| 801 |
| 802 // All of both lines. |
| 803 EXPECT_EQ(gfx::Rect(0, 20, 43, 29).ToString(), |
| 804 manager->GetLocalBoundsForRange( |
| 805 *static_text_accessible, 0, |
| 806 *static_text_accessible2, 3).ToString()); |
| 807 |
| 808 // Part of both lines. |
| 809 EXPECT_EQ(gfx::Rect(10, 20, 23, 29).ToString(), |
| 810 manager->GetLocalBoundsForRange( |
| 811 *static_text_accessible, 2, |
| 812 *static_text_accessible2, 1).ToString()); |
| 813 |
| 814 // Part of both lines in reverse order. |
| 815 EXPECT_EQ(gfx::Rect(10, 20, 23, 29).ToString(), |
| 816 manager->GetLocalBoundsForRange( |
| 817 *static_text_accessible2, 1, |
| 818 *static_text_accessible, 2).ToString()); |
| 819 } |
| 820 |
| 721 TEST(BrowserAccessibilityManagerTest, BoundsForRangeBiDi) { | 821 TEST(BrowserAccessibilityManagerTest, BoundsForRangeBiDi) { |
| 722 // In this example, we assume that the string "123abc" is rendered with | 822 // In this example, we assume that the string "123abc" is rendered with |
| 723 // "123" going left-to-right and "abc" going right-to-left. In other | 823 // "123" going left-to-right and "abc" going right-to-left. In other |
| 724 // words, on-screen it would look like "123cba". This is possible to | 824 // words, on-screen it would look like "123cba". This is possible to |
| 725 // achieve if the source string had unicode control characters | 825 // achieve if the source string had unicode control characters |
| 726 // to switch directions. This test doesn't worry about how, though - it just | 826 // to switch directions. This test doesn't worry about how, though - it just |
| 727 // tests that if something like that were to occur, GetLocalBoundsForRange | 827 // tests that if something like that were to occur, GetLocalBoundsForRange |
| 728 // returns the correct bounds for different ranges. | 828 // returns the correct bounds for different ranges. |
| 729 | 829 |
| 730 ui::AXNodeData root; | 830 ui::AXNodeData root; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 EXPECT_EQ(node3_accessible, manager->NextInTreeOrder(node2_accessible)); | 1083 EXPECT_EQ(node3_accessible, manager->NextInTreeOrder(node2_accessible)); |
| 984 EXPECT_EQ(node4_accessible, manager->NextInTreeOrder(node3_accessible)); | 1084 EXPECT_EQ(node4_accessible, manager->NextInTreeOrder(node3_accessible)); |
| 985 EXPECT_EQ(node5_accessible, manager->NextInTreeOrder(node4_accessible)); | 1085 EXPECT_EQ(node5_accessible, manager->NextInTreeOrder(node4_accessible)); |
| 986 EXPECT_EQ(nullptr, manager->NextInTreeOrder(node5_accessible)); | 1086 EXPECT_EQ(nullptr, manager->NextInTreeOrder(node5_accessible)); |
| 987 | 1087 |
| 988 EXPECT_EQ(nullptr, manager->PreviousInTreeOrder(nullptr)); | 1088 EXPECT_EQ(nullptr, manager->PreviousInTreeOrder(nullptr)); |
| 989 EXPECT_EQ(node4_accessible, manager->PreviousInTreeOrder(node5_accessible)); | 1089 EXPECT_EQ(node4_accessible, manager->PreviousInTreeOrder(node5_accessible)); |
| 990 EXPECT_EQ(node3_accessible, manager->PreviousInTreeOrder(node4_accessible)); | 1090 EXPECT_EQ(node3_accessible, manager->PreviousInTreeOrder(node4_accessible)); |
| 991 EXPECT_EQ(node2_accessible, manager->PreviousInTreeOrder(node3_accessible)); | 1091 EXPECT_EQ(node2_accessible, manager->PreviousInTreeOrder(node3_accessible)); |
| 992 EXPECT_EQ(root_accessible, manager->PreviousInTreeOrder(node2_accessible)); | 1092 EXPECT_EQ(root_accessible, manager->PreviousInTreeOrder(node2_accessible)); |
| 1093 |
| 1094 EXPECT_EQ(ui::AX_TREE_ORDER_EQUAL, |
| 1095 BrowserAccessibilityManager::CompareNodes( |
| 1096 *root_accessible, *root_accessible)); |
| 1097 |
| 1098 EXPECT_EQ(ui::AX_TREE_ORDER_BEFORE, |
| 1099 BrowserAccessibilityManager::CompareNodes( |
| 1100 *node2_accessible, *node3_accessible)); |
| 1101 EXPECT_EQ(ui::AX_TREE_ORDER_AFTER, |
| 1102 BrowserAccessibilityManager::CompareNodes( |
| 1103 *node3_accessible, *node2_accessible)); |
| 1104 |
| 1105 EXPECT_EQ(ui::AX_TREE_ORDER_BEFORE, |
| 1106 BrowserAccessibilityManager::CompareNodes( |
| 1107 *node2_accessible, *node4_accessible)); |
| 1108 EXPECT_EQ(ui::AX_TREE_ORDER_AFTER, |
| 1109 BrowserAccessibilityManager::CompareNodes( |
| 1110 *node4_accessible, *node2_accessible)); |
| 1111 |
| 1112 EXPECT_EQ(ui::AX_TREE_ORDER_BEFORE, |
| 1113 BrowserAccessibilityManager::CompareNodes( |
| 1114 *node3_accessible, *node4_accessible)); |
| 1115 EXPECT_EQ(ui::AX_TREE_ORDER_AFTER, |
| 1116 BrowserAccessibilityManager::CompareNodes( |
| 1117 *node4_accessible, *node3_accessible)); |
| 1118 |
| 1119 EXPECT_EQ(ui::AX_TREE_ORDER_BEFORE, |
| 1120 BrowserAccessibilityManager::CompareNodes( |
| 1121 *root_accessible, *node2_accessible)); |
| 1122 EXPECT_EQ(ui::AX_TREE_ORDER_AFTER, |
| 1123 BrowserAccessibilityManager::CompareNodes( |
| 1124 *node2_accessible, *root_accessible)); |
| 993 } | 1125 } |
| 994 | 1126 |
| 995 TEST(BrowserAccessibilityManagerTest, TestNextPreviousTextOnlyObject) { | 1127 TEST(BrowserAccessibilityManagerTest, TestNextPreviousTextOnlyObject) { |
| 996 ui::AXNodeData root; | 1128 ui::AXNodeData root; |
| 997 root.id = 1; | 1129 root.id = 1; |
| 998 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1130 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 999 | 1131 |
| 1000 ui::AXNodeData node2; | 1132 ui::AXNodeData node2; |
| 1001 node2.id = 2; | 1133 node2.id = 2; |
| 1002 root.child_ids.push_back(2); | 1134 root.child_ids.push_back(2); |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 4, ui::FORWARDS_DIRECTION, ui::AX_TEXT_AFFINITY_DOWNSTREAM)); | 1667 4, ui::FORWARDS_DIRECTION, ui::AX_TEXT_AFFINITY_DOWNSTREAM)); |
| 1536 | 1668 |
| 1537 // If the affinity is upstream, check that we get the second line. | 1669 // If the affinity is upstream, check that we get the second line. |
| 1538 ASSERT_EQ(0, static_text_accessible->GetLineStartBoundary( | 1670 ASSERT_EQ(0, static_text_accessible->GetLineStartBoundary( |
| 1539 4, ui::BACKWARDS_DIRECTION, ui::AX_TEXT_AFFINITY_UPSTREAM)); | 1671 4, ui::BACKWARDS_DIRECTION, ui::AX_TEXT_AFFINITY_UPSTREAM)); |
| 1540 ASSERT_EQ(4, static_text_accessible->GetLineStartBoundary( | 1672 ASSERT_EQ(4, static_text_accessible->GetLineStartBoundary( |
| 1541 4, ui::FORWARDS_DIRECTION, ui::AX_TEXT_AFFINITY_UPSTREAM)); | 1673 4, ui::FORWARDS_DIRECTION, ui::AX_TEXT_AFFINITY_UPSTREAM)); |
| 1542 } | 1674 } |
| 1543 | 1675 |
| 1544 } // namespace content | 1676 } // namespace content |
| OLD | NEW |