Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(695)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc

Issue 6340012: Fix a DCHECK failure in AutocompleteEditModel::OnPopupDataChanged() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Wrap long lines. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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.
248 model->SetDefaultSearchProvider(NULL);
249 std::vector<const TemplateURL*> old = model->GetTemplateURLs();
250 for (size_t i = 0; i < old.size(); ++i)
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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 void DesiredTLDTest() { 503 void DesiredTLDTest() {
499 AutocompleteEditView* edit_view = NULL; 504 AutocompleteEditView* edit_view = NULL;
500 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 505 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
501 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 506 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
502 ASSERT_TRUE(popup_model); 507 ASSERT_TRUE(popup_model);
503 508
504 // Test ctrl-Enter. 509 // Test ctrl-Enter.
505 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys)); 510 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys));
506 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 511 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
507 ASSERT_TRUE(popup_model->IsOpen()); 512 ASSERT_TRUE(popup_model->IsOpen());
508 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be opened . 513 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be
514 // opened.
509 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, true, false, false)); 515 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, true, false, false));
510 516
511 GURL url = browser()->GetSelectedTabContents()->GetURL(); 517 GURL url = browser()->GetSelectedTabContents()->GetURL();
512 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str()); 518 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str());
513 } 519 }
514 520
515 void AltEnterTest() { 521 void AltEnterTest() {
516 AutocompleteEditView* edit_view = NULL; 522 AutocompleteEditView* edit_view = NULL;
517 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 523 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
518 524
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 ASSERT_NE(start, end); 758 ASSERT_NE(start, end);
753 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); 759 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false));
754 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); 760 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
755 ASSERT_EQ(text, edit_view->model()->keyword()); 761 ASSERT_EQ(text, edit_view->model()->keyword());
756 ASSERT_EQ(text + L" ", edit_view->GetText()); 762 ASSERT_EQ(text + L" ", edit_view->GetText());
757 763
758 edit_view->GetSelectionBounds(&start, &end); 764 edit_view->GetSelectionBounds(&start, &end);
759 ASSERT_EQ(start, end); 765 ASSERT_EQ(start, end);
760 } 766 }
761 767
768 void DeleteItemTest() {
769 // Disable the search provider, to make sure the popup contains only history
770 // items.
771 TemplateURLModel* model = browser()->profile()->GetTemplateURLModel();
772 model->SetDefaultSearchProvider(NULL);
773
774 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL));
775 browser()->FocusLocationBar();
776
777 AutocompleteEditView* edit_view = NULL;
778 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
779
780 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
781 ASSERT_TRUE(popup_model);
782
783 std::wstring old_text = edit_view->GetText();
784
785 // Input something that can match history items.
786 edit_view->SetUserText(L"bar");
787 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
788 ASSERT_TRUE(popup_model->IsOpen());
789
790 // Delete the inline autocomplete part.
791 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, false, false, false));
792 std::wstring user_text = edit_view->GetText();
793 ASSERT_EQ(L"bar", user_text);
794 edit_view->SelectAll(true);
795 ASSERT_TRUE(edit_view->IsSelectAll());
796
797 // The first item should be the default match.
798 size_t default_line = popup_model->selected_line();
799 std::string default_url =
800 popup_model->result().match_at(default_line).destination_url.spec();
801
802 // Move down.
803 edit_view->model()->OnUpOrDownKeyPressed(1);
804 ASSERT_EQ(default_line + 1, popup_model->selected_line());
805 std::wstring selected_text =
806 popup_model->result().match_at(default_line + 1).fill_into_edit;
807 // Temporary text is shown.
808 ASSERT_EQ(selected_text, edit_view->GetText());
809 ASSERT_FALSE(edit_view->IsSelectAll());
810
811 // Delete the item.
812 popup_model->TryDeletingCurrentItem();
813 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
814 // The selected line shouldn't be changed, because we have more than two
815 // items.
816 ASSERT_EQ(default_line + 1, popup_model->selected_line());
817 // Make sure the item is really deleted.
818 ASSERT_NE(selected_text,
819 popup_model->result().match_at(default_line + 1).fill_into_edit);
820 selected_text =
821 popup_model->result().match_at(default_line + 1).fill_into_edit;
822 // New temporary text is shown.
823 ASSERT_EQ(selected_text, edit_view->GetText());
824
825 // Revert to the default match.
826 ASSERT_TRUE(edit_view->model()->OnEscapeKeyPressed());
827 ASSERT_EQ(default_line, popup_model->selected_line());
828 ASSERT_EQ(user_text, edit_view->GetText());
829 ASSERT_TRUE(edit_view->IsSelectAll());
830
831 // Move down and up to select the default match as temporary text.
832 edit_view->model()->OnUpOrDownKeyPressed(1);
833 ASSERT_EQ(default_line + 1, popup_model->selected_line());
834 edit_view->model()->OnUpOrDownKeyPressed(-1);
835 ASSERT_EQ(default_line, popup_model->selected_line());
836
837 selected_text = popup_model->result().match_at(default_line).fill_into_edit;
838 // New temporary text is shown.
839 ASSERT_EQ(selected_text, edit_view->GetText());
840 ASSERT_FALSE(edit_view->IsSelectAll());
841
842 // Delete the default item.
843 popup_model->TryDeletingCurrentItem();
844 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
845 // The selected line shouldn't be changed, but the default item should have
846 // been changed.
847 ASSERT_EQ(default_line, popup_model->selected_line());
848 // Make sure the item is really deleted.
849 ASSERT_NE(selected_text,
850 popup_model->result().match_at(default_line).fill_into_edit);
851 selected_text =
852 popup_model->result().match_at(default_line).fill_into_edit;
853 // New temporary text is shown.
854 ASSERT_EQ(selected_text, edit_view->GetText());
855
856 // As the current selected item is the new default item, pressing Escape key
857 // should revert all directly.
858 ASSERT_TRUE(edit_view->model()->OnEscapeKeyPressed());
859 ASSERT_EQ(old_text, edit_view->GetText());
860 ASSERT_TRUE(edit_view->IsSelectAll());
861 }
862
762 }; 863 };
763 864
764 // Test if ctrl-* accelerators are workable in omnibox. 865 // Test if ctrl-* accelerators are workable in omnibox.
765 // See http://crbug.com/19193: omnibox blocks ctrl-* commands 866 // See http://crbug.com/19193: omnibox blocks ctrl-* commands
766 // 867 //
767 // Flaky on interactive tests (dbg), http://crbug.com/69433 868 // Flaky on interactive tests (dbg), http://crbug.com/69433
768 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { 869 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) {
769 BrowserAcceleratorsTest(); 870 BrowserAcceleratorsTest();
770 } 871 }
771 872
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 } 906 }
806 907
807 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) { 908 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) {
808 BasicTextOperationsTest(); 909 BasicTextOperationsTest();
809 } 910 }
810 911
811 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) { 912 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) {
812 AcceptKeywordBySpaceTest(); 913 AcceptKeywordBySpaceTest();
813 } 914 }
814 915
916 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DeleteItem) {
917 DeleteItemTest();
918 }
919
815 #if defined(OS_LINUX) 920 #if defined(OS_LINUX)
816 // TODO(oshima): enable these tests for views-implmentation when 921 // TODO(oshima): enable these tests for views-implmentation when
817 // these featuers are supported. 922 // these featuers are supported.
818 923
819 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { 924 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) {
820 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); 925 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL));
821 browser()->FocusLocationBar(); 926 browser()->FocusLocationBar();
822 927
823 AutocompleteEditView* edit_view = NULL; 928 AutocompleteEditView* edit_view = NULL;
824 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 929 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 } 1086 }
982 1087
983 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, BasicTextOperations) { 1088 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, BasicTextOperations) {
984 BasicTextOperationsTest(); 1089 BasicTextOperationsTest();
985 } 1090 }
986 1091
987 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AcceptKeywordBySpace) { 1092 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AcceptKeywordBySpace) {
988 AcceptKeywordBySpaceTest(); 1093 AcceptKeywordBySpaceTest();
989 } 1094 }
990 1095
1096 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, DeleteItem) {
1097 DeleteItemTest();
1098 }
1099
991 #endif 1100 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698