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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 | 142 |
143 // Clicking in the omnibox should take focus and select all text. | 143 // Clicking in the omnibox should take focus and select all text. |
144 const gfx::Rect omnibox_bounds = BrowserView::GetBrowserViewForBrowser( | 144 const gfx::Rect omnibox_bounds = BrowserView::GetBrowserViewForBrowser( |
145 browser())->GetViewByID(VIEW_ID_OMNIBOX)->GetBoundsInScreen(); | 145 browser())->GetViewByID(VIEW_ID_OMNIBOX)->GetBoundsInScreen(); |
146 const gfx::Point click_location = omnibox_bounds.CenterPoint(); | 146 const gfx::Point click_location = omnibox_bounds.CenterPoint(); |
147 ASSERT_NO_FATAL_FAILURE(Click(ui_controls::LEFT, | 147 ASSERT_NO_FATAL_FAILURE(Click(ui_controls::LEFT, |
148 click_location, click_location)); | 148 click_location, click_location)); |
149 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 149 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
150 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 150 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
151 | 151 |
152 // Clicking in another view should clear focus and the selection. | 152 // Clicking in another view should clear focus. |
153 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | 153 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); |
154 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 154 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
155 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
156 | 155 |
157 // Clicking in the omnibox again should take focus and select all text again. | 156 // Clicking in the omnibox again should take focus and select all text again. |
158 ASSERT_NO_FATAL_FAILURE(Click(ui_controls::LEFT, | 157 ASSERT_NO_FATAL_FAILURE(Click(ui_controls::LEFT, |
159 click_location, click_location)); | 158 click_location, click_location)); |
160 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 159 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
161 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 160 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
162 | 161 |
163 // Clicking another omnibox spot should keep focus but clear the selection. | 162 // Clicking another omnibox spot should keep focus but clear the selection. |
164 omnibox_view->SelectAll(false); | 163 omnibox_view->SelectAll(false); |
165 const gfx::Point click2_location = omnibox_bounds.origin() + | 164 const gfx::Point click2_location = omnibox_bounds.origin() + |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 #endif // OS_LINUX && !OS_CHROMEOS | 237 #endif // OS_LINUX && !OS_CHROMEOS |
239 | 238 |
240 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnTap) { | 239 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnTap) { |
241 OmniboxView* omnibox_view = NULL; | 240 OmniboxView* omnibox_view = NULL; |
242 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); | 241 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); |
243 omnibox_view->SetUserText(base::ASCIIToUTF16("http://www.google.com/")); | 242 omnibox_view->SetUserText(base::ASCIIToUTF16("http://www.google.com/")); |
244 | 243 |
245 // Take the focus away from the omnibox. | 244 // Take the focus away from the omnibox. |
246 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); | 245 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); |
247 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 246 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
248 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
249 | 247 |
250 // Tapping in the omnibox should take focus and select all text. | 248 // Tapping in the omnibox should take focus and select all text. |
251 const gfx::Rect omnibox_bounds = BrowserView::GetBrowserViewForBrowser( | 249 const gfx::Rect omnibox_bounds = BrowserView::GetBrowserViewForBrowser( |
252 browser())->GetViewByID(VIEW_ID_OMNIBOX)->GetBoundsInScreen(); | 250 browser())->GetViewByID(VIEW_ID_OMNIBOX)->GetBoundsInScreen(); |
253 const gfx::Point tap_location = omnibox_bounds.CenterPoint(); | 251 const gfx::Point tap_location = omnibox_bounds.CenterPoint(); |
254 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap_location)); | 252 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap_location)); |
255 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 253 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
256 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 254 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
257 | 255 |
258 // Tapping in another view should clear focus and the selection. | 256 // Tapping in another view should clear focus. |
259 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); | 257 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); |
260 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 258 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
261 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
262 | 259 |
263 // Tapping in the omnibox again should take focus and select all text again. | 260 // Tapping in the omnibox again should take focus and select all text again. |
264 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap_location)); | 261 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap_location)); |
265 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 262 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
266 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 263 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
267 | 264 |
268 // Tapping another omnibox spot should keep focus and selection. | 265 // Tapping another omnibox spot should keep focus and selection. |
269 omnibox_view->SelectAll(false); | 266 omnibox_view->SelectAll(false); |
270 const gfx::Point tap2_location = omnibox_bounds.origin() + | 267 const gfx::Point tap2_location = omnibox_bounds.origin() + |
271 gfx::Vector2d(omnibox_bounds.width() / 4, omnibox_bounds.height() / 4); | 268 gfx::Vector2d(omnibox_bounds.width() / 4, omnibox_bounds.height() / 4); |
272 ASSERT_NO_FATAL_FAILURE(Tap(tap2_location, tap2_location)); | 269 ASSERT_NO_FATAL_FAILURE(Tap(tap2_location, tap2_location)); |
273 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 270 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
274 // We don't test if the all text is selected because it depends on whether or | 271 // We don't test if the all text is selected because it depends on whether or |
275 // not there was text under the tap, which appears to be flaky. | 272 // not there was text under the tap, which appears to be flaky. |
276 | 273 |
277 // Take the focus away and tap in the omnibox again, but drag a bit before | 274 // Take the focus away and tap in the omnibox again, but drag a bit before |
278 // releasing. We should focus the omnibox but not select all of its text. | 275 // releasing. We should focus the omnibox. |
Peter Kasting
2017/05/18 18:27:19
It seems like we should still ensure we don't focu
Matt Giuca
2017/05/19 05:55:32
True, this should still be false. (I kind of guess
| |
279 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); | 276 ASSERT_NO_FATAL_FAILURE(TapBrowserWindowCenter()); |
280 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap2_location)); | 277 ASSERT_NO_FATAL_FAILURE(Tap(tap_location, tap2_location)); |
281 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 278 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
282 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
283 } | 279 } |
284 | 280 |
285 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnTabToFocus) { | 281 IN_PROC_BROWSER_TEST_F(OmniboxViewViewsTest, SelectAllOnTabToFocus) { |
286 OmniboxView* omnibox_view = NULL; | 282 OmniboxView* omnibox_view = NULL; |
287 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); | 283 ASSERT_NO_FATAL_FAILURE(GetOmniboxViewForBrowser(browser(), &omnibox_view)); |
288 ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com/")); | 284 ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com/")); |
289 // RevertAll after navigation to invalidate the selection range saved on blur. | 285 // RevertAll after navigation to invalidate the selection range saved on blur. |
290 omnibox_view->RevertAll(); | 286 omnibox_view->RevertAll(); |
291 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 287 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
292 EXPECT_FALSE(omnibox_view->IsSelectAll()); | 288 EXPECT_FALSE(omnibox_view->IsSelectAll()); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 OmniboxViewViews* omnibox_view_views = static_cast<OmniboxViewViews*>(view); | 449 OmniboxViewViews* omnibox_view_views = static_cast<OmniboxViewViews*>(view); |
454 | 450 |
455 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | 451 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); |
456 EXPECT_EQ(omnibox_view_views->GetRenderText()->elide_behavior(), | 452 EXPECT_EQ(omnibox_view_views->GetRenderText()->elide_behavior(), |
457 gfx::ELIDE_TAIL); | 453 gfx::ELIDE_TAIL); |
458 | 454 |
459 chrome::FocusLocationBar(browser()); | 455 chrome::FocusLocationBar(browser()); |
460 EXPECT_EQ(omnibox_view_views->GetRenderText()->elide_behavior(), | 456 EXPECT_EQ(omnibox_view_views->GetRenderText()->elide_behavior(), |
461 gfx::NO_ELIDE); | 457 gfx::NO_ELIDE); |
462 } | 458 } |
OLD | NEW |