OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 // New temporary text is shown. | 997 // New temporary text is shown. |
998 ASSERT_EQ(selected_text, edit_view->GetText()); | 998 ASSERT_EQ(selected_text, edit_view->GetText()); |
999 | 999 |
1000 // As the current selected item is the new default item, pressing Escape key | 1000 // As the current selected item is the new default item, pressing Escape key |
1001 // should revert all directly. | 1001 // should revert all directly. |
1002 ASSERT_TRUE(edit_view->model()->OnEscapeKeyPressed()); | 1002 ASSERT_TRUE(edit_view->model()->OnEscapeKeyPressed()); |
1003 ASSERT_EQ(old_text, edit_view->GetText()); | 1003 ASSERT_EQ(old_text, edit_view->GetText()); |
1004 ASSERT_TRUE(edit_view->IsSelectAll()); | 1004 ASSERT_TRUE(edit_view->IsSelectAll()); |
1005 } | 1005 } |
1006 | 1006 |
1007 void TabMoveCursorToEndTest() { | 1007 void TabAcceptKeyword() { |
1008 AutocompleteEditView* edit_view = NULL; | 1008 AutocompleteEditView* edit_view = NULL; |
1009 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | 1009 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
1010 | 1010 |
1011 edit_view->SetUserText(ASCIIToUTF16("Hello world")); | 1011 string16 text = UTF8ToUTF16(kSearchKeyword); |
1012 | 1012 |
1013 // Move cursor to the beginning. | 1013 // Trigger keyword hint mode. |
1014 #if defined(OS_MACOSX) | 1014 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); |
1015 // Home doesn't work on Mac trybot. | 1015 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
1016 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, ui::EF_CONTROL_DOWN)); | 1016 ASSERT_EQ(text, edit_view->model()->keyword()); |
1017 #else | 1017 ASSERT_EQ(text, edit_view->GetText()); |
1018 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, 0)); | |
1019 #endif | |
1020 | 1018 |
1021 string16::size_type start, end; | 1019 // Trigger keyword mode by tab. |
1022 edit_view->GetSelectionBounds(&start, &end); | 1020 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); |
1023 EXPECT_EQ(0U, start); | 1021 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
1024 EXPECT_EQ(0U, end); | 1022 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 1023 ASSERT_TRUE(edit_view->GetText().empty()); |
1025 | 1024 |
1026 // Pressing tab should move cursor to the end. | 1025 // Revert to keyword hint mode. |
1027 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); | 1026 edit_view->model()->ClearKeyword(string16()); |
1028 | 1027 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
1029 edit_view->GetSelectionBounds(&start, &end); | 1028 ASSERT_EQ(text, edit_view->model()->keyword()); |
1030 EXPECT_EQ(edit_view->GetText().size(), start); | 1029 ASSERT_EQ(text, edit_view->GetText()); |
1031 EXPECT_EQ(edit_view->GetText().size(), end); | |
1032 | |
1033 // The location bar should still have focus. | |
1034 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | |
1035 | |
1036 // Select all text. | |
1037 edit_view->SelectAll(true); | |
1038 EXPECT_TRUE(edit_view->IsSelectAll()); | |
1039 edit_view->GetSelectionBounds(&start, &end); | |
1040 EXPECT_EQ(0U, start); | |
1041 EXPECT_EQ(edit_view->GetText().size(), end); | |
1042 | |
1043 // Pressing tab should move cursor to the end. | |
1044 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); | |
1045 | |
1046 edit_view->GetSelectionBounds(&start, &end); | |
1047 EXPECT_EQ(edit_view->GetText().size(), start); | |
1048 EXPECT_EQ(edit_view->GetText().size(), end); | |
1049 | |
1050 // The location bar should still have focus. | |
1051 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | |
1052 | |
1053 // Pressing tab when cursor is at the end should change focus. | |
1054 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0)); | |
1055 | |
1056 ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | |
1057 } | 1030 } |
1058 | 1031 |
1059 void PersistKeywordModeOnTabSwitch() { | 1032 void PersistKeywordModeOnTabSwitch() { |
1060 AutocompleteEditView* edit_view = NULL; | 1033 AutocompleteEditView* edit_view = NULL; |
1061 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | 1034 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
1062 | 1035 |
1063 // Trigger keyword hint mode. | 1036 // Trigger keyword hint mode. |
1064 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); | 1037 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); |
1065 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | 1038 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
1066 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(edit_view->model()->keyword())); | 1039 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(edit_view->model()->keyword())); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 | 1071 |
1099 // Make sure inline autocomplete is triggerred. | 1072 // Make sure inline autocomplete is triggerred. |
1100 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); | 1073 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); |
1101 | 1074 |
1102 // Press ctrl key. | 1075 // Press ctrl key. |
1103 edit_view->model()->OnControlKeyChanged(true); | 1076 edit_view->model()->OnControlKeyChanged(true); |
1104 | 1077 |
1105 // Inline autocomplete should still be there. | 1078 // Inline autocomplete should still be there. |
1106 EXPECT_EQ(old_text, edit_view->GetText()); | 1079 EXPECT_EQ(old_text, edit_view->GetText()); |
1107 } | 1080 } |
1108 | |
1109 }; | 1081 }; |
1110 | 1082 |
1111 // Test if ctrl-* accelerators are workable in omnibox. | 1083 // Test if ctrl-* accelerators are workable in omnibox. |
1112 // See http://crbug.com/19193: omnibox blocks ctrl-* commands | 1084 // See http://crbug.com/19193: omnibox blocks ctrl-* commands |
1113 // | 1085 // |
1114 // Flaky on interactive tests (dbg), http://crbug.com/69433 | 1086 // Flaky on interactive tests (dbg), http://crbug.com/69433 |
1115 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { | 1087 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { |
1116 BrowserAcceleratorsTest(); | 1088 BrowserAcceleratorsTest(); |
1117 } | 1089 } |
1118 | 1090 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 } | 1132 } |
1161 | 1133 |
1162 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, NonSubstitutingKeywordTest) { | 1134 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, NonSubstitutingKeywordTest) { |
1163 NonSubstitutingKeywordTest(); | 1135 NonSubstitutingKeywordTest(); |
1164 } | 1136 } |
1165 | 1137 |
1166 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DeleteItem) { | 1138 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DeleteItem) { |
1167 DeleteItemTest(); | 1139 DeleteItemTest(); |
1168 } | 1140 } |
1169 | 1141 |
1170 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, TabMoveCursorToEnd) { | 1142 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, TabAcceptKeyword) { |
1171 TabMoveCursorToEndTest(); | 1143 TabAcceptKeyword(); |
1172 } | 1144 } |
1173 | 1145 |
1174 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, | 1146 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, |
1175 PersistKeywordModeOnTabSwitch) { | 1147 PersistKeywordModeOnTabSwitch) { |
1176 PersistKeywordModeOnTabSwitch(); | 1148 PersistKeywordModeOnTabSwitch(); |
1177 } | 1149 } |
1178 | 1150 |
1179 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, | 1151 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, |
1180 CtrlKeyPressedWithInlineAutocompleteTest) { | 1152 CtrlKeyPressedWithInlineAutocompleteTest) { |
1181 CtrlKeyPressedWithInlineAutocompleteTest(); | 1153 CtrlKeyPressedWithInlineAutocompleteTest(); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 } | 1337 } |
1366 | 1338 |
1367 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, DeleteItem) { | 1339 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, DeleteItem) { |
1368 DeleteItemTest(); | 1340 DeleteItemTest(); |
1369 } | 1341 } |
1370 | 1342 |
1371 // TODO(suzhe): This test is broken because of broken ViewID support when | 1343 // TODO(suzhe): This test is broken because of broken ViewID support when |
1372 // enabling AutocompleteEditViewViews. | 1344 // enabling AutocompleteEditViewViews. |
1373 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, | 1345 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, |
1374 DISABLED_TabMoveCursorToEnd) { | 1346 DISABLED_TabMoveCursorToEnd) { |
1375 TabMoveCursorToEndTest(); | 1347 TabAcceptKeyword(); |
1376 } | 1348 } |
1377 | 1349 |
1378 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, | 1350 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, |
1379 PersistKeywordModeOnTabSwitch) { | 1351 PersistKeywordModeOnTabSwitch) { |
1380 PersistKeywordModeOnTabSwitch(); | 1352 PersistKeywordModeOnTabSwitch(); |
1381 } | 1353 } |
1382 | 1354 |
1383 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, | 1355 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, |
1384 CtrlKeyPressedWithInlineAutocompleteTest) { | 1356 CtrlKeyPressedWithInlineAutocompleteTest) { |
1385 CtrlKeyPressedWithInlineAutocompleteTest(); | 1357 CtrlKeyPressedWithInlineAutocompleteTest(); |
1386 } | 1358 } |
1387 | 1359 |
1388 #endif | 1360 #endif |
OLD | NEW |