| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 const char kFakeVideoInputDeviceId2[] = "fake_video_input 2"; | 110 const char kFakeVideoInputDeviceId2[] = "fake_video_input 2"; |
| 111 const char kFakeAudioOutputDeviceId1[] = "fake_audio_output 1"; | 111 const char kFakeAudioOutputDeviceId1[] = "fake_audio_output 1"; |
| 112 | 112 |
| 113 class MockMediaDevicesDispatcherHost | 113 class MockMediaDevicesDispatcherHost |
| 114 : public ::mojom::MediaDevicesDispatcherHost { | 114 : public ::mojom::MediaDevicesDispatcherHost { |
| 115 public: | 115 public: |
| 116 MockMediaDevicesDispatcherHost() {} | 116 MockMediaDevicesDispatcherHost() {} |
| 117 void EnumerateDevices(bool request_audio_input, | 117 void EnumerateDevices(bool request_audio_input, |
| 118 bool request_video_input, | 118 bool request_video_input, |
| 119 bool request_audio_output, | 119 bool request_audio_output, |
| 120 const url::Origin& security_origin, | |
| 121 EnumerateDevicesCallback callback) override { | 120 EnumerateDevicesCallback callback) override { |
| 122 std::vector<std::vector<MediaDeviceInfo>> result(NUM_MEDIA_DEVICE_TYPES); | 121 std::vector<std::vector<MediaDeviceInfo>> result(NUM_MEDIA_DEVICE_TYPES); |
| 123 if (request_audio_input) { | 122 if (request_audio_input) { |
| 124 result[MEDIA_DEVICE_TYPE_AUDIO_INPUT].push_back(MediaDeviceInfo( | 123 result[MEDIA_DEVICE_TYPE_AUDIO_INPUT].push_back(MediaDeviceInfo( |
| 125 kFakeAudioInputDeviceId1, "Fake Audio Input 1", "fake_group 1")); | 124 kFakeAudioInputDeviceId1, "Fake Audio Input 1", "fake_group 1")); |
| 126 result[MEDIA_DEVICE_TYPE_AUDIO_INPUT].push_back(MediaDeviceInfo( | 125 result[MEDIA_DEVICE_TYPE_AUDIO_INPUT].push_back(MediaDeviceInfo( |
| 127 kFakeAudioInputDeviceId2, "Fake Audio Input 2", "fake_group 2")); | 126 kFakeAudioInputDeviceId2, "Fake Audio Input 2", "fake_group 2")); |
| 128 } | 127 } |
| 129 if (request_video_input) { | 128 if (request_video_input) { |
| 130 result[MEDIA_DEVICE_TYPE_VIDEO_INPUT].push_back( | 129 result[MEDIA_DEVICE_TYPE_VIDEO_INPUT].push_back( |
| 131 MediaDeviceInfo(kFakeVideoInputDeviceId1, "Fake Video Input 1", "")); | 130 MediaDeviceInfo(kFakeVideoInputDeviceId1, "Fake Video Input 1", "")); |
| 132 result[MEDIA_DEVICE_TYPE_VIDEO_INPUT].push_back( | 131 result[MEDIA_DEVICE_TYPE_VIDEO_INPUT].push_back( |
| 133 MediaDeviceInfo(kFakeVideoInputDeviceId2, "Fake Video Input 2", "")); | 132 MediaDeviceInfo(kFakeVideoInputDeviceId2, "Fake Video Input 2", "")); |
| 134 } | 133 } |
| 135 if (request_audio_output) { | 134 if (request_audio_output) { |
| 136 result[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT].push_back(MediaDeviceInfo( | 135 result[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT].push_back(MediaDeviceInfo( |
| 137 kFakeAudioOutputDeviceId1, "Fake Audio Input 1", "fake_group 1")); | 136 kFakeAudioOutputDeviceId1, "Fake Audio Input 1", "fake_group 1")); |
| 138 } | 137 } |
| 139 std::move(callback).Run(result); | 138 std::move(callback).Run(result); |
| 140 } | 139 } |
| 141 | 140 |
| 142 void GetVideoInputCapabilities( | 141 void GetVideoInputCapabilities( |
| 143 const url::Origin& security_origin, | |
| 144 GetVideoInputCapabilitiesCallback client_callback) override { | 142 GetVideoInputCapabilitiesCallback client_callback) override { |
| 145 ::mojom::VideoInputDeviceCapabilitiesPtr device = | 143 ::mojom::VideoInputDeviceCapabilitiesPtr device = |
| 146 ::mojom::VideoInputDeviceCapabilities::New(); | 144 ::mojom::VideoInputDeviceCapabilities::New(); |
| 147 device->device_id = kFakeVideoInputDeviceId1; | 145 device->device_id = kFakeVideoInputDeviceId1; |
| 148 device->facing_mode = ::mojom::FacingMode::USER; | 146 device->facing_mode = ::mojom::FacingMode::USER; |
| 149 device->formats.push_back(media::VideoCaptureFormat( | 147 device->formats.push_back(media::VideoCaptureFormat( |
| 150 gfx::Size(640, 480), 30.0f, media::PIXEL_FORMAT_I420)); | 148 gfx::Size(640, 480), 30.0f, media::PIXEL_FORMAT_I420)); |
| 151 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> result; | 149 std::vector<::mojom::VideoInputDeviceCapabilitiesPtr> result; |
| 152 result.push_back(std::move(device)); | 150 result.push_back(std::move(device)); |
| 153 | 151 |
| 154 device = ::mojom::VideoInputDeviceCapabilities::New(); | 152 device = ::mojom::VideoInputDeviceCapabilities::New(); |
| 155 device->device_id = kFakeVideoInputDeviceId2; | 153 device->device_id = kFakeVideoInputDeviceId2; |
| 156 device->facing_mode = ::mojom::FacingMode::ENVIRONMENT; | 154 device->facing_mode = ::mojom::FacingMode::ENVIRONMENT; |
| 157 device->formats.push_back(media::VideoCaptureFormat( | 155 device->formats.push_back(media::VideoCaptureFormat( |
| 158 gfx::Size(640, 480), 30.0f, media::PIXEL_FORMAT_I420)); | 156 gfx::Size(640, 480), 30.0f, media::PIXEL_FORMAT_I420)); |
| 159 result.push_back(std::move(device)); | 157 result.push_back(std::move(device)); |
| 160 | 158 |
| 161 std::move(client_callback).Run(std::move(result)); | 159 std::move(client_callback).Run(std::move(result)); |
| 162 } | 160 } |
| 163 | 161 |
| 164 MOCK_METHOD3(SubscribeDeviceChangeNotifications, | 162 MOCK_METHOD2(SubscribeDeviceChangeNotifications, |
| 165 void(MediaDeviceType type, | 163 void(MediaDeviceType type, uint32_t subscription_id)); |
| 166 uint32_t subscription_id, | |
| 167 const url::Origin& security_origin)); | |
| 168 MOCK_METHOD2(UnsubscribeDeviceChangeNotifications, | 164 MOCK_METHOD2(UnsubscribeDeviceChangeNotifications, |
| 169 void(MediaDeviceType type, uint32_t subscription_id)); | 165 void(MediaDeviceType type, uint32_t subscription_id)); |
| 170 }; | 166 }; |
| 171 | 167 |
| 172 class UserMediaClientImplUnderTest : public UserMediaClientImpl { | 168 class UserMediaClientImplUnderTest : public UserMediaClientImpl { |
| 173 public: | 169 public: |
| 174 enum RequestState { | 170 enum RequestState { |
| 175 REQUEST_NOT_STARTED, | 171 REQUEST_NOT_STARTED, |
| 176 REQUEST_NOT_COMPLETE, | 172 REQUEST_NOT_COMPLETE, |
| 177 REQUEST_SUCCEEDED, | 173 REQUEST_SUCCEEDED, |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 EXPECT_FALSE(AudioRequestHasAutomaticDeviceSelection( | 770 EXPECT_FALSE(AudioRequestHasAutomaticDeviceSelection( |
| 775 factory.CreateWebMediaConstraints())); | 771 factory.CreateWebMediaConstraints())); |
| 776 | 772 |
| 777 factory.Reset(); | 773 factory.Reset(); |
| 778 factory.basic().render_to_associated_sink.SetExact(false); | 774 factory.basic().render_to_associated_sink.SetExact(false); |
| 779 EXPECT_FALSE(AudioRequestHasAutomaticDeviceSelection( | 775 EXPECT_FALSE(AudioRequestHasAutomaticDeviceSelection( |
| 780 factory.CreateWebMediaConstraints())); | 776 factory.CreateWebMediaConstraints())); |
| 781 } | 777 } |
| 782 | 778 |
| 783 TEST_F(UserMediaClientImplTest, ObserveMediaDeviceChanges) { | 779 TEST_F(UserMediaClientImplTest, ObserveMediaDeviceChanges) { |
| 780 EXPECT_CALL(media_devices_dispatcher_, SubscribeDeviceChangeNotifications( |
| 781 MEDIA_DEVICE_TYPE_AUDIO_INPUT, _)); |
| 782 EXPECT_CALL(media_devices_dispatcher_, SubscribeDeviceChangeNotifications( |
| 783 MEDIA_DEVICE_TYPE_VIDEO_INPUT, _)); |
| 784 EXPECT_CALL( | 784 EXPECT_CALL( |
| 785 media_devices_dispatcher_, | 785 media_devices_dispatcher_, |
| 786 SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_AUDIO_INPUT, _, _)); | 786 SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_AUDIO_OUTPUT, _)); |
| 787 EXPECT_CALL( | |
| 788 media_devices_dispatcher_, | |
| 789 SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_VIDEO_INPUT, _, _)); | |
| 790 EXPECT_CALL( | |
| 791 media_devices_dispatcher_, | |
| 792 SubscribeDeviceChangeNotifications(MEDIA_DEVICE_TYPE_AUDIO_OUTPUT, _, _)); | |
| 793 user_media_client_impl_->SetMediaDeviceChangeObserver( | 787 user_media_client_impl_->SetMediaDeviceChangeObserver( |
| 794 blink::WebMediaDeviceChangeObserver(true)); | 788 blink::WebMediaDeviceChangeObserver(true)); |
| 795 base::RunLoop().RunUntilIdle(); | 789 base::RunLoop().RunUntilIdle(); |
| 796 | 790 |
| 797 base::WeakPtr<MediaDevicesEventDispatcher> event_dispatcher = | 791 base::WeakPtr<MediaDevicesEventDispatcher> event_dispatcher = |
| 798 MediaDevicesEventDispatcher::GetForRenderFrame(nullptr); | 792 MediaDevicesEventDispatcher::GetForRenderFrame(nullptr); |
| 799 event_dispatcher->DispatchDevicesChangedEvent(MEDIA_DEVICE_TYPE_AUDIO_INPUT, | 793 event_dispatcher->DispatchDevicesChangedEvent(MEDIA_DEVICE_TYPE_AUDIO_INPUT, |
| 800 MediaDeviceInfoArray()); | 794 MediaDeviceInfoArray()); |
| 801 event_dispatcher->DispatchDevicesChangedEvent(MEDIA_DEVICE_TYPE_VIDEO_INPUT, | 795 event_dispatcher->DispatchDevicesChangedEvent(MEDIA_DEVICE_TYPE_VIDEO_INPUT, |
| 802 MediaDeviceInfoArray()); | 796 MediaDeviceInfoArray()); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 CreateDeviceConstraints(kFakeAudioInputDeviceId1); | 917 CreateDeviceConstraints(kFakeAudioInputDeviceId1); |
| 924 blink::WebMediaConstraints video_constraints = | 918 blink::WebMediaConstraints video_constraints = |
| 925 CreateFacingModeConstraints("environment"); | 919 CreateFacingModeConstraints("environment"); |
| 926 // kFakeVideoInputDeviceId2 has environment facing mode. | 920 // kFakeVideoInputDeviceId2 has environment facing mode. |
| 927 TestValidRequestWithConstraints(audio_constraints, video_constraints, | 921 TestValidRequestWithConstraints(audio_constraints, video_constraints, |
| 928 kFakeAudioInputDeviceId1, | 922 kFakeAudioInputDeviceId1, |
| 929 kFakeVideoInputDeviceId2); | 923 kFakeVideoInputDeviceId2); |
| 930 } | 924 } |
| 931 | 925 |
| 932 } // namespace content | 926 } // namespace content |
| OLD | NEW |