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

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

Issue 2746813002: Hide AXPlatformNode on ChromeOS. (Closed)
Patch Set: fix stub 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" 5 #include "ui/views/accessibility/native_view_accessibility.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "ui/accessibility/ax_node_data.h" 9 #include "ui/accessibility/ax_node_data.h"
10 #include "ui/gfx/geometry/rect_conversions.h" 10 #include "ui/gfx/geometry/rect_conversions.h"
(...skipping 27 matching lines...) Expand all
38 ViewsTestBase::SetUp(); 38 ViewsTestBase::SetUp();
39 39
40 widget_ = new views::Widget; 40 widget_ = new views::Widget;
41 views::Widget::InitParams params = 41 views::Widget::InitParams params =
42 CreateParams(views::Widget::InitParams::TYPE_WINDOW); 42 CreateParams(views::Widget::InitParams::TYPE_WINDOW);
43 params.bounds = gfx::Rect(0, 0, 200, 200); 43 params.bounds = gfx::Rect(0, 0, 200, 200);
44 widget_->Init(params); 44 widget_->Init(params);
45 45
46 button_ = new TestButton(); 46 button_ = new TestButton();
47 button_->SetSize(gfx::Size(20, 20)); 47 button_->SetSize(gfx::Size(20, 20));
48 button_accessibility_ = NativeViewAccessibility::Create(button_); 48 button_accessibility_ = NativeViewAccessibilityBase::Create(button_);
49 49
50 label_ = new Label(); 50 label_ = new Label();
51 button_->AddChildView(label_); 51 button_->AddChildView(label_);
52 label_accessibility_ = NativeViewAccessibility::Create(label_); 52 label_accessibility_ = NativeViewAccessibilityBase::Create(label_);
53 53
54 widget_->GetContentsView()->AddChildView(button_); 54 widget_->GetContentsView()->AddChildView(button_);
55 widget_->Show(); 55 widget_->Show();
56 } 56 }
57 57
58 void TearDown() override { 58 void TearDown() override {
59 if (!widget_->IsClosed()) 59 if (!widget_->IsClosed())
60 widget_->Close(); 60 widget_->Close();
61 ViewsTestBase::TearDown(); 61 ViewsTestBase::TearDown();
62 } 62 }
63 63
64 NativeViewAccessibility* button_accessibility() {
65 return static_cast<NativeViewAccessibility*>(button_accessibility_.get());
66 }
67
68 NativeViewAccessibility* label_accessibility() {
69 return static_cast<NativeViewAccessibility*>(label_accessibility_.get());
70 }
71
64 protected: 72 protected:
65 views::Widget* widget_; 73 views::Widget* widget_;
66 TestButton* button_; 74 TestButton* button_;
67 std::unique_ptr<NativeViewAccessibility> button_accessibility_; 75 std::unique_ptr<NativeViewAccessibilityBase> button_accessibility_;
68 Label* label_; 76 Label* label_;
69 std::unique_ptr<NativeViewAccessibility> label_accessibility_; 77 std::unique_ptr<NativeViewAccessibilityBase> label_accessibility_;
70 }; 78 };
71 79
72 TEST_F(NativeViewAccessibilityTest, RoleShouldMatch) { 80 TEST_F(NativeViewAccessibilityTest, RoleShouldMatch) {
73 EXPECT_EQ(ui::AX_ROLE_BUTTON, button_accessibility_->GetData().role); 81 EXPECT_EQ(ui::AX_ROLE_BUTTON, button_accessibility()->GetData().role);
74 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, label_accessibility_->GetData().role); 82 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, label_accessibility()->GetData().role);
75 } 83 }
76 84
77 TEST_F(NativeViewAccessibilityTest, BoundsShouldMatch) { 85 TEST_F(NativeViewAccessibilityTest, BoundsShouldMatch) {
78 gfx::Rect bounds = gfx::ToEnclosingRect( 86 gfx::Rect bounds =
79 button_accessibility_->GetData().location); 87 gfx::ToEnclosingRect(button_accessibility()->GetData().location);
80 bounds.Offset(button_accessibility_->GetGlobalCoordinateOffset()); 88 bounds.Offset(button_accessibility()->GetGlobalCoordinateOffset());
81 EXPECT_EQ(button_->GetBoundsInScreen(), bounds); 89 EXPECT_EQ(button_->GetBoundsInScreen(), bounds);
82 } 90 }
83 91
84 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) { 92 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) {
85 EXPECT_EQ(1, button_accessibility_->GetChildCount()); 93 EXPECT_EQ(1, button_accessibility()->GetChildCount());
86 EXPECT_EQ(label_->GetNativeViewAccessible(), 94 EXPECT_EQ(label_->GetNativeViewAccessible(),
87 button_accessibility_->ChildAtIndex(0)); 95 button_accessibility()->ChildAtIndex(0));
88 EXPECT_EQ(button_->GetNativeViewAccessible(), 96 EXPECT_EQ(button_->GetNativeViewAccessible(),
89 label_accessibility_->GetParent()); 97 label_accessibility()->GetParent());
90 } 98 }
91 99
92 // Verify Views with invisible ancestors have AX_STATE_INVISIBLE. 100 // Verify Views with invisible ancestors have AX_STATE_INVISIBLE.
93 TEST_F(NativeViewAccessibilityTest, InvisibleViews) { 101 TEST_F(NativeViewAccessibilityTest, InvisibleViews) {
94 EXPECT_TRUE(widget_->IsVisible()); 102 EXPECT_TRUE(widget_->IsVisible());
95 EXPECT_FALSE( 103 EXPECT_FALSE(
96 button_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE)); 104 button_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
97 EXPECT_FALSE( 105 EXPECT_FALSE(
98 label_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE)); 106 label_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
99 button_->SetVisible(false); 107 button_->SetVisible(false);
100 EXPECT_TRUE( 108 EXPECT_TRUE(
101 button_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE)); 109 button_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
102 EXPECT_TRUE( 110 EXPECT_TRUE(
103 label_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE)); 111 label_accessibility()->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
104 } 112 }
105 113
106 TEST_F(NativeViewAccessibilityTest, WritableFocus) { 114 TEST_F(NativeViewAccessibilityTest, WritableFocus) {
107 // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility. 115 // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility.
108 button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); 116 button_->SetFocusBehavior(View::FocusBehavior::ALWAYS);
109 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); 117 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView());
110 EXPECT_EQ(nullptr, button_accessibility_->GetFocus()); 118 EXPECT_EQ(nullptr, button_accessibility()->GetFocus());
111 EXPECT_TRUE(button_accessibility_->SetFocused(true)); 119 EXPECT_TRUE(button_accessibility()->SetFocused(true));
112 EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView()); 120 EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView());
113 EXPECT_EQ(button_->GetNativeViewAccessible(), 121 EXPECT_EQ(button_->GetNativeViewAccessible(),
114 button_accessibility_->GetFocus()); 122 button_accessibility()->GetFocus());
115 EXPECT_TRUE(button_accessibility_->SetFocused(false)); 123 EXPECT_TRUE(button_accessibility()->SetFocused(false));
116 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); 124 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView());
117 EXPECT_EQ(nullptr, button_accessibility_->GetFocus()); 125 EXPECT_EQ(nullptr, button_accessibility()->GetFocus());
118 126
119 // If not focusable at all, SetFocused() should return false. 127 // If not focusable at all, SetFocused() should return false.
120 button_->SetEnabled(false); 128 button_->SetEnabled(false);
121 EXPECT_FALSE(button_accessibility_->SetFocused(true)); 129 EXPECT_FALSE(button_accessibility()->SetFocused(true));
122 } 130 }
123 131
124 // Subclass of NativeViewAccessibility that destroys itself when its 132 // Subclass of NativeViewAccessibility that destroys itself when its
125 // parent widget is destroyed, for the purposes of making sure this 133 // parent widget is destroyed, for the purposes of making sure this
126 // doesn't lead to a crash. 134 // doesn't lead to a crash.
127 class TestNativeViewAccessibility : public NativeViewAccessibility { 135 class TestNativeViewAccessibility : public NativeViewAccessibility {
128 public: 136 public:
129 explicit TestNativeViewAccessibility(View* view) 137 explicit TestNativeViewAccessibility(View* view)
130 : NativeViewAccessibility(view) {} 138 : NativeViewAccessibility(view) {}
131 139
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // During the destruction of parent, OnBlur will be called and change the 224 // During the destruction of parent, OnBlur will be called and change the
217 // visibility to false. 225 // visibility to false.
218 parent->SetVisible(true); 226 parent->SetVisible(true);
219 AXAuraObjCache* ax = AXAuraObjCache::GetInstance(); 227 AXAuraObjCache* ax = AXAuraObjCache::GetInstance();
220 ax->GetOrCreate(widget.get()); 228 ax->GetOrCreate(widget.get());
221 } 229 }
222 #endif 230 #endif
223 231
224 } // namespace test 232 } // namespace test
225 } // namespace views 233 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698