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

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

Issue 2795843002: Move implementation of accessibility actions to views::View (Closed)
Patch Set: Fix win compile Created 3 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
« no previous file with comments | « ui/views/accessibility/native_view_accessibility_base.cc ('k') | ui/views/view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/memory/ptr_util.h" 5 #include "base/memory/ptr_util.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "ui/accessibility/ax_node_data.h" 7 #include "ui/accessibility/ax_node_data.h"
8 #include "ui/gfx/geometry/rect_conversions.h" 8 #include "ui/gfx/geometry/rect_conversions.h"
9 #include "ui/views/accessibility/ax_aura_obj_cache.h" 9 #include "ui/views/accessibility/ax_aura_obj_cache.h"
10 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" 10 #include "ui/views/accessibility/ax_aura_obj_wrapper.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 NativeViewAccessibilityBase* button_accessibility() { 63 NativeViewAccessibilityBase* button_accessibility() {
64 return static_cast<NativeViewAccessibilityBase*>( 64 return static_cast<NativeViewAccessibilityBase*>(
65 button_accessibility_.get()); 65 button_accessibility_.get());
66 } 66 }
67 67
68 NativeViewAccessibilityBase* label_accessibility() { 68 NativeViewAccessibilityBase* label_accessibility() {
69 return static_cast<NativeViewAccessibilityBase*>( 69 return static_cast<NativeViewAccessibilityBase*>(
70 label_accessibility_.get()); 70 label_accessibility_.get());
71 } 71 }
72 72
73 bool SetFocused(NativeViewAccessibilityBase* view_accessibility,
74 bool focused) {
75 ui::AXActionData data;
76 data.action = focused ? ui::AX_ACTION_FOCUS : ui::AX_ACTION_BLUR;
77 return view_accessibility->AccessibilityPerformAction(data);
78 }
79
73 protected: 80 protected:
74 views::Widget* widget_; 81 views::Widget* widget_;
75 TestButton* button_; 82 TestButton* button_;
76 std::unique_ptr<NativeViewAccessibility> button_accessibility_; 83 std::unique_ptr<NativeViewAccessibility> button_accessibility_;
77 Label* label_; 84 Label* label_;
78 std::unique_ptr<NativeViewAccessibility> label_accessibility_; 85 std::unique_ptr<NativeViewAccessibility> label_accessibility_;
79 }; 86 };
80 87
81 TEST_F(NativeViewAccessibilityTest, RoleShouldMatch) { 88 TEST_F(NativeViewAccessibilityTest, RoleShouldMatch) {
82 EXPECT_EQ(ui::AX_ROLE_BUTTON, button_accessibility()->GetData().role); 89 EXPECT_EQ(ui::AX_ROLE_BUTTON, button_accessibility()->GetData().role);
(...skipping 27 matching lines...) Expand all
110 button_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE)); 117 button_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
111 EXPECT_TRUE( 118 EXPECT_TRUE(
112 label_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE)); 119 label_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
113 } 120 }
114 121
115 TEST_F(NativeViewAccessibilityTest, WritableFocus) { 122 TEST_F(NativeViewAccessibilityTest, WritableFocus) {
116 // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility. 123 // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility.
117 button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); 124 button_->SetFocusBehavior(View::FocusBehavior::ALWAYS);
118 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); 125 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView());
119 EXPECT_EQ(nullptr, button_accessibility()->GetFocus()); 126 EXPECT_EQ(nullptr, button_accessibility()->GetFocus());
120 EXPECT_TRUE(button_accessibility()->SetFocused(true)); 127 EXPECT_TRUE(SetFocused(button_accessibility(), true));
121 EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView()); 128 EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView());
122 EXPECT_EQ(button_->GetNativeViewAccessible(), 129 EXPECT_EQ(button_->GetNativeViewAccessible(),
123 button_accessibility()->GetFocus()); 130 button_accessibility()->GetFocus());
124 EXPECT_TRUE(button_accessibility()->SetFocused(false)); 131 EXPECT_TRUE(SetFocused(button_accessibility(), false));
125 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); 132 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView());
126 EXPECT_EQ(nullptr, button_accessibility()->GetFocus()); 133 EXPECT_EQ(nullptr, button_accessibility()->GetFocus());
127 134
128 // If not focusable at all, SetFocused() should return false. 135 // If not focusable at all, SetFocused() should return false.
129 button_->SetEnabled(false); 136 button_->SetEnabled(false);
130 EXPECT_FALSE(button_accessibility()->SetFocused(true)); 137 EXPECT_FALSE(SetFocused(button_accessibility(), true));
131 } 138 }
132 139
133 // Subclass of NativeViewAccessibility that destroys itself when its 140 // Subclass of NativeViewAccessibility that destroys itself when its
134 // parent widget is destroyed, for the purposes of making sure this 141 // parent widget is destroyed, for the purposes of making sure this
135 // doesn't lead to a crash. 142 // doesn't lead to a crash.
136 class TestNativeViewAccessibility : public NativeViewAccessibilityBase { 143 class TestNativeViewAccessibility : public NativeViewAccessibilityBase {
137 public: 144 public:
138 explicit TestNativeViewAccessibility(View* view) 145 explicit TestNativeViewAccessibility(View* view)
139 : NativeViewAccessibilityBase(view) {} 146 : NativeViewAccessibilityBase(view) {}
140 147
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // During the destruction of parent, OnBlur will be called and change the 232 // During the destruction of parent, OnBlur will be called and change the
226 // visibility to false. 233 // visibility to false.
227 parent->SetVisible(true); 234 parent->SetVisible(true);
228 AXAuraObjCache* ax = AXAuraObjCache::GetInstance(); 235 AXAuraObjCache* ax = AXAuraObjCache::GetInstance();
229 ax->GetOrCreate(widget.get()); 236 ax->GetOrCreate(widget.get());
230 } 237 }
231 #endif 238 #endif
232 239
233 } // namespace test 240 } // namespace test
234 } // namespace views 241 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/accessibility/native_view_accessibility_base.cc ('k') | ui/views/view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698