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

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

Issue 1855423003: Interpret '?' and Ctrl-K or Ctrl-E as putting omnibox in keyword search mode for Default Search Pro… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed forced queries using '?'. Removed Ctrl-K preserving the user's keyword if they're already … Created 4 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 17 matching lines...) Expand all
28 #include "chrome/test/base/search_test_utils.h" 28 #include "chrome/test/base/search_test_utils.h"
29 #include "chrome/test/base/test_switches.h" 29 #include "chrome/test/base/test_switches.h"
30 #include "chrome/test/base/ui_test_utils.h" 30 #include "chrome/test/base/ui_test_utils.h"
31 #include "components/history/core/browser/history_service.h" 31 #include "components/history/core/browser/history_service.h"
32 #include "components/metrics/proto/omnibox_event.pb.h" 32 #include "components/metrics/proto/omnibox_event.pb.h"
33 #include "components/omnibox/browser/autocomplete_input.h" 33 #include "components/omnibox/browser/autocomplete_input.h"
34 #include "components/omnibox/browser/autocomplete_match.h" 34 #include "components/omnibox/browser/autocomplete_match.h"
35 #include "components/omnibox/browser/autocomplete_provider.h" 35 #include "components/omnibox/browser/autocomplete_provider.h"
36 #include "components/omnibox/browser/omnibox_popup_model.h" 36 #include "components/omnibox/browser/omnibox_popup_model.h"
37 #include "components/omnibox/browser/omnibox_view.h" 37 #include "components/omnibox/browser/omnibox_view.h"
38 #include "components/search_engines/template_url_service.h"
38 #include "content/public/browser/notification_service.h" 39 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/notification_types.h" 40 #include "content/public/browser/notification_types.h"
40 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
41 42
42 namespace { 43 namespace {
43 44
44 base::string16 AutocompleteResultAsString(const AutocompleteResult& result) { 45 base::string16 AutocompleteResultAsString(const AutocompleteResult& result) {
45 std::string output(base::StringPrintf("{%" PRIuS "} ", result.size())); 46 std::string output(base::StringPrintf("{%" PRIuS "} ", result.size()));
46 for (size_t i = 0; i < result.size(); ++i) { 47 for (size_t i = 0; i < result.size(); ++i) {
47 AutocompleteMatch match = result.match_at(i); 48 AutocompleteMatch match = result.match_at(i);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 chrome::AddSelectedTabWithURL(browser(), 191 chrome::AddSelectedTabWithURL(browser(),
191 GURL(url::kAboutBlankURL), 192 GURL(url::kAboutBlankURL),
192 ui::PAGE_TRANSITION_AUTO_TOPLEVEL); 193 ui::PAGE_TRANSITION_AUTO_TOPLEVEL);
193 observer.Wait(); 194 observer.Wait();
194 EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL), omnibox_view->GetText()); 195 EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL), omnibox_view->GetText());
195 chrome::CloseTab(browser()); 196 chrome::CloseTab(browser());
196 EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL), omnibox_view->GetText()); 197 EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL), omnibox_view->GetText());
197 EXPECT_TRUE(omnibox_view->IsSelectAll()); 198 EXPECT_TRUE(omnibox_view->IsSelectAll());
198 } 199 }
199 200
201 static void focusSearchCheckPreconditions() {
Peter Kasting 2016/04/13 02:52:16 Nit: First letter of function name should be capit
Tom (Use chromium acct) 2016/04/13 23:37:40 Done.
202 LocationBar* location_bar = GetLocationBar();
Peter Kasting 2016/04/13 02:52:16 You can't call GetLocationBar() from a non-member
Tom (Use chromium acct) 2016/04/13 23:37:40 Done.
203 OmniboxView* omnibox_view = location_bar->GetOmniboxView();
204 OmniboxEditModel* omnibox_model = omnibox_view->model();
205
206 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
207 EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL),
208 omnibox_view->GetText());
209 EXPECT_EQ(base::string16(), omnibox_model->keyword());
210 EXPECT_FALSE(omnibox_model->is_keyword_hint());
211 EXPECT_FALSE(omnibox_model->is_keyword_selected());
212 }
213
200 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { 214 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) {
201 #if defined(OS_WIN) && defined(USE_ASH) 215 #if defined(OS_WIN) && defined(USE_ASH)
202 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 216 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
203 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 217 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
204 switches::kAshBrowserTests)) 218 switches::kAshBrowserTests))
205 return; 219 return;
206 #endif 220 #endif
207 221
208 WaitForTemplateURLServiceToLoad(); 222 WaitForTemplateURLServiceToLoad();
209 LocationBar* location_bar = GetLocationBar(); 223 LocationBar* location_bar = GetLocationBar();
210 OmniboxView* omnibox_view = location_bar->GetOmniboxView(); 224 OmniboxView* omnibox_view = location_bar->GetOmniboxView();
225 OmniboxEditModel* omnibox_model = omnibox_view->model();
211 226
212 // Focus search when omnibox is blank 227 TemplateURLService* template_url_service =
228 TemplateURLServiceFactory::GetForProfile(browser()->profile());
229 base::string16 default_search_keyword =
230 template_url_service->GetDefaultSearchProvider()->keyword();
231
232 base::string16 query_text = ASCIIToUTF16("foo");
Peter Kasting 2016/04/13 02:52:16 Need base:: qualifier
Tom (Use chromium acct) 2016/04/13 23:37:40 Done.
233
234 size_t selection_start, selection_end;
235
236 // Focus search when omnibox is blank.
213 { 237 {
214 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 238 focusSearchCheckPreconditions();
215 EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL), omnibox_view->GetText());
216 239
217 location_bar->FocusSearch(); 240 location_bar->FocusSearch();
218 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 241 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
219 EXPECT_EQ(base::ASCIIToUTF16("?"), omnibox_view->GetText()); 242 EXPECT_EQ(base::string16(), omnibox_view->GetText());
243 EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
244 EXPECT_FALSE(omnibox_model->is_keyword_hint());
245 EXPECT_TRUE(omnibox_model->is_keyword_selected());
220 246
221 size_t selection_start, selection_end;
222 omnibox_view->GetSelectionBounds(&selection_start, &selection_end); 247 omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
223 EXPECT_EQ(1U, selection_start); 248 EXPECT_EQ(0U, selection_start);
224 EXPECT_EQ(1U, selection_end); 249 EXPECT_EQ(0U, selection_end);
250
251 omnibox_view->RevertAll();
225 } 252 }
226 253
227 // Focus search when omnibox is _not_ alread in forced query mode. 254 // Focus search when omnibox is _not_ alread in forced query mode.
228 { 255 {
229 omnibox_view->SetUserText(base::ASCIIToUTF16("foo")); 256 focusSearchCheckPreconditions();
257
258 omnibox_view->SetUserText(query_text);
230 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 259 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
231 EXPECT_EQ(base::ASCIIToUTF16("foo"), omnibox_view->GetText()); 260 EXPECT_EQ(query_text, omnibox_view->GetText());
261 EXPECT_EQ(base::string16(), omnibox_model->keyword());
262 EXPECT_FALSE(omnibox_model->is_keyword_hint());
263 EXPECT_FALSE(omnibox_model->is_keyword_selected());
232 264
233 location_bar->FocusSearch(); 265 location_bar->FocusSearch();
234 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 266 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
235 EXPECT_EQ(base::ASCIIToUTF16("?"), omnibox_view->GetText()); 267 EXPECT_EQ(query_text, omnibox_view->GetText());
268 EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
269 EXPECT_FALSE(omnibox_model->is_keyword_hint());
270 EXPECT_TRUE(omnibox_model->is_keyword_selected());
236 271
237 size_t selection_start, selection_end;
238 omnibox_view->GetSelectionBounds(&selection_start, &selection_end); 272 omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
239 EXPECT_EQ(1U, selection_start); 273 EXPECT_EQ(query_text.length(), selection_start);
240 EXPECT_EQ(1U, selection_end); 274 EXPECT_EQ(query_text.length(), selection_end);
275
276 omnibox_view->RevertAll();
241 } 277 }
242 278
243 // Focus search when omnibox _is_ already in forced query mode, but no query 279 // Focus search when omnibox _is_ already in forced query mode, but no query
244 // has been typed. 280 // has been typed.
245 { 281 {
246 omnibox_view->SetUserText(base::ASCIIToUTF16("?")); 282 focusSearchCheckPreconditions();
247 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
248 EXPECT_EQ(base::ASCIIToUTF16("?"), omnibox_view->GetText());
249 283
250 location_bar->FocusSearch(); 284 location_bar->FocusSearch();
251 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 285 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
252 EXPECT_EQ(base::ASCIIToUTF16("?"), omnibox_view->GetText()); 286 EXPECT_EQ(base::string16(), omnibox_view->GetText());
287 EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
288 EXPECT_FALSE(omnibox_model->is_keyword_hint());
289 EXPECT_TRUE(omnibox_model->is_keyword_selected());
253 290
254 size_t selection_start, selection_end;
255 omnibox_view->GetSelectionBounds(&selection_start, &selection_end); 291 omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
256 EXPECT_EQ(1U, selection_start); 292 EXPECT_EQ(0U, selection_start);
257 EXPECT_EQ(1U, selection_end); 293 EXPECT_EQ(0U, selection_end);
294
295 location_bar->FocusSearch();
296 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
297 EXPECT_EQ(base::string16(), omnibox_view->GetText());
298 EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
299 EXPECT_FALSE(omnibox_model->is_keyword_hint());
300 EXPECT_TRUE(omnibox_model->is_keyword_selected());
301
302 omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
303 EXPECT_EQ(0U, selection_start);
304 EXPECT_EQ(0U, selection_end);
305
306 omnibox_view->RevertAll();
258 } 307 }
259 308
260 // Focus search when omnibox _is_ already in forced query mode, and some query 309 // Focus search when omnibox _is_ already in forced query mode, and some query
261 // has been typed. 310 // has been typed.
262 { 311 {
263 omnibox_view->SetUserText(base::ASCIIToUTF16("?foo")); 312 focusSearchCheckPreconditions();
313
314 omnibox_view->SetUserText(query_text);
315 location_bar->FocusSearch();
264 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 316 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
265 EXPECT_EQ(base::ASCIIToUTF16("?foo"), omnibox_view->GetText()); 317 EXPECT_EQ(query_text, omnibox_view->GetText());
318 EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
319 EXPECT_FALSE(omnibox_model->is_keyword_hint());
320 EXPECT_TRUE(omnibox_model->is_keyword_selected());
321
322 omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
323 EXPECT_EQ(query_text.length(), selection_start);
324 EXPECT_EQ(query_text.length(), selection_end);
266 325
267 location_bar->FocusSearch(); 326 location_bar->FocusSearch();
268 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 327 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
269 EXPECT_EQ(base::ASCIIToUTF16("?foo"), omnibox_view->GetText()); 328 EXPECT_EQ(query_text, omnibox_view->GetText());
329 EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
330 EXPECT_FALSE(omnibox_model->is_keyword_hint());
331 EXPECT_TRUE(omnibox_model->is_keyword_selected());
270 332
271 size_t selection_start, selection_end;
272 omnibox_view->GetSelectionBounds(&selection_start, &selection_end); 333 omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
273 EXPECT_EQ(1U, std::min(selection_start, selection_end)); 334 EXPECT_EQ(0U, std::min(selection_start, selection_end));
274 EXPECT_EQ(4U, std::max(selection_start, selection_end)); 335 EXPECT_EQ(query_text.length(), std::min(selection_start, selection_end));
Peter Kasting 2016/04/13 02:52:16 Shouldn't this be max()?
Tom (Use chromium acct) 2016/04/13 23:37:40 Done.
336
337 omnibox_view->RevertAll();
275 } 338 }
276 339
277 // Focus search when omnibox is in forced query mode with leading whitespace. 340 // If the user gets into keyword mode using a keyboard shortcut, and presses
341 // backspace, they should be left with their original query without their dsp
342 // keyword.
278 { 343 {
279 omnibox_view->SetUserText(base::ASCIIToUTF16(" ?foo")); 344 focusSearchCheckPreconditions();
345
346 omnibox_view->SetUserText(query_text);
347 // The user presses Ctrl-K.
348 location_bar->FocusSearch();
349 // The user presses backspace.
350 omnibox_model->ClearKeyword();
351
280 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 352 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
281 EXPECT_EQ(base::ASCIIToUTF16(" ?foo"), omnibox_view->GetText()); 353 EXPECT_EQ(query_text, omnibox_view->GetText());
354 EXPECT_EQ(base::string16(), omnibox_model->keyword());
355 EXPECT_FALSE(omnibox_model->is_keyword_hint());
356 EXPECT_FALSE(omnibox_model->is_keyword_selected());
282 357
283 location_bar->FocusSearch(); 358 omnibox_view->RevertAll();
359 }
360
361 // If the user gets into keyword mode by typing '?', they should be put into
362 // keyword mode for their default search provider. If they press backspace,
363 // they should be left with '?' in the omnibox.
364 {
365 focusSearchCheckPreconditions();
366
367 omnibox_view->SetUserText(base::ASCIIToUTF16("?"));
368
284 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 369 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
285 EXPECT_EQ(base::ASCIIToUTF16(" ?foo"), omnibox_view->GetText()); 370 EXPECT_EQ(base::string16(), omnibox_view->GetText());
371 EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
372 EXPECT_FALSE(omnibox_model->is_keyword_hint());
373 EXPECT_TRUE(omnibox_model->is_keyword_selected());
286 374
287 size_t selection_start, selection_end; 375 // The user presses backspace.
288 omnibox_view->GetSelectionBounds(&selection_start, &selection_end); 376 omnibox_model->ClearKeyword();
289 EXPECT_EQ(4U, std::min(selection_start, selection_end)); 377
290 EXPECT_EQ(7U, std::max(selection_start, selection_end)); 378 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
379 EXPECT_EQ(base::ASCIIToUTF16("?"), omnibox_view->GetText());
380 EXPECT_EQ(base::string16(), omnibox_model->keyword());
381 EXPECT_FALSE(omnibox_model->is_keyword_hint());
382 EXPECT_FALSE(omnibox_model->is_keyword_selected());
383
384 omnibox_view->RevertAll();
291 } 385 }
292 } 386 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698