| 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 "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
| 9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/omnibox/location_bar.h" | 10 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 11 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 11 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 12 #include "chrome/browser/ui/view_ids.h" | 12 #include "chrome/browser/ui/view_ids.h" |
| 13 #include "chrome/browser/ui/views/frame/browser_view.h" | 13 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/interactive_test_utils.h" | 15 #include "chrome/test/base/interactive_test_utils.h" |
| 16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 17 #include "ui/base/clipboard/clipboard.h" | 17 #include "ui/base/clipboard/clipboard.h" |
| 18 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 18 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 19 #include "ui/base/test/ui_controls.h" | 19 #include "ui/base/test/ui_controls.h" |
| 20 | 20 |
| 21 #if defined(USE_AURA) | 21 #if defined(USE_AURA) |
| 22 #include "ui/aura/root_window.h" | 22 #include "ui/aura/root_window.h" |
| 23 #include "ui/aura/test/event_generator.h" |
| 23 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
| 24 #include "ui/aura/window_tree_host_delegate.h" | 25 #include "ui/aura/window_tree_host_delegate.h" |
| 25 #endif // defined(USE_AURA) | 26 #endif // defined(USE_AURA) |
| 26 | 27 |
| 27 class OmniboxViewViewsTest : public InProcessBrowserTest { | 28 class OmniboxViewViewsTest : public InProcessBrowserTest { |
| 28 protected: | 29 protected: |
| 29 OmniboxViewViewsTest() {} | 30 OmniboxViewViewsTest() {} |
| 30 | 31 |
| 31 static void GetOmniboxViewForBrowser(const Browser* browser, | 32 static void GetOmniboxViewForBrowser(const Browser* browser, |
| 32 OmniboxView** omnibox_view) { | 33 OmniboxView** omnibox_view) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 59 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN)); | 60 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN)); |
| 60 | 61 |
| 61 if (press_location != release_location) | 62 if (press_location != release_location) |
| 62 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_location)); | 63 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_location)); |
| 63 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP)); | 64 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP)); |
| 64 } | 65 } |
| 65 | 66 |
| 66 #if defined(USE_AURA) | 67 #if defined(USE_AURA) |
| 67 // Tap the center of the browser window. | 68 // Tap the center of the browser window. |
| 68 void TapBrowserWindowCenter() { | 69 void TapBrowserWindowCenter() { |
| 69 aura::WindowTreeHostDelegate* rwhd = | |
| 70 browser()->window()->GetNativeWindow()->GetRootWindow()-> | |
| 71 GetDispatcher()->AsWindowTreeHostDelegate(); | |
| 72 | |
| 73 gfx::Point center = BrowserView::GetBrowserViewForBrowser( | 70 gfx::Point center = BrowserView::GetBrowserViewForBrowser( |
| 74 browser())->GetBoundsInScreen().CenterPoint(); | 71 browser())->GetBoundsInScreen().CenterPoint(); |
| 75 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center, | 72 aura::test::EventGenerator generator(browser()->window()-> |
| 76 5, base::TimeDelta::FromMilliseconds(0)); | 73 GetNativeWindow()->GetRootWindow()); |
| 77 rwhd->OnHostTouchEvent(&press); | 74 generator.GestureTapAt(center); |
| 78 | |
| 79 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, center, | |
| 80 5, base::TimeDelta::FromMilliseconds(50)); | |
| 81 rwhd->OnHostTouchEvent(&release); | |
| 82 } | 75 } |
| 83 | 76 |
| 84 // Touch down and release at the specified locations. | 77 // Touch down and release at the specified locations. |
| 85 void Tap(const gfx::Point& press_location, | 78 void Tap(const gfx::Point& press_location, |
| 86 const gfx::Point& release_location) { | 79 const gfx::Point& release_location) { |
| 87 aura::WindowTreeHostDelegate* rwhd = | 80 aura::WindowEventDispatcher* dispatcher = |
| 88 browser()->window()->GetNativeWindow()->GetRootWindow()-> | 81 browser()->window()->GetNativeWindow()->GetDispatcher(); |
| 89 GetDispatcher()->AsWindowTreeHostDelegate(); | |
| 90 | 82 |
| 91 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, press_location, | 83 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, press_location, |
| 92 5, base::TimeDelta::FromMilliseconds(0)); | 84 5, base::TimeDelta::FromMilliseconds(0)); |
| 93 rwhd->OnHostTouchEvent(&press); | 85 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); |
| 86 ASSERT_FALSE(details.dispatcher_destroyed); |
| 94 | 87 |
| 95 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, release_location, | 88 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, release_location, |
| 96 5, base::TimeDelta::FromMilliseconds(50)); | 89 5, base::TimeDelta::FromMilliseconds(50)); |
| 97 rwhd->OnHostTouchEvent(&release); | 90 details = dispatcher->OnEventFromSource(&release); |
| 91 ASSERT_FALSE(details.dispatcher_destroyed); |
| 98 } | 92 } |
| 99 #endif // defined(USE_AURA) | 93 #endif // defined(USE_AURA) |
| 100 | 94 |
| 101 private: | 95 private: |
| 102 // InProcessBrowserTest: | 96 // InProcessBrowserTest: |
| 103 virtual void SetUpOnMainThread() OVERRIDE { | 97 virtual void SetUpOnMainThread() OVERRIDE { |
| 104 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 98 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 105 chrome::FocusLocationBar(browser()); | 99 chrome::FocusLocationBar(browser()); |
| 106 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 100 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 107 } | 101 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 // not there was text under the tap, which appears to be flaky. | 215 // not there was text under the tap, which appears to be flaky. |
| 222 | 216 |
| 223 // Take the focus away and tap in the omnibox again, but drag a bit before | 217 // Take the focus away and tap in the omnibox again, but drag a bit before |
| 224 // releasing. We should focus the omnibox but not select all of its text. | 218 // releasing. We should focus the omnibox but not select all of its text. |
| 225 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); | 219 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); |
| 226 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap2_location)); | 220 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap2_location)); |
| 227 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 221 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 228 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 222 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 229 } | 223 } |
| 230 #endif // defined(USE_AURA) | 224 #endif // defined(USE_AURA) |
| OLD | NEW |