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

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

Issue 13896002: Tweak Views Omnibox/Textfield; re-enable OmniboxViewTest.SelectAllOnClick. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix click location; enable for TOOLKIT_VIEWS; fix Views Textfields middle/right-click. Created 7 years, 8 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
« no previous file with comments | « no previous file | ui/views/controls/textfield/native_textfield_views.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 30 matching lines...) Expand all
41 #include "ui/base/clipboard/clipboard.h" 41 #include "ui/base/clipboard/clipboard.h"
42 #include "ui/base/events/event_constants.h" 42 #include "ui/base/events/event_constants.h"
43 #include "ui/base/keycodes/keyboard_codes.h" 43 #include "ui/base/keycodes/keyboard_codes.h"
44 #include "ui/gfx/point.h" 44 #include "ui/gfx/point.h"
45 45
46 #if defined(TOOLKIT_GTK) 46 #if defined(TOOLKIT_GTK)
47 #include <gdk/gdk.h> 47 #include <gdk/gdk.h>
48 #include <gtk/gtk.h> 48 #include <gtk/gtk.h>
49 #endif 49 #endif
50 50
51 #if defined(USE_AURA) 51 #if defined(TOOLKIT_VIEWS)
52 #include "chrome/browser/ui/views/frame/browser_view.h" 52 #include "chrome/browser/ui/views/frame/browser_view.h"
53 #endif 53 #endif
54 54
55 #if defined(OS_MACOSX) 55 #if defined(OS_MACOSX)
56 #include "base/mac/scoped_nsautorelease_pool.h" 56 #include "base/mac/scoped_nsautorelease_pool.h"
57 #endif 57 #endif
58 58
59 using base::Time; 59 using base::Time;
60 using base::TimeDelta; 60 using base::TimeDelta;
61 61
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 // Make sure inline autocomplete is triggerred. 1257 // Make sure inline autocomplete is triggerred.
1258 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); 1258 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1);
1259 1259
1260 // Press ctrl key. 1260 // Press ctrl key.
1261 omnibox_view->model()->OnControlKeyChanged(true); 1261 omnibox_view->model()->OnControlKeyChanged(true);
1262 1262
1263 // Inline autocomplete should still be there. 1263 // Inline autocomplete should still be there.
1264 EXPECT_EQ(old_text, omnibox_view->GetText()); 1264 EXPECT_EQ(old_text, omnibox_view->GetText());
1265 } 1265 }
1266 1266
1267 #if defined(USE_AURA) 1267 #if defined(TOOLKIT_VIEWS)
1268 const BrowserView* GetBrowserView() const { 1268 const BrowserView* GetBrowserView() const {
1269 return static_cast<BrowserView*>(browser()->window()); 1269 return BrowserView::GetBrowserViewForBrowser(browser());
1270 }
1271
1272 const views::View* GetFocusView() const {
1273 return GetBrowserView()->GetViewByID(VIEW_ID_OMNIBOX);
1274 } 1270 }
1275 1271
1276 // Move the mouse to the center of the browser window and left-click. 1272 // Move the mouse to the center of the browser window and left-click.
1277 void ClickBrowserWindowCenter() { 1273 void ClickBrowserWindowCenter() {
1278 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( 1274 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
1279 GetBrowserView()->GetBoundsInScreen().CenterPoint())); 1275 GetBrowserView()->GetBoundsInScreen().CenterPoint()));
1280 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 1276 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
1281 ui_controls::LEFT, ui_controls::DOWN)); 1277 ui_controls::LEFT, ui_controls::DOWN));
1282 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( 1278 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
1283 ui_controls::LEFT, ui_controls::UP)); 1279 ui_controls::LEFT, ui_controls::UP));
1284 } 1280 }
1285 1281
1286 // Press and release the mouse in the focus view at an offset from its origin. 1282 // Press and release the mouse in the omnibox at an offset from its origin.
1287 // If |release_offset| differs from |press_offset|, the mouse will be moved 1283 // If |release_offset| differs from |press_offset|, the mouse will be moved
1288 // between the press and release. 1284 // between the press and release.
1289 void ClickFocusViewOrigin(ui_controls::MouseButton button, 1285 void ClickOmnibox(ui_controls::MouseButton button,
1290 const gfx::Vector2d& press_offset, 1286 const gfx::Vector2d& press_offset,
1291 const gfx::Vector2d& release_offset) { 1287 const gfx::Vector2d& release_offset) {
1292 gfx::Point focus_view_origin = GetFocusView()->GetBoundsInScreen().origin(); 1288 const views::View* omnibox = GetBrowserView()->GetViewByID(VIEW_ID_OMNIBOX);
1293 gfx::Point press_point = focus_view_origin + press_offset; 1289 gfx::Point omnibox_origin = omnibox->GetBoundsInScreen().origin();
1290 gfx::Point press_point = omnibox_origin + press_offset;
1294 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_point)); 1291 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_point));
1295 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN)); 1292 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN));
1296 1293
1297 gfx::Point release_point = focus_view_origin + release_offset; 1294 gfx::Point release_point = omnibox_origin + release_offset;
1298 if (release_point != press_point) 1295 if (release_point != press_point)
1299 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_point)); 1296 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_point));
1300 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP)); 1297 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP));
1301 } 1298 }
1302 #endif // defined(USE_AURA) 1299 #endif // defined(TOOLKIT_VIEWS)
1303 }; 1300 };
1304 1301
1305 // Test if ctrl-* accelerators are workable in omnibox. 1302 // Test if ctrl-* accelerators are workable in omnibox.
1306 // See http://crbug.com/19193: omnibox blocks ctrl-* commands 1303 // See http://crbug.com/19193: omnibox blocks ctrl-* commands
1307 // 1304 //
1308 // Flaky on interactive tests (dbg), http://crbug.com/69433 1305 // Flaky on interactive tests (dbg), http://crbug.com/69433
1309 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) { 1306 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) {
1310 BrowserAcceleratorsTest(); 1307 BrowserAcceleratorsTest();
1311 } 1308 }
1312 1309
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 // Paste text. 1622 // Paste text.
1626 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); 1623 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN));
1627 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1624 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1628 ASSERT_TRUE(popup_model->IsOpen()); 1625 ASSERT_TRUE(popup_model->IsOpen());
1629 1626
1630 // Inline autocomplete shouldn't be triggered. 1627 // Inline autocomplete shouldn't be triggered.
1631 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); 1628 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText());
1632 } 1629 }
1633 #endif // defined(TOOLKIT_GTK) 1630 #endif // defined(TOOLKIT_GTK)
1634 1631
1635 // TODO(derat): Enable on Windows: http://crbug.com/128556 1632 #if defined(TOOLKIT_VIEWS)
1636 #if defined(USE_AURA) 1633 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, SelectAllOnClick) {
1637 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_SelectAllOnClick) {
1638 OmniboxView* omnibox_view = NULL; 1634 OmniboxView* omnibox_view = NULL;
1639 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 1635 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1640 omnibox_view->SetUserText(ASCIIToUTF16("http://www.google.com/")); 1636 omnibox_view->SetUserText(ASCIIToUTF16("http://www.google.com/"));
1641 const gfx::Vector2d kClickOffset(2, 2); 1637 const gfx::Vector2d click(40, 10);
1642 1638
1643 // Take the focus away from the omnibox. 1639 // Take the focus away from the omnibox.
1644 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); 1640 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
1641 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1645 EXPECT_FALSE(omnibox_view->IsSelectAll()); 1642 EXPECT_FALSE(omnibox_view->IsSelectAll());
1646 EXPECT_FALSE(GetFocusView()->HasFocus());
1647 1643
1648 // Click in the omnibox. All of its text should be selected. 1644 // Clicking in the omnibox should take focus and select all text.
1649 ASSERT_NO_FATAL_FAILURE( 1645 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, click));
1650 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset)); 1646 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1651 EXPECT_TRUE(omnibox_view->IsSelectAll()); 1647 EXPECT_TRUE(omnibox_view->IsSelectAll());
1652 EXPECT_TRUE(GetFocusView()->HasFocus());
1653 1648
1654 // Ensure that all of the text is selected and then take the focus away. The 1649 // Clicking in another view should clear focus and the selection.
1655 // selection should persist. 1650 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
1651 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1652 EXPECT_FALSE(omnibox_view->IsSelectAll());
1653
1654 // Clicking in the omnibox again should take focus and select all text again.
1655 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, click));
1656 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1657 EXPECT_TRUE(omnibox_view->IsSelectAll());
1658
1659 // Clicking another omnibox spot should keep focus but clear the selection.
1656 omnibox_view->SelectAll(false); 1660 omnibox_view->SelectAll(false);
1657 EXPECT_TRUE(omnibox_view->IsSelectAll()); 1661 const gfx::Vector2d click_2(click.x() + 10, click.y());
1658 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); 1662 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click_2, click_2));
1659 EXPECT_TRUE(omnibox_view->IsSelectAll()); 1663 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1660 EXPECT_FALSE(GetFocusView()->HasFocus());
1661
1662 // Clicking in the omnibox while some of its text is already selected should
1663 // have the effect of re-selecting the text.
1664 ASSERT_NO_FATAL_FAILURE(
1665 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset));
1666 // The following expect fails starting with one of the cls (148415-148428),
1667 // most likely the WebKit roll @148419.
1668 // http://crbug.com/139069
1669 EXPECT_TRUE(omnibox_view->IsSelectAll());
1670 EXPECT_TRUE(GetFocusView()->HasFocus());
1671
1672 // Click in a different spot in the omnibox. It should keep the focus but
1673 // lose the selection.
1674 omnibox_view->SelectAll(false);
1675 const gfx::Vector2d kSecondClickOffset(kClickOffset.x() + 10,
1676 kClickOffset.y());
1677 ASSERT_NO_FATAL_FAILURE(
1678 ClickFocusViewOrigin(
1679 ui_controls::LEFT, kSecondClickOffset, kSecondClickOffset));
1680 EXPECT_FALSE(omnibox_view->IsSelectAll()); 1664 EXPECT_FALSE(omnibox_view->IsSelectAll());
1681 EXPECT_TRUE(GetFocusView()->HasFocus());
1682 1665
1683 // Take the focus away and click in the omnibox again, but drag a bit before 1666 // Take the focus away and click in the omnibox again, but drag a bit before
1684 // releasing. We should focus the omnibox but not select all of its text. 1667 // releasing. We should focus the omnibox but not select all of its text.
1685 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); 1668 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
1686 const gfx::Vector2d kReleaseOffset(kClickOffset.x() + 10, kClickOffset.y()); 1669 const gfx::Vector2d release(click.x() + 10, click.y());
1687 ASSERT_NO_FATAL_FAILURE( 1670 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, release));
1688 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kReleaseOffset)); 1671 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1689 EXPECT_FALSE(omnibox_view->IsSelectAll()); 1672 EXPECT_FALSE(omnibox_view->IsSelectAll());
1690 EXPECT_TRUE(GetFocusView()->HasFocus());
1691 1673
1692 // Middle-clicking shouldn't select all the text either. 1674 // Middle-clicking should not be handled by the omnibox.
1693 ASSERT_NO_FATAL_FAILURE(
1694 ClickFocusViewOrigin(ui_controls::LEFT, kClickOffset, kClickOffset));
1695 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); 1675 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter());
1696 ASSERT_NO_FATAL_FAILURE( 1676 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::MIDDLE, click, click));
1697 ClickFocusViewOrigin(ui_controls::MIDDLE, kClickOffset, kClickOffset)); 1677 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1698 EXPECT_FALSE(omnibox_view->IsSelectAll()); 1678 EXPECT_FALSE(omnibox_view->IsSelectAll());
1699 } 1679 }
1700 #endif // defined(USE_AURA) 1680 #endif // defined(TOOLKIT_VIEWS)
1701 1681
1702 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CopyURLToClipboard) { 1682 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CopyURLToClipboard) {
1703 OmniboxView* omnibox_view = NULL; 1683 OmniboxView* omnibox_view = NULL;
1704 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 1684 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1705 const char* target_url = "http://www.google.com/calendar"; 1685 const char* target_url = "http://www.google.com/calendar";
1706 omnibox_view->SetUserText(ASCIIToUTF16(target_url)); 1686 omnibox_view->SetUserText(ASCIIToUTF16(target_url));
1707 1687
1708 // Set permanent text thus making sure that omnibox treats 'google.com' 1688 // Set permanent text thus making sure that omnibox treats 'google.com'
1709 // as URL (not as ordinary user input). 1689 // as URL (not as ordinary user input).
1710 OmniboxEditModel* edit_model = omnibox_view->model(); 1690 OmniboxEditModel* edit_model = omnibox_view->model();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 // BrowserWindowController depends on the auto release pool being recycled 1905 // BrowserWindowController depends on the auto release pool being recycled
1926 // in the message loop to delete itself, which frees the Browser object 1906 // in the message loop to delete itself, which frees the Browser object
1927 // which fires this event. 1907 // which fires this event.
1928 AutoreleasePool()->Recycle(); 1908 AutoreleasePool()->Recycle();
1929 #endif 1909 #endif
1930 1910
1931 signal.Wait(); 1911 signal.Wait();
1932 EXPECT_FALSE(clipboard->IsFormatAvailable( 1912 EXPECT_FALSE(clipboard->IsFormatAvailable(
1933 ui::Clipboard::GetPlainTextFormatType(), ui::Clipboard::BUFFER_STANDARD)); 1913 ui::Clipboard::GetPlainTextFormatType(), ui::Clipboard::BUFFER_STANDARD));
1934 } 1914 }
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/textfield/native_textfield_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698