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

Unified Diff: ui/views/accessibility/native_view_accessibility_unittest.cc

Issue 2490073002: MacViews/a11y: Allow accessibility clients to focus and unfocus focusable Views. (Closed)
Patch Set: Use CreateParams and MakeUnique. Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/accessibility/native_view_accessibility_unittest.cc
diff --git a/ui/views/accessibility/native_view_accessibility_unittest.cc b/ui/views/accessibility/native_view_accessibility_unittest.cc
index 88d9216815e2b48e063cd7e1cc4ca4b1a8dfc340..17e3ad6706862c7b2c1ff7a38193910a2670f4bc 100644
--- a/ui/views/accessibility/native_view_accessibility_unittest.cc
+++ b/ui/views/accessibility/native_view_accessibility_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/gfx/geometry/rect_conversions.h"
@@ -87,6 +88,35 @@ TEST_F(NativeViewAccessibilityTest, LabelIsChildOfButton) {
label_accessibility_->GetParent());
}
+TEST_F(NativeViewAccessibilityTest, WritableFocus) {
+ // Dealing with focus here, so add things into a Widget.
+ 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
+ Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
+ params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ widget->Init(params);
+ widget->GetContentsView()->AddChildView(button_);
+ widget->Show();
+
+ // Make |button_| focusable, and focus/unfocus it via NativeViewAccessibility.
+ button_->SetFocusBehavior(ClientView::FocusBehavior::ALWAYS);
tapted 2016/11/11 00:36:25 ClientView -> View
Patti Lor 2016/11/14 03:51:21 Done.
+ EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView());
+ EXPECT_EQ(nullptr, button_accessibility_->GetFocus());
+ EXPECT_TRUE(button_accessibility_->SetFocused(true));
+ EXPECT_EQ(button_, button_->GetFocusManager()->GetFocusedView());
+ EXPECT_EQ(button_->GetNativeViewAccessible(),
+ button_accessibility_->GetFocus());
+ EXPECT_TRUE(button_accessibility_->SetFocused(false));
+ EXPECT_EQ(nullptr, button_->GetFocusManager()->GetFocusedView());
+ EXPECT_EQ(nullptr, button_accessibility_->GetFocus());
+
+ // If not focusable at all, SetFocused() should return false.
+ button_->SetEnabled(false);
+ EXPECT_FALSE(button_accessibility_->SetFocused(true));
+
+ // Avoid deleting |label_|/|button_| twice since they're already unique_ptrs.
+ 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
+}
+
// Subclass of NativeViewAccessibility that destroys itself when its
// parent widget is destroyed, for the purposes of making sure this
// doesn't lead to a crash.

Powered by Google App Engine
This is Rietveld 408576698