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/browser/ui/views/omnibox/omnibox_views.h" | 14 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "chrome/test/base/interactive_test_utils.h" | 16 #include "chrome/test/base/interactive_test_utils.h" |
17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
18 #include "ui/aura/root_window.h" | |
Peter Kasting
2013/11/04 21:23:07
Don't we need to guard Aura-specific includes and
tdresser
2013/11/05 15:28:00
Done. Are you aware of any bots which build views
Peter Kasting
2013/11/05 19:54:07
We've switched the bots over to not doing this, bu
| |
19 #include "ui/aura/root_window_host_delegate.h" | |
20 #include "ui/aura/window.h" | |
18 #include "ui/base/clipboard/clipboard.h" | 21 #include "ui/base/clipboard/clipboard.h" |
19 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 22 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
20 #include "ui/base/test/ui_controls.h" | 23 #include "ui/base/test/ui_controls.h" |
21 #include "ui/views/controls/textfield/native_textfield_wrapper.h" | 24 #include "ui/views/controls/textfield/native_textfield_wrapper.h" |
22 | 25 |
23 class OmniboxViewViewsTest : public InProcessBrowserTest { | 26 class OmniboxViewViewsTest : public InProcessBrowserTest { |
24 protected: | 27 protected: |
25 OmniboxViewViewsTest() {} | 28 OmniboxViewViewsTest() {} |
26 | 29 |
27 static void GetOmniboxViewForBrowser(const Browser* browser, | 30 static void GetOmniboxViewForBrowser(const Browser* browser, |
(...skipping 10 matching lines...) Expand all Loading... | |
38 void ClickBrowserWindowCenter() { | 41 void ClickBrowserWindowCenter() { |
39 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( | 42 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( |
40 BrowserView::GetBrowserViewForBrowser( | 43 BrowserView::GetBrowserViewForBrowser( |
41 browser())->GetBoundsInScreen().CenterPoint())); | 44 browser())->GetBoundsInScreen().CenterPoint())); |
42 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, | 45 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, |
43 ui_controls::DOWN)); | 46 ui_controls::DOWN)); |
44 ASSERT_TRUE( | 47 ASSERT_TRUE( |
45 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP)); | 48 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP)); |
46 } | 49 } |
47 | 50 |
51 // Tap the center of the browser window. | |
52 void TapBrowserWindowCenter() { | |
53 gfx::Point center = BrowserView::GetBrowserViewForBrowser( | |
54 browser())->GetBoundsInScreen().CenterPoint(); | |
55 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, center, | |
56 5, base::TimeDelta::FromMilliseconds(0)); | |
57 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, center, | |
58 5, base::TimeDelta::FromMilliseconds(50)); | |
59 | |
60 rwhd_->OnHostTouchEvent(&press); | |
Peter Kasting
2013/11/04 21:23:07
Tiny nit: It may make slightly more sense to inter
tdresser
2013/11/05 15:28:00
Done.
| |
61 rwhd_->OnHostTouchEvent(&release); | |
62 } | |
63 | |
48 // Press and release the mouse in the omnibox at an offset from its origin. | 64 // Press and release the mouse in the omnibox at an offset from its origin. |
49 // If |release_offset| differs from |press_offset|, the mouse will be moved | 65 // If |release_offset| differs from |press_offset|, the mouse will be moved |
50 // between the press and release. | 66 // between the press and release. |
51 void ClickOmnibox(ui_controls::MouseButton button, | 67 void ClickOmnibox(ui_controls::MouseButton button, |
52 const gfx::Vector2d& press_offset, | 68 const gfx::Vector2d& press_offset, |
53 const gfx::Vector2d& release_offset) { | 69 const gfx::Vector2d& release_offset) { |
54 const views::View* omnibox = BrowserView::GetBrowserViewForBrowser( | 70 const views::View* omnibox = BrowserView::GetBrowserViewForBrowser( |
55 browser())->GetViewByID(VIEW_ID_OMNIBOX); | 71 browser())->GetViewByID(VIEW_ID_OMNIBOX); |
56 gfx::Point omnibox_origin = omnibox->GetBoundsInScreen().origin(); | 72 gfx::Point omnibox_origin = omnibox->GetBoundsInScreen().origin(); |
57 gfx::Point press_point = omnibox_origin + press_offset; | 73 gfx::Point press_point = omnibox_origin + press_offset; |
58 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_point)); | 74 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_point)); |
59 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN)); | 75 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN)); |
60 | 76 |
61 gfx::Point release_point = omnibox_origin + release_offset; | 77 gfx::Point release_point = omnibox_origin + release_offset; |
62 if (release_point != press_point) | 78 if (release_point != press_point) |
63 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_point)); | 79 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_point)); |
64 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP)); | 80 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP)); |
65 } | 81 } |
66 | 82 |
83 void TapOmnibox(const gfx::Vector2d& press_offset, | |
84 const gfx::Vector2d& release_offset) { | |
85 const views::View* omnibox = BrowserView::GetBrowserViewForBrowser( | |
86 browser())->GetViewByID(VIEW_ID_OMNIBOX); | |
87 gfx::Point omnibox_origin = omnibox->GetBoundsInScreen().origin(); | |
88 gfx::Point press_point = omnibox_origin + press_offset; | |
Peter Kasting
2013/11/04 21:23:07
Nit: I'd probably inline these two temps into the
tdresser
2013/11/05 15:28:00
Done.
| |
89 gfx::Point release_point = omnibox_origin + release_offset; | |
90 | |
91 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, press_point, | |
92 5, base::TimeDelta::FromMilliseconds(0)); | |
93 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, release_point, | |
94 5, base::TimeDelta::FromMilliseconds(50)); | |
95 | |
96 rwhd_->OnHostTouchEvent(&press); | |
97 rwhd_->OnHostTouchEvent(&release); | |
98 } | |
99 | |
67 private: | 100 private: |
68 // InProcessBrowserTest: | 101 // InProcessBrowserTest: |
69 virtual void SetUpOnMainThread() OVERRIDE { | 102 virtual void SetUpOnMainThread() OVERRIDE { |
103 rwhd_ = browser()->window()->GetNativeWindow()->GetRootWindow()-> | |
104 GetDispatcher()->AsRootWindowHostDelegate(); | |
105 | |
70 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 106 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
71 chrome::FocusLocationBar(browser()); | 107 chrome::FocusLocationBar(browser()); |
72 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 108 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
73 } | 109 } |
74 | 110 |
111 aura::RootWindowHostDelegate* rwhd_; | |
Peter Kasting
2013/11/04 21:23:07
Nit: Does this need to be a member? Can't we just
tdresser
2013/11/05 15:28:00
Done.
| |
112 | |
75 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViewsTest); | 113 DISALLOW_COPY_AND_ASSIGN(OmniboxViewViewsTest); |
76 }; | 114 }; |
77 | 115 |
78 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, PasteAndGoDoesNotLeavePopupOpen) { | 116 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, PasteAndGoDoesNotLeavePopupOpen) { |
79 OmniboxView* view = browser()->window()->GetLocationBar()->GetLocationEntry(); | 117 OmniboxView* view = browser()->window()->GetLocationBar()->GetLocationEntry(); |
80 OmniboxViewViews* omnibox_view_views = GetOmniboxViewViews(view); | 118 OmniboxViewViews* omnibox_view_views = GetOmniboxViewViews(view); |
81 // This test is only relevant when OmniboxViewViews is present and is using | 119 // This test is only relevant when OmniboxViewViews is present and is using |
82 // the native textfield wrapper. | 120 // the native textfield wrapper. |
83 if (!omnibox_view_views) | 121 if (!omnibox_view_views) |
84 return; | 122 return; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, release)); | 180 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, release)); |
143 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 181 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
144 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 182 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
145 | 183 |
146 // Middle-clicking should not be handled by the omnibox. | 184 // Middle-clicking should not be handled by the omnibox. |
147 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | 185 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); |
148 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::MIDDLE, click, click)); | 186 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::MIDDLE, click, click)); |
149 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 187 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
150 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 188 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
151 } | 189 } |
190 | |
191 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnTap) { | |
192 OmniboxView* omnibox_view = NULL; | |
193 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); | |
194 omnibox_view->SetUserText(ASCIIToUTF16("http://www.google.com/")); | |
195 const gfx::Vector2d tap(40, 10); | |
Peter Kasting
2013/11/04 21:23:07
Could this offset be outside the omnibox in a futu
tdresser
2013/11/05 15:28:00
Done. I changed this in the click test as well.
| |
196 | |
197 // Take the focus away from the omnibox. | |
198 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); | |
199 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
200 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
201 | |
202 // Tapping in the omnibox should take focus and select all text. | |
203 ASSERT_NO_FATAL_FAILURE(TapOmnibox(tap, tap)); | |
204 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
205 EXPECT_TRUE(omnibox_view->IsSelectAll()); | |
206 | |
207 // Tapping in another view should clear focus and the selection. | |
208 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); | |
209 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
210 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
211 | |
212 // Tapping in the omnibox again should take focus and select all text again. | |
213 ASSERT_NO_FATAL_FAILURE(TapOmnibox(tap, tap)); | |
214 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
215 EXPECT_TRUE(omnibox_view->IsSelectAll()); | |
216 | |
217 // Tapping another omnibox spot should keep focus and selection. | |
218 omnibox_view->SelectAll(false); | |
219 const gfx::Vector2d tap_2(tap.x() + 10, tap.y()); | |
220 ASSERT_NO_FATAL_FAILURE(TapOmnibox(tap_2, tap_2)); | |
221 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
222 EXPECT_TRUE(omnibox_view->IsSelectAll()); | |
223 | |
224 // Take the focus away and tap in the omnibox again, but drag a bit before | |
225 // releasing. We should focus the omnibox but not select all of its text. | |
226 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); | |
227 const gfx::Vector2d release(tap.x() + 50, tap.y()); | |
228 ASSERT_NO_FATAL_FAILURE(TapOmnibox(tap, release)); | |
229 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
230 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
231 } | |
OLD | NEW |