Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 5 | #include "base/basictypes.h" |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame^] | 6 | #include "base/command_line.h" |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 7 | #if defined(OS_MACOSX) |
| 8 | #include "base/mac/mac_util.h" |
| 9 | #endif |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 10 | #include "base/strings/stringprintf.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 11 | #include "base/win/windows_version.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 12 | #include "chrome/browser/extensions/extension_apitest.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 13 | #include "chrome/browser/extensions/extension_service.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 14 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 15 | #include "chrome/browser/extensions/tab_helper.h" |
| 16 | #include "chrome/browser/profiles/profile.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 17 | #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 18 | #include "chrome/common/chrome_switches.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 19 | #include "chrome/common/chrome_version_info.h" |
| 20 | #include "chrome/common/extensions/feature_switch.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 21 | #include "chrome/common/extensions/features/base_feature_provider.h" |
| 22 | #include "chrome/common/extensions/features/complex_feature.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 23 | #include "chrome/common/extensions/features/feature.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 24 | #include "chrome/common/extensions/features/simple_feature.h" |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame^] | 25 | #include "chrome/test/base/test_switches.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 26 | #include "content/public/browser/render_process_host.h" |
| 27 | #include "content/public/browser/render_view_host.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 28 | #include "content/public/common/content_switches.h" |
| 29 | |
| 30 | namespace chrome { |
| 31 | |
| 32 | namespace { |
| 33 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 34 | const char kExtensionId[] = "ddchlicdkolnonkihahngkmmmjnjlkkf"; |
| 35 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 36 | class TabCaptureApiTest : public ExtensionApiTest { |
| 37 | public: |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 38 | TabCaptureApiTest() {} |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 39 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 40 | void AddExtensionToCommandLineWhitelist() { |
| 41 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 42 | switches::kWhitelistedExtensionID, kExtensionId); |
| 43 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | } // namespace |
| 47 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 48 | // http://crbug.com/261493 |
| 49 | #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
| 50 | #define MAYBE_ApiTests DISABLED_ApiTests |
| 51 | #else |
| 52 | #define MAYBE_ApiTests ApiTests |
| 53 | #endif |
| 54 | IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ApiTests) { |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 55 | #if defined(OS_WIN) && defined(USE_ASH) |
| 56 | // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
Torne (Richard Coles) | a36e592 | 2013-08-05 13:57:33 +0100 | [diff] [blame^] | 57 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 58 | return; |
| 59 | #endif |
| 60 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 61 | extensions::FeatureSwitch::ScopedOverride tab_capture( |
| 62 | extensions::FeatureSwitch::tab_capture(), true); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 63 | |
| 64 | #if defined(OS_WIN) |
| 65 | // TODO(justinlin): Disabled for WinXP due to timeout issues. |
| 66 | if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
| 67 | return; |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | AddExtensionToCommandLineWhitelist(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 72 | ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", |
| 73 | "api_tests.html")) << message_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Torne (Richard Coles) | a93a17c | 2013-05-15 11:34:50 +0100 | [diff] [blame] | 76 | IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, ApiTestsAudio) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 77 | extensions::FeatureSwitch::ScopedOverride tab_capture( |
| 78 | extensions::FeatureSwitch::tab_capture(), true); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 79 | |
| 80 | #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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 88 | ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", |
| 89 | "api_tests_audio.html")) << message_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 92 | // http://crbug.com/177163 |
| 93 | #if defined(OS_WIN) && !defined(NDEBUG) |
| 94 | #define MAYBE_EndToEnd DISABLED_EndToEnd |
| 95 | #else |
| 96 | #define MAYBE_EndToEnd EndToEnd |
| 97 | #endif |
| 98 | IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_EndToEnd) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 99 | extensions::FeatureSwitch::ScopedOverride tab_capture( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 100 | extensions::FeatureSwitch::tab_capture(), true); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 101 | |
| 102 | #if defined(OS_WIN) |
| 103 | // TODO(justinlin): Disabled for WinXP due to timeout issues. |
| 104 | if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
| 105 | return; |
| 106 | } |
| 107 | #endif |
| 108 | #if defined(OS_MACOSX) |
| 109 | // TODO(miu): Disabled for Mac OS X 10.6 due to timeout issues. |
| 110 | // http://crbug.com/174640 |
| 111 | if (base::mac::IsOSSnowLeopard()) |
| 112 | return; |
| 113 | #endif |
| 114 | |
| 115 | AddExtensionToCommandLineWhitelist(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 116 | ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", |
| 117 | "end_to_end.html")) << message_; |
| 118 | } |
| 119 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 120 | // http://crbug.com/177163 |
| 121 | #if defined(OS_WIN) && !defined(NDEBUG) |
| 122 | #define MAYBE_GetUserMediaTest DISABLED_GetUserMediaTest |
| 123 | #else |
| 124 | #define MAYBE_GetUserMediaTest GetUserMediaTest |
| 125 | #endif |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 126 | // Test that we can't get tabCapture streams using GetUserMedia directly. |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 127 | IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_GetUserMediaTest) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 128 | ExtensionTestMessageListener listener("ready", true); |
| 129 | |
| 130 | ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", |
| 131 | "get_user_media_test.html")) << message_; |
| 132 | |
| 133 | EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 134 | |
| 135 | content::OpenURLParams params(GURL("about:blank"), content::Referrer(), |
| 136 | NEW_FOREGROUND_TAB, |
| 137 | content::PAGE_TRANSITION_LINK, false); |
| 138 | content::WebContents* web_contents = browser()->OpenURL(params); |
| 139 | |
| 140 | content::RenderViewHost* const rvh = web_contents->GetRenderViewHost(); |
| 141 | int render_process_id = rvh->GetProcess()->GetID(); |
| 142 | int routing_id = rvh->GetRoutingID(); |
| 143 | |
| 144 | listener.Reply(base::StringPrintf("%i:%i", render_process_id, routing_id)); |
| 145 | |
| 146 | ResultCatcher catcher; |
| 147 | catcher.RestrictToProfile(browser()->profile()); |
| 148 | EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 151 | // http://crbug.com/177163 |
| 152 | #if defined(OS_WIN) && !defined(NDEBUG) |
| 153 | #define MAYBE_ActiveTabPermission DISABLED_ActiveTabPermission |
| 154 | #else |
| 155 | #define MAYBE_ActiveTabPermission ActiveTabPermission |
| 156 | #endif |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 157 | // Make sure tabCapture.capture only works if the tab has been granted |
| 158 | // permission via an extension icon click or the extension is whitelisted. |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 159 | IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ActiveTabPermission) { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 160 | ExtensionTestMessageListener before_open_tab("ready1", true); |
| 161 | ExtensionTestMessageListener before_grant_permission("ready2", true); |
| 162 | ExtensionTestMessageListener before_open_new_tab("ready3", true); |
| 163 | ExtensionTestMessageListener before_whitelist_extension("ready4", true); |
| 164 | |
| 165 | ASSERT_TRUE(RunExtensionSubtest( |
| 166 | "tab_capture/experimental", "active_tab_permission_test.html")) |
| 167 | << message_; |
| 168 | |
| 169 | // Open a new tab and make sure capture is denied. |
| 170 | EXPECT_TRUE(before_open_tab.WaitUntilSatisfied()); |
| 171 | content::OpenURLParams params(GURL("http://google.com"), content::Referrer(), |
| 172 | NEW_FOREGROUND_TAB, |
| 173 | content::PAGE_TRANSITION_LINK, false); |
| 174 | content::WebContents* web_contents = browser()->OpenURL(params); |
| 175 | before_open_tab.Reply(""); |
| 176 | |
| 177 | // Grant permission and make sure capture succeeds. |
| 178 | EXPECT_TRUE(before_grant_permission.WaitUntilSatisfied()); |
| 179 | ExtensionService* extension_service = |
| 180 | Profile::FromBrowserContext(web_contents->GetBrowserContext()) |
| 181 | ->GetExtensionService(); |
| 182 | const extensions::Extension* extension = |
| 183 | extension_service->GetExtensionById(kExtensionId, false); |
| 184 | extensions::TabHelper::FromWebContents(web_contents) |
| 185 | ->active_tab_permission_granter()->GrantIfRequested(extension); |
| 186 | before_grant_permission.Reply(""); |
| 187 | |
| 188 | // Open a new tab and make sure capture is denied. |
| 189 | EXPECT_TRUE(before_open_new_tab.WaitUntilSatisfied()); |
| 190 | browser()->OpenURL(params); |
| 191 | before_open_new_tab.Reply(""); |
| 192 | |
| 193 | // Add extension to whitelist and make sure capture succeeds. |
| 194 | EXPECT_TRUE(before_whitelist_extension.WaitUntilSatisfied()); |
| 195 | AddExtensionToCommandLineWhitelist(); |
| 196 | before_whitelist_extension.Reply(""); |
| 197 | |
| 198 | ResultCatcher catcher; |
| 199 | catcher.RestrictToProfile(browser()->profile()); |
| 200 | EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 201 | } |
| 202 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 203 | // http://crbug.com/177163 |
| 204 | #if defined(OS_WIN) && !defined(NDEBUG) |
| 205 | #define MAYBE_FullscreenEvents DISABLED_FullscreenEvents |
| 206 | #elif defined(USE_AURA) || defined(OS_MACOSX) |
| 207 | // These don't always fire fullscreen events when run in tests. Tested manually. |
| 208 | #define MAYBE_FullscreenEvents DISABLED_FullscreenEvents |
| 209 | #elif defined(OS_LINUX) |
| 210 | // Flaky to get out of fullscreen in tests. Tested manually. |
| 211 | #define MAYBE_FullscreenEvents DISABLED_FullscreenEvents |
| 212 | #else |
| 213 | #define MAYBE_FullscreenEvents FullscreenEvents |
| 214 | #endif |
| 215 | IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_FullscreenEvents) { |
| 216 | #if defined(OS_WIN) |
| 217 | // TODO(justinlin): Disabled for WinXP due to timeout issues. |
| 218 | if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
| 219 | return; |
| 220 | } |
| 221 | #endif |
| 222 | |
| 223 | AddExtensionToCommandLineWhitelist(); |
| 224 | |
| 225 | content::OpenURLParams params(GURL("chrome://version"), |
| 226 | content::Referrer(), |
| 227 | CURRENT_TAB, |
| 228 | content::PAGE_TRANSITION_LINK, false); |
| 229 | content::WebContents* web_contents = browser()->OpenURL(params); |
| 230 | |
| 231 | ExtensionTestMessageListener listeners_setup("ready1", true); |
| 232 | ExtensionTestMessageListener fullscreen_entered("ready2", true); |
| 233 | |
| 234 | ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", |
| 235 | "fullscreen_test.html")) << message_; |
| 236 | EXPECT_TRUE(listeners_setup.WaitUntilSatisfied()); |
| 237 | |
| 238 | // Toggle fullscreen after setting up listeners. |
| 239 | browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents, |
| 240 | true); |
| 241 | listeners_setup.Reply(""); |
| 242 | |
| 243 | // Toggle again after JS should have the event. |
| 244 | EXPECT_TRUE(fullscreen_entered.WaitUntilSatisfied()); |
| 245 | browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents, |
| 246 | false); |
| 247 | fullscreen_entered.Reply(""); |
| 248 | |
| 249 | ResultCatcher catcher; |
| 250 | catcher.RestrictToProfile(browser()->profile()); |
| 251 | EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 252 | } |
| 253 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 254 | } // namespace chrome |