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/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "chrome/test/base/ui_test_utils.h" | 38 #include "chrome/test/base/ui_test_utils.h" |
39 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
40 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
41 #include "net/dns/mock_host_resolver.h" | 41 #include "net/dns/mock_host_resolver.h" |
42 #include "ui/base/clipboard/clipboard.h" | 42 #include "ui/base/clipboard/clipboard.h" |
43 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 43 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
44 #include "ui/events/event_constants.h" | 44 #include "ui/events/event_constants.h" |
45 #include "ui/events/keycodes/keyboard_codes.h" | 45 #include "ui/events/keycodes/keyboard_codes.h" |
46 #include "ui/gfx/point.h" | 46 #include "ui/gfx/point.h" |
47 | 47 |
48 #if defined(TOOLKIT_GTK) | |
49 #include <gdk/gdk.h> | |
50 #include <gtk/gtk.h> | |
51 #endif | |
52 | |
53 using base::ASCIIToUTF16; | 48 using base::ASCIIToUTF16; |
54 using base::UTF16ToUTF8; | 49 using base::UTF16ToUTF8; |
55 using base::Time; | 50 using base::Time; |
56 using base::TimeDelta; | 51 using base::TimeDelta; |
57 | 52 |
58 namespace { | 53 namespace { |
59 | 54 |
60 const char kSearchKeyword[] = "foo"; | 55 const char kSearchKeyword[] = "foo"; |
61 const char kSearchKeyword2[] = "footest.com"; | 56 const char kSearchKeyword2[] = "footest.com"; |
62 const wchar_t kSearchKeywordKeys[] = { ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, 0 }; | 57 const wchar_t kSearchKeywordKeys[] = { ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, 0 }; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 103 |
109 // To trigger inline autocomplete. | 104 // To trigger inline autocomplete. |
110 {"http://www.def.com", "Page def", 10000, 10000, true }, | 105 {"http://www.def.com", "Page def", 10000, 10000, true }, |
111 | 106 |
112 // Used in particular for the desired TLD test. This makes it test | 107 // Used in particular for the desired TLD test. This makes it test |
113 // the interesting case when there's an intranet host with the same | 108 // the interesting case when there's an intranet host with the same |
114 // name as the .com. | 109 // name as the .com. |
115 {"http://bar/", "Bar", 1, 0, false }, | 110 {"http://bar/", "Bar", 1, 0, false }, |
116 }; | 111 }; |
117 | 112 |
118 #if defined(TOOLKIT_GTK) | |
119 // Returns the text stored in the PRIMARY clipboard. | |
120 std::string GetPrimarySelectionText() { | |
121 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); | |
122 DCHECK(clipboard); | |
123 | |
124 gchar* selection_text = gtk_clipboard_wait_for_text(clipboard); | |
125 std::string result(selection_text ? selection_text : ""); | |
126 g_free(selection_text); | |
127 return result; | |
128 } | |
129 #endif | |
130 | |
131 // Stores the given text to clipboard. | 113 // Stores the given text to clipboard. |
132 void SetClipboardText(const base::string16& text) { | 114 void SetClipboardText(const base::string16& text) { |
133 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); | 115 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
134 ui::ScopedClipboardWriter writer(clipboard, ui::CLIPBOARD_TYPE_COPY_PASTE); | 116 ui::ScopedClipboardWriter writer(clipboard, ui::CLIPBOARD_TYPE_COPY_PASTE); |
135 writer.WriteText(text); | 117 writer.WriteText(text); |
136 } | 118 } |
137 | 119 |
138 #if defined(OS_MACOSX) | 120 #if defined(OS_MACOSX) |
139 const int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN; | 121 const int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN; |
140 #else | 122 #else |
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 // Make sure inline autocomplete is triggerred. | 1359 // Make sure inline autocomplete is triggerred. |
1378 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); | 1360 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); |
1379 | 1361 |
1380 // Press ctrl key. | 1362 // Press ctrl key. |
1381 omnibox_view->model()->OnControlKeyChanged(true); | 1363 omnibox_view->model()->OnControlKeyChanged(true); |
1382 | 1364 |
1383 // Inline autocomplete should still be there. | 1365 // Inline autocomplete should still be there. |
1384 EXPECT_EQ(old_text, omnibox_view->GetText()); | 1366 EXPECT_EQ(old_text, omnibox_view->GetText()); |
1385 } | 1367 } |
1386 | 1368 |
1387 #if defined(TOOLKIT_GTK) || defined(TOOLKIT_VIEWS) | 1369 #if defined(TOOLKIT_VIEWS) |
1388 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, UndoRedo) { | 1370 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, UndoRedo) { |
1389 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL)); | 1371 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL)); |
1390 chrome::FocusLocationBar(browser()); | 1372 chrome::FocusLocationBar(browser()); |
1391 | 1373 |
1392 OmniboxView* omnibox_view = NULL; | 1374 OmniboxView* omnibox_view = NULL; |
1393 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1375 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
1394 | 1376 |
1395 base::string16 old_text = omnibox_view->GetText(); | 1377 base::string16 old_text = omnibox_view->GetText(); |
1396 EXPECT_EQ(base::UTF8ToUTF16(content::kAboutBlankURL), old_text); | 1378 EXPECT_EQ(base::UTF8ToUTF16(content::kAboutBlankURL), old_text); |
1397 EXPECT_TRUE(omnibox_view->IsSelectAll()); | 1379 EXPECT_TRUE(omnibox_view->IsSelectAll()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1453 // Insert text: ダ | 1435 // Insert text: ダ |
1454 omnibox_view->SetUserText(base::UTF8ToUTF16("\357\276\200\357\276\236")); | 1436 omnibox_view->SetUserText(base::UTF8ToUTF16("\357\276\200\357\276\236")); |
1455 | 1437 |
1456 // Move the cursor to the end. | 1438 // Move the cursor to the end. |
1457 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0)); | 1439 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0)); |
1458 | 1440 |
1459 // Backspace should delete one character. | 1441 // Backspace should delete one character. |
1460 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0)); | 1442 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0)); |
1461 EXPECT_EQ(base::UTF8ToUTF16("\357\276\200"), omnibox_view->GetText()); | 1443 EXPECT_EQ(base::UTF8ToUTF16("\357\276\200"), omnibox_view->GetText()); |
1462 } | 1444 } |
1463 #endif // defined(TOOLKIT_GTK) || defined(TOOLKIT_VIEWS) | 1445 #endif // defined(TOOLKIT_VIEWS) |
1464 | 1446 |
1465 // Flaky test. crbug.com/356850 | 1447 // Flaky test. crbug.com/356850 |
1466 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, | 1448 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, |
1467 DISABLED_DoesNotUpdateAutocompleteOnBlur) { | 1449 DISABLED_DoesNotUpdateAutocompleteOnBlur) { |
1468 OmniboxView* omnibox_view = NULL; | 1450 OmniboxView* omnibox_view = NULL; |
1469 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1451 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
1470 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model(); | 1452 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model(); |
1471 ASSERT_TRUE(popup_model); | 1453 ASSERT_TRUE(popup_model); |
1472 | 1454 |
1473 // Input something to trigger inline autocomplete. | 1455 // Input something to trigger inline autocomplete. |
1474 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys)); | 1456 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys)); |
1475 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1457 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
1476 ASSERT_TRUE(popup_model->IsOpen()); | 1458 ASSERT_TRUE(popup_model->IsOpen()); |
1477 size_t start, end; | 1459 size_t start, end; |
1478 omnibox_view->GetSelectionBounds(&start, &end); | 1460 omnibox_view->GetSelectionBounds(&start, &end); |
1479 EXPECT_TRUE(start != end); | 1461 EXPECT_TRUE(start != end); |
1480 base::string16 old_autocomplete_text = | 1462 base::string16 old_autocomplete_text = |
1481 omnibox_view->model()->autocomplete_controller()->input().text(); | 1463 omnibox_view->model()->autocomplete_controller()->input().text(); |
1482 | 1464 |
1483 // Unfocus the omnibox. This should clear the text field selection and | 1465 // Unfocus the omnibox. This should clear the text field selection and |
1484 // close the popup, but should not run autocomplete. | 1466 // close the popup, but should not run autocomplete. |
1485 // Note: GTK preserves the selection when the omnibox is unfocused. | 1467 // Note: GTK preserves the selection when the omnibox is unfocused. |
1486 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 1468 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
1487 ASSERT_FALSE(popup_model->IsOpen()); | 1469 ASSERT_FALSE(popup_model->IsOpen()); |
1488 omnibox_view->GetSelectionBounds(&start, &end); | 1470 omnibox_view->GetSelectionBounds(&start, &end); |
1489 #if !defined(TOOLKIT_GTK) | |
1490 EXPECT_TRUE(start == end); | 1471 EXPECT_TRUE(start == end); |
1491 #endif | |
1492 | 1472 |
1493 EXPECT_EQ(old_autocomplete_text, | 1473 EXPECT_EQ(old_autocomplete_text, |
1494 omnibox_view->model()->autocomplete_controller()->input().text()); | 1474 omnibox_view->model()->autocomplete_controller()->input().text()); |
1495 } | 1475 } |
1496 | 1476 |
1497 #if defined(TOOLKIT_GTK) | |
1498 // See http://crbug.com/63860 | |
1499 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, PrimarySelection) { | |
1500 OmniboxView* omnibox_view = NULL; | |
1501 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | |
1502 omnibox_view->SetUserText(ASCIIToUTF16("Hello world")); | |
1503 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
1504 | |
1505 // Move the cursor to the end. | |
1506 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0)); | |
1507 | |
1508 // Select all text by pressing Shift+Home | |
1509 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, ui::EF_SHIFT_DOWN)); | |
1510 EXPECT_TRUE(omnibox_view->IsSelectAll()); | |
1511 | |
1512 // The selected content should be saved to the PRIMARY clipboard. | |
1513 EXPECT_EQ("Hello world", GetPrimarySelectionText()); | |
1514 | |
1515 // Move the cursor to the end. | |
1516 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0)); | |
1517 EXPECT_FALSE(omnibox_view->IsSelectAll()); | |
1518 | |
1519 // The content in the PRIMARY clipboard should not be cleared. | |
1520 EXPECT_EQ("Hello world", GetPrimarySelectionText()); | |
1521 } | |
1522 #endif // defined(TOOLKIT_GTK) | |
1523 | |
1524 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, Paste) { | 1477 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, Paste) { |
1525 OmniboxView* omnibox_view = NULL; | 1478 OmniboxView* omnibox_view = NULL; |
1526 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1479 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
1527 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model(); | 1480 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model(); |
1528 ASSERT_TRUE(popup_model); | 1481 ASSERT_TRUE(popup_model); |
1529 EXPECT_FALSE(popup_model->IsOpen()); | 1482 EXPECT_FALSE(popup_model->IsOpen()); |
1530 | 1483 |
1531 // Paste should yield the expected text and open the popup. | 1484 // Paste should yield the expected text and open the popup. |
1532 SetClipboardText(ASCIIToUTF16(kSearchText)); | 1485 SetClipboardText(ASCIIToUTF16(kSearchText)); |
1533 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, kCtrlOrCmdMask)); | 1486 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, kCtrlOrCmdMask)); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 OmniboxView* omnibox_view = NULL; | 1660 OmniboxView* omnibox_view = NULL; |
1708 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1661 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
1709 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_EDIT_SEARCH_ENGINES)); | 1662 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_EDIT_SEARCH_ENGINES)); |
1710 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1663 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
1711 const std::string target_url = | 1664 const std::string target_url = |
1712 std::string(chrome::kChromeUISettingsURL) + chrome::kSearchEnginesSubPage; | 1665 std::string(chrome::kChromeUISettingsURL) + chrome::kSearchEnginesSubPage; |
1713 EXPECT_EQ(ASCIIToUTF16(target_url), omnibox_view->GetText()); | 1666 EXPECT_EQ(ASCIIToUTF16(target_url), omnibox_view->GetText()); |
1714 EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen()); | 1667 EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen()); |
1715 } | 1668 } |
1716 | 1669 |
1717 #if !defined(TOOLKIT_GTK) | |
1718 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, BeginningShownAfterBlur) { | 1670 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, BeginningShownAfterBlur) { |
1719 OmniboxView* omnibox_view = NULL; | 1671 OmniboxView* omnibox_view = NULL; |
1720 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1672 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
1721 | 1673 |
1722 omnibox_view->OnBeforePossibleChange(); | 1674 omnibox_view->OnBeforePossibleChange(); |
1723 omnibox_view->SetWindowTextAndCaretPos(ASCIIToUTF16("data:text/plain,test"), | 1675 omnibox_view->SetWindowTextAndCaretPos(ASCIIToUTF16("data:text/plain,test"), |
1724 5U, false, false); | 1676 5U, false, false); |
1725 omnibox_view->OnAfterPossibleChange(); | 1677 omnibox_view->OnAfterPossibleChange(); |
1726 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 1678 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
1727 size_t start, end; | 1679 size_t start, end; |
1728 omnibox_view->GetSelectionBounds(&start, &end); | 1680 omnibox_view->GetSelectionBounds(&start, &end); |
1729 ASSERT_EQ(5U, start); | 1681 ASSERT_EQ(5U, start); |
1730 ASSERT_EQ(5U, end); | 1682 ASSERT_EQ(5U, end); |
1731 | 1683 |
1732 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 1684 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
1733 ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 1685 ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
1734 | 1686 |
1735 omnibox_view->GetSelectionBounds(&start, &end); | 1687 omnibox_view->GetSelectionBounds(&start, &end); |
1736 ASSERT_EQ(0U, start); | 1688 ASSERT_EQ(0U, start); |
1737 ASSERT_EQ(0U, end); | 1689 ASSERT_EQ(0U, end); |
1738 } | 1690 } |
1739 #endif // !defined(TOOLKIT_GTK) | |
1740 | 1691 |
1741 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CtrlArrowAfterArrowSuggestions) { | 1692 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CtrlArrowAfterArrowSuggestions) { |
1742 OmniboxView* omnibox_view = NULL; | 1693 OmniboxView* omnibox_view = NULL; |
1743 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 1694 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
1744 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model(); | 1695 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model(); |
1745 ASSERT_TRUE(popup_model); | 1696 ASSERT_TRUE(popup_model); |
1746 | 1697 |
1747 // Input something to trigger results. | 1698 // Input something to trigger results. |
1748 const wchar_t kKeys[] = { ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, 0 }; | 1699 const wchar_t kKeys[] = { ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, 0 }; |
1749 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys)); | 1700 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys)); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1831 omnibox_view->Update(); | 1782 omnibox_view->Update(); |
1832 EXPECT_EQ(url_c, omnibox_view->GetText()); | 1783 EXPECT_EQ(url_c, omnibox_view->GetText()); |
1833 } | 1784 } |
1834 | 1785 |
1835 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EscDisablesSearchTermReplacement) { | 1786 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EscDisablesSearchTermReplacement) { |
1836 browser()->toolbar_model()->set_url_replacement_enabled(true); | 1787 browser()->toolbar_model()->set_url_replacement_enabled(true); |
1837 chrome::FocusLocationBar(browser()); | 1788 chrome::FocusLocationBar(browser()); |
1838 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0)); | 1789 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0)); |
1839 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled()); | 1790 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled()); |
1840 } | 1791 } |
OLD | NEW |