Chromium Code Reviews| Index: webrtc/p2p/base/port_unittest.cc | 
| diff --git a/webrtc/p2p/base/port_unittest.cc b/webrtc/p2p/base/port_unittest.cc | 
| index ecd5c416c72a565527fae260aed1652ff9408997..9ab7cb234e2dc8f3e5b90737177a6816c2559217 100644 | 
| --- a/webrtc/p2p/base/port_unittest.cc | 
| +++ b/webrtc/p2p/base/port_unittest.cc | 
| @@ -222,6 +222,23 @@ class TestPort : public Port { | 
| int type_preference_ = 0; | 
| }; | 
| +static void SendPingAndReceiveResponse( | 
| + Connection* lconn, TestPort* lport, Connection* rconn, TestPort* rport, | 
| + rtc::ScopedFakeClock* clock, int64_t ms) { | 
| + lconn->Ping(rtc::TimeMillis()); | 
| + ASSERT_TRUE_WAIT(lport->last_stun_msg(), kDefaultTimeout); | 
| + ASSERT_TRUE(lport->last_stun_buf()); | 
| + rconn->OnReadPacket(lport->last_stun_buf()->data<char>(), | 
| 
 
Taylor Brandstetter
2017/02/27 22:21:09
OnReadPacket is also something that should be priv
 
hbos
2017/02/28 13:59:08
Acknowledged.
 
 | 
| + lport->last_stun_buf()->size(), | 
| + rtc::PacketTime()); | 
| + clock->AdvanceTime(rtc::TimeDelta::FromMilliseconds(ms)); | 
| + ASSERT_TRUE_WAIT(rport->last_stun_msg(), kDefaultTimeout); | 
| + ASSERT_TRUE(rport->last_stun_buf()); | 
| + lconn->OnReadPacket(rport->last_stun_buf()->data<char>(), | 
| + rport->last_stun_buf()->size(), | 
| + rtc::PacketTime()); | 
| +} | 
| + | 
| class TestChannel : public sigslot::has_slots<> { | 
| public: | 
| // Takes ownership of |p1| (but not |p2|). | 
| @@ -1844,6 +1861,49 @@ TEST_F(PortTest, TestNomination) { | 
| EXPECT_EQ(rconn->nominated(), rconn->stats().nominated); | 
| } | 
| +TEST_F(PortTest, TestRoundTripTime) { | 
| + rtc::ScopedFakeClock clock; | 
| + | 
| + std::unique_ptr<TestPort> lport( | 
| + CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 
| + std::unique_ptr<TestPort> rport( | 
| + CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 
| + lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 
| + lport->SetIceTiebreaker(kTiebreaker1); | 
| + rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 
| + rport->SetIceTiebreaker(kTiebreaker2); | 
| + | 
| + lport->PrepareAddress(); | 
| + rport->PrepareAddress(); | 
| + ASSERT_FALSE(lport->Candidates().empty()); | 
| + ASSERT_FALSE(rport->Candidates().empty()); | 
| + Connection* lconn = lport->CreateConnection(rport->Candidates()[0], | 
| + Port::ORIGIN_MESSAGE); | 
| + Connection* rconn = rport->CreateConnection(lport->Candidates()[0], | 
| + Port::ORIGIN_MESSAGE); | 
| + | 
| + EXPECT_EQ(lconn->stats().total_round_trip_time_ms, 0u); | 
| 
 
Taylor Brandstetter
2017/02/27 22:21:09
nit: The expected value (0) goes before the measur
 
hbos
2017/02/28 13:59:08
Done.
 
 | 
| + EXPECT_FALSE(lconn->stats().current_round_trip_time_ms); | 
| + | 
| + SendPingAndReceiveResponse( | 
| + lconn, lport.get(), rconn, rport.get(), &clock, 10); | 
| + EXPECT_EQ(lconn->stats().total_round_trip_time_ms, 10u); | 
| + ASSERT_TRUE(lconn->stats().current_round_trip_time_ms); | 
| + EXPECT_EQ(*lconn->stats().current_round_trip_time_ms, 10u); | 
| + | 
| + SendPingAndReceiveResponse( | 
| + lconn, lport.get(), rconn, rport.get(), &clock, 20); | 
| + EXPECT_EQ(lconn->stats().total_round_trip_time_ms, 30u); | 
| + ASSERT_TRUE(lconn->stats().current_round_trip_time_ms); | 
| + EXPECT_EQ(*lconn->stats().current_round_trip_time_ms, 20u); | 
| + | 
| + SendPingAndReceiveResponse( | 
| + lconn, lport.get(), rconn, rport.get(), &clock, 30); | 
| + EXPECT_EQ(lconn->stats().total_round_trip_time_ms, 60u); | 
| + ASSERT_TRUE(lconn->stats().current_round_trip_time_ms); | 
| + EXPECT_EQ(*lconn->stats().current_round_trip_time_ms, 30u); | 
| +} | 
| + | 
| TEST_F(PortTest, TestUseCandidateAttribute) { | 
| std::unique_ptr<TestPort> lport( | 
| CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |