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

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

Issue 2558933002: Add more fine-grained accessibility modes. (Closed)
Patch Set: Reformat enums as uppercase Created 4 years 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
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #include "base/win/scoped_bstr.h" 14 #include "base/win/scoped_bstr.h"
15 #include "base/win/scoped_comptr.h" 15 #include "base/win/scoped_comptr.h"
16 #include "base/win/scoped_variant.h" 16 #include "base/win/scoped_variant.h"
17 #include "content/browser/accessibility/accessibility_mode_helper.h"
18 #include "content/browser/accessibility/accessibility_tree_formatter.h" 17 #include "content/browser/accessibility/accessibility_tree_formatter.h"
19 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h " 18 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h "
20 #include "content/browser/accessibility/browser_accessibility_manager_win.h" 19 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
21 #include "content/browser/accessibility/browser_accessibility_win.h" 20 #include "content/browser/accessibility/browser_accessibility_win.h"
22 #include "content/browser/renderer_host/render_view_host_impl.h" 21 #include "content/browser/renderer_host/render_view_host_impl.h"
23 #include "content/browser/web_contents/web_contents_impl.h" 22 #include "content/browser/web_contents/web_contents_impl.h"
24 #include "content/browser/web_contents/web_contents_view_aura.h" 23 #include "content/browser/web_contents/web_contents_view_aura.h"
25 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_types.h" 25 #include "content/public/browser/notification_types.h"
27 #include "content/public/browser/render_frame_host.h" 26 #include "content/public/browser/render_frame_host.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 97
99 AccessibilityWinBrowserTest::AccessibilityWinBrowserTest() { 98 AccessibilityWinBrowserTest::AccessibilityWinBrowserTest() {
100 } 99 }
101 100
102 AccessibilityWinBrowserTest::~AccessibilityWinBrowserTest() { 101 AccessibilityWinBrowserTest::~AccessibilityWinBrowserTest() {
103 } 102 }
104 103
105 void AccessibilityWinBrowserTest::LoadInitialAccessibilityTreeFromHtml( 104 void AccessibilityWinBrowserTest::LoadInitialAccessibilityTreeFromHtml(
106 const std::string& html) { 105 const std::string& html) {
107 AccessibilityNotificationWaiter waiter( 106 AccessibilityNotificationWaiter waiter(
108 shell()->web_contents(), AccessibilityModeComplete, 107 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE,
109 ui::AX_EVENT_LOAD_COMPLETE); 108 ui::AX_EVENT_LOAD_COMPLETE);
110 GURL html_data_url("data:text/html," + html); 109 GURL html_data_url("data:text/html," + html);
111 NavigateToURL(shell(), html_data_url); 110 NavigateToURL(shell(), html_data_url);
112 waiter.WaitForNotification(); 111 waiter.WaitForNotification();
113 } 112 }
114 113
115 // 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
116 // of the selected tab. 115 // of the selected tab.
117 IAccessible* AccessibilityWinBrowserTest::GetRendererAccessible() { 116 IAccessible* AccessibilityWinBrowserTest::GetRendererAccessible() {
118 content::WebContents* web_contents = shell()->web_contents(); 117 content::WebContents* web_contents = shell()->web_contents();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 input.Receive())); 155 input.Receive()));
157 LONG input_role = 0; 156 LONG input_role = 0;
158 ASSERT_HRESULT_SUCCEEDED(input->role(&input_role)); 157 ASSERT_HRESULT_SUCCEEDED(input->role(&input_role));
159 ASSERT_EQ(ROLE_SYSTEM_TEXT, input_role); 158 ASSERT_EQ(ROLE_SYSTEM_TEXT, input_role);
160 159
161 // Retrieve the IAccessibleText interface for the field. 160 // Retrieve the IAccessibleText interface for the field.
162 ASSERT_HRESULT_SUCCEEDED(input.QueryInterface(input_text->Receive())); 161 ASSERT_HRESULT_SUCCEEDED(input.QueryInterface(input_text->Receive()));
163 162
164 // Set the caret on the last character. 163 // Set the caret on the last character.
165 AccessibilityNotificationWaiter waiter( 164 AccessibilityNotificationWaiter waiter(
166 shell()->web_contents(), AccessibilityModeComplete, 165 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE,
167 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 166 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
168 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16( 167 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16(
169 static_cast<int>(CONTENTS_LENGTH - 1))); 168 static_cast<int>(CONTENTS_LENGTH - 1)));
170 ExecuteScript(std::wstring( 169 ExecuteScript(std::wstring(
171 L"var textField = document.getElementById('textField');" 170 L"var textField = document.getElementById('textField');"
172 L"textField.focus();" 171 L"textField.focus();"
173 L"textField.setSelectionRange(") + 172 L"textField.setSelectionRange(") +
174 caret_offset + L"," + caret_offset + L");"); 173 caret_offset + L"," + caret_offset + L");");
175 waiter.WaitForNotification(); 174 waiter.WaitForNotification();
176 } 175 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 textarea.Receive())); 207 textarea.Receive()));
209 LONG textarea_role = 0; 208 LONG textarea_role = 0;
210 ASSERT_HRESULT_SUCCEEDED(textarea->role(&textarea_role)); 209 ASSERT_HRESULT_SUCCEEDED(textarea->role(&textarea_role));
211 ASSERT_EQ(ROLE_SYSTEM_TEXT, textarea_role); 210 ASSERT_EQ(ROLE_SYSTEM_TEXT, textarea_role);
212 211
213 // Retrieve the IAccessibleText interface for the field. 212 // Retrieve the IAccessibleText interface for the field.
214 ASSERT_HRESULT_SUCCEEDED(textarea.QueryInterface(textarea_text->Receive())); 213 ASSERT_HRESULT_SUCCEEDED(textarea.QueryInterface(textarea_text->Receive()));
215 214
216 // Set the caret on the last character. 215 // Set the caret on the last character.
217 AccessibilityNotificationWaiter waiter( 216 AccessibilityNotificationWaiter waiter(
218 shell()->web_contents(), AccessibilityModeComplete, 217 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE,
219 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 218 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
220 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16( 219 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16(
221 static_cast<int>(CONTENTS_LENGTH - 1))); 220 static_cast<int>(CONTENTS_LENGTH - 1)));
222 ExecuteScript(std::wstring( 221 ExecuteScript(std::wstring(
223 L"var textField = document.getElementById('textField');" 222 L"var textField = document.getElementById('textField');"
224 L"textField.focus();" 223 L"textField.focus();"
225 L"textField.setSelectionRange(") + 224 L"textField.setSelectionRange(") +
226 caret_offset + L"," + caret_offset + L");"); 225 caret_offset + L"," + caret_offset + L");");
227 waiter.WaitForNotification(); 226 waiter.WaitForNotification();
228 } 227 }
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 return base::string16(); 622 return base::string16();
624 } 623 }
625 624
626 } // namespace 625 } // namespace
627 626
628 627
629 // Tests ---------------------------------------------------------------------- 628 // Tests ----------------------------------------------------------------------
630 629
631 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 630 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
632 TestBusyAccessibilityTree) { 631 TestBusyAccessibilityTree) {
633 if (GetBaseAccessibilityMode() != AccessibilityModeOff)
634 return;
635
636 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 632 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
637 633
638 // The initial accessible returned should have state STATE_SYSTEM_BUSY while 634 // The initial accessible returned should have state STATE_SYSTEM_BUSY while
639 // the accessibility tree is being requested from the renderer. 635 // the accessibility tree is being requested from the renderer.
640 AccessibleChecker document1_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 636 AccessibleChecker document1_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
641 std::wstring()); 637 std::wstring());
642 document1_checker.SetExpectedState( 638 document1_checker.SetExpectedState(
643 STATE_SYSTEM_READONLY | STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED | 639 STATE_SYSTEM_READONLY | STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED |
644 STATE_SYSTEM_BUSY); 640 STATE_SYSTEM_BUSY);
645 document1_checker.CheckAccessible(GetRendererAccessible()); 641 document1_checker.CheckAccessible(GetRendererAccessible());
(...skipping 21 matching lines...) Expand all
667 std::wstring()); 663 std::wstring());
668 list_item_checker.AppendExpectedChild(&list_marker_checker); 664 list_item_checker.AppendExpectedChild(&list_marker_checker);
669 list_item_checker.AppendExpectedChild(&static_text_checker); 665 list_item_checker.AppendExpectedChild(&static_text_checker);
670 radio_group_checker.AppendExpectedChild(&list_item_checker); 666 radio_group_checker.AppendExpectedChild(&list_item_checker);
671 document_checker.AppendExpectedChild(&radio_group_checker); 667 document_checker.AppendExpectedChild(&radio_group_checker);
672 document_checker.CheckAccessible(GetRendererAccessible()); 668 document_checker.CheckAccessible(GetRendererAccessible());
673 669
674 // Set focus to the radio group. 670 // Set focus to the radio group.
675 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 671 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
676 new AccessibilityNotificationWaiter(shell()->web_contents(), 672 new AccessibilityNotificationWaiter(shell()->web_contents(),
677 AccessibilityModeComplete, 673 ACCESSIBILITY_MODE_COMPLETE,
678 ui::AX_EVENT_FOCUS)); 674 ui::AX_EVENT_FOCUS));
679 ExecuteScript(L"document.body.children[0].focus()"); 675 ExecuteScript(L"document.body.children[0].focus()");
680 waiter->WaitForNotification(); 676 waiter->WaitForNotification();
681 677
682 // Check that the accessibility tree of the browser has been updated. 678 // Check that the accessibility tree of the browser has been updated.
683 radio_group_checker.SetExpectedState( 679 radio_group_checker.SetExpectedState(
684 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED); 680 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED);
685 document_checker.CheckAccessible(GetRendererAccessible()); 681 document_checker.CheckAccessible(GetRendererAccessible());
686 682
687 // Set the active descendant of the radio group 683 // Set the active descendant of the radio group
688 waiter.reset(new AccessibilityNotificationWaiter( 684 waiter.reset(new AccessibilityNotificationWaiter(
689 shell()->web_contents(), AccessibilityModeComplete, 685 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE,
690 ui::AX_EVENT_FOCUS)); 686 ui::AX_EVENT_FOCUS));
691 ExecuteScript( 687 ExecuteScript(
692 L"document.body.children[0].setAttribute('aria-activedescendant', 'li')"); 688 L"document.body.children[0].setAttribute('aria-activedescendant', 'li')");
693 waiter->WaitForNotification(); 689 waiter->WaitForNotification();
694 690
695 // Check that the accessibility tree of the browser has been updated. 691 // Check that the accessibility tree of the browser has been updated.
696 list_item_checker.SetExpectedState( 692 list_item_checker.SetExpectedState(
697 STATE_SYSTEM_READONLY | STATE_SYSTEM_FOCUSED); 693 STATE_SYSTEM_READONLY | STATE_SYSTEM_FOCUSED);
698 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); 694 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE);
699 document_checker.CheckAccessible(GetRendererAccessible()); 695 document_checker.CheckAccessible(GetRendererAccessible());
(...skipping 12 matching lines...) Expand all
712 std::wstring()); 708 std::wstring());
713 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 709 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
714 std::wstring()); 710 std::wstring());
715 body_checker.AppendExpectedChild(&checkbox_checker); 711 body_checker.AppendExpectedChild(&checkbox_checker);
716 document_checker.AppendExpectedChild(&body_checker); 712 document_checker.AppendExpectedChild(&body_checker);
717 document_checker.CheckAccessible(GetRendererAccessible()); 713 document_checker.CheckAccessible(GetRendererAccessible());
718 714
719 // Check the checkbox. 715 // Check the checkbox.
720 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 716 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
721 new AccessibilityNotificationWaiter(shell()->web_contents(), 717 new AccessibilityNotificationWaiter(shell()->web_contents(),
722 AccessibilityModeComplete, 718 ACCESSIBILITY_MODE_COMPLETE,
723 ui::AX_EVENT_CHECKED_STATE_CHANGED)); 719 ui::AX_EVENT_CHECKED_STATE_CHANGED));
724 ExecuteScript(L"document.body.children[0].checked=true"); 720 ExecuteScript(L"document.body.children[0].checked=true");
725 waiter->WaitForNotification(); 721 waiter->WaitForNotification();
726 722
727 // Check that the accessibility tree of the browser has been updated. 723 // Check that the accessibility tree of the browser has been updated.
728 checkbox_checker.SetExpectedState( 724 checkbox_checker.SetExpectedState(
729 STATE_SYSTEM_CHECKED | STATE_SYSTEM_FOCUSABLE); 725 STATE_SYSTEM_CHECKED | STATE_SYSTEM_FOCUSABLE);
730 document_checker.CheckAccessible(GetRendererAccessible()); 726 document_checker.CheckAccessible(GetRendererAccessible());
731 } 727 }
732 728
733 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 729 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
734 TestNotificationChildrenChanged) { 730 TestNotificationChildrenChanged) {
735 // The role attribute causes the node to be in the accessibility tree. 731 // The role attribute causes the node to be in the accessibility tree.
736 LoadInitialAccessibilityTreeFromHtml("<body role=group></body>"); 732 LoadInitialAccessibilityTreeFromHtml("<body role=group></body>");
737 733
738 // Check the browser's copy of the renderer accessibility tree. 734 // Check the browser's copy of the renderer accessibility tree.
739 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, 735 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING,
740 std::wstring()); 736 std::wstring());
741 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 737 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
742 std::wstring()); 738 std::wstring());
743 document_checker.AppendExpectedChild(&group_checker); 739 document_checker.AppendExpectedChild(&group_checker);
744 document_checker.CheckAccessible(GetRendererAccessible()); 740 document_checker.CheckAccessible(GetRendererAccessible());
745 741
746 // Change the children of the document body. 742 // Change the children of the document body.
747 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 743 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
748 new AccessibilityNotificationWaiter(shell()->web_contents(), 744 new AccessibilityNotificationWaiter(shell()->web_contents(),
749 AccessibilityModeComplete, 745 ACCESSIBILITY_MODE_COMPLETE,
750 ui::AX_EVENT_CHILDREN_CHANGED)); 746 ui::AX_EVENT_CHILDREN_CHANGED));
751 ExecuteScript(L"document.body.innerHTML='<b>new text</b>'"); 747 ExecuteScript(L"document.body.innerHTML='<b>new text</b>'");
752 waiter->WaitForNotification(); 748 waiter->WaitForNotification();
753 749
754 // Check that the accessibility tree of the browser has been updated. 750 // Check that the accessibility tree of the browser has been updated.
755 AccessibleChecker text_checker( 751 AccessibleChecker text_checker(
756 L"new text", ROLE_SYSTEM_STATICTEXT, std::wstring()); 752 L"new text", ROLE_SYSTEM_STATICTEXT, std::wstring());
757 group_checker.AppendExpectedChild(&text_checker); 753 group_checker.AppendExpectedChild(&text_checker);
758 document_checker.CheckAccessible(GetRendererAccessible()); 754 document_checker.CheckAccessible(GetRendererAccessible());
759 } 755 }
760 756
761 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 757 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
762 TestNotificationChildrenChanged2) { 758 TestNotificationChildrenChanged2) {
763 // The role attribute causes the node to be in the accessibility tree. 759 // The role attribute causes the node to be in the accessibility tree.
764 LoadInitialAccessibilityTreeFromHtml( 760 LoadInitialAccessibilityTreeFromHtml(
765 "<div role=group style='visibility: hidden'>text</div>"); 761 "<div role=group style='visibility: hidden'>text</div>");
766 762
767 // Check the accessible tree of the browser. 763 // Check the accessible tree of the browser.
768 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 764 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
769 std::wstring()); 765 std::wstring());
770 document_checker.CheckAccessible(GetRendererAccessible()); 766 document_checker.CheckAccessible(GetRendererAccessible());
771 767
772 // Change the children of the document body. 768 // Change the children of the document body.
773 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 769 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
774 new AccessibilityNotificationWaiter(shell()->web_contents(), 770 new AccessibilityNotificationWaiter(shell()->web_contents(),
775 AccessibilityModeComplete, 771 ACCESSIBILITY_MODE_COMPLETE,
776 ui::AX_EVENT_CHILDREN_CHANGED)); 772 ui::AX_EVENT_CHILDREN_CHANGED));
777 ExecuteScript(L"document.body.children[0].style.visibility='visible'"); 773 ExecuteScript(L"document.body.children[0].style.visibility='visible'");
778 waiter->WaitForNotification(); 774 waiter->WaitForNotification();
779 775
780 // Check that the accessibility tree of the browser has been updated. 776 // Check that the accessibility tree of the browser has been updated.
781 AccessibleChecker static_text_checker(L"text", ROLE_SYSTEM_STATICTEXT, 777 AccessibleChecker static_text_checker(L"text", ROLE_SYSTEM_STATICTEXT,
782 std::wstring()); 778 std::wstring());
783 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, 779 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING,
784 std::wstring()); 780 std::wstring());
785 document_checker.AppendExpectedChild(&group_checker); 781 document_checker.AppendExpectedChild(&group_checker);
(...skipping 12 matching lines...) Expand all
798 std::wstring()); 794 std::wstring());
799 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); 795 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE);
800 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 796 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
801 std::wstring()); 797 std::wstring());
802 document_checker.AppendExpectedChild(&group_checker); 798 document_checker.AppendExpectedChild(&group_checker);
803 document_checker.CheckAccessible(GetRendererAccessible()); 799 document_checker.CheckAccessible(GetRendererAccessible());
804 800
805 // Focus the div in the document 801 // Focus the div in the document
806 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 802 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
807 new AccessibilityNotificationWaiter(shell()->web_contents(), 803 new AccessibilityNotificationWaiter(shell()->web_contents(),
808 AccessibilityModeComplete, 804 ACCESSIBILITY_MODE_COMPLETE,
809 ui::AX_EVENT_FOCUS)); 805 ui::AX_EVENT_FOCUS));
810 ExecuteScript(L"document.body.children[0].focus()"); 806 ExecuteScript(L"document.body.children[0].focus()");
811 waiter->WaitForNotification(); 807 waiter->WaitForNotification();
812 808
813 // Check that the accessibility tree of the browser has been updated. 809 // Check that the accessibility tree of the browser has been updated.
814 SCOPED_TRACE("Check updated tree after focusing div"); 810 SCOPED_TRACE("Check updated tree after focusing div");
815 group_checker.SetExpectedState( 811 group_checker.SetExpectedState(
816 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED); 812 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED);
817 document_checker.CheckAccessible(GetRendererAccessible()); 813 document_checker.CheckAccessible(GetRendererAccessible());
818 814
819 // Focus the document accessible. This will un-focus the current node. 815 // Focus the document accessible. This will un-focus the current node.
820 waiter.reset( 816 waiter.reset(
821 new AccessibilityNotificationWaiter( 817 new AccessibilityNotificationWaiter(
822 shell()->web_contents(), AccessibilityModeComplete, 818 shell()->web_contents(), ACCESSIBILITY_MODE_COMPLETE,
823 ui::AX_EVENT_BLUR)); 819 ui::AX_EVENT_BLUR));
824 base::win::ScopedComPtr<IAccessible> document_accessible( 820 base::win::ScopedComPtr<IAccessible> document_accessible(
825 GetRendererAccessible()); 821 GetRendererAccessible());
826 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL)); 822 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL));
827 base::win::ScopedVariant childid_self(CHILDID_SELF); 823 base::win::ScopedVariant childid_self(CHILDID_SELF);
828 HRESULT hr = document_accessible->accSelect(SELFLAG_TAKEFOCUS, childid_self); 824 HRESULT hr = document_accessible->accSelect(SELFLAG_TAKEFOCUS, childid_self);
829 ASSERT_EQ(S_OK, hr); 825 ASSERT_EQ(S_OK, hr);
830 waiter->WaitForNotification(); 826 waiter->WaitForNotification();
831 827
832 // Check that the accessibility tree of the browser has been updated. 828 // Check that the accessibility tree of the browser has been updated.
(...skipping 15 matching lines...) Expand all
848 std::wstring()); 844 std::wstring());
849 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 845 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
850 std::wstring()); 846 std::wstring());
851 body_checker.AppendExpectedChild(&text_field_checker); 847 body_checker.AppendExpectedChild(&text_field_checker);
852 document_checker.AppendExpectedChild(&body_checker); 848 document_checker.AppendExpectedChild(&body_checker);
853 document_checker.CheckAccessible(GetRendererAccessible()); 849 document_checker.CheckAccessible(GetRendererAccessible());
854 850
855 // Set the value of the text control 851 // Set the value of the text control
856 std::unique_ptr<AccessibilityNotificationWaiter> waiter( 852 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
857 new AccessibilityNotificationWaiter(shell()->web_contents(), 853 new AccessibilityNotificationWaiter(shell()->web_contents(),
858 AccessibilityModeComplete, 854 ACCESSIBILITY_MODE_COMPLETE,
859 ui::AX_EVENT_VALUE_CHANGED)); 855 ui::AX_EVENT_VALUE_CHANGED));
860 ExecuteScript(L"document.body.children[0].value='new value'"); 856 ExecuteScript(L"document.body.children[0].value='new value'");
861 waiter->WaitForNotification(); 857 waiter->WaitForNotification();
862 858
863 // Check that the accessibility tree of the browser has been updated. 859 // Check that the accessibility tree of the browser has been updated.
864 text_field_checker.SetExpectedValue(L"new value"); 860 text_field_checker.SetExpectedValue(L"new value");
865 document_checker.CheckAccessible(GetRendererAccessible()); 861 document_checker.CheckAccessible(GetRendererAccessible());
866 } 862 }
867 863
868 // This test verifies that the web content's accessibility tree is a 864 // This test verifies that the web content's accessibility tree is a
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 base::win::ScopedComPtr<IAccessibleText> input_text; 1086 base::win::ScopedComPtr<IAccessibleText> input_text;
1091 SetUpInputField(&input_text); 1087 SetUpInputField(&input_text);
1092 1088
1093 LONG caret_offset = 0; 1089 LONG caret_offset = 0;
1094 HRESULT hr = input_text->get_caretOffset(&caret_offset); 1090 HRESULT hr = input_text->get_caretOffset(&caret_offset);
1095 EXPECT_EQ(S_OK, hr); 1091 EXPECT_EQ(S_OK, hr);
1096 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset); 1092 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset);
1097 1093
1098 AccessibilityNotificationWaiter waiter( 1094 AccessibilityNotificationWaiter waiter(
1099 shell()->web_contents(), 1095 shell()->web_contents(),
1100 AccessibilityModeComplete, 1096 ACCESSIBILITY_MODE_COMPLETE,
1101 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 1097 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
1102 caret_offset = 0; 1098 caret_offset = 0;
1103 hr = input_text->setCaretOffset(caret_offset); 1099 hr = input_text->setCaretOffset(caret_offset);
1104 EXPECT_EQ(S_OK, hr); 1100 EXPECT_EQ(S_OK, hr);
1105 waiter.WaitForNotification(); 1101 waiter.WaitForNotification();
1106 1102
1107 hr = input_text->get_caretOffset(&caret_offset); 1103 hr = input_text->get_caretOffset(&caret_offset);
1108 EXPECT_EQ(S_OK, hr); 1104 EXPECT_EQ(S_OK, hr);
1109 EXPECT_EQ(0, caret_offset); 1105 EXPECT_EQ(0, caret_offset);
1110 } 1106 }
1111 1107
1112 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1108 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1113 TestMultiLineSetCaretOffset) { 1109 TestMultiLineSetCaretOffset) {
1114 base::win::ScopedComPtr<IAccessibleText> textarea_text; 1110 base::win::ScopedComPtr<IAccessibleText> textarea_text;
1115 SetUpTextareaField(&textarea_text); 1111 SetUpTextareaField(&textarea_text);
1116 1112
1117 LONG caret_offset = 0; 1113 LONG caret_offset = 0;
1118 HRESULT hr = textarea_text->get_caretOffset(&caret_offset); 1114 HRESULT hr = textarea_text->get_caretOffset(&caret_offset);
1119 EXPECT_EQ(S_OK, hr); 1115 EXPECT_EQ(S_OK, hr);
1120 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset); 1116 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset);
1121 1117
1122 AccessibilityNotificationWaiter waiter( 1118 AccessibilityNotificationWaiter waiter(
1123 shell()->web_contents(), 1119 shell()->web_contents(),
1124 AccessibilityModeComplete, 1120 ACCESSIBILITY_MODE_COMPLETE,
1125 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 1121 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
1126 caret_offset = 0; 1122 caret_offset = 0;
1127 hr = textarea_text->setCaretOffset(caret_offset); 1123 hr = textarea_text->setCaretOffset(caret_offset);
1128 EXPECT_EQ(S_OK, hr); 1124 EXPECT_EQ(S_OK, hr);
1129 waiter.WaitForNotification(); 1125 waiter.WaitForNotification();
1130 1126
1131 hr = textarea_text->get_caretOffset(&caret_offset); 1127 hr = textarea_text->get_caretOffset(&caret_offset);
1132 EXPECT_EQ(S_OK, hr); 1128 EXPECT_EQ(S_OK, hr);
1133 EXPECT_EQ(0, caret_offset); 1129 EXPECT_EQ(0, caret_offset);
1134 } 1130 }
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 1705
1710 base::win::ScopedVariant childid_self(CHILDID_SELF); 1706 base::win::ScopedVariant childid_self(CHILDID_SELF);
1711 base::win::ScopedBstr image_name; 1707 base::win::ScopedBstr image_name;
1712 EXPECT_HRESULT_SUCCEEDED( 1708 EXPECT_HRESULT_SUCCEEDED(
1713 image->get_accName(childid_self, image_name.Receive())); 1709 image->get_accName(childid_self, image_name.Receive()));
1714 EXPECT_EQ(L"image", std::wstring(image_name, image_name.Length())); 1710 EXPECT_EQ(L"image", std::wstring(image_name, image_name.Length()));
1715 image_name.Release(); 1711 image_name.Release();
1716 // Cllicking the image will change its name. 1712 // Cllicking the image will change its name.
1717 EXPECT_HRESULT_SUCCEEDED(image_action->doAction(0)); 1713 EXPECT_HRESULT_SUCCEEDED(image_action->doAction(0));
1718 AccessibilityNotificationWaiter waiter(shell()->web_contents(), 1714 AccessibilityNotificationWaiter waiter(shell()->web_contents(),
1719 AccessibilityModeComplete, 1715 ACCESSIBILITY_MODE_COMPLETE,
1720 ui::AX_EVENT_TEXT_CHANGED); 1716 ui::AX_EVENT_TEXT_CHANGED);
1721 waiter.WaitForNotification(); 1717 waiter.WaitForNotification();
1722 EXPECT_HRESULT_SUCCEEDED( 1718 EXPECT_HRESULT_SUCCEEDED(
1723 image->get_accName(childid_self, image_name.Receive())); 1719 image->get_accName(childid_self, image_name.Receive()));
1724 EXPECT_EQ(L"image2", std::wstring(image_name, image_name.Length())); 1720 EXPECT_EQ(L"image2", std::wstring(image_name, image_name.Length()));
1725 EXPECT_HRESULT_FAILED(image_action->doAction(1)); 1721 EXPECT_HRESULT_FAILED(image_action->doAction(1));
1726 } 1722 }
1727 1723
1728 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, HasHWNDAfterNavigation) { 1724 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, HasHWNDAfterNavigation) {
1729 // This test simulates a scenario where RenderWidgetHostViewAura::SetSize 1725 // This test simulates a scenario where RenderWidgetHostViewAura::SetSize
1730 // is not called again after its window is added to the root window. 1726 // is not called again after its window is added to the root window.
1731 // Ensure that we still get a legacy HWND for accessibility. 1727 // Ensure that we still get a legacy HWND for accessibility.
1732 1728
1733 host_resolver()->AddRule("*", "127.0.0.1"); 1729 host_resolver()->AddRule("*", "127.0.0.1");
1734 ASSERT_TRUE(embedded_test_server()->Start()); 1730 ASSERT_TRUE(embedded_test_server()->Start());
1735 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 1731 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
1736 shell()->web_contents()); 1732 shell()->web_contents());
1737 WebContentsView* web_contents_view = web_contents->GetView(); 1733 WebContentsView* web_contents_view = web_contents->GetView();
1738 WebContentsViewAura* web_contents_view_aura = 1734 WebContentsViewAura* web_contents_view_aura =
1739 static_cast<WebContentsViewAura*>(web_contents_view); 1735 static_cast<WebContentsViewAura*>(web_contents_view);
1740 1736
1741 // Set a flag that will cause WebContentsViewAura to initialize a 1737 // Set a flag that will cause WebContentsViewAura to initialize a
1742 // RenderWidgetHostViewAura with a null parent view. 1738 // RenderWidgetHostViewAura with a null parent view.
1743 web_contents_view_aura->set_init_rwhv_with_null_parent_for_testing(true); 1739 web_contents_view_aura->set_init_rwhv_with_null_parent_for_testing(true);
1744 1740
1745 // Navigate to a new page and wait for the accessibility tree to load. 1741 // Navigate to a new page and wait for the accessibility tree to load.
1746 AccessibilityNotificationWaiter waiter( 1742 AccessibilityNotificationWaiter waiter(
1747 shell()->web_contents(), 1743 shell()->web_contents(),
1748 AccessibilityModeComplete, 1744 ACCESSIBILITY_MODE_COMPLETE,
1749 ui::AX_EVENT_LOAD_COMPLETE); 1745 ui::AX_EVENT_LOAD_COMPLETE);
1750 NavigateToURL(shell(), embedded_test_server()->GetURL( 1746 NavigateToURL(shell(), embedded_test_server()->GetURL(
1751 "/accessibility/html/article.html")); 1747 "/accessibility/html/article.html"));
1752 waiter.WaitForNotification(); 1748 waiter.WaitForNotification();
1753 1749
1754 // At this point the root of the accessibility tree shouldn't have an HWND 1750 // At this point the root of the accessibility tree shouldn't have an HWND
1755 // because we never gave a parent window to the RWHVA. 1751 // because we never gave a parent window to the RWHVA.
1756 BrowserAccessibilityManagerWin* manager = 1752 BrowserAccessibilityManagerWin* manager =
1757 static_cast<BrowserAccessibilityManagerWin*>( 1753 static_cast<BrowserAccessibilityManagerWin*>(
1758 web_contents->GetRootBrowserAccessibilityManager()); 1754 web_contents->GetRootBrowserAccessibilityManager());
1759 ASSERT_EQ(nullptr, manager->GetParentHWND()); 1755 ASSERT_EQ(nullptr, manager->GetParentHWND());
1760 1756
1761 // Now add the RWHVA's window to the root window and ensure that we have 1757 // Now add the RWHVA's window to the root window and ensure that we have
1762 // an HWND for accessibility now. 1758 // an HWND for accessibility now.
1763 web_contents_view->GetNativeView()->AddChild( 1759 web_contents_view->GetNativeView()->AddChild(
1764 web_contents->GetRenderWidgetHostView()->GetNativeView()); 1760 web_contents->GetRenderWidgetHostView()->GetNativeView());
1765 ASSERT_NE(nullptr, manager->GetParentHWND()); 1761 ASSERT_NE(nullptr, manager->GetParentHWND());
1766 } 1762 }
1767 1763
1768 } // namespace content 1764 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698