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

Unified Diff: chrome/browser/click_modifier_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: Clean up html 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | content/public/test/browser_test_utils.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/click_modifier_browsertest.cc
diff --git a/chrome/browser/click_modifier_browsertest.cc b/chrome/browser/click_modifier_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3ea721324bf8a2ab7677e3c8d41d3827d4cfe71c
--- /dev/null
+++ b/chrome/browser/click_modifier_browsertest.cc
@@ -0,0 +1,151 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/file_path.h"
sky 2012/10/23 00:53:38 At a minimum this file needs to be in chrome/brows
ericu 2012/10/23 18:05:33 I'd been modeling it after popup_blocker_browserte
sky 2012/10/23 19:45:01 I'm not a fan of test file that do not have a corr
ericu 2012/10/23 20:09:09 OK; done.
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/content_settings/host_content_settings_map.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/test/browser_test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("click_modifier");
+
+class ClickModifierBrowserTest : public InProcessBrowserTest {
+ public:
+ ClickModifierBrowserTest() {}
+
+ // Returns a url that opens a new window or tab when clicked, via javascript.
+ GURL GetTestURL() {
+ return ui_test_utils::GetTestUrl(
+ FilePath(kTestDir),
+ FilePath(FILE_PATH_LITERAL("window_open.html")));
+ }
+
+ void RunTest(Browser* browser, int modifiers,
sky 2012/10/23 00:53:38 If you can't fit all params on their own line, wra
ericu 2012/10/23 18:05:33 While writing the description, I realised this cou
+ WebKit::WebMouseEvent::Button button, unsigned browser_count,
+ int tab_count, const string16& active_title) {
+
+ GURL url(GetTestURL());
+ 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());
+
+ browser->profile()->GetHostContentSettingsMap()->SetContentSetting(
+ ContentSettingsPattern::FromURL(url),
+ ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_POPUPS,
+ "",
+ CONTENT_SETTING_ALLOW);
+
+ content::WindowedNotificationObserver observer(
+ chrome::NOTIFICATION_TAB_ADDED,
+ content::NotificationService::AllSources());
+ SimulateModifiedMouseClick(web_contents, modifiers, button);
+ observer.Wait();
+
+ EXPECT_EQ(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 (browser_count == 1) {
+ EXPECT_EQ(tab_count, browser->tab_count());
+ web_contents = chrome::GetActiveWebContents(browser);
+ WaitForLoadStop(web_contents);
+ EXPECT_EQ(active_title, web_contents->GetTitle());
+ }
+ }
+};
sky 2012/10/23 00:53:38 private: DISALLOW_COPY_AND_ASSIGN
ericu 2012/10/23 18:05:33 Done.
+
+IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, BasicClickTest) {
+ int modifiers = 0;
+ WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
+ unsigned browser_count = 1;
+ int tab_count = 2;
+ string16 active_tab_title = ASCIIToUTF16("New window!");
+ RunTest(browser(), modifiers, button, browser_count, tab_count,
+ active_tab_title);
+}
+
+// TODO(ericu): Alt-click behavior is platform-dependent and not well defined.
+// Should we add tests so we know if it changes?
+
+// We ignore meta, so this should be just like BasicClickTest.
+IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, MetaClickTest) {
+ int modifiers = WebKit::WebInputEvent::MetaKey;
+ WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
+ unsigned browser_count = 1;
+ int tab_count = 2;
+ string16 active_tab_title = ASCIIToUTF16("New window!");
+ RunTest(browser(), modifiers, button, browser_count, tab_count,
+ active_tab_title);
+}
+
+// Shift-clicks open in a new window.
+IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, ShiftClickTest) {
+ int modifiers = WebKit::WebInputEvent::ShiftKey;
+ WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
+ unsigned browser_count = 2;
+ int tab_count = 1;
+ string16 active_tab_title = ASCIIToUTF16("New window!");
+ RunTest(browser(), modifiers, button, browser_count, tab_count,
+ active_tab_title);
+}
+
+// Shift-clicks open in a background tab.
+IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, ControlClickTest) {
+ int modifiers = WebKit::WebInputEvent::ControlKey;
+ WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
+ unsigned browser_count = 1;
+ int tab_count = 2;
+ string16 active_tab_title = ASCIIToUTF16("First window");
+ RunTest(browser(), modifiers, button, browser_count, tab_count,
+ active_tab_title);
+}
+
+// Control-shift-clicks open in a foreground tab.
+IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, ControlShiftClickTest) {
+ int modifiers = WebKit::WebInputEvent::ControlKey |
+ WebKit::WebInputEvent::ShiftKey;
+ WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft;
+ unsigned browser_count = 1;
+ int tab_count = 2;
+ string16 active_tab_title = ASCIIToUTF16("New window!");
+ RunTest(browser(), modifiers, button, browser_count, tab_count,
+ active_tab_title);
+}
+
+// Middle-clicks open in a background tab.
+IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, MiddleClickTest) {
+ int modifiers = 0;
+ WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle;
+ unsigned browser_count = 1;
+ int tab_count = 2;
+ string16 active_tab_title = ASCIIToUTF16("First window");
+ RunTest(browser(), modifiers, button, browser_count, tab_count,
+ active_tab_title);
+}
+
+// Shift-middle-clicks open in a foreground tab.
+IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, ShiftMiddleClickTest) {
+ int modifiers = WebKit::WebInputEvent::ShiftKey;
+ WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle;
+ unsigned browser_count = 1;
+ int tab_count = 2;
+ string16 active_tab_title = ASCIIToUTF16("New window!");
+ RunTest(browser(), modifiers, button, browser_count, tab_count,
+ active_tab_title);
+}
+
+} // namespace
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | content/public/test/browser_test_utils.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698