| 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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 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 |