tab_capture_apitest.cc revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/basictypes.h" 6a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/command_line.h" 77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#if defined(OS_MACOSX) 87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/mac/mac_util.h" 97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif 10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/stringprintf.h" 11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/win/windows_version.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/extension_apitest.h" 13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/extensions/extension_service.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/extensions/extension_test_message_listener.h" 15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/extensions/tab_helper.h" 16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/profiles/profile.h" 17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/common/chrome_switches.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_version_info.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/extensions/feature_switch.h" 21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/common/extensions/features/base_feature_provider.h" 22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/common/extensions/features/complex_feature.h" 23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/common/extensions/features/simple_feature.h" 24a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/test/base/test_switches.h" 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/render_process_host.h" 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/render_view_host.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/content_switches.h" 283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "extensions/common/features/feature.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kExtensionId[] = "ddchlicdkolnonkihahngkmmmjnjlkkf"; 33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TabCaptureApiTest : public ExtensionApiTest { 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) TabCaptureApiTest() {} 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 38c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch virtual void SetUp() OVERRIDE { 39c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch // TODO(danakj): The GPU Video Decoder needs real GL bindings. 40c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch // crbug.com/269087 41c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch UseRealGLBindings(); 42c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch 43c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch ExtensionApiTest::SetUp(); 44c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch } 45c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch 46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void AddExtensionToCommandLineWhitelist() { 47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) CommandLine::ForCurrentProcess()->AppendSwitchASCII( 48c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) switches::kWhitelistedExtensionID, kExtensionId); 49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 543240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch// http://crbug.com/261493 and http://crbug.com/268644 553240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(USE_AURA) 56ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#define MAYBE_ApiTests DISABLED_ApiTests 57ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#else 58ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#define MAYBE_ApiTests ApiTests 59ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#endif 60ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben MurdochIN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ApiTests) { 61558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#if defined(OS_WIN) && defined(USE_ASH) 62558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // Disable this test in Metro+Ash for now (http://crbug.com/262796). 63a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 64558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch return; 65558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif 66558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 67c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(OS_WIN) 68c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // TODO(justinlin): Disabled for WinXP due to timeout issues. 69c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (base::win::GetVersion() < base::win::VERSION_VISTA) { 70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 72c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif 73c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddExtensionToCommandLineWhitelist(); 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "api_tests.html")) << message_; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 793240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch// http://crbug.com/268644 803240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#if defined(USE_AURA) 813240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#define MAYBE_ApiTestsAudio DISABLED_ApiTestsAudio 823240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#else 833240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#define MAYBE_ApiTestsAudio ApiTestsAudio 843240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#endif 853240926e260ce088908e02ac07a6cf7b0c0cbf44Ben MurdochIN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ApiTestsAudio) { 86c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(OS_WIN) 87c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // TODO(justinlin): Disabled for WinXP due to timeout issues. 88c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (base::win::GetVersion() < base::win::VERSION_VISTA) { 89c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return; 90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif 92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 93c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddExtensionToCommandLineWhitelist(); 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "api_tests_audio.html")) << message_; 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 983240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch// http://crbug.com/177163 and http://crbug.com/268644 993240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#if defined(OS_WIN) && (!defined(NDEBUG) || defined(USE_AURA)) 1007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#define MAYBE_EndToEnd DISABLED_EndToEnd 1017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#else 1027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#define MAYBE_EndToEnd EndToEnd 1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif 1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_EndToEnd) { 1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#if defined(OS_WIN) 1067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // TODO(justinlin): Disabled for WinXP due to timeout issues. 1077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (base::win::GetVersion() < base::win::VERSION_VISTA) { 1087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return; 1097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 1107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif 1117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#if defined(OS_MACOSX) 1127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // TODO(miu): Disabled for Mac OS X 10.6 due to timeout issues. 1137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // http://crbug.com/174640 1147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) if (base::mac::IsOSSnowLeopard()) 1157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return; 1167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif 1177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) AddExtensionToCommandLineWhitelist(); 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "end_to_end.html")) << message_; 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// http://crbug.com/177163 124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#if defined(OS_WIN) && !defined(NDEBUG) 125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define MAYBE_GetUserMediaTest DISABLED_GetUserMediaTest 126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#else 127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define MAYBE_GetUserMediaTest GetUserMediaTest 128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Test that we can't get tabCapture streams using GetUserMedia directly. 130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_GetUserMediaTest) { 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ExtensionTestMessageListener listener("ready", true); 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "get_user_media_test.html")) << message_; 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(listener.WaitUntilSatisfied()); 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::OpenURLParams params(GURL("about:blank"), content::Referrer(), 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NEW_FOREGROUND_TAB, 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::PAGE_TRANSITION_LINK, false); 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::WebContents* web_contents = browser()->OpenURL(params); 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::RenderViewHost* const rvh = web_contents->GetRenderViewHost(); 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int render_process_id = rvh->GetProcess()->GetID(); 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int routing_id = rvh->GetRoutingID(); 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) listener.Reply(base::StringPrintf("%i:%i", render_process_id, routing_id)); 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ResultCatcher catcher; 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) catcher.RestrictToProfile(browser()->profile()); 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 154868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// http://crbug.com/177163 155bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#if defined(OS_WIN) 156868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define MAYBE_ActiveTabPermission DISABLED_ActiveTabPermission 157868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#else 158868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define MAYBE_ActiveTabPermission ActiveTabPermission 159868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif 160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Make sure tabCapture.capture only works if the tab has been granted 161c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// permission via an extension icon click or the extension is whitelisted. 162868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_ActiveTabPermission) { 163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ExtensionTestMessageListener before_open_tab("ready1", true); 164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ExtensionTestMessageListener before_grant_permission("ready2", true); 165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ExtensionTestMessageListener before_open_new_tab("ready3", true); 166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ExtensionTestMessageListener before_whitelist_extension("ready4", true); 167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 168c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ASSERT_TRUE(RunExtensionSubtest( 169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "tab_capture/experimental", "active_tab_permission_test.html")) 170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) << message_; 171c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 172c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Open a new tab and make sure capture is denied. 173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(before_open_tab.WaitUntilSatisfied()); 174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::OpenURLParams params(GURL("http://google.com"), content::Referrer(), 175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) NEW_FOREGROUND_TAB, 176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::PAGE_TRANSITION_LINK, false); 177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::WebContents* web_contents = browser()->OpenURL(params); 178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) before_open_tab.Reply(""); 179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 180c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Grant permission and make sure capture succeeds. 181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(before_grant_permission.WaitUntilSatisfied()); 182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ExtensionService* extension_service = 183c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) Profile::FromBrowserContext(web_contents->GetBrowserContext()) 184c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ->GetExtensionService(); 185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const extensions::Extension* extension = 186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) extension_service->GetExtensionById(kExtensionId, false); 187c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) extensions::TabHelper::FromWebContents(web_contents) 188c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ->active_tab_permission_granter()->GrantIfRequested(extension); 189c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) before_grant_permission.Reply(""); 190c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Open a new tab and make sure capture is denied. 192c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(before_open_new_tab.WaitUntilSatisfied()); 193c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) browser()->OpenURL(params); 194c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) before_open_new_tab.Reply(""); 195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 196c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Add extension to whitelist and make sure capture succeeds. 197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(before_whitelist_extension.WaitUntilSatisfied()); 198c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AddExtensionToCommandLineWhitelist(); 199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) before_whitelist_extension.Reply(""); 200c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 201c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ResultCatcher catcher; 202c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) catcher.RestrictToProfile(browser()->profile()); 203c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 204c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 206eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// http://crbug.com/177163 207eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if defined(OS_WIN) && !defined(NDEBUG) 208eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#define MAYBE_FullscreenEvents DISABLED_FullscreenEvents 209eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#elif defined(USE_AURA) || defined(OS_MACOSX) 210eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// These don't always fire fullscreen events when run in tests. Tested manually. 211eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#define MAYBE_FullscreenEvents DISABLED_FullscreenEvents 212eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#elif defined(OS_LINUX) 213eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Flaky to get out of fullscreen in tests. Tested manually. 214eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#define MAYBE_FullscreenEvents DISABLED_FullscreenEvents 215eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#else 216eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#define MAYBE_FullscreenEvents FullscreenEvents 217eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif 218eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochIN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_FullscreenEvents) { 219eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if defined(OS_WIN) 220eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // TODO(justinlin): Disabled for WinXP due to timeout issues. 221eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch if (base::win::GetVersion() < base::win::VERSION_VISTA) { 222eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch return; 223eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch } 224eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif 225eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 226eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch AddExtensionToCommandLineWhitelist(); 227eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 228eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content::OpenURLParams params(GURL("chrome://version"), 229eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content::Referrer(), 230eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch CURRENT_TAB, 231eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content::PAGE_TRANSITION_LINK, false); 232eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch content::WebContents* web_contents = browser()->OpenURL(params); 233eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 234eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ExtensionTestMessageListener listeners_setup("ready1", true); 235eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ExtensionTestMessageListener fullscreen_entered("ready2", true); 236eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 237eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", 238eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch "fullscreen_test.html")) << message_; 239eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(listeners_setup.WaitUntilSatisfied()); 240eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 241eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Toggle fullscreen after setting up listeners. 242eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents, 243eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch true); 244eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch listeners_setup.Reply(""); 245eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 246eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Toggle again after JS should have the event. 247eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(fullscreen_entered.WaitUntilSatisfied()); 248eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch browser()->fullscreen_controller()->ToggleFullscreenModeForTab(web_contents, 249eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch false); 250eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch fullscreen_entered.Reply(""); 251eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 252eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch ResultCatcher catcher; 253eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch catcher.RestrictToProfile(browser()->profile()); 254eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 256eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 257d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Times out on Win dbg bots: http://crbug.com/177163 258d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// #if defined(OS_WIN) && !defined(NDEBUG) 259d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Times out on all Win bots: http://crbug.com/294431 260d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#if defined(OS_WIN) 261d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#define MAYBE_GrantForChromePages DISABLED_GrantForChromePages 262d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#else 263d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#define MAYBE_GrantForChromePages GrantForChromePages 264d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#endif 265d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Make sure tabCapture API can be granted for Chrome:// pages. 266d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_GrantForChromePages) { 267d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ExtensionTestMessageListener before_open_tab("ready1", true); 268d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", 269d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) "active_tab_chrome_pages.html")) << message_; 270d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_TRUE(before_open_tab.WaitUntilSatisfied()); 271d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 272d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Open a tab on a chrome:// page and make sure we can capture. 273d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) content::OpenURLParams params(GURL("chrome://version"), content::Referrer(), 274d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) NEW_FOREGROUND_TAB, 275d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) content::PAGE_TRANSITION_LINK, false); 276d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) content::WebContents* web_contents = browser()->OpenURL(params); 277d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ExtensionService* extension_service = 278d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Profile::FromBrowserContext(web_contents->GetBrowserContext()) 279d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ->GetExtensionService(); 280d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) extensions::TabHelper::FromWebContents(web_contents) 281d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ->active_tab_permission_granter()->GrantIfRequested( 282d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) extension_service->GetExtensionById(kExtensionId, false)); 283d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) before_open_tab.Reply(""); 284d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 285d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ResultCatcher catcher; 286d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) catcher.RestrictToProfile(browser()->profile()); 287d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 288d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 289d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 2904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#if defined(OS_WIN) 2914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#define MAYBE_CaptureInSplitIncognitoMode DISABLED_CaptureInSplitIncognitoMode 2924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#else 2934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#define MAYBE_CaptureInSplitIncognitoMode CaptureInSplitIncognitoMode 2944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif 2954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Test that a tab can be captured in split incognito mode. 2964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(TabCaptureApiTest, MAYBE_CaptureInSplitIncognitoMode) { 2974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AddExtensionToCommandLineWhitelist(); 2984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_TRUE(RunExtensionSubtest("tab_capture/experimental", 2994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) "incognito.html", 3004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) kFlagEnableIncognito | kFlagUseIncognito)) 3014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) << message_; 3024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 303