Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(582)

Side by Side Diff: content/browser/accessibility/browser_accessibility_manager_unittest.cc

Issue 1598583002: Fixed algorithms that compute bounding rectangles and word start offsets to take into account IA2 h… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a TODO to investigate test failure on Linux. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 ui::AX_ATTR_CHARACTER_OFFSETS, character_offsets2); 679 ui::AX_ATTR_CHARACTER_OFFSETS, character_offsets2);
680 static_text.child_ids.push_back(4); 680 static_text.child_ids.push_back(4);
681 681
682 scoped_ptr<BrowserAccessibilityManager> manager( 682 scoped_ptr<BrowserAccessibilityManager> manager(
683 BrowserAccessibilityManager::Create( 683 BrowserAccessibilityManager::Create(
684 MakeAXTreeUpdate(root, static_text, inline_text1, inline_text2), 684 MakeAXTreeUpdate(root, static_text, inline_text1, inline_text2),
685 nullptr, 685 nullptr,
686 new CountedBrowserAccessibilityFactory())); 686 new CountedBrowserAccessibilityFactory()));
687 687
688 BrowserAccessibility* root_accessible = manager->GetRoot(); 688 BrowserAccessibility* root_accessible = manager->GetRoot();
689 ASSERT_NE(nullptr, root_accessible);
689 BrowserAccessibility* static_text_accessible = 690 BrowserAccessibility* static_text_accessible =
690 root_accessible->PlatformGetChild(0); 691 root_accessible->PlatformGetChild(0);
692 ASSERT_NE(nullptr, static_text_accessible);
691 693
692 EXPECT_EQ(gfx::Rect(100, 100, 6, 9).ToString(), 694 EXPECT_EQ(gfx::Rect(100, 100, 6, 9).ToString(),
693 static_text_accessible->GetLocalBoundsForRange(0, 1).ToString()); 695 static_text_accessible->GetLocalBoundsForRange(0, 1).ToString());
694 696
695 EXPECT_EQ(gfx::Rect(100, 100, 26, 9).ToString(), 697 EXPECT_EQ(gfx::Rect(100, 100, 26, 9).ToString(),
696 static_text_accessible->GetLocalBoundsForRange(0, 5).ToString()); 698 static_text_accessible->GetLocalBoundsForRange(0, 5).ToString());
697 699
698 EXPECT_EQ(gfx::Rect(100, 109, 5, 9).ToString(), 700 EXPECT_EQ(gfx::Rect(100, 109, 5, 9).ToString(),
699 static_text_accessible->GetLocalBoundsForRange(7, 1).ToString()); 701 static_text_accessible->GetLocalBoundsForRange(7, 1).ToString());
700 702
701 EXPECT_EQ(gfx::Rect(100, 109, 25, 9).ToString(), 703 EXPECT_EQ(gfx::Rect(100, 109, 25, 9).ToString(),
702 static_text_accessible->GetLocalBoundsForRange(7, 5).ToString()); 704 static_text_accessible->GetLocalBoundsForRange(7, 5).ToString());
703 705
704 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(), 706 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(),
705 static_text_accessible->GetLocalBoundsForRange(5, 3).ToString()); 707 static_text_accessible->GetLocalBoundsForRange(5, 3).ToString());
706 708
707 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(), 709 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(),
708 static_text_accessible->GetLocalBoundsForRange(0, 13).ToString()); 710 static_text_accessible->GetLocalBoundsForRange(0, 13).ToString());
709 711
710 // Test range that's beyond the text. 712 // Note that each child in the parent element is represented by a single
711 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(), 713 // embedded object character and not by its text.
712 static_text_accessible->GetLocalBoundsForRange(-1, 999).ToString()); 714 // TODO(nektar): Investigate failure on Linux.
713
714 // Test that we can call bounds for range on the parent element, too,
715 // and it still works.
716 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(), 715 EXPECT_EQ(gfx::Rect(100, 100, 29, 18).ToString(),
717 root_accessible->GetLocalBoundsForRange(0, 13).ToString()); 716 root_accessible->GetLocalBoundsForRange(0, 13).ToString());
718 } 717 }
719 718
720 TEST(BrowserAccessibilityManagerTest, BoundsForRangeBiDi) { 719 TEST(BrowserAccessibilityManagerTest, BoundsForRangeBiDi) {
721 // In this example, we assume that the string "123abc" is rendered with 720 // In this example, we assume that the string "123abc" is rendered with
722 // "123" going left-to-right and "abc" going right-to-left. In other 721 // "123" going left-to-right and "abc" going right-to-left. In other
723 // words, on-screen it would look like "123cba". This is possible to 722 // words, on-screen it would look like "123cba". This is possible to
724 // acheive if the source string had unicode control characters 723 // achieve if the source string had unicode control characters
725 // to switch directions. This test doesn't worry about how, though - it just 724 // to switch directions. This test doesn't worry about how, though - it just
726 // tests that if something like that were to occur, GetLocalBoundsForRange 725 // tests that if something like that were to occur, GetLocalBoundsForRange
727 // returns the correct bounds for different ranges. 726 // returns the correct bounds for different ranges.
728 727
729 ui::AXNodeData root; 728 ui::AXNodeData root;
730 root.id = 1; 729 root.id = 1;
731 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 730 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
732 731
733 ui::AXNodeData static_text; 732 ui::AXNodeData static_text;
734 static_text.id = 2; 733 static_text.id = 2;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 ui::AX_ATTR_CHARACTER_OFFSETS, character_offsets2); 766 ui::AX_ATTR_CHARACTER_OFFSETS, character_offsets2);
768 static_text.child_ids.push_back(4); 767 static_text.child_ids.push_back(4);
769 768
770 scoped_ptr<BrowserAccessibilityManager> manager( 769 scoped_ptr<BrowserAccessibilityManager> manager(
771 BrowserAccessibilityManager::Create( 770 BrowserAccessibilityManager::Create(
772 MakeAXTreeUpdate(root, static_text, inline_text1, inline_text2), 771 MakeAXTreeUpdate(root, static_text, inline_text1, inline_text2),
773 nullptr, 772 nullptr,
774 new CountedBrowserAccessibilityFactory())); 773 new CountedBrowserAccessibilityFactory()));
775 774
776 BrowserAccessibility* root_accessible = manager->GetRoot(); 775 BrowserAccessibility* root_accessible = manager->GetRoot();
776 ASSERT_NE(nullptr, root_accessible);
777 BrowserAccessibility* static_text_accessible = 777 BrowserAccessibility* static_text_accessible =
778 root_accessible->PlatformGetChild(0); 778 root_accessible->PlatformGetChild(0);
779 ASSERT_NE(nullptr, static_text_accessible);
779 780
780 EXPECT_EQ(gfx::Rect(100, 100, 60, 20).ToString(), 781 EXPECT_EQ(gfx::Rect(100, 100, 60, 20).ToString(),
781 static_text_accessible->GetLocalBoundsForRange(0, 6).ToString()); 782 static_text_accessible->GetLocalBoundsForRange(0, 6).ToString());
782 783
783 EXPECT_EQ(gfx::Rect(100, 100, 10, 20).ToString(), 784 EXPECT_EQ(gfx::Rect(100, 100, 10, 20).ToString(),
784 static_text_accessible->GetLocalBoundsForRange(0, 1).ToString()); 785 static_text_accessible->GetLocalBoundsForRange(0, 1).ToString());
785 786
786 EXPECT_EQ(gfx::Rect(100, 100, 30, 20).ToString(), 787 EXPECT_EQ(gfx::Rect(100, 100, 30, 20).ToString(),
787 static_text_accessible->GetLocalBoundsForRange(0, 3).ToString()); 788 static_text_accessible->GetLocalBoundsForRange(0, 3).ToString());
788 789
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 ui::AX_ATTR_CHARACTER_OFFSETS, character_offsets1); 828 ui::AX_ATTR_CHARACTER_OFFSETS, character_offsets1);
828 static_text.child_ids.push_back(3); 829 static_text.child_ids.push_back(3);
829 830
830 scoped_ptr<BrowserAccessibilityManager> manager( 831 scoped_ptr<BrowserAccessibilityManager> manager(
831 BrowserAccessibilityManager::Create( 832 BrowserAccessibilityManager::Create(
832 MakeAXTreeUpdate(root, static_text, inline_text), 833 MakeAXTreeUpdate(root, static_text, inline_text),
833 nullptr, 834 nullptr,
834 new CountedBrowserAccessibilityFactory())); 835 new CountedBrowserAccessibilityFactory()));
835 836
836 BrowserAccessibility* root_accessible = manager->GetRoot(); 837 BrowserAccessibility* root_accessible = manager->GetRoot();
838 ASSERT_NE(nullptr, root_accessible);
837 BrowserAccessibility* static_text_accessible = 839 BrowserAccessibility* static_text_accessible =
838 root_accessible->PlatformGetChild(0); 840 root_accessible->PlatformGetChild(0);
841 ASSERT_NE(nullptr, static_text_accessible);
839 842
840 if (manager->UseRootScrollOffsetsWhenComputingBounds()) { 843 if (manager->UseRootScrollOffsetsWhenComputingBounds()) {
841 EXPECT_EQ(gfx::Rect(75, 50, 16, 9).ToString(), 844 EXPECT_EQ(gfx::Rect(75, 50, 16, 9).ToString(),
842 static_text_accessible->GetLocalBoundsForRange(0, 3).ToString()); 845 static_text_accessible->GetLocalBoundsForRange(0, 3).ToString());
843 } else { 846 } else {
844 EXPECT_EQ(gfx::Rect(100, 100, 16, 9).ToString(), 847 EXPECT_EQ(gfx::Rect(100, 100, 16, 9).ToString(),
845 static_text_accessible->GetLocalBoundsForRange(0, 3).ToString()); 848 static_text_accessible->GetLocalBoundsForRange(0, 3).ToString());
846 } 849 }
847 } 850 }
848 851
849 #if defined(OS_WIN) 852 TEST(BrowserAccessibilityManagerTest, BoundsForRangeOnParentElement) {
850 #define MAYBE_BoundsForRangeOnParentElement \
851 DISABLED_BoundsForRangeOnParentElement
852 #else
853 #define MAYBE_BoundsForRangeOnParentElement BoundsForRangeOnParentElement
854 #endif
855 TEST(BrowserAccessibilityManagerTest, MAYBE_BoundsForRangeOnParentElement) {
856 ui::AXNodeData root; 853 ui::AXNodeData root;
857 root.id = 1; 854 root.id = 1;
858 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 855 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
859 root.child_ids.push_back(2); 856 root.child_ids.push_back(2);
860 857
861 ui::AXNodeData div; 858 ui::AXNodeData div;
862 div.id = 2; 859 div.id = 2;
863 div.role = ui::AX_ROLE_DIV; 860 div.role = ui::AX_ROLE_DIV;
864 div.location = gfx::Rect(100, 100, 100, 20); 861 div.location = gfx::Rect(100, 100, 100, 20);
865 div.child_ids.push_back(3); 862 div.child_ids.push_back(3);
866 div.child_ids.push_back(4); 863 div.child_ids.push_back(4);
867 div.child_ids.push_back(5); 864 div.child_ids.push_back(5);
868 865
869 ui::AXNodeData static_text1; 866 ui::AXNodeData static_text1;
870 static_text1.id = 3; 867 static_text1.id = 3;
871 static_text1.SetName("AB"); 868 static_text1.SetName("AB");
872 static_text1.role = ui::AX_ROLE_STATIC_TEXT; 869 static_text1.role = ui::AX_ROLE_STATIC_TEXT;
873 static_text1.location = gfx::Rect(100, 100, 40, 20); 870 static_text1.location = gfx::Rect(100, 100, 40, 20);
874 static_text1.child_ids.push_back(6); 871 static_text1.child_ids.push_back(6);
875 872
876 ui::AXNodeData img; 873 ui::AXNodeData img;
877 img.id = 4; 874 img.id = 4;
875 img.SetName("Test image");
878 img.role = ui::AX_ROLE_IMAGE; 876 img.role = ui::AX_ROLE_IMAGE;
879 img.location = gfx::Rect(140, 100, 20, 20); 877 img.location = gfx::Rect(140, 100, 20, 20);
880 878
881 ui::AXNodeData static_text2; 879 ui::AXNodeData static_text2;
882 static_text2.id = 5; 880 static_text2.id = 5;
883 static_text2.SetName("CD"); 881 static_text2.SetName("CD");
884 static_text2.role = ui::AX_ROLE_STATIC_TEXT; 882 static_text2.role = ui::AX_ROLE_STATIC_TEXT;
885 static_text2.location = gfx::Rect(160, 100, 40, 20); 883 static_text2.location = gfx::Rect(160, 100, 40, 20);
886 static_text2.child_ids.push_back(7); 884 static_text2.child_ids.push_back(7);
887 885
(...skipping 24 matching lines...) Expand all
912 ui::AX_ATTR_CHARACTER_OFFSETS, character_offsets2); 910 ui::AX_ATTR_CHARACTER_OFFSETS, character_offsets2);
913 911
914 scoped_ptr<BrowserAccessibilityManager> manager( 912 scoped_ptr<BrowserAccessibilityManager> manager(
915 BrowserAccessibilityManager::Create( 913 BrowserAccessibilityManager::Create(
916 MakeAXTreeUpdate( 914 MakeAXTreeUpdate(
917 root, div, static_text1, img, 915 root, div, static_text1, img,
918 static_text2, inline_text1, inline_text2), 916 static_text2, inline_text1, inline_text2),
919 nullptr, 917 nullptr,
920 new CountedBrowserAccessibilityFactory())); 918 new CountedBrowserAccessibilityFactory()));
921 BrowserAccessibility* root_accessible = manager->GetRoot(); 919 BrowserAccessibility* root_accessible = manager->GetRoot();
920 ASSERT_NE(nullptr, root_accessible);
921 BrowserAccessibility* div_accessible = root_accessible->PlatformGetChild(0);
922 ASSERT_NE(nullptr, div_accessible);
922 923
923 EXPECT_EQ(gfx::Rect(100, 100, 20, 20).ToString(), 924 EXPECT_EQ(gfx::Rect(100, 100, 20, 20).ToString(),
924 root_accessible->GetLocalBoundsForRange(0, 1).ToString()); 925 div_accessible->GetLocalBoundsForRange(0, 1).ToString());
925 926
926 EXPECT_EQ(gfx::Rect(100, 100, 40, 20).ToString(), 927 EXPECT_EQ(gfx::Rect(100, 100, 40, 20).ToString(),
927 root_accessible->GetLocalBoundsForRange(0, 2).ToString()); 928 div_accessible->GetLocalBoundsForRange(0, 2).ToString());
928 929
929 EXPECT_EQ(gfx::Rect(100, 100, 80, 20).ToString(), 930 EXPECT_EQ(gfx::Rect(100, 100, 80, 20).ToString(),
930 root_accessible->GetLocalBoundsForRange(0, 3).ToString()); 931 div_accessible->GetLocalBoundsForRange(0, 4).ToString());
931 932
932 EXPECT_EQ(gfx::Rect(120, 100, 60, 20).ToString(), 933 EXPECT_EQ(gfx::Rect(120, 100, 60, 20).ToString(),
933 root_accessible->GetLocalBoundsForRange(1, 2).ToString()); 934 div_accessible->GetLocalBoundsForRange(1, 3).ToString());
934 935
935 EXPECT_EQ(gfx::Rect(120, 100, 80, 20).ToString(), 936 EXPECT_EQ(gfx::Rect(120, 100, 80, 20).ToString(),
936 root_accessible->GetLocalBoundsForRange(1, 3).ToString()); 937 div_accessible->GetLocalBoundsForRange(1, 4).ToString());
937 938
938 EXPECT_EQ(gfx::Rect(100, 100, 100, 20).ToString(), 939 EXPECT_EQ(gfx::Rect(100, 100, 100, 20).ToString(),
939 root_accessible->GetLocalBoundsForRange(0, 4).ToString()); 940 div_accessible->GetLocalBoundsForRange(0, 5).ToString());
940 } 941 }
941 942
942 TEST(BrowserAccessibilityManagerTest, TestNextPreviousInTreeOrder) { 943 TEST(BrowserAccessibilityManagerTest, TestNextPreviousInTreeOrder) {
943 ui::AXNodeData root; 944 ui::AXNodeData root;
944 root.id = 1; 945 root.id = 1;
945 root.role = ui::AX_ROLE_ROOT_WEB_AREA; 946 root.role = ui::AX_ROLE_ROOT_WEB_AREA;
946 947
947 ui::AXNodeData node2; 948 ui::AXNodeData node2;
948 node2.id = 2; 949 node2.id = 2;
949 root.child_ids.push_back(2); 950 root.child_ids.push_back(2);
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 events2[0].event_type = ui::AX_EVENT_NONE; 1200 events2[0].event_type = ui::AX_EVENT_NONE;
1200 manager->OnAccessibilityEvents(events2); 1201 manager->OnAccessibilityEvents(events2);
1201 1202
1202 // Make sure that the focused node was updated to the new root and 1203 // Make sure that the focused node was updated to the new root and
1203 // that this doesn't crash. 1204 // that this doesn't crash.
1204 ASSERT_EQ(3, manager->GetRoot()->GetId()); 1205 ASSERT_EQ(3, manager->GetRoot()->GetId());
1205 ASSERT_EQ(3, manager->GetFocus(manager->GetRoot())->GetId()); 1206 ASSERT_EQ(3, manager->GetFocus(manager->GetRoot())->GetId());
1206 } 1207 }
1207 1208
1208 } // namespace content 1209 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698