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" |
| 6 | #if defined(OS_MACOSX) |
| 7 | #include "base/mac/mac_util.h" |
| 8 | #endif |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 9 | #include "base/strings/stringprintf.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 10 | #include "base/win/windows_version.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_apitest.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 12 | #include "chrome/browser/extensions/extension_service.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 13 | #include "chrome/browser/extensions/extension_test_message_listener.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 14 | #include "chrome/browser/extensions/tab_helper.h" |
| 15 | #include "chrome/browser/profiles/profile.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 16 | #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 17 | #include "chrome/common/chrome_switches.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 18 | #include "chrome/common/chrome_version_info.h" |
| 19 | #include "chrome/common/extensions/feature_switch.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 20 | #include "chrome/common/extensions/features/base_feature_provider.h" |
| 21 | #include "chrome/common/extensions/features/complex_feature.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 22 | #include "chrome/common/extensions/features/feature.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 23 | #include "chrome/common/extensions/features/simple_feature.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 24 | #include "content/public/browser/render_process_host.h" |
| 25 | #include "content/public/browser/render_view_host.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 26 | #include "content/public/common/content_switches.h" |
| 27 | |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 28 | #if defined(OS_WIN) && defined(USE_ASH) |
| 29 | #include "base/win/windows_version.h" |
| 30 | #endif |
| 31 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 32 | namespace chrome { |
| 33 | |
| 34 | namespace { |
| 35 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 36 | const char kExtensionId[] = "ddchlicdkolnonkihahngkmmmjnjlkkf"; |
| 37 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 38 | class TabCaptureApiTest : public ExtensionApiTest { |
| 39 | public: |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 40 | TabCaptureApiTest() {} |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 41 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 42 | void AddExtensionToCommandLineWhitelist() { |
| 43 | CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 44 | switches::kWhitelistedExtensionID, kExtensionId); |
| 45 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | } // namespace |
| 49 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 50 | // 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 |
| 56 | IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ApiTests) { |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 57 | #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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 63 | extensions::FeatureSwitch::ScopedOverride tab_capture( |
| 64 | extensions::FeatureSwitch::tab_capture(), true); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 65 | |
| 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 74 | ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", |
| 75 | "api_tests.html")) << message_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Torne (Richard Coles) | a93a17c | 2013-05-15 11:34:50 +0100 | [diff] [blame] | 78 | IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, ApiTestsAudio) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 79 | extensions::FeatureSwitch::ScopedOverride tab_capture( |
| 80 | extensions::FeatureSwitch::tab_capture(), true); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 81 | |
| 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 90 | ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", |
| 91 | "api_tests_audio.html")) << message_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 94 | // 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 |
| 100 | IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_EndToEnd) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 101 | extensions::FeatureSwitch::ScopedOverride tab_capture( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 102 | extensions::FeatureSwitch::tab_capture(), true); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 103 | |
| 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 118 | ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", |
| 119 | "end_to_end.html")) << message_; |
| 120 | } |
| 121 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 122 | // 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) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 128 | // Test that we can't get tabCapture streams using GetUserMedia directly. |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 129 | IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_GetUserMediaTest) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 130 | 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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 153 | // 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) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 159 | // 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) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 161 | IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ActiveTabPermission) { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 162 | 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 Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 205 | // 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 |
| 217 | IN_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) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 256 | } // namespace chrome |