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

Unified Diff: webrtc/p2p/base/port_unittest.cc

Issue 2063823008: Adding IceConfig option to assume TURN/TURN candidate pairs will work. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Responding to comments. Doing "presumed writable" determination in Connection. Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/p2p/base/port_unittest.cc
diff --git a/webrtc/p2p/base/port_unittest.cc b/webrtc/p2p/base/port_unittest.cc
index a345e82b6133fc6c5eb7dfacecedb801e238a932..b8433a8684d06cb3313b54bffbb98ceff50a962f 100644
--- a/webrtc/p2p/base/port_unittest.cc
+++ b/webrtc/p2p/base/port_unittest.cc
@@ -142,13 +142,13 @@ class TestPort : public Port {
return code;
}
- virtual void PrepareAddress() {
+ void PrepareAddress() override {
rtc::SocketAddress addr(ip(), min_port());
AddAddress(addr, addr, rtc::SocketAddress(), "udp", "", "", Type(),
ICE_TYPE_PREFERENCE_HOST, 0, true);
}
- virtual bool SupportsProtocol(const std::string& protocol) const {
+ bool SupportsProtocol(const std::string& protocol) const override {
return true;
}
@@ -166,18 +166,21 @@ class TestPort : public Port {
type_preference, 0, final);
}
- virtual Connection* CreateConnection(const Candidate& remote_candidate,
- CandidateOrigin origin) {
- Connection* conn = new ProxyConnection(this, 0, remote_candidate);
+ Connection* CreateConnection(const Candidate& remote_candidate,
+ CandidateOrigin origin,
+ const IceConfig& config) override {
+ Connection* conn = new ProxyConnection(this, 0, remote_candidate, config);
AddOrReplaceConnection(conn);
// Set use-candidate attribute flag as this will add USE-CANDIDATE attribute
// in STUN binding requests.
conn->set_use_candidate_attr(true);
return conn;
}
- virtual int SendTo(
- const void* data, size_t size, const rtc::SocketAddress& addr,
- const rtc::PacketOptions& options, bool payload) {
+ int SendTo(const void* data,
+ size_t size,
+ const rtc::SocketAddress& addr,
+ const rtc::PacketOptions& options,
+ bool payload) override {
if (!payload) {
IceMessage* msg = new IceMessage;
Buffer* buf = new Buffer(static_cast<const char*>(data), size);
@@ -192,15 +195,9 @@ class TestPort : public Port {
}
return static_cast<int>(size);
}
- virtual int SetOption(rtc::Socket::Option opt, int value) {
- return 0;
- }
- virtual int GetOption(rtc::Socket::Option opt, int* value) {
- return -1;
- }
- virtual int GetError() {
- return 0;
- }
+ int SetOption(rtc::Socket::Option opt, int value) override { return 0; }
+ int GetOption(rtc::Socket::Option opt, int* value) override { return -1; }
+ int GetError() override { return 0; }
void Reset() {
last_stun_buf_.reset();
last_stun_msg_.reset();
@@ -211,7 +208,7 @@ class TestPort : public Port {
private:
void OnSentPacket(rtc::AsyncPacketSocket* socket,
- const rtc::SentPacket& sent_packet) {
+ const rtc::SentPacket& sent_packet) override {
PortInterface::SignalSentPacket(sent_packet);
}
std::unique_ptr<Buffer> last_stun_buf_;
@@ -241,7 +238,8 @@ class TestChannel : public sigslot::has_slots<> {
void Start() { port_->PrepareAddress(); }
void CreateConnection(const Candidate& remote_candidate) {
- conn_ = port_->CreateConnection(remote_candidate, Port::ORIGIN_MESSAGE);
+ conn_ = port_->CreateConnection(remote_candidate, Port::ORIGIN_MESSAGE,
+ IceConfig());
IceMode remote_ice_mode =
(ice_mode_ == ICEMODE_FULL) ? ICEMODE_LITE : ICEMODE_FULL;
conn_->set_remote_ice_mode(remote_ice_mode);
@@ -263,7 +261,7 @@ class TestChannel : public sigslot::has_slots<> {
ASSERT_TRUE(remote_request_.get() != NULL);
Candidate c = remote_candidate;
c.set_address(remote_address_);
- conn_ = port_->CreateConnection(c, Port::ORIGIN_MESSAGE);
+ conn_ = port_->CreateConnection(c, Port::ORIGIN_MESSAGE, IceConfig());
conn_->SignalDestroyed.connect(this, &TestChannel::OnDestroyed);
port_->SendBindingResponse(remote_request_.get(), remote_address_);
remote_request_.reset();
@@ -981,33 +979,30 @@ class FakeAsyncPacketSocket : public AsyncPacketSocket {
public:
// Returns current local address. Address may be set to NULL if the
// socket is not bound yet (GetState() returns STATE_BINDING).
- virtual SocketAddress GetLocalAddress() const {
- return SocketAddress();
- }
+ SocketAddress GetLocalAddress() const override { return SocketAddress(); }
// Returns remote address. Returns zeroes if this is not a client TCP socket.
- virtual SocketAddress GetRemoteAddress() const {
- return SocketAddress();
- }
+ SocketAddress GetRemoteAddress() const override { return SocketAddress(); }
// Send a packet.
- virtual int Send(const void *pv, size_t cb,
- const rtc::PacketOptions& options) {
+ int Send(const void* pv,
+ size_t cb,
+ const rtc::PacketOptions& options) override {
return static_cast<int>(cb);
}
- virtual int SendTo(const void *pv, size_t cb, const SocketAddress& addr,
- const rtc::PacketOptions& options) {
+ int SendTo(const void* pv,
+ size_t cb,
+ const SocketAddress& addr,
+ const rtc::PacketOptions& options) override {
return static_cast<int>(cb);
}
- virtual int Close() {
- return 0;
- }
+ int Close() override { return 0; }
- virtual State GetState() const { return state_; }
- virtual int GetOption(Socket::Option opt, int* value) { return 0; }
- virtual int SetOption(Socket::Option opt, int value) { return 0; }
- virtual int GetError() const { return 0; }
- virtual void SetError(int error) { }
+ State GetState() const override { return state_; }
+ int GetOption(Socket::Option opt, int* value) override { return 0; }
+ int SetOption(Socket::Option opt, int value) override { return 0; }
+ int GetError() const override { return 0; }
+ void SetError(int error) override {}
void set_state(State state) { state_ = state; }
@@ -1331,7 +1326,7 @@ TEST_F(PortTest, TestLoopbackCal) {
lport->PrepareAddress();
ASSERT_FALSE(lport->Candidates().empty());
Connection* conn = lport->CreateConnection(lport->Candidates()[0],
- Port::ORIGIN_MESSAGE);
+ Port::ORIGIN_MESSAGE, IceConfig());
conn->Ping(0);
ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
@@ -1349,8 +1344,8 @@ TEST_F(PortTest, TestLoopbackCal) {
lport->Reset();
lport->AddCandidateAddress(kLocalAddr2);
// Creating a different connection as |conn| is receiving.
- Connection* conn1 = lport->CreateConnection(lport->Candidates()[1],
- Port::ORIGIN_MESSAGE);
+ Connection* conn1 = lport->CreateConnection(
+ lport->Candidates()[1], Port::ORIGIN_MESSAGE, IceConfig());
conn1->Ping(0);
ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
@@ -1397,10 +1392,10 @@ TEST_F(PortTest, TestIceRoleConflict) {
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);
+ Connection* lconn = lport->CreateConnection(
+ rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
+ Connection* rconn = rport->CreateConnection(
+ lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
rconn->Ping(0);
ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000);
@@ -1486,11 +1481,11 @@ void PortTest::TestCrossFamilyPorts(int type) {
factory.set_next_client_tcp_socket(clientsocket);
}
Connection* c = ports[0]->CreateConnection(GetCandidate(ports[2].get()),
- Port::ORIGIN_MESSAGE);
+ Port::ORIGIN_MESSAGE, IceConfig());
EXPECT_TRUE(NULL == c);
EXPECT_EQ(0U, ports[0]->connections().size());
c = ports[0]->CreateConnection(GetCandidate(ports[1].get()),
- Port::ORIGIN_MESSAGE);
+ Port::ORIGIN_MESSAGE, IceConfig());
EXPECT_FALSE(NULL == c);
EXPECT_EQ(1U, ports[0]->connections().size());
@@ -1500,11 +1495,11 @@ void PortTest::TestCrossFamilyPorts(int type) {
factory.set_next_client_tcp_socket(clientsocket);
}
c = ports[2]->CreateConnection(GetCandidate(ports[0].get()),
- Port::ORIGIN_MESSAGE);
+ Port::ORIGIN_MESSAGE, IceConfig());
EXPECT_TRUE(NULL == c);
EXPECT_EQ(0U, ports[2]->connections().size());
c = ports[2]->CreateConnection(GetCandidate(ports[3].get()),
- Port::ORIGIN_MESSAGE);
+ Port::ORIGIN_MESSAGE, IceConfig());
EXPECT_FALSE(NULL == c);
EXPECT_EQ(1U, ports[2]->connections().size());
}
@@ -1518,8 +1513,8 @@ TEST_F(PortTest, TestSkipCrossFamilyUdp) {
}
void PortTest::ExpectPortsCanConnect(bool can_connect, Port* p1, Port* p2) {
- Connection* c = p1->CreateConnection(GetCandidate(p2),
- Port::ORIGIN_MESSAGE);
+ Connection* c =
+ p1->CreateConnection(GetCandidate(p2), Port::ORIGIN_MESSAGE, IceConfig());
if (can_connect) {
EXPECT_FALSE(NULL == c);
EXPECT_EQ(1U, p1->connections().size());
@@ -1612,9 +1607,9 @@ TEST_F(PortTest, TestSendStunMessage) {
rport->PrepareAddress();
ASSERT_FALSE(rport->Candidates().empty());
Connection* lconn = lport->CreateConnection(
- rport->Candidates()[0], Port::ORIGIN_MESSAGE);
+ rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
Connection* rconn = rport->CreateConnection(
- lport->Candidates()[0], Port::ORIGIN_MESSAGE);
+ lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
lconn->Ping(0);
// Check that it's a proper BINDING-REQUEST.
@@ -1777,7 +1772,7 @@ TEST_F(PortTest, TestUseCandidateAttribute) {
rport->PrepareAddress();
ASSERT_FALSE(rport->Candidates().empty());
Connection* lconn = lport->CreateConnection(
- rport->Candidates()[0], Port::ORIGIN_MESSAGE);
+ rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
lconn->Ping(0);
ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
IceMessage* msg = lport->last_stun_msg();
@@ -1819,8 +1814,8 @@ TEST_F(PortTest, TestNetworkCostChange) {
}
// Add a connection and then change the network type.
- Connection* lconn =
- lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
+ Connection* lconn = lport->CreateConnection(
+ rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
// Change the network type to cellular.
SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR);
EXPECT_EQ(rtc::kNetworkCostHigh, lport->network_cost());
@@ -1829,8 +1824,8 @@ TEST_F(PortTest, TestNetworkCostChange) {
}
SetNetworkType(rtc::ADAPTER_TYPE_WIFI);
- Connection* rconn =
- rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE);
+ Connection* rconn = rport->CreateConnection(
+ lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR);
lconn->Ping(0);
// The rconn's remote candidate cost is rtc::kNetworkCostLow, but the ping
@@ -1864,8 +1859,8 @@ TEST_F(PortTest, TestNetworkInfoAttribute) {
// Send a fake ping from lport to rport.
lport->PrepareAddress();
rport->PrepareAddress();
- Connection* lconn =
- lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
+ Connection* lconn = lport->CreateConnection(
+ rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
lconn->Ping(0);
ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
IceMessage* msg = lport->last_stun_msg();
@@ -1882,8 +1877,8 @@ TEST_F(PortTest, TestNetworkInfoAttribute) {
SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR);
uint16_t rnetwork_id = 8;
rport->Network()->set_id(rnetwork_id);
- Connection* rconn =
- rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE);
+ Connection* rconn = rport->CreateConnection(
+ lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
rconn->Ping(0);
ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000);
msg = rport->last_stun_msg();
@@ -2151,10 +2146,10 @@ TEST_F(PortTest, TestHandleStunBindingIndication) {
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);
+ Connection* lconn = lport->CreateConnection(
+ rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
+ Connection* rconn = rport->CreateConnection(
+ lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
rconn->Ping(0);
ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000);
@@ -2382,7 +2377,7 @@ TEST_F(PortTest, TestConnectionPriority) {
lport->SetIceRole(cricket::ICEROLE_CONTROLLING);
rport->SetIceRole(cricket::ICEROLE_CONTROLLED);
Connection* lconn = lport->CreateConnection(
- rport->Candidates()[0], Port::ORIGIN_MESSAGE);
+ rport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
#if defined(WEBRTC_WIN)
EXPECT_EQ(0x2001EE9FC003D0BU, lconn->priority());
#else
@@ -2392,7 +2387,7 @@ TEST_F(PortTest, TestConnectionPriority) {
lport->SetIceRole(cricket::ICEROLE_CONTROLLED);
rport->SetIceRole(cricket::ICEROLE_CONTROLLING);
Connection* rconn = rport->CreateConnection(
- lport->Candidates()[0], Port::ORIGIN_MESSAGE);
+ lport->Candidates()[0], Port::ORIGIN_MESSAGE, IceConfig());
#if defined(WEBRTC_WIN)
EXPECT_EQ(0x2001EE9FC003D0AU, rconn->priority());
#else
@@ -2538,8 +2533,8 @@ TEST_F(PortTest, TestIceLiteConnectivity) {
// NOTE: Ideally we should't create connection at this stage from lite
// port, as it should be done only after receiving ping with USE_CANDIDATE.
// But we need a connection to send a response message.
- ice_lite_port->CreateConnection(
- ice_full_port->Candidates()[0], cricket::Port::ORIGIN_MESSAGE);
+ ice_lite_port->CreateConnection(ice_full_port->Candidates()[0],
+ cricket::Port::ORIGIN_MESSAGE, IceConfig());
std::unique_ptr<IceMessage> request(CopyStunMessage(msg));
ice_lite_port->SendBindingResponse(
request.get(), ice_full_port->Candidates()[0].address());
@@ -2699,7 +2694,7 @@ TEST_F(PortTest, TestAddConnectionWithSameAddress) {
rtc::SocketAddress address("1.1.1.1", 5000);
cricket::Candidate candidate(1, "udp", address, 0, "", "", "relay", 0, "");
cricket::Connection* conn1 =
- port->CreateConnection(candidate, Port::ORIGIN_MESSAGE);
+ port->CreateConnection(candidate, Port::ORIGIN_MESSAGE, IceConfig());
cricket::Connection* conn_in_use = port->GetConnection(address);
EXPECT_EQ(conn1, conn_in_use);
EXPECT_EQ(0u, conn_in_use->remote_candidate().generation());
@@ -2708,7 +2703,7 @@ TEST_F(PortTest, TestAddConnectionWithSameAddress) {
// different connection with the new candidate.
candidate.set_generation(2);
cricket::Connection* conn2 =
- port->CreateConnection(candidate, Port::ORIGIN_MESSAGE);
+ port->CreateConnection(candidate, Port::ORIGIN_MESSAGE, IceConfig());
EXPECT_NE(conn1, conn2);
conn_in_use = port->GetConnection(address);
EXPECT_EQ(conn2, conn_in_use);

Powered by Google App Engine
This is Rietveld 408576698