| Index: webrtc/p2p/base/p2ptransportchannel_unittest.cc
 | 
| diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
 | 
| index cbf5e76a7ae23a13376e6f8aa76ad10559978fbe..eae595aefea5f53754a26ab259c97e5d936ca2c6 100644
 | 
| --- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc
 | 
| +++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
 | 
| @@ -18,6 +18,7 @@
 | 
|  #include "webrtc/p2p/base/testturnserver.h"
 | 
|  #include "webrtc/p2p/client/basicportallocator.h"
 | 
|  #include "webrtc/base/dscp.h"
 | 
| +#include "webrtc/base/fakeclock.h"
 | 
|  #include "webrtc/base/fakenetwork.h"
 | 
|  #include "webrtc/base/firewallsocketserver.h"
 | 
|  #include "webrtc/base/gunit.h"
 | 
| @@ -2686,6 +2687,85 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
 | 
|    EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
 | 
|  }
 | 
|  
 | 
| +// Test that the ICE role is updated even on ports with inactive networks when
 | 
| +// doing continual gathering. These ports may still have connections that need
 | 
| +// a correct role, in case the network becomes active before the connection is
 | 
| +// destroyed.
 | 
| +TEST_F(P2PTransportChannelPingTest,
 | 
| +       TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) {
 | 
| +  cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
 | 
| +  cricket::P2PTransportChannel ch(
 | 
| +      "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
 | 
| +  // Starts with ICEROLE_CONTROLLING.
 | 
| +  PrepareChannel(&ch);
 | 
| +  cricket::IceConfig config = CreateIceConfig(1000, true);
 | 
| +  ch.SetIceConfig(config);
 | 
| +  ch.Connect();
 | 
| +  ch.MaybeStartGathering();
 | 
| +  ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
 | 
| +
 | 
| +  cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
 | 
| +  ASSERT_TRUE(conn != nullptr);
 | 
| +
 | 
| +  // Make the fake port signal that its network is inactive, then change the
 | 
| +  // ICE role and expect it to be updated.
 | 
| +  conn->port()->SignalNetworkInactive(conn->port());
 | 
| +  ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
 | 
| +  EXPECT_EQ(cricket::ICEROLE_CONTROLLED, conn->port()->GetIceRole());
 | 
| +}
 | 
| +
 | 
| +// Test that the ICE role is updated even on ports with inactive networks.
 | 
| +// These ports may still have connections that need a correct role, for the
 | 
| +// pings sent by those connections until they're replaced by newer-generation
 | 
| +// connections.
 | 
| +TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) {
 | 
| +  cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
 | 
| +  cricket::P2PTransportChannel ch(
 | 
| +      "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
 | 
| +  // Starts with ICEROLE_CONTROLLING.
 | 
| +  PrepareChannel(&ch);
 | 
| +  ch.Connect();
 | 
| +  ch.MaybeStartGathering();
 | 
| +  ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
 | 
| +
 | 
| +  cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
 | 
| +  ASSERT_TRUE(conn != nullptr);
 | 
| +
 | 
| +  // Do an ICE restart, change the role, and expect the old port to have its
 | 
| +  // role updated.
 | 
| +  ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
 | 
| +  ch.MaybeStartGathering();
 | 
| +  ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
 | 
| +  EXPECT_EQ(cricket::ICEROLE_CONTROLLED, conn->port()->GetIceRole());
 | 
| +}
 | 
| +
 | 
| +// Test that after some amount of time without receiving data, the connection
 | 
| +// and port are destroyed.
 | 
| +TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) {
 | 
| +  rtc::ScopedFakeClock fake_clock;
 | 
| +
 | 
| +  cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
 | 
| +  cricket::P2PTransportChannel ch(
 | 
| +      "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
 | 
| +  PrepareChannel(&ch);
 | 
| +  // Only a controlled channel should expect its ports to be destroyed.
 | 
| +  ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
 | 
| +  ch.Connect();
 | 
| +  ch.MaybeStartGathering();
 | 
| +  ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
 | 
| +
 | 
| +  cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
 | 
| +  ASSERT_TRUE(conn != nullptr);
 | 
| +
 | 
| +  // Simulate 2 minutes going by. This should be enough time for the port to
 | 
| +  // time out.
 | 
| +  for (int second = 0; second < 120; ++second) {
 | 
| +    fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
 | 
| +  }
 | 
| +  EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1));
 | 
| +  EXPECT_EQ(nullptr, GetPort(&ch));
 | 
| +}
 | 
| +
 | 
|  class P2PTransportChannelMostLikelyToWorkFirstTest
 | 
|      : public P2PTransportChannelPingTest {
 | 
|   public:
 | 
| 
 |