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

Side by Side Diff: ui/views/focus/focus_traversal_unittest.cc

Issue 1894383002: MacViews: Implement Full Keyboard Access. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SetFocusBehavior
Patch Set: Rebased. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/focus/focus_manager.h" 5 #include "ui/views/focus/focus_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) { 596 for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) {
597 GetFocusManager()->AdvanceFocus(true); 597 GetFocusManager()->AdvanceFocus(true);
598 View* focused_view = GetFocusManager()->GetFocusedView(); 598 View* focused_view = GetFocusManager()->GetFocusedView();
599 EXPECT_TRUE(focused_view != NULL); 599 EXPECT_TRUE(focused_view != NULL);
600 if (focused_view) 600 if (focused_view)
601 EXPECT_EQ(kTraversalIDs[j], focused_view->id()); 601 EXPECT_EQ(kTraversalIDs[j], focused_view->id());
602 } 602 }
603 } 603 }
604 } 604 }
605 605
606 #if defined(OS_MACOSX)
607 // Test focus traversal with full keyboard access off on Mac.
608 TEST_F(FocusTraversalTest, NormalTraversalMac) {
609 GetFocusManager()->SetKeyboardAccessible(false);
tapted 2016/04/20 06:05:58 indenting is off here
karandeepb 2016/05/03 02:54:13 Done.
610
611 // Now only views with FocusBehavior of ALWAYS will be focusable.
612 const int kTraversalIDs[] = { kAppleTextfieldID,
613 kOrangeTextfieldID, kBananaTextfieldID, kKiwiTextfieldID,
614 kStyleTextEditID,
615 kSearchTextfieldID,
616 kThumbnailContainerID};
617
618 // Let's traverse the whole focus hierarchy (several times, to make sure it
tapted 2016/04/20 06:05:58 I think this needs to be a helper function - it's
karandeepb 2016/05/03 02:54:13 Done. Turns out there were many other similar call
619 // loops OK).
620 GetFocusManager()->ClearFocus();
621 for (int i = 0; i < 3; ++i) {
622 for (size_t j = 0; j < arraysize(kTraversalIDs); j++) {
623 GetFocusManager()->AdvanceFocus(false);
624 View* focused_view = GetFocusManager()->GetFocusedView();
625 EXPECT_TRUE(focused_view != NULL);
tapted 2016/04/20 06:05:58 I think EXPECT_NE(nullptr, focused_view) is the
karandeepb 2016/05/03 02:54:13 Done.
626 if (focused_view)
627 EXPECT_EQ(kTraversalIDs[j], focused_view->id());
628 }
629 }
630
631 // Let's traverse in reverse order.
632 GetFocusManager()->ClearFocus();
633 for (int i = 0; i < 3; ++i) {
634 for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) {
635 GetFocusManager()->AdvanceFocus(true);
636 View* focused_view = GetFocusManager()->GetFocusedView();
637 EXPECT_TRUE(focused_view != NULL);
638 if (focused_view)
639 EXPECT_EQ(kTraversalIDs[j], focused_view->id());
640 }
641 }
642 }
643
644 // Test toggling full keyboard access correctly changes the focused view on Mac.
645 TEST_F(FocusTraversalTest, FullKeyboardToggle) {
646 // Give focus to kTopCheckBoxID .
647 FindViewByID(kTopCheckBoxID)->RequestFocus();
648 EXPECT_EQ(kTopCheckBoxID, GetFocusManager()->GetFocusedView()->id());
649
650 // Turn off full keyboard access. Focus should move to next view with ALWAYS
651 // focus behavior.
652 GetFocusManager()->SetKeyboardAccessible(false);
653 EXPECT_EQ(kAppleTextfieldID, GetFocusManager()->GetFocusedView()->id());
654
655 // Turning on full keyboard access should not change the focused view.
656 GetFocusManager()->SetKeyboardAccessible(true);
657 EXPECT_EQ(kAppleTextfieldID, GetFocusManager()->GetFocusedView()->id());
658
659 // Give focus to kSearchButtonID.
660 FindViewByID(kSearchButtonID)->RequestFocus();
661 EXPECT_EQ(kSearchButtonID, GetFocusManager()->GetFocusedView()->id());
662
663 // Turn off full keyboard access. Focus should move to next view with ALWAYS
664 // focus behavior.
665 GetFocusManager()->SetKeyboardAccessible(false);
666 EXPECT_EQ(kThumbnailContainerID, GetFocusManager()->GetFocusedView()->id());
667
668 // See focus advances correctly in both directions.
669 GetFocusManager()->AdvanceFocus(false);
670 EXPECT_EQ(kAppleTextfieldID, GetFocusManager()->GetFocusedView()->id());
671
672 GetFocusManager()->AdvanceFocus(true);
673 EXPECT_EQ(kThumbnailContainerID, GetFocusManager()->GetFocusedView()->id());
674 }
675 #endif
tapted 2016/04/20 06:05:58 nit: // OS_MACOSX
karandeepb 2016/05/03 02:54:13 Done.
676
606 TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) { 677 TEST_F(FocusTraversalTest, TraversalWithNonEnabledViews) {
607 const int kDisabledIDs[] = { 678 const int kDisabledIDs[] = {
608 kBananaTextfieldID, kFruitCheckBoxID, kComboboxID, kAsparagusButtonID, 679 kBananaTextfieldID, kFruitCheckBoxID, kComboboxID, kAsparagusButtonID,
609 kCauliflowerButtonID, kClosetLinkID, kVisitingLinkID, kBriceDeNiceLinkID, 680 kCauliflowerButtonID, kClosetLinkID, kVisitingLinkID, kBriceDeNiceLinkID,
610 kTaxiLinkID, kAsterixLinkID, kHelpButtonID, kBoldCheckBoxID, 681 kTaxiLinkID, kAsterixLinkID, kHelpButtonID, kBoldCheckBoxID,
611 kSearchTextfieldID, kHelpLinkID }; 682 kSearchTextfieldID, kHelpLinkID };
612 683
613 const int kTraversalIDs[] = { kTopCheckBoxID, kAppleTextfieldID, 684 const int kTraversalIDs[] = { kTopCheckBoxID, kAppleTextfieldID,
614 kOrangeTextfieldID, kKiwiTextfieldID, kFruitButtonID, kBroccoliButtonID, 685 kOrangeTextfieldID, kKiwiTextfieldID, kFruitButtonID, kBroccoliButtonID,
615 kRosettaLinkID, kStupeurEtTremblementLinkID, kDinerGameLinkID, 686 kRosettaLinkID, kStupeurEtTremblementLinkID, kDinerGameLinkID,
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 GetFocusManager()->AdvanceFocus(false); 918 GetFocusManager()->AdvanceFocus(false);
848 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); 919 EXPECT_FALSE(GetFocusManager()->GetFocusedView());
849 920
850 // Advance backwards from the root node. 921 // Advance backwards from the root node.
851 GetFocusManager()->ClearFocus(); 922 GetFocusManager()->ClearFocus();
852 GetFocusManager()->AdvanceFocus(true); 923 GetFocusManager()->AdvanceFocus(true);
853 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); 924 EXPECT_FALSE(GetFocusManager()->GetFocusedView());
854 } 925 }
855 926
856 } // namespace views 927 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698