Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / content / renderer / media / user_media_client_impl_unittest.cc
blob718bbfeed9a554804087d0ee5189eaeb0b88b4f7
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
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "content/child/child_process.h"
10 #include "content/renderer/media/media_stream.h"
11 #include "content/renderer/media/media_stream_track.h"
12 #include "content/renderer/media/mock_media_stream_dispatcher.h"
13 #include "content/renderer/media/mock_media_stream_video_source.h"
14 #include "content/renderer/media/user_media_client_impl.h"
15 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h"
18 #include "third_party/WebKit/public/platform/WebMediaStream.h"
19 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
20 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
21 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h"
22 #include "third_party/WebKit/public/platform/WebString.h"
23 #include "third_party/WebKit/public/platform/WebVector.h"
24 #include "third_party/WebKit/public/web/WebHeap.h"
26 namespace content {
28 class MockMediaStreamVideoCapturerSource : public MockMediaStreamVideoSource {
29 public:
30 MockMediaStreamVideoCapturerSource(
31 const StreamDeviceInfo& device,
32 const SourceStoppedCallback& stop_callback,
33 PeerConnectionDependencyFactory* factory)
34 : MockMediaStreamVideoSource(false) {
35 SetDeviceInfo(device);
36 SetStopCallback(stop_callback);
40 class UserMediaClientImplUnderTest : public UserMediaClientImpl {
41 public:
42 enum RequestState {
43 REQUEST_NOT_STARTED,
44 REQUEST_NOT_COMPLETE,
45 REQUEST_SUCCEEDED,
46 REQUEST_FAILED,
49 UserMediaClientImplUnderTest(
50 PeerConnectionDependencyFactory* dependency_factory,
51 scoped_ptr<MediaStreamDispatcher> media_stream_dispatcher)
52 : UserMediaClientImpl(
53 NULL, dependency_factory, media_stream_dispatcher.Pass()),
54 state_(REQUEST_NOT_STARTED),
55 result_(NUM_MEDIA_REQUEST_RESULTS),
56 result_name_(""),
57 factory_(dependency_factory),
58 video_source_(NULL) {
61 void RequestUserMedia() {
62 blink::WebUserMediaRequest user_media_request;
63 state_ = REQUEST_NOT_COMPLETE;
64 requestUserMedia(user_media_request);
67 void RequestMediaDevices() {
68 blink::WebMediaDevicesRequest media_devices_request;
69 state_ = REQUEST_NOT_COMPLETE;
70 requestMediaDevices(media_devices_request);
73 void RequestSources() {
74 blink::WebMediaStreamTrackSourcesRequest sources_request;
75 state_ = REQUEST_NOT_COMPLETE;
76 requestSources(sources_request);
79 void GetUserMediaRequestSucceeded(
80 const blink::WebMediaStream& stream,
81 blink::WebUserMediaRequest request_info) override {
82 last_generated_stream_ = stream;
83 state_ = REQUEST_SUCCEEDED;
86 void GetUserMediaRequestFailed(
87 blink::WebUserMediaRequest request_info,
88 content::MediaStreamRequestResult result,
89 const blink::WebString& result_name) override {
90 last_generated_stream_.reset();
91 state_ = REQUEST_FAILED;
92 result_ = result;
93 result_name_ = result_name;
96 void EnumerateDevicesSucceded(
97 blink::WebMediaDevicesRequest* request,
98 blink::WebVector<blink::WebMediaDeviceInfo>& devices) override {
99 state_ = REQUEST_SUCCEEDED;
100 last_devices_ = devices;
103 void EnumerateSourcesSucceded(
104 blink::WebMediaStreamTrackSourcesRequest* request,
105 blink::WebVector<blink::WebSourceInfo>& sources) override {
106 state_ = REQUEST_SUCCEEDED;
107 last_sources_ = sources;
110 MediaStreamVideoSource* CreateVideoSource(
111 const StreamDeviceInfo& device,
112 const MediaStreamSource::SourceStoppedCallback& stop_callback) override {
113 video_source_ = new MockMediaStreamVideoCapturerSource(device,
114 stop_callback,
115 factory_);
116 return video_source_;
119 const blink::WebMediaStream& last_generated_stream() {
120 return last_generated_stream_;
123 const blink::WebVector<blink::WebMediaDeviceInfo>& last_devices() {
124 return last_devices_;
127 const blink::WebVector<blink::WebSourceInfo>& last_sources() {
128 return last_sources_;
131 void ClearLastGeneratedStream() {
132 last_generated_stream_.reset();
135 MockMediaStreamVideoCapturerSource* last_created_video_source() const {
136 return video_source_;
139 RequestState request_state() const { return state_; }
140 content::MediaStreamRequestResult error_reason() const { return result_; }
141 blink::WebString error_name() const { return result_name_; }
143 private:
144 blink::WebMediaStream last_generated_stream_;
145 RequestState state_;
146 content::MediaStreamRequestResult result_;
147 blink::WebString result_name_;
148 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_;
149 blink::WebVector<blink::WebSourceInfo> last_sources_;
150 PeerConnectionDependencyFactory* factory_;
151 MockMediaStreamVideoCapturerSource* video_source_;
154 class UserMediaClientImplTest : public ::testing::Test {
155 public:
156 void SetUp() override {
157 // Create our test object.
158 child_process_.reset(new ChildProcess());
159 dependency_factory_.reset(new MockPeerConnectionDependencyFactory());
160 ms_dispatcher_ = new MockMediaStreamDispatcher();
161 used_media_impl_.reset(new UserMediaClientImplUnderTest(
162 dependency_factory_.get(),
163 scoped_ptr<MediaStreamDispatcher>(ms_dispatcher_).Pass()));
166 void TearDown() override {
167 used_media_impl_.reset();
168 blink::WebHeap::collectAllGarbageForTesting();
171 blink::WebMediaStream RequestLocalMediaStream() {
172 used_media_impl_->RequestUserMedia();
173 base::RunLoop().RunUntilIdle();
174 FakeMediaStreamDispatcherRequestUserMediaComplete();
175 StartMockedVideoSource();
177 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED,
178 used_media_impl_->request_state());
180 blink::WebMediaStream desc = used_media_impl_->last_generated_stream();
181 content::MediaStream* native_stream =
182 content::MediaStream::GetMediaStream(desc);
183 if (!native_stream) {
184 ADD_FAILURE();
185 return desc;
188 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks;
189 desc.audioTracks(audio_tracks);
190 blink::WebVector<blink::WebMediaStreamTrack> video_tracks;
191 desc.videoTracks(video_tracks);
193 EXPECT_EQ(1u, audio_tracks.size());
194 EXPECT_EQ(1u, video_tracks.size());
195 EXPECT_NE(audio_tracks[0].id(), video_tracks[0].id());
196 return desc;
199 void FakeMediaStreamDispatcherRequestUserMediaComplete() {
200 // Audio request ID is used as the shared request ID.
201 used_media_impl_->OnStreamGenerated(
202 ms_dispatcher_->audio_input_request_id(),
203 ms_dispatcher_->stream_label(),
204 ms_dispatcher_->audio_input_array(),
205 ms_dispatcher_->video_array());
208 void FakeMediaStreamDispatcherRequestMediaDevicesComplete() {
209 used_media_impl_->OnDevicesEnumerated(
210 ms_dispatcher_->audio_input_request_id(),
211 ms_dispatcher_->audio_input_array());
212 used_media_impl_->OnDevicesEnumerated(
213 ms_dispatcher_->audio_output_request_id(),
214 ms_dispatcher_->audio_output_array());
215 used_media_impl_->OnDevicesEnumerated(
216 ms_dispatcher_->video_request_id(),
217 ms_dispatcher_->video_array());
220 void FakeMediaStreamDispatcherRequestSourcesComplete() {
221 used_media_impl_->OnDevicesEnumerated(
222 ms_dispatcher_->audio_input_request_id(),
223 ms_dispatcher_->audio_input_array());
224 used_media_impl_->OnDevicesEnumerated(
225 ms_dispatcher_->video_request_id(),
226 ms_dispatcher_->video_array());
229 void StartMockedVideoSource() {
230 MockMediaStreamVideoCapturerSource* video_source =
231 used_media_impl_->last_created_video_source();
232 if (video_source->SourceHasAttemptedToStart())
233 video_source->StartMockedSource();
236 void FailToStartMockedVideoSource() {
237 MockMediaStreamVideoCapturerSource* video_source =
238 used_media_impl_->last_created_video_source();
239 if (video_source->SourceHasAttemptedToStart())
240 video_source->FailToStartMockedSource();
241 blink::WebHeap::collectGarbageForTesting();
244 void FailToCreateNextAudioCapturer() {
245 dependency_factory_->FailToCreateNextAudioCapturer();
246 blink::WebHeap::collectGarbageForTesting();
249 protected:
250 base::MessageLoop message_loop_;
251 scoped_ptr<ChildProcess> child_process_;
252 MockMediaStreamDispatcher* ms_dispatcher_; // Owned by |used_media_impl_|.
253 scoped_ptr<UserMediaClientImplUnderTest> used_media_impl_;
254 scoped_ptr<MockPeerConnectionDependencyFactory> dependency_factory_;
257 TEST_F(UserMediaClientImplTest, GenerateMediaStream) {
258 // Generate a stream with both audio and video.
259 blink::WebMediaStream mixed_desc = RequestLocalMediaStream();
262 // Test that the same source object is used if two MediaStreams are generated
263 // using the same source.
264 TEST_F(UserMediaClientImplTest, GenerateTwoMediaStreamsWithSameSource) {
265 blink::WebMediaStream desc1 = RequestLocalMediaStream();
266 blink::WebMediaStream desc2 = RequestLocalMediaStream();
268 blink::WebVector<blink::WebMediaStreamTrack> desc1_video_tracks;
269 desc1.videoTracks(desc1_video_tracks);
270 blink::WebVector<blink::WebMediaStreamTrack> desc2_video_tracks;
271 desc2.videoTracks(desc2_video_tracks);
272 EXPECT_EQ(desc1_video_tracks[0].source().id(),
273 desc2_video_tracks[0].source().id());
275 EXPECT_EQ(desc1_video_tracks[0].source().extraData(),
276 desc2_video_tracks[0].source().extraData());
278 blink::WebVector<blink::WebMediaStreamTrack> desc1_audio_tracks;
279 desc1.audioTracks(desc1_audio_tracks);
280 blink::WebVector<blink::WebMediaStreamTrack> desc2_audio_tracks;
281 desc2.audioTracks(desc2_audio_tracks);
282 EXPECT_EQ(desc1_audio_tracks[0].source().id(),
283 desc2_audio_tracks[0].source().id());
285 EXPECT_EQ(desc1_audio_tracks[0].source().extraData(),
286 desc2_audio_tracks[0].source().extraData());
289 // Test that the same source object is not used if two MediaStreams are
290 // generated using different sources.
291 TEST_F(UserMediaClientImplTest, GenerateTwoMediaStreamsWithDifferentSources) {
292 blink::WebMediaStream desc1 = RequestLocalMediaStream();
293 // Make sure another device is selected (another |session_id|) in the next
294 // gUM request.
295 ms_dispatcher_->IncrementSessionId();
296 blink::WebMediaStream desc2 = RequestLocalMediaStream();
298 blink::WebVector<blink::WebMediaStreamTrack> desc1_video_tracks;
299 desc1.videoTracks(desc1_video_tracks);
300 blink::WebVector<blink::WebMediaStreamTrack> desc2_video_tracks;
301 desc2.videoTracks(desc2_video_tracks);
302 EXPECT_NE(desc1_video_tracks[0].source().id(),
303 desc2_video_tracks[0].source().id());
305 EXPECT_NE(desc1_video_tracks[0].source().extraData(),
306 desc2_video_tracks[0].source().extraData());
308 blink::WebVector<blink::WebMediaStreamTrack> desc1_audio_tracks;
309 desc1.audioTracks(desc1_audio_tracks);
310 blink::WebVector<blink::WebMediaStreamTrack> desc2_audio_tracks;
311 desc2.audioTracks(desc2_audio_tracks);
312 EXPECT_NE(desc1_audio_tracks[0].source().id(),
313 desc2_audio_tracks[0].source().id());
315 EXPECT_NE(desc1_audio_tracks[0].source().extraData(),
316 desc2_audio_tracks[0].source().extraData());
319 TEST_F(UserMediaClientImplTest, StopLocalTracks) {
320 // Generate a stream with both audio and video.
321 blink::WebMediaStream mixed_desc = RequestLocalMediaStream();
323 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks;
324 mixed_desc.audioTracks(audio_tracks);
325 MediaStreamTrack* audio_track = MediaStreamTrack::GetTrack(audio_tracks[0]);
326 audio_track->Stop();
327 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
329 blink::WebVector<blink::WebMediaStreamTrack> video_tracks;
330 mixed_desc.videoTracks(video_tracks);
331 MediaStreamTrack* video_track = MediaStreamTrack::GetTrack(video_tracks[0]);
332 video_track->Stop();
333 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
336 // This test that a source is not stopped even if the tracks in a
337 // MediaStream is stopped if there are two MediaStreams with tracks using the
338 // same device. The source is stopped
339 // if there are no more MediaStream tracks using the device.
340 TEST_F(UserMediaClientImplTest, StopLocalTracksWhenTwoStreamUseSameDevices) {
341 // Generate a stream with both audio and video.
342 blink::WebMediaStream desc1 = RequestLocalMediaStream();
343 blink::WebMediaStream desc2 = RequestLocalMediaStream();
345 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks1;
346 desc1.audioTracks(audio_tracks1);
347 MediaStreamTrack* audio_track1 = MediaStreamTrack::GetTrack(audio_tracks1[0]);
348 audio_track1->Stop();
349 EXPECT_EQ(0, ms_dispatcher_->stop_audio_device_counter());
351 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks2;
352 desc2.audioTracks(audio_tracks2);
353 MediaStreamTrack* audio_track2 = MediaStreamTrack::GetTrack(audio_tracks2[0]);
354 audio_track2->Stop();
355 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
357 blink::WebVector<blink::WebMediaStreamTrack> video_tracks1;
358 desc1.videoTracks(video_tracks1);
359 MediaStreamTrack* video_track1 = MediaStreamTrack::GetTrack(video_tracks1[0]);
360 video_track1->Stop();
361 EXPECT_EQ(0, ms_dispatcher_->stop_video_device_counter());
363 blink::WebVector<blink::WebMediaStreamTrack> video_tracks2;
364 desc2.videoTracks(video_tracks2);
365 MediaStreamTrack* video_track2 = MediaStreamTrack::GetTrack(video_tracks2[0]);
366 video_track2->Stop();
367 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
370 TEST_F(UserMediaClientImplTest, StopSourceWhenMediaStreamGoesOutOfScope) {
371 // Generate a stream with both audio and video.
372 RequestLocalMediaStream();
373 // Makes sure the test itself don't hold a reference to the created
374 // MediaStream.
375 used_media_impl_->ClearLastGeneratedStream();
376 blink::WebHeap::collectGarbageForTesting();
378 // Expect the sources to be stopped when the MediaStream goes out of scope.
379 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
380 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
383 // Test that the MediaStreams are deleted if the owning WebFrame is closing.
384 // In the unit test the owning frame is NULL.
385 TEST_F(UserMediaClientImplTest, FrameWillClose) {
386 // Test a stream with both audio and video.
387 blink::WebMediaStream mixed_desc = RequestLocalMediaStream();
388 blink::WebMediaStream desc2 = RequestLocalMediaStream();
389 used_media_impl_->FrameWillClose();
390 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
391 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
394 // This test what happens if a video source to a MediaSteam fails to start.
395 TEST_F(UserMediaClientImplTest, MediaVideoSourceFailToStart) {
396 used_media_impl_->RequestUserMedia();
397 base::RunLoop().RunUntilIdle();
398 FakeMediaStreamDispatcherRequestUserMediaComplete();
399 FailToStartMockedVideoSource();
400 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED,
401 used_media_impl_->request_state());
402 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE,
403 used_media_impl_->error_reason());
404 blink::WebHeap::collectGarbageForTesting();
405 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
406 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
407 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
410 // This test what happens if an audio source fail to initialize.
411 TEST_F(UserMediaClientImplTest, MediaAudioSourceFailToInitialize) {
412 FailToCreateNextAudioCapturer();
413 used_media_impl_->RequestUserMedia();
414 base::RunLoop().RunUntilIdle();
415 FakeMediaStreamDispatcherRequestUserMediaComplete();
416 StartMockedVideoSource();
417 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED,
418 used_media_impl_->request_state());
419 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE,
420 used_media_impl_->error_reason());
421 blink::WebHeap::collectGarbageForTesting();
422 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
423 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
424 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
427 // This tests what happens if UserMediaClientImpl is deleted before a source has
428 // started.
429 TEST_F(UserMediaClientImplTest, MediaStreamImplShutDown) {
430 used_media_impl_->RequestUserMedia();
431 base::RunLoop().RunUntilIdle();
432 FakeMediaStreamDispatcherRequestUserMediaComplete();
433 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
434 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_NOT_COMPLETE,
435 used_media_impl_->request_state());
436 used_media_impl_.reset();
439 // This test what happens if the WebFrame is closed while the MediaStream is
440 // being generated by the MediaStreamDispatcher.
441 TEST_F(UserMediaClientImplTest, ReloadFrameWhileGeneratingStream) {
442 used_media_impl_->RequestUserMedia();
443 base::RunLoop().RunUntilIdle();
444 used_media_impl_->FrameWillClose();
445 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
446 EXPECT_EQ(0, ms_dispatcher_->stop_audio_device_counter());
447 EXPECT_EQ(0, ms_dispatcher_->stop_video_device_counter());
448 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_NOT_COMPLETE,
449 used_media_impl_->request_state());
452 // This test what happens if the WebFrame is closed while the sources are being
453 // started.
454 TEST_F(UserMediaClientImplTest, ReloadFrameWhileGeneratingSources) {
455 used_media_impl_->RequestUserMedia();
456 base::RunLoop().RunUntilIdle();
457 FakeMediaStreamDispatcherRequestUserMediaComplete();
458 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
459 used_media_impl_->FrameWillClose();
460 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
461 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
462 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_NOT_COMPLETE,
463 used_media_impl_->request_state());
466 // This test what happens if stop is called on a track after the frame has
467 // been reloaded.
468 TEST_F(UserMediaClientImplTest, StopTrackAfterReload) {
469 blink::WebMediaStream mixed_desc = RequestLocalMediaStream();
470 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
471 used_media_impl_->FrameWillClose();
472 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
473 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
475 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks;
476 mixed_desc.audioTracks(audio_tracks);
477 MediaStreamTrack* audio_track = MediaStreamTrack::GetTrack(audio_tracks[0]);
478 audio_track->Stop();
479 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
481 blink::WebVector<blink::WebMediaStreamTrack> video_tracks;
482 mixed_desc.videoTracks(video_tracks);
483 MediaStreamTrack* video_track = MediaStreamTrack::GetTrack(video_tracks[0]);
484 video_track->Stop();
485 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
488 TEST_F(UserMediaClientImplTest, EnumerateMediaDevices) {
489 used_media_impl_->RequestMediaDevices();
490 FakeMediaStreamDispatcherRequestMediaDevicesComplete();
492 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED,
493 used_media_impl_->request_state());
494 EXPECT_EQ(static_cast<size_t>(5), used_media_impl_->last_devices().size());
496 // Audio input device with matched output ID.
497 const blink::WebMediaDeviceInfo* device =
498 &used_media_impl_->last_devices()[0];
499 EXPECT_FALSE(device->deviceId().isEmpty());
500 EXPECT_EQ(blink::WebMediaDeviceInfo::MediaDeviceKindAudioInput,
501 device->kind());
502 EXPECT_FALSE(device->label().isEmpty());
503 EXPECT_FALSE(device->groupId().isEmpty());
505 // Audio input device without matched output ID.
506 device = &used_media_impl_->last_devices()[1];
507 EXPECT_FALSE(device->deviceId().isEmpty());
508 EXPECT_EQ(blink::WebMediaDeviceInfo::MediaDeviceKindAudioInput,
509 device->kind());
510 EXPECT_FALSE(device->label().isEmpty());
511 EXPECT_FALSE(device->groupId().isEmpty());
513 // Video input devices.
514 device = &used_media_impl_->last_devices()[2];
515 EXPECT_FALSE(device->deviceId().isEmpty());
516 EXPECT_EQ(blink::WebMediaDeviceInfo::MediaDeviceKindVideoInput,
517 device->kind());
518 EXPECT_FALSE(device->label().isEmpty());
519 EXPECT_TRUE(device->groupId().isEmpty());
521 device = &used_media_impl_->last_devices()[3];
522 EXPECT_FALSE(device->deviceId().isEmpty());
523 EXPECT_EQ(blink::WebMediaDeviceInfo::MediaDeviceKindVideoInput,
524 device->kind());
525 EXPECT_FALSE(device->label().isEmpty());
526 EXPECT_TRUE(device->groupId().isEmpty());
528 // Audio output device.
529 device = &used_media_impl_->last_devices()[4];
530 EXPECT_FALSE(device->deviceId().isEmpty());
531 EXPECT_EQ(blink::WebMediaDeviceInfo::MediaDeviceKindAudioOutput,
532 device->kind());
533 EXPECT_FALSE(device->label().isEmpty());
534 EXPECT_FALSE(device->groupId().isEmpty());
536 // Verfify group IDs.
537 EXPECT_TRUE(used_media_impl_->last_devices()[0].groupId().equals(
538 used_media_impl_->last_devices()[4].groupId()));
539 EXPECT_FALSE(used_media_impl_->last_devices()[1].groupId().equals(
540 used_media_impl_->last_devices()[4].groupId()));
543 TEST_F(UserMediaClientImplTest, EnumerateSources) {
544 used_media_impl_->RequestSources();
545 FakeMediaStreamDispatcherRequestSourcesComplete();
547 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED,
548 used_media_impl_->request_state());
549 EXPECT_EQ(static_cast<size_t>(4), used_media_impl_->last_sources().size());
551 // Audio input devices.
552 const blink::WebSourceInfo* source = &used_media_impl_->last_sources()[0];
553 EXPECT_FALSE(source->id().isEmpty());
554 EXPECT_EQ(blink::WebSourceInfo::SourceKindAudio, source->kind());
555 EXPECT_FALSE(source->label().isEmpty());
556 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing());
558 source = &used_media_impl_->last_sources()[1];
559 EXPECT_FALSE(source->id().isEmpty());
560 EXPECT_EQ(blink::WebSourceInfo::SourceKindAudio, source->kind());
561 EXPECT_FALSE(source->label().isEmpty());
562 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone, source->facing());
564 // Video input device user facing.
565 source = &used_media_impl_->last_sources()[2];
566 EXPECT_FALSE(source->id().isEmpty());
567 EXPECT_EQ(blink::WebSourceInfo::SourceKindVideo, source->kind());
568 EXPECT_FALSE(source->label().isEmpty());
569 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeUser, source->facing());
571 // Video input device environment facing.
572 source = &used_media_impl_->last_sources()[3];
573 EXPECT_FALSE(source->id().isEmpty());
574 EXPECT_EQ(blink::WebSourceInfo::SourceKindVideo, source->kind());
575 EXPECT_FALSE(source->label().isEmpty());
576 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeEnvironment, source->facing());
579 } // namespace content