Index: chrome/browser/policy/policy_browsertest.cc |
diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc |
index 140f2c06c53860c9091f13637ff91278233d805c..1b1d2498fbf0c4bbbcadaa47f31a61e9c9e4b078 100644 |
--- a/chrome/browser/policy/policy_browsertest.cc |
+++ b/chrome/browser/policy/policy_browsertest.cc |
@@ -1965,14 +1965,39 @@ class MediaStreamDevicesControllerBrowserTest |
: public PolicyTest, |
public testing::WithParamInterface<bool> { |
public: |
- MediaStreamDevicesControllerBrowserTest() { |
+ MediaStreamDevicesControllerBrowserTest() |
+ : request_url_allowed_via_whitelist_(false) { |
policy_value_ = GetParam(); |
} |
virtual ~MediaStreamDevicesControllerBrowserTest() {} |
+ // Configure a given policy map. |
+ // The |policy_name| is the name of either the audio or video capture allow |
+ // policy and must never be NULL. |
+ // |whitelist_policy| is optional. If NULL, no whitelist policy is set. |
+ // If non-NULL, the request_url_ will be set to be non empty and a matching |
+ // policy that allows the request url, will be set. |
+ void ConfigurePolicyMap(PolicyMap* policies, const char* policy_name, |
+ const char* whitelist_policy) { |
+ policies->Set(policy_name, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
+ base::Value::CreateBooleanValue(policy_value_)); |
+ |
+ if (whitelist_policy) { |
+ // Add an entry to the whitelist that allows the specified URL regardless |
+ // of the setting of kAudioCapturedAllowed. |
+ request_url_ = GURL("http://www.example.com/foo"); |
+ const char kRequestPattern[] = "http://*.example.com/"; |
+ base::ListValue* list = new base::ListValue(); |
+ list->AppendString(kRequestPattern); |
+ policies->Set(whitelist_policy, POLICY_LEVEL_MANDATORY, |
+ POLICY_SCOPE_USER, list); |
+ request_url_allowed_via_whitelist_ = true; |
+ } |
+ } |
+ |
void Accept(const content::MediaStreamDevices& devices, |
scoped_ptr<content::MediaStreamUI> ui) { |
- if (policy_value_) { |
+ if (policy_value_ || request_url_allowed_via_whitelist_) { |
ASSERT_EQ(1U, devices.size()); |
ASSERT_EQ("fake_dev", devices[0].id); |
} else { |
@@ -1981,7 +2006,7 @@ class MediaStreamDevicesControllerBrowserTest |
} |
void FinishAudioTest() { |
- content::MediaStreamRequest request(0, 0, GURL(), |
+ content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(), |
content::MEDIA_OPEN_DEVICE, "fake_dev", |
content::MEDIA_DEVICE_AUDIO_CAPTURE, |
content::MEDIA_NO_SERVICE); |
@@ -1994,7 +2019,7 @@ class MediaStreamDevicesControllerBrowserTest |
} |
void FinishVideoTest() { |
- content::MediaStreamRequest request(0, 0, GURL(), |
+ content::MediaStreamRequest request(0, 0, request_url_.GetOrigin(), |
content::MEDIA_OPEN_DEVICE, "fake_dev", |
content::MEDIA_NO_SERVICE, |
content::MEDIA_DEVICE_VIDEO_CAPTURE); |
@@ -2007,6 +2032,8 @@ class MediaStreamDevicesControllerBrowserTest |
} |
bool policy_value_; |
+ bool request_url_allowed_via_whitelist_; |
+ GURL request_url_; |
}; |
IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
@@ -2017,9 +2044,30 @@ IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
audio_devices.push_back(fake_audio_device); |
PolicyMap policies; |
- policies.Set(key::kAudioCaptureAllowed, POLICY_LEVEL_MANDATORY, |
- POLICY_SCOPE_USER, |
- base::Value::CreateBooleanValue(policy_value_)); |
+ ConfigurePolicyMap(&policies, key::kAudioCaptureAllowed, NULL); |
+ UpdateProviderPolicy(policies); |
+ |
+ content::BrowserThread::PostTaskAndReply( |
+ content::BrowserThread::IO, FROM_HERE, |
+ base::Bind(&MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged, |
+ base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
+ audio_devices), |
+ base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishAudioTest, |
+ this)); |
+ |
+ MessageLoop::current()->Run(); |
+} |
+ |
+IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
+ AudioCaptureAllowedUrls) { |
+ content::MediaStreamDevices audio_devices; |
+ content::MediaStreamDevice fake_audio_device( |
+ content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev", "Fake Audio Device"); |
+ audio_devices.push_back(fake_audio_device); |
+ |
+ PolicyMap policies; |
+ ConfigurePolicyMap(&policies, key::kAudioCaptureAllowed, |
+ key::kAudioCaptureAllowedUrls); |
UpdateProviderPolicy(policies); |
content::BrowserThread::PostTaskAndReply( |
@@ -2041,9 +2089,30 @@ IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
video_devices.push_back(fake_video_device); |
PolicyMap policies; |
- policies.Set(key::kVideoCaptureAllowed, POLICY_LEVEL_MANDATORY, |
- POLICY_SCOPE_USER, |
- base::Value::CreateBooleanValue(policy_value_)); |
+ ConfigurePolicyMap(&policies, key::kVideoCaptureAllowed, NULL); |
+ UpdateProviderPolicy(policies); |
+ |
+ content::BrowserThread::PostTaskAndReply( |
+ content::BrowserThread::IO, FROM_HERE, |
+ base::Bind(&MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged, |
+ base::Unretained(MediaCaptureDevicesDispatcher::GetInstance()), |
+ video_devices), |
+ base::Bind(&MediaStreamDevicesControllerBrowserTest::FinishVideoTest, |
+ this)); |
+ |
+ MessageLoop::current()->Run(); |
+} |
+ |
+IN_PROC_BROWSER_TEST_P(MediaStreamDevicesControllerBrowserTest, |
+ VideoCaptureAllowedUrls) { |
+ content::MediaStreamDevices video_devices; |
+ content::MediaStreamDevice fake_video_device( |
+ content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_dev", "Fake Video Device"); |
+ video_devices.push_back(fake_video_device); |
+ |
+ PolicyMap policies; |
+ ConfigurePolicyMap(&policies, key::kVideoCaptureAllowed, |
+ key::kVideoCaptureAllowedUrls); |
UpdateProviderPolicy(policies); |
content::BrowserThread::PostTaskAndReply( |