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 "content/renderer/media/user_media_client_impl.h" | 5 #include "content/renderer/media/user_media_client_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 blink::WebMediaDevicesRequest* request, | 199 blink::WebMediaDevicesRequest* request, |
200 blink::WebVector<blink::WebMediaDeviceInfo>& devices) override { | 200 blink::WebVector<blink::WebMediaDeviceInfo>& devices) override { |
201 state_ = REQUEST_SUCCEEDED; | 201 state_ = REQUEST_SUCCEEDED; |
202 last_devices_ = devices; | 202 last_devices_ = devices; |
203 } | 203 } |
204 | 204 |
205 void SetCreateSourceThatFails(bool should_fail) { | 205 void SetCreateSourceThatFails(bool should_fail) { |
206 create_source_that_fails_ = should_fail; | 206 create_source_that_fails_ = should_fail; |
207 } | 207 } |
208 | 208 |
209 static void SignalSourceReady( | |
210 const MediaStreamSource::ConstraintsCallback& source_ready, | |
211 MediaStreamSource* source) { | |
212 source_ready.Run(source, MEDIA_DEVICE_OK, ""); | |
213 } | |
214 | |
215 MediaStreamAudioSource* CreateAudioSource( | 209 MediaStreamAudioSource* CreateAudioSource( |
216 const StreamDeviceInfo& device, | 210 const StreamDeviceInfo& device, |
217 const blink::WebMediaConstraints& constraints, | 211 const blink::WebMediaConstraints& constraints) override { |
218 const MediaStreamSource::ConstraintsCallback& source_ready) override { | |
219 MediaStreamAudioSource* source; | 212 MediaStreamAudioSource* source; |
220 if (create_source_that_fails_) { | 213 if (create_source_that_fails_) { |
221 class FailedAtLifeAudioSource : public MediaStreamAudioSource { | 214 class FailedAtLifeAudioSource : public MediaStreamAudioSource { |
222 public: | 215 public: |
223 FailedAtLifeAudioSource() : MediaStreamAudioSource(true) {} | 216 FailedAtLifeAudioSource() : MediaStreamAudioSource(true) {} |
224 ~FailedAtLifeAudioSource() override {} | 217 ~FailedAtLifeAudioSource() override {} |
225 protected: | 218 protected: |
226 bool EnsureSourceIsStarted() override { | 219 bool EnsureSourceIsStarted() override { |
227 return false; | 220 return false; |
228 } | 221 } |
229 }; | 222 }; |
230 source = new FailedAtLifeAudioSource(); | 223 source = new FailedAtLifeAudioSource(); |
231 } else { | 224 } else { |
232 source = new MediaStreamAudioSource(true); | 225 source = new MediaStreamAudioSource(true); |
233 } | 226 } |
234 source->SetDeviceInfo(device); | 227 source->SetDeviceInfo(device); |
235 | |
236 if (!create_source_that_fails_) { | |
237 // RunUntilIdle is required for this task to complete. | |
238 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
239 FROM_HERE, | |
240 base::Bind(&UserMediaClientImplUnderTest::SignalSourceReady, | |
241 source_ready, source)); | |
242 } | |
243 | |
244 return source; | 228 return source; |
245 } | 229 } |
246 | 230 |
247 MediaStreamVideoSource* CreateVideoSource( | 231 MediaStreamVideoSource* CreateVideoSource( |
248 const StreamDeviceInfo& device, | 232 const StreamDeviceInfo& device, |
249 const MediaStreamSource::SourceStoppedCallback& stop_callback) override { | 233 const MediaStreamSource::SourceStoppedCallback& stop_callback) override { |
250 video_source_ = new MockMediaStreamVideoCapturerSource(device, | 234 video_source_ = new MockMediaStreamVideoCapturerSource(device, |
251 stop_callback, | 235 stop_callback, |
252 factory_); | 236 factory_); |
253 return video_source_; | 237 return video_source_; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 EXPECT_NE(audio_tracks[0].id(), video_tracks[0].id()); | 339 EXPECT_NE(audio_tracks[0].id(), video_tracks[0].id()); |
356 return desc; | 340 return desc; |
357 } | 341 } |
358 | 342 |
359 void FakeMediaStreamDispatcherRequestUserMediaComplete() { | 343 void FakeMediaStreamDispatcherRequestUserMediaComplete() { |
360 // Audio request ID is used as the shared request ID. | 344 // Audio request ID is used as the shared request ID. |
361 user_media_client_impl_->OnStreamGenerated( | 345 user_media_client_impl_->OnStreamGenerated( |
362 ms_dispatcher_->audio_input_request_id(), | 346 ms_dispatcher_->audio_input_request_id(), |
363 ms_dispatcher_->stream_label(), ms_dispatcher_->audio_input_array(), | 347 ms_dispatcher_->stream_label(), ms_dispatcher_->audio_input_array(), |
364 ms_dispatcher_->video_array()); | 348 ms_dispatcher_->video_array()); |
365 base::RunLoop().RunUntilIdle(); | |
366 } | 349 } |
367 | 350 |
368 void StartMockedVideoSource() { | 351 void StartMockedVideoSource() { |
369 MockMediaStreamVideoCapturerSource* video_source = | 352 MockMediaStreamVideoCapturerSource* video_source = |
370 user_media_client_impl_->last_created_video_source(); | 353 user_media_client_impl_->last_created_video_source(); |
371 if (video_source->SourceHasAttemptedToStart()) | 354 if (video_source->SourceHasAttemptedToStart()) |
372 video_source->StartMockedSource(); | 355 video_source->StartMockedSource(); |
373 } | 356 } |
374 | 357 |
375 void FailToStartMockedVideoSource() { | 358 void FailToStartMockedVideoSource() { |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 blink::WebMediaConstraints audio_constraints = CreateDeviceConstraints( | 873 blink::WebMediaConstraints audio_constraints = CreateDeviceConstraints( |
891 nullptr, kInvalidDeviceId, kInvalidDeviceId, kFakeAudioInputDeviceId1); | 874 nullptr, kInvalidDeviceId, kInvalidDeviceId, kFakeAudioInputDeviceId1); |
892 blink::WebMediaConstraints video_constraints = CreateDeviceConstraints( | 875 blink::WebMediaConstraints video_constraints = CreateDeviceConstraints( |
893 nullptr, kInvalidDeviceId, kInvalidDeviceId, kFakeVideoInputDeviceId1); | 876 nullptr, kInvalidDeviceId, kInvalidDeviceId, kFakeVideoInputDeviceId1); |
894 TestValidRequestWithDeviceConstraints(audio_constraints, video_constraints, | 877 TestValidRequestWithDeviceConstraints(audio_constraints, video_constraints, |
895 kFakeAudioInputDeviceId1, | 878 kFakeAudioInputDeviceId1, |
896 kFakeVideoInputDeviceId1); | 879 kFakeVideoInputDeviceId1); |
897 } | 880 } |
898 | 881 |
899 } // namespace content | 882 } // namespace content |
OLD | NEW |