OLD | NEW |
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #include "chrome/browser/ui/host_desktop.h" | 59 #include "chrome/browser/ui/host_desktop.h" |
60 #include "chrome/browser/ui/omnibox/location_bar.h" | 60 #include "chrome/browser/ui/omnibox/location_bar.h" |
61 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 61 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
62 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 62 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
63 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 63 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
64 #include "chrome/common/chrome_notification_types.h" | 64 #include "chrome/common/chrome_notification_types.h" |
65 #include "chrome/common/chrome_paths.h" | 65 #include "chrome/common/chrome_paths.h" |
66 #include "chrome/common/chrome_process_type.h" | 66 #include "chrome/common/chrome_process_type.h" |
67 #include "chrome/common/chrome_switches.h" | 67 #include "chrome/common/chrome_switches.h" |
68 #include "chrome/common/content_settings.h" | 68 #include "chrome/common/content_settings.h" |
| 69 #include "chrome/common/content_settings_pattern.h" |
69 #include "chrome/common/extensions/extension.h" | 70 #include "chrome/common/extensions/extension.h" |
70 #include "chrome/common/extensions/extension_constants.h" | 71 #include "chrome/common/extensions/extension_constants.h" |
71 #include "chrome/common/pref_names.h" | 72 #include "chrome/common/pref_names.h" |
72 #include "chrome/common/url_constants.h" | 73 #include "chrome/common/url_constants.h" |
73 #include "chrome/test/base/in_process_browser_test.h" | 74 #include "chrome/test/base/in_process_browser_test.h" |
74 #include "chrome/test/base/ui_test_utils.h" | 75 #include "chrome/test/base/ui_test_utils.h" |
75 #include "content/public/browser/browser_child_process_host_iterator.h" | 76 #include "content/public/browser/browser_child_process_host_iterator.h" |
76 #include "content/public/browser/browser_context.h" | 77 #include "content/public/browser/browser_context.h" |
77 #include "content/public/browser/browser_thread.h" | 78 #include "content/public/browser/browser_thread.h" |
78 #include "content/public/browser/child_process_data.h" | 79 #include "content/public/browser/child_process_data.h" |
(...skipping 1906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1985 // ShowHomeButton has policy ID 35. | 1986 // ShowHomeButton has policy ID 35. |
1986 EXPECT_NE(std::string::npos, text.find("<br>35 ---")); | 1987 EXPECT_NE(std::string::npos, text.find("<br>35 ---")); |
1987 // BookmarkBarEnabled has policy ID 82. | 1988 // BookmarkBarEnabled has policy ID 82. |
1988 EXPECT_NE(std::string::npos, text.find("<br>82 ---")); | 1989 EXPECT_NE(std::string::npos, text.find("<br>82 ---")); |
1989 } | 1990 } |
1990 | 1991 |
1991 class MediaStreamDevicesControllerBrowserTest | 1992 class MediaStreamDevicesControllerBrowserTest |
1992 : public PolicyTest, | 1993 : public PolicyTest, |
1993 public testing::WithParamInterface<bool> { | 1994 public testing::WithParamInterface<bool> { |
1994 public: | 1995 public: |
1995 MediaStreamDevicesControllerBrowserTest() { | 1996 MediaStreamDevicesControllerBrowserTest() |
| 1997 : request_url_allowed_via_whitelist_(false) { |
1996 policy_value_ = GetParam(); | 1998 policy_value_ = GetParam(); |
1997 } | 1999 } |
1998 virtual ~MediaStreamDevicesControllerBrowserTest() {} | 2000 virtual ~MediaStreamDevicesControllerBrowserTest() {} |
1999 | 2001 |
| 2002 // Configure a given policy map. |
| 2003 // The |policy_name| is the name of either the audio or video capture allow |
| 2004 // policy and must never be NULL. |
| 2005 // |whitelist_policy| and |allow_rule| are optional. If NULL, no whitelist |
| 2006 // policy is set. If non-NULL, the request_url_ will be set to be non empty |
| 2007 // and the whitelist policy is set to contain either the |allow_rule| (if |
| 2008 // non-NULL) or an "allow all" wildcard. |
| 2009 void ConfigurePolicyMap(PolicyMap* policies, const char* policy_name, |
| 2010 const char* whitelist_policy, |
| 2011 const char* allow_rule) { |
| 2012 policies->Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 2013 base::Value::CreateBooleanValue(policy_value_)); |
| 2014 |
| 2015 if (whitelist_policy) { |
| 2016 // TODO(tommi): Remove the kiosk mode flag when the whitelist is visible |
| 2017 // in the media exceptions UI. |
| 2018 // See discussion here: https://codereview.chromium.org/15738004/ |
| 2019 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kKioskMode); |
| 2020 |
| 2021 // Add an entry to the whitelist that allows the specified URL regardless |
| 2022 // of the setting of kAudioCapturedAllowed. |
| 2023 request_url_ = GURL("http://www.example.com/foo"); |
| 2024 base::ListValue* list = new base::ListValue(); |
| 2025 if (allow_rule) { |
| 2026 list->AppendString(allow_rule); |
| 2027 request_url_allowed_via_whitelist_ = true; |
| 2028 } else { |
| 2029 list->AppendString(ContentSettingsPattern::Wildcard().ToString()); |
| 2030 // We should ignore all wildcard entries in the whitelist, so even |
| 2031 // though we've added an entry, it should be ignored and our expectation |
| 2032 // is that the request has not been allowed via the whitelist. |
| 2033 request_url_allowed_via_whitelist_ = false; |
| 2034 } |
| 2035 policies->Set(whitelist_policy, POLICY_LEVEL_MANDATORY, |
| 2036 POLICY_SCOPE_USER, list); |
| 2037 } |
| 2038 } |
| 2039 |
2000 void Accept(const content::MediaStreamDevices& devices, | 2040 void Accept(const content::MediaStreamDevices& devices, |
2001 scoped_ptr<content::MediaStreamUI> ui) { | 2041 scoped_ptr<content::MediaStreamUI> ui) { |
2002 if (policy_value_) { | 2042 if (policy_value_ || request_url_allowed_via_whitelist_) { |
2003 ASSERT_EQ(1U, devices.size()); | 2043 ASSERT_EQ(1U, devices.size()); |
2004 ASSERT_EQ("fake_dev", devices[0].id); | 2044 ASSERT_EQ("fake_dev", devices[0].id); |
2005 } else { | 2045 } else { |
2006 ASSERT_EQ(0U, devices.size()); | 2046 ASSERT_EQ(0U, devices.size()); |
2007 } | 2047 } |
2008 } | 2048 } |
2009 | 2049 |
2010 void FinishAudioTest() { | 2050 void FinishAudioTest() { |
2011 content::MediaStreamRequest request(0, 0, GURL(), | 2051 content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(), |
2012 content::MEDIA_OPEN_DEVICE, "fake_dev", | 2052 content::MEDIA_OPEN_DEVICE, "fake_dev", |
2013 content::MEDIA_DEVICE_AUDIO_CAPTURE, | 2053 content::MEDIA_DEVICE_AUDIO_CAPTURE, |
2014 content::MEDIA_NO_SERVICE); | 2054 content::MEDIA_NO_SERVICE); |
2015 MediaStreamDevicesController controller( | 2055 MediaStreamDevicesController controller( |
2016 browser()->tab_strip_model()->GetActiveWebContents(), request, | 2056 browser()->tab_strip_model()->GetActiveWebContents(), request, |
2017 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); | 2057 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); |
2018 controller.DismissInfoBarAndTakeActionOnSettings(); | 2058 controller.DismissInfoBarAndTakeActionOnSettings(); |
2019 | 2059 |
2020 MessageLoop::current()->QuitWhenIdle(); | 2060 MessageLoop::current()->QuitWhenIdle(); |
2021 } | 2061 } |
2022 | 2062 |
2023 void FinishVideoTest() { | 2063 void FinishVideoTest() { |
2024 content::MediaStreamRequest request(0, 0, GURL(), | 2064 content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(), |
2025 content::MEDIA_OPEN_DEVICE, "fake_dev", | 2065 content::MEDIA_OPEN_DEVICE, "fake_dev", |
2026 content::MEDIA_NO_SERVICE, | 2066 content::MEDIA_NO_SERVICE, |
2027 content::MEDIA_DEVICE_VIDEO_CAPTURE); | 2067 content::MEDIA_DEVICE_VIDEO_CAPTURE); |
2028 MediaStreamDevicesController controller( | 2068 MediaStreamDevicesController controller( |
2029 browser()->tab_strip_model()->GetActiveWebContents(), request, | 2069 browser()->tab_strip_model()->GetActiveWebContents(), request, |
2030 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); | 2070 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); |
2031 controller.DismissInfoBarAndTakeActionOnSettings(); | 2071 controller.DismissInfoBarAndTakeActionOnSettings(); |
2032 | 2072 |
2033 MessageLoop::current()->QuitWhenIdle(); | 2073 MessageLoop::current()->QuitWhenIdle(); |
2034 } | 2074 } |
2035 | 2075 |
2036 bool policy_value_; | 2076 bool policy_value_; |
| 2077 bool request_url_allowed_via_whitelist_; |
| 2078 GURL request_url_; |
| 2079 static const char kExampleRequestPattern[]; |
2037 }; | 2080 }; |
2038 | 2081 |
| 2082 // static |
| 2083 const char MediaStreamDevicesControllerBrowserTest::kExampleRequestPattern[] = |
| 2084 "http://[*.]example.com/"; |
| 2085 |
2039 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, | 2086 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
2040 AudioCaptureAllowed) { | 2087 AudioCaptureAllowed) { |
2041 content::MediaStreamDevices audio_devices; | 2088 content::MediaStreamDevices audio_devices; |
2042 content::MediaStreamDevice fake_audio_device( | 2089 content::MediaStreamDevice fake_audio_device( |
2043 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); | 2090 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); |
2044 audio_devices.push_back(fake_audio_device); | 2091 audio_devices.push_back(fake_audio_device); |
2045 | 2092 |
2046 PolicyMap policies; | 2093 PolicyMap policies; |
2047 policies.Set(key::kAudioCaptureAllowed, POLICY_LEVEL_MANDATORY, | 2094 ConfigurePolicyMap(&policies, key::kAudioCaptureAllowed, NULL, NULL); |
2048 POLICY_SCOPE_USER, | |
2049 base::Value::CreateBooleanValue(policy_value_)); | |
2050 UpdateProviderPolicy(policies); | 2095 UpdateProviderPolicy(policies); |
2051 | 2096 |
2052 content::BrowserThread::PostTaskAndReply( | 2097 content::BrowserThread::PostTaskAndReply( |
2053 content::BrowserThread::IO, FROM_HERE, | 2098 content::BrowserThread::IO, FROM_HERE, |
2054 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, | 2099 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, |
2055 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), | 2100 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
2056 audio_devices), | 2101 audio_devices), |
2057 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, | 2102 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, |
2058 this)); | 2103 this)); |
2059 | 2104 |
2060 MessageLoop::current()->Run(); | 2105 MessageLoop::current()->Run(); |
2061 } | 2106 } |
2062 | 2107 |
2063 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, | 2108 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
| 2109 AudioCaptureAllowedUrls) { |
| 2110 content::MediaStreamDevices audio_devices; |
| 2111 content::MediaStreamDevice fake_audio_device( |
| 2112 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); |
| 2113 audio_devices.push_back(fake_audio_device); |
| 2114 |
| 2115 const char* allow_pattern[] = { |
| 2116 kExampleRequestPattern, |
| 2117 // This will set an allow-all policy whitelist. Since we do not allow |
| 2118 // setting an allow-all entry in the whitelist, this entry should be ignored |
| 2119 // and therefore the request should be denied. |
| 2120 NULL, |
| 2121 }; |
| 2122 |
| 2123 for (size_t i = 0; i < arraysize(allow_pattern); ++i) { |
| 2124 PolicyMap policies; |
| 2125 ConfigurePolicyMap(&policies, key::kAudioCaptureAllowed, |
| 2126 key::kAudioCaptureAllowedUrls, allow_pattern[i]); |
| 2127 UpdateProviderPolicy(policies); |
| 2128 |
| 2129 content::BrowserThread::PostTaskAndReply( |
| 2130 content::BrowserThread::IO, FROM_HERE, |
| 2131 base::Bind( |
| 2132 &MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, |
| 2133 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
| 2134 audio_devices), |
| 2135 base::Bind( |
| 2136 &MediaStreamDevicesControllerBrowserTest::FinishAudioTest, |
| 2137 this)); |
| 2138 |
| 2139 MessageLoop::current()->Run(); |
| 2140 } |
| 2141 } |
| 2142 |
| 2143 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
2064 VideoCaptureAllowed) { | 2144 VideoCaptureAllowed) { |
2065 content::MediaStreamDevices video_devices; | 2145 content::MediaStreamDevices video_devices; |
2066 content::MediaStreamDevice fake_video_device( | 2146 content::MediaStreamDevice fake_video_device( |
2067 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); | 2147 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); |
2068 video_devices.push_back(fake_video_device); | 2148 video_devices.push_back(fake_video_device); |
2069 | 2149 |
2070 PolicyMap policies; | 2150 PolicyMap policies; |
2071 policies.Set(key::kVideoCaptureAllowed, POLICY_LEVEL_MANDATORY, | 2151 ConfigurePolicyMap(&policies, key::kVideoCaptureAllowed, NULL, NULL); |
2072 POLICY_SCOPE_USER, | |
2073 base::Value::CreateBooleanValue(policy_value_)); | |
2074 UpdateProviderPolicy(policies); | 2152 UpdateProviderPolicy(policies); |
2075 | 2153 |
2076 content::BrowserThread::PostTaskAndReply( | 2154 content::BrowserThread::PostTaskAndReply( |
2077 content::BrowserThread::IO, FROM_HERE, | 2155 content::BrowserThread::IO, FROM_HERE, |
2078 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, | 2156 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, |
2079 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), | 2157 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
2080 video_devices), | 2158 video_devices), |
2081 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, | 2159 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, |
2082 this)); | 2160 this)); |
2083 | 2161 |
2084 MessageLoop::current()->Run(); | 2162 MessageLoop::current()->Run(); |
2085 } | 2163 } |
2086 | 2164 |
| 2165 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
| 2166 VideoCaptureAllowedUrls) { |
| 2167 content::MediaStreamDevices video_devices; |
| 2168 content::MediaStreamDevice fake_video_device( |
| 2169 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); |
| 2170 video_devices.push_back(fake_video_device); |
| 2171 |
| 2172 const char* allow_pattern[] = { |
| 2173 kExampleRequestPattern, |
| 2174 // This will set an allow-all policy whitelist. Since we do not allow |
| 2175 // setting an allow-all entry in the whitelist, this entry should be ignored |
| 2176 // and therefore the request should be denied. |
| 2177 NULL, |
| 2178 }; |
| 2179 |
| 2180 for (size_t i = 0; i < arraysize(allow_pattern); ++i) { |
| 2181 PolicyMap policies; |
| 2182 ConfigurePolicyMap(&policies, key::kVideoCaptureAllowed, |
| 2183 key::kVideoCaptureAllowedUrls, allow_pattern[i]); |
| 2184 UpdateProviderPolicy(policies); |
| 2185 |
| 2186 content::BrowserThread::PostTaskAndReply( |
| 2187 content::BrowserThread::IO, FROM_HERE, |
| 2188 base::Bind( |
| 2189 &MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, |
| 2190 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
| 2191 video_devices), |
| 2192 base::Bind( |
| 2193 &MediaStreamDevicesControllerBrowserTest::FinishVideoTest, |
| 2194 this)); |
| 2195 |
| 2196 MessageLoop::current()->Run(); |
| 2197 } |
| 2198 } |
| 2199 |
2087 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance, | 2200 INSTANTIATE_TEST_CASE_P(MediaStreamDevicesControllerBrowserTestInstance, |
2088 MediaStreamDevicesControllerBrowserTest, | 2201 MediaStreamDevicesControllerBrowserTest, |
2089 testing::Bool()); | 2202 testing::Bool()); |
2090 | 2203 |
2091 #if !defined(OS_CHROMEOS) | 2204 #if !defined(OS_CHROMEOS) |
2092 // Similar to PolicyTest but sets the proper policy before the browser is | 2205 // Similar to PolicyTest but sets the proper policy before the browser is |
2093 // started. | 2206 // started. |
2094 class PolicyVariationsServiceTest : public PolicyTest { | 2207 class PolicyVariationsServiceTest : public PolicyTest { |
2095 public: | 2208 public: |
2096 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 2209 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
(...skipping 17 matching lines...) Expand all Loading... |
2114 chrome_variations::VariationsService::GetVariationsServerURL( | 2227 chrome_variations::VariationsService::GetVariationsServerURL( |
2115 g_browser_process->local_state()); | 2228 g_browser_process->local_state()); |
2116 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); | 2229 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); |
2117 std::string value; | 2230 std::string value; |
2118 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 2231 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
2119 EXPECT_EQ("restricted", value); | 2232 EXPECT_EQ("restricted", value); |
2120 } | 2233 } |
2121 #endif | 2234 #endif |
2122 | 2235 |
2123 } // namespace policy | 2236 } // namespace policy |
OLD | NEW |