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

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

Issue 2746813002: Hide AXPlatformNode on ChromeOS. (Closed)
Patch Set: has_native_accessibility Created 3 years, 9 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 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 "ui/views/accessibility/native_view_accessibility.h"
6
7 #include "base/memory/ptr_util.h" 5 #include "base/memory/ptr_util.h"
8 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
9 #include "ui/accessibility/ax_node_data.h" 7 #include "ui/accessibility/ax_node_data.h"
10 #include "ui/gfx/geometry/rect_conversions.h" 8 #include "ui/gfx/geometry/rect_conversions.h"
11 #include "ui/views/accessibility/ax_aura_obj_cache.h" 9 #include "ui/views/accessibility/ax_aura_obj_cache.h"
12 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" 10 #include "ui/views/accessibility/ax_aura_obj_wrapper.h"
13 #include "ui/views/accessibility/ax_widget_obj_wrapper.h" 11 #include "ui/views/accessibility/ax_widget_obj_wrapper.h"
12 #include "ui/views/accessibility/native_view_accessibility_base.h"
14 #include "ui/views/controls/button/button.h" 13 #include "ui/views/controls/button/button.h"
15 #include "ui/views/controls/label.h" 14 #include "ui/views/controls/label.h"
16 #include "ui/views/test/views_test_base.h" 15 #include "ui/views/test/views_test_base.h"
17 16
18 namespace views { 17 namespace views {
19 namespace test { 18 namespace test {
20 19
21 class NativeViewAccessibilityTest; 20 class NativeViewAccessibilityTest;
22 21
23 namespace { 22 namespace {
(...skipping 30 matching lines...) Expand all
54 widget_->GetContentsView()->AddChildView(button_); 53 widget_->GetContentsView()->AddChildView(button_);
55 widget_->Show(); 54 widget_->Show();
56 } 55 }
57 56
58 void TearDown() override { 57 void TearDown() override {
59 if (!widget_->IsClosed()) 58 if (!widget_->IsClosed())
60 widget_->Close(); 59 widget_->Close();
61 ViewsTestBase::TearDown(); 60 ViewsTestBase::TearDown();
62 } 61 }
63 62
63 NativeViewAccessibilityBase* button_accessibility() {
64 return static_cast<NativeViewAccessibilityBase*>(
65 button_accessibility_.get());
66 }
67
68 NativeViewAccessibilityBase* label_accessibility() {
69 return static_cast<NativeViewAccessibilityBase*>(
70 label_accessibility_.get());
71 }
72
64 protected: 73 protected:
65 views::Widget* widget_; 74 views::Widget* widget_;
66 TestButton* button_; 75 TestButton* button_;
67 std::unique_ptr<NativeViewAccessibility> button_accessibility_; 76 std::unique_ptr<NativeViewAccessibility> button_accessibility_;
68 Label* label_; 77 Label* label_;
69 std::unique_ptr<NativeViewAccessibility> label_accessibility_; 78 std::unique_ptr<NativeViewAccessibility> label_accessibility_;
70 }; 79 };
71 80
72 TEST_F(NativeViewAccessibilityTest, RoleShouldMatch) { 81 TEST_F(NativeViewAccessibilityTest, RoleShouldMatch) {
73 EXPECT_EQ(ui::AX_ROLE_BUTTON, button_accessibility_->GetData().role); 82 EXPECT_EQ(ui::AX_ROLE_BUTTON, button_accessibility()->GetData().role);
74 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, label_accessibility_->GetData().role); 83 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, label_accessibility()->GetData().role);
75 } 84 }
76 85
77 TEST_F(NativeViewAccessibilityTest, BoundsShouldMatch) { 86 TEST_F(NativeViewAccessibilityTest, BoundsShouldMatch) {
78 gfx::Rect bounds = gfx::ToEnclosingRect( 87 gfx::Rect bounds =
79 button_accessibility_->GetData().location); 88 gfx::ToEnclosingRect(button_accessibility()->GetData().location);
80 bounds.Offset(button_accessibility_->GetGlobalCoordinateOffset()); 89 bounds.Offset(button_accessibility()->GetGlobalCoordinateOffset());
81 EXPECT_EQ(button_->GetBoundsInScreen(), bounds); 90 EXPECT_EQ(button_->GetBoundsInScreen(), bounds);
82 } 91 }
83 92
84 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) { 93 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) {
85 EXPECT_EQ(1, button_accessibility_->GetChildCount()); 94 EXPECT_EQ(1, button_accessibility()->GetChildCount());
86 EXPECT_EQ(label_->GetNativeViewAccessible(), 95 EXPECT_EQ(label_->GetNativeViewAccessible(),
87 button_accessibility_->ChildAtIndex(0)); 96 button_accessibility()->ChildAtIndex(0));
88 EXPECT_EQ(button_->GetNativeViewAccessible(), 97 EXPECT_EQ(button_->GetNativeViewAccessible(),
89 label_accessibility_->GetParent()); 98 label_accessibility()->GetParent());
90 } 99 }
91 100
92 // Verify Views with invisible ancestors have AX_STATE_INVISIBLE. 101 // Verify Views with invisible ancestors have AX_STATE_INVISIBLE.
93 TEST_F(NativeViewAccessibilityTest, InvisibleViews) { 102 TEST_F(NativeViewAccessibilityTest, InvisibleViews) {
94 EXPECT_TRUE(widget_->IsVisible()); 103 EXPECT_TRUE(widget_->IsVisible());
95 EXPECT_FALSE( 104 EXPECT_FALSE(
96 button_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE)); 105 button_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
97 EXPECT_FALSE( 106 EXPECT_FALSE(
98 label_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE)); 107 label_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
99 button_->SetVisible(false); 108 button_->SetVisible(false);
100 EXPECT_TRUE( 109 EXPECT_TRUE(
101 button_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE)); 110 button_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
102 EXPECT_TRUE( 111 EXPECT_TRUE(
103 label_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE)); 112 label_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
104 } 113 }
105 114
106 TEST_F(NativeViewAccessibilityTest, WritableFocus) { 115 TEST_F(NativeViewAccessibilityTest, WritableFocus) {
107 // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility. 116 // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility.
108 button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); 117 button_->SetFocusBehavior(View::FocusBehavior::ALWAYS);
109 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); 118 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView());
110 EXPECT_EQ(nullptr, button_accessibility_->GetFocus()); 119 EXPECT_EQ(nullptr, button_accessibility()->GetFocus());
111 EXPECT_TRUE(button_accessibility_->SetFocused(true)); 120 EXPECT_TRUE(button_accessibility()->SetFocused(true));
112 EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView()); 121 EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView());
113 EXPECT_EQ(button_->GetNativeViewAccessible(), 122 EXPECT_EQ(button_->GetNativeViewAccessible(),
114 button_accessibility_->GetFocus()); 123 button_accessibility()->GetFocus());
115 EXPECT_TRUE(button_accessibility_->SetFocused(false)); 124 EXPECT_TRUE(button_accessibility()->SetFocused(false));
116 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); 125 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView());
117 EXPECT_EQ(nullptr, button_accessibility_->GetFocus()); 126 EXPECT_EQ(nullptr, button_accessibility()->GetFocus());
118 127
119 // If not focusable at all, SetFocused() should return false. 128 // If not focusable at all, SetFocused() should return false.
120 button_->SetEnabled(false); 129 button_->SetEnabled(false);
121 EXPECT_FALSE(button_accessibility_->SetFocused(true)); 130 EXPECT_FALSE(button_accessibility()->SetFocused(true));
122 } 131 }
123 132
124 // Subclass of NativeViewAccessibility that destroys itself when its 133 // Subclass of NativeViewAccessibility that destroys itself when its
125 // parent widget is destroyed, for the purposes of making sure this 134 // parent widget is destroyed, for the purposes of making sure this
126 // doesn't lead to a crash. 135 // doesn't lead to a crash.
127 class TestNativeViewAccessibility : public NativeViewAccessibility { 136 class TestNativeViewAccessibility : public NativeViewAccessibilityBase {
128 public: 137 public:
129 explicit TestNativeViewAccessibility(View* view) 138 explicit TestNativeViewAccessibility(View* view)
130 : NativeViewAccessibility(view) {} 139 : NativeViewAccessibilityBase(view) {}
131 140
132 void OnWidgetDestroying(Widget* widget) override { 141 void OnWidgetDestroying(Widget* widget) override {
133 bool is_destroying_parent_widget = (parent_widget_ == widget); 142 bool is_destroying_parent_widget = (parent_widget_ == widget);
134 NativeViewAccessibility::OnWidgetDestroying(widget); 143 NativeViewAccessibilityBase::OnWidgetDestroying(widget);
135 if (is_destroying_parent_widget) 144 if (is_destroying_parent_widget)
136 delete this; 145 delete this;
137 } 146 }
138 }; 147 };
139 148
140 TEST_F(NativeViewAccessibilityTest, CrashOnWidgetDestroyed) { 149 TEST_F(NativeViewAccessibilityTest, CrashOnWidgetDestroyed) {
141 std::unique_ptr<Widget> parent_widget(new Widget); 150 std::unique_ptr<Widget> parent_widget(new Widget);
142 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 151 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
143 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 152 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
144 params.bounds = gfx::Rect(50, 50, 650, 650); 153 params.bounds = gfx::Rect(50, 50, 650, 650);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // During the destruction of parent, OnBlur will be called and change the 225 // During the destruction of parent, OnBlur will be called and change the
217 // visibility to false. 226 // visibility to false.
218 parent->SetVisible(true); 227 parent->SetVisible(true);
219 AXAuraObjCache* ax = AXAuraObjCache::GetInstance(); 228 AXAuraObjCache* ax = AXAuraObjCache::GetInstance();
220 ax->GetOrCreate(widget.get()); 229 ax->GetOrCreate(widget.get());
221 } 230 }
222 #endif 231 #endif
223 232
224 } // namespace test 233 } // namespace test
225 } // namespace views 234 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/accessibility/native_view_accessibility_stub.cc ('k') | ui/views/accessibility/native_view_accessibility_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698