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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/child/child_process.h" | 8 #include "content/child/child_process.h" |
9 #include "content/renderer/media/media_stream.h" | 9 #include "content/renderer/media/media_stream.h" |
10 #include "content/renderer/media/media_stream_impl.h" | 10 #include "content/renderer/media/media_stream_impl.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 class MediaStreamImplUnderTest : public MediaStreamImpl { | 37 class MediaStreamImplUnderTest : public MediaStreamImpl { |
38 public: | 38 public: |
39 enum RequestState { | 39 enum RequestState { |
40 REQUEST_NOT_STARTED, | 40 REQUEST_NOT_STARTED, |
41 REQUEST_NOT_COMPLETE, | 41 REQUEST_NOT_COMPLETE, |
42 REQUEST_SUCCEEDED, | 42 REQUEST_SUCCEEDED, |
43 REQUEST_FAILED, | 43 REQUEST_FAILED, |
44 }; | 44 }; |
45 | 45 |
46 MediaStreamImplUnderTest(MediaStreamDispatcher* media_stream_dispatcher, | 46 MediaStreamImplUnderTest( |
47 PeerConnectionDependencyFactory* dependency_factory) | 47 PeerConnectionDependencyFactory* dependency_factory, |
48 : MediaStreamImpl(NULL, media_stream_dispatcher, dependency_factory), | 48 scoped_ptr<MediaStreamDispatcher> media_stream_dispatcher) |
| 49 : MediaStreamImpl( |
| 50 NULL, dependency_factory, media_stream_dispatcher.Pass()), |
49 state_(REQUEST_NOT_STARTED), | 51 state_(REQUEST_NOT_STARTED), |
50 result_(NUM_MEDIA_REQUEST_RESULTS), | 52 result_(NUM_MEDIA_REQUEST_RESULTS), |
51 factory_(dependency_factory), | 53 factory_(dependency_factory), |
52 video_source_(NULL) { | 54 video_source_(NULL) { |
53 } | 55 } |
54 | 56 |
55 void RequestUserMedia() { | 57 void RequestUserMedia() { |
56 blink::WebUserMediaRequest user_media_request; | 58 blink::WebUserMediaRequest user_media_request; |
57 state_ = REQUEST_NOT_COMPLETE; | 59 state_ = REQUEST_NOT_COMPLETE; |
58 requestUserMedia(user_media_request); | 60 requestUserMedia(user_media_request); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_; | 123 blink::WebVector<blink::WebMediaDeviceInfo> last_devices_; |
122 PeerConnectionDependencyFactory* factory_; | 124 PeerConnectionDependencyFactory* factory_; |
123 MockMediaStreamVideoCapturerSource* video_source_; | 125 MockMediaStreamVideoCapturerSource* video_source_; |
124 }; | 126 }; |
125 | 127 |
126 class MediaStreamImplTest : public ::testing::Test { | 128 class MediaStreamImplTest : public ::testing::Test { |
127 public: | 129 public: |
128 virtual void SetUp() { | 130 virtual void SetUp() { |
129 // Create our test object. | 131 // Create our test object. |
130 child_process_.reset(new ChildProcess()); | 132 child_process_.reset(new ChildProcess()); |
131 ms_dispatcher_.reset(new MockMediaStreamDispatcher()); | |
132 dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); | 133 dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); |
133 ms_impl_.reset(new MediaStreamImplUnderTest(ms_dispatcher_.get(), | 134 ms_dispatcher_ = new MockMediaStreamDispatcher(); |
134 dependency_factory_.get())); | 135 ms_impl_.reset(new MediaStreamImplUnderTest( |
| 136 dependency_factory_.get(), |
| 137 scoped_ptr<MediaStreamDispatcher>(ms_dispatcher_).Pass())); |
135 } | 138 } |
136 | 139 |
137 blink::WebMediaStream RequestLocalMediaStream() { | 140 blink::WebMediaStream RequestLocalMediaStream() { |
138 ms_impl_->RequestUserMedia(); | 141 ms_impl_->RequestUserMedia(); |
139 FakeMediaStreamDispatcherRequestUserMediaComplete(); | 142 FakeMediaStreamDispatcherRequestUserMediaComplete(); |
140 StartMockedVideoSource(); | 143 StartMockedVideoSource(); |
141 | 144 |
142 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_SUCCEEDED, | 145 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_SUCCEEDED, |
143 ms_impl_->request_state()); | 146 ms_impl_->request_state()); |
144 | 147 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 video_source->FailToStartMockedSource(); | 195 video_source->FailToStartMockedSource(); |
193 } | 196 } |
194 | 197 |
195 void FailToCreateNextAudioCapturer() { | 198 void FailToCreateNextAudioCapturer() { |
196 dependency_factory_->FailToCreateNextAudioCapturer(); | 199 dependency_factory_->FailToCreateNextAudioCapturer(); |
197 } | 200 } |
198 | 201 |
199 protected: | 202 protected: |
200 base::MessageLoop message_loop_; | 203 base::MessageLoop message_loop_; |
201 scoped_ptr<ChildProcess> child_process_; | 204 scoped_ptr<ChildProcess> child_process_; |
202 scoped_ptr<MockMediaStreamDispatcher> ms_dispatcher_; | 205 MockMediaStreamDispatcher* ms_dispatcher_; // Owned my |ms_impl_|. |
203 scoped_ptr<MediaStreamImplUnderTest> ms_impl_; | 206 scoped_ptr<MediaStreamImplUnderTest> ms_impl_; |
204 scoped_ptr<MockPeerConnectionDependencyFactory> dependency_factory_; | 207 scoped_ptr<MockPeerConnectionDependencyFactory> dependency_factory_; |
205 }; | 208 }; |
206 | 209 |
207 TEST_F(MediaStreamImplTest, GenerateMediaStream) { | 210 TEST_F(MediaStreamImplTest, GenerateMediaStream) { |
208 // Generate a stream with both audio and video. | 211 // Generate a stream with both audio and video. |
209 blink::WebMediaStream mixed_desc = RequestLocalMediaStream(); | 212 blink::WebMediaStream mixed_desc = RequestLocalMediaStream(); |
210 } | 213 } |
211 | 214 |
212 // Test that the same source object is used if two MediaStreams are generated | 215 // Test that the same source object is used if two MediaStreams are generated |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 RequestLocalMediaStream(); | 325 RequestLocalMediaStream(); |
323 // Makes sure the test itself don't hold a reference to the created | 326 // Makes sure the test itself don't hold a reference to the created |
324 // MediaStream. | 327 // MediaStream. |
325 ms_impl_->ClearLastGeneratedStream(); | 328 ms_impl_->ClearLastGeneratedStream(); |
326 | 329 |
327 // Expect the sources to be stopped when the MediaStream goes out of scope. | 330 // Expect the sources to be stopped when the MediaStream goes out of scope. |
328 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 331 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
329 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 332 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
330 } | 333 } |
331 | 334 |
332 // Test that the MediaStreams are deleted if the owning WebFrame is deleted. | 335 // Test that the MediaStreams are deleted if the owning WebFrame is closing. |
333 // In the unit test the owning frame is NULL. | 336 // In the unit test the owning frame is NULL. |
334 TEST_F(MediaStreamImplTest, FrameWillClose) { | 337 TEST_F(MediaStreamImplTest, FrameWillClose) { |
335 // Test a stream with both audio and video. | 338 // Test a stream with both audio and video. |
336 blink::WebMediaStream mixed_desc = RequestLocalMediaStream(); | 339 blink::WebMediaStream mixed_desc = RequestLocalMediaStream(); |
337 blink::WebMediaStream desc2 = RequestLocalMediaStream(); | 340 blink::WebMediaStream desc2 = RequestLocalMediaStream(); |
338 | 341 ms_impl_->FrameWillClose(); |
339 // Test that the MediaStreams are deleted if the owning WebFrame is deleted. | |
340 // In the unit test the owning frame is NULL. | |
341 ms_impl_->FrameWillClose(NULL); | |
342 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 342 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
343 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 343 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
344 } | 344 } |
345 | 345 |
346 // This test what happens if a video source to a MediaSteam fails to start. | 346 // This test what happens if a video source to a MediaSteam fails to start. |
347 TEST_F(MediaStreamImplTest, MediaVideoSourceFailToStart) { | 347 TEST_F(MediaStreamImplTest, MediaVideoSourceFailToStart) { |
348 ms_impl_->RequestUserMedia(); | 348 ms_impl_->RequestUserMedia(); |
349 FakeMediaStreamDispatcherRequestUserMediaComplete(); | 349 FakeMediaStreamDispatcherRequestUserMediaComplete(); |
350 FailToStartMockedVideoSource(); | 350 FailToStartMockedVideoSource(); |
351 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_FAILED, | 351 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_FAILED, |
(...skipping 28 matching lines...) Expand all Loading... |
380 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); | 380 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); |
381 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE, | 381 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE, |
382 ms_impl_->request_state()); | 382 ms_impl_->request_state()); |
383 ms_impl_.reset(); | 383 ms_impl_.reset(); |
384 } | 384 } |
385 | 385 |
386 // This test what happens if the WebFrame is closed while the MediaStream is | 386 // This test what happens if the WebFrame is closed while the MediaStream is |
387 // being generated by the MediaStreamDispatcher. | 387 // being generated by the MediaStreamDispatcher. |
388 TEST_F(MediaStreamImplTest, ReloadFrameWhileGeneratingStream) { | 388 TEST_F(MediaStreamImplTest, ReloadFrameWhileGeneratingStream) { |
389 ms_impl_->RequestUserMedia(); | 389 ms_impl_->RequestUserMedia(); |
390 ms_impl_->FrameWillClose(NULL); | 390 ms_impl_->FrameWillClose(); |
391 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); | 391 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); |
392 EXPECT_EQ(0, ms_dispatcher_->stop_audio_device_counter()); | 392 EXPECT_EQ(0, ms_dispatcher_->stop_audio_device_counter()); |
393 EXPECT_EQ(0, ms_dispatcher_->stop_video_device_counter()); | 393 EXPECT_EQ(0, ms_dispatcher_->stop_video_device_counter()); |
394 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE, | 394 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE, |
395 ms_impl_->request_state()); | 395 ms_impl_->request_state()); |
396 } | 396 } |
397 | 397 |
398 // This test what happens if the WebFrame is closed while the sources are being | 398 // This test what happens if the WebFrame is closed while the sources are being |
399 // started. | 399 // started. |
400 TEST_F(MediaStreamImplTest, ReloadFrameWhileGeneratingSources) { | 400 TEST_F(MediaStreamImplTest, ReloadFrameWhileGeneratingSources) { |
401 ms_impl_->RequestUserMedia(); | 401 ms_impl_->RequestUserMedia(); |
402 FakeMediaStreamDispatcherRequestUserMediaComplete(); | 402 FakeMediaStreamDispatcherRequestUserMediaComplete(); |
403 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); | 403 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); |
404 ms_impl_->FrameWillClose(NULL); | 404 ms_impl_->FrameWillClose(); |
405 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 405 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
406 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 406 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
407 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE, | 407 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE, |
408 ms_impl_->request_state()); | 408 ms_impl_->request_state()); |
409 } | 409 } |
410 | 410 |
411 // This test what happens if stop is called on a track after the frame has | 411 // This test what happens if stop is called on a track after the frame has |
412 // been reloaded. | 412 // been reloaded. |
413 TEST_F(MediaStreamImplTest, StopTrackAfterReload) { | 413 TEST_F(MediaStreamImplTest, StopTrackAfterReload) { |
414 blink::WebMediaStream mixed_desc = RequestLocalMediaStream(); | 414 blink::WebMediaStream mixed_desc = RequestLocalMediaStream(); |
415 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); | 415 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); |
416 ms_impl_->FrameWillClose(NULL); | 416 ms_impl_->FrameWillClose(); |
417 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 417 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
418 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 418 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
419 | 419 |
420 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; | 420 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; |
421 mixed_desc.audioTracks(audio_tracks); | 421 mixed_desc.audioTracks(audio_tracks); |
422 MediaStreamTrack* audio_track = MediaStreamTrack::GetTrack(audio_tracks[0]); | 422 MediaStreamTrack* audio_track = MediaStreamTrack::GetTrack(audio_tracks[0]); |
423 audio_track->Stop(); | 423 audio_track->Stop(); |
424 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 424 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
425 | 425 |
426 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 426 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 EXPECT_FALSE(ms_impl_->last_devices()[3].groupId().isEmpty()); | 466 EXPECT_FALSE(ms_impl_->last_devices()[3].groupId().isEmpty()); |
467 | 467 |
468 // Verfify group IDs. | 468 // Verfify group IDs. |
469 EXPECT_TRUE(ms_impl_->last_devices()[0].groupId().equals( | 469 EXPECT_TRUE(ms_impl_->last_devices()[0].groupId().equals( |
470 ms_impl_->last_devices()[3].groupId())); | 470 ms_impl_->last_devices()[3].groupId())); |
471 EXPECT_FALSE(ms_impl_->last_devices()[1].groupId().equals( | 471 EXPECT_FALSE(ms_impl_->last_devices()[1].groupId().equals( |
472 ms_impl_->last_devices()[3].groupId())); | 472 ms_impl_->last_devices()[3].groupId())); |
473 } | 473 } |
474 | 474 |
475 } // namespace content | 475 } // namespace content |
OLD | NEW |