Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/native_view_accessibility.h" | 9 #include "ui/views/accessibility/native_view_accessibility.h" |
| 10 #include "ui/views/controls/button/button.h" | 10 #include "ui/views/controls/button/button.h" |
| 11 #include "ui/views/controls/label.h" | 11 #include "ui/views/controls/label.h" |
| 12 #include "ui/views/test/views_test_base.h" | 12 #include "ui/views/test/views_test_base.h" |
| 13 #include "ui/views/widget/widget.h" | |
| 13 | 14 |
| 14 namespace views { | 15 namespace views { |
| 15 namespace test { | 16 namespace test { |
| 16 | 17 |
| 17 class NativeViewAccessibilityTest; | 18 class NativeViewAccessibilityTest; |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 class TestButton : public Button { | 22 class TestButton : public Button { |
| 22 public: | 23 public: |
| 23 TestButton() : Button(NULL) {} | 24 TestButton() : Button(NULL) {} |
| 24 }; | 25 }; |
| 25 | 26 |
| 27 // Adds a View with given bounds and focusability to a parent. Unused on Linux. | |
| 28 View* AddNewChildWithBoundsAndFocusability(View& parent, | |
| 29 gfx::Rect bounds, | |
| 30 bool focusable) { | |
| 31 View* child = new View; | |
| 32 child->SetBounds(bounds.x(), bounds.y(), bounds.width(), bounds.height()); | |
| 33 parent.AddChildView(child); | |
| 34 if (focusable) | |
| 35 child->SetFocusBehavior(ClientView::FocusBehavior::ACCESSIBLE_ONLY); | |
| 36 else | |
| 37 child->SetFocusBehavior(ClientView::FocusBehavior::NEVER); | |
| 38 return child; | |
| 39 } | |
| 40 | |
| 26 } // namespace | 41 } // namespace |
| 27 | 42 |
| 28 class NativeViewAccessibilityTest : public ViewsTestBase { | 43 class NativeViewAccessibilityTest : public ViewsTestBase { |
| 29 public: | 44 public: |
| 30 NativeViewAccessibilityTest() {} | 45 NativeViewAccessibilityTest() {} |
| 31 ~NativeViewAccessibilityTest() override {} | 46 ~NativeViewAccessibilityTest() override {} |
| 32 | 47 |
| 33 void SetUp() override { | 48 void SetUp() override { |
| 34 ViewsTestBase::SetUp(); | 49 ViewsTestBase::SetUp(); |
| 35 | 50 |
| 36 widget_ = new views::Widget; | 51 widget_ = new Widget; |
| 37 views::Widget::InitParams params = | 52 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 38 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | |
| 39 params.bounds = gfx::Rect(0, 0, 200, 200); | 53 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 40 widget_->Init(params); | 54 widget_->Init(params); |
| 41 | 55 |
| 42 button_ = new TestButton(); | 56 button_ = new TestButton(); |
| 43 button_->SetSize(gfx::Size(20, 20)); | 57 button_->SetSize(gfx::Size(20, 20)); |
| 44 button_accessibility_ = NativeViewAccessibility::Create(button_); | 58 button_accessibility_ = NativeViewAccessibility::GetOrCreate(button_); |
| 45 | 59 |
| 46 label_ = new Label(); | 60 label_ = new Label(); |
| 47 button_->AddChildView(label_); | 61 button_->AddChildView(label_); |
| 48 label_accessibility_ = NativeViewAccessibility::Create(label_); | 62 label_accessibility_ = NativeViewAccessibility::GetOrCreate(label_); |
| 49 | 63 |
| 50 widget_->GetContentsView()->AddChildView(button_); | 64 widget_->GetContentsView()->AddChildView(button_); |
| 51 } | 65 } |
| 52 | 66 |
| 53 void TearDown() override { | 67 void TearDown() override { |
| 68 // Closing the Widget will destroy all its children and their associated | |
| 69 // NativeViewAccessibility instances. | |
| 54 if (!widget_->IsClosed()) | 70 if (!widget_->IsClosed()) |
| 55 widget_->Close(); | 71 widget_->Close(); |
| 56 button_accessibility_->Destroy(); | 72 button_accessibility_ = nullptr; |
| 57 button_accessibility_ = NULL; | 73 label_accessibility_ = nullptr; |
| 58 label_accessibility_->Destroy(); | |
| 59 label_accessibility_ = NULL; | |
| 60 ViewsTestBase::TearDown(); | 74 ViewsTestBase::TearDown(); |
| 61 } | 75 } |
| 62 | 76 |
| 63 protected: | 77 protected: |
| 64 views::Widget* widget_; | 78 Widget* widget_; |
| 65 TestButton* button_; | 79 TestButton* button_; |
| 66 NativeViewAccessibility* button_accessibility_; | 80 NativeViewAccessibility* button_accessibility_; |
| 67 Label* label_; | 81 Label* label_; |
| 68 NativeViewAccessibility* label_accessibility_; | 82 NativeViewAccessibility* label_accessibility_; |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(NativeViewAccessibilityTest); | |
| 69 }; | 85 }; |
| 70 | 86 |
| 71 TEST_F(NativeViewAccessibilityTest, RoleShouldMatch) { | 87 TEST_F(NativeViewAccessibilityTest, RoleShouldMatch) { |
| 72 EXPECT_EQ(ui::AX_ROLE_BUTTON, button_accessibility_->GetData().role); | 88 EXPECT_EQ(ui::AX_ROLE_BUTTON, button_accessibility_->GetData().role); |
| 89 // Since the label is a subview of |button_|, and the button is keyboard | |
| 90 // focusable, the label is assumed to form part of the button and not have a | |
| 91 // role of its own. | |
| 92 EXPECT_EQ(ui::AX_ROLE_IGNORED, label_accessibility_->GetData().role); | |
| 93 // This will happen for all potentially keyboard-focusable Views with | |
| 94 // non-keyboard-focusable children, so if we make the button unfocusable, the | |
| 95 // label will be allowed to have its own role again. | |
| 96 button_->SetFocusBehavior(View::FocusBehavior::NEVER); | |
| 73 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, label_accessibility_->GetData().role); | 97 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, label_accessibility_->GetData().role); |
| 74 } | 98 } |
| 75 | 99 |
| 76 TEST_F(NativeViewAccessibilityTest, BoundsShouldMatch) { | 100 TEST_F(NativeViewAccessibilityTest, BoundsShouldMatch) { |
| 77 gfx::Rect bounds = gfx::ToEnclosingRect( | 101 gfx::Rect bounds = gfx::ToEnclosingRect( |
| 78 button_accessibility_->GetData().location); | 102 button_accessibility_->GetData().location); |
| 79 bounds.Offset(button_accessibility_->GetGlobalCoordinateOffset()); | 103 bounds.Offset(button_accessibility_->GetGlobalCoordinateOffset()); |
| 80 EXPECT_EQ(button_->GetBoundsInScreen(), bounds); | 104 EXPECT_EQ(button_->GetBoundsInScreen(), bounds); |
| 81 } | 105 } |
| 82 | 106 |
| 83 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) { | 107 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) { |
| 108 EXPECT_EQ(0, button_accessibility_->GetChildCount()); | |
| 109 EXPECT_EQ(nullptr, button_accessibility_->ChildAtIndex(0)); | |
| 110 EXPECT_EQ(button_->GetNativeViewAccessible(), | |
| 111 label_accessibility_->GetParent()); | |
| 112 | |
| 113 // If |button_| is no longer focusable, |label_| should show up again. | |
| 114 button_->SetFocusBehavior(View::FocusBehavior::NEVER); | |
| 84 EXPECT_EQ(1, button_accessibility_->GetChildCount()); | 115 EXPECT_EQ(1, button_accessibility_->GetChildCount()); |
| 85 EXPECT_EQ(label_->GetNativeViewAccessible(), | 116 EXPECT_EQ(label_->GetNativeViewAccessible(), |
| 86 button_accessibility_->ChildAtIndex(0)); | 117 button_accessibility_->ChildAtIndex(0)); |
| 87 EXPECT_EQ(button_->GetNativeViewAccessible(), | |
| 88 label_accessibility_->GetParent()); | |
| 89 } | 118 } |
| 90 | 119 |
| 91 TEST_F(NativeViewAccessibilityTest, WritableFocus) { | 120 TEST_F(NativeViewAccessibilityTest, WritableFocus) { |
| 92 widget_->Show(); | 121 widget_->Show(); |
| 93 // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility. | 122 // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility. |
| 94 button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); | 123 button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
| 95 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); | 124 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); |
| 96 EXPECT_EQ(nullptr, button_accessibility_->GetFocus()); | 125 EXPECT_EQ(nullptr, button_accessibility_->GetFocus()); |
| 97 EXPECT_TRUE(button_accessibility_->SetFocused(true)); | 126 EXPECT_TRUE(button_accessibility_->SetFocused(true)); |
| 98 EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView()); | 127 EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 119 bool is_destroying_parent_widget = (parent_widget_ == widget); | 148 bool is_destroying_parent_widget = (parent_widget_ == widget); |
| 120 NativeViewAccessibility::OnWidgetDestroying(widget); | 149 NativeViewAccessibility::OnWidgetDestroying(widget); |
| 121 if (is_destroying_parent_widget) | 150 if (is_destroying_parent_widget) |
| 122 delete this; | 151 delete this; |
| 123 } | 152 } |
| 124 }; | 153 }; |
| 125 | 154 |
| 126 TEST_F(NativeViewAccessibilityTest, CrashOnWidgetDestroyed) { | 155 TEST_F(NativeViewAccessibilityTest, CrashOnWidgetDestroyed) { |
| 127 std::unique_ptr<Widget> parent_widget(new Widget); | 156 std::unique_ptr<Widget> parent_widget(new Widget); |
| 128 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 157 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 129 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 158 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 130 params.bounds = gfx::Rect(50, 50, 650, 650); | 159 params.bounds = gfx::Rect(50, 50, 650, 650); |
| 131 parent_widget->Init(params); | 160 parent_widget->Init(params); |
| 132 | 161 |
| 133 std::unique_ptr<Widget> child_widget(new Widget); | 162 std::unique_ptr<Widget> child_widget(new Widget); |
| 134 child_widget->Init(params); | 163 child_widget->Init(params); |
| 135 | 164 |
| 136 // Make sure that deleting the parent widget can't cause a crash | 165 // Make sure that deleting the parent widget can't cause a crash |
| 137 // due to NativeViewAccessibility not unregistering itself as a | 166 // due to NativeViewAccessibility not unregistering itself as a |
| 138 // WidgetObserver. Note that TestNativeViewAccessibility is a subclass | 167 // WidgetObserver. Note that TestNativeViewAccessibility is a subclass |
| 139 // defined above that destroys itself when its parent widget is destroyed. | 168 // defined above that destroys itself when its parent widget is destroyed. |
| 140 TestNativeViewAccessibility* child_accessible = | 169 TestNativeViewAccessibility* child_accessible = |
| 141 new TestNativeViewAccessibility(child_widget->GetRootView()); | 170 new TestNativeViewAccessibility(child_widget->GetRootView()); |
| 142 child_accessible->SetParentWidget(parent_widget.get()); | 171 child_accessible->SetParentWidget(parent_widget.get()); |
| 143 parent_widget.reset(); | 172 parent_widget.reset(); |
| 144 } | 173 } |
| 145 | 174 |
| 175 // Separate test class for a complicated test case for ignored accessibility | |
| 176 // elements which are excluded from the accessibility tree. On Linux, these | |
| 177 // elements are not actually excluded, only marked as having an ignored role, so | |
| 178 // don't run this test case on Linux. | |
| 179 class NativeViewAccessibilityIgnoredElementsTest : public ViewsTestBase { | |
| 180 public: | |
| 181 NativeViewAccessibilityIgnoredElementsTest() {} | |
| 182 ~NativeViewAccessibilityIgnoredElementsTest() override {} | |
| 183 | |
| 184 void SetUp() override { | |
| 185 ViewsTestBase::SetUp(); | |
| 186 // Set up an accessibility tree where X-nodes should be ignored. A Views | |
| 187 // hierarchy as shown on the left should expose the accessibility tree in | |
| 188 // the middle, and respond to hit tests as shown on the right. This test | |
| 189 // is here for completeness (in practice, it's unlikely a keyboard-focusable | |
| 190 // View will be needed as a descendant of another keyboard-focusable View). | |
| 191 // | |
| 192 // A A | |
|
tapted
2016/12/22 02:56:37
I wonder if there's a naming scheme that could mak
Patti Lor
2017/01/11 02:01:48
Yeah, that sounds like a good idea, but I'd like t
| |
| 193 // / \ / | \ +++---+---+---++---+---+---+++ | |
| 194 // B X1 B F E ||| C | F | B || F | A | E ||| | |
|
tapted
2016/12/22 02:56:37
||| C | F | B || F | A | E |||
should that first
Patti Lor
2017/01/11 02:01:48
Yes, thanks for picking that up :)
| |
| 195 // / | \ / | \ / \ +++---+---+---++---+---+---+++ | |
| 196 // C D X2 X3 X4 E C D | |
| 197 // | | | |
| 198 // X5 F | |
| 199 // | |
| 200 // Note: For hit tests, the parent's bounds will be divided equally amongst | |
| 201 // its children (including ignored elements). This means all Views belonging | |
| 202 // on the same level of the Views hierarchy will be the same size. | |
| 203 a_ = new View; | |
| 204 a_->SetSize(gfx::Size(400, 20)); | |
| 205 a_->SetFocusBehavior(ClientView::FocusBehavior::ACCESSIBLE_ONLY); | |
| 206 | |
| 207 // Create Views in the left subtree from root |a_|. | |
| 208 gfx::Rect new_bounds(0, 0, a_->width() / 2, a_->height()); | |
| 209 b_ = AddNewChildWithBoundsAndFocusability(*a_, new_bounds, true); | |
| 210 // |a_| has 6 leaves, so divvy up space equally between them for hit tests. | |
| 211 new_bounds = gfx::Rect(0, 0, a_->width() / 6, a_->height()); | |
| 212 c_ = AddNewChildWithBoundsAndFocusability(*b_, new_bounds, true); | |
| 213 x5_ = AddNewChildWithBoundsAndFocusability(*c_, new_bounds, false); | |
| 214 // Update the |new_bounds| origin to position leaves next to each other. | |
| 215 new_bounds.set_x(new_bounds.x() + a_->width() / 6); | |
| 216 d_ = AddNewChildWithBoundsAndFocusability(*b_, new_bounds, true); | |
| 217 new_bounds.set_x(new_bounds.x() + a_->width() / 6); | |
| 218 x2_ = AddNewChildWithBoundsAndFocusability(*b_, new_bounds, false); | |
| 219 new_bounds.set_x(new_bounds.x() + a_->width() / 6); | |
| 220 | |
| 221 // Create Views in the right subtree from root |a_|. | |
| 222 new_bounds.set_size(b_->size()); | |
| 223 x1_ = AddNewChildWithBoundsAndFocusability(*a_, new_bounds, false); | |
| 224 new_bounds.set_origin(gfx::Point()); | |
| 225 x3_ = AddNewChildWithBoundsAndFocusability(*x1_, new_bounds, false); | |
| 226 f_ = AddNewChildWithBoundsAndFocusability(*x3_, new_bounds, true); | |
| 227 new_bounds.set_x(new_bounds.x() + a_->width() / 6); | |
| 228 x4_ = AddNewChildWithBoundsAndFocusability(*x1_, new_bounds, false); | |
| 229 new_bounds.set_x(new_bounds.x() + a_->width() / 6); | |
| 230 e_ = AddNewChildWithBoundsAndFocusability(*x1_, new_bounds, true); | |
| 231 | |
| 232 // Populate NativeViewAccessibility instances for convenience. | |
| 233 a_ax_ = NativeViewAccessibility::GetOrCreate(a_); | |
| 234 b_ax_ = NativeViewAccessibility::GetOrCreate(b_); | |
| 235 c_ax_ = NativeViewAccessibility::GetOrCreate(c_); | |
| 236 d_ax_ = NativeViewAccessibility::GetOrCreate(d_); | |
| 237 e_ax_ = NativeViewAccessibility::GetOrCreate(e_); | |
| 238 f_ax_ = NativeViewAccessibility::GetOrCreate(f_); | |
| 239 x1_ax_ = NativeViewAccessibility::GetOrCreate(x1_); | |
| 240 x2_ax_ = NativeViewAccessibility::GetOrCreate(x2_); | |
| 241 x3_ax_ = NativeViewAccessibility::GetOrCreate(x3_); | |
| 242 x4_ax_ = NativeViewAccessibility::GetOrCreate(x4_); | |
| 243 x5_ax_ = NativeViewAccessibility::GetOrCreate(x5_); | |
| 244 | |
| 245 // Add everything to a new widget, needed for hit testing and parent tests. | |
| 246 widget_ = new Widget; | |
| 247 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | |
| 248 widget_->Init(params); | |
| 249 widget_->GetContentsView()->AddChildView(a_); | |
| 250 widget_->Show(); | |
| 251 } | |
| 252 | |
| 253 void TearDown() override { | |
| 254 widget_->Close(); | |
| 255 ViewsTestBase::TearDown(); | |
| 256 } | |
| 257 | |
| 258 protected: | |
| 259 // Don't use std::unique_ptr for the following Views - everything will be | |
| 260 // inside a widget, which will handle their deletion. | |
|
tapted
2016/12/22 02:56:37
You can just say
// Owned by |widget_|.
Patti Lor
2017/01/11 02:01:48
Done.
| |
| 261 View* a_; | |
| 262 View* b_; | |
| 263 View* c_; | |
| 264 View* d_; | |
| 265 View* e_; | |
| 266 View* f_; | |
| 267 View* x1_; | |
| 268 View* x2_; | |
| 269 View* x3_; | |
| 270 View* x4_; | |
| 271 View* x5_; | |
| 272 | |
| 273 // Destroyed when the View they are attached to is destroyed. | |
| 274 NativeViewAccessibility* a_ax_; | |
| 275 NativeViewAccessibility* b_ax_; | |
| 276 NativeViewAccessibility* c_ax_; | |
| 277 NativeViewAccessibility* d_ax_; | |
| 278 NativeViewAccessibility* e_ax_; | |
| 279 NativeViewAccessibility* f_ax_; | |
| 280 NativeViewAccessibility* x1_ax_; | |
| 281 NativeViewAccessibility* x2_ax_; | |
| 282 NativeViewAccessibility* x3_ax_; | |
| 283 NativeViewAccessibility* x4_ax_; | |
| 284 NativeViewAccessibility* x5_ax_; | |
| 285 | |
| 286 Widget* widget_ = nullptr; | |
| 287 | |
| 288 private: | |
| 289 DISALLOW_COPY_AND_ASSIGN(NativeViewAccessibilityIgnoredElementsTest); | |
| 290 }; | |
| 291 | |
| 292 TEST_F(NativeViewAccessibilityIgnoredElementsTest, GetChildCount) { | |
|
tapted
2016/12/22 02:56:37
nit: all these should have a brief comment before
Patti Lor
2017/01/11 02:01:48
Done.
| |
| 293 EXPECT_EQ(3, a_ax_->GetChildCount()); | |
| 294 EXPECT_EQ(2, b_ax_->GetChildCount()); | |
| 295 EXPECT_EQ(0, c_ax_->GetChildCount()); | |
|
tapted
2016/12/22 02:56:37
Perhaps just comment that this is a leaf? Then I t
Patti Lor
2017/01/11 02:01:48
Done.
| |
| 296 EXPECT_EQ(0, x5_ax_->GetChildCount()); | |
| 297 EXPECT_EQ(0, d_ax_->GetChildCount()); | |
| 298 EXPECT_EQ(0, x2_ax_->GetChildCount()); | |
| 299 EXPECT_EQ(2, x1_ax_->GetChildCount()); | |
| 300 EXPECT_EQ(1, x3_ax_->GetChildCount()); | |
| 301 EXPECT_EQ(0, f_ax_->GetChildCount()); | |
| 302 EXPECT_EQ(0, x4_ax_->GetChildCount()); | |
| 303 EXPECT_EQ(0, e_ax_->GetChildCount()); | |
| 304 } | |
| 305 | |
| 306 TEST_F(NativeViewAccessibilityIgnoredElementsTest, ChildAtIndex) { | |
| 307 EXPECT_EQ(b_->GetNativeViewAccessible(), a_ax_->ChildAtIndex(0)); | |
| 308 EXPECT_EQ(f_->GetNativeViewAccessible(), a_ax_->ChildAtIndex(1)); | |
| 309 EXPECT_EQ(e_->GetNativeViewAccessible(), a_ax_->ChildAtIndex(2)); | |
| 310 EXPECT_EQ(nullptr, a_ax_->ChildAtIndex(3)); | |
| 311 | |
| 312 EXPECT_EQ(c_->GetNativeViewAccessible(), b_ax_->ChildAtIndex(0)); | |
| 313 EXPECT_EQ(d_->GetNativeViewAccessible(), b_ax_->ChildAtIndex(1)); | |
| 314 EXPECT_EQ(nullptr, b_ax_->ChildAtIndex(2)); | |
| 315 | |
| 316 EXPECT_EQ(f_->GetNativeViewAccessible(), x1_ax_->ChildAtIndex(0)); | |
| 317 EXPECT_EQ(e_->GetNativeViewAccessible(), x1_ax_->ChildAtIndex(1)); | |
| 318 EXPECT_EQ(nullptr, x1_ax_->ChildAtIndex(2)); | |
| 319 | |
| 320 EXPECT_EQ(f_->GetNativeViewAccessible(), x3_ax_->ChildAtIndex(0)); | |
| 321 | |
| 322 // Node with ignored children. | |
| 323 EXPECT_EQ(nullptr, c_ax_->ChildAtIndex(0)); | |
| 324 // Node with 0 children. | |
| 325 EXPECT_EQ(nullptr, d_ax_->ChildAtIndex(0)); | |
| 326 // Ignored node with 0 children. | |
| 327 EXPECT_EQ(nullptr, x2_ax_->ChildAtIndex(0)); | |
| 328 } | |
| 329 | |
| 330 TEST_F(NativeViewAccessibilityIgnoredElementsTest, GetParent) { | |
| 331 EXPECT_EQ(a_->parent()->GetNativeViewAccessible(), a_ax_->GetParent()); | |
| 332 EXPECT_EQ(a_->GetNativeViewAccessible(), b_ax_->GetParent()); | |
| 333 EXPECT_EQ(b_->GetNativeViewAccessible(), c_ax_->GetParent()); | |
| 334 EXPECT_EQ(c_->GetNativeViewAccessible(), x5_ax_->GetParent()); | |
| 335 EXPECT_EQ(b_->GetNativeViewAccessible(), d_ax_->GetParent()); | |
| 336 EXPECT_EQ(b_->GetNativeViewAccessible(), x2_ax_->GetParent()); | |
| 337 | |
| 338 EXPECT_EQ(a_->GetNativeViewAccessible(), x1_ax_->GetParent()); | |
| 339 EXPECT_EQ(a_->GetNativeViewAccessible(), x3_ax_->GetParent()); | |
| 340 EXPECT_EQ(a_->GetNativeViewAccessible(), x4_ax_->GetParent()); | |
| 341 EXPECT_EQ(a_->GetNativeViewAccessible(), e_ax_->GetParent()); | |
| 342 EXPECT_EQ(a_->GetNativeViewAccessible(), f_ax_->GetParent()); | |
|
tapted
2016/12/22 02:56:37
These need comments to describe what's happening.
Patti Lor
2017/01/11 02:01:48
Done.
| |
| 343 } | |
| 344 | |
| 345 TEST_F(NativeViewAccessibilityIgnoredElementsTest, IsLeafElement) { | |
| 346 EXPECT_FALSE(a_ax_->GetChildCount() == 0); | |
|
tapted
2016/12/22 02:56:36
EXPECT_NE (or _EQ with the actual number?)
Patti Lor
2017/01/11 02:01:48
Deleted this test as you suggested previously.
| |
| 347 EXPECT_FALSE(b_ax_->GetChildCount() == 0); | |
| 348 EXPECT_TRUE(c_ax_->GetChildCount() == 0); | |
|
tapted
2016/12/22 02:56:37
EXPECT_EQ
Patti Lor
2017/01/11 02:01:48
Acknowledged.
| |
| 349 EXPECT_TRUE(d_ax_->GetChildCount() == 0); | |
| 350 EXPECT_TRUE(e_ax_->GetChildCount() == 0); | |
| 351 EXPECT_TRUE(f_ax_->GetChildCount() == 0); | |
| 352 EXPECT_FALSE(x1_ax_->GetChildCount() == 0); | |
| 353 EXPECT_TRUE(x2_ax_->GetChildCount() == 0); | |
| 354 EXPECT_FALSE(x3_ax_->GetChildCount() == 0); | |
| 355 EXPECT_TRUE(x4_ax_->GetChildCount() == 0); | |
| 356 EXPECT_TRUE(x5_ax_->GetChildCount() == 0); | |
| 357 } | |
| 358 | |
| 359 TEST_F(NativeViewAccessibilityIgnoredElementsTest, HitTestSync) { | |
| 360 // Move the hit point horizontally, incrementing by the leaf View width. | |
| 361 int min_width = a_->GetBoundsInScreen().width() / 6; | |
|
tapted
2016/12/22 02:56:37
const?
Patti Lor
2017/01/11 02:01:48
Done.
| |
| 362 int curr_x = a_->GetBoundsInScreen().x() + min_width / 2; | |
| 363 const int y = a_->GetBoundsInScreen().CenterPoint().y(); | |
| 364 | |
| 365 // HitTestSync isn't recursive, so manually do the recursion until arriving at | |
|
dmazzoni
2016/12/28 18:02:35
How about a helper that calls HitTestSync until re
Patti Lor
2017/01/11 02:01:48
I'm not sure the helper is a good idea - it still
| |
| 366 // the correct answer. I.e., the last NativeViewAccessible being tested for | |
| 367 // each |curr_x|, |y| pair below would be the correct return value if | |
| 368 // HitTestSync were recursive. | |
| 369 EXPECT_EQ(b_->GetNativeViewAccessible(), a_ax_->HitTestSync(curr_x, y)); | |
| 370 EXPECT_EQ(c_->GetNativeViewAccessible(), b_ax_->HitTestSync(curr_x, y)); | |
| 371 EXPECT_EQ(c_->GetNativeViewAccessible(), c_ax_->HitTestSync(curr_x, y)); | |
| 372 curr_x += min_width; | |
| 373 EXPECT_EQ(b_->GetNativeViewAccessible(), a_ax_->HitTestSync(curr_x, y)); | |
| 374 EXPECT_EQ(d_->GetNativeViewAccessible(), b_ax_->HitTestSync(curr_x, y)); | |
| 375 curr_x += min_width; | |
| 376 EXPECT_EQ(b_->GetNativeViewAccessible(), a_ax_->HitTestSync(curr_x, y)); | |
| 377 EXPECT_EQ(x2_->GetNativeViewAccessible(), b_ax_->HitTestSync(curr_x, y)); | |
| 378 EXPECT_EQ(b_->GetNativeViewAccessible(), x2_ax_->HitTestSync(curr_x, y)); | |
| 379 curr_x += min_width; | |
| 380 EXPECT_EQ(x1_->GetNativeViewAccessible(), a_ax_->HitTestSync(curr_x, y)); | |
| 381 EXPECT_EQ(x3_->GetNativeViewAccessible(), x1_ax_->HitTestSync(curr_x, y)); | |
| 382 EXPECT_EQ(f_->GetNativeViewAccessible(), x3_ax_->HitTestSync(curr_x, y)); | |
| 383 curr_x += min_width; | |
| 384 EXPECT_EQ(x1_->GetNativeViewAccessible(), a_ax_->HitTestSync(curr_x, y)); | |
| 385 EXPECT_EQ(x4_->GetNativeViewAccessible(), x1_ax_->HitTestSync(curr_x, y)); | |
| 386 EXPECT_EQ(a_->GetNativeViewAccessible(), x4_ax_->HitTestSync(curr_x, y)); | |
| 387 curr_x += min_width; | |
| 388 EXPECT_EQ(x1_->GetNativeViewAccessible(), a_ax_->HitTestSync(curr_x, y)); | |
| 389 EXPECT_EQ(e_->GetNativeViewAccessible(), x1_ax_->HitTestSync(curr_x, y)); | |
| 390 | |
| 391 // If |e_| and |a_| are no longer focusable, |a_|, |x1_|, and |e_| become | |
| 392 // are no longer ignored and |x1_| is revealed in hit testing (covers up the | |
| 393 // the hit coordinates occupied by |a_|). | |
| 394 a_->SetFocusBehavior(ClientView::FocusBehavior::NEVER); | |
| 395 e_->SetFocusBehavior(ClientView::FocusBehavior::NEVER); | |
| 396 EXPECT_EQ(x1_->GetNativeViewAccessible(), a_ax_->HitTestSync(curr_x, y)); | |
| 397 EXPECT_EQ(e_->GetNativeViewAccessible(), x1_ax_->HitTestSync(curr_x, y)); | |
| 398 EXPECT_EQ(e_->GetNativeViewAccessible(), e_ax_->HitTestSync(curr_x, y)); | |
| 399 } | |
| 400 | |
| 146 } // namespace test | 401 } // namespace test |
| 147 } // namespace views | 402 } // namespace views |
| OLD | NEW |