| 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" |
| 11 #include "content/renderer/media/media_stream_track.h" | 11 #include "content/renderer/media/media_stream_track.h" |
| 12 #include "content/renderer/media/mock_media_stream_dependency_factory.h" | |
| 13 #include "content/renderer/media/mock_media_stream_dispatcher.h" | 12 #include "content/renderer/media/mock_media_stream_dispatcher.h" |
| 14 #include "content/renderer/media/mock_media_stream_video_source.h" | 13 #include "content/renderer/media/mock_media_stream_video_source.h" |
| 14 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 16 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 17 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 17 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 19 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
| 20 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 class MockMediaStreamVideoCapturerSource : public MockMediaStreamVideoSource { | 24 class MockMediaStreamVideoCapturerSource : public MockMediaStreamVideoSource { |
| 25 public: | 25 public: |
| 26 MockMediaStreamVideoCapturerSource( | 26 MockMediaStreamVideoCapturerSource( |
| 27 const StreamDeviceInfo& device, | 27 const StreamDeviceInfo& device, |
| 28 const SourceStoppedCallback& stop_callback, | 28 const SourceStoppedCallback& stop_callback, |
| 29 MediaStreamDependencyFactory* factory) | 29 PeerConnectionDependencyFactory* factory) |
| 30 : MockMediaStreamVideoSource(false) { | 30 : MockMediaStreamVideoSource(false) { |
| 31 SetDeviceInfo(device); | 31 SetDeviceInfo(device); |
| 32 SetStopCallback(stop_callback); | 32 SetStopCallback(stop_callback); |
| 33 } | 33 } |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 class MediaStreamImplUnderTest : public MediaStreamImpl { | 36 class MediaStreamImplUnderTest : public MediaStreamImpl { |
| 37 public: | 37 public: |
| 38 enum RequestState { | 38 enum RequestState { |
| 39 REQUEST_NOT_STARTED, | 39 REQUEST_NOT_STARTED, |
| 40 REQUEST_NOT_COMPLETE, | 40 REQUEST_NOT_COMPLETE, |
| 41 REQUEST_SUCCEEDED, | 41 REQUEST_SUCCEEDED, |
| 42 REQUEST_FAILED, | 42 REQUEST_FAILED, |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 MediaStreamImplUnderTest(MediaStreamDispatcher* media_stream_dispatcher, | 45 MediaStreamImplUnderTest(MediaStreamDispatcher* media_stream_dispatcher, |
| 46 MediaStreamDependencyFactory* dependency_factory) | 46 PeerConnectionDependencyFactory* dependency_factory) |
| 47 : MediaStreamImpl(NULL, media_stream_dispatcher, dependency_factory), | 47 : MediaStreamImpl(NULL, media_stream_dispatcher, dependency_factory), |
| 48 state_(REQUEST_NOT_STARTED), | 48 state_(REQUEST_NOT_STARTED), |
| 49 result_(NUM_MEDIA_REQUEST_RESULTS), | 49 result_(NUM_MEDIA_REQUEST_RESULTS), |
| 50 factory_(dependency_factory), | 50 factory_(dependency_factory), |
| 51 video_source_(NULL) { | 51 video_source_(NULL) { |
| 52 } | 52 } |
| 53 | 53 |
| 54 void RequestUserMedia() { | 54 void RequestUserMedia() { |
| 55 blink::WebUserMediaRequest user_media_request; | 55 blink::WebUserMediaRequest user_media_request; |
| 56 state_ = REQUEST_NOT_COMPLETE; | 56 state_ = REQUEST_NOT_COMPLETE; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 return video_source_; | 93 return video_source_; |
| 94 } | 94 } |
| 95 | 95 |
| 96 RequestState request_state() const { return state_; } | 96 RequestState request_state() const { return state_; } |
| 97 content::MediaStreamRequestResult error_reason() const { return result_; } | 97 content::MediaStreamRequestResult error_reason() const { return result_; } |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 blink::WebMediaStream last_generated_stream_; | 100 blink::WebMediaStream last_generated_stream_; |
| 101 RequestState state_; | 101 RequestState state_; |
| 102 content::MediaStreamRequestResult result_; | 102 content::MediaStreamRequestResult result_; |
| 103 MediaStreamDependencyFactory* factory_; | 103 PeerConnectionDependencyFactory* factory_; |
| 104 MockMediaStreamVideoCapturerSource* video_source_; | 104 MockMediaStreamVideoCapturerSource* video_source_; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 class MediaStreamImplTest : public ::testing::Test { | 107 class MediaStreamImplTest : public ::testing::Test { |
| 108 public: | 108 public: |
| 109 virtual void SetUp() { | 109 virtual void SetUp() { |
| 110 // Create our test object. | 110 // Create our test object. |
| 111 child_process_.reset(new ChildProcess()); | 111 child_process_.reset(new ChildProcess()); |
| 112 ms_dispatcher_.reset(new MockMediaStreamDispatcher()); | 112 ms_dispatcher_.reset(new MockMediaStreamDispatcher()); |
| 113 dependency_factory_.reset(new MockMediaStreamDependencyFactory()); | 113 dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); |
| 114 ms_impl_.reset(new MediaStreamImplUnderTest(ms_dispatcher_.get(), | 114 ms_impl_.reset(new MediaStreamImplUnderTest(ms_dispatcher_.get(), |
| 115 dependency_factory_.get())); | 115 dependency_factory_.get())); |
| 116 } | 116 } |
| 117 | 117 |
| 118 blink::WebMediaStream RequestLocalMediaStream() { | 118 blink::WebMediaStream RequestLocalMediaStream() { |
| 119 ms_impl_->RequestUserMedia(); | 119 ms_impl_->RequestUserMedia(); |
| 120 FakeMediaStreamDispatcherComplete(); | 120 FakeMediaStreamDispatcherComplete(); |
| 121 StartMockedVideoSource(); | 121 StartMockedVideoSource(); |
| 122 | 122 |
| 123 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_SUCCEEDED, | 123 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_SUCCEEDED, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 void FailToCreateNextAudioCapturer() { | 166 void FailToCreateNextAudioCapturer() { |
| 167 dependency_factory_->FailToCreateNextAudioCapturer(); | 167 dependency_factory_->FailToCreateNextAudioCapturer(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 protected: | 170 protected: |
| 171 base::MessageLoop message_loop_; | 171 base::MessageLoop message_loop_; |
| 172 scoped_ptr<ChildProcess> child_process_; | 172 scoped_ptr<ChildProcess> child_process_; |
| 173 scoped_ptr<MockMediaStreamDispatcher> ms_dispatcher_; | 173 scoped_ptr<MockMediaStreamDispatcher> ms_dispatcher_; |
| 174 scoped_ptr<MediaStreamImplUnderTest> ms_impl_; | 174 scoped_ptr<MediaStreamImplUnderTest> ms_impl_; |
| 175 scoped_ptr<MockMediaStreamDependencyFactory> dependency_factory_; | 175 scoped_ptr<MockPeerConnectionDependencyFactory> dependency_factory_; |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 TEST_F(MediaStreamImplTest, GenerateMediaStream) { | 178 TEST_F(MediaStreamImplTest, GenerateMediaStream) { |
| 179 // Generate a stream with both audio and video. | 179 // Generate a stream with both audio and video. |
| 180 blink::WebMediaStream mixed_desc = RequestLocalMediaStream(); | 180 blink::WebMediaStream mixed_desc = RequestLocalMediaStream(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 // Test that the same source object is used if two MediaStreams are generated | 183 // Test that the same source object is used if two MediaStreams are generated |
| 184 // using the same source. | 184 // using the same source. |
| 185 TEST_F(MediaStreamImplTest, GenerateTwoMediaStreamsWithSameSource) { | 185 TEST_F(MediaStreamImplTest, GenerateTwoMediaStreamsWithSameSource) { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); | 395 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); |
| 396 | 396 |
| 397 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; | 397 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; |
| 398 mixed_desc.videoTracks(video_tracks); | 398 mixed_desc.videoTracks(video_tracks); |
| 399 MediaStreamTrack* video_track = MediaStreamTrack::GetTrack(video_tracks[0]); | 399 MediaStreamTrack* video_track = MediaStreamTrack::GetTrack(video_tracks[0]); |
| 400 video_track->Stop(); | 400 video_track->Stop(); |
| 401 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); | 401 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); |
| 402 } | 402 } |
| 403 | 403 |
| 404 } // namespace content | 404 } // namespace content |
| OLD | NEW |