blob: 490abfd65cc5d4c057682508ed7879763b247801 [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"
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01006#include "base/command_line.h"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01007#if defined(OS_MACOSX)
8#include "base/mac/mac_util.h"
9#endif
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010010#include "base/strings/stringprintf.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010011#include "base/win/windows_version.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000012#include "chrome/browser/extensions/extension_apitest.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010013#include "chrome/browser/extensions/extension_service.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000014#include "chrome/browser/extensions/extension_test_message_listener.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010015#include "chrome/browser/extensions/tab_helper.h"
16#include "chrome/browser/profiles/profile.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010017#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010018#include "chrome/common/chrome_switches.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000019#include "chrome/common/chrome_version_info.h"
20#include "chrome/common/extensions/feature_switch.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010021#include "chrome/common/extensions/features/base_feature_provider.h"
22#include "chrome/common/extensions/features/complex_feature.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000023#include "chrome/common/extensions/features/feature.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010024#include "chrome/common/extensions/features/simple_feature.h"
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010025#include "chrome/test/base/test_switches.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000026#include "content/public/browser/render_process_host.h"
27#include "content/public/browser/render_view_host.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000028#include "content/public/common/content_switches.h"
29
30namespace chrome {
31
32namespace {
33
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010034const char kExtensionId[] = "ddchlicdkolnonkihahngkmmmjnjlkkf";
35
Torne (Richard Coles)58218062012-11-14 11:43:16 +000036class TabCaptureApiTest : public ExtensionApiTest {
37 public:
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010038 TabCaptureApiTest() {}
Torne (Richard Coles)58218062012-11-14 11:43:16 +000039
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010040 void AddExtensionToCommandLineWhitelist() {
41 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
42 switches::kWhitelistedExtensionID, kExtensionId);
43 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +000044};
45
46} // namespace
47
Ben Murdoch32409262013-08-07 11:04:47 +010048// http://crbug.com/261493 and http://crbug.com/268644
49#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(USE_AURA)
Ben Murdochca12bfa2013-07-23 11:17:05 +010050#define MAYBE_ApiTests DISABLED_ApiTests
51#else
52#define MAYBE_ApiTests ApiTests
53#endif
54IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ApiTests) {
Ben Murdoch558790d2013-07-30 15:19:42 +010055#if defined(OS_WIN) && defined(USE_ASH)
56 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010057 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
Ben Murdoch558790d2013-07-30 15:19:42 +010058 return;
59#endif
60
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010061#if defined(OS_WIN)
62 // TODO(justinlin): Disabled for WinXP due to timeout issues.
63 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
64 return;
65 }
66#endif
67
68 AddExtensionToCommandLineWhitelist();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000069 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
70 "api_tests.html")) << message_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000071}
72
Ben Murdoch32409262013-08-07 11:04:47 +010073// http://crbug.com/268644
74#if defined(USE_AURA)
75#define MAYBE_ApiTestsAudio DISABLED_ApiTestsAudio
76#else
77#define MAYBE_ApiTestsAudio ApiTestsAudio
78#endif
79IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ApiTestsAudio) {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010080#if defined(OS_WIN)
81 // TODO(justinlin): Disabled for WinXP due to timeout issues.
82 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
83 return;
84 }
85#endif
86
87 AddExtensionToCommandLineWhitelist();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000088 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
89 "api_tests_audio.html")) << message_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000090}
91
Ben Murdoch32409262013-08-07 11:04:47 +010092// http://crbug.com/177163 and http://crbug.com/268644
93#if defined(OS_WIN) && (!defined(NDEBUG) || defined(USE_AURA))
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010094#define MAYBE_EndToEnd DISABLED_EndToEnd
95#else
96#define MAYBE_EndToEnd EndToEnd
97#endif
98IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_EndToEnd) {
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010099#if defined(OS_WIN)
100 // TODO(justinlin): Disabled for WinXP due to timeout issues.
101 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
102 return;
103 }
104#endif
105#if defined(OS_MACOSX)
106 // TODO(miu): Disabled for Mac OS X 10.6 due to timeout issues.
107 // http://crbug.com/174640
108 if (base::mac::IsOSSnowLeopard())
109 return;
110#endif
111
112 AddExtensionToCommandLineWhitelist();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000113 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
114 "end_to_end.html")) << message_;
115}
116
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100117// http://crbug.com/177163
118#if defined(OS_WIN) && !defined(NDEBUG)
119#define MAYBE_GetUserMediaTest DISABLED_GetUserMediaTest
120#else
121#define MAYBE_GetUserMediaTest GetUserMediaTest
122#endif
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000123// Test that we can't get tabCapture streams using GetUserMedia directly.
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100124IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_GetUserMediaTest) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000125 ExtensionTestMessageListener listener("ready", true);
126
127 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
128 "get_user_media_test.html")) << message_;
129
130 EXPECT_TRUE(listener.WaitUntilSatisfied());
131
132 content::OpenURLParams params(GURL("about:blank"), content::Referrer(),
133 NEW_FOREGROUND_TAB,
134 content::PAGE_TRANSITION_LINK, false);
135 content::WebContents* web_contents = browser()->OpenURL(params);
136
137 content::RenderViewHost* const rvh = web_contents->GetRenderViewHost();
138 int render_process_id = rvh->GetProcess()->GetID();
139 int routing_id = rvh->GetRoutingID();
140
141 listener.Reply(base::StringPrintf("%i:%i", render_process_id, routing_id));
142
143 ResultCatcher catcher;
144 catcher.RestrictToProfile(browser()->profile());
145 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000146}
147
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100148// http://crbug.com/177163
Ben Murdochbb1529c2013-08-08 10:24:53 +0100149#if defined(OS_WIN)
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100150#define MAYBE_ActiveTabPermission DISABLED_ActiveTabPermission
151#else
152#define MAYBE_ActiveTabPermission ActiveTabPermission
153#endif
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100154// Make sure tabCapture.capture only works if the tab has been granted
155// permission via an extension icon click or the extension is whitelisted.
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100156IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ActiveTabPermission) {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100157 ExtensionTestMessageListener before_open_tab("ready1", true);
158 ExtensionTestMessageListener before_grant_permission("ready2", true);
159 ExtensionTestMessageListener before_open_new_tab("ready3", true);
160 ExtensionTestMessageListener before_whitelist_extension("ready4", true);
161
162 ASSERT_TRUE(RunExtensionSubtest(
163 "tab_capture/experimental", "active_tab_permission_test.html"))
164 << message_;
165
166 // Open a new tab and make sure capture is denied.
167 EXPECT_TRUE(before_open_tab.WaitUntilSatisfied());
168 content::OpenURLParams params(GURL("http://google.com"), content::Referrer(),
169 NEW_FOREGROUND_TAB,
170 content::PAGE_TRANSITION_LINK, false);
171 content::WebContents* web_contents = browser()->OpenURL(params);
172 before_open_tab.Reply("");
173
174 // Grant permission and make sure capture succeeds.
175 EXPECT_TRUE(before_grant_permission.WaitUntilSatisfied());
176 ExtensionService* extension_service =
177 Profile::FromBrowserContext(web_contents->GetBrowserContext())
178 ->GetExtensionService();
179 const extensions::Extension* extension =
180 extension_service->GetExtensionById(kExtensionId, false);
181 extensions::TabHelper::FromWebContents(web_contents)
182 ->active_tab_permission_granter()->GrantIfRequested(extension);
183 before_grant_permission.Reply("");
184
185 // Open a new tab and make sure capture is denied.
186 EXPECT_TRUE(before_open_new_tab.WaitUntilSatisfied());
187 browser()->OpenURL(params);
188 before_open_new_tab.Reply("");
189
190 // Add extension to whitelist and make sure capture succeeds.
191 EXPECT_TRUE(before_whitelist_extension.WaitUntilSatisfied());
192 AddExtensionToCommandLineWhitelist();
193 before_whitelist_extension.Reply("");
194
195 ResultCatcher catcher;
196 catcher.RestrictToProfile(browser()->profile());
197 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
198}
199
Ben Murdocheb525c52013-07-10 11:40:50 +0100200// http://crbug.com/177163
201#if defined(OS_WIN) && !defined(NDEBUG)
202#define MAYBE_FullscreenEvents DISABLED_FullscreenEvents
203#elif defined(USE_AURA) || defined(OS_MACOSX)
204// These don't always fire fullscreen events when run in tests. Tested manually.
205#define MAYBE_FullscreenEvents DISABLED_FullscreenEvents
206#elif defined(OS_LINUX)
207// Flaky to get out of fullscreen in tests. Tested manually.
208#define MAYBE_FullscreenEvents DISABLED_FullscreenEvents
209#else
210#define MAYBE_FullscreenEvents FullscreenEvents
211#endif
212IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_FullscreenEvents) {
213#if defined(OS_WIN)
214 // TODO(justinlin): Disabled for WinXP due to timeout issues.
215 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
216 return;
217 }
218#endif
219
220 AddExtensionToCommandLineWhitelist();
221
222 content::OpenURLParams params(GURL("chrome://version"),
223 content::Referrer(),
224 CURRENT_TAB,
225 content::PAGE_TRANSITION_LINK, false);
226 content::WebContents* web_contents = browser()->OpenURL(params);
227
228 ExtensionTestMessageListener listeners_setup("ready1", true);
229 ExtensionTestMessageListener fullscreen_entered("ready2", true);
230
231 ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental",
232 "fullscreen_test.html")) << message_;
233 EXPECT_TRUE(listeners_setup.WaitUntilSatisfied());
234
235 // Toggle fullscreen after setting up listeners.
236 browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents,
237 true);
238 listeners_setup.Reply("");
239
240 // Toggle again after JS should have the event.
241 EXPECT_TRUE(fullscreen_entered.WaitUntilSatisfied());
242 browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents,
243 false);
244 fullscreen_entered.Reply("");
245
246 ResultCatcher catcher;
247 catcher.RestrictToProfile(browser()->profile());
248 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
249}
250
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000251} // namespace chrome