Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: chrome/browser/policy/policy_browsertest.cc

Issue 15738004: Add a policy list for access to capture devices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only allow the whitelist policy when kioskmode is enabled. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 // ShowHomeButton has policy ID 35. 1958 // ShowHomeButton has policy ID 35.
1959 EXPECT_NE(std::string::npos, text.find("<br>35 ---")); 1959 EXPECT_NE(std::string::npos, text.find("<br>35 ---"));
1960 // BookmarkBarEnabled has policy ID 82. 1960 // BookmarkBarEnabled has policy ID 82.
1961 EXPECT_NE(std::string::npos, text.find("<br>82 ---")); 1961 EXPECT_NE(std::string::npos, text.find("<br>82 ---"));
1962 } 1962 }
1963 1963
1964 class MediaStreamDevicesControllerBrowserTest 1964 class MediaStreamDevicesControllerBrowserTest
1965 : public PolicyTest, 1965 : public PolicyTest,
1966 public testing::WithParamInterface<bool> { 1966 public testing::WithParamInterface<bool> {
1967 public: 1967 public:
1968 MediaStreamDevicesControllerBrowserTest() { 1968 MediaStreamDevicesControllerBrowserTest()
1969 : request_url_allowed_via_whitelist_(false) {
1969 policy_value_ = GetParam(); 1970 policy_value_ = GetParam();
1970 } 1971 }
1971 virtual ~MediaStreamDevicesControllerBrowserTest() {} 1972 virtual ~MediaStreamDevicesControllerBrowserTest() {}
1972 1973
1974 // Configure a given policy map.
1975 // The |policy_name| is the name of either the audio or video capture allow
1976 // policy and must never be NULL.
1977 // |whitelist_policy| is optional. If NULL, no whitelist policy is set.
1978 // If non-NULL, the request_url_ will be set to be non empty and a matching
1979 // policy that allows the request url, will be set.
1980 void ConfigurePolicyMap(PolicyMap* policies, const char* policy_name,
1981 const char* whitelist_policy) {
1982 policies->Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
1983 base::Value::CreateBooleanValue(policy_value_));
1984
1985 if (whitelist_policy) {
1986 // TODO(tommi): Remove the kiosk mode flag when the whitelist is visible
1987 // in the media exceptions UI.
1988 // See discussion here: https://codereview.chromium.org/15738004/
1989 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kKioskMode);
1990
1991 // Add an entry to the whitelist that allows the specified URL regardless
1992 // of the setting of kAudioCapturedAllowed.
1993 request_url_ = GURL("http://www.example.com/foo");
1994 const char kRequestPattern[] = "http://[*.]example.com/";
1995 base::ListValue* list = new base::ListValue();
1996 list->AppendString(kRequestPattern);
1997 policies->Set(whitelist_policy, POLICY_LEVEL_MANDATORY,
1998 POLICY_SCOPE_USER, list);
1999 request_url_allowed_via_whitelist_ = true;
2000 }
2001 }
2002
1973 void Accept(const content::MediaStreamDevices& devices, 2003 void Accept(const content::MediaStreamDevices& devices,
1974 scoped_ptr<content::MediaStreamUI> ui) { 2004 scoped_ptr<content::MediaStreamUI> ui) {
1975 if (policy_value_) { 2005 if (policy_value_ || request_url_allowed_via_whitelist_) {
1976 ASSERT_EQ(1U, devices.size()); 2006 ASSERT_EQ(1U, devices.size());
1977 ASSERT_EQ("fake_dev", devices[0].id); 2007 ASSERT_EQ("fake_dev", devices[0].id);
1978 } else { 2008 } else {
1979 ASSERT_EQ(0U, devices.size()); 2009 ASSERT_EQ(0U, devices.size());
1980 } 2010 }
1981 } 2011 }
1982 2012
1983 void FinishAudioTest() { 2013 void FinishAudioTest() {
1984 content::MediaStreamRequest request(0, 0, GURL(), 2014 content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(),
1985 content::MEDIA_OPEN_DEVICE, "fake_dev", 2015 content::MEDIA_OPEN_DEVICE, "fake_dev",
1986 content::MEDIA_DEVICE_AUDIO_CAPTURE, 2016 content::MEDIA_DEVICE_AUDIO_CAPTURE,
1987 content::MEDIA_NO_SERVICE); 2017 content::MEDIA_NO_SERVICE);
1988 MediaStreamDevicesController controller( 2018 MediaStreamDevicesController controller(
1989 browser()->tab_strip_model()->GetActiveWebContents(), request, 2019 browser()->tab_strip_model()->GetActiveWebContents(), request,
1990 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); 2020 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this));
1991 controller.DismissInfoBarAndTakeActionOnSettings(); 2021 controller.DismissInfoBarAndTakeActionOnSettings();
1992 2022
1993 MessageLoop::current()->QuitWhenIdle(); 2023 MessageLoop::current()->QuitWhenIdle();
1994 } 2024 }
1995 2025
1996 void FinishVideoTest() { 2026 void FinishVideoTest() {
1997 content::MediaStreamRequest request(0, 0, GURL(), 2027 content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(),
1998 content::MEDIA_OPEN_DEVICE, "fake_dev", 2028 content::MEDIA_OPEN_DEVICE, "fake_dev",
1999 content::MEDIA_NO_SERVICE, 2029 content::MEDIA_NO_SERVICE,
2000 content::MEDIA_DEVICE_VIDEO_CAPTURE); 2030 content::MEDIA_DEVICE_VIDEO_CAPTURE);
2001 MediaStreamDevicesController controller( 2031 MediaStreamDevicesController controller(
2002 browser()->tab_strip_model()->GetActiveWebContents(), request, 2032 browser()->tab_strip_model()->GetActiveWebContents(), request,
2003 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); 2033 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this));
2004 controller.DismissInfoBarAndTakeActionOnSettings(); 2034 controller.DismissInfoBarAndTakeActionOnSettings();
2005 2035
2006 MessageLoop::current()->QuitWhenIdle(); 2036 MessageLoop::current()->QuitWhenIdle();
2007 } 2037 }
2008 2038
2009 bool policy_value_; 2039 bool policy_value_;
2040 bool request_url_allowed_via_whitelist_;
2041 GURL request_url_;
2010 }; 2042 };
2011 2043
2012 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, 2044 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest,
2013 AudioCaptureAllowed) { 2045 AudioCaptureAllowed) {
2014 content::MediaStreamDevices audio_devices; 2046 content::MediaStreamDevices audio_devices;
2015 content::MediaStreamDevice fake_audio_device( 2047 content::MediaStreamDevice fake_audio_device(
2016 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); 2048 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device");
2017 audio_devices.push_back(fake_audio_device); 2049 audio_devices.push_back(fake_audio_device);
2018 2050
2019 PolicyMap policies; 2051 PolicyMap policies;
2020 policies.Set(key::kAudioCaptureAllowed, POLICY_LEVEL_MANDATORY, 2052 ConfigurePolicyMap(&policies, key::kAudioCaptureAllowed, NULL);
2021 POLICY_SCOPE_USER,
2022 base::Value::CreateBooleanValue(policy_value_));
2023 UpdateProviderPolicy(policies); 2053 UpdateProviderPolicy(policies);
2024 2054
2025 content::BrowserThread::PostTaskAndReply( 2055 content::BrowserThread::PostTaskAndReply(
2056 content::BrowserThread::IO, FROM_HERE,
2057 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged,
2058 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()),
2059 audio_devices),
2060 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest,
2061 this));
2062
2063 MessageLoop::current()->Run();
2064 }
2065
2066 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest,
2067 AudioCaptureAllowedUrls) {
2068 content::MediaStreamDevices audio_devices;
2069 content::MediaStreamDevice fake_audio_device(
2070 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device");
2071 audio_devices.push_back(fake_audio_device);
2072
2073 PolicyMap policies;
2074 ConfigurePolicyMap(&policies, key::kAudioCaptureAllowed,
2075 key::kAudioCaptureAllowedUrls);
2076 UpdateProviderPolicy(policies);
2077
2078 content::BrowserThread::PostTaskAndReply(
2026 content::BrowserThread::IO, FROM_HERE, 2079 content::BrowserThread::IO, FROM_HERE,
2027 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, 2080 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged,
2028 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), 2081 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()),
2029 audio_devices), 2082 audio_devices),
2030 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, 2083 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest,
2031 this)); 2084 this));
2032 2085
2033 MessageLoop::current()->Run(); 2086 MessageLoop::current()->Run();
2034 } 2087 }
2035 2088
2036 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, 2089 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest,
2037 VideoCaptureAllowed) { 2090 VideoCaptureAllowed) {
2038 content::MediaStreamDevices video_devices; 2091 content::MediaStreamDevices video_devices;
2039 content::MediaStreamDevice fake_video_device( 2092 content::MediaStreamDevice fake_video_device(
2040 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); 2093 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device");
2041 video_devices.push_back(fake_video_device); 2094 video_devices.push_back(fake_video_device);
2042 2095
2043 PolicyMap policies; 2096 PolicyMap policies;
2044 policies.Set(key::kVideoCaptureAllowed, POLICY_LEVEL_MANDATORY, 2097 ConfigurePolicyMap(&policies, key::kVideoCaptureAllowed, NULL);
2045 POLICY_SCOPE_USER,
2046 base::Value::CreateBooleanValue(policy_value_));
2047 UpdateProviderPolicy(policies); 2098 UpdateProviderPolicy(policies);
2048 2099
2049 content::BrowserThread::PostTaskAndReply( 2100 content::BrowserThread::PostTaskAndReply(
2101 content::BrowserThread::IO, FROM_HERE,
2102 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged,
2103 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()),
2104 video_devices),
2105 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest,
2106 this));
2107
2108 MessageLoop::current()->Run();
2109 }
2110
2111 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest,
2112 VideoCaptureAllowedUrls) {
2113 content::MediaStreamDevices video_devices;
2114 content::MediaStreamDevice fake_video_device(
2115 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device");
2116 video_devices.push_back(fake_video_device);
2117
2118 PolicyMap policies;
2119 ConfigurePolicyMap(&policies, key::kVideoCaptureAllowed,
2120 key::kVideoCaptureAllowedUrls);
2121 UpdateProviderPolicy(policies);
2122
2123 content::BrowserThread::PostTaskAndReply(
2050 content::BrowserThread::IO, FROM_HERE, 2124 content::BrowserThread::IO, FROM_HERE,
2051 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, 2125 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged,
2052 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), 2126 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()),
2053 video_devices), 2127 video_devices),
2054 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, 2128 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest,
2055 this)); 2129 this));
2056 2130
2057 MessageLoop::current()->Run(); 2131 MessageLoop::current()->Run();
2058 } 2132 }
2059 2133
(...skipping 27 matching lines...) Expand all
2087 chrome_variations::VariationsService::GetVariationsServerURL( 2161 chrome_variations::VariationsService::GetVariationsServerURL(
2088 g_browser_process->local_state()); 2162 g_browser_process->local_state());
2089 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); 2163 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true));
2090 std::string value; 2164 std::string value;
2091 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); 2165 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
2092 EXPECT_EQ("restricted", value); 2166 EXPECT_EQ("restricted", value);
2093 } 2167 }
2094 #endif 2168 #endif
2095 2169
2096 } // namespace policy 2170 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698