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

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

Issue 9419043: Revert 122412 - Enabled pressing TAB to traverse through the Omnibox results (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 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 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 749
750 // Revert to keyword hint mode. 750 // Revert to keyword hint mode.
751 omnibox_view->model()->ClearKeyword(string16()); 751 omnibox_view->model()->ClearKeyword(string16());
752 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 752 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
753 ASSERT_EQ(text, omnibox_view->model()->keyword()); 753 ASSERT_EQ(text, omnibox_view->model()->keyword());
754 ASSERT_EQ(text, omnibox_view->GetText()); 754 ASSERT_EQ(text, omnibox_view->GetText());
755 755
756 // Keyword should also be accepted by typing an ideographic space. 756 // Keyword should also be accepted by typing an ideographic space.
757 omnibox_view->OnBeforePossibleChange(); 757 omnibox_view->OnBeforePossibleChange();
758 omnibox_view->SetWindowTextAndCaretPos(text + WideToUTF16(L"\x3000"), 758 omnibox_view->SetWindowTextAndCaretPos(text + WideToUTF16(L"\x3000"),
759 text.length() + 1, false, false); 759 text.length() + 1);
760 omnibox_view->OnAfterPossibleChange(); 760 omnibox_view->OnAfterPossibleChange();
761 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 761 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
762 ASSERT_EQ(text, omnibox_view->model()->keyword()); 762 ASSERT_EQ(text, omnibox_view->model()->keyword());
763 ASSERT_TRUE(omnibox_view->GetText().empty()); 763 ASSERT_TRUE(omnibox_view->GetText().empty());
764 764
765 // Revert to keyword hint mode. 765 // Revert to keyword hint mode.
766 omnibox_view->model()->ClearKeyword(string16()); 766 omnibox_view->model()->ClearKeyword(string16());
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, omnibox_view->GetText()); 769 ASSERT_EQ(text, omnibox_view->GetText());
770 770
771 // Keyword shouldn't be accepted by pressing space with a trailing 771 // Keyword shouldn't be accepted by pressing space with a trailing
772 // whitespace. 772 // whitespace.
773 omnibox_view->SetWindowTextAndCaretPos( 773 omnibox_view->SetWindowTextAndCaretPos(
774 text + char16(' '), text.length() + 1, false, false); 774 text + char16(' '), text.length() + 1);
775 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 775 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
776 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 776 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
777 ASSERT_EQ(text, omnibox_view->model()->keyword()); 777 ASSERT_EQ(text, omnibox_view->model()->keyword());
778 ASSERT_EQ(text + ASCIIToUTF16(" "), omnibox_view->GetText()); 778 ASSERT_EQ(text + ASCIIToUTF16(" "), omnibox_view->GetText());
779 779
780 // Keyword shouldn't be accepted by deleting the trailing space. 780 // Keyword shouldn't be accepted by deleting the trailing space.
781 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0)); 781 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
782 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 782 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
783 ASSERT_EQ(text, omnibox_view->model()->keyword()); 783 ASSERT_EQ(text, omnibox_view->model()->keyword());
784 ASSERT_EQ(text + char16(' '), omnibox_view->GetText()); 784 ASSERT_EQ(text + char16(' '), omnibox_view->GetText());
(...skipping 16 matching lines...) Expand all
801 ASSERT_EQ(ASCIIToUTF16("a "), omnibox_view->GetText()); 801 ASSERT_EQ(ASCIIToUTF16("a "), omnibox_view->GetText());
802 802
803 // Keyword shouldn't be accepted by pasting "foo bar". 803 // Keyword shouldn't be accepted by pasting "foo bar".
804 omnibox_view->SetUserText(string16()); 804 omnibox_view->SetUserText(string16());
805 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 805 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
806 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); 806 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
807 807
808 omnibox_view->OnBeforePossibleChange(); 808 omnibox_view->OnBeforePossibleChange();
809 omnibox_view->model()->on_paste(); 809 omnibox_view->model()->on_paste();
810 omnibox_view->SetWindowTextAndCaretPos(text + ASCIIToUTF16(" bar"), 810 omnibox_view->SetWindowTextAndCaretPos(text + ASCIIToUTF16(" bar"),
811 text.length() + 4, false, false); 811 text.length() + 4);
812 omnibox_view->OnAfterPossibleChange(); 812 omnibox_view->OnAfterPossibleChange();
813 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 813 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
814 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); 814 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
815 ASSERT_EQ(text + ASCIIToUTF16(" bar"), omnibox_view->GetText()); 815 ASSERT_EQ(text + ASCIIToUTF16(" bar"), omnibox_view->GetText());
816 816
817 // Keyword shouldn't be accepted for case like: "foo b|ar" -> "foo b |ar". 817 // Keyword shouldn't be accepted for case like: "foo b|ar" -> "foo b |ar".
818 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0)); 818 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
819 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0)); 819 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
820 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 820 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
821 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 821 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 ASSERT_EQ(selected_text, omnibox_view->GetText()); 1015 ASSERT_EQ(selected_text, omnibox_view->GetText());
1016 #endif 1016 #endif
1017 1017
1018 // As the current selected item is the new default item, pressing Escape key 1018 // As the current selected item is the new default item, pressing Escape key
1019 // should revert all directly. 1019 // should revert all directly.
1020 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed()); 1020 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed());
1021 ASSERT_EQ(old_text, omnibox_view->GetText()); 1021 ASSERT_EQ(old_text, omnibox_view->GetText());
1022 ASSERT_TRUE(omnibox_view->IsSelectAll()); 1022 ASSERT_TRUE(omnibox_view->IsSelectAll());
1023 } 1023 }
1024 1024
1025 void TabAcceptKeyword() { 1025 void TabMoveCursorToEndTest() {
1026 OmniboxView* omnibox_view = NULL; 1026 OmniboxView* omnibox_view = NULL;
1027 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 1027 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1028 1028
1029 string16 text = ASCIIToUTF16(kSearchKeyword); 1029 omnibox_view->SetUserText(ASCIIToUTF16("Hello world"));
1030 1030
1031 // Trigger keyword hint mode. 1031 // Move cursor to the beginning.
1032 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 1032 #if defined(OS_MACOSX)
1033 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 1033 // Home doesn't work on Mac trybot.
1034 ASSERT_EQ(text, omnibox_view->model()->keyword()); 1034 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, ui::EF_CONTROL_DOWN));
1035 ASSERT_EQ(text, omnibox_view->GetText()); 1035 #else
1036 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, 0));
1037 #endif
1036 1038
1037 // Trigger keyword mode by tab. 1039 size_t start, end;
1040 omnibox_view->GetSelectionBounds(&start, &end);
1041 EXPECT_EQ(0U, start);
1042 EXPECT_EQ(0U, end);
1043
1044 // Pressing tab should move cursor to the end.
1038 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); 1045 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1039 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1040 ASSERT_EQ(text, omnibox_view->model()->keyword());
1041 ASSERT_TRUE(omnibox_view->GetText().empty());
1042 1046
1043 // Revert to keyword hint mode. 1047 omnibox_view->GetSelectionBounds(&start, &end);
1044 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0)); 1048 EXPECT_EQ(omnibox_view->GetText().size(), start);
1045 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 1049 EXPECT_EQ(omnibox_view->GetText().size(), end);
1046 ASSERT_EQ(text, omnibox_view->model()->keyword());
1047 ASSERT_EQ(text, omnibox_view->GetText());
1048 1050
1049 // The location bar should still have focus. 1051 // The location bar should still have focus.
1050 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), 1052 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
1051 location_bar_focus_view_id_)); 1053 location_bar_focus_view_id_));
1052 1054
1053 // Trigger keyword mode by tab. 1055 // Select all text.
1056 omnibox_view->SelectAll(true);
1057 EXPECT_TRUE(omnibox_view->IsSelectAll());
1058 omnibox_view->GetSelectionBounds(&start, &end);
1059 EXPECT_EQ(0U, start);
1060 EXPECT_EQ(omnibox_view->GetText().size(), end);
1061
1062 // Pressing tab should move cursor to the end.
1054 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); 1063 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1055 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1056 ASSERT_EQ(text, omnibox_view->model()->keyword());
1057 ASSERT_TRUE(omnibox_view->GetText().empty());
1058 1064
1059 // Revert to keyword hint mode with SHIFT+TAB. 1065 omnibox_view->GetSelectionBounds(&start, &end);
1060 #if defined(OS_MACOSX) 1066 EXPECT_EQ(omnibox_view->GetText().size(), start);
1061 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACKTAB, 0)); 1067 EXPECT_EQ(omnibox_view->GetText().size(), end);
1062 #else
1063 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1064 #endif
1065 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1066 ASSERT_EQ(text, omnibox_view->model()->keyword());
1067 ASSERT_EQ(text, omnibox_view->GetText());
1068
1069 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
1070 location_bar_focus_view_id_));
1071 }
1072
1073 void TabTraverseResultsTest() {
1074 OmniboxView* omnibox_view = NULL;
1075 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1076 AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model();
1077 ASSERT_TRUE(popup_model);
1078
1079 // Input something to trigger results.
1080 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys));
1081 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1082 ASSERT_TRUE(popup_model->IsOpen());
1083
1084 size_t old_selected_line = popup_model->selected_line();
1085 EXPECT_EQ(0U, old_selected_line);
1086
1087 // Move down the results.
1088 for (size_t size = popup_model->result().size();
1089 popup_model->selected_line() < size - 1;
1090 old_selected_line = popup_model->selected_line()) {
1091 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1092 ASSERT_LT(old_selected_line, popup_model->selected_line());
1093 }
1094
1095 // Don't move past the end.
1096 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1097 ASSERT_EQ(old_selected_line, popup_model->selected_line());
1098 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
1099 location_bar_focus_view_id_));
1100
1101 // Move back up the results.
1102 for (; popup_model->selected_line() > 0U;
1103 old_selected_line = popup_model->selected_line()) {
1104 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1105 ASSERT_GT(old_selected_line, popup_model->selected_line());
1106 }
1107
1108 // Don't move past the beginning.
1109 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1110 ASSERT_EQ(0U, popup_model->selected_line());
1111 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
1112 location_bar_focus_view_id_));
1113
1114 const TestHistoryEntry kHistoryFoo = {
1115 "http://foo/", "Page foo", kSearchText, 1, 1, false
1116 };
1117
1118 // Add a history entry so "foo" gets multiple matches.
1119 ASSERT_NO_FATAL_FAILURE(
1120 AddHistoryEntry(kHistoryFoo, Time::Now() - TimeDelta::FromHours(1)));
1121
1122 // Load results.
1123 ASSERT_NO_FATAL_FAILURE(omnibox_view->SelectAll(false));
1124 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1125 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1126
1127 // Trigger keyword mode by tab.
1128 string16 text = ASCIIToUTF16(kSearchKeyword);
1129 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1130 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1131 ASSERT_EQ(text, omnibox_view->model()->keyword());
1132 ASSERT_TRUE(omnibox_view->GetText().empty());
1133 1068
1134 // The location bar should still have focus. 1069 // The location bar should still have focus.
1135 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), 1070 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
1136 location_bar_focus_view_id_)); 1071 location_bar_focus_view_id_));
1137 1072
1138 // Pressing tab again should move to the next result and clear keyword 1073 // Pressing tab when cursor is at the end should change focus.
1139 // mode.
1140 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); 1074 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1141 ASSERT_EQ(1U, omnibox_view->model()->popup_model()->selected_line());
1142 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1143 ASSERT_NE(text, omnibox_view->model()->keyword());
1144 1075
1145 // The location bar should still have focus. 1076 ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(),
1146 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), 1077 location_bar_focus_view_id_));
1147 location_bar_focus_view_id_));
1148
1149 // Moving back up should not show keyword mode.
1150 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1151 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1152 ASSERT_EQ(text, omnibox_view->model()->keyword());
1153
1154 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
1155 location_bar_focus_view_id_));
1156 } 1078 }
1157 1079
1158 void PersistKeywordModeOnTabSwitch() { 1080 void PersistKeywordModeOnTabSwitch() {
1159 OmniboxView* omnibox_view = NULL; 1081 OmniboxView* omnibox_view = NULL;
1160 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 1082 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1161 1083
1162 // Trigger keyword hint mode. 1084 // Trigger keyword hint mode.
1163 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 1085 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1164 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 1086 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1165 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); 1087 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 1188
1267 #if defined(OS_POSIX) 1189 #if defined(OS_POSIX)
1268 // Flaky on Mac 10.6, Linux http://crbug.com/84420 1190 // Flaky on Mac 10.6, Linux http://crbug.com/84420
1269 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_DeleteItem) { 1191 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_DeleteItem) {
1270 #else 1192 #else
1271 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) { 1193 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) {
1272 #endif 1194 #endif
1273 DeleteItemTest(); 1195 DeleteItemTest();
1274 } 1196 }
1275 1197
1276 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabAcceptKeyword) { 1198 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabMoveCursorToEnd) {
1277 TabAcceptKeyword(); 1199 TabMoveCursorToEndTest();
1278 } 1200 }
1279 1201
1280 #if !defined(OS_MACOSX)
1281 // Mac intentionally does not support this behavior.
1282 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabTraverseResultsTest) {
1283 TabTraverseResultsTest();
1284 }
1285 #endif
1286
1287 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, 1202 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1288 PersistKeywordModeOnTabSwitch) { 1203 PersistKeywordModeOnTabSwitch) {
1289 PersistKeywordModeOnTabSwitch(); 1204 PersistKeywordModeOnTabSwitch();
1290 } 1205 }
1291 1206
1292 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, 1207 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1293 CtrlKeyPressedWithInlineAutocompleteTest) { 1208 CtrlKeyPressedWithInlineAutocompleteTest) {
1294 CtrlKeyPressedWithInlineAutocompleteTest(); 1209 CtrlKeyPressedWithInlineAutocompleteTest();
1295 } 1210 }
1296 1211
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 1331
1417 // Paste text. 1332 // Paste text.
1418 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); 1333 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN));
1419 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1334 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1420 ASSERT_TRUE(popup_model->IsOpen()); 1335 ASSERT_TRUE(popup_model->IsOpen());
1421 1336
1422 // Inline autocomplete shouldn't be triggered. 1337 // Inline autocomplete shouldn't be triggered.
1423 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); 1338 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText());
1424 } 1339 }
1425 #endif 1340 #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