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

Side by Side Diff: talk/app/webrtc/webrtcsession_unittest.cc

Issue 1363573002: Wire up transport sequence number / send time callbacks to webrtc via libjingle. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Connect to SignalSentPacket when enabling bundle. Created 5 years, 2 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
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 24 matching lines...) Expand all
35 #include "talk/app/webrtc/streamcollection.h" 35 #include "talk/app/webrtc/streamcollection.h"
36 #include "talk/app/webrtc/test/fakeconstraints.h" 36 #include "talk/app/webrtc/test/fakeconstraints.h"
37 #include "talk/app/webrtc/test/fakedtlsidentitystore.h" 37 #include "talk/app/webrtc/test/fakedtlsidentitystore.h"
38 #include "talk/app/webrtc/test/fakemediastreamsignaling.h" 38 #include "talk/app/webrtc/test/fakemediastreamsignaling.h"
39 #include "talk/app/webrtc/videotrack.h" 39 #include "talk/app/webrtc/videotrack.h"
40 #include "talk/app/webrtc/webrtcsession.h" 40 #include "talk/app/webrtc/webrtcsession.h"
41 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" 41 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
42 #include "talk/media/base/fakemediaengine.h" 42 #include "talk/media/base/fakemediaengine.h"
43 #include "talk/media/base/fakevideorenderer.h" 43 #include "talk/media/base/fakevideorenderer.h"
44 #include "talk/media/base/mediachannel.h" 44 #include "talk/media/base/mediachannel.h"
45 #include "talk/media/webrtc/fakewebrtccall.h"
45 #include "webrtc/p2p/base/stunserver.h" 46 #include "webrtc/p2p/base/stunserver.h"
46 #include "webrtc/p2p/base/teststunserver.h" 47 #include "webrtc/p2p/base/teststunserver.h"
47 #include "webrtc/p2p/base/testturnserver.h" 48 #include "webrtc/p2p/base/testturnserver.h"
48 #include "webrtc/p2p/base/transportchannel.h" 49 #include "webrtc/p2p/base/transportchannel.h"
49 #include "webrtc/p2p/client/basicportallocator.h" 50 #include "webrtc/p2p/client/basicportallocator.h"
50 #include "talk/session/media/channelmanager.h" 51 #include "talk/session/media/channelmanager.h"
51 #include "talk/session/media/mediasession.h" 52 #include "talk/session/media/mediasession.h"
52 #include "webrtc/base/fakenetwork.h" 53 #include "webrtc/base/fakenetwork.h"
53 #include "webrtc/base/firewallsocketserver.h" 54 #include "webrtc/base/firewallsocketserver.h"
54 #include "webrtc/base/gunit.h" 55 #include "webrtc/base/gunit.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 PeerConnectionInterface::IceGatheringState ice_gathering_state_; 232 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
232 }; 233 };
233 234
234 class WebRtcSessionForTest : public webrtc::WebRtcSession { 235 class WebRtcSessionForTest : public webrtc::WebRtcSession {
235 public: 236 public:
236 WebRtcSessionForTest(cricket::ChannelManager* cmgr, 237 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
237 rtc::Thread* signaling_thread, 238 rtc::Thread* signaling_thread,
238 rtc::Thread* worker_thread, 239 rtc::Thread* worker_thread,
239 cricket::PortAllocator* port_allocator, 240 cricket::PortAllocator* port_allocator,
240 webrtc::IceObserver* ice_observer, 241 webrtc::IceObserver* ice_observer,
241 webrtc::MediaStreamSignaling* mediastream_signaling) 242 webrtc::MediaStreamSignaling* mediastream_signaling,
242 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator, 243 webrtc::CallFactory* call_factory)
243 mediastream_signaling) { 244 : WebRtcSession(cmgr,
245 signaling_thread,
246 worker_thread,
247 port_allocator,
248 mediastream_signaling,
249 call_factory) {
244 RegisterIceObserver(ice_observer); 250 RegisterIceObserver(ice_observer);
245 } 251 }
246 virtual ~WebRtcSessionForTest() {} 252 virtual ~WebRtcSessionForTest() {}
247 253
248 // Note that these methods are only safe to use if the signaling thread 254 // Note that these methods are only safe to use if the signaling thread
249 // is the same as the worker thread 255 // is the same as the worker thread
250 cricket::TransportChannel* voice_rtp_transport_channel() { 256 cricket::TransportChannel* voice_rtp_transport_channel() {
251 return rtp_transport_channel(voice_channel()); 257 return rtp_transport_channel(voice_channel());
252 } 258 }
253 259
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 352 }
347 void SetSink(Sink* sink) override { sink_ = sink; } 353 void SetSink(Sink* sink) override { sink_ = sink; }
348 354
349 int channel_id() const { return channel_id_; } 355 int channel_id() const { return channel_id_; }
350 cricket::AudioRenderer::Sink* sink() const { return sink_; } 356 cricket::AudioRenderer::Sink* sink() const { return sink_; }
351 private: 357 private:
352 int channel_id_; 358 int channel_id_;
353 cricket::AudioRenderer::Sink* sink_; 359 cricket::AudioRenderer::Sink* sink_;
354 }; 360 };
355 361
362 class FakeCallFactory : public webrtc::CallFactory {
363 public:
364 FakeCallFactory() : fake_call_(nullptr) {}
365
366 webrtc::Call* CreateCall(const webrtc::Call::Config& config) override {
367 fake_call_ = new cricket::FakeCall(config);
368 return fake_call_;
369 }
370
371 cricket::FakeCall* fake_call() const { return fake_call_; }
372
373 private:
374 // Since ownership of fake_call_ is handed over to the caller of CreateCall,
375 // this pointer is only valid until the caller has deleted it.
376 cricket::FakeCall* fake_call_;
377 };
378
356 class WebRtcSessionTest 379 class WebRtcSessionTest
357 : public testing::TestWithParam<RTCCertificateGenerationMethod> { 380 : public testing::TestWithParam<RTCCertificateGenerationMethod> {
358 protected: 381 protected:
359 // TODO Investigate why ChannelManager crashes, if it's created 382 // TODO Investigate why ChannelManager crashes, if it's created
360 // after stun_server. 383 // after stun_server.
361 WebRtcSessionTest() 384 WebRtcSessionTest()
362 : media_engine_(new cricket::FakeMediaEngine()), 385 : media_engine_(new cricket::FakeMediaEngine()),
363 data_engine_(new cricket::FakeDataEngine()), 386 data_engine_(new cricket::FakeDataEngine()),
364 channel_manager_(new cricket::ChannelManager( 387 channel_manager_(new cricket::ChannelManager(
365 media_engine_, data_engine_, new cricket::CaptureManager(), 388 media_engine_, data_engine_, new cricket::CaptureManager(),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // If |dtls_identity_store| != null or |rtc_configuration| contains 421 // If |dtls_identity_store| != null or |rtc_configuration| contains
399 // |certificates| then DTLS will be enabled unless explicitly disabled by 422 // |certificates| then DTLS will be enabled unless explicitly disabled by
400 // |rtc_configuration| options. When DTLS is enabled a certificate will be 423 // |rtc_configuration| options. When DTLS is enabled a certificate will be
401 // used if provided, otherwise one will be generated using the 424 // used if provided, otherwise one will be generated using the
402 // |dtls_identity_store|. 425 // |dtls_identity_store|.
403 void Init( 426 void Init(
404 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store, 427 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
405 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { 428 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
406 ASSERT_TRUE(session_.get() == NULL); 429 ASSERT_TRUE(session_.get() == NULL);
407 session_.reset(new WebRtcSessionForTest( 430 session_.reset(new WebRtcSessionForTest(
408 channel_manager_.get(), rtc::Thread::Current(), 431 channel_manager_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
409 rtc::Thread::Current(), allocator_.get(), 432 allocator_.get(), &observer_, &mediastream_signaling_, &call_factory_));
410 &observer_,
411 &mediastream_signaling_));
412 433
413 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, 434 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
414 observer_.ice_connection_state_); 435 observer_.ice_connection_state_);
415 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, 436 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
416 observer_.ice_gathering_state_); 437 observer_.ice_gathering_state_);
417 438
418 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(), 439 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
419 dtls_identity_store.Pass(), 440 dtls_identity_store.Pass(),
420 rtc_configuration)); 441 rtc_configuration));
421 session_->set_metrics_observer(metrics_observer_); 442 session_->set_metrics_observer(metrics_observer_);
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 // This code is placed in a method so that it can be invoked 1142 // This code is placed in a method so that it can be invoked
1122 // by multiple tests with different allocators (e.g. with and without BUNDLE). 1143 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1123 // While running the call, this method also checks if the session goes through 1144 // While running the call, this method also checks if the session goes through
1124 // the correct sequence of ICE states when a connection is established, 1145 // the correct sequence of ICE states when a connection is established,
1125 // broken, and re-established. 1146 // broken, and re-established.
1126 // The Connection state should go: 1147 // The Connection state should go:
1127 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed 1148 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1128 // -> Failed. 1149 // -> Failed.
1129 // The Gathering state should go: New -> Gathering -> Completed. 1150 // The Gathering state should go: New -> Gathering -> Completed.
1130 1151
1131 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) { 1152 void SetupLoopbackCall() {
1132 LoopbackNetworkManager loopback_network_manager(this, config);
1133 Init(); 1153 Init();
1134 mediastream_signaling_.SendAudioVideoStream1(); 1154 mediastream_signaling_.SendAudioVideoStream1();
1135 SessionDescriptionInterface* offer = CreateOffer(); 1155 SessionDescriptionInterface* offer = CreateOffer();
1136 1156
1137 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, 1157 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1138 observer_.ice_gathering_state_); 1158 observer_.ice_gathering_state_);
1139 SetLocalDescriptionWithoutError(offer); 1159 SetLocalDescriptionWithoutError(offer);
1140 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, 1160 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1141 observer_.ice_connection_state_); 1161 observer_.ice_connection_state_);
1142 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering, 1162 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1143 observer_.ice_gathering_state_, 1163 observer_.ice_gathering_state_, kIceCandidatesTimeout);
1144 kIceCandidatesTimeout);
1145 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); 1164 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1146 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, 1165 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1147 observer_.ice_gathering_state_, 1166 observer_.ice_gathering_state_, kIceCandidatesTimeout);
1148 kIceCandidatesTimeout);
1149 1167
1150 std::string sdp; 1168 std::string sdp;
1151 offer->ToString(&sdp); 1169 offer->ToString(&sdp);
1152 SessionDescriptionInterface* desc = 1170 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1153 webrtc::CreateSessionDescription( 1171 JsepSessionDescription::kAnswer, sdp, nullptr);
1154 JsepSessionDescription::kAnswer, sdp, nullptr);
1155 ASSERT_TRUE(desc != NULL); 1172 ASSERT_TRUE(desc != NULL);
1156 SetRemoteDescriptionWithoutError(desc); 1173 SetRemoteDescriptionWithoutError(desc);
1157 1174
1158 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking, 1175 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1159 observer_.ice_connection_state_, 1176 observer_.ice_connection_state_, kIceCandidatesTimeout);
1160 kIceCandidatesTimeout);
1161 1177
1162 // The ice connection state is "Connected" too briefly to catch in a test. 1178 // The ice connection state is "Connected" too briefly to catch in a test.
1163 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, 1179 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
1164 observer_.ice_connection_state_, 1180 observer_.ice_connection_state_, kIceCandidatesTimeout);
1165 kIceCandidatesTimeout); 1181 }
1166 1182
1183 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1184 LoopbackNetworkManager loopback_network_manager(this, config);
1185 SetupLoopbackCall();
1167 config.VerifyBestConnectionAfterIceConverge(metrics_observer_); 1186 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
1168 // Adding firewall rule to block ping requests, which should cause 1187 // Adding firewall rule to block ping requests, which should cause
1169 // transport channel failure. 1188 // transport channel failure.
1170 1189
1171 loopback_network_manager.ApplyFirewallRules(fss_.get()); 1190 loopback_network_manager.ApplyFirewallRules(fss_.get());
1172 1191
1173 LOG(LS_INFO) << "Firewall Rules applied"; 1192 LOG(LS_INFO) << "Firewall Rules applied";
1174 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, 1193 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1175 observer_.ice_connection_state_, 1194 observer_.ice_connection_state_,
1176 kIceCandidatesTimeout); 1195 kIceCandidatesTimeout);
(...skipping 18 matching lines...) Expand all
1195 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, 1214 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1196 observer_.ice_connection_state_, 1215 observer_.ice_connection_state_,
1197 kIceCandidatesTimeout + port_timeout); 1216 kIceCandidatesTimeout + port_timeout);
1198 } 1217 }
1199 1218
1200 void TestLoopbackCall() { 1219 void TestLoopbackCall() {
1201 LoopbackNetworkConfiguration config; 1220 LoopbackNetworkConfiguration config;
1202 TestLoopbackCall(config); 1221 TestLoopbackCall(config);
1203 } 1222 }
1204 1223
1224 void TestPacketOptions() {
1225 LoopbackNetworkConfiguration config;
1226 LoopbackNetworkManager loopback_network_manager(this, config);
1227
1228 SetupLoopbackCall();
pthatcher1 2015/10/09 20:57:48 For testing, this would be more thorough if we mad
stefan-webrtc 2015/10/10 15:32:51 I don't think that method works, since the Content
1229
1230 uint8_t test_packet[15] = {0};
1231 rtc::PacketOptions options;
1232 options.packet_id = 10;
1233 media_engine_->GetVideoChannel(0)
1234 ->SendRtp(test_packet, sizeof(test_packet), options);
1235
1236 const int kPacketTimeout = 2000;
1237 EXPECT_EQ_WAIT(call_factory_.fake_call()->last_sent_packet().packet_id, 10,
1238 kPacketTimeout);
1239 EXPECT_GT(call_factory_.fake_call()->last_sent_packet().send_time_ms, -1);
1240 }
1241
1205 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory. 1242 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1206 void AddCNCodecs() { 1243 void AddCNCodecs() {
1207 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0); 1244 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1208 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0); 1245 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1209 1246
1210 // Add kCNCodec for dtmf test. 1247 // Add kCNCodec for dtmf test.
1211 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();; 1248 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1212 codecs.push_back(kCNCodec1); 1249 codecs.push_back(kCNCodec1);
1213 codecs.push_back(kCNCodec2); 1250 codecs.push_back(kCNCodec2);
1214 media_engine_->SetAudioCodecs(codecs); 1251 media_engine_->SetAudioCodecs(codecs);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 rtc::FakeNetworkManager network_manager_; 1351 rtc::FakeNetworkManager network_manager_;
1315 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; 1352 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
1316 PeerConnectionFactoryInterface::Options options_; 1353 PeerConnectionFactoryInterface::Options options_;
1317 rtc::scoped_ptr<FakeConstraints> constraints_; 1354 rtc::scoped_ptr<FakeConstraints> constraints_;
1318 FakeMediaStreamSignaling mediastream_signaling_; 1355 FakeMediaStreamSignaling mediastream_signaling_;
1319 rtc::scoped_ptr<WebRtcSessionForTest> session_; 1356 rtc::scoped_ptr<WebRtcSessionForTest> session_;
1320 MockIceObserver observer_; 1357 MockIceObserver observer_;
1321 cricket::FakeVideoMediaChannel* video_channel_; 1358 cricket::FakeVideoMediaChannel* video_channel_;
1322 cricket::FakeVoiceMediaChannel* voice_channel_; 1359 cricket::FakeVoiceMediaChannel* voice_channel_;
1323 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; 1360 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
1361 FakeCallFactory call_factory_;
1324 }; 1362 };
1325 1363
1326 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { 1364 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1327 InitWithDtls(GetParam()); 1365 InitWithDtls(GetParam());
1328 // SDES is disabled when DTLS is on. 1366 // SDES is disabled when DTLS is on.
1329 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); 1367 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
1330 } 1368 }
1331 1369
1332 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { 1370 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
1333 Init(); 1371 Init();
(...skipping 2691 matching lines...) Expand 10 before | Expand all | Expand 10 after
4025 4063
4026 for (auto& o : observers) { 4064 for (auto& o : observers) {
4027 // We expect to have received a notification now even if the session was 4065 // We expect to have received a notification now even if the session was
4028 // terminated. The offer creation may or may not have succeeded, but we 4066 // terminated. The offer creation may or may not have succeeded, but we
4029 // must have received a notification which, so the only invalid state 4067 // must have received a notification which, so the only invalid state
4030 // is kInit. 4068 // is kInit.
4031 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state()); 4069 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4032 } 4070 }
4033 } 4071 }
4034 4072
4073 TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4074 TestPacketOptions();
4075 }
4076
4035 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test 4077 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4036 // currently fails because upon disconnection and reconnection OnIceComplete is 4078 // currently fails because upon disconnection and reconnection OnIceComplete is
4037 // called more than once without returning to IceGatheringGathering. 4079 // called more than once without returning to IceGatheringGathering.
4038 4080
4039 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, 4081 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4040 WebRtcSessionTest, 4082 WebRtcSessionTest,
4041 testing::Values(ALREADY_GENERATED, 4083 testing::Values(ALREADY_GENERATED,
4042 DTLS_IDENTITY_STORE)); 4084 DTLS_IDENTITY_STORE));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698