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 old template urls to avoid interfering our tests. | |
|
Peter Kasting
2011/01/25 21:18:24
Nit: What are the old URLs and how would they inte
James Su
2011/01/25 21:47:03
Done.
| |
| 248 model->SetDefaultSearchProvider(NULL); | |
| 249 std::vector<const TemplateURL*> old = model->GetTemplateURLs(); | |
| 250 for (size_t i = 0; i < old.size(); ++i) | |
|
Peter Kasting
2011/01/25 21:18:24
Nit: An iterator might be nice
James Su
2011/01/25 21:47:03
Done.
| |
| 251 model->Remove(old[i]); | |
| 247 | 252 |
| 248 TemplateURL* template_url = new TemplateURL(); | 253 TemplateURL* template_url = new TemplateURL(); |
| 249 template_url->SetURL(kSearchURL, 0, 0); | 254 template_url->SetURL(kSearchURL, 0, 0); |
| 250 template_url->set_keyword(UTF8ToUTF16(kSearchKeyword)); | 255 template_url->set_keyword(UTF8ToUTF16(kSearchKeyword)); |
| 251 template_url->set_short_name(UTF8ToUTF16(kSearchShortName)); | 256 template_url->set_short_name(UTF8ToUTF16(kSearchShortName)); |
| 252 | 257 |
| 253 model->Add(template_url); | 258 model->Add(template_url); |
| 254 model->SetDefaultSearchProvider(template_url); | 259 model->SetDefaultSearchProvider(template_url); |
| 255 } | 260 } |
| 256 | 261 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 void DesiredTLDTest() { | 507 void DesiredTLDTest() { |
| 503 AutocompleteEditView* edit_view = NULL; | 508 AutocompleteEditView* edit_view = NULL; |
| 504 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | 509 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| 505 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); | 510 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); |
| 506 ASSERT_TRUE(popup_model); | 511 ASSERT_TRUE(popup_model); |
| 507 | 512 |
| 508 // Test ctrl-Enter. | 513 // Test ctrl-Enter. |
| 509 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys)); | 514 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys)); |
| 510 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 515 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 511 ASSERT_TRUE(popup_model->IsOpen()); | 516 ASSERT_TRUE(popup_model->IsOpen()); |
| 512 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be opened . | 517 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be |
| 518 // opened. | |
| 513 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, true, false, false)); | 519 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, true, false, false)); |
| 514 | 520 |
| 515 GURL url = browser()->GetSelectedTabContents()->GetURL(); | 521 GURL url = browser()->GetSelectedTabContents()->GetURL(); |
| 516 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str()); | 522 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str()); |
| 517 } | 523 } |
| 518 | 524 |
| 519 void AltEnterTest() { | 525 void AltEnterTest() { |
| 520 AutocompleteEditView* edit_view = NULL; | 526 AutocompleteEditView* edit_view = NULL; |
| 521 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | 527 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| 522 | 528 |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | 787 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
| 782 ASSERT_TRUE(edit_view->model()->keyword().empty()); | 788 ASSERT_TRUE(edit_view->model()->keyword().empty()); |
| 783 | 789 |
| 784 // Trigger keyword mode by space. | 790 // Trigger keyword mode by space. |
| 785 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); | 791 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); |
| 786 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | 792 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
| 787 ASSERT_EQ(text, edit_view->model()->keyword()); | 793 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 788 ASSERT_TRUE(edit_view->GetText().empty()); | 794 ASSERT_TRUE(edit_view->GetText().empty()); |
| 789 } | 795 } |
| 790 | 796 |
| 797 void DeleteItemTest() { | |
| 798 // Disable the search provider, to make sure the popup contains only history | |
| 799 // items. | |
| 800 TemplateURLModel* model = browser()->profile()->GetTemplateURLModel(); | |
| 801 model->SetDefaultSearchProvider(NULL); | |
| 802 | |
| 803 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | |
| 804 browser()->FocusLocationBar(); | |
| 805 | |
| 806 AutocompleteEditView* edit_view = NULL; | |
| 807 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
| 808 | |
| 809 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); | |
| 810 ASSERT_TRUE(popup_model); | |
| 811 | |
| 812 std::wstring old_text = edit_view->GetText(); | |
| 813 | |
| 814 // Input something that can match history items. | |
| 815 edit_view->SetUserText(L"bar"); | |
| 816 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
| 817 ASSERT_TRUE(popup_model->IsOpen()); | |
| 818 | |
| 819 // Delete the inline autocomplete part. | |
| 820 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, false, false, false)); | |
| 821 std::wstring user_text = edit_view->GetText(); | |
| 822 ASSERT_EQ(L"bar", user_text); | |
| 823 edit_view->SelectAll(true); | |
| 824 ASSERT_TRUE(edit_view->IsSelectAll()); | |
| 825 | |
| 826 // The first item should be the default match. | |
| 827 size_t default_line = popup_model->selected_line(); | |
| 828 std::string default_url = | |
| 829 popup_model->result().match_at(default_line).destination_url.spec(); | |
| 830 | |
| 831 // Move down. | |
| 832 edit_view->model()->OnUpOrDownKeyPressed(1); | |
| 833 ASSERT_EQ(default_line + 1, popup_model->selected_line()); | |
| 834 std::wstring selected_text = | |
| 835 popup_model->result().match_at(default_line + 1).fill_into_edit; | |
| 836 // Temporary text is shown. | |
| 837 ASSERT_EQ(selected_text, edit_view->GetText()); | |
| 838 ASSERT_FALSE(edit_view->IsSelectAll()); | |
| 839 | |
| 840 // Delete the item. | |
| 841 popup_model->TryDeletingCurrentItem(); | |
| 842 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
| 843 // The selected line shouldn't be changed, because we have more than two | |
| 844 // items. | |
| 845 ASSERT_EQ(default_line + 1, popup_model->selected_line()); | |
| 846 // Make sure the item is really deleted. | |
| 847 ASSERT_NE(selected_text, | |
| 848 popup_model->result().match_at(default_line + 1).fill_into_edit); | |
| 849 selected_text = | |
| 850 popup_model->result().match_at(default_line + 1).fill_into_edit; | |
| 851 // New temporary text is shown. | |
| 852 ASSERT_EQ(selected_text, edit_view->GetText()); | |
| 853 | |
| 854 // Revert to the default match. | |
| 855 ASSERT_TRUE(edit_view->model()->OnEscapeKeyPressed()); | |
| 856 ASSERT_EQ(default_line, popup_model->selected_line()); | |
| 857 ASSERT_EQ(user_text, edit_view->GetText()); | |
| 858 ASSERT_TRUE(edit_view->IsSelectAll()); | |
| 859 | |
| 860 // Move down and up to select the default match as temporary text. | |
| 861 edit_view->model()->OnUpOrDownKeyPressed(1); | |
| 862 ASSERT_EQ(default_line + 1, popup_model->selected_line()); | |
| 863 edit_view->model()->OnUpOrDownKeyPressed(-1); | |
| 864 ASSERT_EQ(default_line, popup_model->selected_line()); | |
| 865 | |
| 866 selected_text = popup_model->result().match_at(default_line).fill_into_edit; | |
| 867 // New temporary text is shown. | |
| 868 ASSERT_EQ(selected_text, edit_view->GetText()); | |
| 869 ASSERT_FALSE(edit_view->IsSelectAll()); | |
| 870 | |
| 871 // Delete the default item. | |
| 872 popup_model->TryDeletingCurrentItem(); | |
| 873 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
| 874 // The selected line shouldn't be changed, but the default item should have | |
| 875 // been changed. | |
| 876 ASSERT_EQ(default_line, popup_model->selected_line()); | |
| 877 // Make sure the item is really deleted. | |
| 878 ASSERT_NE(selected_text, | |
| 879 popup_model->result().match_at(default_line).fill_into_edit); | |
| 880 selected_text = | |
| 881 popup_model->result().match_at(default_line).fill_into_edit; | |
| 882 // New temporary text is shown. | |
| 883 ASSERT_EQ(selected_text, edit_view->GetText()); | |
| 884 | |
| 885 // As the current selected item is the new default item, pressing Escape key | |
| 886 // should revert all directly. | |
| 887 ASSERT_TRUE(edit_view->model()->OnEscapeKeyPressed()); | |
| 888 ASSERT_EQ(old_text, edit_view->GetText()); | |
| 889 ASSERT_TRUE(edit_view->IsSelectAll()); | |
| 890 } | |
| 891 | |
| 791 }; | 892 }; |
| 792 | 893 |
| 793 // Test if ctrl-* accelerators are workable in omnibox. | 894 // Test if ctrl-* accelerators are workable in omnibox. |
| 794 // See http://crbug.com/19193: omnibox blocks ctrl-* commands | 895 // See http://crbug.com/19193: omnibox blocks ctrl-* commands |
| 795 // | 896 // |
| 796 // Flaky on interactive tests (dbg), http://crbug.com/69433 | 897 // Flaky on interactive tests (dbg), http://crbug.com/69433 |
| 797 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { | 898 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { |
| 798 BrowserAcceleratorsTest(); | 899 BrowserAcceleratorsTest(); |
| 799 } | 900 } |
| 800 | 901 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 834 } | 935 } |
| 835 | 936 |
| 836 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) { | 937 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) { |
| 837 BasicTextOperationsTest(); | 938 BasicTextOperationsTest(); |
| 838 } | 939 } |
| 839 | 940 |
| 840 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) { | 941 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) { |
| 841 AcceptKeywordBySpaceTest(); | 942 AcceptKeywordBySpaceTest(); |
| 842 } | 943 } |
| 843 | 944 |
| 945 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DeleteItem) { | |
| 946 DeleteItemTest(); | |
| 947 } | |
| 948 | |
| 844 #if defined(OS_LINUX) | 949 #if defined(OS_LINUX) |
| 845 // TODO(oshima): enable these tests for views-implmentation when | 950 // TODO(oshima): enable these tests for views-implmentation when |
| 846 // these featuers are supported. | 951 // these featuers are supported. |
| 847 | 952 |
| 848 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { | 953 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { |
| 849 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 954 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
| 850 browser()->FocusLocationBar(); | 955 browser()->FocusLocationBar(); |
| 851 | 956 |
| 852 AutocompleteEditView* edit_view = NULL; | 957 AutocompleteEditView* edit_view = NULL; |
| 853 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | 958 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1010 } | 1115 } |
| 1011 | 1116 |
| 1012 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, BasicTextOperations) { | 1117 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, BasicTextOperations) { |
| 1013 BasicTextOperationsTest(); | 1118 BasicTextOperationsTest(); |
| 1014 } | 1119 } |
| 1015 | 1120 |
| 1016 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AcceptKeywordBySpace) { | 1121 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AcceptKeywordBySpace) { |
| 1017 AcceptKeywordBySpaceTest(); | 1122 AcceptKeywordBySpaceTest(); |
| 1018 } | 1123 } |
| 1019 | 1124 |
| 1125 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, DeleteItem) { | |
| 1126 DeleteItemTest(); | |
| 1127 } | |
| 1128 | |
| 1020 #endif | 1129 #endif |
| OLD | NEW |