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/strings/utf_string_conversions.h"
8 #include "content/child/child_process.h"
9 #include "content/renderer/media/media_stream.h"
10 #include "content/renderer/media/media_stream_track.h"
11 #include "content/renderer/media/mock_media_stream_dispatcher.h"
12 #include "content/renderer/media/mock_media_stream_video_source.h"
13 #include "content/renderer/media/user_media_client_impl.h"
14 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h"
17 #include "third_party/WebKit/public/platform/WebMediaStream.h"
18 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
19 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
20 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h"
21 #include "third_party/WebKit/public/platform/WebString.h"
22 #include "third_party/WebKit/public/platform/WebVector.h"
23 #include "third_party/WebKit/public/web/WebHeap.h"
27 class MockMediaStreamVideoCapturerSource
: public MockMediaStreamVideoSource
{
29 MockMediaStreamVideoCapturerSource(
30 const StreamDeviceInfo
& device
,
31 const SourceStoppedCallback
& stop_callback
,
32 PeerConnectionDependencyFactory
* factory
)
33 : MockMediaStreamVideoSource(false) {
34 SetDeviceInfo(device
);
35 SetStopCallback(stop_callback
);
39 class UserMediaClientImplUnderTest
: public UserMediaClientImpl
{
48 UserMediaClientImplUnderTest(
49 PeerConnectionDependencyFactory
* dependency_factory
,
50 scoped_ptr
<MediaStreamDispatcher
> media_stream_dispatcher
)
51 : UserMediaClientImpl(
52 NULL
, dependency_factory
, media_stream_dispatcher
.Pass()),
53 state_(REQUEST_NOT_STARTED
),
54 result_(NUM_MEDIA_REQUEST_RESULTS
),
56 factory_(dependency_factory
),
60 void RequestUserMedia() {
61 blink::WebUserMediaRequest user_media_request
;
62 state_
= REQUEST_NOT_COMPLETE
;
63 requestUserMedia(user_media_request
);
66 void RequestMediaDevices() {
67 blink::WebMediaDevicesRequest media_devices_request
;
68 state_
= REQUEST_NOT_COMPLETE
;
69 requestMediaDevices(media_devices_request
);
72 void RequestSources() {
73 blink::WebMediaStreamTrackSourcesRequest sources_request
;
74 state_
= REQUEST_NOT_COMPLETE
;
75 requestSources(sources_request
);
78 void GetUserMediaRequestSucceeded(
79 const blink::WebMediaStream
& stream
,
80 blink::WebUserMediaRequest
* request_info
) override
{
81 last_generated_stream_
= stream
;
82 state_
= REQUEST_SUCCEEDED
;
85 void GetUserMediaRequestFailed(
86 blink::WebUserMediaRequest
* request_info
,
87 content::MediaStreamRequestResult result
,
88 const blink::WebString
& result_name
) override
{
89 last_generated_stream_
.reset();
90 state_
= REQUEST_FAILED
;
92 result_name_
= result_name
;
95 void EnumerateDevicesSucceded(
96 blink::WebMediaDevicesRequest
* request
,
97 blink::WebVector
<blink::WebMediaDeviceInfo
>& devices
) override
{
98 state_
= REQUEST_SUCCEEDED
;
99 last_devices_
= devices
;
102 void EnumerateSourcesSucceded(
103 blink::WebMediaStreamTrackSourcesRequest
* request
,
104 blink::WebVector
<blink::WebSourceInfo
>& sources
) override
{
105 state_
= REQUEST_SUCCEEDED
;
106 last_sources_
= sources
;
109 MediaStreamVideoSource
* CreateVideoSource(
110 const StreamDeviceInfo
& device
,
111 const MediaStreamSource::SourceStoppedCallback
& stop_callback
) override
{
112 video_source_
= new MockMediaStreamVideoCapturerSource(device
,
115 return video_source_
;
118 const blink::WebMediaStream
& last_generated_stream() {
119 return last_generated_stream_
;
122 const blink::WebVector
<blink::WebMediaDeviceInfo
>& last_devices() {
123 return last_devices_
;
126 const blink::WebVector
<blink::WebSourceInfo
>& last_sources() {
127 return last_sources_
;
130 void ClearLastGeneratedStream() {
131 last_generated_stream_
.reset();
134 MockMediaStreamVideoCapturerSource
* last_created_video_source() const {
135 return video_source_
;
138 RequestState
request_state() const { return state_
; }
139 content::MediaStreamRequestResult
error_reason() const { return result_
; }
140 blink::WebString
error_name() const { return result_name_
; }
143 blink::WebMediaStream last_generated_stream_
;
145 content::MediaStreamRequestResult result_
;
146 blink::WebString result_name_
;
147 blink::WebVector
<blink::WebMediaDeviceInfo
> last_devices_
;
148 blink::WebVector
<blink::WebSourceInfo
> last_sources_
;
149 PeerConnectionDependencyFactory
* factory_
;
150 MockMediaStreamVideoCapturerSource
* video_source_
;
153 class UserMediaClientImplTest
: public ::testing::Test
{
155 void SetUp() override
{
156 // Create our test object.
157 child_process_
.reset(new ChildProcess());
158 dependency_factory_
.reset(new MockPeerConnectionDependencyFactory());
159 ms_dispatcher_
= new MockMediaStreamDispatcher();
160 used_media_impl_
.reset(new UserMediaClientImplUnderTest(
161 dependency_factory_
.get(),
162 scoped_ptr
<MediaStreamDispatcher
>(ms_dispatcher_
).Pass()));
165 void TearDown() override
{
166 used_media_impl_
.reset();
167 blink::WebHeap::collectAllGarbageForTesting();
170 blink::WebMediaStream
RequestLocalMediaStream() {
171 used_media_impl_
->RequestUserMedia();
172 FakeMediaStreamDispatcherRequestUserMediaComplete();
173 StartMockedVideoSource();
175 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED
,
176 used_media_impl_
->request_state());
178 blink::WebMediaStream desc
= used_media_impl_
->last_generated_stream();
179 content::MediaStream
* native_stream
=
180 content::MediaStream::GetMediaStream(desc
);
181 if (!native_stream
) {
186 blink::WebVector
<blink::WebMediaStreamTrack
> audio_tracks
;
187 desc
.audioTracks(audio_tracks
);
188 blink::WebVector
<blink::WebMediaStreamTrack
> video_tracks
;
189 desc
.videoTracks(video_tracks
);
191 EXPECT_EQ(1u, audio_tracks
.size());
192 EXPECT_EQ(1u, video_tracks
.size());
193 EXPECT_NE(audio_tracks
[0].id(), video_tracks
[0].id());
197 void FakeMediaStreamDispatcherRequestUserMediaComplete() {
198 // Audio request ID is used as the shared request ID.
199 used_media_impl_
->OnStreamGenerated(
200 ms_dispatcher_
->audio_input_request_id(),
201 ms_dispatcher_
->stream_label(),
202 ms_dispatcher_
->audio_input_array(),
203 ms_dispatcher_
->video_array());
206 void FakeMediaStreamDispatcherRequestMediaDevicesComplete() {
207 used_media_impl_
->OnDevicesEnumerated(
208 ms_dispatcher_
->audio_input_request_id(),
209 ms_dispatcher_
->audio_input_array());
210 used_media_impl_
->OnDevicesEnumerated(
211 ms_dispatcher_
->audio_output_request_id(),
212 ms_dispatcher_
->audio_output_array());
213 used_media_impl_
->OnDevicesEnumerated(
214 ms_dispatcher_
->video_request_id(),
215 ms_dispatcher_
->video_array());
218 void FakeMediaStreamDispatcherRequestSourcesComplete() {
219 used_media_impl_
->OnDevicesEnumerated(
220 ms_dispatcher_
->audio_input_request_id(),
221 ms_dispatcher_
->audio_input_array());
222 used_media_impl_
->OnDevicesEnumerated(
223 ms_dispatcher_
->video_request_id(),
224 ms_dispatcher_
->video_array());
227 void StartMockedVideoSource() {
228 MockMediaStreamVideoCapturerSource
* video_source
=
229 used_media_impl_
->last_created_video_source();
230 if (video_source
->SourceHasAttemptedToStart())
231 video_source
->StartMockedSource();
234 void FailToStartMockedVideoSource() {
235 MockMediaStreamVideoCapturerSource
* video_source
=
236 used_media_impl_
->last_created_video_source();
237 if (video_source
->SourceHasAttemptedToStart())
238 video_source
->FailToStartMockedSource();
239 blink::WebHeap::collectGarbageForTesting();
242 void FailToCreateNextAudioCapturer() {
243 dependency_factory_
->FailToCreateNextAudioCapturer();
244 blink::WebHeap::collectGarbageForTesting();
248 base::MessageLoop message_loop_
;
249 scoped_ptr
<ChildProcess
> child_process_
;
250 MockMediaStreamDispatcher
* ms_dispatcher_
; // Owned by |used_media_impl_|.
251 scoped_ptr
<UserMediaClientImplUnderTest
> used_media_impl_
;
252 scoped_ptr
<MockPeerConnectionDependencyFactory
> dependency_factory_
;
255 TEST_F(UserMediaClientImplTest
, GenerateMediaStream
) {
256 // Generate a stream with both audio and video.
257 blink::WebMediaStream mixed_desc
= RequestLocalMediaStream();
260 // Test that the same source object is used if two MediaStreams are generated
261 // using the same source.
262 TEST_F(UserMediaClientImplTest
, GenerateTwoMediaStreamsWithSameSource
) {
263 blink::WebMediaStream desc1
= RequestLocalMediaStream();
264 blink::WebMediaStream desc2
= RequestLocalMediaStream();
266 blink::WebVector
<blink::WebMediaStreamTrack
> desc1_video_tracks
;
267 desc1
.videoTracks(desc1_video_tracks
);
268 blink::WebVector
<blink::WebMediaStreamTrack
> desc2_video_tracks
;
269 desc2
.videoTracks(desc2_video_tracks
);
270 EXPECT_EQ(desc1_video_tracks
[0].source().id(),
271 desc2_video_tracks
[0].source().id());
273 EXPECT_EQ(desc1_video_tracks
[0].source().extraData(),
274 desc2_video_tracks
[0].source().extraData());
276 blink::WebVector
<blink::WebMediaStreamTrack
> desc1_audio_tracks
;
277 desc1
.audioTracks(desc1_audio_tracks
);
278 blink::WebVector
<blink::WebMediaStreamTrack
> desc2_audio_tracks
;
279 desc2
.audioTracks(desc2_audio_tracks
);
280 EXPECT_EQ(desc1_audio_tracks
[0].source().id(),
281 desc2_audio_tracks
[0].source().id());
283 EXPECT_EQ(desc1_audio_tracks
[0].source().extraData(),
284 desc2_audio_tracks
[0].source().extraData());
287 // Test that the same source object is not used if two MediaStreams are
288 // generated using different sources.
289 TEST_F(UserMediaClientImplTest
, GenerateTwoMediaStreamsWithDifferentSources
) {
290 blink::WebMediaStream desc1
= RequestLocalMediaStream();
291 // Make sure another device is selected (another |session_id|) in the next
293 ms_dispatcher_
->IncrementSessionId();
294 blink::WebMediaStream desc2
= RequestLocalMediaStream();
296 blink::WebVector
<blink::WebMediaStreamTrack
> desc1_video_tracks
;
297 desc1
.videoTracks(desc1_video_tracks
);
298 blink::WebVector
<blink::WebMediaStreamTrack
> desc2_video_tracks
;
299 desc2
.videoTracks(desc2_video_tracks
);
300 EXPECT_NE(desc1_video_tracks
[0].source().id(),
301 desc2_video_tracks
[0].source().id());
303 EXPECT_NE(desc1_video_tracks
[0].source().extraData(),
304 desc2_video_tracks
[0].source().extraData());
306 blink::WebVector
<blink::WebMediaStreamTrack
> desc1_audio_tracks
;
307 desc1
.audioTracks(desc1_audio_tracks
);
308 blink::WebVector
<blink::WebMediaStreamTrack
> desc2_audio_tracks
;
309 desc2
.audioTracks(desc2_audio_tracks
);
310 EXPECT_NE(desc1_audio_tracks
[0].source().id(),
311 desc2_audio_tracks
[0].source().id());
313 EXPECT_NE(desc1_audio_tracks
[0].source().extraData(),
314 desc2_audio_tracks
[0].source().extraData());
317 TEST_F(UserMediaClientImplTest
, StopLocalTracks
) {
318 // Generate a stream with both audio and video.
319 blink::WebMediaStream mixed_desc
= RequestLocalMediaStream();
321 blink::WebVector
<blink::WebMediaStreamTrack
> audio_tracks
;
322 mixed_desc
.audioTracks(audio_tracks
);
323 MediaStreamTrack
* audio_track
= MediaStreamTrack::GetTrack(audio_tracks
[0]);
325 EXPECT_EQ(1, ms_dispatcher_
->stop_audio_device_counter());
327 blink::WebVector
<blink::WebMediaStreamTrack
> video_tracks
;
328 mixed_desc
.videoTracks(video_tracks
);
329 MediaStreamTrack
* video_track
= MediaStreamTrack::GetTrack(video_tracks
[0]);
331 EXPECT_EQ(1, ms_dispatcher_
->stop_video_device_counter());
334 // This test that a source is not stopped even if the tracks in a
335 // MediaStream is stopped if there are two MediaStreams with tracks using the
336 // same device. The source is stopped
337 // if there are no more MediaStream tracks using the device.
338 TEST_F(UserMediaClientImplTest
, StopLocalTracksWhenTwoStreamUseSameDevices
) {
339 // Generate a stream with both audio and video.
340 blink::WebMediaStream desc1
= RequestLocalMediaStream();
341 blink::WebMediaStream desc2
= RequestLocalMediaStream();
343 blink::WebVector
<blink::WebMediaStreamTrack
> audio_tracks1
;
344 desc1
.audioTracks(audio_tracks1
);
345 MediaStreamTrack
* audio_track1
= MediaStreamTrack::GetTrack(audio_tracks1
[0]);
346 audio_track1
->Stop();
347 EXPECT_EQ(0, ms_dispatcher_
->stop_audio_device_counter());
349 blink::WebVector
<blink::WebMediaStreamTrack
> audio_tracks2
;
350 desc2
.audioTracks(audio_tracks2
);
351 MediaStreamTrack
* audio_track2
= MediaStreamTrack::GetTrack(audio_tracks2
[0]);
352 audio_track2
->Stop();
353 EXPECT_EQ(1, ms_dispatcher_
->stop_audio_device_counter());
355 blink::WebVector
<blink::WebMediaStreamTrack
> video_tracks1
;
356 desc1
.videoTracks(video_tracks1
);
357 MediaStreamTrack
* video_track1
= MediaStreamTrack::GetTrack(video_tracks1
[0]);
358 video_track1
->Stop();
359 EXPECT_EQ(0, ms_dispatcher_
->stop_video_device_counter());
361 blink::WebVector
<blink::WebMediaStreamTrack
> video_tracks2
;
362 desc2
.videoTracks(video_tracks2
);
363 MediaStreamTrack
* video_track2
= MediaStreamTrack::GetTrack(video_tracks2
[0]);
364 video_track2
->Stop();
365 EXPECT_EQ(1, ms_dispatcher_
->stop_video_device_counter());
368 TEST_F(UserMediaClientImplTest
, StopSourceWhenMediaStreamGoesOutOfScope
) {
369 // Generate a stream with both audio and video.
370 RequestLocalMediaStream();
371 // Makes sure the test itself don't hold a reference to the created
373 used_media_impl_
->ClearLastGeneratedStream();
374 blink::WebHeap::collectGarbageForTesting();
376 // Expect the sources to be stopped when the MediaStream goes out of scope.
377 EXPECT_EQ(1, ms_dispatcher_
->stop_audio_device_counter());
378 EXPECT_EQ(1, ms_dispatcher_
->stop_video_device_counter());
381 // Test that the MediaStreams are deleted if the owning WebFrame is closing.
382 // In the unit test the owning frame is NULL.
383 TEST_F(UserMediaClientImplTest
, FrameWillClose
) {
384 // Test a stream with both audio and video.
385 blink::WebMediaStream mixed_desc
= RequestLocalMediaStream();
386 blink::WebMediaStream desc2
= RequestLocalMediaStream();
387 used_media_impl_
->FrameWillClose();
388 EXPECT_EQ(1, ms_dispatcher_
->stop_audio_device_counter());
389 EXPECT_EQ(1, ms_dispatcher_
->stop_video_device_counter());
392 // This test what happens if a video source to a MediaSteam fails to start.
393 TEST_F(UserMediaClientImplTest
, MediaVideoSourceFailToStart
) {
394 used_media_impl_
->RequestUserMedia();
395 FakeMediaStreamDispatcherRequestUserMediaComplete();
396 FailToStartMockedVideoSource();
397 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED
,
398 used_media_impl_
->request_state());
399 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE
,
400 used_media_impl_
->error_reason());
401 blink::WebHeap::collectGarbageForTesting();
402 EXPECT_EQ(1, ms_dispatcher_
->request_stream_counter());
403 EXPECT_EQ(1, ms_dispatcher_
->stop_audio_device_counter());
404 EXPECT_EQ(1, ms_dispatcher_
->stop_video_device_counter());
407 // This test what happens if an audio source fail to initialize.
408 TEST_F(UserMediaClientImplTest
, MediaAudioSourceFailToInitialize
) {
409 FailToCreateNextAudioCapturer();
410 used_media_impl_
->RequestUserMedia();
411 FakeMediaStreamDispatcherRequestUserMediaComplete();
412 StartMockedVideoSource();
413 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED
,
414 used_media_impl_
->request_state());
415 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE
,
416 used_media_impl_
->error_reason());
417 blink::WebHeap::collectGarbageForTesting();
418 EXPECT_EQ(1, ms_dispatcher_
->request_stream_counter());
419 EXPECT_EQ(1, ms_dispatcher_
->stop_audio_device_counter());
420 EXPECT_EQ(1, ms_dispatcher_
->stop_video_device_counter());
423 // This test what happens if UserMediaClientImpl is deleted before a source has
425 TEST_F(UserMediaClientImplTest
, MediaStreamImplShutDown
) {
426 used_media_impl_
->RequestUserMedia();
427 FakeMediaStreamDispatcherRequestUserMediaComplete();
428 EXPECT_EQ(1, ms_dispatcher_
->request_stream_counter());
429 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_NOT_COMPLETE
,
430 used_media_impl_
->request_state());
431 used_media_impl_
.reset();
434 // This test what happens if the WebFrame is closed while the MediaStream is
435 // being generated by the MediaStreamDispatcher.
436 TEST_F(UserMediaClientImplTest
, ReloadFrameWhileGeneratingStream
) {
437 used_media_impl_
->RequestUserMedia();
438 used_media_impl_
->FrameWillClose();
439 EXPECT_EQ(1, ms_dispatcher_
->request_stream_counter());
440 EXPECT_EQ(0, ms_dispatcher_
->stop_audio_device_counter());
441 EXPECT_EQ(0, ms_dispatcher_
->stop_video_device_counter());
442 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_NOT_COMPLETE
,
443 used_media_impl_
->request_state());
446 // This test what happens if the WebFrame is closed while the sources are being
448 TEST_F(UserMediaClientImplTest
, ReloadFrameWhileGeneratingSources
) {
449 used_media_impl_
->RequestUserMedia();
450 FakeMediaStreamDispatcherRequestUserMediaComplete();
451 EXPECT_EQ(1, ms_dispatcher_
->request_stream_counter());
452 used_media_impl_
->FrameWillClose();
453 EXPECT_EQ(1, ms_dispatcher_
->stop_audio_device_counter());
454 EXPECT_EQ(1, ms_dispatcher_
->stop_video_device_counter());
455 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_NOT_COMPLETE
,
456 used_media_impl_
->request_state());
459 // This test what happens if stop is called on a track after the frame has
461 TEST_F(UserMediaClientImplTest
, StopTrackAfterReload
) {
462 blink::WebMediaStream mixed_desc
= RequestLocalMediaStream();
463 EXPECT_EQ(1, ms_dispatcher_
->request_stream_counter());
464 used_media_impl_
->FrameWillClose();
465 EXPECT_EQ(1, ms_dispatcher_
->stop_audio_device_counter());
466 EXPECT_EQ(1, ms_dispatcher_
->stop_video_device_counter());
468 blink::WebVector
<blink::WebMediaStreamTrack
> audio_tracks
;
469 mixed_desc
.audioTracks(audio_tracks
);
470 MediaStreamTrack
* audio_track
= MediaStreamTrack::GetTrack(audio_tracks
[0]);
472 EXPECT_EQ(1, ms_dispatcher_
->stop_audio_device_counter());
474 blink::WebVector
<blink::WebMediaStreamTrack
> video_tracks
;
475 mixed_desc
.videoTracks(video_tracks
);
476 MediaStreamTrack
* video_track
= MediaStreamTrack::GetTrack(video_tracks
[0]);
478 EXPECT_EQ(1, ms_dispatcher_
->stop_video_device_counter());
481 TEST_F(UserMediaClientImplTest
, EnumerateMediaDevices
) {
482 used_media_impl_
->RequestMediaDevices();
483 FakeMediaStreamDispatcherRequestMediaDevicesComplete();
485 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED
,
486 used_media_impl_
->request_state());
487 EXPECT_EQ(static_cast<size_t>(5), used_media_impl_
->last_devices().size());
489 // Audio input device with matched output ID.
490 const blink::WebMediaDeviceInfo
* device
=
491 &used_media_impl_
->last_devices()[0];
492 EXPECT_FALSE(device
->deviceId().isEmpty());
493 EXPECT_EQ(blink::WebMediaDeviceInfo::MediaDeviceKindAudioInput
,
495 EXPECT_FALSE(device
->label().isEmpty());
496 EXPECT_FALSE(device
->groupId().isEmpty());
498 // Audio input device without matched output ID.
499 device
= &used_media_impl_
->last_devices()[1];
500 EXPECT_FALSE(device
->deviceId().isEmpty());
501 EXPECT_EQ(blink::WebMediaDeviceInfo::MediaDeviceKindAudioInput
,
503 EXPECT_FALSE(device
->label().isEmpty());
504 EXPECT_FALSE(device
->groupId().isEmpty());
506 // Video input devices.
507 device
= &used_media_impl_
->last_devices()[2];
508 EXPECT_FALSE(device
->deviceId().isEmpty());
509 EXPECT_EQ(blink::WebMediaDeviceInfo::MediaDeviceKindVideoInput
,
511 EXPECT_FALSE(device
->label().isEmpty());
512 EXPECT_TRUE(device
->groupId().isEmpty());
514 device
= &used_media_impl_
->last_devices()[3];
515 EXPECT_FALSE(device
->deviceId().isEmpty());
516 EXPECT_EQ(blink::WebMediaDeviceInfo::MediaDeviceKindVideoInput
,
518 EXPECT_FALSE(device
->label().isEmpty());
519 EXPECT_TRUE(device
->groupId().isEmpty());
521 // Audio output device.
522 device
= &used_media_impl_
->last_devices()[4];
523 EXPECT_FALSE(device
->deviceId().isEmpty());
524 EXPECT_EQ(blink::WebMediaDeviceInfo::MediaDeviceKindAudioOutput
,
526 EXPECT_FALSE(device
->label().isEmpty());
527 EXPECT_FALSE(device
->groupId().isEmpty());
529 // Verfify group IDs.
530 EXPECT_TRUE(used_media_impl_
->last_devices()[0].groupId().equals(
531 used_media_impl_
->last_devices()[4].groupId()));
532 EXPECT_FALSE(used_media_impl_
->last_devices()[1].groupId().equals(
533 used_media_impl_
->last_devices()[4].groupId()));
536 TEST_F(UserMediaClientImplTest
, EnumerateSources
) {
537 used_media_impl_
->RequestSources();
538 FakeMediaStreamDispatcherRequestSourcesComplete();
540 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED
,
541 used_media_impl_
->request_state());
542 EXPECT_EQ(static_cast<size_t>(4), used_media_impl_
->last_sources().size());
544 // Audio input devices.
545 const blink::WebSourceInfo
* source
= &used_media_impl_
->last_sources()[0];
546 EXPECT_FALSE(source
->id().isEmpty());
547 EXPECT_EQ(blink::WebSourceInfo::SourceKindAudio
, source
->kind());
548 EXPECT_FALSE(source
->label().isEmpty());
549 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone
, source
->facing());
551 source
= &used_media_impl_
->last_sources()[1];
552 EXPECT_FALSE(source
->id().isEmpty());
553 EXPECT_EQ(blink::WebSourceInfo::SourceKindAudio
, source
->kind());
554 EXPECT_FALSE(source
->label().isEmpty());
555 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeNone
, source
->facing());
557 // Video input device user facing.
558 source
= &used_media_impl_
->last_sources()[2];
559 EXPECT_FALSE(source
->id().isEmpty());
560 EXPECT_EQ(blink::WebSourceInfo::SourceKindVideo
, source
->kind());
561 EXPECT_FALSE(source
->label().isEmpty());
562 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeUser
, source
->facing());
564 // Video input device environment facing.
565 source
= &used_media_impl_
->last_sources()[3];
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::VideoFacingModeEnvironment
, source
->facing());
572 } // namespace content