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