| 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  | 
|  209   MediaStreamAudioSource* CreateAudioSource( |  215   MediaStreamAudioSource* CreateAudioSource( | 
|  210       const StreamDeviceInfo& device, |  216       const StreamDeviceInfo& device, | 
|  211       const blink::WebMediaConstraints& constraints) override { |  217       const blink::WebMediaConstraints& constraints, | 
 |  218       const MediaStreamSource::ConstraintsCallback& source_ready) override { | 
|  212     MediaStreamAudioSource* source; |  219     MediaStreamAudioSource* source; | 
|  213     if (create_source_that_fails_) { |  220     if (create_source_that_fails_) { | 
|  214       class FailedAtLifeAudioSource : public MediaStreamAudioSource { |  221       class FailedAtLifeAudioSource : public MediaStreamAudioSource { | 
|  215        public: |  222        public: | 
|  216         FailedAtLifeAudioSource() : MediaStreamAudioSource(true) {} |  223         FailedAtLifeAudioSource() : MediaStreamAudioSource(true) {} | 
|  217         ~FailedAtLifeAudioSource() override {} |  224         ~FailedAtLifeAudioSource() override {} | 
|  218        protected: |  225        protected: | 
|  219         bool EnsureSourceIsStarted() override { |  226         bool EnsureSourceIsStarted() override { | 
|  220           return false; |  227           return false; | 
|  221         } |  228         } | 
|  222       }; |  229       }; | 
|  223       source = new FailedAtLifeAudioSource(); |  230       source = new FailedAtLifeAudioSource(); | 
|  224     } else { |  231     } else { | 
|  225       source = new MediaStreamAudioSource(true); |  232       source = new MediaStreamAudioSource(true); | 
|  226     } |  233     } | 
|  227     source->SetDeviceInfo(device); |  234     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  | 
|  228     return source; |  244     return source; | 
|  229   } |  245   } | 
|  230  |  246  | 
|  231   MediaStreamVideoSource* CreateVideoSource( |  247   MediaStreamVideoSource* CreateVideoSource( | 
|  232       const StreamDeviceInfo& device, |  248       const StreamDeviceInfo& device, | 
|  233       const MediaStreamSource::SourceStoppedCallback& stop_callback) override { |  249       const MediaStreamSource::SourceStoppedCallback& stop_callback) override { | 
|  234     video_source_ = new MockMediaStreamVideoCapturerSource(device, |  250     video_source_ = new MockMediaStreamVideoCapturerSource(device, | 
|  235                                                            stop_callback, |  251                                                            stop_callback, | 
|  236                                                            factory_); |  252                                                            factory_); | 
|  237     return video_source_; |  253     return video_source_; | 
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  339     EXPECT_NE(audio_tracks[0].id(), video_tracks[0].id()); |  355     EXPECT_NE(audio_tracks[0].id(), video_tracks[0].id()); | 
|  340     return desc; |  356     return desc; | 
|  341   } |  357   } | 
|  342  |  358  | 
|  343   void FakeMediaStreamDispatcherRequestUserMediaComplete() { |  359   void FakeMediaStreamDispatcherRequestUserMediaComplete() { | 
|  344     // Audio request ID is used as the shared request ID. |  360     // Audio request ID is used as the shared request ID. | 
|  345     user_media_client_impl_->OnStreamGenerated( |  361     user_media_client_impl_->OnStreamGenerated( | 
|  346         ms_dispatcher_->audio_input_request_id(), |  362         ms_dispatcher_->audio_input_request_id(), | 
|  347         ms_dispatcher_->stream_label(), ms_dispatcher_->audio_input_array(), |  363         ms_dispatcher_->stream_label(), ms_dispatcher_->audio_input_array(), | 
|  348         ms_dispatcher_->video_array()); |  364         ms_dispatcher_->video_array()); | 
 |  365     base::RunLoop().RunUntilIdle(); | 
|  349   } |  366   } | 
|  350  |  367  | 
|  351   void StartMockedVideoSource() { |  368   void StartMockedVideoSource() { | 
|  352     MockMediaStreamVideoCapturerSource* video_source = |  369     MockMediaStreamVideoCapturerSource* video_source = | 
|  353         user_media_client_impl_->last_created_video_source(); |  370         user_media_client_impl_->last_created_video_source(); | 
|  354     if (video_source->SourceHasAttemptedToStart()) |  371     if (video_source->SourceHasAttemptedToStart()) | 
|  355       video_source->StartMockedSource(); |  372       video_source->StartMockedSource(); | 
|  356   } |  373   } | 
|  357  |  374  | 
|  358   void FailToStartMockedVideoSource() { |  375   void FailToStartMockedVideoSource() { | 
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  873   blink::WebMediaConstraints audio_constraints = CreateDeviceConstraints( |  890   blink::WebMediaConstraints audio_constraints = CreateDeviceConstraints( | 
|  874       nullptr, kInvalidDeviceId, kInvalidDeviceId, kFakeAudioInputDeviceId1); |  891       nullptr, kInvalidDeviceId, kInvalidDeviceId, kFakeAudioInputDeviceId1); | 
|  875   blink::WebMediaConstraints video_constraints = CreateDeviceConstraints( |  892   blink::WebMediaConstraints video_constraints = CreateDeviceConstraints( | 
|  876       nullptr, kInvalidDeviceId, kInvalidDeviceId, kFakeVideoInputDeviceId1); |  893       nullptr, kInvalidDeviceId, kInvalidDeviceId, kFakeVideoInputDeviceId1); | 
|  877   TestValidRequestWithDeviceConstraints(audio_constraints, video_constraints, |  894   TestValidRequestWithDeviceConstraints(audio_constraints, video_constraints, | 
|  878                                         kFakeAudioInputDeviceId1, |  895                                         kFakeAudioInputDeviceId1, | 
|  879                                         kFakeVideoInputDeviceId1); |  896                                         kFakeVideoInputDeviceId1); | 
|  880 } |  897 } | 
|  881  |  898  | 
|  882 }  // namespace content |  899 }  // namespace content | 
| OLD | NEW |