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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views_browsertest.cc

Issue 2763063002: [omnibox] Narrow condition for resetting selection (Closed)
Patch Set: Cheered up comments and trimmed tests Created 3 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // Pressing tab to focus the omnibox should select all text. 294 // Pressing tab to focus the omnibox should select all text.
295 while (!ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)) { 295 while (!ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)) {
296 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, 296 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB,
297 false, false, false, false)); 297 false, false, false, false));
298 } 298 }
299 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 299 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
300 EXPECT_TRUE(omnibox_view->IsSelectAll()); 300 EXPECT_TRUE(omnibox_view->IsSelectAll());
301 } 301 }
302 302
303 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, CloseOmniboxPopupOnTextDrag) { 303 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, CloseOmniboxPopupOnTextDrag) {
304 OmniboxView* omnibox_view = NULL; 304 OmniboxView* omnibox_view = nullptr;
305 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); 305 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view));
306 OmniboxViewViews* omnibox_view_views = 306 OmniboxViewViews* omnibox_view_views =
307 static_cast<OmniboxViewViews*>(omnibox_view); 307 static_cast<OmniboxViewViews*>(omnibox_view);
308 308
309 // Populate suggestions for the omnibox popup. 309 // Populate suggestions for the omnibox popup.
310 AutocompleteController* autocomplete_controller = 310 AutocompleteController* autocomplete_controller =
311 omnibox_view->model()->popup_model()->autocomplete_controller(); 311 omnibox_view->model()->popup_model()->autocomplete_controller();
312 AutocompleteResult& results = autocomplete_controller->result_; 312 AutocompleteResult& results = autocomplete_controller->result_;
313 ACMatches matches; 313 ACMatches matches;
314 AutocompleteMatch match; 314 AutocompleteMatch match;
315 match.destination_url = GURL("http://autocomplete-result/"); 315 match.destination_url = GURL("http://autocomplete-result/");
316 match.allowed_to_be_default_match = true; 316 match.allowed_to_be_default_match = true;
317 match.type = AutocompleteMatchType::HISTORY_TITLE; 317 match.type = AutocompleteMatchType::HISTORY_TITLE;
318 match.relevance = 500; 318 match.relevance = 500;
319 matches.push_back(match); 319 matches.push_back(match);
320 match.destination_url = GURL("http://autocomplete-result2/");
321 matches.push_back(match);
322 const AutocompleteInput input( 320 const AutocompleteInput input(
323 base::ASCIIToUTF16("a"), base::string16::npos, std::string(), GURL(), 321 base::ASCIIToUTF16("a"), base::string16::npos, std::string(), GURL(),
324 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, 322 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false,
325 TestSchemeClassifier()); 323 TestSchemeClassifier());
326 results.AppendMatches(input, matches); 324 results.AppendMatches(input, matches);
327 results.SortAndCull( 325 results.SortAndCull(
328 input, TemplateURLServiceFactory::GetForProfile(browser()->profile())); 326 input, TemplateURLServiceFactory::GetForProfile(browser()->profile()));
329 327
330 // The omnibox popup should open with suggestions displayed. 328 // The omnibox popup should open with suggestions displayed.
331 omnibox_view->model()->popup_model()->OnResultChanged(); 329 omnibox_view->model()->popup_model()->OnResultChanged();
332 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); 330 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen());
333 331
334 // The omnibox text should be selected. 332 // The omnibox text should be selected.
335 EXPECT_TRUE(omnibox_view->IsSelectAll()); 333 EXPECT_TRUE(omnibox_view->IsSelectAll());
336 334
337 // Simulate a mouse click before dragging the mouse. 335 // Simulate a mouse click before dragging the mouse.
338 gfx::Point point(omnibox_view_views->x(), omnibox_view_views->y()); 336 gfx::Point point(omnibox_view_views->origin());
339 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, point, point, 337 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, point, point,
340 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 338 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
341 ui::EF_LEFT_MOUSE_BUTTON); 339 ui::EF_LEFT_MOUSE_BUTTON);
342 omnibox_view_views->OnMousePressed(pressed); 340 omnibox_view_views->OnMousePressed(pressed);
343 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); 341 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen());
344 342
345 // Simulate a mouse drag of the omnibox text, and the omnibox should close. 343 // Simulate a mouse drag of the omnibox text, and the omnibox should close.
346 ui::MouseEvent dragged(ui::ET_MOUSE_DRAGGED, point, point, 344 ui::MouseEvent dragged(ui::ET_MOUSE_DRAGGED, point, point,
347 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 345 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
348 omnibox_view_views->OnMouseDragged(dragged); 346 omnibox_view_views->OnMouseDragged(dragged);
349 347
350 EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen()); 348 EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen());
351 } 349 }
352 350
351 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, MaintainCursorAfterFocusCycle) {
352 OmniboxView* omnibox_view = nullptr;
353 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view));
354 OmniboxViewViews* omnibox_view_views =
355 static_cast<OmniboxViewViews*>(omnibox_view);
356
357 // Populate suggestions for the omnibox popup.
358 AutocompleteController* autocomplete_controller =
359 omnibox_view->model()->popup_model()->autocomplete_controller();
360 AutocompleteResult& results = autocomplete_controller->result_;
361 ACMatches matches;
362 AutocompleteMatch match;
Peter Kasting 2017/04/12 23:48:24 Nit: Could do AutocompleteMatch match(nullptr,
Kevin Bailey 2017/04/18 19:45:13 Done.
363 match.destination_url = GURL("http://autocomplete-result/");
364 match.allowed_to_be_default_match = true;
365 match.type = AutocompleteMatchType::HISTORY_TITLE;
366 match.relevance = 500;
367 matches.push_back(match);
368 const AutocompleteInput input(
369 base::ASCIIToUTF16("autocomplete-result"), 19, "autocomplete-result",
370 GURL("http://autocomplete-result/"),
371 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false,
372 TestSchemeClassifier());
373 results.AppendMatches(input, matches);
374 results.SortAndCull(
375 input, TemplateURLServiceFactory::GetForProfile(browser()->profile()));
376
377 // The omnibox popup should open with suggestions displayed.
378 omnibox_view->model()->popup_model()->OnResultChanged();
379 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen());
380
381 // The omnibox text should be selected.
382 EXPECT_TRUE(omnibox_view->IsSelectAll());
383
384 // Simulate a mouse click to trigger focus.
385 gfx::Point point(omnibox_view_views->origin());
386 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, point, point,
387 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
388 ui::EF_LEFT_MOUSE_BUTTON);
389 omnibox_view_views->OnMousePressed(pressed);
390 omnibox_view_views->OnMouseReleased(pressed);
391 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen());
392
393 omnibox_view_views->OnBlur();
394 EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen());
395
396 // Redo the above
Peter Kasting 2017/04/12 23:48:24 Nit: Be clearer (since "the above" covers a lot);
Kevin Bailey 2017/04/18 19:45:13 Done.
397 omnibox_view_views->OnFocus();
398 results.AppendMatches(input, matches);
399 results.SortAndCull(
400 input, TemplateURLServiceFactory::GetForProfile(browser()->profile()));
401 omnibox_view->model()->popup_model()->OnResultChanged();
402 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen());
403 size_t start = 0, end;
404 omnibox_view->GetSelectionBounds(&start, &end);
405 // Make sure cursor isn't homed.
Peter Kasting 2017/04/12 23:48:24 Nit: This really goes above the declaration of sta
Kevin Bailey 2017/04/18 19:45:13 Done.
406 EXPECT_NE(0U, start);
Peter Kasting 2017/04/12 23:48:25 Nit: It's not immediately obvious why this should
Kevin Bailey 2017/04/18 19:45:13 Done.
407 // Blur or it dchecks when rendering. The above queues messages for the
408 // task which get handled after the test is finished. Blurring quiesces
409 // them.
Peter Kasting 2017/04/12 23:48:24 OK... this doesn't really make things clearer than
Kevin Bailey 2017/04/13 00:07:12 The part about this that bothers me is that the ne
Peter Kasting 2017/04/13 00:12:15 Yes, I agree with your instinct. Spinning the mes
Kevin Bailey 2017/04/17 16:39:11 (For the reader, since this was discussed off-line
410 omnibox_view_views->OnBlur();
411 }
412
353 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, BackgroundIsOpaque) { 413 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, BackgroundIsOpaque) {
354 // The omnibox text should be rendered on an opaque background. Otherwise, we 414 // The omnibox text should be rendered on an opaque background. Otherwise, we
355 // can't use subpixel rendering. 415 // can't use subpixel rendering.
356 OmniboxViewViews* view = BrowserView::GetBrowserViewForBrowser(browser())-> 416 OmniboxViewViews* view = BrowserView::GetBrowserViewForBrowser(browser())->
357 toolbar()->location_bar()->omnibox_view(); 417 toolbar()->location_bar()->omnibox_view();
358 ASSERT_TRUE(view); 418 ASSERT_TRUE(view);
359 EXPECT_FALSE(view->GetRenderText()->subpixel_rendering_suppressed()); 419 EXPECT_FALSE(view->GetRenderText()->subpixel_rendering_suppressed());
360 } 420 }
361 421
362 // Tests if executing a command hides touch editing handles. 422 // Tests if executing a command hides touch editing handles.
(...skipping 23 matching lines...) Expand all
386 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, FocusedTextInputClient) { 446 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, FocusedTextInputClient) {
387 chrome::FocusLocationBar(browser()); 447 chrome::FocusLocationBar(browser());
388 OmniboxView* view = NULL; 448 OmniboxView* view = NULL;
389 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &view)); 449 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &view));
390 OmniboxViewViews* omnibox_view_views = static_cast<OmniboxViewViews*>(view); 450 OmniboxViewViews* omnibox_view_views = static_cast<OmniboxViewViews*>(view);
391 ui::InputMethod* input_method = 451 ui::InputMethod* input_method =
392 omnibox_view_views->GetWidget()->GetInputMethod(); 452 omnibox_view_views->GetWidget()->GetInputMethod();
393 EXPECT_EQ(static_cast<ui::TextInputClient*>(omnibox_view_views), 453 EXPECT_EQ(static_cast<ui::TextInputClient*>(omnibox_view_views),
394 input_method->GetTextInputClient()); 454 input_method->GetTextInputClient());
395 } 455 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views.cc ('k') | components/omnibox/browser/autocomplete_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698