Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(900)

Side by Side Diff: content/renderer/media/media_stream_impl_unittest.cc

Issue 10919122: Move creation of PeerConnection from the RenderView to the RenderThreadImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding missing files content/renderer/media/webrtc_uma_histograms.h Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h" 6 #include "base/message_loop.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "content/renderer/media/media_stream_extra_data.h"
8 #include "content/renderer/media/media_stream_impl.h" 9 #include "content/renderer/media/media_stream_impl.h"
9 #include "content/renderer/media/mock_media_stream_dependency_factory.h" 10 #include "content/renderer/media/mock_media_stream_dependency_factory.h"
10 #include "content/renderer/media/mock_media_stream_dispatcher.h" 11 #include "content/renderer/media/mock_media_stream_dispatcher.h"
11 #include "content/renderer/media/mock_web_peer_connection_00_handler_client.h"
12 #include "content/renderer/media/mock_web_peer_connection_handler_client.h"
13 #include "content/renderer/media/peer_connection_handler_jsep.h"
14 #include "content/renderer/media/video_capture_impl_manager.h" 12 #include "content/renderer/media/video_capture_impl_manager.h"
15 #include "content/renderer/p2p/socket_dispatcher.h" 13 #include "media/base/video_decoder.h"
16 #include "media/base/message_loop_factory.h" 14 #include "media/base/message_loop_factory.h"
17 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amComponent.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amComponent.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amDescriptor.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebMediaStre amSource.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConne ction00Handler.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPeerConne ctionHandler.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
23 20
24 class MediaStreamImplUnderTest : public MediaStreamImpl { 21 class MediaStreamImplUnderTest : public MediaStreamImpl {
25 public: 22 public:
26 MediaStreamImplUnderTest(MediaStreamDispatcher* media_stream_dispatcher, 23 MediaStreamImplUnderTest(MediaStreamDispatcher* media_stream_dispatcher,
27 content::P2PSocketDispatcher* p2p_socket_dispatcher,
28 VideoCaptureImplManager* vc_manager, 24 VideoCaptureImplManager* vc_manager,
29 MediaStreamDependencyFactory* dependency_factory) 25 MediaStreamDependencyFactory* dependency_factory)
30 : MediaStreamImpl(NULL, media_stream_dispatcher, p2p_socket_dispatcher, 26 : MediaStreamImpl(NULL, media_stream_dispatcher, vc_manager,
31 vc_manager, dependency_factory) { 27 dependency_factory) {
32 } 28 }
33 29
34 virtual void CompleteGetUserMediaRequest( 30 virtual void CompleteGetUserMediaRequest(
35 const WebKit::WebMediaStreamDescriptor& stream, 31 const WebKit::WebMediaStreamDescriptor& stream,
36 WebKit::WebUserMediaRequest* request) { 32 WebKit::WebUserMediaRequest* request) {
37 last_generated_stream_ = stream; 33 last_generated_stream_ = stream;
38 } 34 }
39 35
40 virtual WebKit::WebMediaStreamDescriptor GetMediaStream(const GURL& url) { 36 virtual WebKit::WebMediaStreamDescriptor GetMediaStream(const GURL& url) {
41 return last_generated_stream_; 37 return last_generated_stream_;
42 } 38 }
43 39
44 const WebKit::WebMediaStreamDescriptor& last_generated_stream() { 40 const WebKit::WebMediaStreamDescriptor& last_generated_stream() {
45 return last_generated_stream_; 41 return last_generated_stream_;
46 } 42 }
47 43
48 private: 44 private:
49 WebKit::WebMediaStreamDescriptor last_generated_stream_; 45 WebKit::WebMediaStreamDescriptor last_generated_stream_;
50 }; 46 };
51 47
52 class MediaStreamImplTest : public ::testing::Test { 48 class MediaStreamImplTest : public ::testing::Test {
53 public: 49 public:
54 void SetUp() { 50 void SetUp() {
55 // Create our test object. 51 // Create our test object.
56 ms_dispatcher_.reset(new MockMediaStreamDispatcher()); 52 ms_dispatcher_.reset(new MockMediaStreamDispatcher());
57 p2p_socket_dispatcher_ = new content::P2PSocketDispatcher(
58 loop_.message_loop_proxy());
59 scoped_refptr<VideoCaptureImplManager> vc_manager( 53 scoped_refptr<VideoCaptureImplManager> vc_manager(
60 new VideoCaptureImplManager()); 54 new VideoCaptureImplManager());
61 MockMediaStreamDependencyFactory* dependency_factory = 55 dependency_factory_.reset(new MockMediaStreamDependencyFactory());
62 new MockMediaStreamDependencyFactory(vc_manager);
63 ms_impl_.reset(new MediaStreamImplUnderTest(ms_dispatcher_.get(), 56 ms_impl_.reset(new MediaStreamImplUnderTest(ms_dispatcher_.get(),
64 p2p_socket_dispatcher_.get(),
65 vc_manager.get(), 57 vc_manager.get(),
66 dependency_factory)); 58 dependency_factory_.get()));
67 }
68
69 void TearDown() {
70 // Make sure the message created by
71 // P2PSocketDispatcher::AsyncMessageSender::Send is handled before
72 // tear down to avoid a memory leak.
73 loop_.RunAllPending();
74 } 59 }
75 60
76 WebKit::WebMediaStreamDescriptor RequestLocalMediaStream(bool audio, 61 WebKit::WebMediaStreamDescriptor RequestLocalMediaStream(bool audio,
77 bool video) { 62 bool video) {
78 WebKit::WebUserMediaRequest user_media_request; 63 WebKit::WebUserMediaRequest user_media_request;
79 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources( 64 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources(
80 audio ? static_cast<size_t>(1) : 0); 65 audio ? static_cast<size_t>(1) : 0);
81 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources( 66 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources(
82 video ? static_cast<size_t>(1) : 0); 67 video ? static_cast<size_t>(1) : 0);
83 ms_impl_->requestUserMedia(user_media_request, audio_sources, 68 ms_impl_->requestUserMedia(user_media_request, audio_sources,
(...skipping 17 matching lines...) Expand all
101 if (video) 86 if (video)
102 EXPECT_EQ(1u, extra_data->local_stream()->video_tracks()->count()); 87 EXPECT_EQ(1u, extra_data->local_stream()->video_tracks()->count());
103 if (audio && video) { 88 if (audio && video) {
104 EXPECT_NE(extra_data->local_stream()->audio_tracks()->at(0)->label(), 89 EXPECT_NE(extra_data->local_stream()->audio_tracks()->at(0)->label(),
105 extra_data->local_stream()->video_tracks()->at(0)->label()); 90 extra_data->local_stream()->video_tracks()->at(0)->label());
106 } 91 }
107 return desc; 92 return desc;
108 } 93 }
109 94
110 protected: 95 protected:
111 MessageLoop loop_;
112 scoped_ptr<MockMediaStreamDispatcher> ms_dispatcher_; 96 scoped_ptr<MockMediaStreamDispatcher> ms_dispatcher_;
113 scoped_refptr<content::P2PSocketDispatcher> p2p_socket_dispatcher_;
114 scoped_ptr<MediaStreamImplUnderTest> ms_impl_; 97 scoped_ptr<MediaStreamImplUnderTest> ms_impl_;
98 scoped_ptr<MockMediaStreamDependencyFactory> dependency_factory_;
115 }; 99 };
116 100
117 TEST_F(MediaStreamImplTest, CreatePeerConnection) {
118 // Create JSEP PeerConnection.
119 WebKit::MockWebPeerConnection00HandlerClient client_jsep;
120 scoped_ptr<WebKit::WebPeerConnection00Handler> pc_handler_jsep(
121 ms_impl_->CreatePeerConnectionHandlerJsep(&client_jsep));
122 pc_handler_jsep.reset();
123 }
124
125 TEST_F(MediaStreamImplTest, LocalMediaStream) { 101 TEST_F(MediaStreamImplTest, LocalMediaStream) {
126 // Test a stream with both audio and video. 102 // Test a stream with both audio and video.
127 WebKit::WebMediaStreamDescriptor mixed_desc = RequestLocalMediaStream(true, 103 WebKit::WebMediaStreamDescriptor mixed_desc = RequestLocalMediaStream(true,
128 true); 104 true);
129 // Create a renderer for the stream. 105 // Create a renderer for the stream.
130 scoped_ptr<media::MessageLoopFactory> message_loop_factory( 106 scoped_ptr<media::MessageLoopFactory> message_loop_factory(
131 new media::MessageLoopFactory()); 107 new media::MessageLoopFactory());
132 scoped_refptr<media::VideoDecoder> mixed_decoder( 108 scoped_refptr<media::VideoDecoder> mixed_decoder(
133 ms_impl_->GetVideoDecoder(GURL(), message_loop_factory.get())); 109 ms_impl_->GetVideoDecoder(GURL(), message_loop_factory.get()));
134 EXPECT_TRUE(mixed_decoder.get() != NULL); 110 EXPECT_TRUE(mixed_decoder.get() != NULL);
(...skipping 16 matching lines...) Expand all
151 ms_impl_->StopLocalMediaStream(mixed_desc); 127 ms_impl_->StopLocalMediaStream(mixed_desc);
152 EXPECT_EQ(1, ms_dispatcher_->stop_stream_counter()); 128 EXPECT_EQ(1, ms_dispatcher_->stop_stream_counter());
153 ms_impl_->StopLocalMediaStream(audio_desc); 129 ms_impl_->StopLocalMediaStream(audio_desc);
154 EXPECT_EQ(2, ms_dispatcher_->stop_stream_counter()); 130 EXPECT_EQ(2, ms_dispatcher_->stop_stream_counter());
155 131
156 // Test that the MediaStreams are deleted if the owning WebFrame is deleted. 132 // Test that the MediaStreams are deleted if the owning WebFrame is deleted.
157 // In the unit test the owning frame is NULL. 133 // In the unit test the owning frame is NULL.
158 ms_impl_->FrameWillClose(NULL); 134 ms_impl_->FrameWillClose(NULL);
159 EXPECT_EQ(3, ms_dispatcher_->stop_stream_counter()); 135 EXPECT_EQ(3, ms_dispatcher_->stop_stream_counter());
160 } 136 }
161
162 TEST_F(MediaStreamImplTest, CloneLocalMediaStream) {
163 // Request a stream with both audio and video.
164 WebKit::WebMediaStreamDescriptor mixed_desc =
165 RequestLocalMediaStream(true, true);
166
167 // Create a WebKit MediaStream description with the same sources as the
168 // sources used in the original requested media stream.
169 WebKit::WebMediaStreamDescriptor cloned_desc;
170 WebKit::WebVector<WebKit::WebMediaStreamComponent> compontents;
171 mixed_desc.audioSources(compontents);
172 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources(
173 static_cast<size_t>(1));
174 audio_sources[0] = compontents[0].source();
175 mixed_desc.videoSources(compontents);
176 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources(
177 static_cast<size_t>(1));
178 video_sources[0] = compontents[0].source();
179 cloned_desc.initialize("cloned stream", audio_sources, video_sources);
180
181 // Test that we can clone the local MediaStream.
182 ms_impl_->CreateMediaStream(NULL, &cloned_desc);
183
184 MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>(
185 mixed_desc.extraData());
186
187 MediaStreamExtraData* cloned_extra_data = static_cast<MediaStreamExtraData*>(
188 cloned_desc.extraData());
189
190 ASSERT_TRUE(extra_data && extra_data->local_stream());
191 ASSERT_TRUE(cloned_extra_data && cloned_extra_data->local_stream());
192 ASSERT_EQ(1u, extra_data->local_stream()->video_tracks()->count());
193 ASSERT_EQ(1u, extra_data->local_stream()->audio_tracks()->count());
194
195 EXPECT_EQ(1u, cloned_extra_data->local_stream()->video_tracks()->count());
196 EXPECT_EQ(1u, cloned_extra_data->local_stream()->audio_tracks()->count());
197 EXPECT_NE(extra_data->local_stream()->label(),
198 cloned_extra_data->local_stream()->label());
199 }
200
201 // Test that we don't crash if a MediaStream is created in WebKit with unknown
202 // sources. This can for example happen if a MediaStream is created with
203 // remote tracks.
204 TEST_F(MediaStreamImplTest, CreateInvalidMediaStream) {
205 // Create a WebKit MediaStream description.
206 WebKit::WebMediaStreamDescriptor desc;
207 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources(
208 static_cast<size_t>(1));
209 audio_sources[0].initialize("audio source",
210 WebKit::WebMediaStreamSource::TypeAudio,
211 "something");
212 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources(
213 static_cast<size_t>(1));
214 video_sources[0].initialize("video source",
215 WebKit::WebMediaStreamSource::TypeVideo,
216 "something");
217 desc.initialize("new stream", audio_sources, video_sources);
218
219 ms_impl_->CreateMediaStream(NULL, &desc);
220 MediaStreamExtraData* extra_data = static_cast<MediaStreamExtraData*>(
221 desc.extraData());
222
223 ASSERT_TRUE(extra_data && extra_data->local_stream());
224 EXPECT_EQ(0u, extra_data->local_stream()->video_tracks()->count());
225 EXPECT_EQ(0u, extra_data->local_stream()->audio_tracks()->count());
226 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698