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

Unified Diff: ui/views/focus/focus_manager_unittest.cc

Issue 1690543004: MacViews: Implement Full Keyboard Access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/focus/focus_manager_unittest.cc
diff --git a/ui/views/focus/focus_manager_unittest.cc b/ui/views/focus/focus_manager_unittest.cc
index 96eb42fcf32bf8a5bbc4286bc0a602319ef2d4cc..2649fef03909bf0018f59b3d4990fe06aec43286 100644
--- a/ui/views/focus/focus_manager_unittest.cc
+++ b/ui/views/focus/focus_manager_unittest.cc
@@ -43,7 +43,7 @@ class SimpleTestView : public View {
public:
SimpleTestView(std::vector<FocusTestEvent>* event_list, int view_id)
: event_list_(event_list) {
- SetFocusable(true);
+ SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
set_id(view_id);
}
@@ -95,9 +95,9 @@ TEST_F(FocusManagerTest, ViewFocusCallbacks) {
TEST_F(FocusManagerTest, FocusChangeListener) {
View* view1 = new View();
- view1->SetFocusable(true);
+ view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
View* view2 = new View();
- view2->SetFocusable(true);
+ view2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
GetContentsView()->AddChildView(view1);
GetContentsView()->AddChildView(view2);
@@ -602,17 +602,17 @@ TEST_F(FocusManagerTest, FocusInAboutToRequestFocusFromTabTraversal) {
// Create 3 views focuses the 3 and advances to the second. The 2nd views
// implementation of AboutToRequestFocusFromTabTraversal() focuses the first.
views::View* v1 = new View;
- v1->SetFocusable(true);
+ v1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
GetContentsView()->AddChildView(v1);
FocusInAboutToRequestFocusFromTabTraversalView* v2 =
new FocusInAboutToRequestFocusFromTabTraversalView;
- v2->SetFocusable(true);
+ v2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
v2->set_view_to_focus(v1);
GetContentsView()->AddChildView(v2);
views::View* v3 = new View;
- v3->SetFocusable(true);
+ v3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
GetContentsView()->AddChildView(v3);
v3->RequestFocus();
@@ -625,22 +625,22 @@ TEST_F(FocusManagerTest, RotatePaneFocus) {
GetContentsView()->AddChildView(pane1);
views::View* v1 = new View;
- v1->SetFocusable(true);
+ v1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
pane1->AddChildView(v1);
views::View* v2 = new View;
- v2->SetFocusable(true);
+ v2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
pane1->AddChildView(v2);
views::AccessiblePaneView* pane2 = new AccessiblePaneView();
GetContentsView()->AddChildView(pane2);
views::View* v3 = new View;
- v3->SetFocusable(true);
+ v3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
pane2->AddChildView(v3);
views::View* v4 = new View;
- v4->SetFocusable(true);
+ v4->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
pane2->AddChildView(v4);
std::vector<views::View*> panes;
@@ -695,11 +695,11 @@ TEST_F(FocusManagerTest, RotatePaneFocus) {
// Verifies the stored focus view tracks the focused view.
TEST_F(FocusManagerTest, ImplicitlyStoresFocus) {
views::View* v1 = new View;
- v1->SetFocusable(true);
+ v1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
GetContentsView()->AddChildView(v1);
views::View* v2 = new View;
- v2->SetFocusable(true);
+ v2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
GetContentsView()->AddChildView(v2);
// Verify a focus request on |v1| implicitly updates the stored focus view.
@@ -753,7 +753,7 @@ TEST_F(FocusManagerArrowKeyTraversalTest, ArrowKeyTraversal) {
std::vector<views::View*> v;
for (size_t i = 0; i < 2; ++i) {
views::View* view = new View;
- view->SetFocusable(true);
+ view->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
GetContentsView()->AddChildView(view);
v.push_back(view);
}
@@ -784,20 +784,64 @@ TEST_F(FocusManagerArrowKeyTraversalTest, ArrowKeyTraversal) {
}
TEST_F(FocusManagerTest, StoreFocusedView) {
- View view;
- GetFocusManager()->SetFocusedView(&view);
+ View* view = new View;
+ // Add view to the view hierarchy and make it focusable.
+ GetWidget()->GetRootView()->AddChildView(view);
+ view->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
+
+ GetFocusManager()->SetFocusedView(view);
GetFocusManager()->StoreFocusedView(false);
EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView());
EXPECT_TRUE(GetFocusManager()->RestoreFocusedView());
- EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView());
+ EXPECT_EQ(view, GetFocusManager()->GetStoredFocusView());
// Repeat with |true|.
- GetFocusManager()->SetFocusedView(&view);
+ GetFocusManager()->SetFocusedView(view);
GetFocusManager()->StoreFocusedView(true);
EXPECT_EQ(NULL, GetFocusManager()->GetFocusedView());
EXPECT_TRUE(GetFocusManager()->RestoreFocusedView());
- EXPECT_EQ(&view, GetFocusManager()->GetStoredFocusView());
+ EXPECT_EQ(view, GetFocusManager()->GetStoredFocusView());
+}
+
+#if defined(OS_MACOSX)
+// Test that the correct view is restored if full keyboard access is changed.
+TEST_F(FocusManagerTest, StoreFocusedViewFullKeyboardAccess) {
+ View* view1 = new View;
+ View* view2 = new View;
+ View* view3 = new View;
+
+ // Make view1 focusable in accessibility mode, view2 not focusable and view3
+ // always focusable.
+ view1->SetFocusBehavior(views::View::FocusBehavior::ACCESSIBLE_ONLY);
+ view2->SetFocusBehavior(views::View::FocusBehavior::NEVER);
+ view3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
+
+ // Add views to the view hierarchy
+ GetWidget()->GetRootView()->AddChildView(view1);
+ GetWidget()->GetRootView()->AddChildView(view2);
+ GetWidget()->GetRootView()->AddChildView(view3);
+
+ view1->RequestFocus();
+ EXPECT_EQ(view1, GetFocusManager()->GetFocusedView());
+ GetFocusManager()->StoreFocusedView(true);
+ EXPECT_EQ(nullptr, GetFocusManager()->GetFocusedView());
+
+ // Turn off full keyboard access mode and restore focused view. Since view1 is
+ // no longer focusable, view3 should have focus.
+ GetFocusManager()->SetKeyboardAccessible(false);
+ EXPECT_FALSE(GetFocusManager()->RestoreFocusedView());
+ EXPECT_EQ(view3, GetFocusManager()->GetFocusedView());
+
+ GetFocusManager()->StoreFocusedView(false);
+ EXPECT_EQ(nullptr, GetFocusManager()->GetFocusedView());
+
+ // Turn on full keyboard access mode and restore focused view. Since view3 is
+ // still focusable, view3 should have focus.
+ GetFocusManager()->SetKeyboardAccessible(true);
+ EXPECT_TRUE(GetFocusManager()->RestoreFocusedView());
+ EXPECT_EQ(view3, GetFocusManager()->GetFocusedView());
}
+#endif
namespace {
@@ -834,7 +878,7 @@ class AdvanceFocusWidgetDelegate : public WidgetDelegate {
TEST_F(FocusManagerTest, AdvanceFocusStaysInWidget) {
// Add |widget_view| as a child of the Widget.
View* widget_view = new View;
- widget_view->SetFocusable(true);
+ widget_view->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
widget_view->SetBounds(20, 0, 20, 20);
GetContentsView()->AddChildView(widget_view);
@@ -850,10 +894,10 @@ TEST_F(FocusManagerTest, AdvanceFocusStaysInWidget) {
params.delegate = delegate.get();
child_widget.Init(params);
View* view1 = new View;
- view1->SetFocusable(true);
+ view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
view1->SetBounds(0, 0, 20, 20);
View* view2 = new View;
- view2->SetFocusable(true);
+ view2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
view2->SetBounds(20, 0, 20, 20);
child_widget.client_view()->AddChildView(view1);
child_widget.client_view()->AddChildView(view2);
« no previous file with comments | « ui/views/focus/focus_manager.cc ('k') | ui/views/focus/focus_search.h » ('j') | ui/views/view.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698