| 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/aura/test/event_generator.h" |
| 18 #include "ui/aura/window.h" |
| 19 #include "ui/aura/window_tree_host.h" |
| 17 #include "ui/base/clipboard/clipboard.h" | 20 #include "ui/base/clipboard/clipboard.h" |
| 18 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 21 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 19 #include "ui/base/test/ui_controls.h" | 22 #include "ui/base/test/ui_controls.h" |
| 20 | |
| 21 #if defined(USE_AURA) | |
| 22 #include "ui/aura/test/event_generator.h" | |
| 23 #include "ui/aura/window.h" | |
| 24 #include "ui/aura/window_tree_host.h" | |
| 25 #include "ui/events/event_processor.h" | 23 #include "ui/events/event_processor.h" |
| 26 #endif // defined(USE_AURA) | |
| 27 | 24 |
| 28 class OmniboxViewViewsTest : public InProcessBrowserTest { | 25 class OmniboxViewViewsTest : public InProcessBrowserTest { |
| 29 protected: | 26 protected: |
| 30 OmniboxViewViewsTest() {} | 27 OmniboxViewViewsTest() {} |
| 31 | 28 |
| 32 static void GetOmniboxViewForBrowser(const Browser* browser, | 29 static void GetOmniboxViewForBrowser(const Browser* browser, |
| 33 OmniboxView** omnibox_view) { | 30 OmniboxView** omnibox_view) { |
| 34 BrowserWindow* window = browser->window(); | 31 BrowserWindow* window = browser->window(); |
| 35 ASSERT_TRUE(window); | 32 ASSERT_TRUE(window); |
| 36 LocationBar* location_bar = window->GetLocationBar(); | 33 LocationBar* location_bar = window->GetLocationBar(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 57 const gfx::Point& press_location, | 54 const gfx::Point& press_location, |
| 58 const gfx::Point& release_location) { | 55 const gfx::Point& release_location) { |
| 59 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_location)); | 56 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_location)); |
| 60 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN)); | 57 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN)); |
| 61 | 58 |
| 62 if (press_location != release_location) | 59 if (press_location != release_location) |
| 63 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_location)); | 60 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_location)); |
| 64 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP)); | 61 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP)); |
| 65 } | 62 } |
| 66 | 63 |
| 67 #if defined(USE_AURA) | |
| 68 // Tap the center of the browser window. | 64 // Tap the center of the browser window. |
| 69 void TapBrowserWindowCenter() { | 65 void TapBrowserWindowCenter() { |
| 70 gfx::Point center = BrowserView::GetBrowserViewForBrowser( | 66 gfx::Point center = BrowserView::GetBrowserViewForBrowser( |
| 71 browser())->GetBoundsInScreen().CenterPoint(); | 67 browser())->GetBoundsInScreen().CenterPoint(); |
| 72 aura::test::EventGenerator generator(browser()->window()-> | 68 aura::test::EventGenerator generator(browser()->window()-> |
| 73 GetNativeWindow()->GetRootWindow()); | 69 GetNativeWindow()->GetRootWindow()); |
| 74 generator.GestureTapAt(center); | 70 generator.GestureTapAt(center); |
| 75 } | 71 } |
| 76 | 72 |
| 77 // Touch down and release at the specified locations. | 73 // Touch down and release at the specified locations. |
| 78 void Tap(const gfx::Point& press_location, | 74 void Tap(const gfx::Point& press_location, |
| 79 const gfx::Point& release_location) { | 75 const gfx::Point& release_location) { |
| 80 ui::EventProcessor* dispatcher = | 76 ui::EventProcessor* dispatcher = |
| 81 browser()->window()->GetNativeWindow()->GetHost()->event_processor(); | 77 browser()->window()->GetNativeWindow()->GetHost()->event_processor(); |
| 82 | 78 |
| 83 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, press_location, | 79 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, press_location, |
| 84 5, base::TimeDelta::FromMilliseconds(0)); | 80 5, base::TimeDelta::FromMilliseconds(0)); |
| 85 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); | 81 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press); |
| 86 ASSERT_FALSE(details.dispatcher_destroyed); | 82 ASSERT_FALSE(details.dispatcher_destroyed); |
| 87 | 83 |
| 88 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, release_location, | 84 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, release_location, |
| 89 5, base::TimeDelta::FromMilliseconds(50)); | 85 5, base::TimeDelta::FromMilliseconds(50)); |
| 90 details = dispatcher->OnEventFromSource(&release); | 86 details = dispatcher->OnEventFromSource(&release); |
| 91 ASSERT_FALSE(details.dispatcher_destroyed); | 87 ASSERT_FALSE(details.dispatcher_destroyed); |
| 92 } | 88 } |
| 93 #endif // defined(USE_AURA) | |
| 94 | 89 |
| 95 private: | 90 private: |
| 96 // InProcessBrowserTest: | 91 // InProcessBrowserTest: |
| 97 virtual void SetUpOnMainThread() OVERRIDE { | 92 virtual void SetUpOnMainThread() OVERRIDE { |
| 98 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 93 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 99 chrome::FocusLocationBar(browser()); | 94 chrome::FocusLocationBar(browser()); |
| 100 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 95 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 101 } | 96 } |
| 102 | 97 |
| 103 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViewsTest); | 98 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViewsTest); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 164 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 170 | 165 |
| 171 // Middle-clicking should not be handled by the omnibox. | 166 // Middle-clicking should not be handled by the omnibox. |
| 172 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | 167 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); |
| 173 ASSERT_NO_FATAL_FAILURE(Click(ui_controls::MIDDLE, | 168 ASSERT_NO_FATAL_FAILURE(Click(ui_controls::MIDDLE, |
| 174 click_location, click_location)); | 169 click_location, click_location)); |
| 175 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 170 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 176 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 171 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 177 } | 172 } |
| 178 | 173 |
| 179 #if defined(USE_AURA) | |
| 180 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnTap) { | 174 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnTap) { |
| 181 OmniboxView* omnibox_view = NULL; | 175 OmniboxView* omnibox_view = NULL; |
| 182 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); | 176 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); |
| 183 omnibox_view->SetUserText(base::ASCIIToUTF16("http://www.google.com/")); | 177 omnibox_view->SetUserText(base::ASCIIToUTF16("http://www.google.com/")); |
| 184 | 178 |
| 185 // Take the focus away from the omnibox. | 179 // Take the focus away from the omnibox. |
| 186 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); | 180 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); |
| 187 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 181 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 188 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 182 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 189 | 183 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 214 // We don't test if the all text is selected because it depends on whether or | 208 // We don't test if the all text is selected because it depends on whether or |
| 215 // not there was text under the tap, which appears to be flaky. | 209 // not there was text under the tap, which appears to be flaky. |
| 216 | 210 |
| 217 // Take the focus away and tap in the omnibox again, but drag a bit before | 211 // Take the focus away and tap in the omnibox again, but drag a bit before |
| 218 // releasing. We should focus the omnibox but not select all of its text. | 212 // releasing. We should focus the omnibox but not select all of its text. |
| 219 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); | 213 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); |
| 220 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap2_location)); | 214 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap2_location)); |
| 221 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 215 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 222 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 216 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 223 } | 217 } |
| 224 #endif // defined(USE_AURA) | |
| 225 | 218 |
| 226 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnTabToFocus) { | 219 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnTabToFocus) { |
| 227 OmniboxView* omnibox_view = NULL; | 220 OmniboxView* omnibox_view = NULL; |
| 228 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); | 221 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); |
| 229 ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com/")); | 222 ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com/")); |
| 230 // RevertAll after navigation to invalidate the selection range saved on blur. | 223 // RevertAll after navigation to invalidate the selection range saved on blur. |
| 231 omnibox_view->RevertAll(); | 224 omnibox_view->RevertAll(); |
| 232 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 225 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 233 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 226 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
| 234 | 227 |
| 235 // Pressing tab to focus the omnibox should select all text. | 228 // Pressing tab to focus the omnibox should select all text. |
| 236 while (!ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)) { | 229 while (!ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)) { |
| 237 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, | 230 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, |
| 238 false, false, false, false)); | 231 false, false, false, false)); |
| 239 } | 232 } |
| 240 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 233 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
| 241 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 234 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
| 242 } | 235 } |
| OLD | NEW |