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

Side by Side Diff: ui/views/accessibility/native_view_accessibility_win_unittest.cc

Issue 2865713002: Remove ScopedComPtr::IsSameObject() (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « base/win/scoped_comptr_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "ui/views/accessibility/native_view_accessibility_base.h" 11 #include "ui/views/accessibility/native_view_accessibility_base.h"
12 #include "ui/views/controls/textfield/textfield.h" 12 #include "ui/views/controls/textfield/textfield.h"
13 #include "ui/views/test/views_test_base.h" 13 #include "ui/views/test/views_test_base.h"
14 14
15 using base::win::ScopedBstr; 15 using base::win::ScopedBstr;
16 using base::win::ScopedComPtr; 16 using base::win::ScopedComPtr;
17 using base::win::ScopedVariant; 17 using base::win::ScopedVariant;
18 18
19 namespace views { 19 namespace views {
20 namespace test { 20 namespace test {
21 21
22 namespace {
23
24 // Whether |left| represents the same COM object as |right|.
25 template <typename T, typename U>
26 bool IsSameObject(T* left, U* right) {
27 if (!left && !right)
28 return true;
29
30 if (!left || !right)
31 return false;
32
33 ScopedComPtr<IUnknown> left_unknown;
34 left->QueryInterface(IID_PPV_ARGS(&left_unknown));
35
36 ScopedComPtr<IUnknown> right_unknown;
37 right->QueryInterface(IID_PPV_ARGS(&right_unknown));
38
39 return left_unknown == right_unknown;
40 }
41
42 } // namespace
43
22 class NativeViewAccessibilityWinTest : public ViewsTestBase { 44 class NativeViewAccessibilityWinTest : public ViewsTestBase {
23 public: 45 public:
24 NativeViewAccessibilityWinTest() {} 46 NativeViewAccessibilityWinTest() {}
25 ~NativeViewAccessibilityWinTest() override {} 47 ~NativeViewAccessibilityWinTest() override {}
26 48
27 protected: 49 protected:
28 void GetIAccessible2InterfaceForView(View* view, IAccessible2_2** result) { 50 void GetIAccessible2InterfaceForView(View* view, IAccessible2_2** result) {
29 ScopedComPtr<IAccessible> view_accessible( 51 ScopedComPtr<IAccessible> view_accessible(
30 view->GetNativeViewAccessible()); 52 view->GetNativeViewAccessible());
31 ScopedComPtr<IServiceProvider> service_provider; 53 ScopedComPtr<IServiceProvider> service_provider;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 ASSERT_EQ(0, n_targets); 203 ASSERT_EQ(0, n_targets);
182 204
183 // Fire alert events on the infobars. 205 // Fire alert events on the infobars.
184 infobar->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 206 infobar->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
185 infobar2->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 207 infobar2->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
186 208
187 // Now calling get_relationTargetsOfType should retrieve the alerts. 209 // Now calling get_relationTargetsOfType should retrieve the alerts.
188 ASSERT_EQ(S_OK, root_view_accessible->get_relationTargetsOfType( 210 ASSERT_EQ(S_OK, root_view_accessible->get_relationTargetsOfType(
189 alerts_bstr, 0, &targets, &n_targets)); 211 alerts_bstr, 0, &targets, &n_targets));
190 ASSERT_EQ(2, n_targets); 212 ASSERT_EQ(2, n_targets);
191 ASSERT_TRUE(infobar_accessible.IsSameObject(targets[0])); 213 ASSERT_TRUE(IsSameObject(infobar_accessible.Get(), targets[0]));
192 ASSERT_TRUE(infobar2_accessible.IsSameObject(targets[1])); 214 ASSERT_TRUE(IsSameObject(infobar2_accessible.Get(), targets[1]));
193 CoTaskMemFree(targets); 215 CoTaskMemFree(targets);
194 216
195 // If we set max_targets to 1, we should only get the first one. 217 // If we set max_targets to 1, we should only get the first one.
196 ASSERT_EQ(S_OK, root_view_accessible->get_relationTargetsOfType( 218 ASSERT_EQ(S_OK, root_view_accessible->get_relationTargetsOfType(
197 alerts_bstr, 1, &targets, &n_targets)); 219 alerts_bstr, 1, &targets, &n_targets));
198 ASSERT_EQ(1, n_targets); 220 ASSERT_EQ(1, n_targets);
199 ASSERT_TRUE(infobar_accessible.IsSameObject(targets[0])); 221 ASSERT_TRUE(IsSameObject(infobar_accessible.Get(), targets[0]));
200 CoTaskMemFree(targets); 222 CoTaskMemFree(targets);
201 223
202 // If we delete the first view, we should only get the second one now. 224 // If we delete the first view, we should only get the second one now.
203 delete infobar; 225 delete infobar;
204 ASSERT_EQ(S_OK, root_view_accessible->get_relationTargetsOfType( 226 ASSERT_EQ(S_OK, root_view_accessible->get_relationTargetsOfType(
205 alerts_bstr, 0, &targets, &n_targets)); 227 alerts_bstr, 0, &targets, &n_targets));
206 ASSERT_EQ(1, n_targets); 228 ASSERT_EQ(1, n_targets);
207 ASSERT_TRUE(infobar2_accessible.IsSameObject(targets[0])); 229 ASSERT_TRUE(IsSameObject(infobar2_accessible.Get(), targets[0]));
208 CoTaskMemFree(targets); 230 CoTaskMemFree(targets);
209 } 231 }
210 232
211 // Test trying to retrieve child widgets during window close does not crash. 233 // Test trying to retrieve child widgets during window close does not crash.
212 TEST_F(NativeViewAccessibilityWinTest, GetAllOwnedWidgetsCrash) { 234 TEST_F(NativeViewAccessibilityWinTest, GetAllOwnedWidgetsCrash) {
213 Widget widget; 235 Widget widget;
214 Widget::InitParams init_params = 236 Widget::InitParams init_params =
215 CreateParams(Widget::InitParams::TYPE_WINDOW); 237 CreateParams(Widget::InitParams::TYPE_WINDOW);
216 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 238 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
217 widget.Init(init_params); 239 widget.Init(init_params);
218 widget.CloseNow(); 240 widget.CloseNow();
219 241
220 LONG child_count = 0; 242 LONG child_count = 0;
221 ScopedComPtr<IAccessible> content_accessible( 243 ScopedComPtr<IAccessible> content_accessible(
222 widget.GetRootView()->GetNativeViewAccessible()); 244 widget.GetRootView()->GetNativeViewAccessible());
223 EXPECT_EQ(S_OK, content_accessible->get_accChildCount(&child_count)); 245 EXPECT_EQ(S_OK, content_accessible->get_accChildCount(&child_count));
224 EXPECT_EQ(1L, child_count); 246 EXPECT_EQ(1L, child_count);
225 } 247 }
226 248
227 } // namespace test 249 } // namespace test
228 } // namespace views 250 } // namespace views
OLDNEW
« no previous file with comments | « base/win/scoped_comptr_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698