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

Side by Side Diff: views/focus/focus_manager_unittest.cc

Issue 2935005: Prevent non-visible views from getting focused. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Fix nit Created 10 years, 5 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 | « no previous file | views/view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "app/combobox_model.h" 7 #include "app/combobox_model.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/keyboard_codes.h" 9 #include "base/keyboard_codes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 kRidiculeLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID, 1107 kRidiculeLinkID, kAmelieLinkID, kJoyeuxNoelLinkID, kCampingLinkID,
1108 kOKButtonID, kCancelButtonID, kStyleContainerID, kItalicCheckBoxID, 1108 kOKButtonID, kCancelButtonID, kStyleContainerID, kItalicCheckBoxID,
1109 kUnderlinedCheckBoxID, kStyleHelpLinkID, kStyleTextEditID, 1109 kUnderlinedCheckBoxID, kStyleHelpLinkID, kStyleTextEditID,
1110 kSearchButtonID, kThumbnailContainerID, kThumbnailStarID, 1110 kSearchButtonID, kThumbnailContainerID, kThumbnailStarID,
1111 kThumbnailSuperStarID }; 1111 kThumbnailSuperStarID };
1112 1112
1113 // Let's disable some views. 1113 // Let's disable some views.
1114 for (size_t i = 0; i < arraysize(kDisabledIDs); i++) { 1114 for (size_t i = 0; i < arraysize(kDisabledIDs); i++) {
1115 View* v = FindViewByID(kDisabledIDs[i]); 1115 View* v = FindViewByID(kDisabledIDs[i]);
1116 ASSERT_TRUE(v != NULL); 1116 ASSERT_TRUE(v != NULL);
1117 if (v) 1117 v->SetEnabled(false);
1118 v->SetEnabled(false);
1119 } 1118 }
1120 1119
1121 // Uncomment the following line if you want to test manually the UI of this 1120 // Uncomment the following line if you want to test manually the UI of this
1121 // test.
1122 // MessageLoopForUI::current()->Run(new AcceleratorHandler());
1123
1124 View* focused_view;
1125 // Let's do one traversal (several times, to make sure it loops ok).
1126 GetFocusManager()->ClearFocus();
1127 for (int i = 0; i < 3; ++i) {
1128 for (size_t j = 0; j < arraysize(kTraversalIDs); j++) {
1129 GetFocusManager()->AdvanceFocus(false);
1130 focused_view = GetFocusManager()->GetFocusedView();
1131 EXPECT_TRUE(focused_view != NULL);
1132 if (focused_view)
1133 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID());
1134 }
1135 }
1136
1137 // Same thing in reverse.
1138 GetFocusManager()->ClearFocus();
1139 for (int i = 0; i < 3; ++i) {
1140 for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) {
1141 GetFocusManager()->AdvanceFocus(true);
1142 focused_view = GetFocusManager()->GetFocusedView();
1143 EXPECT_TRUE(focused_view != NULL);
1144 if (focused_view)
1145 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID());
1146 }
1147 }
1148 }
1149
1150 TEST_F(FocusTraversalTest, TraversalWithInvisibleViews) {
1151 const int kInvisibleIDs[] = { kTopCheckBoxID, kOKButtonID,
1152 kThumbnailContainerID };
1153
1154 const int kTraversalIDs[] = { kAppleTextfieldID, kOrangeTextfieldID,
1155 kBananaTextfieldID, kKiwiTextfieldID, kFruitButtonID, kFruitCheckBoxID,
1156 kComboboxID, kBroccoliButtonID, kRosettaLinkID,
1157 kStupeurEtTremblementLinkID, kDinerGameLinkID, kRidiculeLinkID,
1158 kClosetLinkID, kVisitingLinkID, kAmelieLinkID, kJoyeuxNoelLinkID,
1159 kCampingLinkID, kBriceDeNiceLinkID, kTaxiLinkID, kAsterixLinkID,
1160 kCancelButtonID, kHelpButtonID, kStyleContainerID, kBoldCheckBoxID,
1161 kItalicCheckBoxID, kUnderlinedCheckBoxID, kStyleHelpLinkID,
1162 kStyleTextEditID, kSearchTextfieldID, kSearchButtonID, kHelpLinkID };
1163
1164
1165 // Let's make some views invisible.
1166 for (size_t i = 0; i < arraysize(kInvisibleIDs); i++) {
1167 View* v = FindViewByID(kInvisibleIDs[i]);
1168 ASSERT_TRUE(v != NULL);
1169 v->SetVisible(false);
1170 }
1171
1172 // Uncomment the following line if you want to test manually the UI of this
1122 // test. 1173 // test.
1123 // MessageLoopForUI::current()->Run(new AcceleratorHandler()); 1174 // MessageLoopForUI::current()->Run(new AcceleratorHandler());
1124 1175
1125 View* focused_view; 1176 View* focused_view;
1126 // Let's do one traversal (several times, to make sure it loops ok). 1177 // Let's do one traversal (several times, to make sure it loops ok).
1127 GetFocusManager()->ClearFocus(); 1178 GetFocusManager()->ClearFocus();
1128 for (int i = 0; i < 3; ++i) { 1179 for (int i = 0; i < 3; ++i) {
1129 for (size_t j = 0; j < arraysize(kTraversalIDs); j++) { 1180 for (size_t j = 0; j < arraysize(kTraversalIDs); j++) {
1130 GetFocusManager()->AdvanceFocus(false); 1181 GetFocusManager()->AdvanceFocus(false);
1131 focused_view = GetFocusManager()->GetFocusedView(); 1182 focused_view = GetFocusManager()->GetFocusedView();
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 // Focus manager should be the last one to destruct. 1717 // Focus manager should be the last one to destruct.
1667 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str()); 1718 ASSERT_STREQ("FocusManagerDtorTracked", dtor_tracker_[2].c_str());
1668 1719
1669 // Clear window_ so that we don't try to close it again. 1720 // Clear window_ so that we don't try to close it again.
1670 window_ = NULL; 1721 window_ = NULL;
1671 } 1722 }
1672 1723
1673 #endif // defined(OS_CHROMEOS) 1724 #endif // defined(OS_CHROMEOS)
1674 1725
1675 } // namespace views 1726 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | views/view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698