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

Side by Side Diff: webrtc/p2p/base/tcpport_unittest.cc

Issue 2834083002: Fixing SignalSentPacket for TCP connections. (Closed)
Patch Set: Don't crash if socket wasn't created successfully. Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/tcpport.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 std::unique_ptr<TCPPort> lport(CreateTCPPort(kLocalAddr)); 78 std::unique_ptr<TCPPort> lport(CreateTCPPort(kLocalAddr));
79 std::unique_ptr<TCPPort> rport(CreateTCPPort(kRemoteAddr)); 79 std::unique_ptr<TCPPort> rport(CreateTCPPort(kRemoteAddr));
80 lport->PrepareAddress(); 80 lport->PrepareAddress();
81 rport->PrepareAddress(); 81 rport->PrepareAddress();
82 // Start to listen to new socket creation event. 82 // Start to listen to new socket creation event.
83 ConnectSignalSocketCreated(); 83 ConnectSignalSocketCreated();
84 Connection* conn = 84 Connection* conn =
85 lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE); 85 lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE);
86 EXPECT_TRUE_WAIT(conn->connected(), kTimeout); 86 EXPECT_TRUE_WAIT(conn->connected(), kTimeout);
87 } 87 }
88
89 class SentPacketCounter : public sigslot::has_slots<> {
90 public:
91 SentPacketCounter(TCPPort* p) {
92 p->SignalSentPacket.connect(this, &SentPacketCounter::OnSentPacket);
93 }
94
95 int sent_packets() const { return sent_packets_; }
96
97 private:
98 void OnSentPacket(const rtc::SentPacket&) { ++sent_packets_; }
99
100 int sent_packets_ = 0;
101 };
102
103 // Test that SignalSentPacket is fired when a packet is successfully sent, for
104 // both TCP client and server sockets.
105 TEST_F(TCPPortTest, SignalSentPacket) {
106 std::unique_ptr<TCPPort> client(CreateTCPPort(kLocalAddr));
107 std::unique_ptr<TCPPort> server(CreateTCPPort(kRemoteAddr));
108 client->SetIceRole(cricket::ICEROLE_CONTROLLING);
109 server->SetIceRole(cricket::ICEROLE_CONTROLLED);
110 client->PrepareAddress();
111 server->PrepareAddress();
112
113 Connection* client_conn =
114 client->CreateConnection(server->Candidates()[0], Port::ORIGIN_MESSAGE);
115 ASSERT_NE(nullptr, client_conn);
116 ASSERT_TRUE_WAIT(client_conn->connected(), kTimeout);
117
118 // Need to get the port of the actual outgoing socket, not the server socket..
119 cricket::Candidate client_candidate = client->Candidates()[0];
120 client_candidate.set_address(static_cast<cricket::TCPConnection*>(client_conn)
121 ->socket()
122 ->GetLocalAddress());
123 Connection* server_conn =
124 server->CreateConnection(client_candidate, Port::ORIGIN_THIS_PORT);
125 ASSERT_NE(nullptr, server_conn);
126 ASSERT_TRUE_WAIT(server_conn->connected(), kTimeout);
127
128 client_conn->Ping(rtc::TimeMillis());
129 server_conn->Ping(rtc::TimeMillis());
130 ASSERT_TRUE_WAIT(client_conn->writable(), kTimeout);
131 ASSERT_TRUE_WAIT(server_conn->writable(), kTimeout);
132
133 SentPacketCounter client_counter(client.get());
134 SentPacketCounter server_counter(server.get());
135 static const char kData[] = "hello";
136 for (int i = 0; i < 10; ++i) {
137 client_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
138 server_conn->Send(&kData, sizeof(kData), rtc::PacketOptions());
139 }
140 EXPECT_EQ_WAIT(10, client_counter.sent_packets(), kTimeout);
141 EXPECT_EQ_WAIT(10, server_counter.sent_packets(), kTimeout);
142 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/tcpport.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698