| 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 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Add an entry to the whitelist that allows the specified URL regardless |
| 1987 // of the setting of kAudioCapturedAllowed. |
| 1988 request_url_ = GURL("http://www.example.com/foo"); |
| 1989 const char kRequestPattern[] = "http://*.example.com/"; |
| 1990 base::ListValue* list = new base::ListValue(); |
| 1991 list->AppendString(kRequestPattern); |
| 1992 policies->Set(whitelist_policy, POLICY_LEVEL_MANDATORY, |
| 1993 POLICY_SCOPE_USER, list); |
| 1994 request_url_allowed_via_whitelist_ = true; |
| 1995 } |
| 1996 } |
| 1997 |
| 1973 void Accept(const content::MediaStreamDevices& devices, | 1998 void Accept(const content::MediaStreamDevices& devices, |
| 1974 scoped_ptr<content::MediaStreamUI> ui) { | 1999 scoped_ptr<content::MediaStreamUI> ui) { |
| 1975 if (policy_value_) { | 2000 if (policy_value_ || request_url_allowed_via_whitelist_) { |
| 1976 ASSERT_EQ(1U, devices.size()); | 2001 ASSERT_EQ(1U, devices.size()); |
| 1977 ASSERT_EQ("fake_dev", devices[0].id); | 2002 ASSERT_EQ("fake_dev", devices[0].id); |
| 1978 } else { | 2003 } else { |
| 1979 ASSERT_EQ(0U, devices.size()); | 2004 ASSERT_EQ(0U, devices.size()); |
| 1980 } | 2005 } |
| 1981 } | 2006 } |
| 1982 | 2007 |
| 1983 void FinishAudioTest() { | 2008 void FinishAudioTest() { |
| 1984 content::MediaStreamRequest request(0, 0, GURL(), | 2009 content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(), |
| 1985 content::MEDIA_OPEN_DEVICE, "fake_dev", | 2010 content::MEDIA_OPEN_DEVICE, "fake_dev", |
| 1986 content::MEDIA_DEVICE_AUDIO_CAPTURE, | 2011 content::MEDIA_DEVICE_AUDIO_CAPTURE, |
| 1987 content::MEDIA_NO_SERVICE); | 2012 content::MEDIA_NO_SERVICE); |
| 1988 MediaStreamDevicesController controller( | 2013 MediaStreamDevicesController controller( |
| 1989 browser()->tab_strip_model()->GetActiveWebContents(), request, | 2014 browser()->tab_strip_model()->GetActiveWebContents(), request, |
| 1990 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); | 2015 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); |
| 1991 controller.DismissInfoBarAndTakeActionOnSettings(); | 2016 controller.DismissInfoBarAndTakeActionOnSettings(); |
| 1992 | 2017 |
| 1993 MessageLoop::current()->QuitWhenIdle(); | 2018 MessageLoop::current()->QuitWhenIdle(); |
| 1994 } | 2019 } |
| 1995 | 2020 |
| 1996 void FinishVideoTest() { | 2021 void FinishVideoTest() { |
| 1997 content::MediaStreamRequest request(0, 0, GURL(), | 2022 content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(), |
| 1998 content::MEDIA_OPEN_DEVICE, "fake_dev", | 2023 content::MEDIA_OPEN_DEVICE, "fake_dev", |
| 1999 content::MEDIA_NO_SERVICE, | 2024 content::MEDIA_NO_SERVICE, |
| 2000 content::MEDIA_DEVICE_VIDEO_CAPTURE); | 2025 content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 2001 MediaStreamDevicesController controller( | 2026 MediaStreamDevicesController controller( |
| 2002 browser()->tab_strip_model()->GetActiveWebContents(), request, | 2027 browser()->tab_strip_model()->GetActiveWebContents(), request, |
| 2003 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); | 2028 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, this)); |
| 2004 controller.DismissInfoBarAndTakeActionOnSettings(); | 2029 controller.DismissInfoBarAndTakeActionOnSettings(); |
| 2005 | 2030 |
| 2006 MessageLoop::current()->QuitWhenIdle(); | 2031 MessageLoop::current()->QuitWhenIdle(); |
| 2007 } | 2032 } |
| 2008 | 2033 |
| 2009 bool policy_value_; | 2034 bool policy_value_; |
| 2035 bool request_url_allowed_via_whitelist_; |
| 2036 GURL request_url_; |
| 2010 }; | 2037 }; |
| 2011 | 2038 |
| 2012 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, | 2039 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
| 2013 AudioCaptureAllowed) { | 2040 AudioCaptureAllowed) { |
| 2014 content::MediaStreamDevices audio_devices; | 2041 content::MediaStreamDevices audio_devices; |
| 2015 content::MediaStreamDevice fake_audio_device( | 2042 content::MediaStreamDevice fake_audio_device( |
| 2016 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); | 2043 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); |
| 2017 audio_devices.push_back(fake_audio_device); | 2044 audio_devices.push_back(fake_audio_device); |
| 2018 | 2045 |
| 2019 PolicyMap policies; | 2046 PolicyMap policies; |
| 2020 policies.Set(key::kAudioCaptureAllowed, POLICY_LEVEL_MANDATORY, | 2047 ConfigurePolicyMap(&policies, key::kAudioCaptureAllowed, NULL); |
| 2021 POLICY_SCOPE_USER, | |
| 2022 base::Value::CreateBooleanValue(policy_value_)); | |
| 2023 UpdateProviderPolicy(policies); | 2048 UpdateProviderPolicy(policies); |
| 2024 | 2049 |
| 2025 content::BrowserThread::PostTaskAndReply( | 2050 content::BrowserThread::PostTaskAndReply( |
| 2051 content::BrowserThread::IO, FROM_HERE, |
| 2052 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, |
| 2053 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
| 2054 audio_devices), |
| 2055 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, |
| 2056 this)); |
| 2057 |
| 2058 MessageLoop::current()->Run(); |
| 2059 } |
| 2060 |
| 2061 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
| 2062 AudioCaptureAllowedUrls) { |
| 2063 content::MediaStreamDevices audio_devices; |
| 2064 content::MediaStreamDevice fake_audio_device( |
| 2065 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); |
| 2066 audio_devices.push_back(fake_audio_device); |
| 2067 |
| 2068 PolicyMap policies; |
| 2069 ConfigurePolicyMap(&policies, key::kAudioCaptureAllowed, |
| 2070 key::kAudioCaptureAllowedUrls); |
| 2071 UpdateProviderPolicy(policies); |
| 2072 |
| 2073 content::BrowserThread::PostTaskAndReply( |
| 2026 content::BrowserThread::IO, FROM_HERE, | 2074 content::BrowserThread::IO, FROM_HERE, |
| 2027 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, | 2075 base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, |
| 2028 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), | 2076 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
| 2029 audio_devices), | 2077 audio_devices), |
| 2030 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, | 2078 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, |
| 2031 this)); | 2079 this)); |
| 2032 | 2080 |
| 2033 MessageLoop::current()->Run(); | 2081 MessageLoop::current()->Run(); |
| 2034 } | 2082 } |
| 2035 | 2083 |
| 2036 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, | 2084 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
| 2037 VideoCaptureAllowed) { | 2085 VideoCaptureAllowed) { |
| 2038 content::MediaStreamDevices video_devices; | 2086 content::MediaStreamDevices video_devices; |
| 2039 content::MediaStreamDevice fake_video_device( | 2087 content::MediaStreamDevice fake_video_device( |
| 2040 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); | 2088 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); |
| 2041 video_devices.push_back(fake_video_device); | 2089 video_devices.push_back(fake_video_device); |
| 2042 | 2090 |
| 2043 PolicyMap policies; | 2091 PolicyMap policies; |
| 2044 policies.Set(key::kVideoCaptureAllowed, POLICY_LEVEL_MANDATORY, | 2092 ConfigurePolicyMap(&policies, key::kVideoCaptureAllowed, NULL); |
| 2045 POLICY_SCOPE_USER, | |
| 2046 base::Value::CreateBooleanValue(policy_value_)); | |
| 2047 UpdateProviderPolicy(policies); | 2093 UpdateProviderPolicy(policies); |
| 2048 | 2094 |
| 2049 content::BrowserThread::PostTaskAndReply( | 2095 content::BrowserThread::PostTaskAndReply( |
| 2096 content::BrowserThread::IO, FROM_HERE, |
| 2097 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, |
| 2098 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
| 2099 video_devices), |
| 2100 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, |
| 2101 this)); |
| 2102 |
| 2103 MessageLoop::current()->Run(); |
| 2104 } |
| 2105 |
| 2106 IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
| 2107 VideoCaptureAllowedUrls) { |
| 2108 content::MediaStreamDevices video_devices; |
| 2109 content::MediaStreamDevice fake_video_device( |
| 2110 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); |
| 2111 video_devices.push_back(fake_video_device); |
| 2112 |
| 2113 PolicyMap policies; |
| 2114 ConfigurePolicyMap(&policies, key::kVideoCaptureAllowed, |
| 2115 key::kVideoCaptureAllowedUrls); |
| 2116 UpdateProviderPolicy(policies); |
| 2117 |
| 2118 content::BrowserThread::PostTaskAndReply( |
| 2050 content::BrowserThread::IO, FROM_HERE, | 2119 content::BrowserThread::IO, FROM_HERE, |
| 2051 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, | 2120 base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, |
| 2052 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), | 2121 base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
| 2053 video_devices), | 2122 video_devices), |
| 2054 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, | 2123 base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, |
| 2055 this)); | 2124 this)); |
| 2056 | 2125 |
| 2057 MessageLoop::current()->Run(); | 2126 MessageLoop::current()->Run(); |
| 2058 } | 2127 } |
| 2059 | 2128 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2087 chrome_variations::VariationsService::GetVariationsServerURL( | 2156 chrome_variations::VariationsService::GetVariationsServerURL( |
| 2088 g_browser_process->local_state()); | 2157 g_browser_process->local_state()); |
| 2089 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); | 2158 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); |
| 2090 std::string value; | 2159 std::string value; |
| 2091 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 2160 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
| 2092 EXPECT_EQ("restricted", value); | 2161 EXPECT_EQ("restricted", value); |
| 2093 } | 2162 } |
| 2094 #endif | 2163 #endif |
| 2095 | 2164 |
| 2096 } // namespace policy | 2165 } // namespace policy |
| OLD | NEW |