OLD | NEW |
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/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 43 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
44 #include "ui/base/events/event_constants.h" | 44 #include "ui/base/events/event_constants.h" |
45 #include "ui/base/keycodes/keyboard_codes.h" | 45 #include "ui/base/keycodes/keyboard_codes.h" |
46 #include "ui/gfx/point.h" | 46 #include "ui/gfx/point.h" |
47 | 47 |
48 #if defined(TOOLKIT_GTK) | 48 #if defined(TOOLKIT_GTK) |
49 #include <gdk/gdk.h> | 49 #include <gdk/gdk.h> |
50 #include <gtk/gtk.h> | 50 #include <gtk/gtk.h> |
51 #endif | 51 #endif |
52 | 52 |
53 #if defined(TOOLKIT_VIEWS) | |
54 #include "chrome/browser/ui/views/frame/browser_view.h" | |
55 #endif | |
56 | |
57 using base::Time; | 53 using base::Time; |
58 using base::TimeDelta; | 54 using base::TimeDelta; |
59 | 55 |
60 namespace { | 56 namespace { |
61 | 57 |
62 const char kSearchKeyword[] = "foo"; | 58 const char kSearchKeyword[] = "foo"; |
63 const char kSearchKeyword2[] = "footest.com"; | 59 const char kSearchKeyword2[] = "footest.com"; |
64 const wchar_t kSearchKeywordKeys[] = { ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, 0 }; | 60 const wchar_t kSearchKeywordKeys[] = { ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, 0 }; |
65 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}"; | 61 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}"; |
66 const char kSearchShortName[] = "foo"; | 62 const char kSearchShortName[] = "foo"; |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 | 1245 |
1250 // Make sure inline autocomplete is triggerred. | 1246 // Make sure inline autocomplete is triggerred. |
1251 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); | 1247 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); |
1252 | 1248 |
1253 // Press ctrl key. | 1249 // Press ctrl key. |
1254 omnibox_view->model()->OnControlKeyChanged(true); | 1250 omnibox_view->model()->OnControlKeyChanged(true); |
1255 | 1251 |
1256 // Inline autocomplete should still be there. | 1252 // Inline autocomplete should still be there. |
1257 EXPECT_EQ(old_text, omnibox_view->GetText()); | 1253 EXPECT_EQ(old_text, omnibox_view->GetText()); |
1258 } | 1254 } |
1259 | |
1260 #if defined(TOOLKIT_VIEWS) | |
1261 const BrowserView* GetBrowserView() const { | |
1262 return BrowserView::GetBrowserViewForBrowser(browser()); | |
1263 } | |
1264 | |
1265 // Move the mouse to the center of the browser window and left-click. | |
1266 void ClickBrowserWindowCenter() { | |
1267 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( | |
1268 GetBrowserView()->GetBoundsInScreen().CenterPoint())); | |
1269 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( | |
1270 ui_controls::LEFT, ui_controls::DOWN)); | |
1271 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( | |
1272 ui_controls::LEFT, ui_controls::UP)); | |
1273 } | |
1274 | |
1275 // Press and release the mouse in the omnibox at an offset from its origin. | |
1276 // If |release_offset| differs from |press_offset|, the mouse will be moved | |
1277 // between the press and release. | |
1278 void ClickOmnibox(ui_controls::MouseButton button, | |
1279 const gfx::Vector2d& press_offset, | |
1280 const gfx::Vector2d& release_offset) { | |
1281 const views::View* omnibox = GetBrowserView()->GetViewByID(VIEW_ID_OMNIBOX); | |
1282 gfx::Point omnibox_origin = omnibox->GetBoundsInScreen().origin(); | |
1283 gfx::Point press_point = omnibox_origin + press_offset; | |
1284 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(press_point)); | |
1285 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::DOWN)); | |
1286 | |
1287 gfx::Point release_point = omnibox_origin + release_offset; | |
1288 if (release_point != press_point) | |
1289 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(release_point)); | |
1290 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(button, ui_controls::UP)); | |
1291 } | |
1292 #endif // defined(TOOLKIT_VIEWS) | |
1293 }; | 1255 }; |
1294 | 1256 |
1295 // Test if ctrl-* accelerators are workable in omnibox. | 1257 // Test if ctrl-* accelerators are workable in omnibox. |
1296 // See http://crbug.com/19193: omnibox blocks ctrl-* commands | 1258 // See http://crbug.com/19193: omnibox blocks ctrl-* commands |
1297 // | 1259 // |
1298 // Flaky on interactive tests (dbg), http://crbug.com/69433 | 1260 // Flaky on interactive tests (dbg), http://crbug.com/69433 |
1299 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) { | 1261 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) { |
1300 BrowserAcceleratorsTest(); | 1262 BrowserAcceleratorsTest(); |
1301 } | 1263 } |
1302 | 1264 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 EXPECT_FALSE(popup_model->IsOpen()); | 1577 EXPECT_FALSE(popup_model->IsOpen()); |
1616 | 1578 |
1617 // Pasting amid text should yield the expected text and re-open the popup. | 1579 // Pasting amid text should yield the expected text and re-open the popup. |
1618 omnibox_view->SetWindowTextAndCaretPos(ASCIIToUTF16("abcd"), 2, false, false); | 1580 omnibox_view->SetWindowTextAndCaretPos(ASCIIToUTF16("abcd"), 2, false, false); |
1619 SetClipboardText(ASCIIToUTF16("123")); | 1581 SetClipboardText(ASCIIToUTF16("123")); |
1620 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, kCtrlOrCmdMask)); | 1582 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, kCtrlOrCmdMask)); |
1621 EXPECT_EQ(ASCIIToUTF16("ab123cd"), omnibox_view->GetText()); | 1583 EXPECT_EQ(ASCIIToUTF16("ab123cd"), omnibox_view->GetText()); |
1622 EXPECT_TRUE(popup_model->IsOpen()); | 1584 EXPECT_TRUE(popup_model->IsOpen()); |
1623 } | 1585 } |
1624 | 1586 |
1625 #if defined(TOOLKIT_VIEWS) | |
1626 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, SelectAllOnClick) { | |
1627 OmniboxView* omnibox_view = NULL; | |
1628 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | |
1629 omnibox_view->SetUserText(ASCIIToUTF16("http://www.google.com/")); | |
1630 const gfx::Vector2d click(40, 10); | |
1631 | |
1632 // Take the focus away from the omnibox. | |
1633 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | |
1634 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
1635 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
1636 | |
1637 // Clicking in the omnibox should take focus and select all text. | |
1638 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, click)); | |
1639 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
1640 EXPECT_TRUE(omnibox_view->IsSelectAll()); | |
1641 | |
1642 // Clicking in another view should clear focus and the selection. | |
1643 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | |
1644 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
1645 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
1646 | |
1647 // Clicking in the omnibox again should take focus and select all text again. | |
1648 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, click)); | |
1649 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
1650 EXPECT_TRUE(omnibox_view->IsSelectAll()); | |
1651 | |
1652 // Clicking another omnibox spot should keep focus but clear the selection. | |
1653 omnibox_view->SelectAll(false); | |
1654 const gfx::Vector2d click_2(click.x() + 10, click.y()); | |
1655 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click_2, click_2)); | |
1656 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
1657 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
1658 | |
1659 // Take the focus away and click in the omnibox again, but drag a bit before | |
1660 // releasing. We should focus the omnibox but not select all of its text. | |
1661 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | |
1662 const gfx::Vector2d release(click.x() + 10, click.y()); | |
1663 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::LEFT, click, release)); | |
1664 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
1665 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
1666 | |
1667 // Middle-clicking should not be handled by the omnibox. | |
1668 ASSERT_NO_FATAL_FAILURE(ClickBrowserWindowCenter()); | |
1669 ASSERT_NO_FATAL_FAILURE(ClickOmnibox(ui_controls::MIDDLE, click, click)); | |
1670 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | |
1671 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
1672 } | |
1673 #endif // defined(TOOLKIT_VIEWS) | |
1674 | |
1675 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CopyURLToClipboard) { | 1587 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CopyURLToClipboard) { |
1676 // Set permanent text thus making sure that omnibox treats 'google.com' | 1588 // Set permanent text thus making sure that omnibox treats 'google.com' |
1677 // as URL (not as ordinary user input). | 1589 // as URL (not as ordinary user input). |
1678 TestToolbarModel* test_toolbar_model = new TestToolbarModel; | 1590 TestToolbarModel* test_toolbar_model = new TestToolbarModel; |
1679 scoped_ptr<ToolbarModel> toolbar_model(test_toolbar_model); | 1591 scoped_ptr<ToolbarModel> toolbar_model(test_toolbar_model); |
1680 test_toolbar_model->set_text(ASCIIToUTF16("http://www.google.com/")); | 1592 test_toolbar_model->set_text(ASCIIToUTF16("http://www.google.com/")); |
1681 browser()->swap_toolbar_models(&toolbar_model); | 1593 browser()->swap_toolbar_models(&toolbar_model); |
1682 OmniboxView* omnibox_view = NULL; | 1594 OmniboxView* omnibox_view = NULL; |
1683 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1595 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
1684 OmniboxEditModel* edit_model = omnibox_view->model(); | 1596 OmniboxEditModel* edit_model = omnibox_view->model(); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 #if defined(OS_MACOSX) | 1783 #if defined(OS_MACOSX) |
1872 // Mac uses alt-left/right to select a word. | 1784 // Mac uses alt-left/right to select a word. |
1873 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN; | 1785 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN; |
1874 #else | 1786 #else |
1875 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN; | 1787 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN; |
1876 #endif | 1788 #endif |
1877 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers)); | 1789 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers)); |
1878 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers)); | 1790 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers)); |
1879 ASSERT_EQ(ASCIIToUTF16("www.bar.com/2"), omnibox_view->GetText()); | 1791 ASSERT_EQ(ASCIIToUTF16("www.bar.com/2"), omnibox_view->GetText()); |
1880 } | 1792 } |
OLD | NEW |