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.
5 #include "base/basictypes.h"
6 #include "base/command_line.h"
8 #include "base/mac/mac_util.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/win/windows_version.h"
12 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_test_message_listener.h"
15 #include "chrome/browser/extensions/tab_helper.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/chrome_version_info.h"
20 #include "chrome/common/extensions/feature_switch.h"
21 #include "chrome/common/extensions/features/base_feature_provider.h"
22 #include "chrome/common/extensions/features/complex_feature.h"
23 #include "chrome/common/extensions/features/simple_feature.h"
24 #include "chrome/test/base/test_switches.h"
25 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/render_view_host.h"
27 #include "content/public/common/content_switches.h"
28 #include "extensions/common/features/feature.h"
29 #include "ui/compositor/compositor_switches.h"
33 const char kExtensionId[] = "ddchlicdkolnonkihahngkmmmjnjlkkf";
35 class TabCaptureApiTest : public ExtensionApiTest {
37 TabCaptureApiTest() {}
39 virtual void SetUp() OVERRIDE {
40 // TODO(danakj): The GPU Video Decoder needs real GL bindings.
44 // These test should be using OSMesa on CrOS, which would make this
47 #if !defined(OS_CHROMEOS)
51 ExtensionApiTest::SetUp();
54 void AddExtensionToCommandLineWhitelist() {
55 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
56 switches::kWhitelistedExtensionID, kExtensionId);
62 // http://crbug.com/261493
63 #if defined(OS_CHROMEOS)
64 #define MAYBE_ApiTests DISABLED_ApiTests
66 #define MAYBE_ApiTests ApiTests
68 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ApiTests) {
69 #if defined(OS_WIN) && defined(USE_ASH)
70 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
71 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
76 // TODO(justinlin): Disabled for WinXP due to timeout issues.
77 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
82 AddExtensionToCommandLineWhitelist();
83 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
84 "api_tests.html")) << message_;
87 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, ApiTestsAudio) {
89 // TODO(justinlin): Disabled for WinXP due to timeout issues.
90 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
95 AddExtensionToCommandLineWhitelist();
96 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
97 "api_tests_audio.html")) << message_;
100 // http://crbug.com/177163
101 #if defined(OS_WIN) && !defined(NDEBUG)
102 #define MAYBE_EndToEnd DISABLED_EndToEnd
104 #define MAYBE_EndToEnd EndToEnd
106 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_EndToEnd) {
108 // TODO(justinlin): Disabled for WinXP due to timeout issues.
109 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
113 #if defined(OS_MACOSX)
114 // TODO(miu): Disabled for Mac OS X 10.6 due to timeout issues.
115 // http://crbug.com/174640
116 if (base::mac::IsOSSnowLeopard())
120 AddExtensionToCommandLineWhitelist();
121 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
122 "end_to_end.html")) << message_;
125 // http://crbug.com/177163
126 #if defined(OS_WIN) && !defined(NDEBUG)
127 #define MAYBE_GetUserMediaTest DISABLED_GetUserMediaTest
129 #define MAYBE_GetUserMediaTest GetUserMediaTest
131 // Test that we can't get tabCapture streams using GetUserMedia directly.
132 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_GetUserMediaTest) {
133 ExtensionTestMessageListener listener("ready", true);
135 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
136 "get_user_media_test.html")) << message_;
138 EXPECT_TRUE(listener.WaitUntilSatisfied());
140 content::OpenURLParams params(GURL("about:blank"), content::Referrer(),
142 content::PAGE_TRANSITION_LINK, false);
143 content::WebContents* web_contents = browser()->OpenURL(params);
145 content::RenderViewHost* const rvh = web_contents->GetRenderViewHost();
146 int render_process_id = rvh->GetProcess()->GetID();
147 int routing_id = rvh->GetRoutingID();
149 listener.Reply(base::StringPrintf("%i:%i", render_process_id, routing_id));
151 ResultCatcher catcher;
152 catcher.RestrictToProfile(browser()->profile());
153 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
156 // http://crbug.com/177163
157 #if defined(OS_WIN) && !defined(NDEBUG)
158 #define MAYBE_ActiveTabPermission DISABLED_ActiveTabPermission
160 #define MAYBE_ActiveTabPermission ActiveTabPermission
162 // Make sure tabCapture.capture only works if the tab has been granted
163 // permission via an extension icon click or the extension is whitelisted.
164 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ActiveTabPermission) {
165 ExtensionTestMessageListener before_open_tab("ready1", true);
166 ExtensionTestMessageListener before_grant_permission("ready2", true);
167 ExtensionTestMessageListener before_open_new_tab("ready3", true);
168 ExtensionTestMessageListener before_whitelist_extension("ready4", true);
170 ASSERT_TRUE(RunExtensionSubtest(
171 "tab_capture/experimental", "active_tab_permission_test.html"))
174 // Open a new tab and make sure capture is denied.
175 EXPECT_TRUE(before_open_tab.WaitUntilSatisfied());
176 content::OpenURLParams params(GURL("http://google.com"), content::Referrer(),
178 content::PAGE_TRANSITION_LINK, false);
179 content::WebContents* web_contents = browser()->OpenURL(params);
180 before_open_tab.Reply("");
182 // Grant permission and make sure capture succeeds.
183 EXPECT_TRUE(before_grant_permission.WaitUntilSatisfied());
184 ExtensionService* extension_service =
185 Profile::FromBrowserContext(web_contents->GetBrowserContext())
186 ->GetExtensionService();
187 const extensions::Extension* extension =
188 extension_service->GetExtensionById(kExtensionId, false);
189 extensions::TabHelper::FromWebContents(web_contents)
190 ->active_tab_permission_granter()->GrantIfRequested(extension);
191 before_grant_permission.Reply("");
193 // Open a new tab and make sure capture is denied.
194 EXPECT_TRUE(before_open_new_tab.WaitUntilSatisfied());
195 browser()->OpenURL(params);
196 before_open_new_tab.Reply("");
198 // Add extension to whitelist and make sure capture succeeds.
199 EXPECT_TRUE(before_whitelist_extension.WaitUntilSatisfied());
200 AddExtensionToCommandLineWhitelist();
201 before_whitelist_extension.Reply("");
203 ResultCatcher catcher;
204 catcher.RestrictToProfile(browser()->profile());
205 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
208 // http://crbug.com/177163
209 #if defined(OS_WIN) && !defined(NDEBUG)
210 #define MAYBE_FullscreenEvents DISABLED_FullscreenEvents
211 #elif defined(USE_AURA) || defined(OS_MACOSX)
212 // These don't always fire fullscreen events when run in tests. Tested manually.
213 #define MAYBE_FullscreenEvents DISABLED_FullscreenEvents
214 #elif defined(OS_LINUX)
215 // Flaky to get out of fullscreen in tests. Tested manually.
216 #define MAYBE_FullscreenEvents DISABLED_FullscreenEvents
218 #define MAYBE_FullscreenEvents FullscreenEvents
220 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_FullscreenEvents) {
222 // TODO(justinlin): Disabled for WinXP due to timeout issues.
223 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
228 AddExtensionToCommandLineWhitelist();
230 content::OpenURLParams params(GURL("chrome://version"),
233 content::PAGE_TRANSITION_LINK, false);
234 content::WebContents* web_contents = browser()->OpenURL(params);
236 ExtensionTestMessageListener listeners_setup("ready1", true);
237 ExtensionTestMessageListener fullscreen_entered("ready2", true);
239 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
240 "fullscreen_test.html")) << message_;
241 EXPECT_TRUE(listeners_setup.WaitUntilSatisfied());
243 // Toggle fullscreen after setting up listeners.
244 browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents,
246 listeners_setup.Reply("");
248 // Toggle again after JS should have the event.
249 EXPECT_TRUE(fullscreen_entered.WaitUntilSatisfied());
250 browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents,
252 fullscreen_entered.Reply("");
254 ResultCatcher catcher;
255 catcher.RestrictToProfile(browser()->profile());
256 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
259 // Times out on Win dbg bots: http://crbug.com/177163
260 // #if defined(OS_WIN) && !defined(NDEBUG)
261 // Times out on all Win bots: http://crbug.com/294431
263 #define MAYBE_GrantForChromePages DISABLED_GrantForChromePages
265 #define MAYBE_GrantForChromePages GrantForChromePages
267 // Make sure tabCapture API can be granted for Chrome:// pages.
268 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_GrantForChromePages) {
269 ExtensionTestMessageListener before_open_tab("ready1", true);
270 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
271 "active_tab_chrome_pages.html")) << message_;
272 EXPECT_TRUE(before_open_tab.WaitUntilSatisfied());
274 // Open a tab on a chrome:// page and make sure we can capture.
275 content::OpenURLParams params(GURL("chrome://version"), content::Referrer(),
277 content::PAGE_TRANSITION_LINK, false);
278 content::WebContents* web_contents = browser()->OpenURL(params);
279 ExtensionService* extension_service =
280 Profile::FromBrowserContext(web_contents->GetBrowserContext())
281 ->GetExtensionService();
282 extensions::TabHelper::FromWebContents(web_contents)
283 ->active_tab_permission_granter()->GrantIfRequested(
284 extension_service->GetExtensionById(kExtensionId, false));
285 before_open_tab.Reply("");
287 ResultCatcher catcher;
288 catcher.RestrictToProfile(browser()->profile());
289 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
292 #if defined(OS_WIN) && !defined(NDEBUG)
293 #define MAYBE_CaptureInSplitIncognitoMode DISABLED_CaptureInSplitIncognitoMode
295 #define MAYBE_CaptureInSplitIncognitoMode CaptureInSplitIncognitoMode
297 // Test that a tab can be captured in split incognito mode.
298 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_CaptureInSplitIncognitoMode) {
299 AddExtensionToCommandLineWhitelist();
300 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
302 kFlagEnableIncognito | kFlagUseIncognito))
306 #if defined(OS_WIN) && !defined(NDEBUG)
307 #define MAYBE_Constraints DISABLED_Constraints
309 #define MAYBE_Constraints Constraints
311 IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_Constraints) {
312 AddExtensionToCommandLineWhitelist();
313 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
314 "constraints.html")) << message_;