| 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 "base/command_line.h" |
| 7 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
| 9 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/omnibox/location_bar.h" | 11 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 11 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 12 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 12 #include "chrome/browser/ui/view_ids.h" | 13 #include "chrome/browser/ui/view_ids.h" |
| 13 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/interactive_test_utils.h" | 17 #include "chrome/test/base/interactive_test_utils.h" |
| 17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 18 #include "ui/aura/test/event_generator.h" | 19 #include "ui/aura/test/event_generator.h" |
| 19 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_tree_host.h" | 21 #include "ui/aura/window_tree_host.h" |
| 21 #include "ui/base/clipboard/clipboard.h" | 22 #include "ui/base/clipboard/clipboard.h" |
| 22 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 23 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 23 #include "ui/base/test/ui_controls.h" | 24 #include "ui/base/test/ui_controls.h" |
| 25 #include "ui/base/ui_base_switches.h" |
| 24 #include "ui/events/event_processor.h" | 26 #include "ui/events/event_processor.h" |
| 25 | 27 |
| 26 class OmniboxViewViewsTest : public InProcessBrowserTest { | 28 class OmniboxViewViewsTest : public InProcessBrowserTest { |
| 27 protected: | 29 protected: |
| 28 OmniboxViewViewsTest() {} | 30 OmniboxViewViewsTest() {} |
| 29 | 31 |
| 30 static void GetOmniboxViewForBrowser(const Browser* browser, | 32 static void GetOmniboxViewForBrowser(const Browser* browser, |
| 31 OmniboxView** omnibox_view) { | 33 OmniboxView** omnibox_view) { |
| 32 BrowserWindow* window = browser->window(); | 34 BrowserWindow* window = browser->window(); |
| 33 ASSERT_TRUE(window); | 35 ASSERT_TRUE(window); |
| 34 LocationBar* location_bar = window->GetLocationBar(); | 36 LocationBar* location_bar = window->GetLocationBar(); |
| 35 ASSERT_TRUE(location_bar); | 37 ASSERT_TRUE(location_bar); |
| 36 *omnibox_view = location_bar->GetOmniboxView(); | 38 *omnibox_view = location_bar->GetOmniboxView(); |
| 37 ASSERT_TRUE(*omnibox_view); | 39 ASSERT_TRUE(*omnibox_view); |
| 38 } | 40 } |
| 39 | 41 |
| 42 static ui::TouchSelectionController* GetTouchSelectionControllerForTextfield( |
| 43 views::Textfield* textfield) { |
| 44 return textfield->touch_selection_controller_.get(); |
| 45 } |
| 46 |
| 40 // Move the mouse to the center of the browser window and left-click. | 47 // Move the mouse to the center of the browser window and left-click. |
| 41 void ClickBrowserWindowCenter() { | 48 void ClickBrowserWindowCenter() { |
| 42 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( | 49 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( |
| 43 BrowserView::GetBrowserViewForBrowser( | 50 BrowserView::GetBrowserViewForBrowser( |
| 44 browser())->GetBoundsInScreen().CenterPoint())); | 51 browser())->GetBoundsInScreen().CenterPoint())); |
| 45 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, | 52 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, |
| 46 ui_controls::DOWN)); | 53 ui_controls::DOWN)); |
| 47 ASSERT_TRUE( | 54 ASSERT_TRUE( |
| 48 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP)); | 55 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP)); |
| 49 } | 56 } |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 289 |
| 283 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, BackgroundIsOpaque) { | 290 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, BackgroundIsOpaque) { |
| 284 // The omnibox text should be rendered on an opaque background. Otherwise, we | 291 // The omnibox text should be rendered on an opaque background. Otherwise, we |
| 285 // can't use subpixel rendering. | 292 // can't use subpixel rendering. |
| 286 BrowserWindowTesting* window = browser()->window()->GetBrowserWindowTesting(); | 293 BrowserWindowTesting* window = browser()->window()->GetBrowserWindowTesting(); |
| 287 ASSERT_TRUE(window); | 294 ASSERT_TRUE(window); |
| 288 OmniboxViewViews* view = window->GetLocationBarView()->omnibox_view(); | 295 OmniboxViewViews* view = window->GetLocationBarView()->omnibox_view(); |
| 289 ASSERT_TRUE(view); | 296 ASSERT_TRUE(view); |
| 290 EXPECT_FALSE(view->GetRenderText()->background_is_transparent()); | 297 EXPECT_FALSE(view->GetRenderText()->background_is_transparent()); |
| 291 } | 298 } |
| 299 |
| 300 // Tests if executing a command hides touch editing handles. |
| 301 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, |
| 302 DeactivateTouchEditingOnExecuteCommand) { |
| 303 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
| 304 |
| 305 OmniboxView* view = NULL; |
| 306 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &view)); |
| 307 OmniboxViewViews* omnibox_view_views = static_cast<OmniboxViewViews*>(view); |
| 308 |
| 309 // Put a URL on the clipboard. It is written to the clipboard upon destruction |
| 310 // of the writer. |
| 311 { |
| 312 ui::ScopedClipboardWriter clipboard_writer( |
| 313 ui::Clipboard::GetForCurrentThread(), |
| 314 ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 315 clipboard_writer.WriteURL(base::ASCIIToUTF16("http://www.example.com/")); |
| 316 } |
| 317 |
| 318 // Tap to activate touch editing. |
| 319 gfx::Point omnibox_center = |
| 320 omnibox_view_views->GetBoundsInScreen().CenterPoint(); |
| 321 Tap(omnibox_center, omnibox_center); |
| 322 EXPECT_TRUE(GetTouchSelectionControllerForTextfield(omnibox_view_views)); |
| 323 |
| 324 // Execute a command and check if it deactivate touch editing. Paste & Go is |
| 325 // chosen since it is specific to Omnibox and its execution wouldn't be |
| 326 // delgated to the base Textfield class. |
| 327 omnibox_view_views->ExecuteCommand(IDS_PASTE_AND_GO, ui::EF_NONE); |
| 328 EXPECT_FALSE(GetTouchSelectionControllerForTextfield(omnibox_view_views)); |
| 329 } |
| OLD | NEW |