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

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

Issue 2601883002: MacViews/a11y: Mark Views as invisible if their parents are invisible. (Closed)
Patch Set: Switch to View::IsDrawn(). Created 3 years, 11 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.cc ('k') | no next file » | 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/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"
(...skipping 30 matching lines...) Expand all
41 41
42 button_ = new TestButton(); 42 button_ = new TestButton();
43 button_->SetSize(gfx::Size(20, 20)); 43 button_->SetSize(gfx::Size(20, 20));
44 button_accessibility_ = NativeViewAccessibility::Create(button_); 44 button_accessibility_ = NativeViewAccessibility::Create(button_);
45 45
46 label_ = new Label(); 46 label_ = new Label();
47 button_->AddChildView(label_); 47 button_->AddChildView(label_);
48 label_accessibility_ = NativeViewAccessibility::Create(label_); 48 label_accessibility_ = NativeViewAccessibility::Create(label_);
49 49
50 widget_->GetContentsView()->AddChildView(button_); 50 widget_->GetContentsView()->AddChildView(button_);
51 widget_->Show();
51 } 52 }
52 53
53 void TearDown() override { 54 void TearDown() override {
54 if (!widget_->IsClosed()) 55 if (!widget_->IsClosed())
55 widget_->Close(); 56 widget_->Close();
56 button_accessibility_->Destroy(); 57 button_accessibility_->Destroy();
57 button_accessibility_ = NULL; 58 button_accessibility_ = NULL;
58 label_accessibility_->Destroy(); 59 label_accessibility_->Destroy();
59 label_accessibility_ = NULL; 60 label_accessibility_ = NULL;
60 ViewsTestBase::TearDown(); 61 ViewsTestBase::TearDown();
(...skipping 20 matching lines...) Expand all
81 } 82 }
82 83
83 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) { 84 TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) {
84 EXPECT_EQ(1, button_accessibility_->GetChildCount()); 85 EXPECT_EQ(1, button_accessibility_->GetChildCount());
85 EXPECT_EQ(label_->GetNativeViewAccessible(), 86 EXPECT_EQ(label_->GetNativeViewAccessible(),
86 button_accessibility_->ChildAtIndex(0)); 87 button_accessibility_->ChildAtIndex(0));
87 EXPECT_EQ(button_->GetNativeViewAccessible(), 88 EXPECT_EQ(button_->GetNativeViewAccessible(),
88 label_accessibility_->GetParent()); 89 label_accessibility_->GetParent());
89 } 90 }
90 91
92 // Verify Views with invisible ancestors have AX_STATE_INVISIBLE.
93 TEST_F(NativeViewAccessibilityTest, InvisibleViews) {
94 EXPECT_TRUE(widget_->IsVisible());
95 EXPECT_FALSE(
96 button_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
97 EXPECT_FALSE(
98 label_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
99 button_->SetVisible(false);
100 EXPECT_TRUE(
101 button_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
102 EXPECT_TRUE(
103 label_accessibility_->GetData().HasStateFlag(ui::AX_STATE_INVISIBLE));
104 }
105
91 TEST_F(NativeViewAccessibilityTest, WritableFocus) { 106 TEST_F(NativeViewAccessibilityTest, WritableFocus) {
92 widget_->Show();
93 // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility. 107 // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility.
94 button_->SetFocusBehavior(View::FocusBehavior::ALWAYS); 108 button_->SetFocusBehavior(View::FocusBehavior::ALWAYS);
95 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); 109 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView());
96 EXPECT_EQ(nullptr, button_accessibility_->GetFocus()); 110 EXPECT_EQ(nullptr, button_accessibility_->GetFocus());
97 EXPECT_TRUE(button_accessibility_->SetFocused(true)); 111 EXPECT_TRUE(button_accessibility_->SetFocused(true));
98 EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView()); 112 EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView());
99 EXPECT_EQ(button_->GetNativeViewAccessible(), 113 EXPECT_EQ(button_->GetNativeViewAccessible(),
100 button_accessibility_->GetFocus()); 114 button_accessibility_->GetFocus());
101 EXPECT_TRUE(button_accessibility_->SetFocused(false)); 115 EXPECT_TRUE(button_accessibility_->SetFocused(false));
102 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView()); 116 EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // WidgetObserver. Note that TestNativeViewAccessibility is a subclass 152 // WidgetObserver. Note that TestNativeViewAccessibility is a subclass
139 // defined above that destroys itself when its parent widget is destroyed. 153 // defined above that destroys itself when its parent widget is destroyed.
140 TestNativeViewAccessibility* child_accessible = 154 TestNativeViewAccessibility* child_accessible =
141 new TestNativeViewAccessibility(child_widget->GetRootView()); 155 new TestNativeViewAccessibility(child_widget->GetRootView());
142 child_accessible->SetParentWidget(parent_widget.get()); 156 child_accessible->SetParentWidget(parent_widget.get());
143 parent_widget.reset(); 157 parent_widget.reset();
144 } 158 }
145 159
146 } // namespace test 160 } // namespace test
147 } // namespace views 161 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/accessibility/native_view_accessibility.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698