| OLD | NEW |
| 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 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. |
| 1054 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); | 1051 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN)); |
| 1052 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); |
| 1053 ASSERT_EQ(text, omnibox_view->model()->keyword()); |
| 1054 ASSERT_EQ(text, omnibox_view->GetText()); |
| 1055 | 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(), | 1056 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 1062 location_bar_focus_view_id_)); | 1057 location_bar_focus_view_id_)); |
| 1063 | |
| 1064 // Pressing tab when cursor is at the end should change focus. | |
| 1065 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); | |
| 1066 | |
| 1067 ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(), | |
| 1068 location_bar_focus_view_id_)); | |
| 1069 } | 1058 } |
| 1070 | 1059 |
| 1071 void PersistKeywordModeOnTabSwitch() { | 1060 void PersistKeywordModeOnTabSwitch() { |
| 1072 OmniboxView* omnibox_view = NULL; | 1061 OmniboxView* omnibox_view = NULL; |
| 1073 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1062 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
| 1074 | 1063 |
| 1075 // Trigger keyword hint mode. | 1064 // Trigger keyword hint mode. |
| 1076 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); | 1065 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); |
| 1077 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); | 1066 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); |
| 1078 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); | 1067 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 | 1173 |
| 1185 #if defined(OS_POSIX) | 1174 #if defined(OS_POSIX) |
| 1186 // Flaky on Mac 10.6, Linux http://crbug.com/84420 | 1175 // Flaky on Mac 10.6, Linux http://crbug.com/84420 |
| 1187 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_DeleteItem) { | 1176 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_DeleteItem) { |
| 1188 #else | 1177 #else |
| 1189 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) { | 1178 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) { |
| 1190 #endif | 1179 #endif |
| 1191 DeleteItemTest(); | 1180 DeleteItemTest(); |
| 1192 } | 1181 } |
| 1193 | 1182 |
| 1194 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabMoveCursorToEnd) { | 1183 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabAcceptKeyword) { |
| 1195 TabMoveCursorToEndTest(); | 1184 TabAcceptKeyword(); |
| 1196 } | 1185 } |
| 1197 | 1186 |
| 1198 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, | 1187 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, |
| 1199 PersistKeywordModeOnTabSwitch) { | 1188 PersistKeywordModeOnTabSwitch) { |
| 1200 PersistKeywordModeOnTabSwitch(); | 1189 PersistKeywordModeOnTabSwitch(); |
| 1201 } | 1190 } |
| 1202 | 1191 |
| 1203 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, | 1192 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, |
| 1204 CtrlKeyPressedWithInlineAutocompleteTest) { | 1193 CtrlKeyPressedWithInlineAutocompleteTest) { |
| 1205 CtrlKeyPressedWithInlineAutocompleteTest(); | 1194 CtrlKeyPressedWithInlineAutocompleteTest(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 | 1316 |
| 1328 // Paste text. | 1317 // Paste text. |
| 1329 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); | 1318 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); |
| 1330 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1319 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 1331 ASSERT_TRUE(popup_model->IsOpen()); | 1320 ASSERT_TRUE(popup_model->IsOpen()); |
| 1332 | 1321 |
| 1333 // Inline autocomplete shouldn't be triggered. | 1322 // Inline autocomplete shouldn't be triggered. |
| 1334 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); | 1323 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); |
| 1335 } | 1324 } |
| 1336 #endif | 1325 #endif |
| OLD | NEW |