Fix the turn and udp port type.
The port type was not set if it was created on a shared socket.

BUG=
R=pthatcher@webrtc.org

Review URL: https://codereview.webrtc.org/2099023002 .

Cr-Original-Commit-Position: refs/heads/master@{#13313}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: d00c05788f27e0a58298a0e0ac4132da32ea6ada
diff --git a/p2p/base/port.cc b/p2p/base/port.cc
index 55d6b87..ca162b8 100644
--- a/p2p/base/port.cc
+++ b/p2p/base/port.cc
@@ -130,6 +130,7 @@
 }
 
 Port::Port(rtc::Thread* thread,
+           const std::string& type,
            rtc::PacketSocketFactory* factory,
            rtc::Network* network,
            const rtc::IPAddress& ip,
@@ -137,6 +138,7 @@
            const std::string& password)
     : thread_(thread),
       factory_(factory),
+      type_(type),
       send_retransmit_count_attribute_(false),
       network_(network),
       ip_(ip),
diff --git a/p2p/base/port.h b/p2p/base/port.h
index 53056c1..6cae6f8 100644
--- a/p2p/base/port.h
+++ b/p2p/base/port.h
@@ -123,6 +123,7 @@
              public sigslot::has_slots<> {
  public:
   Port(rtc::Thread* thread,
+       const std::string& type,
        rtc::PacketSocketFactory* factory,
        rtc::Network* network,
        const rtc::IPAddress& ip,
diff --git a/p2p/base/stunport.cc b/p2p/base/stunport.cc
index e56d454..c25b8b1 100644
--- a/p2p/base/stunport.cc
+++ b/p2p/base/stunport.cc
@@ -168,6 +168,7 @@
                  const std::string& origin,
                  bool emit_local_for_anyaddress)
     : Port(thread,
+           LOCAL_PORT_TYPE,
            factory,
            network,
            socket->GetLocalAddress().ipaddr(),
diff --git a/p2p/base/stunport_unittest.cc b/p2p/base/stunport_unittest.cc
index e514651..522369d 100644
--- a/p2p/base/stunport_unittest.cc
+++ b/p2p/base/stunport_unittest.cc
@@ -92,7 +92,7 @@
         &StunPortTest::OnPortError);
   }
 
-  void CreateSharedStunPort(const rtc::SocketAddress& server_addr) {
+  void CreateSharedUdpPort(const rtc::SocketAddress& server_addr) {
     socket_.reset(socket_factory_.CreateUdpSocket(
         rtc::SocketAddress(kLocalAddr.ipaddr(), 0), 0, 0));
     ASSERT_TRUE(socket_ != NULL);
@@ -176,13 +176,20 @@
   int stun_keepalive_lifetime_;
 };
 
-// Test that we can create a STUN port
-TEST_F(StunPortTest, TestBasic) {
+// Test that we can create a STUN port.
+TEST_F(StunPortTest, TestCreateStunPort) {
   CreateStunPort(kStunAddr1);
   EXPECT_EQ("stun", port()->Type());
   EXPECT_EQ(0U, port()->Candidates().size());
 }
 
+// Test that we can create a UDP port.
+TEST_F(StunPortTest, TestCreateUdpPort) {
+  CreateSharedUdpPort(kStunAddr1);
+  EXPECT_EQ("local", port()->Type());
+  EXPECT_EQ(0U, port()->Candidates().size());
+}
+
 // Test that we can get an address from a STUN server.
 TEST_F(StunPortTest, TestPrepareAddress) {
   CreateStunPort(kStunAddr1);
@@ -240,7 +247,7 @@
 
 // Test that a local candidate can be generated using a shared socket.
 TEST_F(StunPortTest, TestSharedSocketPrepareAddress) {
-  CreateSharedStunPort(kStunAddr1);
+  CreateSharedUdpPort(kStunAddr1);
   PrepareAddress();
   EXPECT_TRUE_WAIT(done(), kTimeoutMs);
   ASSERT_EQ(1U, port()->Candidates().size());
@@ -251,7 +258,7 @@
 // Also verifing that UDPPort can receive packets when stun address can't be
 // resolved.
 TEST_F(StunPortTest, TestSharedSocketPrepareAddressInvalidHostname) {
-  CreateSharedStunPort(kBadHostnameAddr);
+  CreateSharedUdpPort(kBadHostnameAddr);
   PrepareAddress();
   EXPECT_TRUE_WAIT(done(), kTimeoutMs);
   ASSERT_EQ(1U, port()->Candidates().size());
@@ -333,7 +340,7 @@
 // if the network type changes.
 TEST_F(StunPortTest, TestUdpPortGetStunKeepaliveLifetime) {
   // Lifetime for the default (unknown) network type is |kInfiniteLifetime|.
-  CreateSharedStunPort(kStunAddr1);
+  CreateSharedUdpPort(kStunAddr1);
   EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime());
   // Lifetime for the cellular network is |kHighCostPortKeepaliveLifetimeMs|.
   SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR);
@@ -342,7 +349,7 @@
 
   // Lifetime for the wifi network type is |kInfiniteLifetime|.
   SetNetworkType(rtc::ADAPTER_TYPE_WIFI);
-  CreateSharedStunPort(kStunAddr2);
+  CreateSharedUdpPort(kStunAddr2);
   EXPECT_EQ(kInfiniteLifetime, port()->stun_keepalive_lifetime());
 }
 
diff --git a/p2p/base/turnport.cc b/p2p/base/turnport.cc
index 567916f..573ca90 100644
--- a/p2p/base/turnport.cc
+++ b/p2p/base/turnport.cc
@@ -190,6 +190,7 @@
                    int server_priority,
                    const std::string& origin)
     : Port(thread,
+           RELAY_PORT_TYPE,
            factory,
            network,
            socket->GetLocalAddress().ipaddr(),
diff --git a/p2p/base/turnport_unittest.cc b/p2p/base/turnport_unittest.cc
index e82f10f..edb3454 100644
--- a/p2p/base/turnport_unittest.cc
+++ b/p2p/base/turnport_unittest.cc
@@ -584,6 +584,11 @@
   rtc::PacketOptions options;
 };
 
+TEST_F(TurnPortTest, TestTurnPortType) {
+  CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);
+  EXPECT_EQ(cricket::RELAY_PORT_TYPE, turn_port_->Type());
+}
+
 // Do a normal TURN allocation.
 TEST_F(TurnPortTest, TestTurnAllocate) {
   CreateTurnPort(kTurnUsername, kTurnPassword, kTurnUdpProtoAddr);