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

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

Issue 2694413006: Scope and clean up uses of AccessibilityMode. (Closed)
Patch Set: merge Created 3 years, 9 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 <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 }; 96 };
97 97
98 AccessibilityWinBrowserTest::AccessibilityWinBrowserTest() { 98 AccessibilityWinBrowserTest::AccessibilityWinBrowserTest() {
99 } 99 }
100 100
101 AccessibilityWinBrowserTest::~AccessibilityWinBrowserTest() { 101 AccessibilityWinBrowserTest::~AccessibilityWinBrowserTest() {
102 } 102 }
103 103
104 void AccessibilityWinBrowserTest::LoadInitialAccessibilityTreeFromHtml( 104 void AccessibilityWinBrowserTest::LoadInitialAccessibilityTreeFromHtml(
105 const std::string& html) { 105 const std::string& html) {
106 AccessibilityNotificationWaiter waiter( 106 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
107 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, 107 kAccessibilityModeComplete,
108 ui::AX_EVENT_LOAD_COMPLETE); 108 ui::AX_EVENT_LOAD_COMPLETE);
109 GURL html_data_url("data:text/html," + html); 109 GURL html_data_url("data:text/html," + html);
110 NavigateToURL(shell(), html_data_url); 110 NavigateToURL(shell(), html_data_url);
111 waiter.WaitForNotification(); 111 waiter.WaitForNotification();
112 } 112 }
113 113
114 // Retrieve the MSAA client accessibility object for the Render Widget Host View 114 // Retrieve the MSAA client accessibility object for the Render Widget Host View
115 // of the selected tab. 115 // of the selected tab.
116 IAccessible* AccessibilityWinBrowserTest::GetRendererAccessible() { 116 IAccessible* AccessibilityWinBrowserTest::GetRendererAccessible() {
117 content::WebContents* web_contents = shell()->web_contents(); 117 content::WebContents* web_contents = shell()->web_contents();
118 return web_contents->GetRenderWidgetHostView()->GetNativeViewAccessible(); 118 return web_contents->GetRenderWidgetHostView()->GetNativeViewAccessible();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 GetAccessibleFromVariant(form.get(), form_children[1].AsInput()).get(), 154 GetAccessibleFromVariant(form.get(), form_children[1].AsInput()).get(),
155 input.Receive())); 155 input.Receive()));
156 LONG input_role = 0; 156 LONG input_role = 0;
157 ASSERT_HRESULT_SUCCEEDED(input->role(&input_role)); 157 ASSERT_HRESULT_SUCCEEDED(input->role(&input_role));
158 ASSERT_EQ(ROLE_SYSTEM_TEXT, input_role); 158 ASSERT_EQ(ROLE_SYSTEM_TEXT, input_role);
159 159
160 // Retrieve the IAccessibleText interface for the field. 160 // Retrieve the IAccessibleText interface for the field.
161 ASSERT_HRESULT_SUCCEEDED(input.QueryInterface(input_text->Receive())); 161 ASSERT_HRESULT_SUCCEEDED(input.QueryInterface(input_text->Receive()));
162 162
163 // Set the caret on the last character. 163 // Set the caret on the last character.
164 AccessibilityNotificationWaiter waiter( 164 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
165 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, 165 kAccessibilityModeComplete,
166 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 166 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
167 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16( 167 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16(
168 static_cast<int>(CONTENTS_LENGTH - 1))); 168 static_cast<int>(CONTENTS_LENGTH - 1)));
169 ExecuteScript(std::wstring( 169 ExecuteScript(std::wstring(
170 L"var textField = document.getElementById('textField');" 170 L"var textField = document.getElementById('textField');"
171 L"textField.focus();" 171 L"textField.focus();"
172 L"textField.setSelectionRange(") + 172 L"textField.setSelectionRange(") +
173 caret_offset + L"," + caret_offset + L");"); 173 caret_offset + L"," + caret_offset + L");");
174 waiter.WaitForNotification(); 174 waiter.WaitForNotification();
175 } 175 }
176 176
(...skipping 29 matching lines...) Expand all
206 .get(), 206 .get(),
207 textarea.Receive())); 207 textarea.Receive()));
208 LONG textarea_role = 0; 208 LONG textarea_role = 0;
209 ASSERT_HRESULT_SUCCEEDED(textarea->role(&textarea_role)); 209 ASSERT_HRESULT_SUCCEEDED(textarea->role(&textarea_role));
210 ASSERT_EQ(ROLE_SYSTEM_TEXT, textarea_role); 210 ASSERT_EQ(ROLE_SYSTEM_TEXT, textarea_role);
211 211
212 // Retrieve the IAccessibleText interface for the field. 212 // Retrieve the IAccessibleText interface for the field.
213 ASSERT_HRESULT_SUCCEEDED(textarea.QueryInterface(textarea_text->Receive())); 213 ASSERT_HRESULT_SUCCEEDED(textarea.QueryInterface(textarea_text->Receive()));
214 214
215 // Set the caret on the last character. 215 // Set the caret on the last character.
216 AccessibilityNotificationWaiter waiter( 216 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
217 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, 217 kAccessibilityModeComplete,
218 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 218 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
219 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16( 219 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16(
220 static_cast<int>(CONTENTS_LENGTH - 1))); 220 static_cast<int>(CONTENTS_LENGTH - 1)));
221 ExecuteScript(std::wstring( 221 ExecuteScript(std::wstring(
222 L"var textField = document.getElementById('textField');" 222 L"var textField = document.getElementById('textField');"
223 L"textField.focus();" 223 L"textField.focus();"
224 L"textField.setSelectionRange(") + 224 L"textField.setSelectionRange(") +
225 caret_offset + L"," + caret_offset + L");"); 225 caret_offset + L"," + caret_offset + L");");
226 waiter.WaitForNotification(); 226 waiter.WaitForNotification();
227 } 227 }
228 228
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 std::wstring()); 665 std::wstring());
666 list_item_checker.AppendExpectedChild(&list_marker_checker); 666 list_item_checker.AppendExpectedChild(&list_marker_checker);
667 list_item_checker.AppendExpectedChild(&static_text_checker); 667 list_item_checker.AppendExpectedChild(&static_text_checker);
668 radio_group_checker.AppendExpectedChild(&list_item_checker); 668 radio_group_checker.AppendExpectedChild(&list_item_checker);
669 document_checker.AppendExpectedChild(&radio_group_checker); 669 document_checker.AppendExpectedChild(&radio_group_checker);
670 document_checker.CheckAccessible(GetRendererAccessible()); 670 document_checker.CheckAccessible(GetRendererAccessible());
671 671
672 // Set focus to the radio group. 672 // Set focus to the radio group.
673 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 673 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
674 new AccessibilityNotificationWaiter(shell()->web_contents(), 674 new AccessibilityNotificationWaiter(shell()->web_contents(),
675 ACCESSIBILITY_MODE_COMPLETE, 675 kAccessibilityModeComplete,
676 ui::AX_EVENT_FOCUS)); 676 ui::AX_EVENT_FOCUS));
677 ExecuteScript(L"document.body.children[0].focus()"); 677 ExecuteScript(L"document.body.children[0].focus()");
678 waiter->WaitForNotification(); 678 waiter->WaitForNotification();
679 679
680 // Check that the accessibility tree of the browser has been updated. 680 // Check that the accessibility tree of the browser has been updated.
681 radio_group_checker.SetExpectedState( 681 radio_group_checker.SetExpectedState(
682 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED); 682 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED);
683 document_checker.CheckAccessible(GetRendererAccessible()); 683 document_checker.CheckAccessible(GetRendererAccessible());
684 684
685 // Set the active descendant of the radio group 685 // Set the active descendant of the radio group
686 waiter.reset(new AccessibilityNotificationWaiter( 686 waiter.reset(new AccessibilityNotificationWaiter(
687 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, 687 shell()->web_contents(), kAccessibilityModeComplete, ui::AX_EVENT_FOCUS));
688 ui::AX_EVENT_FOCUS));
689 ExecuteScript( 688 ExecuteScript(
690 L"document.body.children[0].setAttribute('aria-activedescendant', 'li')"); 689 L"document.body.children[0].setAttribute('aria-activedescendant', 'li')");
691 waiter->WaitForNotification(); 690 waiter->WaitForNotification();
692 691
693 // Check that the accessibility tree of the browser has been updated. 692 // Check that the accessibility tree of the browser has been updated.
694 list_item_checker.SetExpectedState( 693 list_item_checker.SetExpectedState(
695 STATE_SYSTEM_READONLY | STATE_SYSTEM_FOCUSED); 694 STATE_SYSTEM_READONLY | STATE_SYSTEM_FOCUSED);
696 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); 695 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE);
697 document_checker.CheckAccessible(GetRendererAccessible()); 696 document_checker.CheckAccessible(GetRendererAccessible());
698 } 697 }
(...skipping 11 matching lines...) Expand all
710 std::wstring()); 709 std::wstring());
711 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 710 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
712 std::wstring()); 711 std::wstring());
713 body_checker.AppendExpectedChild(&checkbox_checker); 712 body_checker.AppendExpectedChild(&checkbox_checker);
714 document_checker.AppendExpectedChild(&body_checker); 713 document_checker.AppendExpectedChild(&body_checker);
715 document_checker.CheckAccessible(GetRendererAccessible()); 714 document_checker.CheckAccessible(GetRendererAccessible());
716 715
717 // Check the checkbox. 716 // Check the checkbox.
718 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 717 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
719 new AccessibilityNotificationWaiter(shell()->web_contents(), 718 new AccessibilityNotificationWaiter(shell()->web_contents(),
720 ACCESSIBILITY_MODE_COMPLETE, 719 kAccessibilityModeComplete,
721 ui::AX_EVENT_CHECKED_STATE_CHANGED)); 720 ui::AX_EVENT_CHECKED_STATE_CHANGED));
722 ExecuteScript(L"document.body.children[0].checked=true"); 721 ExecuteScript(L"document.body.children[0].checked=true");
723 waiter->WaitForNotification(); 722 waiter->WaitForNotification();
724 723
725 // Check that the accessibility tree of the browser has been updated. 724 // Check that the accessibility tree of the browser has been updated.
726 checkbox_checker.SetExpectedState( 725 checkbox_checker.SetExpectedState(
727 STATE_SYSTEM_CHECKED | STATE_SYSTEM_FOCUSABLE); 726 STATE_SYSTEM_CHECKED | STATE_SYSTEM_FOCUSABLE);
728 document_checker.CheckAccessible(GetRendererAccessible()); 727 document_checker.CheckAccessible(GetRendererAccessible());
729 } 728 }
730 729
731 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 730 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
732 TestNotificationChildrenChanged) { 731 TestNotificationChildrenChanged) {
733 // The role attribute causes the node to be in the accessibility tree. 732 // The role attribute causes the node to be in the accessibility tree.
734 LoadInitialAccessibilityTreeFromHtml("<body role=group></body>"); 733 LoadInitialAccessibilityTreeFromHtml("<body role=group></body>");
735 734
736 // Check the browser's copy of the renderer accessibility tree. 735 // Check the browser's copy of the renderer accessibility tree.
737 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, 736 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING,
738 std::wstring()); 737 std::wstring());
739 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 738 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
740 std::wstring()); 739 std::wstring());
741 document_checker.AppendExpectedChild(&group_checker); 740 document_checker.AppendExpectedChild(&group_checker);
742 document_checker.CheckAccessible(GetRendererAccessible()); 741 document_checker.CheckAccessible(GetRendererAccessible());
743 742
744 // Change the children of the document body. 743 // Change the children of the document body.
745 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 744 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
746 new AccessibilityNotificationWaiter(shell()->web_contents(), 745 new AccessibilityNotificationWaiter(shell()->web_contents(),
747 ACCESSIBILITY_MODE_COMPLETE, 746 kAccessibilityModeComplete,
748 ui::AX_EVENT_CHILDREN_CHANGED)); 747 ui::AX_EVENT_CHILDREN_CHANGED));
749 ExecuteScript(L"document.body.innerHTML='<b>new text</b>'"); 748 ExecuteScript(L"document.body.innerHTML='<b>new text</b>'");
750 waiter->WaitForNotification(); 749 waiter->WaitForNotification();
751 750
752 // Check that the accessibility tree of the browser has been updated. 751 // Check that the accessibility tree of the browser has been updated.
753 AccessibleChecker text_checker( 752 AccessibleChecker text_checker(
754 L"new text", ROLE_SYSTEM_STATICTEXT, std::wstring()); 753 L"new text", ROLE_SYSTEM_STATICTEXT, std::wstring());
755 group_checker.AppendExpectedChild(&text_checker); 754 group_checker.AppendExpectedChild(&text_checker);
756 document_checker.CheckAccessible(GetRendererAccessible()); 755 document_checker.CheckAccessible(GetRendererAccessible());
757 } 756 }
758 757
759 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 758 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
760 TestNotificationChildrenChanged2) { 759 TestNotificationChildrenChanged2) {
761 // The role attribute causes the node to be in the accessibility tree. 760 // The role attribute causes the node to be in the accessibility tree.
762 LoadInitialAccessibilityTreeFromHtml( 761 LoadInitialAccessibilityTreeFromHtml(
763 "<div role=group style='visibility: hidden'>text</div>"); 762 "<div role=group style='visibility: hidden'>text</div>");
764 763
765 // Check the accessible tree of the browser. 764 // Check the accessible tree of the browser.
766 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 765 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
767 std::wstring()); 766 std::wstring());
768 document_checker.CheckAccessible(GetRendererAccessible()); 767 document_checker.CheckAccessible(GetRendererAccessible());
769 768
770 // Change the children of the document body. 769 // Change the children of the document body.
771 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 770 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
772 new AccessibilityNotificationWaiter(shell()->web_contents(), 771 new AccessibilityNotificationWaiter(shell()->web_contents(),
773 ACCESSIBILITY_MODE_COMPLETE, 772 kAccessibilityModeComplete,
774 ui::AX_EVENT_CHILDREN_CHANGED)); 773 ui::AX_EVENT_CHILDREN_CHANGED));
775 ExecuteScript(L"document.body.children[0].style.visibility='visible'"); 774 ExecuteScript(L"document.body.children[0].style.visibility='visible'");
776 waiter->WaitForNotification(); 775 waiter->WaitForNotification();
777 776
778 // Check that the accessibility tree of the browser has been updated. 777 // Check that the accessibility tree of the browser has been updated.
779 AccessibleChecker static_text_checker(L"text", ROLE_SYSTEM_STATICTEXT, 778 AccessibleChecker static_text_checker(L"text", ROLE_SYSTEM_STATICTEXT,
780 std::wstring()); 779 std::wstring());
781 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, 780 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING,
782 std::wstring()); 781 std::wstring());
783 document_checker.AppendExpectedChild(&group_checker); 782 document_checker.AppendExpectedChild(&group_checker);
(...skipping 12 matching lines...) Expand all
796 std::wstring()); 795 std::wstring());
797 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); 796 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE);
798 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 797 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
799 std::wstring()); 798 std::wstring());
800 document_checker.AppendExpectedChild(&group_checker); 799 document_checker.AppendExpectedChild(&group_checker);
801 document_checker.CheckAccessible(GetRendererAccessible()); 800 document_checker.CheckAccessible(GetRendererAccessible());
802 801
803 // Focus the div in the document 802 // Focus the div in the document
804 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 803 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
805 new AccessibilityNotificationWaiter(shell()->web_contents(), 804 new AccessibilityNotificationWaiter(shell()->web_contents(),
806 ACCESSIBILITY_MODE_COMPLETE, 805 kAccessibilityModeComplete,
807 ui::AX_EVENT_FOCUS)); 806 ui::AX_EVENT_FOCUS));
808 ExecuteScript(L"document.body.children[0].focus()"); 807 ExecuteScript(L"document.body.children[0].focus()");
809 waiter->WaitForNotification(); 808 waiter->WaitForNotification();
810 809
811 // Check that the accessibility tree of the browser has been updated. 810 // Check that the accessibility tree of the browser has been updated.
812 SCOPED_TRACE("Check updated tree after focusing div"); 811 SCOPED_TRACE("Check updated tree after focusing div");
813 group_checker.SetExpectedState( 812 group_checker.SetExpectedState(
814 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED); 813 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED);
815 document_checker.CheckAccessible(GetRendererAccessible()); 814 document_checker.CheckAccessible(GetRendererAccessible());
816 815
817 // Focus the document accessible. This will un-focus the current node. 816 // Focus the document accessible. This will un-focus the current node.
818 waiter.reset( 817 waiter.reset(new AccessibilityNotificationWaiter(
819 new AccessibilityNotificationWaiter( 818 shell()->web_contents(), kAccessibilityModeComplete, ui::AX_EVENT_BLUR));
820 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE,
821 ui::AX_EVENT_BLUR));
822 base::win::ScopedComPtr<IAccessible> document_accessible( 819 base::win::ScopedComPtr<IAccessible> document_accessible(
823 GetRendererAccessible()); 820 GetRendererAccessible());
824 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL)); 821 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL));
825 base::win::ScopedVariant childid_self(CHILDID_SELF); 822 base::win::ScopedVariant childid_self(CHILDID_SELF);
826 HRESULT hr = document_accessible->accSelect(SELFLAG_TAKEFOCUS, childid_self); 823 HRESULT hr = document_accessible->accSelect(SELFLAG_TAKEFOCUS, childid_self);
827 ASSERT_EQ(S_OK, hr); 824 ASSERT_EQ(S_OK, hr);
828 waiter->WaitForNotification(); 825 waiter->WaitForNotification();
829 826
830 // Check that the accessibility tree of the browser has been updated. 827 // Check that the accessibility tree of the browser has been updated.
831 SCOPED_TRACE("Check updated tree after focusing document again"); 828 SCOPED_TRACE("Check updated tree after focusing document again");
(...skipping 14 matching lines...) Expand all
846 std::wstring()); 843 std::wstring());
847 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 844 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
848 std::wstring()); 845 std::wstring());
849 body_checker.AppendExpectedChild(&text_field_checker); 846 body_checker.AppendExpectedChild(&text_field_checker);
850 document_checker.AppendExpectedChild(&body_checker); 847 document_checker.AppendExpectedChild(&body_checker);
851 document_checker.CheckAccessible(GetRendererAccessible()); 848 document_checker.CheckAccessible(GetRendererAccessible());
852 849
853 // Set the value of the text control 850 // Set the value of the text control
854 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 851 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
855 new AccessibilityNotificationWaiter(shell()->web_contents(), 852 new AccessibilityNotificationWaiter(shell()->web_contents(),
856 ACCESSIBILITY_MODE_COMPLETE, 853 kAccessibilityModeComplete,
857 ui::AX_EVENT_VALUE_CHANGED)); 854 ui::AX_EVENT_VALUE_CHANGED));
858 ExecuteScript(L"document.body.children[0].value='new value'"); 855 ExecuteScript(L"document.body.children[0].value='new value'");
859 waiter->WaitForNotification(); 856 waiter->WaitForNotification();
860 857
861 // Check that the accessibility tree of the browser has been updated. 858 // Check that the accessibility tree of the browser has been updated.
862 text_field_checker.SetExpectedValue(L"new value"); 859 text_field_checker.SetExpectedValue(L"new value");
863 document_checker.CheckAccessible(GetRendererAccessible()); 860 document_checker.CheckAccessible(GetRendererAccessible());
864 } 861 }
865 862
866 // This test verifies that the web content's accessibility tree is a 863 // This test verifies that the web content's accessibility tree is a
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 1083
1087 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestScrollToPoint) { 1084 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestScrollToPoint) {
1088 base::win::ScopedComPtr<IAccessible2> paragraph; 1085 base::win::ScopedComPtr<IAccessible2> paragraph;
1089 SetUpSampleParagraph(&paragraph); 1086 SetUpSampleParagraph(&paragraph);
1090 1087
1091 LONG prev_x, prev_y, x, y, width, height; 1088 LONG prev_x, prev_y, x, y, width, height;
1092 base::win::ScopedVariant childid_self(CHILDID_SELF); 1089 base::win::ScopedVariant childid_self(CHILDID_SELF);
1093 ASSERT_HRESULT_SUCCEEDED( 1090 ASSERT_HRESULT_SUCCEEDED(
1094 paragraph->accLocation(&prev_x, &prev_y, &width, &height, childid_self)); 1091 paragraph->accLocation(&prev_x, &prev_y, &width, &height, childid_self));
1095 AccessibilityNotificationWaiter location_changed_waiter( 1092 AccessibilityNotificationWaiter location_changed_waiter(
1096 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, 1093 shell()->web_contents(), kAccessibilityModeComplete,
1097 ui::AX_EVENT_LOCATION_CHANGED); 1094 ui::AX_EVENT_LOCATION_CHANGED);
1098 EXPECT_HRESULT_SUCCEEDED( 1095 EXPECT_HRESULT_SUCCEEDED(
1099 paragraph->scrollToPoint(IA2_COORDTYPE_PARENT_RELATIVE, 0, 0)); 1096 paragraph->scrollToPoint(IA2_COORDTYPE_PARENT_RELATIVE, 0, 0));
1100 location_changed_waiter.WaitForNotification(); 1097 location_changed_waiter.WaitForNotification();
1101 1098
1102 ASSERT_HRESULT_SUCCEEDED( 1099 ASSERT_HRESULT_SUCCEEDED(
1103 paragraph->accLocation(&x, &y, &width, &height, childid_self)); 1100 paragraph->accLocation(&x, &y, &width, &height, childid_self));
1104 EXPECT_EQ(prev_x, x); 1101 EXPECT_EQ(prev_x, x);
1105 EXPECT_GT(prev_y, y); 1102 EXPECT_GT(prev_y, y);
1106 1103
(...skipping 10 matching lines...) Expand all
1117 1114
1118 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestSetCaretOffset) { 1115 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestSetCaretOffset) {
1119 base::win::ScopedComPtr<IAccessibleText> input_text; 1116 base::win::ScopedComPtr<IAccessibleText> input_text;
1120 SetUpInputField(&input_text); 1117 SetUpInputField(&input_text);
1121 1118
1122 LONG caret_offset = 0; 1119 LONG caret_offset = 0;
1123 HRESULT hr = input_text->get_caretOffset(&caret_offset); 1120 HRESULT hr = input_text->get_caretOffset(&caret_offset);
1124 EXPECT_EQ(S_OK, hr); 1121 EXPECT_EQ(S_OK, hr);
1125 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset); 1122 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset);
1126 1123
1127 AccessibilityNotificationWaiter waiter( 1124 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
1128 shell()->web_contents(), 1125 kAccessibilityModeComplete,
1129 ACCESSIBILITY_MODE_COMPLETE, 1126 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
1130 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
1131 caret_offset = 0; 1127 caret_offset = 0;
1132 hr = input_text->setCaretOffset(caret_offset); 1128 hr = input_text->setCaretOffset(caret_offset);
1133 EXPECT_EQ(S_OK, hr); 1129 EXPECT_EQ(S_OK, hr);
1134 waiter.WaitForNotification(); 1130 waiter.WaitForNotification();
1135 1131
1136 hr = input_text->get_caretOffset(&caret_offset); 1132 hr = input_text->get_caretOffset(&caret_offset);
1137 EXPECT_EQ(S_OK, hr); 1133 EXPECT_EQ(S_OK, hr);
1138 EXPECT_EQ(0, caret_offset); 1134 EXPECT_EQ(0, caret_offset);
1139 } 1135 }
1140 1136
1141 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1137 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1142 TestMultiLineSetCaretOffset) { 1138 TestMultiLineSetCaretOffset) {
1143 base::win::ScopedComPtr<IAccessibleText> textarea_text; 1139 base::win::ScopedComPtr<IAccessibleText> textarea_text;
1144 SetUpTextareaField(&textarea_text); 1140 SetUpTextareaField(&textarea_text);
1145 1141
1146 LONG caret_offset = 0; 1142 LONG caret_offset = 0;
1147 HRESULT hr = textarea_text->get_caretOffset(&caret_offset); 1143 HRESULT hr = textarea_text->get_caretOffset(&caret_offset);
1148 EXPECT_EQ(S_OK, hr); 1144 EXPECT_EQ(S_OK, hr);
1149 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset); 1145 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset);
1150 1146
1151 AccessibilityNotificationWaiter waiter( 1147 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
1152 shell()->web_contents(), 1148 kAccessibilityModeComplete,
1153 ACCESSIBILITY_MODE_COMPLETE, 1149 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
1154 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
1155 caret_offset = 0; 1150 caret_offset = 0;
1156 hr = textarea_text->setCaretOffset(caret_offset); 1151 hr = textarea_text->setCaretOffset(caret_offset);
1157 EXPECT_EQ(S_OK, hr); 1152 EXPECT_EQ(S_OK, hr);
1158 waiter.WaitForNotification(); 1153 waiter.WaitForNotification();
1159 1154
1160 hr = textarea_text->get_caretOffset(&caret_offset); 1155 hr = textarea_text->get_caretOffset(&caret_offset);
1161 EXPECT_EQ(S_OK, hr); 1156 EXPECT_EQ(S_OK, hr);
1162 EXPECT_EQ(0, caret_offset); 1157 EXPECT_EQ(0, caret_offset);
1163 } 1158 }
1164 1159
1165 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestSetSelection) { 1160 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestSetSelection) {
1166 base::win::ScopedComPtr<IAccessibleText> input_text; 1161 base::win::ScopedComPtr<IAccessibleText> input_text;
1167 SetUpInputField(&input_text); 1162 SetUpInputField(&input_text);
1168 1163
1169 LONG start_offset, end_offset; 1164 LONG start_offset, end_offset;
1170 EXPECT_HRESULT_FAILED( 1165 EXPECT_HRESULT_FAILED(
1171 input_text->get_selection(1, &start_offset, &end_offset)); 1166 input_text->get_selection(1, &start_offset, &end_offset));
1172 HRESULT hr = input_text->get_selection(0, &start_offset, &end_offset); 1167 HRESULT hr = input_text->get_selection(0, &start_offset, &end_offset);
1173 // There is no selection, just a caret. 1168 // There is no selection, just a caret.
1174 EXPECT_EQ(E_INVALIDARG, hr); 1169 EXPECT_EQ(E_INVALIDARG, hr);
1175 1170
1176 AccessibilityNotificationWaiter waiter(shell()->web_contents(), 1171 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
1177 ACCESSIBILITY_MODE_COMPLETE, 1172 kAccessibilityModeComplete,
1178 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 1173 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
1179 start_offset = 0; 1174 start_offset = 0;
1180 end_offset = CONTENTS_LENGTH; 1175 end_offset = CONTENTS_LENGTH;
1181 EXPECT_HRESULT_FAILED(input_text->setSelection(1, start_offset, end_offset)); 1176 EXPECT_HRESULT_FAILED(input_text->setSelection(1, start_offset, end_offset));
1182 EXPECT_HRESULT_SUCCEEDED( 1177 EXPECT_HRESULT_SUCCEEDED(
1183 input_text->setSelection(0, start_offset, end_offset)); 1178 input_text->setSelection(0, start_offset, end_offset));
1184 waiter.WaitForNotification(); 1179 waiter.WaitForNotification();
1185 1180
1186 hr = input_text->get_selection(0, &start_offset, &end_offset); 1181 hr = input_text->get_selection(0, &start_offset, &end_offset);
1187 EXPECT_EQ(S_OK, hr); 1182 EXPECT_EQ(S_OK, hr);
(...skipping 18 matching lines...) Expand all
1206 SetUpTextareaField(&textarea_text); 1201 SetUpTextareaField(&textarea_text);
1207 1202
1208 LONG start_offset, end_offset; 1203 LONG start_offset, end_offset;
1209 EXPECT_HRESULT_FAILED( 1204 EXPECT_HRESULT_FAILED(
1210 textarea_text->get_selection(1, &start_offset, &end_offset)); 1205 textarea_text->get_selection(1, &start_offset, &end_offset));
1211 HRESULT hr = textarea_text->get_selection(0, &start_offset, &end_offset); 1206 HRESULT hr = textarea_text->get_selection(0, &start_offset, &end_offset);
1212 // There is no selection, just a caret. 1207 // There is no selection, just a caret.
1213 EXPECT_EQ(E_INVALIDARG, hr); 1208 EXPECT_EQ(E_INVALIDARG, hr);
1214 1209
1215 AccessibilityNotificationWaiter waiter(shell()->web_contents(), 1210 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
1216 ACCESSIBILITY_MODE_COMPLETE, 1211 kAccessibilityModeComplete,
1217 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 1212 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
1218 start_offset = 0; 1213 start_offset = 0;
1219 end_offset = CONTENTS_LENGTH; 1214 end_offset = CONTENTS_LENGTH;
1220 EXPECT_HRESULT_FAILED( 1215 EXPECT_HRESULT_FAILED(
1221 textarea_text->setSelection(1, start_offset, end_offset)); 1216 textarea_text->setSelection(1, start_offset, end_offset));
1222 EXPECT_HRESULT_SUCCEEDED( 1217 EXPECT_HRESULT_SUCCEEDED(
1223 textarea_text->setSelection(0, start_offset, end_offset)); 1218 textarea_text->setSelection(0, start_offset, end_offset));
1224 waiter.WaitForNotification(); 1219 waiter.WaitForNotification();
1225 1220
1226 hr = textarea_text->get_selection(0, &start_offset, &end_offset); 1221 hr = textarea_text->get_selection(0, &start_offset, &end_offset);
(...skipping 17 matching lines...) Expand all
1244 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1239 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1245 TestStaticTextSetSelection) { 1240 TestStaticTextSetSelection) {
1246 base::win::ScopedComPtr<IAccessibleText> paragraph_text; 1241 base::win::ScopedComPtr<IAccessibleText> paragraph_text;
1247 SetUpSampleParagraph(&paragraph_text); 1242 SetUpSampleParagraph(&paragraph_text);
1248 1243
1249 LONG n_characters; 1244 LONG n_characters;
1250 ASSERT_HRESULT_SUCCEEDED(paragraph_text->get_nCharacters(&n_characters)); 1245 ASSERT_HRESULT_SUCCEEDED(paragraph_text->get_nCharacters(&n_characters));
1251 ASSERT_LT(0, n_characters); 1246 ASSERT_LT(0, n_characters);
1252 1247
1253 AccessibilityNotificationWaiter waiter( 1248 AccessibilityNotificationWaiter waiter(
1254 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE, 1249 shell()->web_contents(), kAccessibilityModeComplete,
1255 ui::AX_EVENT_DOCUMENT_SELECTION_CHANGED); 1250 ui::AX_EVENT_DOCUMENT_SELECTION_CHANGED);
1256 LONG start_offset = 0; 1251 LONG start_offset = 0;
1257 LONG end_offset = n_characters; 1252 LONG end_offset = n_characters;
1258 EXPECT_HRESULT_FAILED( 1253 EXPECT_HRESULT_FAILED(
1259 paragraph_text->setSelection(1, start_offset, end_offset)); 1254 paragraph_text->setSelection(1, start_offset, end_offset));
1260 EXPECT_HRESULT_SUCCEEDED( 1255 EXPECT_HRESULT_SUCCEEDED(
1261 paragraph_text->setSelection(0, start_offset, end_offset)); 1256 paragraph_text->setSelection(0, start_offset, end_offset));
1262 waiter.WaitForNotification(); 1257 waiter.WaitForNotification();
1263 1258
1264 HRESULT hr = paragraph_text->get_selection(0, &start_offset, &end_offset); 1259 HRESULT hr = paragraph_text->get_selection(0, &start_offset, &end_offset);
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 1850
1856 base::win::ScopedVariant childid_self(CHILDID_SELF); 1851 base::win::ScopedVariant childid_self(CHILDID_SELF);
1857 base::win::ScopedBstr image_name; 1852 base::win::ScopedBstr image_name;
1858 EXPECT_HRESULT_SUCCEEDED( 1853 EXPECT_HRESULT_SUCCEEDED(
1859 image->get_accName(childid_self, image_name.Receive())); 1854 image->get_accName(childid_self, image_name.Receive()));
1860 EXPECT_EQ(L"image", std::wstring(image_name, image_name.Length())); 1855 EXPECT_EQ(L"image", std::wstring(image_name, image_name.Length()));
1861 image_name.Release(); 1856 image_name.Release();
1862 // Cllicking the image will change its name. 1857 // Cllicking the image will change its name.
1863 EXPECT_HRESULT_SUCCEEDED(image_action->doAction(0)); 1858 EXPECT_HRESULT_SUCCEEDED(image_action->doAction(0));
1864 AccessibilityNotificationWaiter waiter(shell()->web_contents(), 1859 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
1865 ACCESSIBILITY_MODE_COMPLETE, 1860 kAccessibilityModeComplete,
1866 ui::AX_EVENT_TEXT_CHANGED); 1861 ui::AX_EVENT_TEXT_CHANGED);
1867 waiter.WaitForNotification(); 1862 waiter.WaitForNotification();
1868 EXPECT_HRESULT_SUCCEEDED( 1863 EXPECT_HRESULT_SUCCEEDED(
1869 image->get_accName(childid_self, image_name.Receive())); 1864 image->get_accName(childid_self, image_name.Receive()));
1870 EXPECT_EQ(L"image2", std::wstring(image_name, image_name.Length())); 1865 EXPECT_EQ(L"image2", std::wstring(image_name, image_name.Length()));
1871 EXPECT_HRESULT_FAILED(image_action->doAction(1)); 1866 EXPECT_HRESULT_FAILED(image_action->doAction(1));
1872 } 1867 }
1873 1868
1874 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, HasHWNDAfterNavigation) { 1869 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, HasHWNDAfterNavigation) {
1875 // This test simulates a scenario where RenderWidgetHostViewAura::SetSize 1870 // This test simulates a scenario where RenderWidgetHostViewAura::SetSize
1876 // is not called again after its window is added to the root window. 1871 // is not called again after its window is added to the root window.
1877 // Ensure that we still get a legacy HWND for accessibility. 1872 // Ensure that we still get a legacy HWND for accessibility.
1878 1873
1879 host_resolver()->AddRule("*", "127.0.0.1"); 1874 host_resolver()->AddRule("*", "127.0.0.1");
1880 ASSERT_TRUE(embedded_test_server()->Start()); 1875 ASSERT_TRUE(embedded_test_server()->Start());
1881 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 1876 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
1882 shell()->web_contents()); 1877 shell()->web_contents());
1883 WebContentsView* web_contents_view = web_contents->GetView(); 1878 WebContentsView* web_contents_view = web_contents->GetView();
1884 WebContentsViewAura* web_contents_view_aura = 1879 WebContentsViewAura* web_contents_view_aura =
1885 static_cast<WebContentsViewAura*>(web_contents_view); 1880 static_cast<WebContentsViewAura*>(web_contents_view);
1886 1881
1887 // Set a flag that will cause WebContentsViewAura to initialize a 1882 // Set a flag that will cause WebContentsViewAura to initialize a
1888 // RenderWidgetHostViewAura with a null parent view. 1883 // RenderWidgetHostViewAura with a null parent view.
1889 web_contents_view_aura->set_init_rwhv_with_null_parent_for_testing(true); 1884 web_contents_view_aura->set_init_rwhv_with_null_parent_for_testing(true);
1890 1885
1891 // Navigate to a new page and wait for the accessibility tree to load. 1886 // Navigate to a new page and wait for the accessibility tree to load.
1892 AccessibilityNotificationWaiter waiter( 1887 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
1893 shell()->web_contents(), 1888 kAccessibilityModeComplete,
1894 ACCESSIBILITY_MODE_COMPLETE, 1889 ui::AX_EVENT_LOAD_COMPLETE);
1895 ui::AX_EVENT_LOAD_COMPLETE);
1896 NavigateToURL(shell(), embedded_test_server()->GetURL( 1890 NavigateToURL(shell(), embedded_test_server()->GetURL(
1897 "/accessibility/html/article.html")); 1891 "/accessibility/html/article.html"));
1898 waiter.WaitForNotification(); 1892 waiter.WaitForNotification();
1899 1893
1900 // At this point the root of the accessibility tree shouldn't have an HWND 1894 // At this point the root of the accessibility tree shouldn't have an HWND
1901 // because we never gave a parent window to the RWHVA. 1895 // because we never gave a parent window to the RWHVA.
1902 BrowserAccessibilityManagerWin* manager = 1896 BrowserAccessibilityManagerWin* manager =
1903 static_cast<BrowserAccessibilityManagerWin*>( 1897 static_cast<BrowserAccessibilityManagerWin*>(
1904 web_contents->GetRootBrowserAccessibilityManager()); 1898 web_contents->GetRootBrowserAccessibilityManager());
1905 ASSERT_EQ(nullptr, manager->GetParentHWND()); 1899 ASSERT_EQ(nullptr, manager->GetParentHWND());
1906 1900
1907 // Now add the RWHVA's window to the root window and ensure that we have 1901 // Now add the RWHVA's window to the root window and ensure that we have
1908 // an HWND for accessibility now. 1902 // an HWND for accessibility now.
1909 web_contents_view->GetNativeView()->AddChild( 1903 web_contents_view->GetNativeView()->AddChild(
1910 web_contents->GetRenderWidgetHostView()->GetNativeView()); 1904 web_contents->GetRenderWidgetHostView()->GetNativeView());
1911 ASSERT_NE(nullptr, manager->GetParentHWND()); 1905 ASSERT_NE(nullptr, manager->GetParentHWND());
1912 } 1906 }
1913 1907
1914 } // namespace content 1908 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698