Chromium Code Reviews| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 const struct TestHistoryEntry { | 91 const struct TestHistoryEntry { |
| 92 const char* url; | 92 const char* url; |
| 93 const char* title; | 93 const char* title; |
| 94 const char* body; | 94 const char* body; |
| 95 int visit_count; | 95 int visit_count; |
| 96 int typed_count; | 96 int typed_count; |
| 97 bool starred; | 97 bool starred; |
| 98 } kHistoryEntries[] = { | 98 } kHistoryEntries[] = { |
| 99 {"http://www.bar.com/1", "Page 1", kSearchText, 1, 1, false }, | 99 {"http://www.bar.com/1", "Page 1", kSearchText, 10, 10, false }, |
| 100 {"http://www.bar.com/2", "Page 2", kSearchText, 1, 1, false }, | 100 {"http://www.bar.com/2", "Page 2", kSearchText, 9, 9, false }, |
| 101 {"http://www.bar.com/3", "Page 3", kSearchText, 1, 1, false }, | 101 {"http://www.bar.com/3", "Page 3", kSearchText, 8, 8, false }, |
| 102 {"http://www.bar.com/4", "Page 4", kSearchText, 1, 1, false }, | 102 {"http://www.bar.com/4", "Page 4", kSearchText, 7, 7, false }, |
| 103 {"http://www.bar.com/5", "Page 5", kSearchText, 1, 1, false }, | 103 {"http://www.bar.com/5", "Page 5", kSearchText, 6, 6, false }, |
| 104 {"http://www.bar.com/6", "Page 6", kSearchText, 1, 1, false }, | 104 {"http://www.bar.com/6", "Page 6", kSearchText, 5, 5, false }, |
| 105 {"http://www.bar.com/7", "Page 7", kSearchText, 1, 1, false }, | 105 {"http://www.bar.com/7", "Page 7", kSearchText, 4, 4, false }, |
| 106 {"http://www.bar.com/8", "Page 8", kSearchText, 1, 1, false }, | 106 {"http://www.bar.com/8", "Page 8", kSearchText, 3, 3, false }, |
| 107 {"http://www.bar.com/9", "Page 9", kSearchText, 1, 1, false }, | 107 {"http://www.bar.com/9", "Page 9", kSearchText, 2, 2, false }, |
| 108 | 108 |
| 109 // To trigger inline autocomplete. | 109 // To trigger inline autocomplete. |
| 110 {"http://www.def.com", "Page def", kSearchText, 10000, 10000, true }, | 110 {"http://www.def.com", "Page def", kSearchText, 10000, 10000, true }, |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 #if defined(OS_LINUX) | 113 #if defined(OS_LINUX) |
| 114 // Returns the text stored in the PRIMARY clipboard. | 114 // Returns the text stored in the PRIMARY clipboard. |
| 115 std::string GetPrimarySelectionText() { | 115 std::string GetPrimarySelectionText() { |
| 116 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); | 116 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); |
| 117 DCHECK(clipboard); | 117 DCHECK(clipboard); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 | 237 |
| 238 if (!model->loaded()) { | 238 if (!model->loaded()) { |
| 239 NotificationRegistrar registrar; | 239 NotificationRegistrar registrar; |
| 240 registrar.Add(this, NotificationType::TEMPLATE_URL_MODEL_LOADED, | 240 registrar.Add(this, NotificationType::TEMPLATE_URL_MODEL_LOADED, |
| 241 Source<TemplateURLModel>(model)); | 241 Source<TemplateURLModel>(model)); |
| 242 model->Load(); | 242 model->Load(); |
| 243 ui_test_utils::RunMessageLoop(); | 243 ui_test_utils::RunMessageLoop(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 ASSERT_TRUE(model->loaded()); | 246 ASSERT_TRUE(model->loaded()); |
| 247 // Remove built-in template urls, like google.com, bing.com etc., as they | |
| 248 // may appear as autocomplete suggests and interfere with our tests. | |
| 249 model->SetDefaultSearchProvider(NULL); | |
| 250 TemplateURLModel::TemplateURLVector builtins = model->GetTemplateURLs(); | |
| 251 TemplateURLModel::TemplateURLVector::const_iterator i = builtins.begin(); | |
|
Peter Kasting
2011/01/26 17:36:22
Nit: Never pull loop index variables out of the lo
| |
| 252 for (; i != builtins.end(); ++i) | |
| 253 model->Remove(*i); | |
| 247 | 254 |
| 248 TemplateURL* template_url = new TemplateURL(); | 255 TemplateURL* template_url = new TemplateURL(); |
| 249 template_url->SetURL(kSearchURL, 0, 0); | 256 template_url->SetURL(kSearchURL, 0, 0); |
| 250 template_url->set_keyword(UTF8ToUTF16(kSearchKeyword)); | 257 template_url->set_keyword(UTF8ToUTF16(kSearchKeyword)); |
| 251 template_url->set_short_name(UTF8ToUTF16(kSearchShortName)); | 258 template_url->set_short_name(UTF8ToUTF16(kSearchShortName)); |
| 252 | 259 |
| 253 model->Add(template_url); | 260 model->Add(template_url); |
| 254 model->SetDefaultSearchProvider(template_url); | 261 model->SetDefaultSearchProvider(template_url); |
| 255 } | 262 } |
| 256 | 263 |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 834 | 841 |
| 835 // We always allow exact matches for non-substituting keywords. | 842 // We always allow exact matches for non-substituting keywords. |
| 836 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); | 843 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); |
| 837 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 844 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 838 ASSERT_TRUE(popup_model->IsOpen()); | 845 ASSERT_TRUE(popup_model->IsOpen()); |
| 839 ASSERT_EQ(AutocompleteMatch::HISTORY_KEYWORD, | 846 ASSERT_EQ(AutocompleteMatch::HISTORY_KEYWORD, |
| 840 popup_model->result().default_match()->type); | 847 popup_model->result().default_match()->type); |
| 841 ASSERT_EQ("http://abc.com/", | 848 ASSERT_EQ("http://abc.com/", |
| 842 popup_model->result().default_match()->destination_url.spec()); | 849 popup_model->result().default_match()->destination_url.spec()); |
| 843 } | 850 } |
| 851 | |
| 852 void DeleteItemTest() { | |
| 853 // Disable the search provider, to make sure the popup contains only history | |
| 854 // items. | |
| 855 TemplateURLModel* model = browser()->profile()->GetTemplateURLModel(); | |
| 856 model->SetDefaultSearchProvider(NULL); | |
| 857 | |
| 858 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | |
| 859 browser()->FocusLocationBar(); | |
| 860 | |
| 861 AutocompleteEditView* edit_view = NULL; | |
| 862 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
| 863 | |
| 864 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); | |
| 865 ASSERT_TRUE(popup_model); | |
| 866 | |
| 867 string16 old_text = edit_view->GetText(); | |
| 868 | |
| 869 // Input something that can match history items. | |
| 870 edit_view->SetUserText(ASCIIToUTF16("bar")); | |
| 871 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
| 872 ASSERT_TRUE(popup_model->IsOpen()); | |
| 873 | |
| 874 // Delete the inline autocomplete part. | |
| 875 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, false, false, false)); | |
| 876 string16 user_text = edit_view->GetText(); | |
| 877 ASSERT_EQ(ASCIIToUTF16("bar"), user_text); | |
| 878 edit_view->SelectAll(true); | |
| 879 ASSERT_TRUE(edit_view->IsSelectAll()); | |
| 880 | |
| 881 // The first item should be the default match. | |
| 882 size_t default_line = popup_model->selected_line(); | |
| 883 std::string default_url = | |
| 884 popup_model->result().match_at(default_line).destination_url.spec(); | |
| 885 | |
| 886 // Move down. | |
| 887 edit_view->model()->OnUpOrDownKeyPressed(1); | |
| 888 ASSERT_EQ(default_line + 1, popup_model->selected_line()); | |
| 889 string16 selected_text = | |
| 890 popup_model->result().match_at(default_line + 1).fill_into_edit; | |
| 891 // Temporary text is shown. | |
| 892 ASSERT_EQ(selected_text, edit_view->GetText()); | |
| 893 ASSERT_FALSE(edit_view->IsSelectAll()); | |
| 894 | |
| 895 // Delete the item. | |
| 896 popup_model->TryDeletingCurrentItem(); | |
| 897 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
| 898 // The selected line shouldn't be changed, because we have more than two | |
| 899 // items. | |
| 900 ASSERT_EQ(default_line + 1, popup_model->selected_line()); | |
| 901 // Make sure the item is really deleted. | |
| 902 ASSERT_NE(selected_text, | |
| 903 popup_model->result().match_at(default_line + 1).fill_into_edit); | |
| 904 selected_text = | |
| 905 popup_model->result().match_at(default_line + 1).fill_into_edit; | |
| 906 // New temporary text is shown. | |
| 907 ASSERT_EQ(selected_text, edit_view->GetText()); | |
| 908 | |
| 909 // Revert to the default match. | |
| 910 ASSERT_TRUE(edit_view->model()->OnEscapeKeyPressed()); | |
| 911 ASSERT_EQ(default_line, popup_model->selected_line()); | |
| 912 ASSERT_EQ(user_text, edit_view->GetText()); | |
| 913 ASSERT_TRUE(edit_view->IsSelectAll()); | |
| 914 | |
| 915 // Move down and up to select the default match as temporary text. | |
| 916 edit_view->model()->OnUpOrDownKeyPressed(1); | |
| 917 ASSERT_EQ(default_line + 1, popup_model->selected_line()); | |
| 918 edit_view->model()->OnUpOrDownKeyPressed(-1); | |
| 919 ASSERT_EQ(default_line, popup_model->selected_line()); | |
| 920 | |
| 921 selected_text = popup_model->result().match_at(default_line).fill_into_edit; | |
| 922 // New temporary text is shown. | |
| 923 ASSERT_EQ(selected_text, edit_view->GetText()); | |
| 924 ASSERT_FALSE(edit_view->IsSelectAll()); | |
| 925 | |
| 926 // Delete the default item. | |
| 927 popup_model->TryDeletingCurrentItem(); | |
| 928 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
| 929 // The selected line shouldn't be changed, but the default item should have | |
| 930 // been changed. | |
| 931 ASSERT_EQ(default_line, popup_model->selected_line()); | |
| 932 // Make sure the item is really deleted. | |
| 933 ASSERT_NE(selected_text, | |
| 934 popup_model->result().match_at(default_line).fill_into_edit); | |
| 935 selected_text = | |
| 936 popup_model->result().match_at(default_line).fill_into_edit; | |
| 937 // New temporary text is shown. | |
| 938 ASSERT_EQ(selected_text, edit_view->GetText()); | |
| 939 | |
| 940 // As the current selected item is the new default item, pressing Escape key | |
| 941 // should revert all directly. | |
| 942 ASSERT_TRUE(edit_view->model()->OnEscapeKeyPressed()); | |
| 943 ASSERT_EQ(old_text, edit_view->GetText()); | |
| 944 ASSERT_TRUE(edit_view->IsSelectAll()); | |
| 945 } | |
| 946 | |
| 844 }; | 947 }; |
| 845 | 948 |
| 846 // Test if ctrl-* accelerators are workable in omnibox. | 949 // Test if ctrl-* accelerators are workable in omnibox. |
| 847 // See http://crbug.com/19193: omnibox blocks ctrl-* commands | 950 // See http://crbug.com/19193: omnibox blocks ctrl-* commands |
| 848 // | 951 // |
| 849 // Flaky on interactive tests (dbg), http://crbug.com/69433 | 952 // Flaky on interactive tests (dbg), http://crbug.com/69433 |
| 850 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { | 953 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { |
| 851 BrowserAcceleratorsTest(); | 954 BrowserAcceleratorsTest(); |
| 852 } | 955 } |
| 853 | 956 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 891 } | 994 } |
| 892 | 995 |
| 893 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) { | 996 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) { |
| 894 AcceptKeywordBySpaceTest(); | 997 AcceptKeywordBySpaceTest(); |
| 895 } | 998 } |
| 896 | 999 |
| 897 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, NonSubstitutingKeywordTest) { | 1000 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, NonSubstitutingKeywordTest) { |
| 898 NonSubstitutingKeywordTest(); | 1001 NonSubstitutingKeywordTest(); |
| 899 } | 1002 } |
| 900 | 1003 |
| 1004 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DeleteItem) { | |
| 1005 DeleteItemTest(); | |
| 1006 } | |
| 1007 | |
| 901 #if defined(OS_LINUX) | 1008 #if defined(OS_LINUX) |
| 902 // TODO(oshima): enable these tests for views-implmentation when | 1009 // TODO(oshima): enable these tests for views-implmentation when |
| 903 // these featuers are supported. | 1010 // these featuers are supported. |
| 904 | 1011 |
| 905 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { | 1012 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { |
| 906 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 1013 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
| 907 browser()->FocusLocationBar(); | 1014 browser()->FocusLocationBar(); |
| 908 | 1015 |
| 909 AutocompleteEditView* edit_view = NULL; | 1016 AutocompleteEditView* edit_view = NULL; |
| 910 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | 1017 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1072 | 1179 |
| 1073 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AcceptKeywordBySpace) { | 1180 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AcceptKeywordBySpace) { |
| 1074 AcceptKeywordBySpaceTest(); | 1181 AcceptKeywordBySpaceTest(); |
| 1075 } | 1182 } |
| 1076 | 1183 |
| 1077 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, | 1184 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, |
| 1078 NonSubstitutingKeywordTest) { | 1185 NonSubstitutingKeywordTest) { |
| 1079 NonSubstitutingKeywordTest(); | 1186 NonSubstitutingKeywordTest(); |
| 1080 } | 1187 } |
| 1081 | 1188 |
| 1189 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, DeleteItem) { | |
| 1190 DeleteItemTest(); | |
| 1191 } | |
| 1192 | |
| 1082 #endif | 1193 #endif |
| OLD | NEW |