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

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 8 years, 11 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) 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 <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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 740
741 // Revert to keyword hint mode. 741 // Revert to keyword hint mode.
742 omnibox_view->model()->ClearKeyword(string16()); 742 omnibox_view->model()->ClearKeyword(string16());
743 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 743 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
744 ASSERT_EQ(text, omnibox_view->model()->keyword()); 744 ASSERT_EQ(text, omnibox_view->model()->keyword());
745 ASSERT_EQ(text, omnibox_view->GetText()); 745 ASSERT_EQ(text, omnibox_view->GetText());
746 746
747 // Keyword should also be accepted by typing an ideographic space. 747 // Keyword should also be accepted by typing an ideographic space.
748 omnibox_view->OnBeforePossibleChange(); 748 omnibox_view->OnBeforePossibleChange();
749 omnibox_view->SetWindowTextAndCaretPos(text + WideToUTF16(L"\x3000"), 749 omnibox_view->SetWindowTextAndCaretPos(text + WideToUTF16(L"\x3000"),
750 text.length() + 1); 750 text.length() + 1, false, false);
751 omnibox_view->OnAfterPossibleChange(); 751 omnibox_view->OnAfterPossibleChange();
752 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 752 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
753 ASSERT_EQ(text, omnibox_view->model()->keyword()); 753 ASSERT_EQ(text, omnibox_view->model()->keyword());
754 ASSERT_TRUE(omnibox_view->GetText().empty()); 754 ASSERT_TRUE(omnibox_view->GetText().empty());
755 755
756 // Revert to keyword hint mode. 756 // Revert to keyword hint mode.
757 omnibox_view->model()->ClearKeyword(string16()); 757 omnibox_view->model()->ClearKeyword(string16());
758 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 758 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
759 ASSERT_EQ(text, omnibox_view->model()->keyword()); 759 ASSERT_EQ(text, omnibox_view->model()->keyword());
760 ASSERT_EQ(text, omnibox_view->GetText()); 760 ASSERT_EQ(text, omnibox_view->GetText());
761 761
762 // Keyword shouldn't be accepted by pressing space with a trailing 762 // Keyword shouldn't be accepted by pressing space with a trailing
763 // whitespace. 763 // whitespace.
764 omnibox_view->SetWindowTextAndCaretPos( 764 omnibox_view->SetWindowTextAndCaretPos(
765 text + char16(' '), text.length() + 1); 765 text + char16(' '), text.length() + 1, false, false);
766 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 766 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
767 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 767 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
768 ASSERT_EQ(text, omnibox_view->model()->keyword()); 768 ASSERT_EQ(text, omnibox_view->model()->keyword());
769 ASSERT_EQ(text + ASCIIToUTF16(" "), omnibox_view->GetText()); 769 ASSERT_EQ(text + ASCIIToUTF16(" "), omnibox_view->GetText());
770 770
771 // Keyword shouldn't be accepted by deleting the trailing space. 771 // Keyword shouldn't be accepted by deleting the trailing space.
772 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0)); 772 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
773 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 773 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
774 ASSERT_EQ(text, omnibox_view->model()->keyword()); 774 ASSERT_EQ(text, omnibox_view->model()->keyword());
775 ASSERT_EQ(text + char16(' '), omnibox_view->GetText()); 775 ASSERT_EQ(text + char16(' '), omnibox_view->GetText());
(...skipping 16 matching lines...) Expand all
792 ASSERT_EQ(ASCIIToUTF16("a "), omnibox_view->GetText()); 792 ASSERT_EQ(ASCIIToUTF16("a "), omnibox_view->GetText());
793 793
794 // Keyword shouldn't be accepted by pasting "foo bar". 794 // Keyword shouldn't be accepted by pasting "foo bar".
795 omnibox_view->SetUserText(string16()); 795 omnibox_view->SetUserText(string16());
796 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 796 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
797 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); 797 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
798 798
799 omnibox_view->OnBeforePossibleChange(); 799 omnibox_view->OnBeforePossibleChange();
800 omnibox_view->model()->on_paste(); 800 omnibox_view->model()->on_paste();
801 omnibox_view->SetWindowTextAndCaretPos(text + ASCIIToUTF16(" bar"), 801 omnibox_view->SetWindowTextAndCaretPos(text + ASCIIToUTF16(" bar"),
802 text.length() + 4); 802 text.length() + 4, false, false);
803 omnibox_view->OnAfterPossibleChange(); 803 omnibox_view->OnAfterPossibleChange();
804 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 804 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
805 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); 805 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
806 ASSERT_EQ(text + ASCIIToUTF16(" bar"), omnibox_view->GetText()); 806 ASSERT_EQ(text + ASCIIToUTF16(" bar"), omnibox_view->GetText());
807 807
808 // Keyword shouldn't be accepted for case like: "foo b|ar" -> "foo b |ar". 808 // Keyword shouldn't be accepted for case like: "foo b|ar" -> "foo b |ar".
809 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0)); 809 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
810 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0)); 810 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
811 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 811 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
812 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 812 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 ASSERT_EQ(selected_text, omnibox_view->GetText()); 1006 ASSERT_EQ(selected_text, omnibox_view->GetText());
1007 #endif 1007 #endif
1008 1008
1009 // As the current selected item is the new default item, pressing Escape key 1009 // As the current selected item is the new default item, pressing Escape key
1010 // should revert all directly. 1010 // should revert all directly.
1011 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed()); 1011 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed());
1012 ASSERT_EQ(old_text, omnibox_view->GetText()); 1012 ASSERT_EQ(old_text, omnibox_view->GetText());
1013 ASSERT_TRUE(omnibox_view->IsSelectAll()); 1013 ASSERT_TRUE(omnibox_view->IsSelectAll());
1014 } 1014 }
1015 1015
1016 void TabMoveCursorToEndTest() { 1016 void TabAcceptKeyword() {
1017 OmniboxView* omnibox_view = NULL; 1017 OmniboxView* omnibox_view = NULL;
1018 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 1018 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1019 1019
1020 omnibox_view->SetUserText(ASCIIToUTF16("Hello world")); 1020 string16 text = ASCIIToUTF16(kSearchKeyword);
1021 1021
1022 // Move cursor to the beginning. 1022 // Trigger keyword hint mode.
1023 #if defined(OS_MACOSX) 1023 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1024 // Home doesn't work on Mac trybot. 1024 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1025 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, ui::EF_CONTROL_DOWN)); 1025 ASSERT_EQ(text, omnibox_view->model()->keyword());
1026 #else 1026 ASSERT_EQ(text, omnibox_view->GetText());
1027 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, 0));
1028 #endif
1029 1027
1030 size_t start, end; 1028 // Trigger keyword mode by tab.
1031 omnibox_view->GetSelectionBounds(&start, &end); 1029 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1032 EXPECT_EQ(0U, start); 1030 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1033 EXPECT_EQ(0U, end); 1031 ASSERT_EQ(text, omnibox_view->model()->keyword());
1032 ASSERT_TRUE(omnibox_view->GetText().empty());
1034 1033
1035 // Pressing tab should move cursor to the end. 1034 // Revert to keyword hint mode.
1036 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); 1035 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1037 1036 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1038 omnibox_view->GetSelectionBounds(&start, &end); 1037 ASSERT_EQ(text, omnibox_view->model()->keyword());
1039 EXPECT_EQ(omnibox_view->GetText().size(), start); 1038 ASSERT_EQ(text, omnibox_view->GetText());
1040 EXPECT_EQ(omnibox_view->GetText().size(), end);
1041 1039
1042 // The location bar should still have focus. 1040 // The location bar should still have focus.
1043 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), 1041 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
1044 location_bar_focus_view_id_)); 1042 location_bar_focus_view_id_));
1045 1043
1046 // Select all text. 1044 // Trigger keyword mode by tab.
1047 omnibox_view->SelectAll(true); 1045 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1048 EXPECT_TRUE(omnibox_view->IsSelectAll()); 1046 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1049 omnibox_view->GetSelectionBounds(&start, &end); 1047 ASSERT_EQ(text, omnibox_view->model()->keyword());
1050 EXPECT_EQ(0U, start); 1048 ASSERT_TRUE(omnibox_view->GetText().empty());
1051 EXPECT_EQ(omnibox_view->GetText().size(), end);
1052 1049
1053 // Pressing tab should move cursor to the end. 1050 // Revert to keyword hint mode with SHIFT+TAB.
1051 #if defined(OS_MACOSX)
1052 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACKTAB, 0));
1053 #else
1054 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1055 #endif
1056 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1057 ASSERT_EQ(text, omnibox_view->model()->keyword());
1058 ASSERT_EQ(text, omnibox_view->GetText());
1059
1060 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
1061 location_bar_focus_view_id_));
1062 }
1063
1064 void TabTraverseResultsTest() {
1065 OmniboxView* omnibox_view = NULL;
1066 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1067 AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model();
1068 ASSERT_TRUE(popup_model);
1069
1070 // Input something to trigger results.
1071 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys));
1072 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1073 ASSERT_TRUE(popup_model->IsOpen());
1074
1075 size_t old_selected_line = popup_model->selected_line();
1076 EXPECT_EQ(0U, old_selected_line);
1077
1078 // Move down the results.
1079 size_t size = popup_model->result().size();
Peter Kasting 2012/01/25 05:53:05 Nit: Optional form: for (size_t size = popup_
1080 while (popup_model->selected_line() < size - 1) {
1081 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1082 ASSERT_LT(old_selected_line, popup_model->selected_line());
1083 old_selected_line = popup_model->selected_line();
1084 }
1085
1086 // Don't move past the end.
1054 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); 1087 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1055 1088 ASSERT_EQ(old_selected_line, popup_model->selected_line());
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(), 1089 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
1062 location_bar_focus_view_id_)); 1090 location_bar_focus_view_id_));
1063 1091
1064 // Pressing tab when cursor is at the end should change focus. 1092 // Move back up the results.
1065 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); 1093 while (popup_model->selected_line() > 0U) {
1094 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1095 ASSERT_GT(old_selected_line, popup_model->selected_line());
1096 old_selected_line = popup_model->selected_line();
1097 }
1066 1098
1067 ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(), 1099 // Don't move past the beginning.
1068 location_bar_focus_view_id_)); 1100 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1101 ASSERT_EQ(0U, popup_model->selected_line());
1102 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
1103 location_bar_focus_view_id_));
1069 } 1104 }
1070 1105
1071 void PersistKeywordModeOnTabSwitch() { 1106 void PersistKeywordModeOnTabSwitch() {
1072 OmniboxView* omnibox_view = NULL; 1107 OmniboxView* omnibox_view = NULL;
1073 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 1108 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1074 1109
1075 // Trigger keyword hint mode. 1110 // Trigger keyword hint mode.
1076 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 1111 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1077 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 1112 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1078 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); 1113 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 1219
1185 #if defined(OS_POSIX) 1220 #if defined(OS_POSIX)
1186 // Flaky on Mac 10.6, Linux http://crbug.com/84420 1221 // Flaky on Mac 10.6, Linux http://crbug.com/84420
1187 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_DeleteItem) { 1222 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_DeleteItem) {
1188 #else 1223 #else
1189 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) { 1224 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) {
1190 #endif 1225 #endif
1191 DeleteItemTest(); 1226 DeleteItemTest();
1192 } 1227 }
1193 1228
1194 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabMoveCursorToEnd) { 1229 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabAcceptKeyword) {
1195 TabMoveCursorToEndTest(); 1230 TabAcceptKeyword();
1196 } 1231 }
1197 1232
1233 #if !defined(OS_MACOSX)
1234 // Mac intentionally does not support this behavior.
1235 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabTraverseResultsTest) {
1236 TabTraverseResultsTest();
1237 }
1238 #endif
1239
1198 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, 1240 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1199 PersistKeywordModeOnTabSwitch) { 1241 PersistKeywordModeOnTabSwitch) {
1200 PersistKeywordModeOnTabSwitch(); 1242 PersistKeywordModeOnTabSwitch();
1201 } 1243 }
1202 1244
1203 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, 1245 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1204 CtrlKeyPressedWithInlineAutocompleteTest) { 1246 CtrlKeyPressedWithInlineAutocompleteTest) {
1205 CtrlKeyPressedWithInlineAutocompleteTest(); 1247 CtrlKeyPressedWithInlineAutocompleteTest();
1206 } 1248 }
1207 1249
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 1369
1328 // Paste text. 1370 // Paste text.
1329 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); 1371 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN));
1330 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1372 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1331 ASSERT_TRUE(popup_model->IsOpen()); 1373 ASSERT_TRUE(popup_model->IsOpen());
1332 1374
1333 // Inline autocomplete shouldn't be triggered. 1375 // Inline autocomplete shouldn't be triggered.
1334 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); 1376 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText());
1335 } 1377 }
1336 #endif 1378 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/omnibox_view.h ('k') | chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698