Chromium Code Reviews| Index: talk/app/webrtc/webrtcsession_unittest.cc |
| diff --git a/talk/app/webrtc/webrtcsession_unittest.cc b/talk/app/webrtc/webrtcsession_unittest.cc |
| index 2853ca43a7301b5e28b202f60041f35784342bb2..6ad77dc7b1eb73bd971ae35ac0b08dab125dae25 100644 |
| --- a/talk/app/webrtc/webrtcsession_unittest.cc |
| +++ b/talk/app/webrtc/webrtcsession_unittest.cc |
| @@ -42,6 +42,7 @@ |
| #include "talk/media/base/fakemediaengine.h" |
| #include "talk/media/base/fakevideorenderer.h" |
| #include "talk/media/base/mediachannel.h" |
| +#include "talk/media/webrtc/fakewebrtccall.h" |
| #include "webrtc/p2p/base/stunserver.h" |
| #include "webrtc/p2p/base/teststunserver.h" |
| #include "webrtc/p2p/base/testturnserver.h" |
| @@ -238,9 +239,14 @@ class WebRtcSessionForTest : public webrtc::WebRtcSession { |
| rtc::Thread* worker_thread, |
| cricket::PortAllocator* port_allocator, |
| webrtc::IceObserver* ice_observer, |
| - webrtc::MediaStreamSignaling* mediastream_signaling) |
| - : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator, |
| - mediastream_signaling) { |
| + webrtc::MediaStreamSignaling* mediastream_signaling, |
| + webrtc::CallFactory* call_factory) |
| + : WebRtcSession(cmgr, |
| + signaling_thread, |
| + worker_thread, |
| + port_allocator, |
| + mediastream_signaling, |
| + call_factory) { |
| RegisterIceObserver(ice_observer); |
| } |
| virtual ~WebRtcSessionForTest() {} |
| @@ -353,6 +359,23 @@ class FakeAudioRenderer : public cricket::AudioRenderer { |
| cricket::AudioRenderer::Sink* sink_; |
| }; |
| +class FakeCallFactory : public webrtc::CallFactory { |
| + public: |
| + FakeCallFactory() : fake_call_(nullptr) {} |
| + |
| + webrtc::Call* CreateCall(const webrtc::Call::Config& config) override { |
| + fake_call_ = new cricket::FakeCall(config); |
| + return fake_call_; |
| + } |
| + |
| + cricket::FakeCall* fake_call() const { return fake_call_; } |
| + |
| + private: |
| + // Since ownership of fake_call_ is handed over to the caller of CreateCall, |
| + // this pointer is only valid until the caller has deleted it. |
| + cricket::FakeCall* fake_call_; |
| +}; |
| + |
| class WebRtcSessionTest |
| : public testing::TestWithParam<RTCCertificateGenerationMethod> { |
| protected: |
| @@ -405,10 +428,8 @@ class WebRtcSessionTest |
| const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { |
| ASSERT_TRUE(session_.get() == NULL); |
| session_.reset(new WebRtcSessionForTest( |
| - channel_manager_.get(), rtc::Thread::Current(), |
| - rtc::Thread::Current(), allocator_.get(), |
| - &observer_, |
| - &mediastream_signaling_)); |
| + channel_manager_.get(), rtc::Thread::Current(), rtc::Thread::Current(), |
| + allocator_.get(), &observer_, &mediastream_signaling_, &call_factory_)); |
| EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| observer_.ice_connection_state_); |
| @@ -1128,8 +1149,7 @@ class WebRtcSessionTest |
| // -> Failed. |
| // The Gathering state should go: New -> Gathering -> Completed. |
| - void TestLoopbackCall(const LoopbackNetworkConfiguration& config) { |
| - LoopbackNetworkManager loopback_network_manager(this, config); |
| + void SetupLoopbackCall() { |
| Init(); |
| mediastream_signaling_.SendAudioVideoStream1(); |
| SessionDescriptionInterface* offer = CreateOffer(); |
| @@ -1140,30 +1160,29 @@ class WebRtcSessionTest |
| EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| observer_.ice_connection_state_); |
| EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering, |
| - observer_.ice_gathering_state_, |
| - kIceCandidatesTimeout); |
| + observer_.ice_gathering_state_, kIceCandidatesTimeout); |
| EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| - observer_.ice_gathering_state_, |
| - kIceCandidatesTimeout); |
| + observer_.ice_gathering_state_, kIceCandidatesTimeout); |
| std::string sdp; |
| offer->ToString(&sdp); |
| - SessionDescriptionInterface* desc = |
| - webrtc::CreateSessionDescription( |
| - JsepSessionDescription::kAnswer, sdp, nullptr); |
| + SessionDescriptionInterface* desc = webrtc::CreateSessionDescription( |
| + JsepSessionDescription::kAnswer, sdp, nullptr); |
| ASSERT_TRUE(desc != NULL); |
| SetRemoteDescriptionWithoutError(desc); |
| EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking, |
| - observer_.ice_connection_state_, |
| - kIceCandidatesTimeout); |
| + observer_.ice_connection_state_, kIceCandidatesTimeout); |
| // The ice connection state is "Connected" too briefly to catch in a test. |
| EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| - observer_.ice_connection_state_, |
| - kIceCandidatesTimeout); |
| + observer_.ice_connection_state_, kIceCandidatesTimeout); |
| + } |
| + void TestLoopbackCall(const LoopbackNetworkConfiguration& config) { |
| + LoopbackNetworkManager loopback_network_manager(this, config); |
| + SetupLoopbackCall(); |
| config.VerifyBestConnectionAfterIceConverge(metrics_observer_); |
| // Adding firewall rule to block ping requests, which should cause |
| // transport channel failure. |
| @@ -1202,6 +1221,24 @@ class WebRtcSessionTest |
| TestLoopbackCall(config); |
| } |
| + void TestPacketOptions() { |
| + LoopbackNetworkConfiguration config; |
| + LoopbackNetworkManager loopback_network_manager(this, config); |
| + |
| + 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
|
| + |
| + uint8_t test_packet[15] = {0}; |
| + rtc::PacketOptions options; |
| + options.packet_id = 10; |
| + media_engine_->GetVideoChannel(0) |
| + ->SendRtp(test_packet, sizeof(test_packet), options); |
| + |
| + const int kPacketTimeout = 2000; |
| + EXPECT_EQ_WAIT(call_factory_.fake_call()->last_sent_packet().packet_id, 10, |
| + kPacketTimeout); |
| + EXPECT_GT(call_factory_.fake_call()->last_sent_packet().send_time_ms, -1); |
| + } |
| + |
| // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory. |
| void AddCNCodecs() { |
| const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0); |
| @@ -1321,6 +1358,7 @@ class WebRtcSessionTest |
| cricket::FakeVideoMediaChannel* video_channel_; |
| cricket::FakeVoiceMediaChannel* voice_channel_; |
| rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; |
| + FakeCallFactory call_factory_; |
| }; |
| TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { |
| @@ -4032,6 +4070,10 @@ TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) { |
| } |
| } |
| +TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) { |
| + TestPacketOptions(); |
| +} |
| + |
| // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| // currently fails because upon disconnection and reconnection OnIceComplete is |
| // called more than once without returning to IceGatheringGathering. |