| 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/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "content/renderer/media/media_stream.h" | 7 #include "content/renderer/media/media_stream.h" |
| 8 #include "content/renderer/media/media_stream_impl.h" | 8 #include "content/renderer/media/media_stream_impl.h" |
| 9 #include "content/renderer/media/mock_media_stream_dependency_factory.h" | 9 #include "content/renderer/media/mock_media_stream_dependency_factory.h" |
| 10 #include "content/renderer/media/mock_media_stream_dispatcher.h" | 10 #include "content/renderer/media/mock_media_stream_dispatcher.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 void RequestUserMedia() { | 50 void RequestUserMedia() { |
| 51 blink::WebUserMediaRequest user_media_request; | 51 blink::WebUserMediaRequest user_media_request; |
| 52 state_ = REQUEST_NOT_COMPLETE; | 52 state_ = REQUEST_NOT_COMPLETE; |
| 53 requestUserMedia(user_media_request); | 53 requestUserMedia(user_media_request); |
| 54 } | 54 } |
| 55 | 55 |
| 56 virtual void CompleteGetUserMediaRequest( | 56 virtual void CompleteGetUserMediaRequest( |
| 57 const blink::WebMediaStream& stream, | 57 const blink::WebMediaStream& stream, |
| 58 blink::WebUserMediaRequest* request_info, | 58 blink::WebUserMediaRequest* request_info, |
| 59 bool request_succeeded) OVERRIDE { | 59 content::MediaStreamRequestResult result) OVERRIDE { |
| 60 last_generated_stream_ = stream; | 60 last_generated_stream_ = stream; |
| 61 state_ = request_succeeded ? REQUEST_SUCCEEDED : REQUEST_FAILED; | 61 result_ = result; |
| 62 state_ = (result == MEDIA_DEVICE_OK ? REQUEST_SUCCEEDED : REQUEST_FAILED); |
| 62 } | 63 } |
| 63 | 64 |
| 64 virtual blink::WebMediaStream GetMediaStream( | 65 virtual blink::WebMediaStream GetMediaStream( |
| 65 const GURL& url) OVERRIDE { | 66 const GURL& url) OVERRIDE { |
| 66 return last_generated_stream_; | 67 return last_generated_stream_; |
| 67 } | 68 } |
| 68 | 69 |
| 69 virtual MediaStreamVideoSource* CreateVideoSource( | 70 virtual MediaStreamVideoSource* CreateVideoSource( |
| 70 const StreamDeviceInfo& device, | 71 const StreamDeviceInfo& device, |
| 71 const MediaStreamSource::SourceStoppedCallback& stop_callback) OVERRIDE { | 72 const MediaStreamSource::SourceStoppedCallback& stop_callback) OVERRIDE { |
| 72 video_source_ = new MockMediaStreamVideoCapturerSource(device, | 73 video_source_ = new MockMediaStreamVideoCapturerSource(device, |
| 73 stop_callback, | 74 stop_callback, |
| 74 factory_); | 75 factory_); |
| 75 return video_source_; | 76 return video_source_; |
| 76 } | 77 } |
| 77 | 78 |
| 78 using MediaStreamImpl::OnLocalMediaStreamStop; | 79 using MediaStreamImpl::OnLocalMediaStreamStop; |
| 79 using MediaStreamImpl::OnLocalSourceStopped; | 80 using MediaStreamImpl::OnLocalSourceStopped; |
| 80 | 81 |
| 81 const blink::WebMediaStream& last_generated_stream() { | 82 const blink::WebMediaStream& last_generated_stream() { |
| 82 return last_generated_stream_; | 83 return last_generated_stream_; |
| 83 } | 84 } |
| 84 | 85 |
| 85 MockMediaStreamVideoCapturerSource* last_created_video_source() const { | 86 MockMediaStreamVideoCapturerSource* last_created_video_source() const { |
| 86 return video_source_; | 87 return video_source_; |
| 87 } | 88 } |
| 88 | 89 |
| 89 RequestState request_state() const { return state_; } | 90 RequestState request_state() const { return state_; } |
| 91 content::MediaStreamRequestResult error_reason() const { return result_; } |
| 90 | 92 |
| 91 private: | 93 private: |
| 92 blink::WebMediaStream last_generated_stream_; | 94 blink::WebMediaStream last_generated_stream_; |
| 93 RequestState state_; | 95 RequestState state_; |
| 96 content::MediaStreamRequestResult result_; |
| 94 MediaStreamDependencyFactory* factory_; | 97 MediaStreamDependencyFactory* factory_; |
| 95 MockMediaStreamVideoCapturerSource* video_source_; | 98 MockMediaStreamVideoCapturerSource* video_source_; |
| 96 }; | 99 }; |
| 97 | 100 |
| 98 class MediaStreamImplTest : public ::testing::Test { | 101 class MediaStreamImplTest : public ::testing::Test { |
| 99 public: | 102 public: |
| 100 virtual void SetUp() { | 103 virtual void SetUp() { |
| 101 // Create our test object. | 104 // Create our test object. |
| 102 ms_dispatcher_.reset(new MockMediaStreamDispatcher()); | 105 ms_dispatcher_.reset(new MockMediaStreamDispatcher()); |
| 103 dependency_factory_.reset(new MockMediaStreamDependencyFactory()); | 106 dependency_factory_.reset(new MockMediaStreamDependencyFactory()); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 286 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 284 } | 287 } |
| 285 | 288 |
| 286 // This test what happens if a source to a MediaSteam fails to start. | 289 // This test what happens if a source to a MediaSteam fails to start. |
| 287 TEST_F(MediaStreamImplTest, MediaSourceFailToStart) { | 290 TEST_F(MediaStreamImplTest, MediaSourceFailToStart) { |
| 288 ms_impl_->RequestUserMedia(); | 291 ms_impl_->RequestUserMedia(); |
| 289 FakeMediaStreamDispatcherComplete(); | 292 FakeMediaStreamDispatcherComplete(); |
| 290 FailToStartMockedVideoSource(); | 293 FailToStartMockedVideoSource(); |
| 291 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_FAILED, | 294 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_FAILED, |
| 292 ms_impl_->request_state()); | 295 ms_impl_->request_state()); |
| 296 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, |
| 297 ms_impl_->error_reason()); |
| 293 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); | 298 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); |
| 294 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 299 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
| 295 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 300 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 296 } | 301 } |
| 297 | 302 |
| 298 // This test what happens if MediaStreamImpl is deleted while the sources of a | 303 // This test what happens if MediaStreamImpl is deleted while the sources of a |
| 299 // MediaStream is being started. | 304 // MediaStream is being started. |
| 300 TEST_F(MediaStreamImplTest, MediaStreamImplShutDown) { | 305 TEST_F(MediaStreamImplTest, MediaStreamImplShutDown) { |
| 301 ms_impl_->RequestUserMedia(); | 306 ms_impl_->RequestUserMedia(); |
| 302 FakeMediaStreamDispatcherComplete(); | 307 FakeMediaStreamDispatcherComplete(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); | 350 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); |
| 346 ms_impl_->FrameWillClose(NULL); | 351 ms_impl_->FrameWillClose(NULL); |
| 347 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 352 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
| 348 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 353 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 349 ms_impl_->OnLocalMediaStreamStop(mixed_desc.id().utf8()); | 354 ms_impl_->OnLocalMediaStreamStop(mixed_desc.id().utf8()); |
| 350 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 355 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
| 351 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 356 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 352 } | 357 } |
| 353 | 358 |
| 354 } // namespace content | 359 } // namespace content |
| OLD | NEW |