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

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

Issue 1874893002: Convert //content/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 <vector> 9 #include <vector>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.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" 17 #include "content/browser/accessibility/accessibility_mode_helper.h"
18 #include "content/browser/accessibility/accessibility_tree_formatter.h" 18 #include "content/browser/accessibility/accessibility_tree_formatter.h"
19 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h " 19 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h "
20 #include "content/browser/accessibility/browser_accessibility_win.h" 20 #include "content/browser/accessibility/browser_accessibility_win.h"
21 #include "content/browser/renderer_host/render_view_host_impl.h" 21 #include "content/browser/renderer_host/render_view_host_impl.h"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 360
361 std::vector<base::win::ScopedVariant> 361 std::vector<base::win::ScopedVariant>
362 AccessibilityWinBrowserTest::GetAllAccessibleChildren( 362 AccessibilityWinBrowserTest::GetAllAccessibleChildren(
363 IAccessible* element) { 363 IAccessible* element) {
364 LONG child_count = 0; 364 LONG child_count = 0;
365 HRESULT hr = element->get_accChildCount(&child_count); 365 HRESULT hr = element->get_accChildCount(&child_count);
366 EXPECT_EQ(S_OK, hr); 366 EXPECT_EQ(S_OK, hr);
367 if (child_count <= 0) 367 if (child_count <= 0)
368 return std::vector<base::win::ScopedVariant>(); 368 return std::vector<base::win::ScopedVariant>();
369 369
370 scoped_ptr<VARIANT[]> children_array(new VARIANT[child_count]); 370 std::unique_ptr<VARIANT[]> children_array(new VARIANT[child_count]);
371 LONG obtained_count = 0; 371 LONG obtained_count = 0;
372 hr = AccessibleChildren( 372 hr = AccessibleChildren(
373 element, 0, child_count, children_array.get(), &obtained_count); 373 element, 0, child_count, children_array.get(), &obtained_count);
374 EXPECT_EQ(S_OK, hr); 374 EXPECT_EQ(S_OK, hr);
375 EXPECT_EQ(child_count, obtained_count); 375 EXPECT_EQ(child_count, obtained_count);
376 376
377 std::vector<base::win::ScopedVariant> children( 377 std::vector<base::win::ScopedVariant> children(
378 static_cast<size_t>(child_count)); 378 static_cast<size_t>(child_count));
379 for (size_t i = 0; i < children.size(); i++) { 379 for (size_t i = 0; i < children.size(); i++) {
380 children[i].Reset(children_array[i]); 380 children[i].Reset(children_array[i]);
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); 660 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE);
661 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 661 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
662 std::wstring()); 662 std::wstring());
663 list_item_checker.AppendExpectedChild(&list_marker_checker); 663 list_item_checker.AppendExpectedChild(&list_marker_checker);
664 list_item_checker.AppendExpectedChild(&static_text_checker); 664 list_item_checker.AppendExpectedChild(&static_text_checker);
665 radio_group_checker.AppendExpectedChild(&list_item_checker); 665 radio_group_checker.AppendExpectedChild(&list_item_checker);
666 document_checker.AppendExpectedChild(&radio_group_checker); 666 document_checker.AppendExpectedChild(&radio_group_checker);
667 document_checker.CheckAccessible(GetRendererAccessible()); 667 document_checker.CheckAccessible(GetRendererAccessible());
668 668
669 // Set focus to the radio group. 669 // Set focus to the radio group.
670 scoped_ptr<AccessibilityNotificationWaiter> waiter( 670 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
671 new AccessibilityNotificationWaiter( 671 new AccessibilityNotificationWaiter(shell(), AccessibilityModeComplete,
672 shell(), AccessibilityModeComplete, 672 ui::AX_EVENT_FOCUS));
673 ui::AX_EVENT_FOCUS));
674 ExecuteScript(L"document.body.children[0].focus()"); 673 ExecuteScript(L"document.body.children[0].focus()");
675 waiter->WaitForNotification(); 674 waiter->WaitForNotification();
676 675
677 // Check that the accessibility tree of the browser has been updated. 676 // Check that the accessibility tree of the browser has been updated.
678 radio_group_checker.SetExpectedState( 677 radio_group_checker.SetExpectedState(
679 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED); 678 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED);
680 document_checker.CheckAccessible(GetRendererAccessible()); 679 document_checker.CheckAccessible(GetRendererAccessible());
681 680
682 // Set the active descendant of the radio group 681 // Set the active descendant of the radio group
683 waiter.reset(new AccessibilityNotificationWaiter( 682 waiter.reset(new AccessibilityNotificationWaiter(
(...skipping 21 matching lines...) Expand all
705 checkbox_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); 704 checkbox_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE);
706 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION, 705 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION,
707 std::wstring()); 706 std::wstring());
708 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 707 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
709 std::wstring()); 708 std::wstring());
710 body_checker.AppendExpectedChild(&checkbox_checker); 709 body_checker.AppendExpectedChild(&checkbox_checker);
711 document_checker.AppendExpectedChild(&body_checker); 710 document_checker.AppendExpectedChild(&body_checker);
712 document_checker.CheckAccessible(GetRendererAccessible()); 711 document_checker.CheckAccessible(GetRendererAccessible());
713 712
714 // Check the checkbox. 713 // Check the checkbox.
715 scoped_ptr<AccessibilityNotificationWaiter> waiter( 714 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
716 new AccessibilityNotificationWaiter( 715 new AccessibilityNotificationWaiter(shell(), AccessibilityModeComplete,
717 shell(), AccessibilityModeComplete, 716 ui::AX_EVENT_CHECKED_STATE_CHANGED));
718 ui::AX_EVENT_CHECKED_STATE_CHANGED));
719 ExecuteScript(L"document.body.children[0].checked=true"); 717 ExecuteScript(L"document.body.children[0].checked=true");
720 waiter->WaitForNotification(); 718 waiter->WaitForNotification();
721 719
722 // Check that the accessibility tree of the browser has been updated. 720 // Check that the accessibility tree of the browser has been updated.
723 checkbox_checker.SetExpectedState( 721 checkbox_checker.SetExpectedState(
724 STATE_SYSTEM_CHECKED | STATE_SYSTEM_FOCUSABLE); 722 STATE_SYSTEM_CHECKED | STATE_SYSTEM_FOCUSABLE);
725 document_checker.CheckAccessible(GetRendererAccessible()); 723 document_checker.CheckAccessible(GetRendererAccessible());
726 } 724 }
727 725
728 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 726 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
729 TestNotificationChildrenChanged) { 727 TestNotificationChildrenChanged) {
730 // The role attribute causes the node to be in the accessibility tree. 728 // The role attribute causes the node to be in the accessibility tree.
731 LoadInitialAccessibilityTreeFromHtml("<body role=group></body>"); 729 LoadInitialAccessibilityTreeFromHtml("<body role=group></body>");
732 730
733 // Check the browser's copy of the renderer accessibility tree. 731 // Check the browser's copy of the renderer accessibility tree.
734 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, 732 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING,
735 std::wstring()); 733 std::wstring());
736 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 734 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
737 std::wstring()); 735 std::wstring());
738 document_checker.AppendExpectedChild(&group_checker); 736 document_checker.AppendExpectedChild(&group_checker);
739 document_checker.CheckAccessible(GetRendererAccessible()); 737 document_checker.CheckAccessible(GetRendererAccessible());
740 738
741 // Change the children of the document body. 739 // Change the children of the document body.
742 scoped_ptr<AccessibilityNotificationWaiter> waiter( 740 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
743 new AccessibilityNotificationWaiter( 741 new AccessibilityNotificationWaiter(shell(), AccessibilityModeComplete,
744 shell(), 742 ui::AX_EVENT_CHILDREN_CHANGED));
745 AccessibilityModeComplete,
746 ui::AX_EVENT_CHILDREN_CHANGED));
747 ExecuteScript(L"document.body.innerHTML='<b>new text</b>'"); 743 ExecuteScript(L"document.body.innerHTML='<b>new text</b>'");
748 waiter->WaitForNotification(); 744 waiter->WaitForNotification();
749 745
750 // Check that the accessibility tree of the browser has been updated. 746 // Check that the accessibility tree of the browser has been updated.
751 AccessibleChecker text_checker( 747 AccessibleChecker text_checker(
752 L"new text", ROLE_SYSTEM_STATICTEXT, std::wstring()); 748 L"new text", ROLE_SYSTEM_STATICTEXT, std::wstring());
753 group_checker.AppendExpectedChild(&text_checker); 749 group_checker.AppendExpectedChild(&text_checker);
754 document_checker.CheckAccessible(GetRendererAccessible()); 750 document_checker.CheckAccessible(GetRendererAccessible());
755 } 751 }
756 752
757 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 753 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
758 TestNotificationChildrenChanged2) { 754 TestNotificationChildrenChanged2) {
759 // The role attribute causes the node to be in the accessibility tree. 755 // The role attribute causes the node to be in the accessibility tree.
760 LoadInitialAccessibilityTreeFromHtml( 756 LoadInitialAccessibilityTreeFromHtml(
761 "<div role=group style='visibility: hidden'>text</div>"); 757 "<div role=group style='visibility: hidden'>text</div>");
762 758
763 // Check the accessible tree of the browser. 759 // Check the accessible tree of the browser.
764 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 760 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
765 std::wstring()); 761 std::wstring());
766 document_checker.CheckAccessible(GetRendererAccessible()); 762 document_checker.CheckAccessible(GetRendererAccessible());
767 763
768 // Change the children of the document body. 764 // Change the children of the document body.
769 scoped_ptr<AccessibilityNotificationWaiter> waiter( 765 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
770 new AccessibilityNotificationWaiter( 766 new AccessibilityNotificationWaiter(shell(), AccessibilityModeComplete,
771 shell(), AccessibilityModeComplete, 767 ui::AX_EVENT_CHILDREN_CHANGED));
772 ui::AX_EVENT_CHILDREN_CHANGED));
773 ExecuteScript(L"document.body.children[0].style.visibility='visible'"); 768 ExecuteScript(L"document.body.children[0].style.visibility='visible'");
774 waiter->WaitForNotification(); 769 waiter->WaitForNotification();
775 770
776 // Check that the accessibility tree of the browser has been updated. 771 // Check that the accessibility tree of the browser has been updated.
777 AccessibleChecker static_text_checker(L"text", ROLE_SYSTEM_STATICTEXT, 772 AccessibleChecker static_text_checker(L"text", ROLE_SYSTEM_STATICTEXT,
778 std::wstring()); 773 std::wstring());
779 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, 774 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING,
780 std::wstring()); 775 std::wstring());
781 document_checker.AppendExpectedChild(&group_checker); 776 document_checker.AppendExpectedChild(&group_checker);
782 group_checker.AppendExpectedChild(&static_text_checker); 777 group_checker.AppendExpectedChild(&static_text_checker);
783 document_checker.CheckAccessible(GetRendererAccessible()); 778 document_checker.CheckAccessible(GetRendererAccessible());
784 } 779 }
785 780
786 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 781 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
787 TestNotificationFocusChanged) { 782 TestNotificationFocusChanged) {
788 // The role attribute causes the node to be in the accessibility tree. 783 // The role attribute causes the node to be in the accessibility tree.
789 LoadInitialAccessibilityTreeFromHtml("<div role=group tabindex='-1'></div>"); 784 LoadInitialAccessibilityTreeFromHtml("<div role=group tabindex='-1'></div>");
790 785
791 // Check the browser's copy of the renderer accessibility tree. 786 // Check the browser's copy of the renderer accessibility tree.
792 SCOPED_TRACE("Check initial tree"); 787 SCOPED_TRACE("Check initial tree");
793 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, 788 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING,
794 std::wstring()); 789 std::wstring());
795 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); 790 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE);
796 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 791 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
797 std::wstring()); 792 std::wstring());
798 document_checker.AppendExpectedChild(&group_checker); 793 document_checker.AppendExpectedChild(&group_checker);
799 document_checker.CheckAccessible(GetRendererAccessible()); 794 document_checker.CheckAccessible(GetRendererAccessible());
800 795
801 // Focus the div in the document 796 // Focus the div in the document
802 scoped_ptr<AccessibilityNotificationWaiter> waiter( 797 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
803 new AccessibilityNotificationWaiter( 798 new AccessibilityNotificationWaiter(shell(), AccessibilityModeComplete,
804 shell(), AccessibilityModeComplete, 799 ui::AX_EVENT_FOCUS));
805 ui::AX_EVENT_FOCUS));
806 ExecuteScript(L"document.body.children[0].focus()"); 800 ExecuteScript(L"document.body.children[0].focus()");
807 waiter->WaitForNotification(); 801 waiter->WaitForNotification();
808 802
809 // Check that the accessibility tree of the browser has been updated. 803 // Check that the accessibility tree of the browser has been updated.
810 SCOPED_TRACE("Check updated tree after focusing div"); 804 SCOPED_TRACE("Check updated tree after focusing div");
811 group_checker.SetExpectedState( 805 group_checker.SetExpectedState(
812 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED); 806 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED);
813 document_checker.CheckAccessible(GetRendererAccessible()); 807 document_checker.CheckAccessible(GetRendererAccessible());
814 808
815 // Focus the document accessible. This will un-focus the current node. 809 // Focus the document accessible. This will un-focus the current node.
(...skipping 26 matching lines...) Expand all
842 text_field_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); 836 text_field_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE);
843 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION, 837 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION,
844 std::wstring()); 838 std::wstring());
845 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 839 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
846 std::wstring()); 840 std::wstring());
847 body_checker.AppendExpectedChild(&text_field_checker); 841 body_checker.AppendExpectedChild(&text_field_checker);
848 document_checker.AppendExpectedChild(&body_checker); 842 document_checker.AppendExpectedChild(&body_checker);
849 document_checker.CheckAccessible(GetRendererAccessible()); 843 document_checker.CheckAccessible(GetRendererAccessible());
850 844
851 // Set the value of the text control 845 // Set the value of the text control
852 scoped_ptr<AccessibilityNotificationWaiter> waiter( 846 std::unique_ptr<AccessibilityNotificationWaiter> waiter(
853 new AccessibilityNotificationWaiter( 847 new AccessibilityNotificationWaiter(shell(), AccessibilityModeComplete,
854 shell(), AccessibilityModeComplete, 848 ui::AX_EVENT_VALUE_CHANGED));
855 ui::AX_EVENT_VALUE_CHANGED));
856 ExecuteScript(L"document.body.children[0].value='new value'"); 849 ExecuteScript(L"document.body.children[0].value='new value'");
857 waiter->WaitForNotification(); 850 waiter->WaitForNotification();
858 851
859 // Check that the accessibility tree of the browser has been updated. 852 // Check that the accessibility tree of the browser has been updated.
860 text_field_checker.SetExpectedValue(L"new value"); 853 text_field_checker.SetExpectedValue(L"new value");
861 document_checker.CheckAccessible(GetRendererAccessible()); 854 document_checker.CheckAccessible(GetRendererAccessible());
862 } 855 }
863 856
864 // This test verifies that the web content's accessibility tree is a 857 // This test verifies that the web content's accessibility tree is a
865 // descendant of the main browser window's accessibility tree, so that 858 // descendant of the main browser window's accessibility tree, so that
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1616 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1624 TestMultiLineTextAtOffsetWithBoundaryAll) { 1617 TestMultiLineTextAtOffsetWithBoundaryAll) {
1625 base::win::ScopedComPtr<IAccessibleText> textarea_text; 1618 base::win::ScopedComPtr<IAccessibleText> textarea_text;
1626 SetUpTextareaField(&textarea_text); 1619 SetUpTextareaField(&textarea_text);
1627 1620
1628 CheckTextAtOffset(textarea_text, CONTENTS_LENGTH - 1, IA2_TEXT_BOUNDARY_ALL, 1621 CheckTextAtOffset(textarea_text, CONTENTS_LENGTH - 1, IA2_TEXT_BOUNDARY_ALL,
1629 0, CONTENTS_LENGTH, base::SysUTF8ToWide(TEXTAREA_CONTENTS)); 1622 0, CONTENTS_LENGTH, base::SysUTF8ToWide(TEXTAREA_CONTENTS));
1630 } 1623 }
1631 1624
1632 } // namespace content 1625 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/accessibility_ui.cc ('k') | content/browser/accessibility/browser_accessibility_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698