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

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: Reverted autocomplete_text_field* 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
202
Peter Kasting 2016/04/08 00:39:56 Nit: Don't add these
Tom (Use chromium acct) 2016/04/12 20:03:05 Done.
200 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { 203 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) {
201 #if defined(OS_WIN) && defined(USE_ASH) 204 #if defined(OS_WIN) && defined(USE_ASH)
202 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 205 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
203 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 206 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
204 switches::kAshBrowserTests)) 207 switches::kAshBrowserTests))
205 return; 208 return;
206 #endif 209 #endif
207 210
208 WaitForTemplateURLServiceToLoad(); 211 WaitForTemplateURLServiceToLoad();
209 LocationBar* location_bar = GetLocationBar(); 212 LocationBar* location_bar = GetLocationBar();
210 OmniboxView* omnibox_view = location_bar->GetOmniboxView(); 213 OmniboxView* omnibox_view = location_bar->GetOmniboxView();
214 OmniboxEditModel* omnibox_model = omnibox_view->model();
215
216 TemplateURLService* template_url_service =
217 TemplateURLServiceFactory::GetForProfile(browser()->profile());
218 base::string16 dsp =
Peter Kasting 2016/04/08 00:39:56 Nit: Since this is really a keyword and not a prov
Tom (Use chromium acct) 2016/04/12 20:03:05 Done.
219 template_url_service->GetDefaultSearchProvider()->keyword();
220
221 const char query_text[] = "foo";
Peter Kasting 2016/04/08 00:39:56 Every place below that wants this wants it as a st
Tom (Use chromium acct) 2016/04/12 20:03:04 Done.
222 const size_t query_text_len = sizeof(query_text) - 1;
223
224 size_t selection_start, selection_end;
225
226 #define FOCUS_SEARCH_CHECK_PRECONDITIONS() \
Peter Kasting 2016/04/08 00:39:55 We try to avoid macros if possible. Why not put t
Tom (Use chromium acct) 2016/04/12 20:03:04 Done.
227 do { \
228 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); \
229 EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL), \
230 omnibox_view->GetText()); \
231 EXPECT_EQ(base::string16(), omnibox_model->keyword()); \
232 EXPECT_FALSE(omnibox_model->is_keyword_hint()); \
233 EXPECT_FALSE(omnibox_model->is_keyword_selected()); \
234 } while (false)
211 235
212 // Focus search when omnibox is blank 236 // Focus search when omnibox is blank
213 { 237 {
214 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 238 FOCUS_SEARCH_CHECK_PRECONDITIONS();
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(dsp, 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 FOCUS_SEARCH_CHECK_PRECONDITIONS();
257
258 omnibox_view->SetUserText(base::ASCIIToUTF16(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(base::ASCIIToUTF16(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(base::ASCIIToUTF16(query_text), omnibox_view->GetText());
268 EXPECT_EQ(dsp, 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_len, selection_start);
240 EXPECT_EQ(1U, selection_end); 274 EXPECT_EQ(query_text_len, 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 FOCUS_SEARCH_CHECK_PRECONDITIONS();
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(dsp, 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(dsp, 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 FOCUS_SEARCH_CHECK_PRECONDITIONS();
313
314 omnibox_view->SetUserText(base::ASCIIToUTF16(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(base::ASCIIToUTF16(query_text), omnibox_view->GetText());
318 EXPECT_EQ(dsp, 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_len, selection_start);
324 EXPECT_EQ(query_text_len, 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(base::ASCIIToUTF16(query_text), omnibox_view->GetText());
329 EXPECT_EQ(dsp, 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,
274 EXPECT_EQ(4U, std::max(selection_start, selection_end)); 335 selection_start < selection_end ?
336 selection_start : selection_end);
Peter Kasting 2016/04/08 00:39:56 Nit: Use std::min()
Tom (Use chromium acct) 2016/04/12 20:03:05 Done.
337 EXPECT_EQ(query_text_len,
338 selection_start > selection_end ?
339 selection_start : selection_end);
Peter Kasting 2016/04/08 00:39:56 Nit: Use std::max()
Tom (Use chromium acct) 2016/04/12 20:03:05 Done.
340
341 omnibox_view->RevertAll();
275 } 342 }
276 343
277 // Focus search when omnibox is in forced query mode with leading whitespace. 344 // If the user got into keyword mode using a keyboard shortcut, and presses
Peter Kasting 2016/04/08 00:39:56 Nit: Tense agreement: got -> gets (here and below)
Tom (Use chromium acct) 2016/04/12 20:03:04 Done.
345 // backspace, they should be left with their original query without their dsp
346 // keyword.
278 { 347 {
279 omnibox_view->SetUserText(base::ASCIIToUTF16(" ?foo")); 348 FOCUS_SEARCH_CHECK_PRECONDITIONS();
349
350 omnibox_view->SetUserText(base::ASCIIToUTF16(query_text));
351 // the user presses Ctrl-K
Peter Kasting 2016/04/08 00:39:55 Nit: Capitalization, trailing period (multiple pla
Tom (Use chromium acct) 2016/04/12 20:03:05 Done.
352 location_bar->FocusSearch();
353 // the user presses backspace
354 omnibox_model->ClearKeyword();
Peter Kasting 2016/04/08 00:39:55 Can we just send a backspace keypress? That ensur
Tom (Use chromium acct) 2016/04/12 20:03:04 Is there a testing API for pressing backspace or m
Peter Kasting 2016/04/12 20:04:13 I thought there was an API to send any key by key
355
280 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 356 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
281 EXPECT_EQ(base::ASCIIToUTF16(" ?foo"), omnibox_view->GetText()); 357 EXPECT_EQ(base::ASCIIToUTF16(query_text), omnibox_view->GetText());
358 EXPECT_EQ(base::string16(), omnibox_model->keyword());
359 EXPECT_FALSE(omnibox_model->is_keyword_hint());
360 EXPECT_FALSE(omnibox_model->is_keyword_selected());
282 361
283 location_bar->FocusSearch(); 362 omnibox_view->RevertAll();
363 }
364
365 // If the user got into keyword mode by typing '?', they should be put into
366 // keyword mode with their dsp. If they press backspace, they should be left
Peter Kasting 2016/04/08 00:39:55 Nit: with their dsp -> for their default search pr
Tom (Use chromium acct) 2016/04/12 20:03:04 Done.
367 // with '?' in the omnibox.
368 {
369 FOCUS_SEARCH_CHECK_PRECONDITIONS();
370
371 omnibox_view->SetUserText(base::ASCIIToUTF16("?"));
372
284 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid()); 373 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
285 EXPECT_EQ(base::ASCIIToUTF16(" ?foo"), omnibox_view->GetText()); 374 EXPECT_EQ(base::string16(), omnibox_view->GetText());
375 EXPECT_EQ(dsp, omnibox_model->keyword());
376 EXPECT_FALSE(omnibox_model->is_keyword_hint());
377 EXPECT_TRUE(omnibox_model->is_keyword_selected());
286 378
287 size_t selection_start, selection_end; 379 // the user presses backspace
288 omnibox_view->GetSelectionBounds(&selection_start, &selection_end); 380 omnibox_model->ClearKeyword();
289 EXPECT_EQ(4U, std::min(selection_start, selection_end)); 381
290 EXPECT_EQ(7U, std::max(selection_start, selection_end)); 382 EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
383 EXPECT_EQ(base::ASCIIToUTF16("?"), omnibox_view->GetText());
384 EXPECT_EQ(base::string16(), omnibox_model->keyword());
385 EXPECT_FALSE(omnibox_model->is_keyword_hint());
386 EXPECT_FALSE(omnibox_model->is_keyword_selected());
387
388 omnibox_view->RevertAll();
291 } 389 }
292 } 390 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h » ('j') | chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698