| 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 10 matching lines...) Expand all Loading... |
| 21 #include "content/renderer/media/mock_constraint_factory.h" | 21 #include "content/renderer/media/mock_constraint_factory.h" |
| 22 #include "content/renderer/media/mock_media_stream_dispatcher.h" | 22 #include "content/renderer/media/mock_media_stream_dispatcher.h" |
| 23 #include "content/renderer/media/mock_media_stream_video_source.h" | 23 #include "content/renderer/media/mock_media_stream_video_source.h" |
| 24 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" | 24 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" |
| 25 #include "mojo/public/cpp/bindings/binding.h" | 25 #include "mojo/public/cpp/bindings/binding.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" | 27 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" |
| 28 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 28 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 29 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 29 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 30 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 30 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 31 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h
" |
| 31 #include "third_party/WebKit/public/platform/WebString.h" | 32 #include "third_party/WebKit/public/platform/WebString.h" |
| 32 #include "third_party/WebKit/public/platform/WebVector.h" | 33 #include "third_party/WebKit/public/platform/WebVector.h" |
| 33 #include "third_party/WebKit/public/web/WebHeap.h" | 34 #include "third_party/WebKit/public/web/WebHeap.h" |
| 34 | 35 |
| 35 using testing::_; | 36 using testing::_; |
| 36 | 37 |
| 37 namespace content { | 38 namespace content { |
| 38 | 39 |
| 39 class MockMediaStreamVideoCapturerSource : public MockMediaStreamVideoSource { | 40 class MockMediaStreamVideoCapturerSource : public MockMediaStreamVideoSource { |
| 40 public: | 41 public: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 blink::WebUserMediaRequest user_media_request; | 117 blink::WebUserMediaRequest user_media_request; |
| 117 RequestUserMedia(user_media_request); | 118 RequestUserMedia(user_media_request); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void RequestMediaDevices() { | 121 void RequestMediaDevices() { |
| 121 blink::WebMediaDevicesRequest media_devices_request; | 122 blink::WebMediaDevicesRequest media_devices_request; |
| 122 state_ = REQUEST_NOT_COMPLETE; | 123 state_ = REQUEST_NOT_COMPLETE; |
| 123 requestMediaDevices(media_devices_request); | 124 requestMediaDevices(media_devices_request); |
| 124 } | 125 } |
| 125 | 126 |
| 127 void RequestSources() { |
| 128 blink::WebMediaStreamTrackSourcesRequest sources_request; |
| 129 state_ = REQUEST_NOT_COMPLETE; |
| 130 requestSources(sources_request); |
| 131 } |
| 132 |
| 126 void SetMediaDeviceChangeObserver() { | 133 void SetMediaDeviceChangeObserver() { |
| 127 blink::WebMediaDeviceChangeObserver observer(true); | 134 blink::WebMediaDeviceChangeObserver observer(true); |
| 128 setMediaDeviceChangeObserver(observer); | 135 setMediaDeviceChangeObserver(observer); |
| 129 } | 136 } |
| 130 | 137 |
| 131 void RemoveMediaDeviceChangeObserver() { | 138 void RemoveMediaDeviceChangeObserver() { |
| 132 setMediaDeviceChangeObserver(blink::WebMediaDeviceChangeObserver()); | 139 setMediaDeviceChangeObserver(blink::WebMediaDeviceChangeObserver()); |
| 133 } | 140 } |
| 134 | 141 |
| 135 void GetUserMediaRequestSucceeded( | 142 void GetUserMediaRequestSucceeded( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 149 result_name_ = result_name; | 156 result_name_ = result_name; |
| 150 } | 157 } |
| 151 | 158 |
| 152 void EnumerateDevicesSucceded( | 159 void EnumerateDevicesSucceded( |
| 153 blink::WebMediaDevicesRequest* request, | 160 blink::WebMediaDevicesRequest* request, |
| 154 blink::WebVector<blink::WebMediaDeviceInfo>& devices) override { | 161 blink::WebVector<blink::WebMediaDeviceInfo>& devices) override { |
| 155 state_ = REQUEST_SUCCEEDED; | 162 state_ = REQUEST_SUCCEEDED; |
| 156 last_devices_ = devices; | 163 last_devices_ = devices; |
| 157 } | 164 } |
| 158 | 165 |
| 166 void EnumerateSourcesSucceded( |
| 167 blink::WebMediaStreamTrackSourcesRequest* request, |
| 168 blink::WebVector<blink::WebSourceInfo>& sources) override { |
| 169 state_ = REQUEST_SUCCEEDED; |
| 170 last_sources_ = sources; |
| 171 } |
| 172 |
| 159 void SetCreateSourceThatFails(bool should_fail) { | 173 void SetCreateSourceThatFails(bool should_fail) { |
| 160 create_source_that_fails_ = should_fail; | 174 create_source_that_fails_ = should_fail; |
| 161 } | 175 } |
| 162 | 176 |
| 163 MediaStreamAudioSource* CreateAudioSource( | 177 MediaStreamAudioSource* CreateAudioSource( |
| 164 const StreamDeviceInfo& device, | 178 const StreamDeviceInfo& device, |
| 165 const blink::WebMediaConstraints& constraints) override { | 179 const blink::WebMediaConstraints& constraints) override { |
| 166 MediaStreamAudioSource* source; | 180 MediaStreamAudioSource* source; |
| 167 if (create_source_that_fails_) { | 181 if (create_source_that_fails_) { |
| 168 class FailedAtLifeAudioSource : public MediaStreamAudioSource { | 182 class FailedAtLifeAudioSource : public MediaStreamAudioSource { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 192 } | 206 } |
| 193 | 207 |
| 194 const blink::WebMediaStream& last_generated_stream() { | 208 const blink::WebMediaStream& last_generated_stream() { |
| 195 return last_generated_stream_; | 209 return last_generated_stream_; |
| 196 } | 210 } |
| 197 | 211 |
| 198 const blink::WebVector<blink::WebMediaDeviceInfo>& last_devices() { | 212 const blink::WebVector<blink::WebMediaDeviceInfo>& last_devices() { |
| 199 return last_devices_; | 213 return last_devices_; |
| 200 } | 214 } |
| 201 | 215 |
| 216 const blink::WebVector<blink::WebSourceInfo>& last_sources() { |
| 217 return last_sources_; |
| 218 } |
| 219 |
| 202 void ClearLastGeneratedStream() { | 220 void ClearLastGeneratedStream() { |
| 203 last_generated_stream_.reset(); | 221 last_generated_stream_.reset(); |
| 204 } | 222 } |
| 205 | 223 |
| 206 MockMediaStreamVideoCapturerSource* last_created_video_source() const { | 224 MockMediaStreamVideoCapturerSource* last_created_video_source() const { |
| 207 return video_source_; | 225 return video_source_; |
| 208 } | 226 } |
| 209 | 227 |
| 210 RequestState request_state() const { return state_; } | 228 RequestState request_state() const { return state_; } |
| 211 content::MediaStreamRequestResult error_reason() const { return result_; } | 229 content::MediaStreamRequestResult error_reason() const { return result_; } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 222 auto* request = FindUserMediaRequestInfo(request_id); | 240 auto* request = FindUserMediaRequestInfo(request_id); |
| 223 DeleteUserMediaRequestInfo(request); | 241 DeleteUserMediaRequestInfo(request); |
| 224 } | 242 } |
| 225 | 243 |
| 226 private: | 244 private: |
| 227 blink::WebMediaStream last_generated_stream_; | 245 blink::WebMediaStream last_generated_stream_; |
| 228 RequestState state_; | 246 RequestState state_; |
| 229 content::MediaStreamRequestResult result_; | 247 content::MediaStreamRequestResult result_; |
| 230 blink::WebString result_name_; | 248 blink::WebString result_name_; |
| 231 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_; | 249 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_; |
| 250 blink::WebVector<blink::WebSourceInfo> last_sources_; |
| 232 PeerConnectionDependencyFactory* factory_; | 251 PeerConnectionDependencyFactory* factory_; |
| 233 bool create_source_that_fails_; | 252 bool create_source_that_fails_; |
| 234 MockMediaStreamVideoCapturerSource* video_source_; | 253 MockMediaStreamVideoCapturerSource* video_source_; |
| 235 }; | 254 }; |
| 236 | 255 |
| 237 class UserMediaClientImplTest : public ::testing::Test { | 256 class UserMediaClientImplTest : public ::testing::Test { |
| 238 public: | 257 public: |
| 239 UserMediaClientImplTest() | 258 UserMediaClientImplTest() |
| 240 : binding_user_media(&media_devices_dispatcher_), | 259 : binding_user_media(&media_devices_dispatcher_), |
| 241 binding_event_dispatcher_(&media_devices_dispatcher_) {} | 260 binding_event_dispatcher_(&media_devices_dispatcher_) {} |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 EXPECT_FALSE(device->label().isEmpty()); | 637 EXPECT_FALSE(device->label().isEmpty()); |
| 619 EXPECT_FALSE(device->groupId().isEmpty()); | 638 EXPECT_FALSE(device->groupId().isEmpty()); |
| 620 | 639 |
| 621 // Verfify group IDs. | 640 // Verfify group IDs. |
| 622 EXPECT_TRUE(used_media_impl_->last_devices()[0].groupId().equals( | 641 EXPECT_TRUE(used_media_impl_->last_devices()[0].groupId().equals( |
| 623 used_media_impl_->last_devices()[4].groupId())); | 642 used_media_impl_->last_devices()[4].groupId())); |
| 624 EXPECT_FALSE(used_media_impl_->last_devices()[1].groupId().equals( | 643 EXPECT_FALSE(used_media_impl_->last_devices()[1].groupId().equals( |
| 625 used_media_impl_->last_devices()[4].groupId())); | 644 used_media_impl_->last_devices()[4].groupId())); |
| 626 } | 645 } |
| 627 | 646 |
| 647 TEST_F(UserMediaClientImplTest, EnumerateSources) { |
| 648 used_media_impl_->RequestSources(); |
| 649 base::RunLoop().RunUntilIdle(); |
| 650 |
| 651 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED, |
| 652 used_media_impl_->request_state()); |
| 653 EXPECT_EQ(static_cast<size_t>(4), used_media_impl_->last_sources().size()); |
| 654 |
| 655 // Audio input devices. |
| 656 const blink::WebSourceInfo* source = &used_media_impl_->last_sources()[0]; |
| 657 EXPECT_FALSE(source->id().isEmpty()); |
| 658 EXPECT_EQ(blink::WebSourceInfo::SourceKindAudio, source->kind()); |
| 659 EXPECT_FALSE(source->label().isEmpty()); |
| 660 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing()); |
| 661 |
| 662 source = &used_media_impl_->last_sources()[1]; |
| 663 EXPECT_FALSE(source->id().isEmpty()); |
| 664 EXPECT_EQ(blink::WebSourceInfo::SourceKindAudio, source->kind()); |
| 665 EXPECT_FALSE(source->label().isEmpty()); |
| 666 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing()); |
| 667 |
| 668 // Video input device user facing. |
| 669 source = &used_media_impl_->last_sources()[2]; |
| 670 EXPECT_FALSE(source->id().isEmpty()); |
| 671 EXPECT_EQ(blink::WebSourceInfo::SourceKindVideo, source->kind()); |
| 672 EXPECT_FALSE(source->label().isEmpty()); |
| 673 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing()); |
| 674 |
| 675 // Video input device environment facing. |
| 676 source = &used_media_impl_->last_sources()[3]; |
| 677 EXPECT_FALSE(source->id().isEmpty()); |
| 678 EXPECT_EQ(blink::WebSourceInfo::SourceKindVideo, source->kind()); |
| 679 EXPECT_FALSE(source->label().isEmpty()); |
| 680 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing()); |
| 681 } |
| 682 |
| 628 TEST_F(UserMediaClientImplTest, RenderToAssociatedSinkConstraint) { | 683 TEST_F(UserMediaClientImplTest, RenderToAssociatedSinkConstraint) { |
| 629 // For a null UserMediaRequest (no audio requested), we expect false. | 684 // For a null UserMediaRequest (no audio requested), we expect false. |
| 630 used_media_impl_->RequestUserMedia(); | 685 used_media_impl_->RequestUserMedia(); |
| 631 EXPECT_FALSE(used_media_impl_->UserMediaRequestHasAutomaticDeviceSelection( | 686 EXPECT_FALSE(used_media_impl_->UserMediaRequestHasAutomaticDeviceSelection( |
| 632 ms_dispatcher_->audio_input_request_id())); | 687 ms_dispatcher_->audio_input_request_id())); |
| 633 used_media_impl_->DeleteRequest(ms_dispatcher_->audio_input_request_id()); | 688 used_media_impl_->DeleteRequest(ms_dispatcher_->audio_input_request_id()); |
| 634 | 689 |
| 635 // If audio is requested, but no constraint, it should be true. | 690 // If audio is requested, but no constraint, it should be true. |
| 636 // Currently we expect it to be false due to a suspected bug in the | 691 // Currently we expect it to be false due to a suspected bug in the |
| 637 // device-matching code causing issues with some sound adapters. | 692 // device-matching code causing issues with some sound adapters. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 // Now we load a new document in the web frame. If in the above Stop() call, | 768 // Now we load a new document in the web frame. If in the above Stop() call, |
| 714 // UserMediaClientImpl accidentally removed audio track, then video track will | 769 // UserMediaClientImpl accidentally removed audio track, then video track will |
| 715 // be removed again here, which is incorrect. | 770 // be removed again here, which is incorrect. |
| 716 LoadNewDocumentInFrame(); | 771 LoadNewDocumentInFrame(); |
| 717 blink::WebHeap::collectAllGarbageForTesting(); | 772 blink::WebHeap::collectAllGarbageForTesting(); |
| 718 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 773 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 719 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 774 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
| 720 } | 775 } |
| 721 | 776 |
| 722 } // namespace content | 777 } // namespace content |
| OLD | NEW |