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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
(...skipping 1650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1661 EXPECT_EQ(0u, BrowserList::size()); | 1661 EXPECT_EQ(0u, BrowserList::size()); |
1662 | 1662 |
1663 // Starting a browser window should work just fine. | 1663 // Starting a browser window should work just fine. |
1664 ui_test_utils::BrowserAddedObserver browser_added_observer; | 1664 ui_test_utils::BrowserAddedObserver browser_added_observer; |
1665 CreateBrowser(ProfileManager::GetDefaultProfile()); | 1665 CreateBrowser(ProfileManager::GetDefaultProfile()); |
1666 browser_added_observer.WaitForSingleNewBrowser(); | 1666 browser_added_observer.WaitForSingleNewBrowser(); |
1667 | 1667 |
1668 EXPECT_EQ(1u, BrowserList::size()); | 1668 EXPECT_EQ(1u, BrowserList::size()); |
1669 } | 1669 } |
1670 | 1670 |
1671 // This test needs to be placed outside the anonymouse namespace because we | 1671 // This test needs to be placed outside the anonymous namespace because we |
1672 // need to access private type of Browser. | 1672 // need to access private type of Browser. |
1673 class AppModeTest : public BrowserTest { | 1673 class AppModeTest : public BrowserTest { |
1674 public: | 1674 public: |
1675 AppModeTest() {} | 1675 AppModeTest() {} |
1676 | 1676 |
1677 virtual void SetUpCommandLine(CommandLine* command_line) { | 1677 virtual void SetUpCommandLine(CommandLine* command_line) { |
1678 GURL url = ui_test_utils::GetTestUrl( | 1678 GURL url = ui_test_utils::GetTestUrl( |
1679 FilePath(), FilePath().AppendASCII("title1.html")); | 1679 FilePath(), FilePath().AppendASCII("title1.html")); |
1680 command_line->AppendSwitchASCII(switches::kApp, url.spec()); | 1680 command_line->AppendSwitchASCII(switches::kApp, url.spec()); |
1681 } | 1681 } |
(...skipping 13 matching lines...) Expand all Loading... |
1695 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("WebKit"), true, true, | 1695 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("WebKit"), true, true, |
1696 NULL, NULL), | 1696 NULL, NULL), |
1697 0); | 1697 0); |
1698 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("OS"), true, true, | 1698 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("OS"), true, true, |
1699 NULL, NULL), | 1699 NULL, NULL), |
1700 0); | 1700 0); |
1701 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("JavaScript"), true, | 1701 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("JavaScript"), true, |
1702 true, NULL, NULL), | 1702 true, NULL, NULL), |
1703 0); | 1703 0); |
1704 } | 1704 } |
| 1705 |
| 1706 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("click_modifier"); |
| 1707 static const char kFirstPageTitle[] = "First window"; |
| 1708 static const char kSecondPageTitle[] = "New window!"; |
| 1709 |
| 1710 class ClickModifierTest : public InProcessBrowserTest { |
| 1711 public: |
| 1712 ClickModifierTest() { |
| 1713 } |
| 1714 |
| 1715 // Returns a url that opens a new window or tab when clicked, via javascript. |
| 1716 GURL GetTestURL() { |
| 1717 return ui_test_utils::GetTestUrl( |
| 1718 FilePath(kTestDir), |
| 1719 FilePath(FILE_PATH_LITERAL("window_open.html"))); |
| 1720 } |
| 1721 |
| 1722 string16 getFirstPageTitle() { |
| 1723 return ASCIIToUTF16(kFirstPageTitle); |
| 1724 } |
| 1725 |
| 1726 string16 getSecondPageTitle() { |
| 1727 return ASCIIToUTF16(kSecondPageTitle); |
| 1728 } |
| 1729 |
| 1730 // Loads our test page and simulates a single click using the supplied button |
| 1731 // and modifiers. The test page will call window.open, creating either a new |
| 1732 // tab or a new window. In the case of a tab, it will verify whether the |
| 1733 // tab's in the foreground or background. |
| 1734 void RunTest(Browser* browser, |
| 1735 int modifiers, |
| 1736 WebKit::WebMouseEvent::Button button, |
| 1737 bool expect_new_window, |
| 1738 bool expect_foreground) { |
| 1739 GURL url(GetTestURL()); |
| 1740 ui_test_utils::NavigateToURL(browser, url); |
| 1741 EXPECT_EQ(1u, browser::GetBrowserCount(browser->profile())); |
| 1742 EXPECT_EQ(1, browser->tab_count()); |
| 1743 content::WebContents* web_contents = chrome::GetActiveWebContents(browser); |
| 1744 EXPECT_EQ(url, web_contents->GetURL()); |
| 1745 |
| 1746 content::WindowedNotificationObserver observer( |
| 1747 chrome::NOTIFICATION_TAB_ADDED, |
| 1748 content::NotificationService::AllSources()); |
| 1749 SimulateMouseClick(web_contents, modifiers, button); |
| 1750 observer.Wait(); |
| 1751 |
| 1752 unsigned expected_browser_count = expect_new_window ? 2 : 1; |
| 1753 EXPECT_EQ(expected_browser_count, |
| 1754 browser::GetBrowserCount(browser->profile())); |
| 1755 |
| 1756 // If we didn't pop up a new window, we need to make sure the right tab's in |
| 1757 // front. |
| 1758 if (!expect_new_window) { |
| 1759 EXPECT_EQ(2, browser->tab_count()); |
| 1760 web_contents = chrome::GetActiveWebContents(browser); |
| 1761 WaitForLoadStop(web_contents); |
| 1762 if (expect_foreground) { |
| 1763 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle()); |
| 1764 } else { |
| 1765 EXPECT_EQ(getFirstPageTitle(), web_contents->GetTitle()); |
| 1766 } |
| 1767 } |
| 1768 } |
| 1769 |
| 1770 private: |
| 1771 DISALLOW_COPY_AND_ASSIGN(ClickModifierTest); |
| 1772 }; |
| 1773 |
| 1774 IN_PROC_BROWSER_TEST_F(ClickModifierTest, BasicClickTest) { |
| 1775 int modifiers = 0; |
| 1776 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft; |
| 1777 bool expect_new_window = false; |
| 1778 bool expect_foreground = true; |
| 1779 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground); |
| 1780 } |
| 1781 |
| 1782 // TODO(ericu): Alt-click behavior is platform-dependent and not well defined. |
| 1783 // Should we add tests so we know if it changes? |
| 1784 |
| 1785 // Shift-clicks open in a new window. |
| 1786 // TODO(ericu): Disabled until https://bugs.webkit.org/show_bug.cgi?id=99202 |
| 1787 // lands, fixing http://crbug.com/31631. |
| 1788 IN_PROC_BROWSER_TEST_F(ClickModifierTest, DISABLED_ShiftClickTest) { |
| 1789 int modifiers = WebKit::WebInputEvent::ShiftKey; |
| 1790 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft; |
| 1791 bool expect_new_window = true; |
| 1792 bool expect_foreground = true; |
| 1793 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground); |
| 1794 } |
| 1795 |
| 1796 // Control-clicks open in a background tab. |
| 1797 // On OSX meta [the command key] takes the place of control. |
| 1798 IN_PROC_BROWSER_TEST_F(ClickModifierTest, ControlClickTest) { |
| 1799 #if defined(OS_MACOSX) |
| 1800 int modifiers = WebKit::WebInputEvent::MetaKey; |
| 1801 #else |
| 1802 int modifiers = WebKit::WebInputEvent::ControlKey; |
| 1803 #endif |
| 1804 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft; |
| 1805 bool expect_new_window = false; |
| 1806 bool expect_foreground = false; |
| 1807 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground); |
| 1808 } |
| 1809 |
| 1810 // Control-shift-clicks open in a foreground tab. |
| 1811 // On OSX meta [the command key] takes the place of control. |
| 1812 IN_PROC_BROWSER_TEST_F(ClickModifierTest, ControlShiftClickTest) { |
| 1813 #if defined(OS_MACOSX) |
| 1814 int modifiers = WebKit::WebInputEvent::MetaKey; |
| 1815 #else |
| 1816 int modifiers = WebKit::WebInputEvent::ControlKey; |
| 1817 #endif |
| 1818 modifiers |= WebKit::WebInputEvent::ShiftKey; |
| 1819 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft; |
| 1820 bool expect_new_window = false; |
| 1821 bool expect_foreground = true; |
| 1822 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground); |
| 1823 } |
| 1824 |
| 1825 // Middle-clicks open in a background tab. |
| 1826 IN_PROC_BROWSER_TEST_F(ClickModifierTest, MiddleClickTest) { |
| 1827 int modifiers = 0; |
| 1828 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle; |
| 1829 bool expect_new_window = false; |
| 1830 bool expect_foreground = false; |
| 1831 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground); |
| 1832 } |
| 1833 |
| 1834 // Shift-middle-clicks open in a foreground tab. |
| 1835 IN_PROC_BROWSER_TEST_F(ClickModifierTest, ShiftMiddleClickTest) { |
| 1836 int modifiers = WebKit::WebInputEvent::ShiftKey; |
| 1837 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle; |
| 1838 bool expect_new_window = false; |
| 1839 bool expect_foreground = true; |
| 1840 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground); |
| 1841 } |
OLD | NEW |