| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/renderer_host/media/media_devices_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/media_devices_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 audio_manager_.reset( | 57 audio_manager_.reset( |
| 58 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); | 58 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); |
| 59 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 59 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
| 60 | 60 |
| 61 MockResourceContext* mock_resource_context = | 61 MockResourceContext* mock_resource_context = |
| 62 static_cast<MockResourceContext*>( | 62 static_cast<MockResourceContext*>( |
| 63 browser_context_.GetResourceContext()); | 63 browser_context_.GetResourceContext()); |
| 64 | 64 |
| 65 host_ = base::MakeUnique<MediaDevicesDispatcherHost>( | 65 host_ = base::MakeUnique<MediaDevicesDispatcherHost>( |
| 66 kProcessId, kRenderId, mock_resource_context->GetMediaDeviceIDSalt(), | 66 kProcessId, kRenderId, mock_resource_context->GetMediaDeviceIDSalt(), |
| 67 media_stream_manager_.get(), true /* use_fake_ui */); | 67 media_stream_manager_.get()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void SetUp() override { | 70 void SetUp() override { |
| 71 base::RunLoop run_loop; | 71 base::RunLoop run_loop; |
| 72 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; | 72 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; |
| 73 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true; | 73 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true; |
| 74 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true; | 74 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true; |
| 75 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true; | 75 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true; |
| 76 media_stream_manager_->media_devices_manager()->EnumerateDevices( | 76 media_stream_manager_->media_devices_manager()->EnumerateDevices( |
| 77 devices_to_enumerate, | 77 devices_to_enumerate, |
| 78 base::Bind(&PhysicalDevicesEnumerated, run_loop.QuitClosure(), | 78 base::Bind(&PhysicalDevicesEnumerated, run_loop.QuitClosure(), |
| 79 &physical_devices_)); | 79 &physical_devices_)); |
| 80 run_loop.Run(); | 80 run_loop.Run(); |
| 81 | 81 |
| 82 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_AUDIO_INPUT].size(), 0u); | 82 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_AUDIO_INPUT].size(), 0u); |
| 83 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_VIDEO_INPUT].size(), 0u); | 83 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_VIDEO_INPUT].size(), 0u); |
| 84 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT].size(), 0u); | 84 ASSERT_GT(physical_devices_[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT].size(), 0u); |
| 85 } | 85 } |
| 86 | 86 |
| 87 protected: | 87 protected: |
| 88 void DevicesEnumerated( | 88 void DevicesEnumerated( |
| 89 const base::Closure& closure, | 89 const base::Closure& closure, |
| 90 const std::vector<std::vector<MediaDeviceInfo>>& devices) { | 90 const std::vector<std::vector<MediaDeviceInfo>>& devices) { |
| 91 enumerated_devices_ = devices; | 91 enumerated_devices_ = devices; |
| 92 closure.Run(); | 92 closure.Run(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void EnumerateDevicesAndWaitForResult( | 95 void EnumerateDevicesAndWaitForResult(bool enumerate_audio_input, |
| 96 bool enumerate_audio_input, | 96 bool enumerate_video_input, |
| 97 bool enumerate_video_input, | 97 bool enumerate_audio_output, |
| 98 bool enumerate_audio_output, | 98 bool permission_override_value = true) { |
| 99 std::unique_ptr<MediaStreamUIProxy> ui_proxy) { | 99 MediaDevicesPermissionChecker permission_checker; |
| 100 if (ui_proxy) | 100 permission_checker.OverridePermissions(permission_override_value); |
| 101 host_->SetFakeUIProxyForTesting(std::move(ui_proxy)); | 101 host_->SetPermissionChecker(permission_checker); |
| 102 base::RunLoop run_loop; | 102 base::RunLoop run_loop; |
| 103 host_->EnumerateDevices( | 103 host_->EnumerateDevices( |
| 104 enumerate_audio_input, enumerate_video_input, enumerate_audio_output, | 104 enumerate_audio_input, enumerate_video_input, enumerate_audio_output, |
| 105 origin_, base::Bind(&MediaDevicesDispatcherHostTest::DevicesEnumerated, | 105 origin_, base::Bind(&MediaDevicesDispatcherHostTest::DevicesEnumerated, |
| 106 base::Unretained(this), run_loop.QuitClosure())); | 106 base::Unretained(this), run_loop.QuitClosure())); |
| 107 run_loop.Run(); | 107 run_loop.Run(); |
| 108 | 108 |
| 109 ASSERT_FALSE(enumerated_devices_.empty()); | 109 ASSERT_FALSE(enumerated_devices_.empty()); |
| 110 if (enumerate_audio_input) | 110 if (enumerate_audio_input) |
| 111 EXPECT_FALSE(enumerated_devices_[MEDIA_DEVICE_TYPE_AUDIO_INPUT].empty()); | 111 EXPECT_FALSE(enumerated_devices_[MEDIA_DEVICE_TYPE_AUDIO_INPUT].empty()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> | 190 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> |
| 191 audio_manager_; | 191 audio_manager_; |
| 192 content::TestBrowserContext browser_context_; | 192 content::TestBrowserContext browser_context_; |
| 193 MediaDeviceEnumeration physical_devices_; | 193 MediaDeviceEnumeration physical_devices_; |
| 194 url::Origin origin_; | 194 url::Origin origin_; |
| 195 | 195 |
| 196 std::vector<std::vector<MediaDeviceInfo>> enumerated_devices_; | 196 std::vector<std::vector<MediaDeviceInfo>> enumerated_devices_; |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioInputDevices) { | 199 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioInputDevices) { |
| 200 EnumerateDevicesAndWaitForResult(true, false, false, nullptr); | 200 EnumerateDevicesAndWaitForResult(true, false, false); |
| 201 EXPECT_TRUE(DoesContainLabels(enumerated_devices_)); | 201 EXPECT_TRUE(DoesContainLabels(enumerated_devices_)); |
| 202 } | 202 } |
| 203 | 203 |
| 204 TEST_F(MediaDevicesDispatcherHostTest, EnumerateVideoInputDevices) { | 204 TEST_F(MediaDevicesDispatcherHostTest, EnumerateVideoInputDevices) { |
| 205 EnumerateDevicesAndWaitForResult(false, true, false, nullptr); | 205 EnumerateDevicesAndWaitForResult(false, true, false); |
| 206 EXPECT_TRUE(DoesContainLabels(enumerated_devices_)); | 206 EXPECT_TRUE(DoesContainLabels(enumerated_devices_)); |
| 207 } | 207 } |
| 208 | 208 |
| 209 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioOutputDevices) { | 209 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioOutputDevices) { |
| 210 EnumerateDevicesAndWaitForResult(false, false, true, nullptr); | 210 EnumerateDevicesAndWaitForResult(false, false, true); |
| 211 EXPECT_TRUE(DoesContainLabels(enumerated_devices_)); | 211 EXPECT_TRUE(DoesContainLabels(enumerated_devices_)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAllDevices) { | 214 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAllDevices) { |
| 215 EnumerateDevicesAndWaitForResult(true, true, true, nullptr); | 215 EnumerateDevicesAndWaitForResult(true, true, true); |
| 216 EXPECT_TRUE(DoesContainLabels(enumerated_devices_)); | 216 EXPECT_TRUE(DoesContainLabels(enumerated_devices_)); |
| 217 } | 217 } |
| 218 | 218 |
| 219 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioInputDevicesNoAccess) { | 219 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioInputDevicesNoAccess) { |
| 220 std::unique_ptr<FakeMediaStreamUIProxy> fake_ui_proxy = | 220 EnumerateDevicesAndWaitForResult(true, false, false, false); |
| 221 base::MakeUnique<FakeMediaStreamUIProxy>(); | |
| 222 fake_ui_proxy->SetMicAccess(false); | |
| 223 EnumerateDevicesAndWaitForResult(true, false, false, | |
| 224 std::move(fake_ui_proxy)); | |
| 225 EXPECT_TRUE(DoesNotContainLabels(enumerated_devices_)); | 221 EXPECT_TRUE(DoesNotContainLabels(enumerated_devices_)); |
| 226 } | 222 } |
| 227 | 223 |
| 228 TEST_F(MediaDevicesDispatcherHostTest, EnumerateVideoInputDevicesNoAccess) { | 224 TEST_F(MediaDevicesDispatcherHostTest, EnumerateVideoInputDevicesNoAccess) { |
| 229 std::unique_ptr<FakeMediaStreamUIProxy> fake_ui_proxy = | 225 EnumerateDevicesAndWaitForResult(false, true, false, false); |
| 230 base::MakeUnique<FakeMediaStreamUIProxy>(); | |
| 231 fake_ui_proxy->SetCameraAccess(false); | |
| 232 EnumerateDevicesAndWaitForResult(false, true, false, | |
| 233 std::move(fake_ui_proxy)); | |
| 234 EXPECT_TRUE(DoesNotContainLabels(enumerated_devices_)); | 226 EXPECT_TRUE(DoesNotContainLabels(enumerated_devices_)); |
| 235 } | 227 } |
| 236 | 228 |
| 237 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioOutputDevicesNoAccess) { | 229 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioOutputDevicesNoAccess) { |
| 238 std::unique_ptr<FakeMediaStreamUIProxy> fake_ui_proxy = | 230 EnumerateDevicesAndWaitForResult(false, false, true, false); |
| 239 base::MakeUnique<FakeMediaStreamUIProxy>(); | |
| 240 fake_ui_proxy->SetMicAccess(false); | |
| 241 EnumerateDevicesAndWaitForResult(false, false, true, | |
| 242 std::move(fake_ui_proxy)); | |
| 243 EXPECT_TRUE(DoesNotContainLabels(enumerated_devices_)); | 231 EXPECT_TRUE(DoesNotContainLabels(enumerated_devices_)); |
| 244 } | 232 } |
| 245 | 233 |
| 246 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAllDevicesNoAccess) { | 234 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAllDevicesNoAccess) { |
| 247 std::unique_ptr<FakeMediaStreamUIProxy> fake_ui_proxy = | 235 EnumerateDevicesAndWaitForResult(true, true, true, false); |
| 248 base::MakeUnique<FakeMediaStreamUIProxy>(); | |
| 249 fake_ui_proxy->SetMicAccess(false); | |
| 250 fake_ui_proxy->SetCameraAccess(false); | |
| 251 EnumerateDevicesAndWaitForResult(true, true, true, std::move(fake_ui_proxy)); | |
| 252 EXPECT_TRUE(DoesNotContainLabels(enumerated_devices_)); | 236 EXPECT_TRUE(DoesNotContainLabels(enumerated_devices_)); |
| 253 } | 237 } |
| 254 | 238 |
| 255 }; // namespace content | 239 }; // namespace content |
| OLD | NEW |