Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 11 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 11 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 12 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" | 12 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" |
| 13 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" | 13 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" |
| 14 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" | 14 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" |
| 15 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h" | 15 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h" |
| 16 #include "chrome/browser/permissions/permission_context_base.h" | 16 #include "chrome/browser/permissions/permission_context_base.h" |
| 17 #include "chrome/browser/permissions/permission_request_manager.h" | |
| 17 #include "chrome/browser/permissions/permission_util.h" | 18 #include "chrome/browser/permissions/permission_util.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "components/content_settings/core/browser/host_content_settings_map.h" | 24 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 24 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 25 #include "components/variations/variations_associated_data.h" | 26 #include "components/variations/variations_associated_data.h" |
| 26 #include "content/public/common/media_stream_request.h" | 27 #include "content/public/common/media_stream_request.h" |
| 27 #include "content/public/test/mock_render_process_host.h" | 28 #include "content/public/test/mock_render_process_host.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 30 |
| 30 namespace { | |
| 31 | |
| 32 // Causes the controller to update the TabSpecificContentSettings associated | |
| 33 // with the same WebContents with the current permissions. This should be the | |
| 34 // last change made to the controller in the test. | |
| 35 void NotifyTabSpecificContentSettings( | |
| 36 MediaStreamDevicesController* controller) { | |
| 37 // Note that calling Deny() would have the same effect of passing the current | |
| 38 // permissions state to the TabSpecificContentSettings. Deny() and Accept() | |
| 39 // differ in their effect on the controller itself, but that is not important | |
| 40 // in the tests calling this. | |
| 41 if (controller->IsAskingForAudio() || controller->IsAskingForVideo()) | |
| 42 controller->PermissionGranted(); | |
| 43 } | |
| 44 | |
| 45 } // namespace | |
| 46 | |
| 47 class MediaStreamDevicesControllerTest : public WebRtcTestBase { | 31 class MediaStreamDevicesControllerTest : public WebRtcTestBase { |
| 48 public: | 32 public: |
| 33 // TODO(raymes): When crbug.com/606138 is finished and the | |
| 34 // PermissionRequestManager is used to show all prompts on Android/Desktop | |
| 35 // we should remove PermissionPromptDelegate and just use | |
| 36 // MockPermissionPromptFactory instead. The APIs are the same. | |
| 37 class TestPermissionPromptDelegate | |
| 38 : public MediaStreamDevicesController::PermissionPromptDelegate { | |
| 39 public: | |
| 40 void ShowPrompt( | |
| 41 bool user_gesture, | |
| 42 content::WebContents* web_contents, | |
| 43 std::unique_ptr<MediaStreamDevicesController> controller) override { | |
| 44 if (controller->IsAskingForAudio()) | |
| 45 ++total_request_count_; | |
| 46 if (controller->IsAskingForVideo()) | |
| 47 ++total_request_count_; | |
| 48 | |
| 49 if (response_type_ == PermissionRequestManager::ACCEPT_ALL) | |
| 50 controller->PermissionGranted(); | |
| 51 else if (response_type_ == PermissionRequestManager::DENY_ALL) | |
| 52 controller->PermissionDenied(); | |
| 53 } | |
| 54 | |
| 55 void set_response_type( | |
| 56 PermissionRequestManager::AutoResponseType response_type) { | |
| 57 response_type_ = response_type; | |
| 58 } | |
| 59 | |
| 60 int total_request_count() { return total_request_count_; } | |
| 61 | |
| 62 void ResetCounts() { total_request_count_ = 0; } | |
| 63 | |
| 64 private: | |
| 65 PermissionRequestManager::AutoResponseType response_type_ = | |
| 66 PermissionRequestManager::NONE; | |
| 67 int total_request_count_ = 0; | |
| 68 }; | |
| 69 | |
| 49 MediaStreamDevicesControllerTest() | 70 MediaStreamDevicesControllerTest() |
| 50 : example_audio_id_("fake_audio_dev"), | 71 : example_audio_id_("fake_audio_dev"), |
| 51 example_video_id_("fake_video_dev"), | 72 example_video_id_("fake_video_dev"), |
| 52 media_stream_result_(content::NUM_MEDIA_REQUEST_RESULTS) {} | 73 media_stream_result_(content::NUM_MEDIA_REQUEST_RESULTS) {} |
| 53 | 74 |
| 54 // Dummy callback for when we deny the current request directly. | 75 // Dummy callback for when we deny the current request directly. |
| 55 void OnMediaStreamResponse(const content::MediaStreamDevices& devices, | 76 void OnMediaStreamResponse(const content::MediaStreamDevices& devices, |
| 56 content::MediaStreamRequestResult result, | 77 content::MediaStreamRequestResult result, |
| 57 std::unique_ptr<content::MediaStreamUI> ui) { | 78 std::unique_ptr<content::MediaStreamUI> ui) { |
| 58 media_stream_devices_ = devices; | 79 media_stream_devices_ = devices; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 69 return TabSpecificContentSettings::FromWebContents(GetWebContents()); | 90 return TabSpecificContentSettings::FromWebContents(GetWebContents()); |
| 70 } | 91 } |
| 71 | 92 |
| 72 const std::string& example_audio_id() const { return example_audio_id_; } | 93 const std::string& example_audio_id() const { return example_audio_id_; } |
| 73 const std::string& example_video_id() const { return example_video_id_; } | 94 const std::string& example_video_id() const { return example_video_id_; } |
| 74 | 95 |
| 75 content::MediaStreamRequestResult media_stream_result() const { | 96 content::MediaStreamRequestResult media_stream_result() const { |
| 76 return media_stream_result_; | 97 return media_stream_result_; |
| 77 } | 98 } |
| 78 | 99 |
| 79 std::unique_ptr<MediaStreamDevicesController> | 100 void RequestPermissions(content::WebContents* web_contents, |
| 80 CreateMediaStreamDevicesController( | 101 const content::MediaStreamRequest& request, |
| 81 content::WebContents* web_contents, | 102 const content::MediaResponseCallback& callback) { |
| 82 const content::MediaStreamRequest& request, | 103 MediaStreamDevicesController::RequestPermissionsWithDelegate( |
| 83 const content::MediaResponseCallback& callback) { | 104 web_contents, request, callback, &prompt_delegate_); |
| 84 return base::WrapUnique( | |
| 85 new MediaStreamDevicesController(web_contents, request, callback)); | |
| 86 } | 105 } |
| 87 | 106 |
| 88 bool IsAskingForAudio(const MediaStreamDevicesController* controller) { | 107 TestPermissionPromptDelegate* prompt_delegate() { return &prompt_delegate_; } |
| 89 return controller->IsAskingForAudio(); | |
| 90 } | |
| 91 | |
| 92 bool IsAskingForVideo(const MediaStreamDevicesController* controller) { | |
| 93 return controller->IsAskingForVideo(); | |
| 94 } | |
| 95 | |
| 96 void PermissionGranted(MediaStreamDevicesController* controller) { | |
| 97 return controller->PermissionGranted(); | |
| 98 } | |
| 99 | |
| 100 void PermissionDenied(MediaStreamDevicesController* controller) { | |
| 101 return controller->PermissionDenied(); | |
| 102 } | |
| 103 | 108 |
| 104 // Sets the device policy-controlled |access| for |example_url_| to be for the | 109 // Sets the device policy-controlled |access| for |example_url_| to be for the |
| 105 // selected |device_type|. | 110 // selected |device_type|. |
| 106 void SetDevicePolicy(DeviceType device_type, Access access) { | 111 void SetDevicePolicy(DeviceType device_type, Access access) { |
| 107 PrefService* prefs = Profile::FromBrowserContext( | 112 PrefService* prefs = Profile::FromBrowserContext( |
| 108 GetWebContents()->GetBrowserContext())->GetPrefs(); | 113 GetWebContents()->GetBrowserContext())->GetPrefs(); |
| 109 const char* policy_name = NULL; | 114 const char* policy_name = NULL; |
| 110 switch (device_type) { | 115 switch (device_type) { |
| 111 case DEVICE_TYPE_AUDIO: | 116 case DEVICE_TYPE_AUDIO: |
| 112 policy_name = prefs::kAudioCaptureAllowed; | 117 policy_name = prefs::kAudioCaptureAllowed; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 MediaCaptureDevicesDispatcher::GetInstance()->SetTestVideoCaptureDevices( | 207 MediaCaptureDevicesDispatcher::GetInstance()->SetTestVideoCaptureDevices( |
| 203 video_devices); | 208 video_devices); |
| 204 } | 209 } |
| 205 | 210 |
| 206 GURL example_url_; | 211 GURL example_url_; |
| 207 const std::string example_audio_id_; | 212 const std::string example_audio_id_; |
| 208 const std::string example_video_id_; | 213 const std::string example_video_id_; |
| 209 | 214 |
| 210 content::MediaStreamDevices media_stream_devices_; | 215 content::MediaStreamDevices media_stream_devices_; |
| 211 content::MediaStreamRequestResult media_stream_result_; | 216 content::MediaStreamRequestResult media_stream_result_; |
| 217 | |
| 218 TestPermissionPromptDelegate prompt_delegate_; | |
| 212 }; | 219 }; |
| 213 | 220 |
| 214 // Request and allow microphone access. | 221 // Request and allow microphone access. |
| 215 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowMic) { | 222 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowMic) { |
| 216 InitWithUrl(GURL("https://www.example.com")); | 223 InitWithUrl(GURL("https://www.example.com")); |
| 217 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); | 224 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); |
| 218 std::unique_ptr<MediaStreamDevicesController> controller( | 225 // Ensure the prompt is accepted if necessary such that tab specific content |
| 219 CreateMediaStreamDevicesController( | 226 // settings are updated. |
| 220 GetWebContents(), CreateRequest(example_audio_id(), std::string()), | 227 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 221 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 228 RequestPermissions( |
| 222 base::Unretained(this)))); | 229 GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| 223 NotifyTabSpecificContentSettings(controller.get()); | 230 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 231 base::Unretained(this))); | |
| 224 | 232 |
| 225 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( | 233 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| 226 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 234 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 227 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( | 235 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( |
| 228 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 236 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 229 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED, | 237 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED, |
| 230 GetContentSettings()->GetMicrophoneCameraState()); | 238 GetContentSettings()->GetMicrophoneCameraState()); |
| 231 EXPECT_EQ(example_audio_id(), | 239 EXPECT_EQ(example_audio_id(), |
| 232 GetContentSettings()->media_stream_requested_audio_device()); | 240 GetContentSettings()->media_stream_requested_audio_device()); |
| 233 EXPECT_EQ(example_audio_id(), | 241 EXPECT_EQ(example_audio_id(), |
| 234 GetContentSettings()->media_stream_selected_audio_device()); | 242 GetContentSettings()->media_stream_selected_audio_device()); |
| 235 EXPECT_EQ(std::string(), | 243 EXPECT_EQ(std::string(), |
| 236 GetContentSettings()->media_stream_requested_video_device()); | 244 GetContentSettings()->media_stream_requested_video_device()); |
| 237 EXPECT_EQ(std::string(), | 245 EXPECT_EQ(std::string(), |
| 238 GetContentSettings()->media_stream_selected_video_device()); | 246 GetContentSettings()->media_stream_selected_video_device()); |
| 239 } | 247 } |
| 240 | 248 |
| 241 // Request and allow camera access. | 249 // Request and allow camera access. |
| 242 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowCam) { | 250 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowCam) { |
| 243 InitWithUrl(GURL("https://www.example.com")); | 251 InitWithUrl(GURL("https://www.example.com")); |
| 244 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); | 252 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| 245 std::unique_ptr<MediaStreamDevicesController> controller( | 253 // Ensure the prompt is accepted if necessary such that tab specific content |
| 246 CreateMediaStreamDevicesController( | 254 // settings are updated. |
| 247 GetWebContents(), CreateRequest(std::string(), example_video_id()), | 255 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 248 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 256 RequestPermissions( |
| 249 base::Unretained(this)))); | 257 GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| 250 NotifyTabSpecificContentSettings(controller.get()); | 258 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 259 base::Unretained(this))); | |
| 251 | 260 |
| 252 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( | 261 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| 253 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 262 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 254 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( | 263 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( |
| 255 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 264 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 256 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED, | 265 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED, |
| 257 GetContentSettings()->GetMicrophoneCameraState()); | 266 GetContentSettings()->GetMicrophoneCameraState()); |
| 258 EXPECT_EQ(std::string(), | 267 EXPECT_EQ(std::string(), |
| 259 GetContentSettings()->media_stream_requested_audio_device()); | 268 GetContentSettings()->media_stream_requested_audio_device()); |
| 260 EXPECT_EQ(std::string(), | 269 EXPECT_EQ(std::string(), |
| 261 GetContentSettings()->media_stream_selected_audio_device()); | 270 GetContentSettings()->media_stream_selected_audio_device()); |
| 262 EXPECT_EQ(example_video_id(), | 271 EXPECT_EQ(example_video_id(), |
| 263 GetContentSettings()->media_stream_requested_video_device()); | 272 GetContentSettings()->media_stream_requested_video_device()); |
| 264 EXPECT_EQ(example_video_id(), | 273 EXPECT_EQ(example_video_id(), |
| 265 GetContentSettings()->media_stream_selected_video_device()); | 274 GetContentSettings()->media_stream_selected_video_device()); |
| 266 } | 275 } |
| 267 | 276 |
| 268 // Request and block microphone access. | 277 // Request and block microphone access. |
| 269 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndBlockMic) { | 278 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndBlockMic) { |
| 270 InitWithUrl(GURL("https://www.example.com")); | 279 InitWithUrl(GURL("https://www.example.com")); |
| 271 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); | 280 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); |
| 272 std::unique_ptr<MediaStreamDevicesController> controller( | 281 // Ensure the prompt is accepted if necessary such that tab specific content |
| 273 CreateMediaStreamDevicesController( | 282 // settings are updated. |
| 274 GetWebContents(), CreateRequest(example_audio_id(), std::string()), | 283 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 275 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 284 RequestPermissions( |
| 276 base::Unretained(this)))); | 285 GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| 277 NotifyTabSpecificContentSettings(controller.get()); | 286 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 287 base::Unretained(this))); | |
| 278 | 288 |
| 279 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( | 289 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| 280 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 290 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 281 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( | 291 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( |
| 282 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 292 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 283 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | | 293 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| 284 TabSpecificContentSettings::MICROPHONE_BLOCKED, | 294 TabSpecificContentSettings::MICROPHONE_BLOCKED, |
| 285 GetContentSettings()->GetMicrophoneCameraState()); | 295 GetContentSettings()->GetMicrophoneCameraState()); |
| 286 EXPECT_EQ(example_audio_id(), | 296 EXPECT_EQ(example_audio_id(), |
| 287 GetContentSettings()->media_stream_requested_audio_device()); | 297 GetContentSettings()->media_stream_requested_audio_device()); |
| 288 EXPECT_EQ(example_audio_id(), | 298 EXPECT_EQ(example_audio_id(), |
| 289 GetContentSettings()->media_stream_selected_audio_device()); | 299 GetContentSettings()->media_stream_selected_audio_device()); |
| 290 EXPECT_EQ(std::string(), | 300 EXPECT_EQ(std::string(), |
| 291 GetContentSettings()->media_stream_requested_video_device()); | 301 GetContentSettings()->media_stream_requested_video_device()); |
| 292 EXPECT_EQ(std::string(), | 302 EXPECT_EQ(std::string(), |
| 293 GetContentSettings()->media_stream_selected_video_device()); | 303 GetContentSettings()->media_stream_selected_video_device()); |
| 294 } | 304 } |
| 295 | 305 |
| 296 // Request and block camera access. | 306 // Request and block camera access. |
| 297 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndBlockCam) { | 307 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndBlockCam) { |
| 298 InitWithUrl(GURL("https://www.example.com")); | 308 InitWithUrl(GURL("https://www.example.com")); |
| 299 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); | 309 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); |
| 300 std::unique_ptr<MediaStreamDevicesController> controller( | 310 // Ensure the prompt is accepted if necessary such that tab specific content |
| 301 CreateMediaStreamDevicesController( | 311 // settings are updated. |
| 302 GetWebContents(), CreateRequest(std::string(), example_video_id()), | 312 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 303 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 313 RequestPermissions( |
| 304 base::Unretained(this)))); | 314 GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| 305 NotifyTabSpecificContentSettings(controller.get()); | 315 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 316 base::Unretained(this))); | |
| 306 | 317 |
| 307 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( | 318 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| 308 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 319 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 309 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( | 320 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( |
| 310 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 321 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 311 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED | | 322 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED | |
| 312 TabSpecificContentSettings::CAMERA_BLOCKED, | 323 TabSpecificContentSettings::CAMERA_BLOCKED, |
| 313 GetContentSettings()->GetMicrophoneCameraState()); | 324 GetContentSettings()->GetMicrophoneCameraState()); |
| 314 EXPECT_EQ(std::string(), | 325 EXPECT_EQ(std::string(), |
| 315 GetContentSettings()->media_stream_requested_audio_device()); | 326 GetContentSettings()->media_stream_requested_audio_device()); |
| 316 EXPECT_EQ(std::string(), | 327 EXPECT_EQ(std::string(), |
| 317 GetContentSettings()->media_stream_selected_audio_device()); | 328 GetContentSettings()->media_stream_selected_audio_device()); |
| 318 EXPECT_EQ(example_video_id(), | 329 EXPECT_EQ(example_video_id(), |
| 319 GetContentSettings()->media_stream_requested_video_device()); | 330 GetContentSettings()->media_stream_requested_video_device()); |
| 320 EXPECT_EQ(example_video_id(), | 331 EXPECT_EQ(example_video_id(), |
| 321 GetContentSettings()->media_stream_selected_video_device()); | 332 GetContentSettings()->media_stream_selected_video_device()); |
| 322 } | 333 } |
| 323 | 334 |
| 324 // Request and allow microphone and camera access. | 335 // Request and allow microphone and camera access. |
| 325 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, | 336 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| 326 RequestAndAllowMicCam) { | 337 RequestAndAllowMicCam) { |
| 327 InitWithUrl(GURL("https://www.example.com")); | 338 InitWithUrl(GURL("https://www.example.com")); |
| 328 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); | 339 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); |
| 329 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); | 340 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| 330 std::unique_ptr<MediaStreamDevicesController> controller( | 341 // Ensure the prompt is accepted if necessary such that tab specific content |
| 331 CreateMediaStreamDevicesController( | 342 // settings are updated. |
| 332 GetWebContents(), | 343 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 333 CreateRequest(example_audio_id(), example_video_id()), | 344 RequestPermissions( |
| 334 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 345 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| 335 base::Unretained(this)))); | 346 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 336 NotifyTabSpecificContentSettings(controller.get()); | 347 base::Unretained(this))); |
| 337 | 348 |
| 338 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( | 349 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| 339 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 350 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 340 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( | 351 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( |
| 341 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 352 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 342 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( | 353 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| 343 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 354 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 344 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( | 355 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( |
| 345 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 356 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 346 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | | 357 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| 347 TabSpecificContentSettings::CAMERA_ACCESSED, | 358 TabSpecificContentSettings::CAMERA_ACCESSED, |
| 348 GetContentSettings()->GetMicrophoneCameraState()); | 359 GetContentSettings()->GetMicrophoneCameraState()); |
| 349 EXPECT_EQ(example_audio_id(), | 360 EXPECT_EQ(example_audio_id(), |
| 350 GetContentSettings()->media_stream_requested_audio_device()); | 361 GetContentSettings()->media_stream_requested_audio_device()); |
| 351 EXPECT_EQ(example_audio_id(), | 362 EXPECT_EQ(example_audio_id(), |
| 352 GetContentSettings()->media_stream_selected_audio_device()); | 363 GetContentSettings()->media_stream_selected_audio_device()); |
| 353 EXPECT_EQ(example_video_id(), | 364 EXPECT_EQ(example_video_id(), |
| 354 GetContentSettings()->media_stream_requested_video_device()); | 365 GetContentSettings()->media_stream_requested_video_device()); |
| 355 EXPECT_EQ(example_video_id(), | 366 EXPECT_EQ(example_video_id(), |
| 356 GetContentSettings()->media_stream_selected_video_device()); | 367 GetContentSettings()->media_stream_selected_video_device()); |
| 357 } | 368 } |
| 358 | 369 |
| 359 // Request and block microphone and camera access. | 370 // Request and block microphone and camera access. |
| 360 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, | 371 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| 361 RequestAndBlockMicCam) { | 372 RequestAndBlockMicCam) { |
| 362 InitWithUrl(GURL("https://www.example.com")); | 373 InitWithUrl(GURL("https://www.example.com")); |
| 363 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); | 374 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); |
| 364 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); | 375 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); |
| 365 std::unique_ptr<MediaStreamDevicesController> controller( | 376 // Ensure the prompt is accepted if necessary such that tab specific content |
| 366 CreateMediaStreamDevicesController( | 377 // settings are updated. |
| 367 GetWebContents(), | 378 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 368 CreateRequest(example_audio_id(), example_video_id()), | 379 RequestPermissions( |
| 369 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 380 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| 370 base::Unretained(this)))); | 381 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 371 NotifyTabSpecificContentSettings(controller.get()); | 382 base::Unretained(this))); |
| 372 | 383 |
| 373 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( | 384 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| 374 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 385 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 375 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( | 386 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( |
| 376 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 387 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 377 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( | 388 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| 378 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 389 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 379 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( | 390 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( |
| 380 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 391 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 381 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | | 392 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 392 EXPECT_EQ(example_video_id(), | 403 EXPECT_EQ(example_video_id(), |
| 393 GetContentSettings()->media_stream_selected_video_device()); | 404 GetContentSettings()->media_stream_selected_video_device()); |
| 394 } | 405 } |
| 395 | 406 |
| 396 // Request microphone and camera access. Allow microphone, block camera. | 407 // Request microphone and camera access. Allow microphone, block camera. |
| 397 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, | 408 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| 398 RequestMicCamBlockCam) { | 409 RequestMicCamBlockCam) { |
| 399 InitWithUrl(GURL("https://www.example.com")); | 410 InitWithUrl(GURL("https://www.example.com")); |
| 400 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); | 411 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); |
| 401 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); | 412 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); |
| 402 std::unique_ptr<MediaStreamDevicesController> controller( | 413 // Ensure the prompt is accepted if necessary such that tab specific content |
| 403 CreateMediaStreamDevicesController( | 414 // settings are updated. |
| 404 GetWebContents(), | 415 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 405 CreateRequest(example_audio_id(), example_video_id()), | 416 RequestPermissions( |
| 406 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 417 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| 407 base::Unretained(this)))); | 418 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 408 NotifyTabSpecificContentSettings(controller.get()); | 419 base::Unretained(this))); |
| 409 | 420 |
| 410 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( | 421 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| 411 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 422 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 412 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( | 423 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( |
| 413 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 424 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 414 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( | 425 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| 415 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 426 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 416 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( | 427 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( |
| 417 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 428 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 418 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | | 429 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| 419 TabSpecificContentSettings::CAMERA_ACCESSED | | 430 TabSpecificContentSettings::CAMERA_ACCESSED | |
| 420 TabSpecificContentSettings::CAMERA_BLOCKED, | 431 TabSpecificContentSettings::CAMERA_BLOCKED, |
| 421 GetContentSettings()->GetMicrophoneCameraState()); | 432 GetContentSettings()->GetMicrophoneCameraState()); |
| 422 EXPECT_EQ(example_audio_id(), | 433 EXPECT_EQ(example_audio_id(), |
| 423 GetContentSettings()->media_stream_requested_audio_device()); | 434 GetContentSettings()->media_stream_requested_audio_device()); |
| 424 EXPECT_EQ(example_audio_id(), | 435 EXPECT_EQ(example_audio_id(), |
| 425 GetContentSettings()->media_stream_selected_audio_device()); | 436 GetContentSettings()->media_stream_selected_audio_device()); |
| 426 EXPECT_EQ(example_video_id(), | 437 EXPECT_EQ(example_video_id(), |
| 427 GetContentSettings()->media_stream_requested_video_device()); | 438 GetContentSettings()->media_stream_requested_video_device()); |
| 428 EXPECT_EQ(example_video_id(), | 439 EXPECT_EQ(example_video_id(), |
| 429 GetContentSettings()->media_stream_selected_video_device()); | 440 GetContentSettings()->media_stream_selected_video_device()); |
| 430 } | 441 } |
| 431 | 442 |
| 432 // Request microphone and camera access. Block microphone, allow camera. | 443 // Request microphone and camera access. Block microphone, allow camera. |
| 433 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, | 444 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| 434 RequestMicCamBlockMic) { | 445 RequestMicCamBlockMic) { |
| 435 InitWithUrl(GURL("https://www.example.com")); | 446 InitWithUrl(GURL("https://www.example.com")); |
| 436 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); | 447 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); |
| 437 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); | 448 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| 438 std::unique_ptr<MediaStreamDevicesController> controller( | 449 // Ensure the prompt is accepted if necessary such that tab specific content |
| 439 CreateMediaStreamDevicesController( | 450 // settings are updated. |
| 440 GetWebContents(), | 451 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 441 CreateRequest(example_audio_id(), example_video_id()), | 452 RequestPermissions( |
| 442 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 453 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| 443 base::Unretained(this)))); | 454 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 444 NotifyTabSpecificContentSettings(controller.get()); | 455 base::Unretained(this))); |
| 445 | 456 |
| 446 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( | 457 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| 447 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 458 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 448 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( | 459 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( |
| 449 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 460 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 450 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( | 461 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| 451 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 462 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 452 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( | 463 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( |
| 453 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 464 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 454 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | | 465 EXPECT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 465 GetContentSettings()->media_stream_selected_video_device()); | 476 GetContentSettings()->media_stream_selected_video_device()); |
| 466 } | 477 } |
| 467 | 478 |
| 468 // Request microphone access. Requesting camera should not change microphone | 479 // Request microphone access. Requesting camera should not change microphone |
| 469 // state. | 480 // state. |
| 470 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, | 481 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| 471 RequestCamDoesNotChangeMic) { | 482 RequestCamDoesNotChangeMic) { |
| 472 InitWithUrl(GURL("https://www.example.com")); | 483 InitWithUrl(GURL("https://www.example.com")); |
| 473 // Request mic and deny. | 484 // Request mic and deny. |
| 474 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); | 485 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); |
| 475 std::unique_ptr<MediaStreamDevicesController> mic_controller( | 486 // Ensure the prompt is accepted if necessary such that tab specific content |
| 476 CreateMediaStreamDevicesController( | 487 // settings are updated. |
| 477 GetWebContents(), CreateRequest(example_audio_id(), std::string()), | 488 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 478 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 489 RequestPermissions( |
| 479 base::Unretained(this)))); | 490 GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| 480 NotifyTabSpecificContentSettings(mic_controller.get()); | 491 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 492 base::Unretained(this))); | |
| 481 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( | 493 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| 482 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 494 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 483 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( | 495 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( |
| 484 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 496 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 485 EXPECT_EQ(example_audio_id(), | 497 EXPECT_EQ(example_audio_id(), |
| 486 GetContentSettings()->media_stream_requested_audio_device()); | 498 GetContentSettings()->media_stream_requested_audio_device()); |
| 487 EXPECT_EQ(example_audio_id(), | 499 EXPECT_EQ(example_audio_id(), |
| 488 GetContentSettings()->media_stream_selected_audio_device()); | 500 GetContentSettings()->media_stream_selected_audio_device()); |
| 489 | 501 |
| 490 // Request cam and allow | 502 // Request cam and allow |
| 491 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); | 503 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| 492 std::unique_ptr<MediaStreamDevicesController> cam_controller( | 504 RequestPermissions( |
| 493 CreateMediaStreamDevicesController( | 505 GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| 494 GetWebContents(), CreateRequest(std::string(), example_video_id()), | 506 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 495 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 507 base::Unretained(this))); |
| 496 base::Unretained(this)))); | |
| 497 NotifyTabSpecificContentSettings(cam_controller.get()); | |
| 498 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( | 508 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| 499 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 509 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 500 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( | 510 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( |
| 501 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 511 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 502 EXPECT_EQ(example_video_id(), | 512 EXPECT_EQ(example_video_id(), |
| 503 GetContentSettings()->media_stream_requested_video_device()); | 513 GetContentSettings()->media_stream_requested_video_device()); |
| 504 EXPECT_EQ(example_video_id(), | 514 EXPECT_EQ(example_video_id(), |
| 505 GetContentSettings()->media_stream_selected_video_device()); | 515 GetContentSettings()->media_stream_selected_video_device()); |
| 506 | 516 |
| 507 // Mic state should not have changed. | 517 // Mic state should not have changed. |
| 508 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( | 518 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| 509 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 519 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 510 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( | 520 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( |
| 511 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 521 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 512 EXPECT_EQ(example_audio_id(), | 522 EXPECT_EQ(example_audio_id(), |
| 513 GetContentSettings()->media_stream_requested_audio_device()); | 523 GetContentSettings()->media_stream_requested_audio_device()); |
| 514 EXPECT_EQ(example_audio_id(), | 524 EXPECT_EQ(example_audio_id(), |
| 515 GetContentSettings()->media_stream_selected_audio_device()); | 525 GetContentSettings()->media_stream_selected_audio_device()); |
| 516 } | 526 } |
| 517 | 527 |
| 518 // Denying mic access after camera access should still show the camera as state. | 528 // Denying mic access after camera access should still show the camera as state. |
| 519 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, | 529 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| 520 DenyMicDoesNotChangeCam) { | 530 DenyMicDoesNotChangeCam) { |
| 521 InitWithUrl(GURL("https://www.example.com")); | 531 InitWithUrl(GURL("https://www.example.com")); |
| 522 // Request cam and allow | 532 // Request cam and allow |
| 523 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); | 533 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| 524 std::unique_ptr<MediaStreamDevicesController> cam_controller( | 534 // Ensure the prompt is accepted if necessary such that tab specific content |
| 525 CreateMediaStreamDevicesController( | 535 // settings are updated. |
| 526 GetWebContents(), CreateRequest(std::string(), example_video_id()), | 536 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 527 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 537 RequestPermissions( |
| 528 base::Unretained(this)))); | 538 GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| 529 NotifyTabSpecificContentSettings(cam_controller.get()); | 539 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 540 base::Unretained(this))); | |
| 530 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( | 541 EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| 531 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 542 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 532 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( | 543 EXPECT_FALSE(GetContentSettings()->IsContentBlocked( |
| 533 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); | 544 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| 534 EXPECT_EQ(example_video_id(), | 545 EXPECT_EQ(example_video_id(), |
| 535 GetContentSettings()->media_stream_requested_video_device()); | 546 GetContentSettings()->media_stream_requested_video_device()); |
| 536 EXPECT_EQ(example_video_id(), | 547 EXPECT_EQ(example_video_id(), |
| 537 GetContentSettings()->media_stream_selected_video_device()); | 548 GetContentSettings()->media_stream_selected_video_device()); |
| 538 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED, | 549 EXPECT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED, |
| 539 GetContentSettings()->GetMicrophoneCameraState()); | 550 GetContentSettings()->GetMicrophoneCameraState()); |
| 540 | 551 |
| 541 // Simulate that an a video stream is now being captured. | 552 // Simulate that an a video stream is now being captured. |
| 542 content::MediaStreamDevice fake_video_device( | 553 content::MediaStreamDevice fake_video_device( |
| 543 content::MEDIA_DEVICE_VIDEO_CAPTURE, example_video_id(), | 554 content::MEDIA_DEVICE_VIDEO_CAPTURE, example_video_id(), |
| 544 example_video_id()); | 555 example_video_id()); |
| 545 content::MediaStreamDevices video_devices(1, fake_video_device); | 556 content::MediaStreamDevices video_devices(1, fake_video_device); |
| 546 MediaCaptureDevicesDispatcher* dispatcher = | 557 MediaCaptureDevicesDispatcher* dispatcher = |
| 547 MediaCaptureDevicesDispatcher::GetInstance(); | 558 MediaCaptureDevicesDispatcher::GetInstance(); |
| 548 dispatcher->SetTestVideoCaptureDevices(video_devices); | 559 dispatcher->SetTestVideoCaptureDevices(video_devices); |
| 549 std::unique_ptr<content::MediaStreamUI> video_stream_ui = | 560 std::unique_ptr<content::MediaStreamUI> video_stream_ui = |
| 550 dispatcher->GetMediaStreamCaptureIndicator()->RegisterMediaStream( | 561 dispatcher->GetMediaStreamCaptureIndicator()->RegisterMediaStream( |
| 551 GetWebContents(), video_devices); | 562 GetWebContents(), video_devices); |
| 552 video_stream_ui->OnStarted(base::Closure()); | 563 video_stream_ui->OnStarted(base::Closure()); |
| 553 | 564 |
| 554 // Request mic and deny. | 565 // Request mic and deny. |
| 555 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); | 566 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); |
| 556 std::unique_ptr<MediaStreamDevicesController> mic_controller( | 567 // Ensure the prompt is accepted if necessary such that tab specific content |
| 557 CreateMediaStreamDevicesController( | 568 // settings are updated. |
| 558 GetWebContents(), CreateRequest(example_audio_id(), std::string()), | 569 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 559 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 570 RequestPermissions( |
| 560 base::Unretained(this)))); | 571 GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| 561 NotifyTabSpecificContentSettings(mic_controller.get()); | 572 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 573 base::Unretained(this))); | |
| 562 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( | 574 EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| 563 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 575 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 564 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( | 576 EXPECT_TRUE(GetContentSettings()->IsContentBlocked( |
| 565 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); | 577 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| 566 EXPECT_EQ(example_audio_id(), | 578 EXPECT_EQ(example_audio_id(), |
| 567 GetContentSettings()->media_stream_requested_audio_device()); | 579 GetContentSettings()->media_stream_requested_audio_device()); |
| 568 EXPECT_EQ(example_audio_id(), | 580 EXPECT_EQ(example_audio_id(), |
| 569 GetContentSettings()->media_stream_selected_audio_device()); | 581 GetContentSettings()->media_stream_selected_audio_device()); |
| 570 | 582 |
| 571 // Cam should still be included in the state. | 583 // Cam should still be included in the state. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 594 // which return the expected outputs for that test. | 606 // which return the expected outputs for that test. |
| 595 struct ContentSettingsTestData { | 607 struct ContentSettingsTestData { |
| 596 // The initial value of the mic/cam content settings. | 608 // The initial value of the mic/cam content settings. |
| 597 ContentSetting mic; | 609 ContentSetting mic; |
| 598 ContentSetting cam; | 610 ContentSetting cam; |
| 599 // Whether the infobar should be accepted if it's shown. | 611 // Whether the infobar should be accepted if it's shown. |
| 600 bool accept_infobar; | 612 bool accept_infobar; |
| 601 | 613 |
| 602 // Whether the infobar should be displayed to request mic/cam for the given | 614 // Whether the infobar should be displayed to request mic/cam for the given |
| 603 // content settings inputs. | 615 // content settings inputs. |
| 604 bool ExpectMicInfobar() const { return mic == CONTENT_SETTING_ASK; } | 616 int NumExpectedPrompts() const { |
| 605 bool ExpectCamInfobar() const { return cam == CONTENT_SETTING_ASK; } | 617 int result = 0; |
| 618 if (mic == CONTENT_SETTING_ASK) | |
| 619 ++result; | |
| 620 if (cam == CONTENT_SETTING_ASK) | |
| 621 ++result; | |
| 622 return result; | |
| 623 } | |
| 606 | 624 |
| 607 // Whether or not the mic/cam should be allowed after clicking accept/deny for | 625 // Whether or not the mic/cam should be allowed after clicking accept/deny for |
| 608 // the given inputs. | 626 // the given inputs. |
| 609 bool ExpectMicAllowed() const { | 627 bool ExpectMicAllowed() const { |
| 610 return mic == CONTENT_SETTING_ALLOW || | 628 return mic == CONTENT_SETTING_ALLOW || |
| 611 (mic == CONTENT_SETTING_ASK && accept_infobar); | 629 (mic == CONTENT_SETTING_ASK && accept_infobar); |
| 612 } | 630 } |
| 613 bool ExpectCamAllowed() const { | 631 bool ExpectCamAllowed() const { |
| 614 return cam == CONTENT_SETTING_ALLOW || | 632 return cam == CONTENT_SETTING_ALLOW || |
| 615 (cam == CONTENT_SETTING_ASK && accept_infobar); | 633 (cam == CONTENT_SETTING_ASK && accept_infobar); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 647 | 665 |
| 648 {CONTENT_SETTING_ASK, CONTENT_SETTING_ALLOW, false}, | 666 {CONTENT_SETTING_ASK, CONTENT_SETTING_ALLOW, false}, |
| 649 {CONTENT_SETTING_ASK, CONTENT_SETTING_ALLOW, true}, | 667 {CONTENT_SETTING_ASK, CONTENT_SETTING_ALLOW, true}, |
| 650 | 668 |
| 651 {CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK, false}, | 669 {CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK, false}, |
| 652 {CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK, true}, | 670 {CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK, true}, |
| 653 }; | 671 }; |
| 654 | 672 |
| 655 for (auto& test : tests) { | 673 for (auto& test : tests) { |
| 656 SetContentSettings(test.mic, test.cam); | 674 SetContentSettings(test.mic, test.cam); |
| 657 std::unique_ptr<MediaStreamDevicesController> controller( | 675 |
| 658 CreateMediaStreamDevicesController( | 676 prompt_delegate()->ResetCounts(); |
| 659 GetWebContents(), | 677 |
| 660 CreateRequest(example_audio_id(), example_video_id()), | 678 // Accept or deny the infobar if it's showing. |
| 661 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 679 if (test.NumExpectedPrompts() > 0) { |
| 662 base::Unretained(this)))); | 680 if (test.accept_infobar) { |
| 681 prompt_delegate()->set_response_type( | |
| 682 PermissionRequestManager::ACCEPT_ALL); | |
| 683 } else { | |
| 684 prompt_delegate()->set_response_type( | |
| 685 PermissionRequestManager::DENY_ALL); | |
| 686 } | |
| 687 } else { | |
| 688 prompt_delegate()->set_response_type(PermissionRequestManager::NONE); | |
| 689 } | |
| 690 RequestPermissions( | |
| 691 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), | |
| 692 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | |
| 693 base::Unretained(this))); | |
| 663 | 694 |
| 664 // Check that the infobar is requesting the expected cam/mic values. | 695 // Check that the infobar is requesting the expected cam/mic values. |
| 665 ASSERT_EQ(test.ExpectMicInfobar(), IsAskingForAudio(controller.get())); | 696 ASSERT_EQ(test.NumExpectedPrompts(), |
|
Timothy Loh
2017/02/28 00:39:20
This makes the test a bit less thorough, can we re
raymes
2017/03/01 02:08:01
That's true. I kept the checks back in by storing
| |
| 666 ASSERT_EQ(test.ExpectCamInfobar(), IsAskingForVideo(controller.get())); | 697 prompt_delegate()->total_request_count()); |
| 667 | |
| 668 // Accept or deny the infobar if it's showing. | |
| 669 if (test.ExpectMicInfobar() || test.ExpectCamInfobar()) { | |
| 670 if (test.accept_infobar) | |
| 671 PermissionGranted(controller.get()); | |
| 672 else | |
| 673 PermissionDenied(controller.get()); | |
| 674 } | |
| 675 | 698 |
| 676 // Check the media stream result is expected and the devices returned are | 699 // Check the media stream result is expected and the devices returned are |
| 677 // expected; | 700 // expected; |
| 678 ASSERT_EQ(test.ExpectedMediaStreamResult(), media_stream_result()); | 701 ASSERT_EQ(test.ExpectedMediaStreamResult(), media_stream_result()); |
| 679 ASSERT_EQ(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE), | 702 ASSERT_EQ(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE), |
| 680 test.ExpectMicAllowed()); | 703 test.ExpectMicAllowed()); |
| 681 ASSERT_EQ(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE), | 704 ASSERT_EQ(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE), |
| 682 test.ExpectCamAllowed()); | 705 test.ExpectCamAllowed()); |
| 683 } | 706 } |
| 684 } | 707 } |
| 685 | 708 |
| 686 // Request and allow camera access on WebUI pages without prompting. | 709 // Request and allow camera access on WebUI pages without prompting. |
| 687 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, | 710 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| 688 WebUIRequestAndAllowCam) { | 711 WebUIRequestAndAllowCam) { |
| 689 InitWithUrl(GURL("chrome://test-page")); | 712 InitWithUrl(GURL("chrome://test-page")); |
| 690 std::unique_ptr<MediaStreamDevicesController> controller( | 713 RequestPermissions( |
| 691 CreateMediaStreamDevicesController( | 714 GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| 692 GetWebContents(), CreateRequest(std::string(), example_video_id()), | 715 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 693 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 716 base::Unretained(this))); |
| 694 base::Unretained(this)))); | |
| 695 | 717 |
| 696 ASSERT_FALSE(IsAskingForAudio(controller.get())); | 718 ASSERT_EQ(0, prompt_delegate()->total_request_count()); |
| 697 ASSERT_FALSE(IsAskingForVideo(controller.get())); | |
| 698 | 719 |
| 699 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); | 720 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); |
| 700 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); | 721 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); |
| 701 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); | 722 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); |
| 702 } | 723 } |
| 703 | 724 |
| 704 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, | 725 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| 705 ExtensionRequestMicCam) { | 726 ExtensionRequestMicCam) { |
| 706 InitWithUrl(GURL("chrome-extension://test-page")); | 727 InitWithUrl(GURL("chrome-extension://test-page")); |
| 707 // Test that a prompt is required. | 728 // Test that a prompt is required. |
| 708 std::unique_ptr<MediaStreamDevicesController> controller( | 729 prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| 709 CreateMediaStreamDevicesController( | 730 RequestPermissions( |
| 710 GetWebContents(), | 731 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| 711 CreateRequest(example_audio_id(), example_video_id()), | 732 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 712 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 733 base::Unretained(this))); |
| 713 base::Unretained(this)))); | 734 ASSERT_EQ(2, prompt_delegate()->total_request_count()); |
| 714 ASSERT_TRUE(IsAskingForAudio(controller.get())); | |
| 715 ASSERT_TRUE(IsAskingForVideo(controller.get())); | |
| 716 | 735 |
| 717 // Accept the prompt. | 736 // Accept the prompt. |
| 718 PermissionGranted(controller.get()); | |
| 719 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); | 737 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); |
| 720 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); | 738 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); |
| 721 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); | 739 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); |
| 722 | 740 |
| 723 // Check that re-requesting allows without prompting. | 741 // Check that re-requesting allows without prompting. |
| 724 std::unique_ptr<MediaStreamDevicesController> controller2( | 742 prompt_delegate()->ResetCounts(); |
| 725 CreateMediaStreamDevicesController( | 743 RequestPermissions( |
| 726 GetWebContents(), | 744 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| 727 CreateRequest(example_audio_id(), example_video_id()), | 745 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 728 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 746 base::Unretained(this))); |
| 729 base::Unretained(this)))); | 747 ASSERT_EQ(0, prompt_delegate()->total_request_count()); |
| 730 ASSERT_FALSE(IsAskingForAudio(controller2.get())); | |
| 731 ASSERT_FALSE(IsAskingForVideo(controller2.get())); | |
| 732 | 748 |
| 733 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); | 749 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); |
| 734 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); | 750 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); |
| 735 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); | 751 ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); |
| 736 } | 752 } |
| 737 | 753 |
| 738 // For Pepper request from insecure origin, even if it's ALLOW, it won't be | 754 // For Pepper request from insecure origin, even if it's ALLOW, it won't be |
| 739 // changed to ASK. | 755 // changed to ASK. |
| 740 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, | 756 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| 741 PepperRequestInsecure) { | 757 PepperRequestInsecure) { |
| 742 InitWithUrl(GURL("http://www.example.com")); | 758 InitWithUrl(GURL("http://www.example.com")); |
| 743 SetContentSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW); | 759 SetContentSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW); |
| 744 | 760 |
| 745 std::unique_ptr<MediaStreamDevicesController> controller( | 761 RequestPermissions( |
| 746 CreateMediaStreamDevicesController( | 762 GetWebContents(), |
| 747 GetWebContents(), | 763 CreateRequestWithType(example_audio_id(), std::string(), |
| 748 CreateRequestWithType(example_audio_id(), std::string(), | 764 content::MEDIA_OPEN_DEVICE_PEPPER_ONLY), |
| 749 content::MEDIA_OPEN_DEVICE_PEPPER_ONLY), | 765 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 750 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 766 base::Unretained(this))); |
| 751 base::Unretained(this)))); | 767 ASSERT_EQ(0, prompt_delegate()->total_request_count()); |
| 752 ASSERT_FALSE(IsAskingForAudio(controller.get())); | |
| 753 ASSERT_FALSE(IsAskingForVideo(controller.get())); | |
| 754 } | 768 } |
| 755 | 769 |
| 756 // Request and block microphone and camera access with kill switch. | 770 // Request and block microphone and camera access with kill switch. |
| 757 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, | 771 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| 758 RequestAndKillSwitchMicCam) { | 772 RequestAndKillSwitchMicCam) { |
| 759 std::map<std::string, std::string> params; | 773 std::map<std::string, std::string> params; |
| 760 params[PermissionUtil::GetPermissionString( | 774 params[PermissionUtil::GetPermissionString( |
| 761 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)] = | 775 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)] = |
| 762 PermissionContextBase::kPermissionsKillSwitchBlockedValue; | 776 PermissionContextBase::kPermissionsKillSwitchBlockedValue; |
| 763 params[PermissionUtil::GetPermissionString( | 777 params[PermissionUtil::GetPermissionString( |
| 764 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)] = | 778 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)] = |
| 765 PermissionContextBase::kPermissionsKillSwitchBlockedValue; | 779 PermissionContextBase::kPermissionsKillSwitchBlockedValue; |
| 766 variations::AssociateVariationParams( | 780 variations::AssociateVariationParams( |
| 767 PermissionContextBase::kPermissionsKillSwitchFieldStudy, | 781 PermissionContextBase::kPermissionsKillSwitchFieldStudy, |
| 768 "TestGroup", params); | 782 "TestGroup", params); |
| 769 base::FieldTrialList::CreateFieldTrial( | 783 base::FieldTrialList::CreateFieldTrial( |
| 770 PermissionContextBase::kPermissionsKillSwitchFieldStudy, | 784 PermissionContextBase::kPermissionsKillSwitchFieldStudy, |
| 771 "TestGroup"); | 785 "TestGroup"); |
| 772 InitWithUrl(GURL("https://www.example.com")); | 786 InitWithUrl(GURL("https://www.example.com")); |
| 773 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); | 787 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); |
| 774 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); | 788 SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| 775 std::unique_ptr<MediaStreamDevicesController> controller( | 789 RequestPermissions( |
| 776 CreateMediaStreamDevicesController( | 790 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| 777 GetWebContents(), | 791 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 778 CreateRequest(example_audio_id(), example_video_id()), | 792 base::Unretained(this))); |
| 779 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | |
| 780 base::Unretained(this)))); | |
| 781 | 793 |
| 782 EXPECT_FALSE(IsAskingForAudio(controller.get())); | 794 ASSERT_EQ(0, prompt_delegate()->total_request_count()); |
| 783 EXPECT_FALSE(IsAskingForVideo(controller.get())); | |
| 784 | 795 |
| 785 ASSERT_EQ(content::MEDIA_DEVICE_KILL_SWITCH_ON, media_stream_result()); | 796 ASSERT_EQ(content::MEDIA_DEVICE_KILL_SWITCH_ON, media_stream_result()); |
| 786 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); | 797 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); |
| 787 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); | 798 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); |
| 788 } | 799 } |
| OLD | NEW |