OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/win/scoped_bstr.h" | 7 #include "base/win/scoped_bstr.h" |
8 #include "base/win/scoped_comptr.h" | 8 #include "base/win/scoped_comptr.h" |
9 #include "base/win/scoped_variant.h" | 9 #include "base/win/scoped_variant.h" |
10 #include "third_party/iaccessible2/ia2_api_all.h" | 10 #include "third_party/iaccessible2/ia2_api_all.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 ASSERT_EQ(S_OK, textfield_accessible->get_accValue( | 74 ASSERT_EQ(S_OK, textfield_accessible->get_accValue( |
75 childid_self, value.Receive())); | 75 childid_self, value.Receive())); |
76 ASSERT_STREQ(L"Value", value); | 76 ASSERT_STREQ(L"Value", value); |
77 | 77 |
78 ScopedBstr new_value(L"New value"); | 78 ScopedBstr new_value(L"New value"); |
79 ASSERT_EQ(S_OK, textfield_accessible->put_accValue(childid_self, new_value)); | 79 ASSERT_EQ(S_OK, textfield_accessible->put_accValue(childid_self, new_value)); |
80 | 80 |
81 ASSERT_STREQ(L"New value", textfield->text().c_str()); | 81 ASSERT_STREQ(L"New value", textfield->text().c_str()); |
82 } | 82 } |
83 | 83 |
84 TEST_F(NativeViewAcccessibilityWinTest, UnattachedWebView) { | |
85 // This is a regression test. Calling get_accChild on the native accessible | |
86 // object for a WebView with no attached WebContents was causing an | |
87 // infinite loop and crash. This test simulates that with an ordinary | |
88 // View that registers itself as a web view with NativeViewAcccessibility. | |
89 | |
90 Widget widget; | |
91 Widget::InitParams init_params = | |
92 CreateParams(Widget::InitParams::TYPE_POPUP); | |
93 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
94 widget.Init(init_params); | |
95 | |
96 View* content = new View; | |
97 widget.SetContentsView(content); | |
98 | |
99 View* web_view = new View; | |
100 content->AddChildView(web_view); | |
101 NativeViewAccessibility::RegisterWebView(web_view); | |
102 | |
103 ScopedComPtr<IAccessible> web_view_accessible( | |
104 web_view->GetNativeViewAccessible()); | |
105 ScopedComPtr<IDispatch> result_dispatch; | |
106 ScopedVariant child_index(-999); | |
107 ASSERT_EQ(E_FAIL, web_view_accessible->get_accChild( | |
108 child_index, result_dispatch.Receive())); | |
109 | |
110 NativeViewAccessibility::UnregisterWebView(web_view); | |
111 } | |
112 | |
113 TEST_F(NativeViewAcccessibilityWinTest, AuraOwnedWidgets) { | 84 TEST_F(NativeViewAcccessibilityWinTest, AuraOwnedWidgets) { |
114 Widget widget; | 85 Widget widget; |
115 Widget::InitParams init_params = | 86 Widget::InitParams init_params = |
116 CreateParams(Widget::InitParams::TYPE_WINDOW); | 87 CreateParams(Widget::InitParams::TYPE_WINDOW); |
117 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 88 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
118 widget.Init(init_params); | 89 widget.Init(init_params); |
119 | 90 |
120 ScopedComPtr<IAccessible> root_view_accessible( | 91 ScopedComPtr<IAccessible> root_view_accessible( |
121 widget.GetRootView()->GetNativeViewAccessible()); | 92 widget.GetRootView()->GetNativeViewAccessible()); |
122 | 93 |
123 LONG child_count = 0; | 94 LONG child_count = 0; |
124 ASSERT_EQ(S_OK, root_view_accessible->get_accChildCount(&child_count)); | 95 ASSERT_EQ(S_OK, root_view_accessible->get_accChildCount(&child_count)); |
125 ASSERT_EQ(1L, child_count); | 96 ASSERT_EQ(1L, child_count); |
126 | 97 |
| 98 ScopedComPtr<IDispatch> child_view_dispatch; |
| 99 ScopedComPtr<IAccessible> child_view_accessible; |
| 100 ScopedVariant child_index_1(1); |
| 101 ASSERT_EQ(S_OK, root_view_accessible->get_accChild( |
| 102 child_index_1, child_view_dispatch.Receive())); |
| 103 ASSERT_EQ(S_OK, child_view_dispatch.QueryInterface( |
| 104 child_view_accessible.Receive())); |
| 105 |
127 Widget owned_widget; | 106 Widget owned_widget; |
128 Widget::InitParams owned_init_params = | 107 Widget::InitParams owned_init_params = |
129 CreateParams(Widget::InitParams::TYPE_POPUP); | 108 CreateParams(Widget::InitParams::TYPE_POPUP); |
130 owned_init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 109 owned_init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
131 owned_init_params.parent = widget.GetNativeView(); | 110 owned_init_params.parent = widget.GetNativeView(); |
132 owned_widget.Init(owned_init_params); | 111 owned_widget.Init(owned_init_params); |
133 owned_widget.Show(); | 112 owned_widget.Show(); |
134 | 113 |
135 ASSERT_EQ(S_OK, root_view_accessible->get_accChildCount(&child_count)); | 114 ASSERT_EQ(S_OK, root_view_accessible->get_accChildCount(&child_count)); |
136 ASSERT_EQ(2L, child_count); | 115 ASSERT_EQ(2L, child_count); |
| 116 |
| 117 ScopedComPtr<IDispatch> child_widget_dispatch; |
| 118 ScopedComPtr<IAccessible> child_widget_accessible; |
| 119 ScopedVariant child_index_2(2); |
| 120 ASSERT_EQ(S_OK, root_view_accessible->get_accChild( |
| 121 child_index_2, child_widget_dispatch.Receive())); |
| 122 ASSERT_EQ(S_OK, child_widget_dispatch.QueryInterface( |
| 123 child_widget_accessible.Receive())); |
| 124 |
| 125 ScopedComPtr<IDispatch> child_widget_sibling_dispatch; |
| 126 ScopedComPtr<IAccessible> child_widget_sibling_accessible; |
| 127 ScopedVariant childid_self(CHILDID_SELF); |
| 128 ScopedVariant result; |
| 129 ASSERT_EQ(S_OK, child_widget_accessible->accNavigate( |
| 130 NAVDIR_PREVIOUS, childid_self, result.Receive())); |
| 131 ASSERT_EQ(VT_DISPATCH, V_VT(&result)); |
| 132 child_widget_sibling_dispatch = V_DISPATCH(&result); |
| 133 ASSERT_EQ(S_OK, child_widget_sibling_dispatch.QueryInterface( |
| 134 child_widget_sibling_accessible.Receive())); |
| 135 ASSERT_EQ(child_view_accessible.get(), child_widget_sibling_accessible.get()); |
| 136 |
| 137 ScopedComPtr<IDispatch> child_widget_parent_dispatch; |
| 138 ScopedComPtr<IAccessible> child_widget_parent_accessible; |
| 139 ASSERT_EQ(S_OK, child_widget_accessible->get_accParent( |
| 140 child_widget_parent_dispatch.Receive())); |
| 141 ASSERT_EQ(S_OK, child_widget_parent_dispatch.QueryInterface( |
| 142 child_widget_parent_accessible.Receive())); |
| 143 ASSERT_EQ(root_view_accessible.get(), child_widget_parent_accessible.get()); |
137 } | 144 } |
138 | 145 |
139 TEST_F(NativeViewAcccessibilityWinTest, RetrieveAllAlerts) { | 146 TEST_F(NativeViewAcccessibilityWinTest, RetrieveAllAlerts) { |
140 Widget widget; | 147 Widget widget; |
141 Widget::InitParams init_params = | 148 Widget::InitParams init_params = |
142 CreateParams(Widget::InitParams::TYPE_POPUP); | 149 CreateParams(Widget::InitParams::TYPE_POPUP); |
143 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 150 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
144 widget.Init(init_params); | 151 widget.Init(init_params); |
145 | 152 |
146 View* content = new View; | 153 View* content = new View; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 delete infobar; | 202 delete infobar; |
196 ASSERT_EQ(S_OK, root_view_accessible->get_relationTargetsOfType( | 203 ASSERT_EQ(S_OK, root_view_accessible->get_relationTargetsOfType( |
197 alerts_bstr, 0, &targets, &n_targets)); | 204 alerts_bstr, 0, &targets, &n_targets)); |
198 ASSERT_EQ(1, n_targets); | 205 ASSERT_EQ(1, n_targets); |
199 ASSERT_TRUE(infobar2_accessible.IsSameObject(targets[0])); | 206 ASSERT_TRUE(infobar2_accessible.IsSameObject(targets[0])); |
200 CoTaskMemFree(targets); | 207 CoTaskMemFree(targets); |
201 } | 208 } |
202 | 209 |
203 } // namespace test | 210 } // namespace test |
204 } // namespace views | 211 } // namespace views |
OLD | NEW |