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

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

Issue 5774004: Make HistoryContentsProvider results deletable (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Move DeleteMatch to common base class, update includes, etc. Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/string_util.h" 5 #include "base/string_util.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/autocomplete/autocomplete.h" 7 #include "chrome/browser/autocomplete/autocomplete.h"
8 #include "chrome/browser/autocomplete/autocomplete_edit.h" 8 #include "chrome/browser/autocomplete/autocomplete_edit.h"
9 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" 9 #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h" 10 #include "chrome/browser/autocomplete/autocomplete_match.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 AutocompleteController* GetAutocompleteController() const { 55 AutocompleteController* GetAutocompleteController() const {
56 return GetLocationBar()->location_entry()->model()->popup_model()-> 56 return GetLocationBar()->location_entry()->model()->popup_model()->
57 autocomplete_controller(); 57 autocomplete_controller();
58 } 58 }
59 }; 59 };
60 60
61 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) { 61 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) {
62 LocationBar* location_bar = GetLocationBar(); 62 LocationBar* location_bar = GetLocationBar();
63 63
64 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 64 EXPECT_TRUE(location_bar->GetInputString().empty());
65 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 65 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL),
66 location_bar->location_entry()->GetText()); 66 location_bar->location_entry()->GetText());
67 // TODO(phajdan.jr): check state of IsSelectAll when it's consistent across 67 // TODO(phajdan.jr): check state of IsSelectAll when it's consistent across
68 // platforms. 68 // platforms.
69 69
70 location_bar->FocusLocation(true); 70 location_bar->FocusLocation(true);
71 71
72 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 72 EXPECT_TRUE(location_bar->GetInputString().empty());
73 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 73 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL),
74 location_bar->location_entry()->GetText()); 74 location_bar->location_entry()->GetText());
75 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); 75 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll());
76 76
77 location_bar->location_entry()->SetUserText(L"chrome"); 77 location_bar->location_entry()->SetUserText(L"chrome");
78 78
79 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 79 EXPECT_TRUE(location_bar->GetInputString().empty());
80 EXPECT_EQ(L"chrome", location_bar->location_entry()->GetText()); 80 EXPECT_EQ(L"chrome", location_bar->location_entry()->GetText());
81 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); 81 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll());
82 82
83 location_bar->location_entry()->RevertAll(); 83 location_bar->location_entry()->RevertAll();
84 84
85 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 85 EXPECT_TRUE(location_bar->GetInputString().empty());
86 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 86 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL),
87 location_bar->location_entry()->GetText()); 87 location_bar->location_entry()->GetText());
88 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); 88 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll());
89 89
90 location_bar->location_entry()->SetUserText(L"chrome"); 90 location_bar->location_entry()->SetUserText(L"chrome");
91 location_bar->Revert(); 91 location_bar->Revert();
92 92
93 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 93 EXPECT_TRUE(location_bar->GetInputString().empty());
94 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 94 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL),
95 location_bar->location_entry()->GetText()); 95 location_bar->location_entry()->GetText());
96 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); 96 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll());
97 } 97 }
98 98
99 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) { 99 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) {
100 // The results depend on the history backend being loaded. Make sure it is 100 // The results depend on the history backend being loaded. Make sure it is
101 // loaded so that the autocomplete results are consistent. 101 // loaded so that the autocomplete results are consistent.
102 ui_test_utils::WaitForHistoryToLoad(browser()); 102 ui_test_utils::WaitForHistoryToLoad(browser());
103 103
104 LocationBar* location_bar = GetLocationBar(); 104 LocationBar* location_bar = GetLocationBar();
105 AutocompleteController* autocomplete_controller = GetAutocompleteController(); 105 AutocompleteController* autocomplete_controller = GetAutocompleteController();
106 106
107 { 107 {
108 autocomplete_controller->Start(L"chrome", std::wstring(), 108 autocomplete_controller->Start(L"chrome", std::wstring(),
109 true, false, true, true); 109 true, false, true, true);
110 110
111 EXPECT_TRUE(autocomplete_controller->done()); 111 EXPECT_TRUE(autocomplete_controller->done());
112 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 112 EXPECT_TRUE(location_bar->GetInputString().empty());
113 EXPECT_EQ(std::wstring(), location_bar->location_entry()->GetText()); 113 EXPECT_TRUE(location_bar->location_entry()->GetText().empty());
114 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); 114 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll());
115 const AutocompleteResult& result = autocomplete_controller->result(); 115 const AutocompleteResult& result = autocomplete_controller->result();
116 ASSERT_EQ(1U, result.size()) << AutocompleteResultAsString(result); 116 ASSERT_EQ(1U, result.size()) << AutocompleteResultAsString(result);
117 AutocompleteMatch match = result.match_at(0); 117 AutocompleteMatch match = result.match_at(0);
118 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); 118 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type);
119 EXPECT_FALSE(match.deletable); 119 EXPECT_FALSE(match.deletable);
120 } 120 }
121 121
122 { 122 {
123 location_bar->Revert(); 123 location_bar->Revert();
124 124
125 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 125 EXPECT_TRUE(location_bar->GetInputString().empty());
126 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 126 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL),
127 location_bar->location_entry()->GetText()); 127 location_bar->location_entry()->GetText());
128 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); 128 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll());
129 const AutocompleteResult& result = autocomplete_controller->result(); 129 const AutocompleteResult& result = autocomplete_controller->result();
130 EXPECT_TRUE(result.empty()) << AutocompleteResultAsString(result); 130 EXPECT_TRUE(result.empty()) << AutocompleteResultAsString(result);
131 } 131 }
132 } 132 }
133 133
134 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) { 134 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) {
135 // http://code.google.com/p/chromium/issues/detail?id=38385 135 // http://code.google.com/p/chromium/issues/detail?id=38385
(...skipping 13 matching lines...) Expand all
149 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 149 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL),
150 location_bar->location_entry()->GetText()); 150 location_bar->location_entry()->GetText());
151 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); 151 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll());
152 } 152 }
153 153
154 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { 154 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) {
155 LocationBar* location_bar = GetLocationBar(); 155 LocationBar* location_bar = GetLocationBar();
156 156
157 // Focus search when omnibox is blank 157 // Focus search when omnibox is blank
158 { 158 {
159 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 159 EXPECT_TRUE(location_bar->GetInputString().empty());
160 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), 160 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL),
161 location_bar->location_entry()->GetText()); 161 location_bar->location_entry()->GetText());
162 162
163 location_bar->FocusSearch(); 163 location_bar->FocusSearch();
164 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 164 EXPECT_TRUE(location_bar->GetInputString().empty());
165 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); 165 EXPECT_EQ(L"?", location_bar->location_entry()->GetText());
166 166
167 size_t selection_start, selection_end; 167 size_t selection_start, selection_end;
168 location_bar->location_entry()->GetSelectionBounds(&selection_start, 168 location_bar->location_entry()->GetSelectionBounds(&selection_start,
169 &selection_end); 169 &selection_end);
170 EXPECT_EQ(1U, selection_start); 170 EXPECT_EQ(1U, selection_start);
171 EXPECT_EQ(1U, selection_end); 171 EXPECT_EQ(1U, selection_end);
172 } 172 }
173 173
174 // Focus search when omnibox is _not_ alread in forced query mode. 174 // Focus search when omnibox is _not_ alread in forced query mode.
175 { 175 {
176 location_bar->location_entry()->SetUserText(L"foo"); 176 location_bar->location_entry()->SetUserText(L"foo");
177 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 177 EXPECT_TRUE(location_bar->GetInputString().empty());
178 EXPECT_EQ(L"foo", location_bar->location_entry()->GetText()); 178 EXPECT_EQ(L"foo", location_bar->location_entry()->GetText());
179 179
180 location_bar->FocusSearch(); 180 location_bar->FocusSearch();
181 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 181 EXPECT_TRUE(location_bar->GetInputString().empty());
182 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); 182 EXPECT_EQ(L"?", location_bar->location_entry()->GetText());
183 183
184 size_t selection_start, selection_end; 184 size_t selection_start, selection_end;
185 location_bar->location_entry()->GetSelectionBounds(&selection_start, 185 location_bar->location_entry()->GetSelectionBounds(&selection_start,
186 &selection_end); 186 &selection_end);
187 EXPECT_EQ(1U, selection_start); 187 EXPECT_EQ(1U, selection_start);
188 EXPECT_EQ(1U, selection_end); 188 EXPECT_EQ(1U, selection_end);
189 } 189 }
190 190
191 // Focus search when omnibox _is_ already in forced query mode, but no query 191 // Focus search when omnibox _is_ already in forced query mode, but no query
192 // has been typed. 192 // has been typed.
193 { 193 {
194 location_bar->location_entry()->SetUserText(L"?"); 194 location_bar->location_entry()->SetUserText(L"?");
195 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 195 EXPECT_TRUE(location_bar->GetInputString().empty());
196 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); 196 EXPECT_EQ(L"?", location_bar->location_entry()->GetText());
197 197
198 location_bar->FocusSearch(); 198 location_bar->FocusSearch();
199 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 199 EXPECT_TRUE(location_bar->GetInputString().empty());
200 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); 200 EXPECT_EQ(L"?", location_bar->location_entry()->GetText());
201 201
202 size_t selection_start, selection_end; 202 size_t selection_start, selection_end;
203 location_bar->location_entry()->GetSelectionBounds(&selection_start, 203 location_bar->location_entry()->GetSelectionBounds(&selection_start,
204 &selection_end); 204 &selection_end);
205 EXPECT_EQ(1U, selection_start); 205 EXPECT_EQ(1U, selection_start);
206 EXPECT_EQ(1U, selection_end); 206 EXPECT_EQ(1U, selection_end);
207 } 207 }
208 208
209 // Focus search when omnibox _is_ already in forced query mode, and some query 209 // Focus search when omnibox _is_ already in forced query mode, and some query
210 // has been typed. 210 // has been typed.
211 { 211 {
212 location_bar->location_entry()->SetUserText(L"?foo"); 212 location_bar->location_entry()->SetUserText(L"?foo");
213 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 213 EXPECT_TRUE(location_bar->GetInputString().empty());
214 EXPECT_EQ(L"?foo", location_bar->location_entry()->GetText()); 214 EXPECT_EQ(L"?foo", location_bar->location_entry()->GetText());
215 215
216 location_bar->FocusSearch(); 216 location_bar->FocusSearch();
217 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 217 EXPECT_TRUE(location_bar->GetInputString().empty());
218 EXPECT_EQ(L"?foo", location_bar->location_entry()->GetText()); 218 EXPECT_EQ(L"?foo", location_bar->location_entry()->GetText());
219 219
220 size_t selection_start, selection_end; 220 size_t selection_start, selection_end;
221 location_bar->location_entry()->GetSelectionBounds(&selection_start, 221 location_bar->location_entry()->GetSelectionBounds(&selection_start,
222 &selection_end); 222 &selection_end);
223 EXPECT_EQ(1U, std::min(selection_start, selection_end)); 223 EXPECT_EQ(1U, std::min(selection_start, selection_end));
224 EXPECT_EQ(4U, std::max(selection_start, selection_end)); 224 EXPECT_EQ(4U, std::max(selection_start, selection_end));
225 } 225 }
226 226
227 // Focus search when omnibox is in forced query mode with leading whitespace. 227 // Focus search when omnibox is in forced query mode with leading whitespace.
228 { 228 {
229 location_bar->location_entry()->SetUserText(L" ?foo"); 229 location_bar->location_entry()->SetUserText(L" ?foo");
230 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 230 EXPECT_TRUE(location_bar->GetInputString().empty());
231 EXPECT_EQ(L" ?foo", location_bar->location_entry()->GetText()); 231 EXPECT_EQ(L" ?foo", location_bar->location_entry()->GetText());
232 232
233 location_bar->FocusSearch(); 233 location_bar->FocusSearch();
234 EXPECT_EQ(std::wstring(), location_bar->GetInputString()); 234 EXPECT_TRUE(location_bar->GetInputString().empty());
235 EXPECT_EQ(L" ?foo", location_bar->location_entry()->GetText()); 235 EXPECT_EQ(L" ?foo", location_bar->location_entry()->GetText());
236 236
237 size_t selection_start, selection_end; 237 size_t selection_start, selection_end;
238 location_bar->location_entry()->GetSelectionBounds(&selection_start, 238 location_bar->location_entry()->GetSelectionBounds(&selection_start,
239 &selection_end); 239 &selection_end);
240 EXPECT_EQ(4U, std::min(selection_start, selection_end)); 240 EXPECT_EQ(4U, std::min(selection_start, selection_end));
241 EXPECT_EQ(7U, std::max(selection_start, selection_end)); 241 EXPECT_EQ(7U, std::max(selection_start, selection_end));
242 } 242 }
243 } 243 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_match.h » ('j') | chrome/browser/autocomplete/history_provider.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698