Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1047)

Side by Side Diff: content/renderer/media/user_media_client_impl_unittest.cc

Issue 2481263004: Revert of Remove MediaStreamTrack.getSources(). (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 namespace content { 36 namespace content {
36 37
37 class MockMediaStreamVideoCapturerSource : public MockMediaStreamVideoSource { 38 class MockMediaStreamVideoCapturerSource : public MockMediaStreamVideoSource {
38 public: 39 public:
39 MockMediaStreamVideoCapturerSource( 40 MockMediaStreamVideoCapturerSource(
40 const StreamDeviceInfo& device, 41 const StreamDeviceInfo& device,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 blink::WebUserMediaRequest user_media_request; 115 blink::WebUserMediaRequest user_media_request;
115 RequestUserMedia(user_media_request); 116 RequestUserMedia(user_media_request);
116 } 117 }
117 118
118 void RequestMediaDevices() { 119 void RequestMediaDevices() {
119 blink::WebMediaDevicesRequest media_devices_request; 120 blink::WebMediaDevicesRequest media_devices_request;
120 state_ = REQUEST_NOT_COMPLETE; 121 state_ = REQUEST_NOT_COMPLETE;
121 requestMediaDevices(media_devices_request); 122 requestMediaDevices(media_devices_request);
122 } 123 }
123 124
125 void RequestSources() {
126 blink::WebMediaStreamTrackSourcesRequest sources_request;
127 state_ = REQUEST_NOT_COMPLETE;
128 requestSources(sources_request);
129 }
130
124 void SetMediaDeviceChangeObserver() { 131 void SetMediaDeviceChangeObserver() {
125 blink::WebMediaDeviceChangeObserver observer(true); 132 blink::WebMediaDeviceChangeObserver observer(true);
126 setMediaDeviceChangeObserver(observer); 133 setMediaDeviceChangeObserver(observer);
127 } 134 }
128 135
129 void RemoveMediaDeviceChangeObserver() { 136 void RemoveMediaDeviceChangeObserver() {
130 setMediaDeviceChangeObserver(blink::WebMediaDeviceChangeObserver()); 137 setMediaDeviceChangeObserver(blink::WebMediaDeviceChangeObserver());
131 } 138 }
132 139
133 void GetUserMediaRequestSucceeded( 140 void GetUserMediaRequestSucceeded(
(...skipping 13 matching lines...) Expand all
147 result_name_ = result_name; 154 result_name_ = result_name;
148 } 155 }
149 156
150 void EnumerateDevicesSucceded( 157 void EnumerateDevicesSucceded(
151 blink::WebMediaDevicesRequest* request, 158 blink::WebMediaDevicesRequest* request,
152 blink::WebVector<blink::WebMediaDeviceInfo>& devices) override { 159 blink::WebVector<blink::WebMediaDeviceInfo>& devices) override {
153 state_ = REQUEST_SUCCEEDED; 160 state_ = REQUEST_SUCCEEDED;
154 last_devices_ = devices; 161 last_devices_ = devices;
155 } 162 }
156 163
164 void EnumerateSourcesSucceded(
165 blink::WebMediaStreamTrackSourcesRequest* request,
166 blink::WebVector<blink::WebSourceInfo>& sources) override {
167 state_ = REQUEST_SUCCEEDED;
168 last_sources_ = sources;
169 }
170
157 void SetCreateSourceThatFails(bool should_fail) { 171 void SetCreateSourceThatFails(bool should_fail) {
158 create_source_that_fails_ = should_fail; 172 create_source_that_fails_ = should_fail;
159 } 173 }
160 174
161 MediaStreamAudioSource* CreateAudioSource( 175 MediaStreamAudioSource* CreateAudioSource(
162 const StreamDeviceInfo& device, 176 const StreamDeviceInfo& device,
163 const blink::WebMediaConstraints& constraints) override { 177 const blink::WebMediaConstraints& constraints) override {
164 MediaStreamAudioSource* source; 178 MediaStreamAudioSource* source;
165 if (create_source_that_fails_) { 179 if (create_source_that_fails_) {
166 class FailedAtLifeAudioSource : public MediaStreamAudioSource { 180 class FailedAtLifeAudioSource : public MediaStreamAudioSource {
(...skipping 23 matching lines...) Expand all
190 } 204 }
191 205
192 const blink::WebMediaStream& last_generated_stream() { 206 const blink::WebMediaStream& last_generated_stream() {
193 return last_generated_stream_; 207 return last_generated_stream_;
194 } 208 }
195 209
196 const blink::WebVector<blink::WebMediaDeviceInfo>& last_devices() { 210 const blink::WebVector<blink::WebMediaDeviceInfo>& last_devices() {
197 return last_devices_; 211 return last_devices_;
198 } 212 }
199 213
214 const blink::WebVector<blink::WebSourceInfo>& last_sources() {
215 return last_sources_;
216 }
217
200 void ClearLastGeneratedStream() { 218 void ClearLastGeneratedStream() {
201 last_generated_stream_.reset(); 219 last_generated_stream_.reset();
202 } 220 }
203 221
204 MockMediaStreamVideoCapturerSource* last_created_video_source() const { 222 MockMediaStreamVideoCapturerSource* last_created_video_source() const {
205 return video_source_; 223 return video_source_;
206 } 224 }
207 225
208 RequestState request_state() const { return state_; } 226 RequestState request_state() const { return state_; }
209 content::MediaStreamRequestResult error_reason() const { return result_; } 227 content::MediaStreamRequestResult error_reason() const { return result_; }
(...skipping 10 matching lines...) Expand all
220 auto* request = FindUserMediaRequestInfo(request_id); 238 auto* request = FindUserMediaRequestInfo(request_id);
221 DeleteUserMediaRequestInfo(request); 239 DeleteUserMediaRequestInfo(request);
222 } 240 }
223 241
224 private: 242 private:
225 blink::WebMediaStream last_generated_stream_; 243 blink::WebMediaStream last_generated_stream_;
226 RequestState state_; 244 RequestState state_;
227 content::MediaStreamRequestResult result_; 245 content::MediaStreamRequestResult result_;
228 blink::WebString result_name_; 246 blink::WebString result_name_;
229 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_; 247 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_;
248 blink::WebVector<blink::WebSourceInfo> last_sources_;
230 PeerConnectionDependencyFactory* factory_; 249 PeerConnectionDependencyFactory* factory_;
231 bool create_source_that_fails_; 250 bool create_source_that_fails_;
232 MockMediaStreamVideoCapturerSource* video_source_; 251 MockMediaStreamVideoCapturerSource* video_source_;
233 }; 252 };
234 253
235 class UserMediaClientImplTest : public ::testing::Test { 254 class UserMediaClientImplTest : public ::testing::Test {
236 public: 255 public:
237 void SetUp() override { 256 void SetUp() override {
238 // Create our test object. 257 // Create our test object.
239 child_process_.reset(new ChildProcess()); 258 child_process_.reset(new ChildProcess());
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 EXPECT_FALSE(device->label().isEmpty()); 623 EXPECT_FALSE(device->label().isEmpty());
605 EXPECT_FALSE(device->groupId().isEmpty()); 624 EXPECT_FALSE(device->groupId().isEmpty());
606 625
607 // Verfify group IDs. 626 // Verfify group IDs.
608 EXPECT_TRUE(used_media_impl_->last_devices()[0].groupId().equals( 627 EXPECT_TRUE(used_media_impl_->last_devices()[0].groupId().equals(
609 used_media_impl_->last_devices()[4].groupId())); 628 used_media_impl_->last_devices()[4].groupId()));
610 EXPECT_FALSE(used_media_impl_->last_devices()[1].groupId().equals( 629 EXPECT_FALSE(used_media_impl_->last_devices()[1].groupId().equals(
611 used_media_impl_->last_devices()[4].groupId())); 630 used_media_impl_->last_devices()[4].groupId()));
612 } 631 }
613 632
633 TEST_F(UserMediaClientImplTest, EnumerateSources) {
634 used_media_impl_->RequestSources();
635 base::RunLoop().RunUntilIdle();
636
637 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED,
638 used_media_impl_->request_state());
639 EXPECT_EQ(static_cast<size_t>(4), used_media_impl_->last_sources().size());
640
641 // Audio input devices.
642 const blink::WebSourceInfo* source = &used_media_impl_->last_sources()[0];
643 EXPECT_FALSE(source->id().isEmpty());
644 EXPECT_EQ(blink::WebSourceInfo::SourceKindAudio, source->kind());
645 EXPECT_FALSE(source->label().isEmpty());
646 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing());
647
648 source = &used_media_impl_->last_sources()[1];
649 EXPECT_FALSE(source->id().isEmpty());
650 EXPECT_EQ(blink::WebSourceInfo::SourceKindAudio, source->kind());
651 EXPECT_FALSE(source->label().isEmpty());
652 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing());
653
654 // Video input device user facing.
655 source = &used_media_impl_->last_sources()[2];
656 EXPECT_FALSE(source->id().isEmpty());
657 EXPECT_EQ(blink::WebSourceInfo::SourceKindVideo, source->kind());
658 EXPECT_FALSE(source->label().isEmpty());
659 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing());
660
661 // Video input device environment facing.
662 source = &used_media_impl_->last_sources()[3];
663 EXPECT_FALSE(source->id().isEmpty());
664 EXPECT_EQ(blink::WebSourceInfo::SourceKindVideo, source->kind());
665 EXPECT_FALSE(source->label().isEmpty());
666 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing());
667 }
668
614 TEST_F(UserMediaClientImplTest, RenderToAssociatedSinkConstraint) { 669 TEST_F(UserMediaClientImplTest, RenderToAssociatedSinkConstraint) {
615 // For a null UserMediaRequest (no audio requested), we expect false. 670 // For a null UserMediaRequest (no audio requested), we expect false.
616 used_media_impl_->RequestUserMedia(); 671 used_media_impl_->RequestUserMedia();
617 EXPECT_FALSE(used_media_impl_->UserMediaRequestHasAutomaticDeviceSelection( 672 EXPECT_FALSE(used_media_impl_->UserMediaRequestHasAutomaticDeviceSelection(
618 ms_dispatcher_->audio_input_request_id())); 673 ms_dispatcher_->audio_input_request_id()));
619 used_media_impl_->DeleteRequest(ms_dispatcher_->audio_input_request_id()); 674 used_media_impl_->DeleteRequest(ms_dispatcher_->audio_input_request_id());
620 675
621 // If audio is requested, but no constraint, it should be true. 676 // If audio is requested, but no constraint, it should be true.
622 // Currently we expect it to be false due to a suspected bug in the 677 // Currently we expect it to be false due to a suspected bug in the
623 // device-matching code causing issues with some sound adapters. 678 // device-matching code causing issues with some sound adapters.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 // Now we load a new document in the web frame. If in the above Stop() call, 731 // Now we load a new document in the web frame. If in the above Stop() call,
677 // UserMediaClientImpl accidentally removed audio track, then video track will 732 // UserMediaClientImpl accidentally removed audio track, then video track will
678 // be removed again here, which is incorrect. 733 // be removed again here, which is incorrect.
679 LoadNewDocumentInFrame(); 734 LoadNewDocumentInFrame();
680 blink::WebHeap::collectAllGarbageForTesting(); 735 blink::WebHeap::collectAllGarbageForTesting();
681 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 736 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
682 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 737 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
683 } 738 }
684 739
685 } // namespace content 740 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/user_media_client_impl.cc ('k') | content/test/data/media/getusermedia.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698