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

Side by Side Diff: chrome/browser/ui/browser_browsertest.cc

Issue 11235048: Test suite that monitors the disposition of JS-created windows based on what (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix OSX. Created 8 years, 2 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 <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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 179 }
180 180
181 virtual std::string GetHTMLContents() OVERRIDE { 181 virtual std::string GetHTMLContents() OVERRIDE {
182 return "<h1>INTERSTITIAL</h1>"; 182 return "<h1>INTERSTITIAL</h1>";
183 } 183 }
184 184
185 private: 185 private:
186 InterstitialPage* interstitial_page_; // Owns us. 186 InterstitialPage* interstitial_page_; // Owns us.
187 }; 187 };
188 188
189 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("click_modifier");
sky 2012/10/23 23:09:28 Move this close to your tests.
ericu 2012/10/23 23:15:44 Done.
190 static const char kFirstPageTitle[] = "First window";
191 static const char kSecondPageTitle[] = "New window!";
192
193 class ClickModifierTest : public InProcessBrowserTest {
194 public:
195 ClickModifierTest() {
196 }
197
198 // Returns a url that opens a new window or tab when clicked, via javascript.
199 GURL GetTestURL() {
200 return ui_test_utils::GetTestUrl(
201 FilePath(kTestDir),
202 FilePath(FILE_PATH_LITERAL("window_open.html")));
203 }
204
205 string16 getFirstPageTitle() {
206 return ASCIIToUTF16(kFirstPageTitle);
207 }
208
209 string16 getSecondPageTitle() {
210 return ASCIIToUTF16(kSecondPageTitle);
211 }
212
213 // Loads our test page and simulates a single click using the supplied button
214 // and modifiers. The test page will call window.open, creating either a new
215 // tab or a new window. In the case of a tab, it will verify whether the
216 // tab's in the foreground or background.
217 void RunTest(
sky 2012/10/23 23:09:28 nit: wrap at the ( and move the first arg up to th
ericu 2012/10/23 23:15:44 Done.
218 Browser* browser,
219 int modifiers,
220 WebKit::WebMouseEvent::Button button,
221 bool expect_new_window,
222 bool expect_foreground) {
223
sky 2012/10/23 23:09:28 nit: remove newline.
ericu 2012/10/23 23:15:44 Done.
224 GURL url(GetTestURL());
225 ui_test_utils::NavigateToURL(browser, url);
226 EXPECT_EQ(1u, browser::GetBrowserCount(browser->profile()));
227 EXPECT_EQ(1, browser->tab_count());
228 content::WebContents* web_contents = chrome::GetActiveWebContents(browser);
229 EXPECT_EQ(url, web_contents->GetURL());
230
231 content::WindowedNotificationObserver observer(
232 chrome::NOTIFICATION_TAB_ADDED,
233 content::NotificationService::AllSources());
234 SimulateMouseClick(web_contents, modifiers, button);
235 observer.Wait();
236
237 unsigned expected_browser_count = expect_new_window ? 2 : 1;
238 EXPECT_EQ(expected_browser_count,
239 browser::GetBrowserCount(browser->profile()));
240
241 // If we didn't pop up a new window, we need to make sure the right tab's in
242 // front.
243 if (!expect_new_window) {
244 EXPECT_EQ(2, browser->tab_count());
245 web_contents = chrome::GetActiveWebContents(browser);
246 WaitForLoadStop(web_contents);
247 if (expect_foreground) {
248 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle());
249 } else {
250 EXPECT_EQ(getFirstPageTitle(), web_contents->GetTitle());
251 }
252 }
253 }
254
255 private:
256 DISALLOW_COPY_AND_ASSIGN(ClickModifierTest);
257 };
258
259
189 } // namespace 260 } // namespace
190 261
191 class BrowserTest : public ExtensionBrowserTest { 262 class BrowserTest : public ExtensionBrowserTest {
192 protected: 263 protected:
193 // In RTL locales wrap the page title with RTL embedding characters so that it 264 // In RTL locales wrap the page title with RTL embedding characters so that it
194 // matches the value returned by GetWindowTitle(). 265 // matches the value returned by GetWindowTitle().
195 string16 LocaleWindowCaptionFromPageTitle(const string16& expected_title) { 266 string16 LocaleWindowCaptionFromPageTitle(const string16& expected_title) {
196 string16 page_title = WindowCaptionFromPageTitle(expected_title); 267 string16 page_title = WindowCaptionFromPageTitle(expected_title);
197 #if defined(OS_WIN) 268 #if defined(OS_WIN)
198 std::string locale = g_browser_process->GetApplicationLocale(); 269 std::string locale = g_browser_process->GetApplicationLocale();
(...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 EXPECT_EQ(0u, BrowserList::size()); 1732 EXPECT_EQ(0u, BrowserList::size());
1662 1733
1663 // Starting a browser window should work just fine. 1734 // Starting a browser window should work just fine.
1664 ui_test_utils::BrowserAddedObserver browser_added_observer; 1735 ui_test_utils::BrowserAddedObserver browser_added_observer;
1665 CreateBrowser(ProfileManager::GetDefaultProfile()); 1736 CreateBrowser(ProfileManager::GetDefaultProfile());
1666 browser_added_observer.WaitForSingleNewBrowser(); 1737 browser_added_observer.WaitForSingleNewBrowser();
1667 1738
1668 EXPECT_EQ(1u, BrowserList::size()); 1739 EXPECT_EQ(1u, BrowserList::size());
1669 } 1740 }
1670 1741
1671 // This test needs to be placed outside the anonymouse namespace because we 1742 // This test needs to be placed outside the anonymous namespace because we
1672 // need to access private type of Browser. 1743 // need to access private type of Browser.
1673 class AppModeTest : public BrowserTest { 1744 class AppModeTest : public BrowserTest {
1674 public: 1745 public:
1675 AppModeTest() {} 1746 AppModeTest() {}
1676 1747
1677 virtual void SetUpCommandLine(CommandLine* command_line) { 1748 virtual void SetUpCommandLine(CommandLine* command_line) {
1678 GURL url = ui_test_utils::GetTestUrl( 1749 GURL url = ui_test_utils::GetTestUrl(
1679 FilePath(), FilePath().AppendASCII("title1.html")); 1750 FilePath(), FilePath().AppendASCII("title1.html"));
1680 command_line->AppendSwitchASCII(switches::kApp, url.spec()); 1751 command_line->AppendSwitchASCII(switches::kApp, url.spec());
1681 } 1752 }
(...skipping 13 matching lines...) Expand all
1695 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("WebKit"), true, true, 1766 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("WebKit"), true, true,
1696 NULL, NULL), 1767 NULL, NULL),
1697 0); 1768 0);
1698 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("OS"), true, true, 1769 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("OS"), true, true,
1699 NULL, NULL), 1770 NULL, NULL),
1700 0); 1771 0);
1701 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("JavaScript"), true, 1772 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("JavaScript"), true,
1702 true, NULL, NULL), 1773 true, NULL, NULL),
1703 0); 1774 0);
1704 } 1775 }
1776
1777 IN_PROC_BROWSER_TEST_F(ClickModifierTest, BasicClickTest) {
1778 int modifiers = 0;
1779 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
1780 bool expect_new_window = false;
1781 bool expect_foreground = true;
1782 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
1783 }
1784
1785 // TODO(ericu): Alt-click behavior is platform-dependent and not well defined.
1786 // Should we add tests so we know if it changes?
1787
1788 // On non-OSX platforms we ignore meta, so this should be just like
1789 // BasicClickTest. On OSX, meta-click replaces control-click as a way to
1790 // send a link to a background tab.
1791 IN_PROC_BROWSER_TEST_F(ClickModifierTest, MetaClickTest) {
1792 int modifiers = WebKit::WebInputEvent::MetaKey;
1793 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
1794 bool expect_new_window = false;
1795 #if defined(OS_MACOSX)
1796 bool expect_foreground = false;
1797 #else
1798 bool expect_foreground = true;
1799 #endif
1800 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
1801 }
1802
1803 // Shift-clicks open in a new window.
1804 // TODO(ericu): Disabled until https://bugs.webkit.org/show_bug.cgi?id=99202
1805 // lands, fixing http://crbug.com/31631.
1806 IN_PROC_BROWSER_TEST_F(ClickModifierTest, DISABLED_ShiftClickTest) {
1807 int modifiers = WebKit::WebInputEvent::ShiftKey;
1808 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
1809 bool expect_new_window = true;
1810 bool expect_foreground = true;
1811 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
1812 }
1813
1814 // Control-click doesn't cause a click on OSX.
1815 #if !defined(OS_MACOSX)
1816 // Control-clicks open in a background tab.
1817 IN_PROC_BROWSER_TEST_F(ClickModifierTest, ControlClickTest) {
1818 int modifiers = WebKit::WebInputEvent::ControlKey;
1819 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
1820 bool expect_new_window = false;
1821 bool expect_foreground = false;
1822 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
1823 }
1824 #endif
1825
1826 // Control-shift-clicks open in a foreground tab.
1827 IN_PROC_BROWSER_TEST_F(ClickModifierTest, ControlShiftClickTest) {
1828 int modifiers = WebKit::WebInputEvent::ControlKey |
1829 WebKit::WebInputEvent::ShiftKey;
1830 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
1831 bool expect_new_window = false;
1832 bool expect_foreground = true;
1833 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
1834 }
1835
1836 // Middle-clicks open in a background tab.
1837 IN_PROC_BROWSER_TEST_F(ClickModifierTest, MiddleClickTest) {
1838 int modifiers = 0;
1839 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle;
1840 bool expect_new_window = false;
1841 bool expect_foreground = false;
1842 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
1843 }
1844
1845 // Shift-middle-clicks open in a foreground tab.
1846 IN_PROC_BROWSER_TEST_F(ClickModifierTest, ShiftMiddleClickTest) {
1847 int modifiers = WebKit::WebInputEvent::ShiftKey;
1848 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle;
1849 bool expect_new_window = false;
1850 bool expect_foreground = true;
1851 RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
1852 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698