| Index: chrome/browser/ui/browser_browsertest.cc
|
| diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc
|
| index 025551c480f32264f9acb28053736eb272fd0f40..e7c89ff239de8487b225286aa2d287f16d25822d 100644
|
| --- a/chrome/browser/ui/browser_browsertest.cc
|
| +++ b/chrome/browser/ui/browser_browsertest.cc
|
| @@ -60,6 +60,7 @@
|
| #include "content/public/common/renderer_preferences.h"
|
| #include "content/public/common/url_constants.h"
|
| #include "content/public/test/browser_test_utils.h"
|
| +#include "content/public/test/test_navigation_observer.h"
|
| #include "grit/chromium_strings.h"
|
| #include "grit/generated_resources.h"
|
| #include "net/base/mock_host_resolver.h"
|
| @@ -1713,12 +1714,20 @@ class ClickModifierTest : public InProcessBrowserTest {
|
| }
|
|
|
| // Returns a url that opens a new window or tab when clicked, via javascript.
|
| - GURL GetTestURL() {
|
| + GURL GetWindowOpenURL() {
|
| return ui_test_utils::GetTestUrl(
|
| FilePath(kTestDir),
|
| FilePath(FILE_PATH_LITERAL("window_open.html")));
|
| }
|
|
|
| + // Returns a url that follows a simple link when clicked, unless affected by
|
| + // modifiers.
|
| + GURL GetHrefURL() {
|
| + return ui_test_utils::GetTestUrl(
|
| + FilePath(kTestDir),
|
| + FilePath(FILE_PATH_LITERAL("href.html")));
|
| + }
|
| +
|
| string16 getFirstPageTitle() {
|
| return ASCIIToUTF16(kFirstPageTitle);
|
| }
|
| @@ -1728,42 +1737,59 @@ class ClickModifierTest : public InProcessBrowserTest {
|
| }
|
|
|
| // Loads our test page and simulates a single click using the supplied button
|
| - // and modifiers. The test page will call window.open, creating either a new
|
| - // tab or a new window. In the case of a tab, it will verify whether the
|
| - // tab's in the foreground or background.
|
| + // and modifiers. The click will cause either a navigation or the creation of
|
| + // a new window or foreground or background tab. We verify that the expected
|
| + // disposition occurs.
|
| void RunTest(Browser* browser,
|
| + const GURL& url,
|
| int modifiers,
|
| WebKit::WebMouseEvent::Button button,
|
| - bool expect_new_window,
|
| - bool expect_foreground) {
|
| - GURL url(GetTestURL());
|
| + WindowOpenDisposition disposition) {
|
| ui_test_utils::NavigateToURL(browser, url);
|
| EXPECT_EQ(1u, browser::GetBrowserCount(browser->profile()));
|
| EXPECT_EQ(1, browser->tab_count());
|
| content::WebContents* web_contents = chrome::GetActiveWebContents(browser);
|
| EXPECT_EQ(url, web_contents->GetURL());
|
|
|
| + if (disposition == CURRENT_TAB) {
|
| + NavigationController* controller =
|
| + chrome::GetActiveWebContents(browser) ?
|
| + &chrome::GetActiveWebContents(browser)->GetController() : NULL;
|
| + content::TestNavigationObserver same_tab_observer(
|
| + content::Source<NavigationController>(controller),
|
| + NULL,
|
| + 1);
|
| + SimulateMouseClick(web_contents, modifiers, button);
|
| + base::RunLoop run_loop;
|
| + same_tab_observer.WaitForObservation(
|
| + base::Bind(&content::RunThisRunLoop, base::Unretained(&run_loop)),
|
| + content::GetQuitTaskForRunLoop(&run_loop));
|
| + EXPECT_EQ(1u, browser::GetBrowserCount(browser->profile()));
|
| + EXPECT_EQ(1, browser->tab_count());
|
| + EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle());
|
| + return;
|
| + }
|
| +
|
| content::WindowedNotificationObserver observer(
|
| chrome::NOTIFICATION_TAB_ADDED,
|
| content::NotificationService::AllSources());
|
| SimulateMouseClick(web_contents, modifiers, button);
|
| observer.Wait();
|
|
|
| - unsigned expected_browser_count = expect_new_window ? 2 : 1;
|
| - EXPECT_EQ(expected_browser_count,
|
| - browser::GetBrowserCount(browser->profile()));
|
| -
|
| - // If we didn't pop up a new window, we need to make sure the right tab's in
|
| - // front.
|
| - if (!expect_new_window) {
|
| - EXPECT_EQ(2, browser->tab_count());
|
| - web_contents = chrome::GetActiveWebContents(browser);
|
| - WaitForLoadStop(web_contents);
|
| - if (expect_foreground) {
|
| - EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle());
|
| - } else {
|
| - EXPECT_EQ(getFirstPageTitle(), web_contents->GetTitle());
|
| - }
|
| + if (disposition == NEW_WINDOW) {
|
| + EXPECT_EQ(2u, browser::GetBrowserCount(browser->profile()));
|
| + return;
|
| + }
|
| +
|
| + EXPECT_EQ(1u, browser::GetBrowserCount(browser->profile()));
|
| + EXPECT_EQ(2, browser->tab_count());
|
| + web_contents = chrome::GetActiveWebContents(browser);
|
| + WaitForLoadStop(web_contents);
|
| + if (disposition == NEW_FOREGROUND_TAB) {
|
| + EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle());
|
| + } else {
|
| + ASSERT_EQ(NEW_BACKGROUND_TAB, disposition);
|
| + EXPECT_EQ(getFirstPageTitle(), web_contents->GetTitle());
|
| }
|
| }
|
|
|
| @@ -1771,45 +1797,107 @@ class ClickModifierTest : public InProcessBrowserTest {
|
| DISALLOW_COPY_AND_ASSIGN(ClickModifierTest);
|
| };
|
|
|
| -IN_PROC_BROWSER_TEST_F(ClickModifierTest, BasicClickTest) {
|
| +// Tests for clicking on elements with handlers that run window.open.
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenBasicClickTest) {
|
| int modifiers = 0;
|
| WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
|
| - bool expect_new_window = false;
|
| - bool expect_foreground = true;
|
| - RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
|
| + WindowOpenDisposition disposition = NEW_FOREGROUND_TAB;
|
| + RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition);
|
| }
|
|
|
| -// TODO(ericu): Alt-click behavior is platform-dependent and not well defined.
|
| -// Should we add tests so we know if it changes?
|
| +// TODO(ericu): Alt-click behavior on window.open is platform-dependent and not
|
| +// well defined. Should we add tests so we know if it changes?
|
|
|
| // Shift-clicks open in a new window.
|
| // TODO(ericu): Disabled until https://bugs.webkit.org/show_bug.cgi?id=99202
|
| // lands, fixing http://crbug.com/31631.
|
| -IN_PROC_BROWSER_TEST_F(ClickModifierTest, DISABLED_ShiftClickTest) {
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, DISABLED_WindowOpenShiftClickTest) {
|
| + int modifiers = WebKit::WebInputEvent::ShiftKey;
|
| + WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
|
| + WindowOpenDisposition disposition = NEW_WINDOW;
|
| + RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition);
|
| +}
|
| +
|
| +// Control-clicks open in a background tab.
|
| +// On OSX meta [the command key] takes the place of control.
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenControlClickTest) {
|
| +#if defined(OS_MACOSX)
|
| + int modifiers = WebKit::WebInputEvent::MetaKey;
|
| +#else
|
| + int modifiers = WebKit::WebInputEvent::ControlKey;
|
| +#endif
|
| + WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
|
| + WindowOpenDisposition disposition = NEW_BACKGROUND_TAB;
|
| + RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition);
|
| +}
|
| +
|
| +// Control-shift-clicks open in a foreground tab.
|
| +// On OSX meta [the command key] takes the place of control.
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenControlShiftClickTest) {
|
| +#if defined(OS_MACOSX)
|
| + int modifiers = WebKit::WebInputEvent::MetaKey;
|
| +#else
|
| + int modifiers = WebKit::WebInputEvent::ControlKey;
|
| +#endif
|
| + modifiers |= WebKit::WebInputEvent::ShiftKey;
|
| + WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
|
| + WindowOpenDisposition disposition = NEW_FOREGROUND_TAB;
|
| + RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition);
|
| +}
|
| +
|
| +// Middle-clicks open in a background tab.
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenMiddleClickTest) {
|
| + int modifiers = 0;
|
| + WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle;
|
| + WindowOpenDisposition disposition = NEW_BACKGROUND_TAB;
|
| + RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition);
|
| +}
|
| +
|
| +// Shift-middle-clicks open in a foreground tab.
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenShiftMiddleClickTest) {
|
| + int modifiers = WebKit::WebInputEvent::ShiftKey;
|
| + WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle;
|
| + WindowOpenDisposition disposition = NEW_FOREGROUND_TAB;
|
| + RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition);
|
| +}
|
| +
|
| +// Tests for clicking on normal links.
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefBasicClickTest) {
|
| + int modifiers = 0;
|
| + WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
|
| + WindowOpenDisposition disposition = CURRENT_TAB;
|
| + RunTest(browser(), GetHrefURL(), modifiers, button, disposition);
|
| +}
|
| +
|
| +// TODO(ericu): Alt-click behavior on links is platform-dependent and not well
|
| +// defined. Should we add tests so we know if it changes?
|
| +
|
| +// Shift-clicks open in a new window.
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefShiftClickTest) {
|
| int modifiers = WebKit::WebInputEvent::ShiftKey;
|
| WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
|
| - bool expect_new_window = true;
|
| - bool expect_foreground = true;
|
| - RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
|
| + WindowOpenDisposition disposition = NEW_WINDOW;
|
| + RunTest(browser(), GetHrefURL(), modifiers, button, disposition);
|
| }
|
|
|
| // Control-clicks open in a background tab.
|
| // On OSX meta [the command key] takes the place of control.
|
| -IN_PROC_BROWSER_TEST_F(ClickModifierTest, ControlClickTest) {
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefControlClickTest) {
|
| #if defined(OS_MACOSX)
|
| int modifiers = WebKit::WebInputEvent::MetaKey;
|
| #else
|
| int modifiers = WebKit::WebInputEvent::ControlKey;
|
| #endif
|
| WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
|
| - bool expect_new_window = false;
|
| - bool expect_foreground = false;
|
| - RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
|
| + WindowOpenDisposition disposition = NEW_BACKGROUND_TAB;
|
| + RunTest(browser(), GetHrefURL(), modifiers, button, disposition);
|
| }
|
|
|
| // Control-shift-clicks open in a foreground tab.
|
| // On OSX meta [the command key] takes the place of control.
|
| -IN_PROC_BROWSER_TEST_F(ClickModifierTest, ControlShiftClickTest) {
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefControlShiftClickTest) {
|
| #if defined(OS_MACOSX)
|
| int modifiers = WebKit::WebInputEvent::MetaKey;
|
| #else
|
| @@ -1817,25 +1905,22 @@ IN_PROC_BROWSER_TEST_F(ClickModifierTest, ControlShiftClickTest) {
|
| #endif
|
| modifiers |= WebKit::WebInputEvent::ShiftKey;
|
| WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
|
| - bool expect_new_window = false;
|
| - bool expect_foreground = true;
|
| - RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
|
| + WindowOpenDisposition disposition = NEW_FOREGROUND_TAB;
|
| + RunTest(browser(), GetHrefURL(), modifiers, button, disposition);
|
| }
|
|
|
| // Middle-clicks open in a background tab.
|
| -IN_PROC_BROWSER_TEST_F(ClickModifierTest, MiddleClickTest) {
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefMiddleClickTest) {
|
| int modifiers = 0;
|
| WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle;
|
| - bool expect_new_window = false;
|
| - bool expect_foreground = false;
|
| - RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
|
| + WindowOpenDisposition disposition = NEW_BACKGROUND_TAB;
|
| + RunTest(browser(), GetHrefURL(), modifiers, button, disposition);
|
| }
|
|
|
| // Shift-middle-clicks open in a foreground tab.
|
| -IN_PROC_BROWSER_TEST_F(ClickModifierTest, ShiftMiddleClickTest) {
|
| +IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefShiftMiddleClickTest) {
|
| int modifiers = WebKit::WebInputEvent::ShiftKey;
|
| WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle;
|
| - bool expect_new_window = false;
|
| - bool expect_foreground = true;
|
| - RunTest(browser(), modifiers, button, expect_new_window, expect_foreground);
|
| + WindowOpenDisposition disposition = NEW_FOREGROUND_TAB;
|
| + RunTest(browser(), GetHrefURL(), modifiers, button, disposition);
|
| }
|
|
|