| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 UserMediaClientImplUnderTest( | 55 UserMediaClientImplUnderTest( |
| 56 PeerConnectionDependencyFactory* dependency_factory, | 56 PeerConnectionDependencyFactory* dependency_factory, |
| 57 std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher) | 57 std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher) |
| 58 : UserMediaClientImpl(NULL, | 58 : UserMediaClientImpl(NULL, |
| 59 dependency_factory, | 59 dependency_factory, |
| 60 std::move(media_stream_dispatcher)), | 60 std::move(media_stream_dispatcher)), |
| 61 state_(REQUEST_NOT_STARTED), | 61 state_(REQUEST_NOT_STARTED), |
| 62 result_(NUM_MEDIA_REQUEST_RESULTS), | 62 result_(NUM_MEDIA_REQUEST_RESULTS), |
| 63 result_name_(""), | 63 result_name_(""), |
| 64 factory_(dependency_factory), | 64 factory_(dependency_factory), |
| 65 create_source_that_fails_(false), | |
| 66 video_source_(NULL) {} | 65 video_source_(NULL) {} |
| 67 | 66 |
| 68 void RequestUserMedia(const blink::WebUserMediaRequest& user_media_request) { | 67 void RequestUserMedia(const blink::WebUserMediaRequest& user_media_request) { |
| 69 state_ = REQUEST_NOT_COMPLETE; | 68 state_ = REQUEST_NOT_COMPLETE; |
| 70 requestUserMedia(user_media_request); | 69 requestUserMedia(user_media_request); |
| 71 } | 70 } |
| 72 | 71 |
| 73 void RequestUserMedia() { | 72 void RequestUserMedia() { |
| 74 blink::WebUserMediaRequest user_media_request; | 73 blink::WebUserMediaRequest user_media_request; |
| 75 RequestUserMedia(user_media_request); | 74 RequestUserMedia(user_media_request); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 last_devices_ = devices; | 119 last_devices_ = devices; |
| 121 } | 120 } |
| 122 | 121 |
| 123 void EnumerateSourcesSucceded( | 122 void EnumerateSourcesSucceded( |
| 124 blink::WebMediaStreamTrackSourcesRequest* request, | 123 blink::WebMediaStreamTrackSourcesRequest* request, |
| 125 blink::WebVector<blink::WebSourceInfo>& sources) override { | 124 blink::WebVector<blink::WebSourceInfo>& sources) override { |
| 126 state_ = REQUEST_SUCCEEDED; | 125 state_ = REQUEST_SUCCEEDED; |
| 127 last_sources_ = sources; | 126 last_sources_ = sources; |
| 128 } | 127 } |
| 129 | 128 |
| 130 void SetCreateSourceThatFails(bool should_fail) { | |
| 131 create_source_that_fails_ = should_fail; | |
| 132 } | |
| 133 | |
| 134 MediaStreamAudioSource* CreateAudioSource( | |
| 135 const StreamDeviceInfo& device, | |
| 136 const blink::WebMediaConstraints& constraints) override { | |
| 137 MediaStreamAudioSource* source; | |
| 138 if (create_source_that_fails_) { | |
| 139 class FailedAtLifeAudioSource : public MediaStreamAudioSource { | |
| 140 public: | |
| 141 FailedAtLifeAudioSource() : MediaStreamAudioSource(true) {} | |
| 142 ~FailedAtLifeAudioSource() override {} | |
| 143 protected: | |
| 144 bool EnsureSourceIsStarted() override { | |
| 145 return false; | |
| 146 } | |
| 147 }; | |
| 148 source = new FailedAtLifeAudioSource(); | |
| 149 } else { | |
| 150 source = new MediaStreamAudioSource(true); | |
| 151 } | |
| 152 source->SetDeviceInfo(device); | |
| 153 return source; | |
| 154 } | |
| 155 | |
| 156 MediaStreamVideoSource* CreateVideoSource( | 129 MediaStreamVideoSource* CreateVideoSource( |
| 157 const StreamDeviceInfo& device, | 130 const StreamDeviceInfo& device, |
| 158 const MediaStreamSource::SourceStoppedCallback& stop_callback) override { | 131 const MediaStreamSource::SourceStoppedCallback& stop_callback) override { |
| 159 video_source_ = new MockMediaStreamVideoCapturerSource(device, | 132 video_source_ = new MockMediaStreamVideoCapturerSource(device, |
| 160 stop_callback, | 133 stop_callback, |
| 161 factory_); | 134 factory_); |
| 162 return video_source_; | 135 return video_source_; |
| 163 } | 136 } |
| 164 | 137 |
| 165 const blink::WebMediaStream& last_generated_stream() { | 138 const blink::WebMediaStream& last_generated_stream() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 172 } |
| 200 | 173 |
| 201 private: | 174 private: |
| 202 blink::WebMediaStream last_generated_stream_; | 175 blink::WebMediaStream last_generated_stream_; |
| 203 RequestState state_; | 176 RequestState state_; |
| 204 content::MediaStreamRequestResult result_; | 177 content::MediaStreamRequestResult result_; |
| 205 blink::WebString result_name_; | 178 blink::WebString result_name_; |
| 206 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_; | 179 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_; |
| 207 blink::WebVector<blink::WebSourceInfo> last_sources_; | 180 blink::WebVector<blink::WebSourceInfo> last_sources_; |
| 208 PeerConnectionDependencyFactory* factory_; | 181 PeerConnectionDependencyFactory* factory_; |
| 209 bool create_source_that_fails_; | |
| 210 MockMediaStreamVideoCapturerSource* video_source_; | 182 MockMediaStreamVideoCapturerSource* video_source_; |
| 211 }; | 183 }; |
| 212 | 184 |
| 213 class UserMediaClientImplTest : public ::testing::Test { | 185 class UserMediaClientImplTest : public ::testing::Test { |
| 214 public: | 186 public: |
| 215 void SetUp() override { | 187 void SetUp() override { |
| 216 // Create our test object. | 188 // Create our test object. |
| 217 child_process_.reset(new ChildProcess()); | 189 child_process_.reset(new ChildProcess()); |
| 218 dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); | 190 dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); |
| 219 ms_dispatcher_ = new MockMediaStreamDispatcher(); | 191 ms_dispatcher_ = new MockMediaStreamDispatcher(); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } | 264 } |
| 293 | 265 |
| 294 void FailToStartMockedVideoSource() { | 266 void FailToStartMockedVideoSource() { |
| 295 MockMediaStreamVideoCapturerSource* video_source = | 267 MockMediaStreamVideoCapturerSource* video_source = |
| 296 used_media_impl_->last_created_video_source(); | 268 used_media_impl_->last_created_video_source(); |
| 297 if (video_source->SourceHasAttemptedToStart()) | 269 if (video_source->SourceHasAttemptedToStart()) |
| 298 video_source->FailToStartMockedSource(); | 270 video_source->FailToStartMockedSource(); |
| 299 blink::WebHeap::collectGarbageForTesting(); | 271 blink::WebHeap::collectGarbageForTesting(); |
| 300 } | 272 } |
| 301 | 273 |
| 274 void FailToCreateNextAudioCapturer() { |
| 275 dependency_factory_->FailToCreateNextAudioCapturer(); |
| 276 blink::WebHeap::collectGarbageForTesting(); |
| 277 } |
| 278 |
| 302 bool AudioRequestHasAutomaticDeviceSelection( | 279 bool AudioRequestHasAutomaticDeviceSelection( |
| 303 const blink::WebMediaConstraints& audio_constraints) { | 280 const blink::WebMediaConstraints& audio_constraints) { |
| 304 blink::WebMediaConstraints null_constraints; | 281 blink::WebMediaConstraints null_constraints; |
| 305 blink::WebUserMediaRequest request = | 282 blink::WebUserMediaRequest request = |
| 306 blink::WebUserMediaRequest::createForTesting(audio_constraints, | 283 blink::WebUserMediaRequest::createForTesting(audio_constraints, |
| 307 null_constraints); | 284 null_constraints); |
| 308 used_media_impl_->RequestUserMedia(request); | 285 used_media_impl_->RequestUserMedia(request); |
| 309 bool result = used_media_impl_->UserMediaRequestHasAutomaticDeviceSelection( | 286 bool result = used_media_impl_->UserMediaRequestHasAutomaticDeviceSelection( |
| 310 ms_dispatcher_->audio_input_request_id()); | 287 ms_dispatcher_->audio_input_request_id()); |
| 311 used_media_impl_->DeleteRequest(ms_dispatcher_->audio_input_request_id()); | 288 used_media_impl_->DeleteRequest(ms_dispatcher_->audio_input_request_id()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, | 445 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, |
| 469 used_media_impl_->error_reason()); | 446 used_media_impl_->error_reason()); |
| 470 blink::WebHeap::collectAllGarbageForTesting(); | 447 blink::WebHeap::collectAllGarbageForTesting(); |
| 471 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); | 448 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); |
| 472 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 449 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
| 473 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 450 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 474 } | 451 } |
| 475 | 452 |
| 476 // This test what happens if an audio source fail to initialize. | 453 // This test what happens if an audio source fail to initialize. |
| 477 TEST_F(UserMediaClientImplTest, MediaAudioSourceFailToInitialize) { | 454 TEST_F(UserMediaClientImplTest, MediaAudioSourceFailToInitialize) { |
| 478 used_media_impl_->SetCreateSourceThatFails(true); | 455 FailToCreateNextAudioCapturer(); |
| 479 used_media_impl_->RequestUserMedia(); | 456 used_media_impl_->RequestUserMedia(); |
| 480 FakeMediaStreamDispatcherRequestUserMediaComplete(); | 457 FakeMediaStreamDispatcherRequestUserMediaComplete(); |
| 481 StartMockedVideoSource(); | 458 StartMockedVideoSource(); |
| 482 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED, | 459 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED, |
| 483 used_media_impl_->request_state()); | 460 used_media_impl_->request_state()); |
| 484 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, | 461 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, |
| 485 used_media_impl_->error_reason()); | 462 used_media_impl_->error_reason()); |
| 486 blink::WebHeap::collectAllGarbageForTesting(); | 463 blink::WebHeap::collectAllGarbageForTesting(); |
| 487 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); | 464 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); |
| 488 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 465 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 // Now we close the web frame, if in the above Stop() call, | 681 // Now we close the web frame, if in the above Stop() call, |
| 705 // UserMediaClientImpl accidentally removed audio track, then video track will | 682 // UserMediaClientImpl accidentally removed audio track, then video track will |
| 706 // be removed again here, which is incorrect. | 683 // be removed again here, which is incorrect. |
| 707 used_media_impl_->FrameWillClose(); | 684 used_media_impl_->FrameWillClose(); |
| 708 blink::WebHeap::collectAllGarbageForTesting(); | 685 blink::WebHeap::collectAllGarbageForTesting(); |
| 709 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 686 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 710 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 687 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
| 711 } | 688 } |
| 712 | 689 |
| 713 } // namespace content | 690 } // namespace content |
| OLD | NEW |