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

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

Issue 12084088: Renamed WebMediaStreamComponent and WebMediaStreamDescriptor to WebMediaStreamTrack & WebMediaStream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 <string> 5 #include <string>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "content/renderer/media/media_stream_extra_data.h" 9 #include "content/renderer/media/media_stream_extra_data.h"
10 #include "content/renderer/media/mock_media_stream_dependency_factory.h" 10 #include "content/renderer/media/mock_media_stream_dependency_factory.h"
11 #include "content/renderer/media/mock_peer_connection_impl.h" 11 #include "content/renderer/media/mock_peer_connection_impl.h"
12 #include "content/renderer/media/mock_web_rtc_peer_connection_handler_client.h" 12 #include "content/renderer/media/mock_web_rtc_peer_connection_handler_client.h"
13 #include "content/renderer/media/rtc_peer_connection_handler.h" 13 #include "content/renderer/media/rtc_peer_connection_handler.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h "
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints .h" 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints .h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamCompo nent.h" 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStream.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamDescr iptor.h"
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSourc e.h" 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSourc e.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack .h"
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCConfiguration .h" 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCConfiguration .h"
21 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCDataChannelHa ndler.h" 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCDataChannelHa ndler.h"
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCICECandidate. h" 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCICECandidate. h"
23 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCPeerConnectio nHandlerClient.h" 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCPeerConnectio nHandlerClient.h"
24 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCSessionDescri ption.h" 23 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCSessionDescri ption.h"
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCSessionDescri ptionRequest.h" 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCSessionDescri ptionRequest.h"
26 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCStatsRequest. h" 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCStatsRequest. h"
27 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCVoidRequest.h " 26 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCVoidRequest.h "
28 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" 27 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
28 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h "
29 29
30 static const char kDummySdp[] = "dummy sdp"; 30 static const char kDummySdp[] = "dummy sdp";
31 static const char kDummySdpType[] = "dummy type"; 31 static const char kDummySdpType[] = "dummy type";
32 32
33 namespace content { 33 namespace content {
34 34
35 class MockRTCStatsResponse : public LocalRTCStatsResponse { 35 class MockRTCStatsResponse : public LocalRTCStatsResponse {
36 public: 36 public:
37 MockRTCStatsResponse() 37 MockRTCStatsResponse()
38 : report_count_(0), 38 : report_count_(0),
(...skipping 28 matching lines...) Expand all
67 class MockRTCStatsRequest : public LocalRTCStatsRequest { 67 class MockRTCStatsRequest : public LocalRTCStatsRequest {
68 public: 68 public:
69 MockRTCStatsRequest() 69 MockRTCStatsRequest()
70 : has_selector_(false), 70 : has_selector_(false),
71 stream_(), 71 stream_(),
72 request_succeeded_called_(false) {} 72 request_succeeded_called_(false) {}
73 73
74 virtual bool hasSelector() const OVERRIDE { 74 virtual bool hasSelector() const OVERRIDE {
75 return has_selector_; 75 return has_selector_;
76 } 76 }
77 virtual WebKit::WebMediaStreamDescriptor stream() const OVERRIDE { 77 virtual WebKit::WebMediaStream stream() const OVERRIDE {
78 return stream_; 78 return stream_;
79 } 79 }
80 virtual WebKit::WebMediaStreamComponent component() const OVERRIDE { 80 virtual WebKit::WebMediaStreamTrack component() const OVERRIDE {
81 return component_; 81 return component_;
82 } 82 }
83 virtual scoped_refptr<LocalRTCStatsResponse> createResponse() OVERRIDE { 83 virtual scoped_refptr<LocalRTCStatsResponse> createResponse() OVERRIDE {
84 DCHECK(!response_); 84 DCHECK(!response_);
85 response_ = new talk_base::RefCountedObject<MockRTCStatsResponse>(); 85 response_ = new talk_base::RefCountedObject<MockRTCStatsResponse>();
86 return response_; 86 return response_;
87 } 87 }
88 88
89 virtual void requestSucceeded(const LocalRTCStatsResponse* response) 89 virtual void requestSucceeded(const LocalRTCStatsResponse* response)
90 OVERRIDE { 90 OVERRIDE {
91 EXPECT_EQ(response, response_.get()); 91 EXPECT_EQ(response, response_.get());
92 request_succeeded_called_ = true; 92 request_succeeded_called_ = true;
93 } 93 }
94 94
95 // Function for setting whether or not a selector is available. 95 // Function for setting whether or not a selector is available.
96 void setSelector(const WebKit::WebMediaStreamDescriptor& stream, 96 void setSelector(const WebKit::WebMediaStream& stream,
97 const WebKit::WebMediaStreamComponent& component) { 97 const WebKit::WebMediaStreamTrack& component) {
98 has_selector_ = true; 98 has_selector_ = true;
99 stream_ = stream; 99 stream_ = stream;
100 component_ = component; 100 component_ = component;
101 } 101 }
102 102
103 // Function for inspecting the result of a stats request. 103 // Function for inspecting the result of a stats request.
104 MockRTCStatsResponse* result() { 104 MockRTCStatsResponse* result() {
105 if (request_succeeded_called_) { 105 if (request_succeeded_called_) {
106 return response_.get(); 106 return response_.get();
107 } else { 107 } else {
108 return NULL; 108 return NULL;
109 } 109 }
110 } 110 }
111 111
112 private: 112 private:
113 bool has_selector_; 113 bool has_selector_;
114 WebKit::WebMediaStreamDescriptor stream_; 114 WebKit::WebMediaStream stream_;
115 WebKit::WebMediaStreamComponent component_; 115 WebKit::WebMediaStreamTrack component_;
116 scoped_refptr<MockRTCStatsResponse> response_; 116 scoped_refptr<MockRTCStatsResponse> response_;
117 bool request_succeeded_called_; 117 bool request_succeeded_called_;
118 }; 118 };
119 119
120 class RTCPeerConnectionHandlerUnderTest : public RTCPeerConnectionHandler { 120 class RTCPeerConnectionHandlerUnderTest : public RTCPeerConnectionHandler {
121 public: 121 public:
122 RTCPeerConnectionHandlerUnderTest( 122 RTCPeerConnectionHandlerUnderTest(
123 WebKit::WebRTCPeerConnectionHandlerClient* client, 123 WebKit::WebRTCPeerConnectionHandlerClient* client,
124 MediaStreamDependencyFactory* dependency_factory) 124 MediaStreamDependencyFactory* dependency_factory)
125 : RTCPeerConnectionHandler(client, dependency_factory) { 125 : RTCPeerConnectionHandler(client, dependency_factory) {
(...skipping 19 matching lines...) Expand all
145 145
146 WebKit::WebRTCConfiguration config; 146 WebKit::WebRTCConfiguration config;
147 WebKit::WebMediaConstraints constraints; 147 WebKit::WebMediaConstraints constraints;
148 EXPECT_TRUE(pc_handler_->InitializeForTest(config, constraints)); 148 EXPECT_TRUE(pc_handler_->InitializeForTest(config, constraints));
149 149
150 mock_peer_connection_ = pc_handler_->native_peer_connection(); 150 mock_peer_connection_ = pc_handler_->native_peer_connection();
151 ASSERT_TRUE(mock_peer_connection_); 151 ASSERT_TRUE(mock_peer_connection_);
152 } 152 }
153 153
154 // Creates a WebKit local MediaStream. 154 // Creates a WebKit local MediaStream.
155 WebKit::WebMediaStreamDescriptor CreateLocalMediaStream( 155 WebKit::WebMediaStream CreateLocalMediaStream(
156 const std::string& stream_label) { 156 const std::string& stream_label) {
157 std::string video_track_label("video-label"); 157 std::string video_track_label("video-label");
158 std::string audio_track_label("audio-label"); 158 std::string audio_track_label("audio-label");
159 159
160 scoped_refptr<webrtc::LocalMediaStreamInterface> native_stream( 160 scoped_refptr<webrtc::LocalMediaStreamInterface> native_stream(
161 mock_dependency_factory_->CreateLocalMediaStream(stream_label)); 161 mock_dependency_factory_->CreateLocalMediaStream(stream_label));
162 scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track( 162 scoped_refptr<webrtc::LocalAudioTrackInterface> audio_track(
163 mock_dependency_factory_->CreateLocalAudioTrack(audio_track_label, 163 mock_dependency_factory_->CreateLocalAudioTrack(audio_track_label,
164 NULL)); 164 NULL));
165 native_stream->AddTrack(audio_track); 165 native_stream->AddTrack(audio_track);
166 scoped_refptr<webrtc::LocalVideoTrackInterface> video_track( 166 scoped_refptr<webrtc::LocalVideoTrackInterface> video_track(
167 mock_dependency_factory_->CreateLocalVideoTrack( 167 mock_dependency_factory_->CreateLocalVideoTrack(
168 video_track_label, 0)); 168 video_track_label, 0));
169 native_stream->AddTrack(video_track); 169 native_stream->AddTrack(video_track);
170 170
171 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources( 171 WebKit::WebVector<WebKit::WebMediaStreamSource> audio_sources(
172 static_cast<size_t>(1)); 172 static_cast<size_t>(1));
173 audio_sources[0].initialize(WebKit::WebString::fromUTF8(audio_track_label), 173 audio_sources[0].initialize(WebKit::WebString::fromUTF8(audio_track_label),
174 WebKit::WebMediaStreamSource::TypeAudio, 174 WebKit::WebMediaStreamSource::TypeAudio,
175 WebKit::WebString::fromUTF8("audio_track")); 175 WebKit::WebString::fromUTF8("audio_track"));
176 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources( 176 WebKit::WebVector<WebKit::WebMediaStreamSource> video_sources(
177 static_cast<size_t>(1)); 177 static_cast<size_t>(1));
178 video_sources[0].initialize(WebKit::WebString::fromUTF8(video_track_label), 178 video_sources[0].initialize(WebKit::WebString::fromUTF8(video_track_label),
179 WebKit::WebMediaStreamSource::TypeVideo, 179 WebKit::WebMediaStreamSource::TypeVideo,
180 WebKit::WebString::fromUTF8("video_track")); 180 WebKit::WebString::fromUTF8("video_track"));
181 WebKit::WebMediaStreamDescriptor local_stream; 181 WebKit::WebMediaStream local_stream;
182 local_stream.initialize(UTF8ToUTF16(stream_label), audio_sources, 182 local_stream.initialize(UTF8ToUTF16(stream_label), audio_sources,
183 video_sources); 183 video_sources);
184 local_stream.setExtraData(new MediaStreamExtraData(native_stream)); 184 local_stream.setExtraData(new MediaStreamExtraData(native_stream));
185 return local_stream; 185 return local_stream;
186 } 186 }
187 187
188 // Creates a remote MediaStream and adds it to the mocked native 188 // Creates a remote MediaStream and adds it to the mocked native
189 // peer connection. 189 // peer connection.
190 scoped_refptr<webrtc::MediaStreamInterface> 190 scoped_refptr<webrtc::MediaStreamInterface>
191 AddRemoteMockMediaStream(const std::string& stream_label, 191 AddRemoteMockMediaStream(const std::string& stream_label,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 WebKit::WebRTCICECandidate candidate; 285 WebKit::WebRTCICECandidate candidate;
286 candidate.initialize(kDummySdp, "mid", 1); 286 candidate.initialize(kDummySdp, "mid", 1);
287 EXPECT_TRUE(pc_handler_->addICECandidate(candidate)); 287 EXPECT_TRUE(pc_handler_->addICECandidate(candidate));
288 EXPECT_EQ(kDummySdp, mock_peer_connection_->ice_sdp()); 288 EXPECT_EQ(kDummySdp, mock_peer_connection_->ice_sdp());
289 EXPECT_EQ(1, mock_peer_connection_->sdp_mline_index()); 289 EXPECT_EQ(1, mock_peer_connection_->sdp_mline_index());
290 EXPECT_EQ("mid", mock_peer_connection_->sdp_mid()); 290 EXPECT_EQ("mid", mock_peer_connection_->sdp_mid());
291 } 291 }
292 292
293 TEST_F(RTCPeerConnectionHandlerTest, addAndRemoveStream) { 293 TEST_F(RTCPeerConnectionHandlerTest, addAndRemoveStream) {
294 std::string stream_label = "local_stream"; 294 std::string stream_label = "local_stream";
295 WebKit::WebMediaStreamDescriptor local_stream( 295 WebKit::WebMediaStream local_stream(
296 CreateLocalMediaStream(stream_label)); 296 CreateLocalMediaStream(stream_label));
297 WebKit::WebMediaConstraints constraints; 297 WebKit::WebMediaConstraints constraints;
298 298
299 EXPECT_TRUE(pc_handler_->addStream(local_stream, constraints)); 299 EXPECT_TRUE(pc_handler_->addStream(local_stream, constraints));
300 EXPECT_EQ(stream_label, mock_peer_connection_->stream_label()); 300 EXPECT_EQ(stream_label, mock_peer_connection_->stream_label());
301 EXPECT_EQ(1u, 301 EXPECT_EQ(1u,
302 mock_peer_connection_->local_streams()->at(0)->audio_tracks()->count()); 302 mock_peer_connection_->local_streams()->at(0)->audio_tracks()->count());
303 EXPECT_EQ(1u, 303 EXPECT_EQ(1u,
304 mock_peer_connection_->local_streams()->at(0)->video_tracks()->count()); 304 mock_peer_connection_->local_streams()->at(0)->video_tracks()->count());
305 305
306 pc_handler_->removeStream(local_stream); 306 pc_handler_->removeStream(local_stream);
307 EXPECT_EQ(0u, mock_peer_connection_->local_streams()->count()); 307 EXPECT_EQ(0u, mock_peer_connection_->local_streams()->count());
308 } 308 }
309 309
310 TEST_F(RTCPeerConnectionHandlerTest, GetStatsNoSelector) { 310 TEST_F(RTCPeerConnectionHandlerTest, GetStatsNoSelector) {
311 scoped_refptr<MockRTCStatsRequest> request( 311 scoped_refptr<MockRTCStatsRequest> request(
312 new talk_base::RefCountedObject<MockRTCStatsRequest>()); 312 new talk_base::RefCountedObject<MockRTCStatsRequest>());
313 pc_handler_->getStats(request.get()); 313 pc_handler_->getStats(request.get());
314 // Note that callback gets executed synchronously by mock. 314 // Note that callback gets executed synchronously by mock.
315 ASSERT_TRUE(request->result()); 315 ASSERT_TRUE(request->result());
316 EXPECT_LT(1, request->result()->report_count()); 316 EXPECT_LT(1, request->result()->report_count());
317 } 317 }
318 318
319 TEST_F(RTCPeerConnectionHandlerTest, GetStatsWithSelector) { 319 TEST_F(RTCPeerConnectionHandlerTest, GetStatsWithSelector) {
320 std::string stream_label = "local_stream"; 320 std::string stream_label = "local_stream";
321 WebKit::WebMediaStreamDescriptor local_stream( 321 WebKit::WebMediaStream local_stream(
322 CreateLocalMediaStream(stream_label)); 322 CreateLocalMediaStream(stream_label));
323 WebKit::WebMediaConstraints constraints; 323 WebKit::WebMediaConstraints constraints;
324 pc_handler_->addStream(local_stream, constraints); 324 pc_handler_->addStream(local_stream, constraints);
325 WebKit::WebVector<WebKit::WebMediaStreamComponent> components; 325 WebKit::WebVector<WebKit::WebMediaStreamTrack> components;
326 local_stream.audioSources(components); 326 local_stream.audioSources(components);
327 ASSERT_LE(1ul, components.size()); 327 ASSERT_LE(1ul, components.size());
328 328
329 scoped_refptr<MockRTCStatsRequest> request( 329 scoped_refptr<MockRTCStatsRequest> request(
330 new talk_base::RefCountedObject<MockRTCStatsRequest>()); 330 new talk_base::RefCountedObject<MockRTCStatsRequest>());
331 request->setSelector(local_stream, components[0]); 331 request->setSelector(local_stream, components[0]);
332 pc_handler_->getStats(request.get()); 332 pc_handler_->getStats(request.get());
333 EXPECT_EQ(1, request->result()->report_count()); 333 EXPECT_EQ(1, request->result()->report_count());
334 } 334 }
335 335
336 TEST_F(RTCPeerConnectionHandlerTest, GetStatsAfterStop) { 336 TEST_F(RTCPeerConnectionHandlerTest, GetStatsAfterStop) {
337 scoped_refptr<MockRTCStatsRequest> request( 337 scoped_refptr<MockRTCStatsRequest> request(
338 new talk_base::RefCountedObject<MockRTCStatsRequest>()); 338 new talk_base::RefCountedObject<MockRTCStatsRequest>());
339 pc_handler_->stop(); 339 pc_handler_->stop();
340 pc_handler_->getStats(request.get()); 340 pc_handler_->getStats(request.get());
341 // Note that callback gets executed synchronously by mock. 341 // Note that callback gets executed synchronously by mock.
342 ASSERT_TRUE(request->result()); 342 ASSERT_TRUE(request->result());
343 // Note - returning no stats is a temporary workaround. 343 // Note - returning no stats is a temporary workaround.
344 EXPECT_EQ(0, request->result()->report_count()); 344 EXPECT_EQ(0, request->result()->report_count());
345 } 345 }
346 346
347 TEST_F(RTCPeerConnectionHandlerTest, GetStatsWithBadSelector) { 347 TEST_F(RTCPeerConnectionHandlerTest, GetStatsWithBadSelector) {
348 // The setup is the same as above, but the stream is not added to the 348 // The setup is the same as above, but the stream is not added to the
349 // PeerConnection. 349 // PeerConnection.
350 std::string stream_label = "local_stream_2"; 350 std::string stream_label = "local_stream_2";
351 WebKit::WebMediaStreamDescriptor local_stream( 351 WebKit::WebMediaStream local_stream(
352 CreateLocalMediaStream(stream_label)); 352 CreateLocalMediaStream(stream_label));
353 WebKit::WebMediaConstraints constraints; 353 WebKit::WebMediaConstraints constraints;
354 WebKit::WebVector<WebKit::WebMediaStreamComponent> components; 354 WebKit::WebVector<WebKit::WebMediaStreamTrack> components;
355 local_stream.audioSources(components); 355 local_stream.audioSources(components);
356 WebKit::WebMediaStreamComponent component = components[0]; 356 WebKit::WebMediaStreamTrack component = components[0];
357 EXPECT_EQ(0u, mock_peer_connection_->local_streams()->count()); 357 EXPECT_EQ(0u, mock_peer_connection_->local_streams()->count());
358 358
359 scoped_refptr<MockRTCStatsRequest> request( 359 scoped_refptr<MockRTCStatsRequest> request(
360 new talk_base::RefCountedObject<MockRTCStatsRequest>()); 360 new talk_base::RefCountedObject<MockRTCStatsRequest>());
361 request->setSelector(local_stream, component); 361 request->setSelector(local_stream, component);
362 pc_handler_->getStats(request.get()); 362 pc_handler_->getStats(request.get());
363 EXPECT_EQ(0, request->result()->report_count()); 363 EXPECT_EQ(0, request->result()->report_count());
364 } 364 }
365 365
366 TEST_F(RTCPeerConnectionHandlerTest, OnStateChange) { 366 TEST_F(RTCPeerConnectionHandlerTest, OnStateChange) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 474
475 TEST_F(RTCPeerConnectionHandlerTest, CreateDataChannel) { 475 TEST_F(RTCPeerConnectionHandlerTest, CreateDataChannel) {
476 WebKit::WebString label = "d1"; 476 WebKit::WebString label = "d1";
477 scoped_ptr<WebKit::WebRTCDataChannelHandler> channel( 477 scoped_ptr<WebKit::WebRTCDataChannelHandler> channel(
478 pc_handler_->createDataChannel("d1", true)); 478 pc_handler_->createDataChannel("d1", true));
479 EXPECT_TRUE(channel.get() != NULL); 479 EXPECT_TRUE(channel.get() != NULL);
480 EXPECT_EQ(label, channel->label()); 480 EXPECT_EQ(label, channel->label());
481 } 481 }
482 482
483 } // namespace content 483 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_peer_connection_handler.cc ('k') | webkit/support/test_media_stream_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698