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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_view_browsertest.cc

Issue 6731036: Enabled pressing TAB to cycle through the Omnibox results. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 4 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 ASSERT_EQ(selected_text, omnibox_view->GetText()); 1007 ASSERT_EQ(selected_text, omnibox_view->GetText());
1008 #endif 1008 #endif
1009 1009
1010 // As the current selected item is the new default item, pressing Escape key 1010 // As the current selected item is the new default item, pressing Escape key
1011 // should revert all directly. 1011 // should revert all directly.
1012 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed()); 1012 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed());
1013 ASSERT_EQ(old_text, omnibox_view->GetText()); 1013 ASSERT_EQ(old_text, omnibox_view->GetText());
1014 ASSERT_TRUE(omnibox_view->IsSelectAll()); 1014 ASSERT_TRUE(omnibox_view->IsSelectAll());
1015 } 1015 }
1016 1016
1017 void TabMoveCursorToEndTest() { 1017 void TabAcceptKeyword() {
1018 OmniboxView* omnibox_view = NULL; 1018 OmniboxView* omnibox_view = NULL;
1019 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 1019 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1020 1020
1021 omnibox_view->SetUserText(ASCIIToUTF16("Hello world")); 1021 string16 text = UTF8ToUTF16(kSearchKeyword);
1022 1022
1023 // Move cursor to the beginning. 1023 // Trigger keyword hint mode.
1024 #if defined(OS_MACOSX) 1024 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1025 // Home doesn't work on Mac trybot. 1025 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1026 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, ui::EF_CONTROL_DOWN)); 1026 ASSERT_EQ(text, omnibox_view->model()->keyword());
1027 #else 1027 ASSERT_EQ(text, omnibox_view->GetText());
1028 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, 0));
1029 #endif
1030 1028
1031 size_t start, end; 1029 // Trigger keyword mode by tab.
1032 omnibox_view->GetSelectionBounds(&start, &end); 1030 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1033 EXPECT_EQ(0U, start); 1031 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1034 EXPECT_EQ(0U, end); 1032 ASSERT_EQ(text, omnibox_view->model()->keyword());
1033 ASSERT_TRUE(omnibox_view->GetText().empty());
1035 1034
1036 // Pressing tab should move cursor to the end. 1035 // Revert to keyword hint mode.
1037 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); 1036 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1038 1037 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1039 omnibox_view->GetSelectionBounds(&start, &end); 1038 ASSERT_EQ(text, omnibox_view->model()->keyword());
1040 EXPECT_EQ(omnibox_view->GetText().size(), start); 1039 ASSERT_EQ(text, omnibox_view->GetText());
1041 EXPECT_EQ(omnibox_view->GetText().size(), end);
1042
1043 // The location bar should still have focus.
1044 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR));
1045
1046 // Select all text.
1047 omnibox_view->SelectAll(true);
1048 EXPECT_TRUE(omnibox_view->IsSelectAll());
1049 omnibox_view->GetSelectionBounds(&start, &end);
1050 EXPECT_EQ(0U, start);
1051 EXPECT_EQ(omnibox_view->GetText().size(), end);
1052
1053 // Pressing tab should move cursor to the end.
1054 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1055
1056 omnibox_view->GetSelectionBounds(&start, &end);
1057 EXPECT_EQ(omnibox_view->GetText().size(), start);
1058 EXPECT_EQ(omnibox_view->GetText().size(), end);
1059
1060 // The location bar should still have focus.
1061 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR));
1062
1063 // Pressing tab when cursor is at the end should change focus.
1064 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1065
1066 ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR));
1067 } 1040 }
1068 1041
1069 void PersistKeywordModeOnTabSwitch() { 1042 void PersistKeywordModeOnTabSwitch() {
1070 OmniboxView* omnibox_view = NULL; 1043 OmniboxView* omnibox_view = NULL;
1071 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 1044 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1072 1045
1073 // Trigger keyword hint mode. 1046 // Trigger keyword hint mode.
1074 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 1047 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1075 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 1048 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1076 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); 1049 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 1153
1181 #if defined(OS_POSIX) 1154 #if defined(OS_POSIX)
1182 // Flaky on Mac 10.6, Linux http://crbug.com/84420 1155 // Flaky on Mac 10.6, Linux http://crbug.com/84420
1183 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_DeleteItem) { 1156 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_DeleteItem) {
1184 #else 1157 #else
1185 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) { 1158 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) {
1186 #endif 1159 #endif
1187 DeleteItemTest(); 1160 DeleteItemTest();
1188 } 1161 }
1189 1162
1190 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabMoveCursorToEnd) { 1163 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabAcceptKeyword) {
1191 TabMoveCursorToEndTest(); 1164 TabAcceptKeyword();
1192 } 1165 }
1193 1166
1194 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, 1167 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1195 PersistKeywordModeOnTabSwitch) { 1168 PersistKeywordModeOnTabSwitch) {
1196 PersistKeywordModeOnTabSwitch(); 1169 PersistKeywordModeOnTabSwitch();
1197 } 1170 }
1198 1171
1199 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, 1172 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1200 CtrlKeyPressedWithInlineAutocompleteTest) { 1173 CtrlKeyPressedWithInlineAutocompleteTest) {
1201 CtrlKeyPressedWithInlineAutocompleteTest(); 1174 CtrlKeyPressedWithInlineAutocompleteTest();
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 PersistKeywordModeOnTabSwitch) { 1374 PersistKeywordModeOnTabSwitch) {
1402 PersistKeywordModeOnTabSwitch(); 1375 PersistKeywordModeOnTabSwitch();
1403 } 1376 }
1404 1377
1405 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, 1378 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest,
1406 CtrlKeyPressedWithInlineAutocompleteTest) { 1379 CtrlKeyPressedWithInlineAutocompleteTest) {
1407 CtrlKeyPressedWithInlineAutocompleteTest(); 1380 CtrlKeyPressedWithInlineAutocompleteTest();
1408 } 1381 }
1409 1382
1410 #endif 1383 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698