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/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 6 #include "ui/accessibility/ax_node_data.h" | 7 #include "ui/accessibility/ax_node_data.h" |
| 7 #include "ui/gfx/geometry/rect_conversions.h" | 8 #include "ui/gfx/geometry/rect_conversions.h" |
| 8 #include "ui/views/accessibility/native_view_accessibility.h" | 9 #include "ui/views/accessibility/native_view_accessibility.h" |
| 9 #include "ui/views/controls/button/button.h" | 10 #include "ui/views/controls/button/button.h" |
| 10 #include "ui/views/controls/label.h" | 11 #include "ui/views/controls/label.h" |
| 11 #include "ui/views/test/views_test_base.h" | 12 #include "ui/views/test/views_test_base.h" |
| 12 | 13 |
| 13 namespace views { | 14 namespace views { |
| 14 namespace test { | 15 namespace test { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 } | 81 } |
| 81 | 82 |
| 82 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) { | 83 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) { |
| 83 EXPECT_EQ(1, button_accessibility_->GetChildCount()); | 84 EXPECT_EQ(1, button_accessibility_->GetChildCount()); |
| 84 EXPECT_EQ(label_->GetNativeViewAccessible(), | 85 EXPECT_EQ(label_->GetNativeViewAccessible(), |
| 85 button_accessibility_->ChildAtIndex(0)); | 86 button_accessibility_->ChildAtIndex(0)); |
| 86 EXPECT_EQ(button_->GetNativeViewAccessible(), | 87 EXPECT_EQ(button_->GetNativeViewAccessible(), |
| 87 label_accessibility_->GetParent()); | 88 label_accessibility_->GetParent()); |
| 88 } | 89 } |
| 89 | 90 |
| 91 TEST_F(NativeViewAccessibilityTest, WritableFocus) { | |
| 92 // Dealing with focus here, so add things into a Widget. | |
| 93 std::unique_ptr<Widget> widget = base::MakeUnique<Widget>(); | |
|
tapted
2016/11/11 00:36:25
NativeViewAccessibilityTest already has a |widget_
Patti Lor
2016/11/14 03:51:21
Ah, thank you! I think it got all mixed up in a re
| |
| 94 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | |
| 95 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 96 widget->Init(params); | |
| 97 widget->GetContentsView()->AddChildView(button_); | |
| 98 widget->Show(); | |
| 99 | |
| 100 // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility. | |
| 101 button_->SetFocusBehavior(ClientView::FocusBehavior::ALWAYS); | |
|
tapted
2016/11/11 00:36:25
ClientView -> View
Patti Lor
2016/11/14 03:51:21
Done.
| |
| 102 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); | |
| 103 EXPECT_EQ(nullptr, button_accessibility_->GetFocus()); | |
| 104 EXPECT_TRUE(button_accessibility_->SetFocused(true)); | |
| 105 EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView()); | |
| 106 EXPECT_EQ(button_->GetNativeViewAccessible(), | |
| 107 button_accessibility_->GetFocus()); | |
| 108 EXPECT_TRUE(button_accessibility_->SetFocused(false)); | |
| 109 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); | |
| 110 EXPECT_EQ(nullptr, button_accessibility_->GetFocus()); | |
| 111 | |
| 112 // If not focusable at all, SetFocused() should return false. | |
| 113 button_->SetEnabled(false); | |
| 114 EXPECT_FALSE(button_accessibility_->SetFocused(true)); | |
| 115 | |
| 116 // Avoid deleting |label_|/|button_| twice since they're already unique_ptrs. | |
| 117 widget->GetContentsView()->RemoveChildView(button_); | |
|
tapted
2016/11/11 00:36:25
this shouldn't be necessary... And I'm not sure th
Patti Lor
2016/11/14 03:51:21
Yep, not necessary - originally had it that way in
| |
| 118 } | |
| 119 | |
| 90 // Subclass of NativeViewAccessibility that destroys itself when its | 120 // Subclass of NativeViewAccessibility that destroys itself when its |
| 91 // parent widget is destroyed, for the purposes of making sure this | 121 // parent widget is destroyed, for the purposes of making sure this |
| 92 // doesn't lead to a crash. | 122 // doesn't lead to a crash. |
| 93 class TestNativeViewAccessibility : public NativeViewAccessibility { | 123 class TestNativeViewAccessibility : public NativeViewAccessibility { |
| 94 public: | 124 public: |
| 95 explicit TestNativeViewAccessibility(View* view) | 125 explicit TestNativeViewAccessibility(View* view) |
| 96 : NativeViewAccessibility(view) {} | 126 : NativeViewAccessibility(view) {} |
| 97 | 127 |
| 98 void OnWidgetDestroying(Widget* widget) override { | 128 void OnWidgetDestroying(Widget* widget) override { |
| 99 bool is_destroying_parent_widget = (parent_widget_ == widget); | 129 bool is_destroying_parent_widget = (parent_widget_ == widget); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 118 // WidgetObserver. Note that TestNativeViewAccessibility is a subclass | 148 // WidgetObserver. Note that TestNativeViewAccessibility is a subclass |
| 119 // defined above that destroys itself when its parent widget is destroyed. | 149 // defined above that destroys itself when its parent widget is destroyed. |
| 120 TestNativeViewAccessibility* child_accessible = | 150 TestNativeViewAccessibility* child_accessible = |
| 121 new TestNativeViewAccessibility(child_widget->GetRootView()); | 151 new TestNativeViewAccessibility(child_widget->GetRootView()); |
| 122 child_accessible->SetParentWidget(parent_widget.get()); | 152 child_accessible->SetParentWidget(parent_widget.get()); |
| 123 parent_widget.reset(); | 153 parent_widget.reset(); |
| 124 } | 154 } |
| 125 | 155 |
| 126 } // namespace test | 156 } // namespace test |
| 127 } // namespace views | 157 } // namespace views |
| OLD | NEW |