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

Side by Side Diff: chrome/browser/ui/views/accessibility/browser_views_accessibility_browsertest.cc

Issue 10991052: Miscellaneous tiny cleanups done while converting files to use ScopedCOMInitializer, pulled out sep… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
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 <oleacc.h> 5 #include <oleacc.h>
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "base/win/scoped_comptr.h" 8 #include "base/win/scoped_comptr.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
(...skipping 13 matching lines...) Expand all
24 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
25 25
26 namespace { 26 namespace {
27 27
28 VARIANT id_self = {VT_I4, CHILDID_SELF}; 28 VARIANT id_self = {VT_I4, CHILDID_SELF};
29 29
30 } // namespace 30 } // namespace
31 31
32 class BrowserViewsAccessibilityTest : public InProcessBrowserTest { 32 class BrowserViewsAccessibilityTest : public InProcessBrowserTest {
33 public: 33 public:
34 BrowserViewsAccessibilityTest() { 34 BrowserViewsAccessibilityTest();
35 ui::win::CreateATLModuleIfNeeded(); 35 ~BrowserViewsAccessibilityTest();
36 ::CoInitialize(NULL);
37 }
38 36
39 ~BrowserViewsAccessibilityTest() { 37 // Retrieves an instance of BrowserWindowTesting.
40 ::CoUninitialize(); 38 BrowserWindowTesting* GetBrowserWindowTesting();
41 }
42 39
43 // Retrieves an instance of BrowserWindowTesting 40 // Retrieve an instance of BrowserView.
44 BrowserWindowTesting* GetBrowserWindowTesting() { 41 BrowserView* GetBrowserView();
45 BrowserWindow* browser_window = browser()->window();
46
47 if (!browser_window)
48 return NULL;
49
50 return browser_window->GetBrowserWindowTesting();
51 }
52
53 // Retrieve an instance of BrowserView
54 BrowserView* GetBrowserView() {
55 return BrowserView::GetBrowserViewForBrowser(browser());
56 }
57 42
58 // Retrieves and initializes an instance of ToolbarView. 43 // Retrieves and initializes an instance of ToolbarView.
59 ToolbarView* GetToolbarView() { 44 ToolbarView* GetToolbarView();
60 BrowserWindowTesting* browser_window_testing = GetBrowserWindowTesting();
61
62 if (!browser_window_testing)
63 return NULL;
64
65 return browser_window_testing->GetToolbarView();
66 }
67 45
68 // Retrieves and initializes an instance of BookmarkBarView. 46 // Retrieves and initializes an instance of BookmarkBarView.
69 BookmarkBarView* GetBookmarkBarView() { 47 BookmarkBarView* GetBookmarkBarView();
70 BrowserWindowTesting* browser_window_testing = GetBrowserWindowTesting();
71
72 if (!browser_window_testing)
73 return NULL;
74
75 return browser_window_testing->GetBookmarkBarView();
76 }
77 48
78 // Retrieves and verifies the accessibility object for the given View. 49 // Retrieves and verifies the accessibility object for the given View.
79 void TestViewAccessibilityObject(views::View* view, std::wstring name, 50 void TestViewAccessibilityObject(views::View* view,
80 int32 role) { 51 std::wstring name,
81 ASSERT_TRUE(NULL != view); 52 int32 role);
82
83 TestAccessibilityInfo(view->GetNativeViewAccessible(), name, role);
84 }
85
86 53
87 // Verifies MSAA Name and Role properties of the given IAccessible. 54 // Verifies MSAA Name and Role properties of the given IAccessible.
88 void TestAccessibilityInfo(IAccessible* acc_obj, std::wstring name, 55 void TestAccessibilityInfo(IAccessible* acc_obj,
89 int32 role) { 56 std::wstring name,
90 // Verify MSAA Name property. 57 int32 role);
91 BSTR acc_name; 58 };
92 59
93 HRESULT hr = acc_obj->get_accName(id_self, &acc_name); 60 BrowserViewsAccessibilityTest::BrowserViewsAccessibilityTest() {
94 ASSERT_EQ(S_OK, hr); 61 ui::win::CreateATLModuleIfNeeded();
95 EXPECT_STREQ(acc_name, name.c_str()); 62 ::CoInitialize(NULL);
63 }
96 64
97 // Verify MSAA Role property. 65 BrowserViewsAccessibilityTest::~BrowserViewsAccessibilityTest() {
98 VARIANT acc_role; 66 ::CoUninitialize();
99 ::VariantInit(&acc_role); 67 }
100 68
101 hr = acc_obj->get_accRole(id_self, &acc_role); 69 BrowserWindowTesting* BrowserViewsAccessibilityTest::GetBrowserWindowTesting() {
102 ASSERT_EQ(S_OK, hr); 70 BrowserWindow* browser_window = browser()->window();
103 EXPECT_EQ(VT_I4, acc_role.vt); 71 return browser_window ? browser_window->GetBrowserWindowTesting() : NULL;
104 EXPECT_EQ(role, acc_role.lVal); 72 }
105 73
106 ::VariantClear(&acc_role); 74 BrowserView* BrowserViewsAccessibilityTest::GetBrowserView() {
107 ::SysFreeString(acc_name); 75 return BrowserView::GetBrowserViewForBrowser(browser());
108 } 76 }
109 }; 77
78 ToolbarView* BrowserViewsAccessibilityTest::GetToolbarView() {
79 BrowserWindowTesting* browser_window_testing = GetBrowserWindowTesting();
80 return browser_window_testing ?
81 browser_window_testing->GetToolbarView() : NULL;
82 }
83
84 BookmarkBarView* BrowserViewsAccessibilityTest::GetBookmarkBarView() {
85 BrowserWindowTesting* browser_window_testing = GetBrowserWindowTesting();
86 return browser_window_testing ?
87 browser_window_testing->GetBookmarkBarView() : NULL;
88 }
89
90 void BrowserViewsAccessibilityTest::TestViewAccessibilityObject(
91 views::View* view,
92 std::wstring name,
93 int32 role) {
94 ASSERT_TRUE(view != NULL);
95 TestAccessibilityInfo(view->GetNativeViewAccessible(), name, role);
96 }
97
98 void BrowserViewsAccessibilityTest::TestAccessibilityInfo(IAccessible* acc_obj,
99 std::wstring name,
100 int32 role) {
101 // Verify MSAA Name property.
102 BSTR acc_name;
103
104 HRESULT hr = acc_obj->get_accName(id_self, &acc_name);
105 ASSERT_EQ(S_OK, hr);
106 EXPECT_STREQ(acc_name, name.c_str());
107
108 // Verify MSAA Role property.
109 VARIANT acc_role;
110 ::VariantInit(&acc_role);
cpu_(ooo_6.6-7.5) 2012/09/27 19:14:36 Note that we have wrappers for variants as well.
Peter Kasting 2012/09/27 19:50:32 Awesome. I have an upcoming change to use ScopedB
111
112 hr = acc_obj->get_accRole(id_self, &acc_role);
113 ASSERT_EQ(S_OK, hr);
114 EXPECT_EQ(VT_I4, acc_role.vt);
115 EXPECT_EQ(role, acc_role.lVal);
116
117 ::VariantClear(&acc_role);
118 ::SysFreeString(acc_name);
119 }
110 120
111 // Retrieve accessibility object for main window and verify accessibility info. 121 // Retrieve accessibility object for main window and verify accessibility info.
112 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, 122 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest,
113 TestChromeWindowAccObj) { 123 TestChromeWindowAccObj) {
114 BrowserWindow* browser_window = browser()->window(); 124 BrowserWindow* browser_window = browser()->window();
115 ASSERT_TRUE(NULL != browser_window); 125 ASSERT_TRUE(NULL != browser_window);
116 126
117 HWND hwnd = browser_window->GetNativeWindow(); 127 HWND hwnd = browser_window->GetNativeWindow();
118 ASSERT_TRUE(NULL != hwnd); 128 ASSERT_TRUE(NULL != hwnd);
119 129
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 259 }
250 260
251 // http://crbug.com/104132 261 // http://crbug.com/104132
252 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, 262 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest,
253 DISABLED_TestBookmarkBarViewAccObj) { 263 DISABLED_TestBookmarkBarViewAccObj) {
254 TestViewAccessibilityObject( 264 TestViewAccessibilityObject(
255 GetBookmarkBarView(), 265 GetBookmarkBarView(),
256 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS)), 266 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS)),
257 ROLE_SYSTEM_TOOLBAR); 267 ROLE_SYSTEM_TOOLBAR);
258 } 268 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698