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

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, 1 month 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 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 ASSERT_EQ(selected_text, omnibox_view->GetText()); 1014 ASSERT_EQ(selected_text, omnibox_view->GetText());
1015 #endif 1015 #endif
1016 1016
1017 // As the current selected item is the new default item, pressing Escape key 1017 // As the current selected item is the new default item, pressing Escape key
1018 // should revert all directly. 1018 // should revert all directly.
1019 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed()); 1019 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed());
1020 ASSERT_EQ(old_text, omnibox_view->GetText()); 1020 ASSERT_EQ(old_text, omnibox_view->GetText());
1021 ASSERT_TRUE(omnibox_view->IsSelectAll()); 1021 ASSERT_TRUE(omnibox_view->IsSelectAll());
1022 } 1022 }
1023 1023
1024 void TabMoveCursorToEndTest() { 1024 void TabAcceptKeyword() {
1025 OmniboxView* omnibox_view = NULL; 1025 OmniboxView* omnibox_view = NULL;
1026 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 1026 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1027 1027
1028 omnibox_view->SetUserText(ASCIIToUTF16("Hello world")); 1028 string16 text = UTF8ToUTF16(kSearchKeyword);
1029 1029
1030 // Move cursor to the beginning. 1030 // Trigger keyword hint mode.
1031 #if defined(OS_MACOSX) 1031 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1032 // Home doesn't work on Mac trybot. 1032 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1033 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, ui::EF_CONTROL_DOWN)); 1033 ASSERT_EQ(text, omnibox_view->model()->keyword());
1034 #else 1034 ASSERT_EQ(text, omnibox_view->GetText());
1035 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, 0));
1036 #endif
1037 1035
1038 size_t start, end; 1036 // Trigger keyword mode by tab.
1039 omnibox_view->GetSelectionBounds(&start, &end); 1037 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1040 EXPECT_EQ(0U, start); 1038 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1041 EXPECT_EQ(0U, end); 1039 ASSERT_EQ(text, omnibox_view->model()->keyword());
1040 ASSERT_TRUE(omnibox_view->GetText().empty());
1042 1041
1043 // Pressing tab should move cursor to the end. 1042 // Revert to keyword hint mode.
1043 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1044 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1045 ASSERT_EQ(text, omnibox_view->model()->keyword());
1046 ASSERT_EQ(text, omnibox_view->GetText());
1047 }
1048
1049 void ShiftTabRevertKeyword() {
Peter Kasting 2011/12/15 22:56:04 Nit: Instead of writing two tests for these it see
1050 OmniboxView* omnibox_view = NULL;
1051 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1052
1053 string16 text = UTF8ToUTF16(kSearchKeyword);
1054
1055 // Trigger keyword hint mode.
1056 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1057 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1058 ASSERT_EQ(text, omnibox_view->model()->keyword());
1059 ASSERT_EQ(text, omnibox_view->GetText());
1060
1061 // Trigger keyword mode by tab.
1044 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); 1062 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1063 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1064 ASSERT_EQ(text, omnibox_view->model()->keyword());
1065 ASSERT_TRUE(omnibox_view->GetText().empty());
1045 1066
1046 omnibox_view->GetSelectionBounds(&start, &end); 1067 // Revert to keyword hint mode.
1047 EXPECT_EQ(omnibox_view->GetText().size(), start); 1068 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1048 EXPECT_EQ(omnibox_view->GetText().size(), end); 1069 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1049 1070 ASSERT_EQ(text, omnibox_view->model()->keyword());
1050 // The location bar should still have focus. 1071 ASSERT_EQ(text, omnibox_view->GetText());
1051 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR));
1052
1053 // Select all text.
1054 omnibox_view->SelectAll(true);
1055 EXPECT_TRUE(omnibox_view->IsSelectAll());
1056 omnibox_view->GetSelectionBounds(&start, &end);
1057 EXPECT_EQ(0U, start);
1058 EXPECT_EQ(omnibox_view->GetText().size(), end);
1059
1060 // Pressing tab should move cursor to the end.
1061 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1062
1063 omnibox_view->GetSelectionBounds(&start, &end);
1064 EXPECT_EQ(omnibox_view->GetText().size(), start);
1065 EXPECT_EQ(omnibox_view->GetText().size(), end);
1066
1067 // The location bar should still have focus.
1068 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR));
1069
1070 // Pressing tab when cursor is at the end should change focus.
1071 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1072
1073 ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR));
1074 } 1072 }
1075 1073
1076 void PersistKeywordModeOnTabSwitch() { 1074 void PersistKeywordModeOnTabSwitch() {
1077 OmniboxView* omnibox_view = NULL; 1075 OmniboxView* omnibox_view = NULL;
1078 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 1076 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1079 1077
1080 // Trigger keyword hint mode. 1078 // Trigger keyword hint mode.
1081 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 1079 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1082 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 1080 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1083 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); 1081 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 1185
1188 #if defined(OS_POSIX) 1186 #if defined(OS_POSIX)
1189 // Flaky on Mac 10.6, Linux http://crbug.com/84420 1187 // Flaky on Mac 10.6, Linux http://crbug.com/84420
1190 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_DeleteItem) { 1188 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_DeleteItem) {
1191 #else 1189 #else
1192 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) { 1190 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) {
1193 #endif 1191 #endif
1194 DeleteItemTest(); 1192 DeleteItemTest();
1195 } 1193 }
1196 1194
1197 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabMoveCursorToEnd) { 1195 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabAcceptKeyword) {
1198 TabMoveCursorToEndTest(); 1196 TabAcceptKeyword();
1197 }
1198
1199 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, ShiftTabRevertKeyword) {
1200 ShiftTabRevertKeyword();
1199 } 1201 }
1200 1202
1201 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, 1203 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1202 PersistKeywordModeOnTabSwitch) { 1204 PersistKeywordModeOnTabSwitch) {
1203 PersistKeywordModeOnTabSwitch(); 1205 PersistKeywordModeOnTabSwitch();
1204 } 1206 }
1205 1207
1206 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, 1208 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1207 CtrlKeyPressedWithInlineAutocompleteTest) { 1209 CtrlKeyPressedWithInlineAutocompleteTest) {
1208 CtrlKeyPressedWithInlineAutocompleteTest(); 1210 CtrlKeyPressedWithInlineAutocompleteTest();
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 PersistKeywordModeOnTabSwitch) { 1410 PersistKeywordModeOnTabSwitch) {
1409 PersistKeywordModeOnTabSwitch(); 1411 PersistKeywordModeOnTabSwitch();
1410 } 1412 }
1411 1413
1412 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, 1414 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest,
1413 CtrlKeyPressedWithInlineAutocompleteTest) { 1415 CtrlKeyPressedWithInlineAutocompleteTest) {
1414 CtrlKeyPressedWithInlineAutocompleteTest(); 1416 CtrlKeyPressedWithInlineAutocompleteTest();
1415 } 1417 }
1416 1418
1417 #endif 1419 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698