Chromium Code Reviews| 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 ? | |
|
perkj_chrome
2014/03/07 12:46:22
Please use parentheses and fix the indentation.
Tommy Widenflycht
2014/03/07 14:37:09
Done.
| |
| 63 REQUEST_SUCCEEDED : REQUEST_FAILED; | |
| 62 } | 64 } |
| 63 | 65 |
| 64 virtual blink::WebMediaStream GetMediaStream( | 66 virtual blink::WebMediaStream GetMediaStream( |
| 65 const GURL& url) OVERRIDE { | 67 const GURL& url) OVERRIDE { |
| 66 return last_generated_stream_; | 68 return last_generated_stream_; |
| 67 } | 69 } |
| 68 | 70 |
| 69 virtual MediaStreamVideoSource* CreateVideoSource( | 71 virtual MediaStreamVideoSource* CreateVideoSource( |
| 70 const StreamDeviceInfo& device, | 72 const StreamDeviceInfo& device, |
| 71 const MediaStreamSource::SourceStoppedCallback& stop_callback) OVERRIDE { | 73 const MediaStreamSource::SourceStoppedCallback& stop_callback) OVERRIDE { |
| 72 video_source_ = new MockMediaStreamVideoCapturerSource(device, | 74 video_source_ = new MockMediaStreamVideoCapturerSource(device, |
| 73 stop_callback, | 75 stop_callback, |
| 74 factory_); | 76 factory_); |
| 75 return video_source_; | 77 return video_source_; |
| 76 } | 78 } |
| 77 | 79 |
| 78 using MediaStreamImpl::OnLocalMediaStreamStop; | 80 using MediaStreamImpl::OnLocalMediaStreamStop; |
| 79 using MediaStreamImpl::OnLocalSourceStopped; | 81 using MediaStreamImpl::OnLocalSourceStopped; |
| 80 | 82 |
| 81 const blink::WebMediaStream& last_generated_stream() { | 83 const blink::WebMediaStream& last_generated_stream() { |
| 82 return last_generated_stream_; | 84 return last_generated_stream_; |
| 83 } | 85 } |
| 84 | 86 |
| 85 MockMediaStreamVideoCapturerSource* last_created_video_source() const { | 87 MockMediaStreamVideoCapturerSource* last_created_video_source() const { |
| 86 return video_source_; | 88 return video_source_; |
| 87 } | 89 } |
| 88 | 90 |
| 89 RequestState request_state() const { return state_; } | 91 RequestState request_state() const { return state_; } |
| 92 content::MediaStreamRequestResult error_reason() const { return result_; } | |
| 90 | 93 |
| 91 private: | 94 private: |
| 92 blink::WebMediaStream last_generated_stream_; | 95 blink::WebMediaStream last_generated_stream_; |
| 93 RequestState state_; | 96 RequestState state_; |
| 97 content::MediaStreamRequestResult result_; | |
| 94 MediaStreamDependencyFactory* factory_; | 98 MediaStreamDependencyFactory* factory_; |
| 95 MockMediaStreamVideoCapturerSource* video_source_; | 99 MockMediaStreamVideoCapturerSource* video_source_; |
| 96 }; | 100 }; |
| 97 | 101 |
| 98 class MediaStreamImplTest : public ::testing::Test { | 102 class MediaStreamImplTest : public ::testing::Test { |
| 99 public: | 103 public: |
| 100 virtual void SetUp() { | 104 virtual void SetUp() { |
| 101 // Create our test object. | 105 // Create our test object. |
| 102 ms_dispatcher_.reset(new MockMediaStreamDispatcher()); | 106 ms_dispatcher_.reset(new MockMediaStreamDispatcher()); |
| 103 dependency_factory_.reset(new MockMediaStreamDependencyFactory()); | 107 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()); | 287 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 284 } | 288 } |
| 285 | 289 |
| 286 // This test what happens if a source to a MediaSteam fails to start. | 290 // This test what happens if a source to a MediaSteam fails to start. |
| 287 TEST_F(MediaStreamImplTest, MediaSourceFailToStart) { | 291 TEST_F(MediaStreamImplTest, MediaSourceFailToStart) { |
| 288 ms_impl_->RequestUserMedia(); | 292 ms_impl_->RequestUserMedia(); |
| 289 FakeMediaStreamDispatcherComplete(); | 293 FakeMediaStreamDispatcherComplete(); |
| 290 FailToStartMockedVideoSource(); | 294 FailToStartMockedVideoSource(); |
| 291 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_FAILED, | 295 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_FAILED, |
| 292 ms_impl_->request_state()); | 296 ms_impl_->request_state()); |
| 297 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, | |
| 298 ms_impl_->error_reason()); | |
| 293 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); | 299 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); |
| 294 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 300 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
| 295 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 301 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 296 } | 302 } |
| 297 | 303 |
| 298 // This test what happens if MediaStreamImpl is deleted while the sources of a | 304 // This test what happens if MediaStreamImpl is deleted while the sources of a |
| 299 // MediaStream is being started. | 305 // MediaStream is being started. |
| 300 TEST_F(MediaStreamImplTest, MediaStreamImplShutDown) { | 306 TEST_F(MediaStreamImplTest, MediaStreamImplShutDown) { |
| 301 ms_impl_->RequestUserMedia(); | 307 ms_impl_->RequestUserMedia(); |
| 302 FakeMediaStreamDispatcherComplete(); | 308 FakeMediaStreamDispatcherComplete(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); | 351 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); |
| 346 ms_impl_->FrameWillClose(NULL); | 352 ms_impl_->FrameWillClose(NULL); |
| 347 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 353 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
| 348 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 354 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 349 ms_impl_->OnLocalMediaStreamStop(mixed_desc.id().utf8()); | 355 ms_impl_->OnLocalMediaStreamStop(mixed_desc.id().utf8()); |
| 350 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 356 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
| 351 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 357 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 352 } | 358 } |
| 353 | 359 |
| 354 } // namespace content | 360 } // namespace content |
| OLD | NEW |