Index: ui/views/focus/focus_traversal_unittest.cc |
diff --git a/ui/views/focus/focus_traversal_unittest.cc b/ui/views/focus/focus_traversal_unittest.cc |
index f1bee540cc40125b20cc54f574ac55bf8142cd48..3a50e7d6d23886fe72680fc386a9ba3737238173 100644 |
--- a/ui/views/focus/focus_traversal_unittest.cc |
+++ b/ui/views/focus/focus_traversal_unittest.cc |
@@ -134,7 +134,7 @@ class BorderView : public NativeViewHost { |
public: |
explicit BorderView(View* child) : child_(child), widget_(NULL) { |
DCHECK(child); |
- SetFocusable(false); |
+ SetFocusBehavior(View::FocusBehavior::NEVER); |
} |
~BorderView() override {} |
@@ -543,7 +543,7 @@ void FocusTraversalTest::InitContentView() { |
y += 60; |
contents = new View(); |
- contents->SetFocusable(true); |
+ contents->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
contents->set_background(Background::CreateSolidBackground(SK_ColorBLUE)); |
contents->set_id(kThumbnailContainerID); |
button = new LabelButton(NULL, ASCIIToUTF16("Star")); |
@@ -603,6 +603,77 @@ TEST_F(FocusTraversalTest, NormalTraversal) { |
} |
} |
+#if defined(OS_MACOSX) |
+// Test focus traversal with full keyboard access off on Mac. |
+TEST_F(FocusTraversalTest, NormalTraversalMac) { |
+GetFocusManager()->SetKeyboardAccessible(false); |
+ |
+// Now only views with FocusBehavior of ALWAYS will be focusable. |
+const int kTraversalIDs[] = { kAppleTextfieldID, |
+ kOrangeTextfieldID, kBananaTextfieldID, kKiwiTextfieldID, |
+ kStyleTextEditID, |
+ kSearchTextfieldID, |
+ kThumbnailContainerID}; |
+ |
+ // Let's traverse the whole focus hierarchy (several times, to make sure it |
+ // loops OK). |
+ GetFocusManager()->ClearFocus(); |
+ for (int i = 0; i < 3; ++i) { |
+ for (size_t j = 0; j < arraysize(kTraversalIDs); j++) { |
+ GetFocusManager()->AdvanceFocus(false); |
+ View* focused_view = GetFocusManager()->GetFocusedView(); |
+ EXPECT_TRUE(focused_view != NULL); |
+ if (focused_view) |
+ EXPECT_EQ(kTraversalIDs[j], focused_view->id()); |
+ } |
+ } |
+ |
+ // Let's traverse in reverse order. |
+ GetFocusManager()->ClearFocus(); |
+ for (int i = 0; i < 3; ++i) { |
+ for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) { |
+ GetFocusManager()->AdvanceFocus(true); |
+ View* focused_view = GetFocusManager()->GetFocusedView(); |
+ EXPECT_TRUE(focused_view != NULL); |
+ if (focused_view) |
+ EXPECT_EQ(kTraversalIDs[j], focused_view->id()); |
+ } |
+ } |
+} |
+ |
+// Test toggling full keyboard access correctly changes the focused view on Mac. |
+TEST_F(FocusTraversalTest, FullKeyboardToggle) { |
+ // Give focus to kTopCheckBoxID . |
+ FindViewByID(kTopCheckBoxID)->RequestFocus(); |
+ EXPECT_EQ(kTopCheckBoxID, GetFocusManager()->GetFocusedView()->id()); |
+ |
+ // Turn off full keyboard access. Focus should move to next view with ALWAYS |
+ // focus behavior. |
+ GetFocusManager()->SetKeyboardAccessible(false); |
+ EXPECT_EQ(kAppleTextfieldID, GetFocusManager()->GetFocusedView()->id()); |
+ |
+ // Turning on full keyboard access should not change the focused view. |
+ GetFocusManager()->SetKeyboardAccessible(true); |
+ EXPECT_EQ(kAppleTextfieldID, GetFocusManager()->GetFocusedView()->id()); |
+ |
+ // Give focus to kSearchButtonID. |
+ FindViewByID(kSearchButtonID)->RequestFocus(); |
+ EXPECT_EQ(kSearchButtonID, GetFocusManager()->GetFocusedView()->id()); |
+ |
+ // Turn off full keyboard access. Focus should move to next view with ALWAYS |
+ // focus behavior. |
+ GetFocusManager()->SetKeyboardAccessible(false); |
+ EXPECT_EQ(kThumbnailContainerID, GetFocusManager()->GetFocusedView()->id()); |
+ |
+ // See focus advances correctly in both directions. |
+ GetFocusManager()->AdvanceFocus(false); |
+ EXPECT_EQ(kAppleTextfieldID, GetFocusManager()->GetFocusedView()->id()); |
+ |
+ GetFocusManager()->AdvanceFocus(true); |
+ EXPECT_EQ(kThumbnailContainerID, GetFocusManager()->GetFocusedView()->id()); |
+} |
+#endif |
+ |
TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) { |
const int kDisabledIDs[] = { |
kBananaTextfieldID, kFruitCheckBoxID, kComboboxID, kAsparagusButtonID, |
@@ -747,10 +818,11 @@ TEST_F(FocusTraversalTest, PaneTraversal) { |
FocusSearch focus_search_right(right_container_, true, true); |
right_container_->EnablePaneFocus(&focus_search_right); |
- FindViewByID(kRosettaLinkID)->SetFocusable(false); |
- FindViewByID(kStupeurEtTremblementLinkID)->SetFocusable(false); |
- FindViewByID(kDinerGameLinkID)->SetAccessibilityFocusable(true); |
- FindViewByID(kDinerGameLinkID)->SetFocusable(false); |
+ FindViewByID(kRosettaLinkID)->SetFocusBehavior(View::FocusBehavior::NEVER); |
+ FindViewByID(kStupeurEtTremblementLinkID) |
+ ->SetFocusBehavior(View::FocusBehavior::NEVER); |
+ FindViewByID(kDinerGameLinkID) |
+ ->SetFocusBehavior(View::FocusBehavior::ACCESSIBLE_ONLY); |
FindViewByID(kAsterixLinkID)->RequestFocus(); |
// Traverse the focus hierarchy within the pane several times. |