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

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

Issue 125130: Fix focus traversal cycle. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « views/focus/focus_manager.cc ('k') | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // Disabled right now as this won't work on BuildBots right now as this test 5 // Disabled right now as this won't work on BuildBots right now as this test
6 // require the box it runs on to be unlocked (and no screen-savers). 6 // require the box it runs on to be unlocked (and no screen-savers).
7 // The test actually simulates mouse and key events, so if the screen is locked, 7 // The test actually simulates mouse and key events, so if the screen is locked,
8 // the events don't go to the Chrome window. 8 // the events don't go to the Chrome window.
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 for (int i = 0; i < 3; ++i) { 878 for (int i = 0; i < 3; ++i) {
879 for (int j = 0; j < arraysize(kTraversalIDs); j++) { 879 for (int j = 0; j < arraysize(kTraversalIDs); j++) {
880 GetFocusManager()->AdvanceFocus(false); 880 GetFocusManager()->AdvanceFocus(false);
881 View* focused_view = GetFocusManager()->GetFocusedView(); 881 View* focused_view = GetFocusManager()->GetFocusedView();
882 EXPECT_TRUE(focused_view != NULL); 882 EXPECT_TRUE(focused_view != NULL);
883 if (focused_view) 883 if (focused_view)
884 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID()); 884 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID());
885 } 885 }
886 } 886 }
887 887
888 // Focus the 1st item.
889 GetFocusManager()->SetFocusedView(
890 content_view_->GetViewByID(kTraversalIDs[0]));
891
892 // Let's traverse in reverse order. 888 // Let's traverse in reverse order.
889 GetFocusManager()->SetFocusedView(NULL);
893 for (int i = 0; i < 3; ++i) { 890 for (int i = 0; i < 3; ++i) {
894 for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) { 891 for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) {
895 GetFocusManager()->AdvanceFocus(true); 892 GetFocusManager()->AdvanceFocus(true);
896 View* focused_view = GetFocusManager()->GetFocusedView(); 893 View* focused_view = GetFocusManager()->GetFocusedView();
897 EXPECT_TRUE(focused_view != NULL); 894 EXPECT_TRUE(focused_view != NULL);
898 if (focused_view) 895 if (focused_view)
899 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID()); 896 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID());
900 } 897 }
901 } 898 }
902 } 899 }
(...skipping 21 matching lines...) Expand all
924 if (v) 921 if (v)
925 v->SetEnabled(false); 922 v->SetEnabled(false);
926 } 923 }
927 924
928 // Uncomment the following line if you want to test manually the UI of this 925 // Uncomment the following line if you want to test manually the UI of this
929 // test. 926 // test.
930 // MessageLoopForUI::current()->Run(new AcceleratorHandler()); 927 // MessageLoopForUI::current()->Run(new AcceleratorHandler());
931 928
932 View* focused_view; 929 View* focused_view;
933 // Let's do one traversal (several times, to make sure it loops ok). 930 // Let's do one traversal (several times, to make sure it loops ok).
931 GetFocusManager()->SetFocusedView(NULL);
934 for (int i = 0; i < 3; ++i) { 932 for (int i = 0; i < 3; ++i) {
935 for (int j = 0; j < arraysize(kTraversalIDs); j++) { 933 for (int j = 0; j < arraysize(kTraversalIDs); j++) {
936 GetFocusManager()->AdvanceFocus(false); 934 GetFocusManager()->AdvanceFocus(false);
937 focused_view = GetFocusManager()->GetFocusedView(); 935 focused_view = GetFocusManager()->GetFocusedView();
938 EXPECT_TRUE(focused_view != NULL); 936 EXPECT_TRUE(focused_view != NULL);
939 if (focused_view) 937 if (focused_view)
940 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID()); 938 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID());
941 } 939 }
942 } 940 }
943 941
944 // Focus the 1st item.
945 GetFocusManager()->AdvanceFocus(false);
946 focused_view = GetFocusManager()->GetFocusedView();
947 EXPECT_TRUE(focused_view != NULL);
948 if (focused_view)
949 EXPECT_EQ(kTraversalIDs[0], focused_view->GetID());
950
951 // Same thing in reverse. 942 // Same thing in reverse.
943 GetFocusManager()->SetFocusedView(NULL);
952 for (int i = 0; i < 3; ++i) { 944 for (int i = 0; i < 3; ++i) {
953 for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) { 945 for (int j = arraysize(kTraversalIDs) - 1; j >= 0; --j) {
954 GetFocusManager()->AdvanceFocus(true); 946 GetFocusManager()->AdvanceFocus(true);
955 focused_view = GetFocusManager()->GetFocusedView(); 947 focused_view = GetFocusManager()->GetFocusedView();
956 EXPECT_TRUE(focused_view != NULL); 948 EXPECT_TRUE(focused_view != NULL);
957 if (focused_view) 949 if (focused_view)
958 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID()); 950 EXPECT_EQ(kTraversalIDs[j], focused_view->GetID());
959 } 951 }
960 } 952 }
961 } 953 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 EXPECT_EQ(target.accelerator_count(), 1); 1108 EXPECT_EQ(target.accelerator_count(), 1);
1117 EXPECT_EQ(NULL, 1109 EXPECT_EQ(NULL,
1118 focus_manager->GetCurrentTargetForAccelerator(return_accelerator)); 1110 focus_manager->GetCurrentTargetForAccelerator(return_accelerator));
1119 1111
1120 // Hitting the return key again; nothing should happen. 1112 // Hitting the return key again; nothing should happen.
1121 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); 1113 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator));
1122 EXPECT_EQ(target.accelerator_count(), 1); 1114 EXPECT_EQ(target.accelerator_count(), 1);
1123 } 1115 }
1124 1116
1125 } // namespace views 1117 } // namespace views
OLDNEW
« no previous file with comments | « views/focus/focus_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698