blob: f40ccefd3484151c5d4d46e8f3d9c314c2392740 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01005#include "base/basictypes.h"
6#if defined(OS_MACOSX)
7#include "base/mac/mac_util.h"
8#endif
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +01009#include "base/strings/stringprintf.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010010#include "base/win/windows_version.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000011#include "chrome/browser/extensions/extension_apitest.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010012#include "chrome/browser/extensions/extension_service.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000013#include "chrome/browser/extensions/extension_test_message_listener.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010014#include "chrome/browser/extensions/tab_helper.h"
15#include "chrome/browser/profiles/profile.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010016#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010017#include "chrome/common/chrome_switches.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000018#include "chrome/common/chrome_version_info.h"
19#include "chrome/common/extensions/feature_switch.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010020#include "chrome/common/extensions/features/base_feature_provider.h"
21#include "chrome/common/extensions/features/complex_feature.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000022#include "chrome/common/extensions/features/feature.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010023#include "chrome/common/extensions/features/simple_feature.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000024#include "content/public/browser/render_process_host.h"
25#include "content/public/browser/render_view_host.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000026#include "content/public/common/content_switches.h"
27
Ben Murdoch558790d2013-07-30 15:19:42 +010028#if defined(OS_WIN) && defined(USE_ASH)
29#include "base/win/windows_version.h"
30#endif
31
Torne (Richard Coles)58218062012-11-14 11:43:16 +000032namespace chrome {
33
34namespace {
35
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010036const char kExtensionId[] = "ddchlicdkolnonkihahngkmmmjnjlkkf";
37
Torne (Richard Coles)58218062012-11-14 11:43:16 +000038class TabCaptureApiTest : public ExtensionApiTest {
39 public:
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010040 TabCaptureApiTest() {}
Torne (Richard Coles)58218062012-11-14 11:43:16 +000041
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010042 void AddExtensionToCommandLineWhitelist() {
43 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
44 switches::kWhitelistedExtensionID, kExtensionId);
45 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +000046};
47
48} // namespace
49
Ben Murdochca12bfa2013-07-23 11:17:05 +010050// http://crbug.com/261493
51#if defined(OS_LINUX) || defined(OS_CHROMEOS)
52#define MAYBE_ApiTests DISABLED_ApiTests
53#else
54#define MAYBE_ApiTests ApiTests
55#endif
56IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ApiTests) {
Ben Murdoch558790d2013-07-30 15:19:42 +010057#if defined(OS_WIN) && defined(USE_ASH)
58 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
59 if (base::win::GetVersion() >= base::win::VERSION_WIN8)
60 return;
61#endif
62
Torne (Richard Coles)58218062012-11-14 11:43:16 +000063 extensions::FeatureSwitch::ScopedOverride tab_capture(
64 extensions::FeatureSwitch::tab_capture(), true);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010065
66#if defined(OS_WIN)
67 // TODO(justinlin): Disabled for WinXP due to timeout issues.
68 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
69 return;
70 }
71#endif
72
73 AddExtensionToCommandLineWhitelist();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000074 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
75 "api_tests.html")) << message_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000076}
77
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +010078IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, ApiTestsAudio) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000079 extensions::FeatureSwitch::ScopedOverride tab_capture(
80 extensions::FeatureSwitch::tab_capture(), true);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010081
82#if defined(OS_WIN)
83 // TODO(justinlin): Disabled for WinXP due to timeout issues.
84 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
85 return;
86 }
87#endif
88
89 AddExtensionToCommandLineWhitelist();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000090 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
91 "api_tests_audio.html")) << message_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000092}
93
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010094// http://crbug.com/177163
95#if defined(OS_WIN) && !defined(NDEBUG)
96#define MAYBE_EndToEnd DISABLED_EndToEnd
97#else
98#define MAYBE_EndToEnd EndToEnd
99#endif
100IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_EndToEnd) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000101 extensions::FeatureSwitch::ScopedOverride tab_capture(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000102 extensions::FeatureSwitch::tab_capture(), true);
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100103
104#if defined(OS_WIN)
105 // TODO(justinlin): Disabled for WinXP due to timeout issues.
106 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
107 return;
108 }
109#endif
110#if defined(OS_MACOSX)
111 // TODO(miu): Disabled for Mac OS X 10.6 due to timeout issues.
112 // http://crbug.com/174640
113 if (base::mac::IsOSSnowLeopard())
114 return;
115#endif
116
117 AddExtensionToCommandLineWhitelist();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000118 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
119 "end_to_end.html")) << message_;
120}
121
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100122// http://crbug.com/177163
123#if defined(OS_WIN) && !defined(NDEBUG)
124#define MAYBE_GetUserMediaTest DISABLED_GetUserMediaTest
125#else
126#define MAYBE_GetUserMediaTest GetUserMediaTest
127#endif
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000128// Test that we can't get tabCapture streams using GetUserMedia directly.
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100129IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_GetUserMediaTest) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000130 ExtensionTestMessageListener listener("ready", true);
131
132 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
133 "get_user_media_test.html")) << message_;
134
135 EXPECT_TRUE(listener.WaitUntilSatisfied());
136
137 content::OpenURLParams params(GURL("about:blank"), content::Referrer(),
138 NEW_FOREGROUND_TAB,
139 content::PAGE_TRANSITION_LINK, false);
140 content::WebContents* web_contents = browser()->OpenURL(params);
141
142 content::RenderViewHost* const rvh = web_contents->GetRenderViewHost();
143 int render_process_id = rvh->GetProcess()->GetID();
144 int routing_id = rvh->GetRoutingID();
145
146 listener.Reply(base::StringPrintf("%i:%i", render_process_id, routing_id));
147
148 ResultCatcher catcher;
149 catcher.RestrictToProfile(browser()->profile());
150 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000151}
152
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100153// http://crbug.com/177163
154#if defined(OS_WIN) && !defined(NDEBUG)
155#define MAYBE_ActiveTabPermission DISABLED_ActiveTabPermission
156#else
157#define MAYBE_ActiveTabPermission ActiveTabPermission
158#endif
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100159// Make sure tabCapture.capture only works if the tab has been granted
160// permission via an extension icon click or the extension is whitelisted.
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100161IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ActiveTabPermission) {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100162 ExtensionTestMessageListener before_open_tab("ready1", true);
163 ExtensionTestMessageListener before_grant_permission("ready2", true);
164 ExtensionTestMessageListener before_open_new_tab("ready3", true);
165 ExtensionTestMessageListener before_whitelist_extension("ready4", true);
166
167 ASSERT_TRUE(RunExtensionSubtest(
168 "tab_capture/experimental", "active_tab_permission_test.html"))
169 << message_;
170
171 // Open a new tab and make sure capture is denied.
172 EXPECT_TRUE(before_open_tab.WaitUntilSatisfied());
173 content::OpenURLParams params(GURL("http://google.com"), content::Referrer(),
174 NEW_FOREGROUND_TAB,
175 content::PAGE_TRANSITION_LINK, false);
176 content::WebContents* web_contents = browser()->OpenURL(params);
177 before_open_tab.Reply("");
178
179 // Grant permission and make sure capture succeeds.
180 EXPECT_TRUE(before_grant_permission.WaitUntilSatisfied());
181 ExtensionService* extension_service =
182 Profile::FromBrowserContext(web_contents->GetBrowserContext())
183 ->GetExtensionService();
184 const extensions::Extension* extension =
185 extension_service->GetExtensionById(kExtensionId, false);
186 extensions::TabHelper::FromWebContents(web_contents)
187 ->active_tab_permission_granter()->GrantIfRequested(extension);
188 before_grant_permission.Reply("");
189
190 // Open a new tab and make sure capture is denied.
191 EXPECT_TRUE(before_open_new_tab.WaitUntilSatisfied());
192 browser()->OpenURL(params);
193 before_open_new_tab.Reply("");
194
195 // Add extension to whitelist and make sure capture succeeds.
196 EXPECT_TRUE(before_whitelist_extension.WaitUntilSatisfied());
197 AddExtensionToCommandLineWhitelist();
198 before_whitelist_extension.Reply("");
199
200 ResultCatcher catcher;
201 catcher.RestrictToProfile(browser()->profile());
202 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
203}
204
Ben Murdocheb525c52013-07-10 11:40:50 +0100205// http://crbug.com/177163
206#if defined(OS_WIN) && !defined(NDEBUG)
207#define MAYBE_FullscreenEvents DISABLED_FullscreenEvents
208#elif defined(USE_AURA) || defined(OS_MACOSX)
209// These don't always fire fullscreen events when run in tests. Tested manually.
210#define MAYBE_FullscreenEvents DISABLED_FullscreenEvents
211#elif defined(OS_LINUX)
212// Flaky to get out of fullscreen in tests. Tested manually.
213#define MAYBE_FullscreenEvents DISABLED_FullscreenEvents
214#else
215#define MAYBE_FullscreenEvents FullscreenEvents
216#endif
217IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_FullscreenEvents) {
218#if defined(OS_WIN)
219 // TODO(justinlin): Disabled for WinXP due to timeout issues.
220 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
221 return;
222 }
223#endif
224
225 AddExtensionToCommandLineWhitelist();
226
227 content::OpenURLParams params(GURL("chrome://version"),
228 content::Referrer(),
229 CURRENT_TAB,
230 content::PAGE_TRANSITION_LINK, false);
231 content::WebContents* web_contents = browser()->OpenURL(params);
232
233 ExtensionTestMessageListener listeners_setup("ready1", true);
234 ExtensionTestMessageListener fullscreen_entered("ready2", true);
235
236 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
237 "fullscreen_test.html")) << message_;
238 EXPECT_TRUE(listeners_setup.WaitUntilSatisfied());
239
240 // Toggle fullscreen after setting up listeners.
241 browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents,
242 true);
243 listeners_setup.Reply("");
244
245 // Toggle again after JS should have the event.
246 EXPECT_TRUE(fullscreen_entered.WaitUntilSatisfied());
247 browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents,
248 false);
249 fullscreen_entered.Reply("");
250
251 ResultCatcher catcher;
252 catcher.RestrictToProfile(browser()->profile());
253 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
254}
255
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000256} // namespace chrome