Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1003)

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_view_browsertest.cc

Issue 10386173: ash: Select omnibox text on mouse up instead of down. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: only run tests for USE_AURA Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 18 matching lines...) Expand all
29 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
31 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
32 #include "chrome/test/base/in_process_browser_test.h" 32 #include "chrome/test/base/in_process_browser_test.h"
33 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
34 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
35 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
36 #include "net/base/mock_host_resolver.h" 36 #include "net/base/mock_host_resolver.h"
37 #include "ui/base/events.h" 37 #include "ui/base/events.h"
38 #include "ui/base/keycodes/keyboard_codes.h" 38 #include "ui/base/keycodes/keyboard_codes.h"
39 #include "ui/gfx/point.h"
39 40
40 #if defined(TOOLKIT_GTK) 41 #if defined(TOOLKIT_GTK)
41 #include <gdk/gdk.h> 42 #include <gdk/gdk.h>
42 #include <gtk/gtk.h> 43 #include <gtk/gtk.h>
43 #endif 44 #endif
44 45
45 #if defined(TOOLKIT_VIEWS) 46 #if defined(USE_AURA)
46 #include "ui/views/controls/textfield/native_textfield_views.h" 47 #include "chrome/browser/ui/views/frame/browser_view.h"
47 #include "ui/views/events/event.h"
48 #include "ui/views/widget/widget.h"
49 #endif 48 #endif
50 49
51 using base::Time; 50 using base::Time;
52 using base::TimeDelta; 51 using base::TimeDelta;
53 52
54 namespace { 53 namespace {
55 54
56 const char kSearchKeyword[] = "foo"; 55 const char kSearchKeyword[] = "foo";
57 const char kSearchKeyword2[] = "footest.com"; 56 const char kSearchKeyword2[] = "footest.com";
58 const wchar_t kSearchKeywordKeys[] = { 57 const wchar_t kSearchKeywordKeys[] = {
(...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 // Make sure inline autocomplete is triggerred. 1262 // Make sure inline autocomplete is triggerred.
1264 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); 1263 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1);
1265 1264
1266 // Press ctrl key. 1265 // Press ctrl key.
1267 omnibox_view->model()->OnControlKeyChanged(true); 1266 omnibox_view->model()->OnControlKeyChanged(true);
1268 1267
1269 // Inline autocomplete should still be there. 1268 // Inline autocomplete should still be there.
1270 EXPECT_EQ(old_text, omnibox_view->GetText()); 1269 EXPECT_EQ(old_text, omnibox_view->GetText());
1271 } 1270 }
1272 1271
1272 #if defined(USE_AURA)
1273 BrowserView* GetBrowserView() {
1274 return static_cast<BrowserView*>(browser()->window());
1275 }
1276
1277 views::View* GetFocusView() {
1278 return GetBrowserView()->GetViewByID(location_bar_focus_view_id_);
1279 }
1280
1281 // Move the mouse to the center of the browser window and left-click.
1282 void ClickBrowserWindowCenter() {
1283 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
1284 GetBrowserView()->GetScreenBounds().CenterPoint()));
1285 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
1286 ui_controls::LEFT, ui_controls::DOWN));
1287 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
1288 ui_controls::LEFT, ui_controls::UP));
1289 }
1290
1291 // Press and release the mouse in the focus view at an offset from its origin.
1292 // If |release_offset| differs from |press_offset|, the mouse will be moved
1293 // between the press and release.
1294 void ClickFocusViewOrigin(ui_controls::MouseButton button,
1295 const gfx::Point& press_offset,
1296 const gfx::Point& release_offset) {
1297 gfx::Point focus_view_origin = GetFocusView()->GetScreenBounds().origin();
1298 gfx::Point press_point = focus_view_origin;
1299 press_point.Offset(press_offset.x(), press_offset.y());
1300 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_point));
1301 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN));
1302
1303 gfx::Point release_point = focus_view_origin;
1304 release_point.Offset(release_offset.x(), release_offset.y());
1305 if (release_point != press_point)
1306 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_point));
1307 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP));
1308 }
1309 #endif // defined(USE_AURA)
1310
1273 private: 1311 private:
1274 ViewID location_bar_focus_view_id_; 1312 ViewID location_bar_focus_view_id_;
1275 }; 1313 };
1276 1314
1277 // Test if ctrl-* accelerators are workable in omnibox. 1315 // Test if ctrl-* accelerators are workable in omnibox.
1278 // See http://crbug.com/19193: omnibox blocks ctrl-* commands 1316 // See http://crbug.com/19193: omnibox blocks ctrl-* commands
1279 // 1317 //
1280 // Flaky on interactive tests (dbg), http://crbug.com/69433 1318 // Flaky on interactive tests (dbg), http://crbug.com/69433
1281 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) { 1319 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) {
1282 BrowserAcceleratorsTest(); 1320 BrowserAcceleratorsTest();
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 SetClipboardText(kSearchText); 1512 SetClipboardText(kSearchText);
1475 1513
1476 // Paste text. 1514 // Paste text.
1477 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); 1515 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN));
1478 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1516 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1479 ASSERT_TRUE(popup_model->IsOpen()); 1517 ASSERT_TRUE(popup_model->IsOpen());
1480 1518
1481 // Inline autocomplete shouldn't be triggered. 1519 // Inline autocomplete shouldn't be triggered.
1482 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); 1520 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText());
1483 } 1521 }
1484 #endif 1522 #endif // defined(TOOLKIT_GTK)
1523
1524 #if defined(USE_AURA)
Daniel Erat 2012/05/16 21:06:02 I'd prefer to run these for TOOLKIT_VIEWS, but I'm
oshima 2012/05/16 21:28:31 I think so. I have no idea why this doesn't work o
Peter Kasting 2012/05/16 21:42:25 Right, it uses a subclass of a native CRichEditCtr
1525 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, SelectAllOnClick) {
1526 OmniboxView* omnibox_view = NULL;
1527 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1528 omnibox_view->SetUserText(ASCIIToUTF16("http://www.google.com/"));
1529 const gfx::Point kClickOffset(2, 2);
1530
1531 // Take the focus away from the omnibox.
1532 ClickBrowserWindowCenter();
1533 EXPECT_FALSE(omnibox_view->IsSelectAll());
1534 EXPECT_FALSE(GetFocusView()->HasFocus());
1535
1536 // Click in the omnibox. All of its text should be selected.
1537 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset);
sky 2012/05/16 21:39:56 You should wrap functions you call that ASSERT wit
Daniel Erat 2012/05/16 22:03:10 Done.
1538 EXPECT_TRUE(omnibox_view->IsSelectAll());
1539 EXPECT_TRUE(GetFocusView()->HasFocus());
1540
1541 // Ensure that all of the text is selected and then take the focus away. The
1542 // selection should persist.
1543 omnibox_view->SelectAll(false);
1544 EXPECT_TRUE(omnibox_view->IsSelectAll());
1545 ClickBrowserWindowCenter();
1546 EXPECT_TRUE(omnibox_view->IsSelectAll());
1547 EXPECT_FALSE(GetFocusView()->HasFocus());
1548
1549 // Clicking in the omnibox while some of its text is already selected should
1550 // have the effect of unselecting the text, rather than re-selecting all of
1551 // it.
1552 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset);
1553 EXPECT_FALSE(omnibox_view->IsSelectAll());
Peter Kasting 2012/05/16 21:42:25 This seems wrong. If we create a selection or som
Daniel Erat 2012/05/16 22:03:10 Done.
1554 EXPECT_TRUE(GetFocusView()->HasFocus());
1555
1556 // Take the focus away and click in the omnibox again, but drag a bit before
1557 // releasing. We should focus the omnibox but not select all of its text.
1558 ClickBrowserWindowCenter();
1559 const gfx::Point kReleaseOffset(kClickOffset.x() + 10, kClickOffset.y());
1560 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kReleaseOffset);
1561 EXPECT_FALSE(omnibox_view->IsSelectAll());
1562 EXPECT_TRUE(GetFocusView()->HasFocus());
1563
1564 // Middle-clicking shouldn't select all the text either.
1565 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset);
1566 ClickBrowserWindowCenter();
1567 ClickFocusViewOrigin(ui_controls::MIDDLE, kClickOffset, kClickOffset);
1568 EXPECT_FALSE(omnibox_view->IsSelectAll());
1569 }
1570 #endif // defined(USE_AURA)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698