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 std::vector<const TemplateURL*> builtins = model->GetTemplateURLs(); | |
251 for (std::vector<const TemplateURL*>::iterator i = builtins.begin(); | |
Peter Kasting
2011/01/25 21:56:44
Nit: Can use a const_iterator here.
We really oug
James Su
2011/01/25 22:32:37
Done.
| |
252 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
784 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | 791 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
785 ASSERT_TRUE(edit_view->model()->keyword().empty()); | 792 ASSERT_TRUE(edit_view->model()->keyword().empty()); |
786 | 793 |
787 // Trigger keyword mode by space. | 794 // Trigger keyword mode by space. |
788 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); | 795 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); |
789 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | 796 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
790 ASSERT_EQ(text, edit_view->model()->keyword()); | 797 ASSERT_EQ(text, edit_view->model()->keyword()); |
791 ASSERT_TRUE(edit_view->GetText().empty()); | 798 ASSERT_TRUE(edit_view->GetText().empty()); |
792 } | 799 } |
793 | 800 |
801 void DeleteItemTest() { | |
802 // Disable the search provider, to make sure the popup contains only history | |
803 // items. | |
804 TemplateURLModel* model = browser()->profile()->GetTemplateURLModel(); | |
805 model->SetDefaultSearchProvider(NULL); | |
806 | |
807 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | |
808 browser()->FocusLocationBar(); | |
809 | |
810 AutocompleteEditView* edit_view = NULL; | |
811 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
812 | |
813 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); | |
814 ASSERT_TRUE(popup_model); | |
815 | |
816 string16 old_text = edit_view->GetText(); | |
817 | |
818 // Input something that can match history items. | |
819 edit_view->SetUserText(ASCIIToUTF16("bar")); | |
820 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
821 ASSERT_TRUE(popup_model->IsOpen()); | |
822 | |
823 // Delete the inline autocomplete part. | |
824 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, false, false, false)); | |
825 string16 user_text = edit_view->GetText(); | |
826 ASSERT_EQ(ASCIIToUTF16("bar"), user_text); | |
827 edit_view->SelectAll(true); | |
828 ASSERT_TRUE(edit_view->IsSelectAll()); | |
829 | |
830 // The first item should be the default match. | |
831 size_t default_line = popup_model->selected_line(); | |
832 std::string default_url = | |
833 popup_model->result().match_at(default_line).destination_url.spec(); | |
834 | |
835 // Move down. | |
836 edit_view->model()->OnUpOrDownKeyPressed(1); | |
837 ASSERT_EQ(default_line + 1, popup_model->selected_line()); | |
838 string16 selected_text = | |
839 popup_model->result().match_at(default_line + 1).fill_into_edit; | |
840 // Temporary text is shown. | |
841 ASSERT_EQ(selected_text, edit_view->GetText()); | |
842 ASSERT_FALSE(edit_view->IsSelectAll()); | |
843 | |
844 // Delete the item. | |
845 popup_model->TryDeletingCurrentItem(); | |
846 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
847 // The selected line shouldn't be changed, because we have more than two | |
848 // items. | |
849 ASSERT_EQ(default_line + 1, popup_model->selected_line()); | |
850 // Make sure the item is really deleted. | |
851 ASSERT_NE(selected_text, | |
852 popup_model->result().match_at(default_line + 1).fill_into_edit); | |
853 selected_text = | |
854 popup_model->result().match_at(default_line + 1).fill_into_edit; | |
855 // New temporary text is shown. | |
856 ASSERT_EQ(selected_text, edit_view->GetText()); | |
857 | |
858 // Revert to the default match. | |
859 ASSERT_TRUE(edit_view->model()->OnEscapeKeyPressed()); | |
860 ASSERT_EQ(default_line, popup_model->selected_line()); | |
861 ASSERT_EQ(user_text, edit_view->GetText()); | |
862 ASSERT_TRUE(edit_view->IsSelectAll()); | |
863 | |
864 // Move down and up to select the default match as temporary text. | |
865 edit_view->model()->OnUpOrDownKeyPressed(1); | |
866 ASSERT_EQ(default_line + 1, popup_model->selected_line()); | |
867 edit_view->model()->OnUpOrDownKeyPressed(-1); | |
868 ASSERT_EQ(default_line, popup_model->selected_line()); | |
869 | |
870 selected_text = popup_model->result().match_at(default_line).fill_into_edit; | |
871 // New temporary text is shown. | |
872 ASSERT_EQ(selected_text, edit_view->GetText()); | |
873 ASSERT_FALSE(edit_view->IsSelectAll()); | |
874 | |
875 // Delete the default item. | |
876 popup_model->TryDeletingCurrentItem(); | |
877 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
878 // The selected line shouldn't be changed, but the default item should have | |
879 // been changed. | |
880 ASSERT_EQ(default_line, popup_model->selected_line()); | |
881 // Make sure the item is really deleted. | |
882 ASSERT_NE(selected_text, | |
883 popup_model->result().match_at(default_line).fill_into_edit); | |
884 selected_text = | |
885 popup_model->result().match_at(default_line).fill_into_edit; | |
886 // New temporary text is shown. | |
887 ASSERT_EQ(selected_text, edit_view->GetText()); | |
888 | |
889 // As the current selected item is the new default item, pressing Escape key | |
890 // should revert all directly. | |
891 ASSERT_TRUE(edit_view->model()->OnEscapeKeyPressed()); | |
892 ASSERT_EQ(old_text, edit_view->GetText()); | |
893 ASSERT_TRUE(edit_view->IsSelectAll()); | |
894 } | |
895 | |
794 }; | 896 }; |
795 | 897 |
796 // Test if ctrl-* accelerators are workable in omnibox. | 898 // Test if ctrl-* accelerators are workable in omnibox. |
797 // See http://crbug.com/19193: omnibox blocks ctrl-* commands | 899 // See http://crbug.com/19193: omnibox blocks ctrl-* commands |
798 // | 900 // |
799 // Flaky on interactive tests (dbg), http://crbug.com/69433 | 901 // Flaky on interactive tests (dbg), http://crbug.com/69433 |
800 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { | 902 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { |
801 BrowserAcceleratorsTest(); | 903 BrowserAcceleratorsTest(); |
802 } | 904 } |
803 | 905 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 } | 939 } |
838 | 940 |
839 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) { | 941 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) { |
840 BasicTextOperationsTest(); | 942 BasicTextOperationsTest(); |
841 } | 943 } |
842 | 944 |
843 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) { | 945 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) { |
844 AcceptKeywordBySpaceTest(); | 946 AcceptKeywordBySpaceTest(); |
845 } | 947 } |
846 | 948 |
949 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DeleteItem) { | |
950 DeleteItemTest(); | |
951 } | |
952 | |
847 #if defined(OS_LINUX) | 953 #if defined(OS_LINUX) |
848 // TODO(oshima): enable these tests for views-implmentation when | 954 // TODO(oshima): enable these tests for views-implmentation when |
849 // these featuers are supported. | 955 // these featuers are supported. |
850 | 956 |
851 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { | 957 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { |
852 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 958 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
853 browser()->FocusLocationBar(); | 959 browser()->FocusLocationBar(); |
854 | 960 |
855 AutocompleteEditView* edit_view = NULL; | 961 AutocompleteEditView* edit_view = NULL; |
856 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | 962 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1013 } | 1119 } |
1014 | 1120 |
1015 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, BasicTextOperations) { | 1121 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, BasicTextOperations) { |
1016 BasicTextOperationsTest(); | 1122 BasicTextOperationsTest(); |
1017 } | 1123 } |
1018 | 1124 |
1019 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AcceptKeywordBySpace) { | 1125 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AcceptKeywordBySpace) { |
1020 AcceptKeywordBySpaceTest(); | 1126 AcceptKeywordBySpaceTest(); |
1021 } | 1127 } |
1022 | 1128 |
1129 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, DeleteItem) { | |
1130 DeleteItemTest(); | |
1131 } | |
1132 | |
1023 #endif | 1133 #endif |
OLD | NEW |