| 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 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 // Keyword should be accepted by pressing space in the middle of context and | 784 // Keyword should be accepted by pressing space in the middle of context and |
| 785 // just after the keyword. | 785 // just after the keyword. |
| 786 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0)); | 786 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0)); |
| 787 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0)); | 787 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0)); |
| 788 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0)); | 788 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0)); |
| 789 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); | 789 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); |
| 790 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); | 790 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); |
| 791 ASSERT_EQ(text, omnibox_view->model()->keyword()); | 791 ASSERT_EQ(text, omnibox_view->model()->keyword()); |
| 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," but the Omnibox |
| 795 // should still show a keyword hint. |
| 795 omnibox_view->SetUserText(string16()); | 796 omnibox_view->SetUserText(string16()); |
| 796 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); | 797 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); |
| 797 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); | 798 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); |
| 798 | 799 |
| 799 omnibox_view->OnBeforePossibleChange(); | 800 omnibox_view->OnBeforePossibleChange(); |
| 800 omnibox_view->model()->on_paste(); | 801 omnibox_view->model()->on_paste(); |
| 801 omnibox_view->SetWindowTextAndCaretPos(text + ASCIIToUTF16(" bar"), | 802 omnibox_view->SetWindowTextAndCaretPos(text + ASCIIToUTF16(" bar"), |
| 802 text.length() + 4); | 803 text.length() + 4); |
| 803 omnibox_view->OnAfterPossibleChange(); | 804 omnibox_view->OnAfterPossibleChange(); |
| 804 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); | 805 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); |
| 805 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); | 806 ASSERT_EQ(text, omnibox_view->model()->keyword()); |
| 806 ASSERT_EQ(text + ASCIIToUTF16(" bar"), omnibox_view->GetText()); | 807 ASSERT_EQ(text + ASCIIToUTF16(" bar"), omnibox_view->GetText()); |
| 807 | 808 |
| 808 // Keyword shouldn't be accepted for case like: "foo b|ar" -> "foo b |ar". | 809 // Keyword shouldn't be accepted for case like: "foo b|ar" -> "foo b |ar". |
| 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_LEFT, 0)); |
| 811 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); | 812 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); |
| 812 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); | 813 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); |
| 813 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); | 814 ASSERT_EQ(text, omnibox_view->model()->keyword()); |
| 814 ASSERT_EQ(text + ASCIIToUTF16(" b ar"), omnibox_view->GetText()); | 815 ASSERT_EQ(text + ASCIIToUTF16(" b ar"), omnibox_view->GetText()); |
| 815 | 816 |
| 816 // Keyword could be accepted by pressing space with a selected range at the | 817 // Keyword could be accepted by pressing space with a selected range at the |
| 817 // end of text. | 818 // end of text. |
| 818 omnibox_view->OnBeforePossibleChange(); | 819 omnibox_view->OnBeforePossibleChange(); |
| 819 omnibox_view->OnInlineAutocompleteTextMaybeChanged( | 820 omnibox_view->OnInlineAutocompleteTextMaybeChanged( |
| 820 text + ASCIIToUTF16(" "), text.length()); | 821 text + ASCIIToUTF16(" "), text.length()); |
| 821 omnibox_view->OnAfterPossibleChange(); | 822 omnibox_view->OnAfterPossibleChange(); |
| 822 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); | 823 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); |
| 823 ASSERT_EQ(text, omnibox_view->model()->keyword()); | 824 ASSERT_EQ(text, omnibox_view->model()->keyword()); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 ASSERT_EQ(selected_text, omnibox_view->GetText()); | 1007 ASSERT_EQ(selected_text, omnibox_view->GetText()); |
| 1007 #endif | 1008 #endif |
| 1008 | 1009 |
| 1009 // 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 |
| 1010 // should revert all directly. | 1011 // should revert all directly. |
| 1011 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed()); | 1012 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed()); |
| 1012 ASSERT_EQ(old_text, omnibox_view->GetText()); | 1013 ASSERT_EQ(old_text, omnibox_view->GetText()); |
| 1013 ASSERT_TRUE(omnibox_view->IsSelectAll()); | 1014 ASSERT_TRUE(omnibox_view->IsSelectAll()); |
| 1014 } | 1015 } |
| 1015 | 1016 |
| 1016 void TabMoveCursorToEndTest() { | 1017 void TabAcceptKeyword() { |
| 1017 OmniboxView* omnibox_view = NULL; | 1018 OmniboxView* omnibox_view = NULL; |
| 1018 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1019 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
| 1019 | 1020 |
| 1020 omnibox_view->SetUserText(ASCIIToUTF16("Hello world")); | 1021 string16 text = ASCIIToUTF16(kSearchKeyword); |
| 1021 | 1022 |
| 1022 // Move cursor to the beginning. | 1023 // Trigger keyword hint mode. |
| 1023 #if defined(OS_MACOSX) | 1024 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); |
| 1024 // Home doesn't work on Mac trybot. | 1025 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); |
| 1025 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, ui::EF_CONTROL_DOWN)); | 1026 ASSERT_EQ(text, omnibox_view->model()->keyword()); |
| 1026 #else | 1027 ASSERT_EQ(text, omnibox_view->GetText()); |
| 1027 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, 0)); | |
| 1028 #endif | |
| 1029 | 1028 |
| 1030 size_t start, end; | 1029 // Trigger keyword mode by tab. |
| 1031 omnibox_view->GetSelectionBounds(&start, &end); | 1030 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); |
| 1032 EXPECT_EQ(0U, start); | 1031 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); |
| 1033 EXPECT_EQ(0U, end); | 1032 ASSERT_EQ(text, omnibox_view->model()->keyword()); |
| 1033 ASSERT_TRUE(omnibox_view->GetText().empty()); |
| 1034 | 1034 |
| 1035 // Pressing tab should move cursor to the end. | 1035 // Revert to keyword hint mode. |
| 1036 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); | 1036 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0)); |
| 1037 | 1037 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); |
| 1038 omnibox_view->GetSelectionBounds(&start, &end); | 1038 ASSERT_EQ(text, omnibox_view->model()->keyword()); |
| 1039 EXPECT_EQ(omnibox_view->GetText().size(), start); | 1039 ASSERT_EQ(text, omnibox_view->GetText()); |
| 1040 EXPECT_EQ(omnibox_view->GetText().size(), end); | |
| 1041 | 1040 |
| 1042 // The location bar should still have focus. | 1041 // The location bar should still have focus. |
| 1043 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), | 1042 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 1044 location_bar_focus_view_id_)); | 1043 location_bar_focus_view_id_)); |
| 1045 | 1044 |
| 1046 // Select all text. | 1045 // Trigger keyword mode by tab. |
| 1047 omnibox_view->SelectAll(true); | 1046 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); |
| 1048 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 1047 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); |
| 1049 omnibox_view->GetSelectionBounds(&start, &end); | 1048 ASSERT_EQ(text, omnibox_view->model()->keyword()); |
| 1050 EXPECT_EQ(0U, start); | 1049 ASSERT_TRUE(omnibox_view->GetText().empty()); |
| 1051 EXPECT_EQ(omnibox_view->GetText().size(), end); | |
| 1052 | 1050 |
| 1053 // Pressing tab should move cursor to the end. | 1051 // Revert to keyword hint mode with SHIFT+TAB. |
| 1054 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); | 1052 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN)); |
| 1053 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); |
| 1054 ASSERT_EQ(text, omnibox_view->model()->keyword()); |
| 1055 ASSERT_EQ(text, omnibox_view->GetText()); |
| 1055 | 1056 |
| 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(), | 1057 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 1062 location_bar_focus_view_id_)); | 1058 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 } | 1059 } |
| 1070 | 1060 |
| 1071 void PersistKeywordModeOnTabSwitch() { | 1061 void PersistKeywordModeOnTabSwitch() { |
| 1072 OmniboxView* omnibox_view = NULL; | 1062 OmniboxView* omnibox_view = NULL; |
| 1073 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1063 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
| 1074 | 1064 |
| 1075 // Trigger keyword hint mode. | 1065 // Trigger keyword hint mode. |
| 1076 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); | 1066 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); |
| 1077 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); | 1067 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); |
| 1078 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); | 1068 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword())); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1184 | 1174 |
| 1185 #if defined(OS_POSIX) | 1175 #if defined(OS_POSIX) |
| 1186 // Flaky on Mac 10.6, Linux http://crbug.com/84420 | 1176 // Flaky on Mac 10.6, Linux http://crbug.com/84420 |
| 1187 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_DeleteItem) { | 1177 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, FLAKY_DeleteItem) { |
| 1188 #else | 1178 #else |
| 1189 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) { | 1179 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) { |
| 1190 #endif | 1180 #endif |
| 1191 DeleteItemTest(); | 1181 DeleteItemTest(); |
| 1192 } | 1182 } |
| 1193 | 1183 |
| 1194 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabMoveCursorToEnd) { | 1184 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, TabAcceptKeyword) { |
| 1195 TabMoveCursorToEndTest(); | 1185 TabAcceptKeyword(); |
| 1196 } | 1186 } |
| 1197 | 1187 |
| 1198 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, | 1188 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, |
| 1199 PersistKeywordModeOnTabSwitch) { | 1189 PersistKeywordModeOnTabSwitch) { |
| 1200 PersistKeywordModeOnTabSwitch(); | 1190 PersistKeywordModeOnTabSwitch(); |
| 1201 } | 1191 } |
| 1202 | 1192 |
| 1203 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, | 1193 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, |
| 1204 CtrlKeyPressedWithInlineAutocompleteTest) { | 1194 CtrlKeyPressedWithInlineAutocompleteTest) { |
| 1205 CtrlKeyPressedWithInlineAutocompleteTest(); | 1195 CtrlKeyPressedWithInlineAutocompleteTest(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 | 1317 |
| 1328 // Paste text. | 1318 // Paste text. |
| 1329 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); | 1319 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); |
| 1330 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1320 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 1331 ASSERT_TRUE(popup_model->IsOpen()); | 1321 ASSERT_TRUE(popup_model->IsOpen()); |
| 1332 | 1322 |
| 1333 // Inline autocomplete shouldn't be triggered. | 1323 // Inline autocomplete shouldn't be triggered. |
| 1334 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); | 1324 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); |
| 1335 } | 1325 } |
| 1336 #endif | 1326 #endif |
| OLD | NEW |