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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/thread_task_runner_handle.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "content/child/child_process.h" | 14 #include "content/child/child_process.h" |
14 #include "content/renderer/media/media_stream.h" | 15 #include "content/renderer/media/media_stream.h" |
15 #include "content/renderer/media/media_stream_audio_source.h" | 16 #include "content/renderer/media/media_stream_audio_source.h" |
16 #include "content/renderer/media/media_stream_source.h" | 17 #include "content/renderer/media/media_stream_source.h" |
17 #include "content/renderer/media/media_stream_video_track.h" | 18 #include "content/renderer/media/media_stream_video_track.h" |
18 #include "content/renderer/media/mock_media_constraint_factory.h" | 19 #include "content/renderer/media/mock_media_constraint_factory.h" |
19 #include "content/renderer/media/mock_media_stream_video_source.h" | 20 #include "content/renderer/media/mock_media_stream_video_source.h" |
20 #include "content/renderer/media/mock_peer_connection_impl.h" | 21 #include "content/renderer/media/mock_peer_connection_impl.h" |
21 #include "content/renderer/media/mock_web_rtc_peer_connection_handler_client.h" | 22 #include "content/renderer/media/mock_web_rtc_peer_connection_handler_client.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 void(RTCPeerConnectionHandler* pc_handler)); | 184 void(RTCPeerConnectionHandler* pc_handler)); |
184 MOCK_METHOD2(TrackCreateDTMFSender, | 185 MOCK_METHOD2(TrackCreateDTMFSender, |
185 void(RTCPeerConnectionHandler* pc_handler, | 186 void(RTCPeerConnectionHandler* pc_handler, |
186 const blink::WebMediaStreamTrack& track)); | 187 const blink::WebMediaStreamTrack& track)); |
187 }; | 188 }; |
188 | 189 |
189 class RTCPeerConnectionHandlerUnderTest : public RTCPeerConnectionHandler { | 190 class RTCPeerConnectionHandlerUnderTest : public RTCPeerConnectionHandler { |
190 public: | 191 public: |
191 RTCPeerConnectionHandlerUnderTest( | 192 RTCPeerConnectionHandlerUnderTest( |
192 WebRTCPeerConnectionHandlerClient* client, | 193 WebRTCPeerConnectionHandlerClient* client, |
193 PeerConnectionDependencyFactory* dependency_factory, | 194 PeerConnectionDependencyFactory* dependency_factory) |
194 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread) | 195 : RTCPeerConnectionHandler(client, dependency_factory) { |
195 : RTCPeerConnectionHandler(client, dependency_factory, signaling_thread) { | |
196 } | 196 } |
197 | 197 |
198 MockPeerConnectionImpl* native_peer_connection() { | 198 MockPeerConnectionImpl* native_peer_connection() { |
199 return static_cast<MockPeerConnectionImpl*>( | 199 return static_cast<MockPeerConnectionImpl*>( |
200 RTCPeerConnectionHandler::native_peer_connection()); | 200 RTCPeerConnectionHandler::native_peer_connection()); |
201 } | 201 } |
202 | 202 |
203 webrtc::PeerConnectionObserver* observer() { | 203 webrtc::PeerConnectionObserver* observer() { |
204 return native_peer_connection()->observer(); | 204 return native_peer_connection()->observer(); |
205 } | 205 } |
| 206 |
| 207 scoped_refptr<base::SingleThreadTaskRunner> |
| 208 signaling_thread() const override { |
| 209 return base::ThreadTaskRunnerHandle::Get(); |
| 210 } |
206 }; | 211 }; |
207 | 212 |
208 class RTCPeerConnectionHandlerTest : public ::testing::Test { | 213 class RTCPeerConnectionHandlerTest : public ::testing::Test { |
209 public: | 214 public: |
210 RTCPeerConnectionHandlerTest() : mock_peer_connection_(NULL) { | 215 RTCPeerConnectionHandlerTest() : mock_peer_connection_(NULL) { |
211 child_process_.reset(new ChildProcess()); | 216 child_process_.reset(new ChildProcess()); |
212 } | 217 } |
213 | 218 |
214 void SetUp() override { | 219 void SetUp() override { |
215 mock_client_.reset(new NiceMock<MockWebRTCPeerConnectionHandlerClient>()); | 220 mock_client_.reset(new NiceMock<MockWebRTCPeerConnectionHandlerClient>()); |
216 mock_dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); | 221 mock_dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); |
217 pc_handler_.reset( | 222 pc_handler_.reset( |
218 new RTCPeerConnectionHandlerUnderTest( | 223 new RTCPeerConnectionHandlerUnderTest( |
219 mock_client_.get(), mock_dependency_factory_.get(), | 224 mock_client_.get(), mock_dependency_factory_.get())); |
220 message_loop_.message_loop_proxy())); | |
221 mock_tracker_.reset(new NiceMock<MockPeerConnectionTracker>()); | 225 mock_tracker_.reset(new NiceMock<MockPeerConnectionTracker>()); |
222 blink::WebRTCConfiguration config; | 226 blink::WebRTCConfiguration config; |
223 blink::WebMediaConstraints constraints; | 227 blink::WebMediaConstraints constraints; |
224 EXPECT_TRUE(pc_handler_->InitializeForTest( | 228 EXPECT_TRUE(pc_handler_->InitializeForTest( |
225 config, constraints, mock_tracker_.get()->AsWeakPtr())); | 229 config, constraints, mock_tracker_.get()->AsWeakPtr())); |
226 | 230 |
227 mock_peer_connection_ = pc_handler_->native_peer_connection(); | 231 mock_peer_connection_ = pc_handler_->native_peer_connection(); |
228 ASSERT_TRUE(mock_peer_connection_); | 232 ASSERT_TRUE(mock_peer_connection_); |
229 } | 233 } |
230 | 234 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 // PeerConnectionTracker::TrackSetSessionDescription is expected to be called | 364 // PeerConnectionTracker::TrackSetSessionDescription is expected to be called |
361 // before |mock_peer_connection| is called. | 365 // before |mock_peer_connection| is called. |
362 testing::InSequence sequence; | 366 testing::InSequence sequence; |
363 EXPECT_CALL(*mock_tracker_.get(), | 367 EXPECT_CALL(*mock_tracker_.get(), |
364 TrackSetSessionDescription(pc_handler_.get(), kDummySdp, | 368 TrackSetSessionDescription(pc_handler_.get(), kDummySdp, |
365 kDummySdpType, | 369 kDummySdpType, |
366 PeerConnectionTracker::SOURCE_LOCAL)); | 370 PeerConnectionTracker::SOURCE_LOCAL)); |
367 EXPECT_CALL(*mock_peer_connection_, SetLocalDescription(_, _)); | 371 EXPECT_CALL(*mock_peer_connection_, SetLocalDescription(_, _)); |
368 | 372 |
369 pc_handler_->setLocalDescription(request, description); | 373 pc_handler_->setLocalDescription(request, description); |
| 374 base::RunLoop().RunUntilIdle(); |
370 EXPECT_EQ(description.type(), pc_handler_->localDescription().type()); | 375 EXPECT_EQ(description.type(), pc_handler_->localDescription().type()); |
371 EXPECT_EQ(description.sdp(), pc_handler_->localDescription().sdp()); | 376 EXPECT_EQ(description.sdp(), pc_handler_->localDescription().sdp()); |
372 | 377 |
373 std::string sdp_string; | 378 std::string sdp_string; |
374 ASSERT_TRUE(mock_peer_connection_->local_description() != NULL); | 379 ASSERT_TRUE(mock_peer_connection_->local_description() != NULL); |
375 EXPECT_EQ(kDummySdpType, mock_peer_connection_->local_description()->type()); | 380 EXPECT_EQ(kDummySdpType, mock_peer_connection_->local_description()->type()); |
376 mock_peer_connection_->local_description()->ToString(&sdp_string); | 381 mock_peer_connection_->local_description()->ToString(&sdp_string); |
377 EXPECT_EQ(kDummySdp, sdp_string); | 382 EXPECT_EQ(kDummySdp, sdp_string); |
378 } | 383 } |
379 | 384 |
380 TEST_F(RTCPeerConnectionHandlerTest, setRemoteDescription) { | 385 TEST_F(RTCPeerConnectionHandlerTest, setRemoteDescription) { |
381 blink::WebRTCVoidRequest request; | 386 blink::WebRTCVoidRequest request; |
382 blink::WebRTCSessionDescription description; | 387 blink::WebRTCSessionDescription description; |
383 description.initialize(kDummySdpType, kDummySdp); | 388 description.initialize(kDummySdpType, kDummySdp); |
384 | 389 |
385 // PeerConnectionTracker::TrackSetSessionDescription is expected to be called | 390 // PeerConnectionTracker::TrackSetSessionDescription is expected to be called |
386 // before |mock_peer_connection| is called. | 391 // before |mock_peer_connection| is called. |
387 testing::InSequence sequence; | 392 testing::InSequence sequence; |
388 EXPECT_CALL(*mock_tracker_.get(), | 393 EXPECT_CALL(*mock_tracker_.get(), |
389 TrackSetSessionDescription(pc_handler_.get(), kDummySdp, | 394 TrackSetSessionDescription(pc_handler_.get(), kDummySdp, |
390 kDummySdpType, | 395 kDummySdpType, |
391 PeerConnectionTracker::SOURCE_REMOTE)); | 396 PeerConnectionTracker::SOURCE_REMOTE)); |
392 EXPECT_CALL(*mock_peer_connection_, SetRemoteDescription(_, _)); | 397 EXPECT_CALL(*mock_peer_connection_, SetRemoteDescription(_, _)); |
393 | 398 |
394 pc_handler_->setRemoteDescription(request, description); | 399 pc_handler_->setRemoteDescription(request, description); |
| 400 base::RunLoop().RunUntilIdle(); |
395 EXPECT_EQ(description.type(), pc_handler_->remoteDescription().type()); | 401 EXPECT_EQ(description.type(), pc_handler_->remoteDescription().type()); |
396 EXPECT_EQ(description.sdp(), pc_handler_->remoteDescription().sdp()); | 402 EXPECT_EQ(description.sdp(), pc_handler_->remoteDescription().sdp()); |
397 | 403 |
398 std::string sdp_string; | 404 std::string sdp_string; |
399 ASSERT_TRUE(mock_peer_connection_->remote_description() != NULL); | 405 ASSERT_TRUE(mock_peer_connection_->remote_description() != NULL); |
400 EXPECT_EQ(kDummySdpType, mock_peer_connection_->remote_description()->type()); | 406 EXPECT_EQ(kDummySdpType, mock_peer_connection_->remote_description()->type()); |
401 mock_peer_connection_->remote_description()->ToString(&sdp_string); | 407 mock_peer_connection_->remote_description()->ToString(&sdp_string); |
402 EXPECT_EQ(kDummySdp, sdp_string); | 408 EXPECT_EQ(kDummySdp, sdp_string); |
403 } | 409 } |
404 | 410 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 pc_handler_->getStats(request.get()); | 497 pc_handler_->getStats(request.get()); |
492 base::RunLoop().RunUntilIdle(); | 498 base::RunLoop().RunUntilIdle(); |
493 ASSERT_TRUE(request->result()); | 499 ASSERT_TRUE(request->result()); |
494 EXPECT_LT(1, request->result()->report_count()); | 500 EXPECT_LT(1, request->result()->report_count()); |
495 } | 501 } |
496 | 502 |
497 TEST_F(RTCPeerConnectionHandlerTest, GetStatsAfterClose) { | 503 TEST_F(RTCPeerConnectionHandlerTest, GetStatsAfterClose) { |
498 scoped_refptr<MockRTCStatsRequest> request( | 504 scoped_refptr<MockRTCStatsRequest> request( |
499 new rtc::RefCountedObject<MockRTCStatsRequest>()); | 505 new rtc::RefCountedObject<MockRTCStatsRequest>()); |
500 pc_handler_->stop(); | 506 pc_handler_->stop(); |
| 507 base::RunLoop().RunUntilIdle(); |
501 pc_handler_->getStats(request.get()); | 508 pc_handler_->getStats(request.get()); |
502 base::RunLoop().RunUntilIdle(); | 509 base::RunLoop().RunUntilIdle(); |
503 ASSERT_TRUE(request->result()); | 510 ASSERT_TRUE(request->result()); |
504 EXPECT_LT(1, request->result()->report_count()); | 511 EXPECT_LT(1, request->result()->report_count()); |
505 } | 512 } |
506 | 513 |
507 TEST_F(RTCPeerConnectionHandlerTest, GetStatsWithLocalSelector) { | 514 TEST_F(RTCPeerConnectionHandlerTest, GetStatsWithLocalSelector) { |
508 blink::WebMediaStream local_stream( | 515 blink::WebMediaStream local_stream( |
509 CreateLocalMediaStream("local_stream")); | 516 CreateLocalMediaStream("local_stream")); |
510 blink::WebMediaConstraints constraints; | 517 blink::WebMediaConstraints constraints; |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 EXPECT_CALL(*mock_tracker_.get(), | 986 EXPECT_CALL(*mock_tracker_.get(), |
980 TrackCreateDTMFSender(pc_handler_.get(), | 987 TrackCreateDTMFSender(pc_handler_.get(), |
981 testing::Ref(tracks[0]))); | 988 testing::Ref(tracks[0]))); |
982 | 989 |
983 scoped_ptr<blink::WebRTCDTMFSenderHandler> sender( | 990 scoped_ptr<blink::WebRTCDTMFSenderHandler> sender( |
984 pc_handler_->createDTMFSender(tracks[0])); | 991 pc_handler_->createDTMFSender(tracks[0])); |
985 EXPECT_TRUE(sender.get()); | 992 EXPECT_TRUE(sender.get()); |
986 } | 993 } |
987 | 994 |
988 } // namespace content | 995 } // namespace content |
OLD | NEW |