OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #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.
| |
6 #include "base/utf_string_conversions.h" | |
7 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
8 #include "chrome/browser/profiles/profile.h" | |
9 #include "chrome/browser/ui/browser.h" | |
10 #include "chrome/browser/ui/browser_finder.h" | |
11 #include "chrome/browser/ui/browser_tabstrip.h" | |
12 #include "chrome/common/chrome_notification_types.h" | |
13 #include "chrome/test/base/in_process_browser_test.h" | |
14 #include "chrome/test/base/ui_test_utils.h" | |
15 #include "content/public/browser/web_contents.h" | |
16 #include "content/public/browser/notification_service.h" | |
17 #include "content/public/test/browser_test_utils.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 | |
20 namespace { | |
21 | |
22 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("click_modifier"); | |
23 | |
24 class ClickModifierBrowserTest : public InProcessBrowserTest { | |
25 public: | |
26 ClickModifierBrowserTest() {} | |
27 | |
28 // Returns a url that opens a new window or tab when clicked, via javascript. | |
29 GURL GetTestURL() { | |
30 return ui_test_utils::GetTestUrl( | |
31 FilePath(kTestDir), | |
32 FilePath(FILE_PATH_LITERAL("window_open.html"))); | |
33 } | |
34 | |
35 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
| |
36 WebKit::WebMouseEvent::Button button, unsigned browser_count, | |
37 int tab_count, const string16& active_title) { | |
38 | |
39 GURL url(GetTestURL()); | |
40 ui_test_utils::NavigateToURL(browser, url); | |
41 EXPECT_EQ(1u, browser::GetBrowserCount(browser->profile())); | |
42 EXPECT_EQ(1, browser->tab_count()); | |
43 content::WebContents* web_contents = chrome::GetActiveWebContents(browser); | |
44 EXPECT_EQ(url, web_contents->GetURL()); | |
45 | |
46 browser->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
47 ContentSettingsPattern::FromURL(url), | |
48 ContentSettingsPattern::Wildcard(), | |
49 CONTENT_SETTINGS_TYPE_POPUPS, | |
50 "", | |
51 CONTENT_SETTING_ALLOW); | |
52 | |
53 content::WindowedNotificationObserver observer( | |
54 chrome::NOTIFICATION_TAB_ADDED, | |
55 content::NotificationService::AllSources()); | |
56 SimulateModifiedMouseClick(web_contents, modifiers, button); | |
57 observer.Wait(); | |
58 | |
59 EXPECT_EQ(browser_count, browser::GetBrowserCount(browser->profile())); | |
60 // If we didn't pop up a new window, we need to make sure the right tab's in | |
61 // front. | |
62 if (browser_count == 1) { | |
63 EXPECT_EQ(tab_count, browser->tab_count()); | |
64 web_contents = chrome::GetActiveWebContents(browser); | |
65 WaitForLoadStop(web_contents); | |
66 EXPECT_EQ(active_title, web_contents->GetTitle()); | |
67 } | |
68 } | |
69 }; | |
sky
2012/10/23 00:53:38
private:
DISALLOW_COPY_AND_ASSIGN
ericu
2012/10/23 18:05:33
Done.
| |
70 | |
71 IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, BasicClickTest) { | |
72 int modifiers = 0; | |
73 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft; | |
74 unsigned browser_count = 1; | |
75 int tab_count = 2; | |
76 string16 active_tab_title = ASCIIToUTF16("New window!"); | |
77 RunTest(browser(), modifiers, button, browser_count, tab_count, | |
78 active_tab_title); | |
79 } | |
80 | |
81 // TODO(ericu): Alt-click behavior is platform-dependent and not well defined. | |
82 // Should we add tests so we know if it changes? | |
83 | |
84 // We ignore meta, so this should be just like BasicClickTest. | |
85 IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, MetaClickTest) { | |
86 int modifiers = WebKit::WebInputEvent::MetaKey; | |
87 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft; | |
88 unsigned browser_count = 1; | |
89 int tab_count = 2; | |
90 string16 active_tab_title = ASCIIToUTF16("New window!"); | |
91 RunTest(browser(), modifiers, button, browser_count, tab_count, | |
92 active_tab_title); | |
93 } | |
94 | |
95 // Shift-clicks open in a new window. | |
96 IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, ShiftClickTest) { | |
97 int modifiers = WebKit::WebInputEvent::ShiftKey; | |
98 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft; | |
99 unsigned browser_count = 2; | |
100 int tab_count = 1; | |
101 string16 active_tab_title = ASCIIToUTF16("New window!"); | |
102 RunTest(browser(), modifiers, button, browser_count, tab_count, | |
103 active_tab_title); | |
104 } | |
105 | |
106 // Shift-clicks open in a background tab. | |
107 IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, ControlClickTest) { | |
108 int modifiers = WebKit::WebInputEvent::ControlKey; | |
109 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft; | |
110 unsigned browser_count = 1; | |
111 int tab_count = 2; | |
112 string16 active_tab_title = ASCIIToUTF16("First window"); | |
113 RunTest(browser(), modifiers, button, browser_count, tab_count, | |
114 active_tab_title); | |
115 } | |
116 | |
117 // Control-shift-clicks open in a foreground tab. | |
118 IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, ControlShiftClickTest) { | |
119 int modifiers = WebKit::WebInputEvent::ControlKey | | |
120 WebKit::WebInputEvent::ShiftKey; | |
121 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonLeft; | |
122 unsigned browser_count = 1; | |
123 int tab_count = 2; | |
124 string16 active_tab_title = ASCIIToUTF16("New window!"); | |
125 RunTest(browser(), modifiers, button, browser_count, tab_count, | |
126 active_tab_title); | |
127 } | |
128 | |
129 // Middle-clicks open in a background tab. | |
130 IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, MiddleClickTest) { | |
131 int modifiers = 0; | |
132 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle; | |
133 unsigned browser_count = 1; | |
134 int tab_count = 2; | |
135 string16 active_tab_title = ASCIIToUTF16("First window"); | |
136 RunTest(browser(), modifiers, button, browser_count, tab_count, | |
137 active_tab_title); | |
138 } | |
139 | |
140 // Shift-middle-clicks open in a foreground tab. | |
141 IN_PROC_BROWSER_TEST_F(ClickModifierBrowserTest, ShiftMiddleClickTest) { | |
142 int modifiers = WebKit::WebInputEvent::ShiftKey; | |
143 WebKit::WebMouseEvent::Button button = WebKit::WebMouseEvent::ButtonMiddle; | |
144 unsigned browser_count = 1; | |
145 int tab_count = 2; | |
146 string16 active_tab_title = ASCIIToUTF16("New window!"); | |
147 RunTest(browser(), modifiers, button, browser_count, tab_count, | |
148 active_tab_title); | |
149 } | |
150 | |
151 } // namespace | |
OLD | NEW |