| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 | 301 |
| 302 MockMediaStreamVideoCapturerSource* last_created_video_source() const { | 302 MockMediaStreamVideoCapturerSource* last_created_video_source() const { |
| 303 return video_source_; | 303 return video_source_; |
| 304 } | 304 } |
| 305 | 305 |
| 306 RequestState request_state() const { return state_; } | 306 RequestState request_state() const { return state_; } |
| 307 content::MediaStreamRequestResult error_reason() const { return result_; } | 307 content::MediaStreamRequestResult error_reason() const { return result_; } |
| 308 blink::WebString error_name() const { return result_name_; } | 308 blink::WebString error_name() const { return result_name_; } |
| 309 | 309 |
| 310 // Access to the request queue for testing. | 310 // Access to the request queue for testing. |
| 311 bool UserMediaRequestHasAutomaticDeviceSelection(int request_id) { | 311 bool UserMediaRequestHasAutomaticDeviceSelection() { |
| 312 auto* request = FindUserMediaRequestInfo(request_id); | 312 base::Optional<bool> enabled = |
| 313 EXPECT_TRUE(request != nullptr); | 313 AutomaticOutputDeviceSelectionEnabledForCurrentRequest(); |
| 314 return request && request->enable_automatic_output_device_selection; | 314 EXPECT_TRUE(enabled); |
| 315 } | 315 return *enabled; |
| 316 | |
| 317 void DeleteRequest(int request_id) { | |
| 318 auto* request = FindUserMediaRequestInfo(request_id); | |
| 319 DeleteUserMediaRequestInfo(request); | |
| 320 } | 316 } |
| 321 | 317 |
| 322 private: | 318 private: |
| 323 blink::WebMediaStream last_generated_stream_; | 319 blink::WebMediaStream last_generated_stream_; |
| 324 RequestState state_; | 320 RequestState state_; |
| 325 content::MediaStreamRequestResult result_; | 321 content::MediaStreamRequestResult result_; |
| 326 blink::WebString result_name_; | 322 blink::WebString result_name_; |
| 327 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_; | 323 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_; |
| 328 PeerConnectionDependencyFactory* factory_; | 324 PeerConnectionDependencyFactory* factory_; |
| 329 bool create_source_that_fails_; | 325 bool create_source_that_fails_; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 } | 411 } |
| 416 | 412 |
| 417 bool AudioRequestHasAutomaticDeviceSelection( | 413 bool AudioRequestHasAutomaticDeviceSelection( |
| 418 const blink::WebMediaConstraints& audio_constraints) { | 414 const blink::WebMediaConstraints& audio_constraints) { |
| 419 blink::WebMediaConstraints null_constraints; | 415 blink::WebMediaConstraints null_constraints; |
| 420 blink::WebUserMediaRequest request = | 416 blink::WebUserMediaRequest request = |
| 421 blink::WebUserMediaRequest::createForTesting(audio_constraints, | 417 blink::WebUserMediaRequest::createForTesting(audio_constraints, |
| 422 null_constraints); | 418 null_constraints); |
| 423 user_media_client_impl_->RequestUserMediaForTest(request); | 419 user_media_client_impl_->RequestUserMediaForTest(request); |
| 424 bool result = | 420 bool result = |
| 425 user_media_client_impl_->UserMediaRequestHasAutomaticDeviceSelection( | 421 user_media_client_impl_->UserMediaRequestHasAutomaticDeviceSelection(); |
| 426 ms_dispatcher_->audio_input_request_id()); | 422 user_media_client_impl_->cancelUserMediaRequest(request); |
| 427 user_media_client_impl_->DeleteRequest( | |
| 428 ms_dispatcher_->audio_input_request_id()); | |
| 429 return result; | 423 return result; |
| 430 } | 424 } |
| 431 | 425 |
| 432 void TestValidRequestWithConstraints( | 426 void TestValidRequestWithConstraints( |
| 433 const blink::WebMediaConstraints& audio_constraints, | 427 const blink::WebMediaConstraints& audio_constraints, |
| 434 const blink::WebMediaConstraints& video_constraints, | 428 const blink::WebMediaConstraints& video_constraints, |
| 435 const std::string& expected_audio_device_id, | 429 const std::string& expected_audio_device_id, |
| 436 const std::string& expected_video_device_id) { | 430 const std::string& expected_video_device_id) { |
| 437 DCHECK(!audio_constraints.isNull()); | 431 DCHECK(!audio_constraints.isNull()); |
| 438 DCHECK(!video_constraints.isNull()); | 432 DCHECK(!video_constraints.isNull()); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 EXPECT_FALSE(device->groupId().isEmpty()); | 739 EXPECT_FALSE(device->groupId().isEmpty()); |
| 746 | 740 |
| 747 // Verfify group IDs. | 741 // Verfify group IDs. |
| 748 EXPECT_TRUE(user_media_client_impl_->last_devices()[0].groupId().equals( | 742 EXPECT_TRUE(user_media_client_impl_->last_devices()[0].groupId().equals( |
| 749 user_media_client_impl_->last_devices()[4].groupId())); | 743 user_media_client_impl_->last_devices()[4].groupId())); |
| 750 EXPECT_FALSE(user_media_client_impl_->last_devices()[1].groupId().equals( | 744 EXPECT_FALSE(user_media_client_impl_->last_devices()[1].groupId().equals( |
| 751 user_media_client_impl_->last_devices()[4].groupId())); | 745 user_media_client_impl_->last_devices()[4].groupId())); |
| 752 } | 746 } |
| 753 | 747 |
| 754 TEST_F(UserMediaClientImplTest, RenderToAssociatedSinkConstraint) { | 748 TEST_F(UserMediaClientImplTest, RenderToAssociatedSinkConstraint) { |
| 755 // For a null UserMediaRequest (no audio requested), we expect false. | 749 // For a UserMediaRequest without audio, we expect false. |
| 756 user_media_client_impl_->RequestUserMediaForTest(); | 750 blink::WebUserMediaRequest request = |
| 751 blink::WebUserMediaRequest::createForTesting(blink::WebMediaConstraints(), |
| 752 CreateDefaultConstraints()); |
| 753 user_media_client_impl_->RequestUserMediaForTest(request); |
| 757 EXPECT_FALSE( | 754 EXPECT_FALSE( |
| 758 user_media_client_impl_->UserMediaRequestHasAutomaticDeviceSelection( | 755 user_media_client_impl_->UserMediaRequestHasAutomaticDeviceSelection()); |
| 759 ms_dispatcher_->audio_input_request_id())); | 756 user_media_client_impl_->cancelUserMediaRequest(request); |
| 760 user_media_client_impl_->DeleteRequest( | |
| 761 ms_dispatcher_->audio_input_request_id()); | |
| 762 | 757 |
| 763 // If audio is requested, but no constraint, it should be true. | 758 // If audio is requested, but no constraint, it should be true. |
| 764 // Currently we expect it to be false due to a suspected bug in the | 759 // Currently we expect it to be false due to a suspected bug in the |
| 765 // device-matching code causing issues with some sound adapters. | 760 // device-matching code causing issues with some sound adapters. |
| 766 // See crbug.com/604523 | 761 // See crbug.com/604523 |
| 767 MockConstraintFactory factory; | 762 MockConstraintFactory factory; |
| 768 blink::WebMediaConstraints audio_constraints = | 763 blink::WebMediaConstraints audio_constraints = |
| 769 factory.CreateWebMediaConstraints(); | 764 factory.CreateWebMediaConstraints(); |
| 770 EXPECT_FALSE(AudioRequestHasAutomaticDeviceSelection( | 765 EXPECT_FALSE(AudioRequestHasAutomaticDeviceSelection( |
| 771 factory.CreateWebMediaConstraints())); | 766 factory.CreateWebMediaConstraints())); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 CreateDeviceConstraints(kFakeAudioInputDeviceId1); | 925 CreateDeviceConstraints(kFakeAudioInputDeviceId1); |
| 931 blink::WebMediaConstraints video_constraints = | 926 blink::WebMediaConstraints video_constraints = |
| 932 CreateFacingModeConstraints("environment"); | 927 CreateFacingModeConstraints("environment"); |
| 933 // kFakeVideoInputDeviceId2 has environment facing mode. | 928 // kFakeVideoInputDeviceId2 has environment facing mode. |
| 934 TestValidRequestWithConstraints(audio_constraints, video_constraints, | 929 TestValidRequestWithConstraints(audio_constraints, video_constraints, |
| 935 kFakeAudioInputDeviceId1, | 930 kFakeAudioInputDeviceId1, |
| 936 kFakeVideoInputDeviceId2); | 931 kFakeVideoInputDeviceId2); |
| 937 } | 932 } |
| 938 | 933 |
| 939 } // namespace content | 934 } // namespace content |
| OLD | NEW |