Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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(nullptr, 500, false, |
| 315 AutocompleteMatchType::HISTORY_TITLE); | |
| 316 match.contents = base::ASCIIToUTF16("http://autocomplete-result/"); | |
| 317 match.contents_class.push_back( | |
| 318 ACMatchClassification(0, ACMatchClassification::URL)); | |
| 315 match.destination_url = GURL("http://autocomplete-result/"); | 319 match.destination_url = GURL("http://autocomplete-result/"); |
| 316 match.allowed_to_be_default_match = true; | 320 match.allowed_to_be_default_match = true; |
| 317 match.type = AutocompleteMatchType::HISTORY_TITLE; | |
| 318 match.relevance = 500; | |
| 319 matches.push_back(match); | |
| 320 match.destination_url = GURL("http://autocomplete-result2/"); | |
| 321 matches.push_back(match); | 321 matches.push_back(match); |
| 322 const AutocompleteInput input( | 322 const AutocompleteInput input( |
| 323 base::ASCIIToUTF16("a"), base::string16::npos, std::string(), GURL(), | 323 base::ASCIIToUTF16("a"), base::string16::npos, std::string(), GURL(), |
| 324 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, | 324 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, |
| 325 TestSchemeClassifier()); | 325 TestSchemeClassifier()); |
| 326 results.AppendMatches(input, matches); | 326 results.AppendMatches(input, matches); |
| 327 results.SortAndCull( | 327 results.SortAndCull( |
| 328 input, TemplateURLServiceFactory::GetForProfile(browser()->profile())); | 328 input, TemplateURLServiceFactory::GetForProfile(browser()->profile())); |
| 329 | 329 |
| 330 // The omnibox popup should open with suggestions displayed. | 330 // The omnibox popup should open with suggestions displayed. |
| 331 omnibox_view->model()->popup_model()->OnResultChanged(); | 331 omnibox_view->model()->popup_model()->OnResultChanged(); |
| 332 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); | 332 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); |
| 333 | 333 |
| 334 // The omnibox text should be selected. | 334 // The omnibox text should be selected. |
| 335 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 335 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 336 | 336 |
| 337 // Simulate a mouse click before dragging the mouse. | 337 // Simulate a mouse click before dragging the mouse. |
| 338 gfx::Point point(omnibox_view_views->x(), omnibox_view_views->y()); | 338 gfx::Point point(omnibox_view_views->origin()); |
| 339 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, point, point, | 339 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, point, point, |
| 340 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 340 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 341 ui::EF_LEFT_MOUSE_BUTTON); | 341 ui::EF_LEFT_MOUSE_BUTTON); |
| 342 omnibox_view_views->OnMousePressed(pressed); | 342 omnibox_view_views->OnMousePressed(pressed); |
| 343 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); | 343 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); |
| 344 | 344 |
| 345 // Simulate a mouse drag of the omnibox text, and the omnibox should close. | 345 // Simulate a mouse drag of the omnibox text, and the omnibox should close. |
| 346 ui::MouseEvent dragged(ui::ET_MOUSE_DRAGGED, point, point, | 346 ui::MouseEvent dragged(ui::ET_MOUSE_DRAGGED, point, point, |
| 347 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); | 347 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 348 omnibox_view_views->OnMouseDragged(dragged); | 348 omnibox_view_views->OnMouseDragged(dragged); |
| 349 | 349 |
| 350 EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen()); | 350 EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen()); |
| 351 } | 351 } |
| 352 | 352 |
| 353 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, MaintainCursorAfterFocusCycle) { | |
| 354 OmniboxView* omnibox_view = nullptr; | |
| 355 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); | |
| 356 OmniboxViewViews* omnibox_view_views = | |
| 357 static_cast<OmniboxViewViews*>(omnibox_view); | |
| 358 | |
| 359 // Populate suggestions for the omnibox popup. | |
| 360 AutocompleteController* autocomplete_controller = | |
| 361 omnibox_view->model()->popup_model()->autocomplete_controller(); | |
| 362 AutocompleteResult& results = autocomplete_controller->result_; | |
| 363 ACMatches matches; | |
| 364 AutocompleteMatch match(nullptr, 500, false, | |
| 365 AutocompleteMatchType::HISTORY_TITLE); | |
| 366 match.contents = base::ASCIIToUTF16("http://autocomplete-result/"); | |
| 367 match.contents_class.push_back( | |
| 368 ACMatchClassification(0, ACMatchClassification::URL)); | |
| 369 match.destination_url = GURL("http://autocomplete-result/"); | |
| 370 match.allowed_to_be_default_match = true; | |
| 371 matches.push_back(match); | |
| 372 const AutocompleteInput input( | |
| 373 base::ASCIIToUTF16("autocomplete-result"), 19, "autocomplete-result", | |
| 374 GURL("http://autocomplete-result/"), | |
| 375 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, | |
| 376 TestSchemeClassifier()); | |
| 377 results.AppendMatches(input, matches); | |
| 378 results.SortAndCull( | |
| 379 input, TemplateURLServiceFactory::GetForProfile(browser()->profile())); | |
| 380 | |
| 381 // The omnibox popup should open with suggestions displayed. | |
| 382 omnibox_view->model()->popup_model()->OnResultChanged(); | |
| 383 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); | |
| 384 | |
| 385 // The omnibox text should be selected. | |
| 386 EXPECT_TRUE(omnibox_view->IsSelectAll()); | |
| 387 | |
| 388 // Simulate a mouse click to trigger focus. Click well right of text. | |
|
Peter Kasting
2017/04/17 17:46:39
This seems a bit fiddly when all you really want (
Peter Kasting
2017/04/17 19:57:23
Note that calling ClickBrowserWindowCenter() would
| |
| 389 gfx::Point point(omnibox_view_views->origin()); | |
| 390 point = gfx::Point(point.x() + 100, point.y() + 1); | |
| 391 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, point, point, | |
| 392 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | |
| 393 ui::EF_LEFT_MOUSE_BUTTON); | |
| 394 omnibox_view_views->OnMousePressed(pressed); | |
| 395 omnibox_view_views->OnMouseReleased(pressed); | |
| 396 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); | |
| 397 | |
| 398 // Save cursor position, before blur. | |
| 399 size_t prev_start, end; | |
| 400 omnibox_view->GetSelectionBounds(&prev_start, &end); | |
| 401 | |
| 402 omnibox_view_views->OnBlur(); | |
| 403 EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen()); | |
| 404 | |
| 405 // Redo the above. | |
| 406 omnibox_view_views->OnFocus(); | |
| 407 results.AppendMatches(input, matches); | |
| 408 results.SortAndCull( | |
| 409 input, TemplateURLServiceFactory::GetForProfile(browser()->profile())); | |
| 410 omnibox_view->model()->popup_model()->OnResultChanged(); | |
| 411 EXPECT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); | |
| 412 | |
| 413 // Make sure cursor is restored. | |
| 414 size_t start = 0; | |
|
Peter Kasting
2017/04/17 17:46:39
Nit: No need to init this, but if you do, init the
Kevin Bailey
2017/04/18 19:45:13
I like to be paranoid and initialize things such t
| |
| 415 omnibox_view->GetSelectionBounds(&start, &end); | |
| 416 EXPECT_EQ(prev_start, start); | |
| 417 } | |
| 418 | |
| 353 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, BackgroundIsOpaque) { | 419 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, BackgroundIsOpaque) { |
| 354 // The omnibox text should be rendered on an opaque background. Otherwise, we | 420 // The omnibox text should be rendered on an opaque background. Otherwise, we |
| 355 // can't use subpixel rendering. | 421 // can't use subpixel rendering. |
| 356 OmniboxViewViews* view = BrowserView::GetBrowserViewForBrowser(browser())-> | 422 OmniboxViewViews* view = BrowserView::GetBrowserViewForBrowser(browser())-> |
| 357 toolbar()->location_bar()->omnibox_view(); | 423 toolbar()->location_bar()->omnibox_view(); |
| 358 ASSERT_TRUE(view); | 424 ASSERT_TRUE(view); |
| 359 EXPECT_FALSE(view->GetRenderText()->subpixel_rendering_suppressed()); | 425 EXPECT_FALSE(view->GetRenderText()->subpixel_rendering_suppressed()); |
| 360 } | 426 } |
| 361 | 427 |
| 362 // Tests if executing a command hides touch editing handles. | 428 // Tests if executing a command hides touch editing handles. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 386 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, FocusedTextInputClient) { | 452 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, FocusedTextInputClient) { |
| 387 chrome::FocusLocationBar(browser()); | 453 chrome::FocusLocationBar(browser()); |
| 388 OmniboxView* view = NULL; | 454 OmniboxView* view = NULL; |
| 389 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &view)); | 455 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &view)); |
| 390 OmniboxViewViews* omnibox_view_views = static_cast<OmniboxViewViews*>(view); | 456 OmniboxViewViews* omnibox_view_views = static_cast<OmniboxViewViews*>(view); |
| 391 ui::InputMethod* input_method = | 457 ui::InputMethod* input_method = |
| 392 omnibox_view_views->GetWidget()->GetInputMethod(); | 458 omnibox_view_views->GetWidget()->GetInputMethod(); |
| 393 EXPECT_EQ(static_cast<ui::TextInputClient*>(omnibox_view_views), | 459 EXPECT_EQ(static_cast<ui::TextInputClient*>(omnibox_view_views), |
| 394 input_method->GetTextInputClient()); | 460 input_method->GetTextInputClient()); |
| 395 } | 461 } |
| OLD | NEW |