| 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 "content/common/media/media_stream_options.h" | 6 #include "content/common/media/media_stream_options.h" |
| 7 #include "content/renderer/media/media_stream_extra_data.h" | 7 #include "content/renderer/media/media_stream_extra_data.h" |
| 8 #include "content/renderer/media/media_stream_source_extra_data.h" | 8 #include "content/renderer/media/media_stream_source_extra_data.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_web_rtc_peer_connection_handler_client.h" | 10 #include "content/renderer/media/mock_web_rtc_peer_connection_handler_client.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/libjingle/source/talk/app/webrtc/videosourceinterface.h" | |
| 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints
.h" | 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints
.h" |
| 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamCompo
nent.h" | 13 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStream.h" |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamDescr
iptor.h" | |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSourc
e.h" | 14 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSourc
e.h" |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack
.h" |
| 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCPeerConnectio
nHandler.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCPeerConnectio
nHandler.h" |
| 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" |
| 18 #include "third_party/libjingle/source/talk/app/webrtc/videosourceinterface.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 class MediaSourceCreatedObserver { | 22 class MediaSourceCreatedObserver { |
| 23 public: | 23 public: |
| 24 MediaSourceCreatedObserver() | 24 MediaSourceCreatedObserver() |
| 25 : result_(false), | 25 : result_(false), |
| 26 description_(NULL) { | 26 description_(NULL) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 void OnCreateNativeSourcesComplete( | 29 void OnCreateNativeSourcesComplete( |
| 30 WebKit::WebMediaStreamDescriptor* description, | 30 WebKit::WebMediaStream* description, |
| 31 bool request_succeeded) { | 31 bool request_succeeded) { |
| 32 result_ = request_succeeded; | 32 result_ = request_succeeded; |
| 33 description_ = description; | 33 description_ = description; |
| 34 } | 34 } |
| 35 | 35 |
| 36 WebKit::WebMediaStreamDescriptor* description() const { | 36 WebKit::WebMediaStream* description() const { |
| 37 return description_; | 37 return description_; |
| 38 } | 38 } |
| 39 bool result() const { return result_; } | 39 bool result() const { return result_; } |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 bool result_; | 42 bool result_; |
| 43 WebKit::WebMediaStreamDescriptor* description_; | 43 WebKit::WebMediaStream* description_; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class MediaStreamDependencyFactoryTest : public ::testing::Test { | 46 class MediaStreamDependencyFactoryTest : public ::testing::Test { |
| 47 public: | 47 public: |
| 48 void SetUp() { | 48 void SetUp() { |
| 49 dependency_factory_.reset(new MockMediaStreamDependencyFactory()); | 49 dependency_factory_.reset(new MockMediaStreamDependencyFactory()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 WebKit::WebMediaStreamDescriptor CreateWebKitMediaStream(bool audio, | 52 WebKit::WebMediaStream CreateWebKitMediaStream(bool audio, |
| 53 bool video) { | 53 bool video) { |
| 54 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources( | 54 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources( |
| 55 audio ? static_cast<size_t>(1) : 0); | 55 audio ? static_cast<size_t>(1) : 0); |
| 56 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources( | 56 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources( |
| 57 video ? static_cast<size_t>(1) : 0); | 57 video ? static_cast<size_t>(1) : 0); |
| 58 | 58 |
| 59 if (audio) { | 59 if (audio) { |
| 60 StreamDeviceInfo info; | 60 StreamDeviceInfo info; |
| 61 info.device.type = content::MEDIA_DEVICE_AUDIO_CAPTURE; | 61 info.device.type = content::MEDIA_DEVICE_AUDIO_CAPTURE; |
| 62 info.device.name = "audio"; | 62 info.device.name = "audio"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 73 StreamDeviceInfo info; | 73 StreamDeviceInfo info; |
| 74 info.device.type = content::MEDIA_DEVICE_VIDEO_CAPTURE; | 74 info.device.type = content::MEDIA_DEVICE_VIDEO_CAPTURE; |
| 75 info.device.name = "video"; | 75 info.device.name = "video"; |
| 76 info.session_id = 98; | 76 info.session_id = 98; |
| 77 video_sources[0].initialize("video", | 77 video_sources[0].initialize("video", |
| 78 WebKit::WebMediaStreamSource::TypeVideo, | 78 WebKit::WebMediaStreamSource::TypeVideo, |
| 79 "video"); | 79 "video"); |
| 80 video_sources[0].setExtraData( | 80 video_sources[0].setExtraData( |
| 81 new MediaStreamSourceExtraData(info)); | 81 new MediaStreamSourceExtraData(info)); |
| 82 } | 82 } |
| 83 WebKit::WebMediaStreamDescriptor stream_desc; | 83 WebKit::WebMediaStream stream_desc; |
| 84 stream_desc.initialize("media stream", audio_sources, video_sources); | 84 stream_desc.initialize("media stream", audio_sources, video_sources); |
| 85 | 85 |
| 86 return stream_desc; | 86 return stream_desc; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void CreateNativeSources(WebKit::WebMediaStreamDescriptor* descriptor) { | 89 void CreateNativeSources(WebKit::WebMediaStream* descriptor) { |
| 90 MediaSourceCreatedObserver observer; | 90 MediaSourceCreatedObserver observer; |
| 91 WebKit::WebMediaConstraints audio_constraints; | 91 WebKit::WebMediaConstraints audio_constraints; |
| 92 dependency_factory_->CreateNativeMediaSources( | 92 dependency_factory_->CreateNativeMediaSources( |
| 93 WebKit::WebMediaConstraints(), | 93 WebKit::WebMediaConstraints(), |
| 94 WebKit::WebMediaConstraints(), | 94 WebKit::WebMediaConstraints(), |
| 95 descriptor, | 95 descriptor, |
| 96 base::Bind( | 96 base::Bind( |
| 97 &MediaSourceCreatedObserver::OnCreateNativeSourcesComplete, | 97 &MediaSourceCreatedObserver::OnCreateNativeSourcesComplete, |
| 98 base::Unretained(&observer))); | 98 base::Unretained(&observer))); |
| 99 | 99 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 TEST_F(MediaStreamDependencyFactoryTest, CreateRTCPeerConnectionHandler) { | 115 TEST_F(MediaStreamDependencyFactoryTest, CreateRTCPeerConnectionHandler) { |
| 116 MockWebRTCPeerConnectionHandlerClient client_jsep; | 116 MockWebRTCPeerConnectionHandlerClient client_jsep; |
| 117 scoped_ptr<WebKit::WebRTCPeerConnectionHandler> pc_handler( | 117 scoped_ptr<WebKit::WebRTCPeerConnectionHandler> pc_handler( |
| 118 dependency_factory_->CreateRTCPeerConnectionHandler(&client_jsep)); | 118 dependency_factory_->CreateRTCPeerConnectionHandler(&client_jsep)); |
| 119 EXPECT_TRUE(pc_handler.get() != NULL); | 119 EXPECT_TRUE(pc_handler.get() != NULL); |
| 120 } | 120 } |
| 121 | 121 |
| 122 TEST_F(MediaStreamDependencyFactoryTest, CreateNativeMediaStream) { | 122 TEST_F(MediaStreamDependencyFactoryTest, CreateNativeMediaStream) { |
| 123 WebKit::WebMediaStreamDescriptor stream_desc = CreateWebKitMediaStream(true, | 123 WebKit::WebMediaStream stream_desc = CreateWebKitMediaStream(true, true); |
| 124 true); | |
| 125 CreateNativeSources(&stream_desc); | 124 CreateNativeSources(&stream_desc); |
| 126 | 125 |
| 127 dependency_factory_->CreateNativeLocalMediaStream(&stream_desc); | 126 dependency_factory_->CreateNativeLocalMediaStream(&stream_desc); |
| 128 | 127 |
| 129 content::MediaStreamExtraData* extra_data = | 128 content::MediaStreamExtraData* extra_data = |
| 130 static_cast<content::MediaStreamExtraData*>(stream_desc.extraData()); | 129 static_cast<content::MediaStreamExtraData*>(stream_desc.extraData()); |
| 131 ASSERT_TRUE(extra_data && extra_data->local_stream()); | 130 ASSERT_TRUE(extra_data && extra_data->local_stream()); |
| 132 EXPECT_EQ(1u, extra_data->local_stream()->audio_tracks()->count()); | 131 EXPECT_EQ(1u, extra_data->local_stream()->audio_tracks()->count()); |
| 133 EXPECT_EQ(1u, extra_data->local_stream()->video_tracks()->count()); | 132 EXPECT_EQ(1u, extra_data->local_stream()->video_tracks()->count()); |
| 134 } | 133 } |
| 135 | 134 |
| 136 // Test that we don't crash if a MediaStream is created in WebKit with unknown | 135 // Test that we don't crash if a MediaStream is created in WebKit with unknown |
| 137 // sources. This can for example happen if a MediaStream is created with | 136 // sources. This can for example happen if a MediaStream is created with |
| 138 // remote tracks. | 137 // remote tracks. |
| 139 TEST_F(MediaStreamDependencyFactoryTest, CreateNativeMediaStreamWithoutSource) { | 138 TEST_F(MediaStreamDependencyFactoryTest, CreateNativeMediaStreamWithoutSource) { |
| 140 // Create a WebKit MediaStream description. | 139 // Create a WebKit MediaStream description. |
| 141 WebKit::WebMediaStreamDescriptor stream_desc; | 140 WebKit::WebMediaStream stream_desc; |
| 142 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources( | 141 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources( |
| 143 static_cast<size_t>(1)); | 142 static_cast<size_t>(1)); |
| 144 audio_sources[0].initialize("audio source", | 143 audio_sources[0].initialize("audio source", |
| 145 WebKit::WebMediaStreamSource::TypeAudio, | 144 WebKit::WebMediaStreamSource::TypeAudio, |
| 146 "something"); | 145 "something"); |
| 147 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources( | 146 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources( |
| 148 static_cast<size_t>(1)); | 147 static_cast<size_t>(1)); |
| 149 video_sources[0].initialize("video source", | 148 video_sources[0].initialize("video source", |
| 150 WebKit::WebMediaStreamSource::TypeVideo, | 149 WebKit::WebMediaStreamSource::TypeVideo, |
| 151 "something"); | 150 "something"); |
| 152 stream_desc.initialize("new stream", audio_sources, video_sources); | 151 stream_desc.initialize("new stream", audio_sources, video_sources); |
| 153 | 152 |
| 154 EXPECT_TRUE(dependency_factory_->EnsurePeerConnectionFactory()); | 153 EXPECT_TRUE(dependency_factory_->EnsurePeerConnectionFactory()); |
| 155 dependency_factory_->CreateNativeLocalMediaStream(&stream_desc); | 154 dependency_factory_->CreateNativeLocalMediaStream(&stream_desc); |
| 156 MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>( | 155 MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>( |
| 157 stream_desc.extraData()); | 156 stream_desc.extraData()); |
| 158 ASSERT_TRUE(extra_data && extra_data->local_stream()); | 157 ASSERT_TRUE(extra_data && extra_data->local_stream()); |
| 159 EXPECT_EQ(0u, extra_data->local_stream()->video_tracks()->count()); | 158 EXPECT_EQ(0u, extra_data->local_stream()->video_tracks()->count()); |
| 160 EXPECT_EQ(0u, extra_data->local_stream()->audio_tracks()->count()); | 159 EXPECT_EQ(0u, extra_data->local_stream()->audio_tracks()->count()); |
| 161 } | 160 } |
| 162 | 161 |
| 163 } // namespace content | 162 } // namespace content |
| OLD | NEW |