Index: webrtc/p2p/base/p2ptransportchannel_unittest.cc |
diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
index e2aba9a8d5e786abc43704d1c725db6ca273e3ed..e1a652aa3d6dab151393430d8bf0a2f92f7708f2 100644 |
--- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
+++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc |
@@ -1673,6 +1673,9 @@ TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) { |
// Test that when the "presume_writable_when_fully_relayed" flag is set to |
// true and there's a TURN-TURN candidate pair, it's presumed to be writable |
// as soon as it's created. |
+// TODO(deadbeef): Move this and other "presumed writable" tests into a test |
+// class that operates on a single P2PTransportChannel, once an appropriate one |
+// (which supports TURN servers and TURN candidate gathering) is available. |
TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) { |
ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
kDefaultPortAllocatorFlags); |
@@ -1798,6 +1801,42 @@ TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) { |
DestroyChannels(); |
} |
+// Ensure that "SignalReadyToSend" is fired as expected with a "presumed |
+// writable" connection. Previously this did not work. |
+TEST_F(P2PTransportChannelTest, SignalReadyToSendWithPresumedWritable) { |
+ ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
+ kDefaultPortAllocatorFlags); |
+ // Only test one endpoint, so we can ensure the connection doesn't receive a |
+ // binding response and advance beyond being "presumed" writable. |
+ GetEndpoint(0)->cd1_.ch_.reset(CreateChannel( |
+ 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1])); |
+ IceConfig config; |
+ config.presume_writable_when_fully_relayed = true; |
+ ep1_ch1()->SetIceConfig(config); |
+ ep1_ch1()->MaybeStartGathering(); |
+ EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, |
+ ep1_ch1()->gathering_state(), kDefaultTimeout); |
+ ep1_ch1()->AddRemoteCandidate( |
+ CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 0)); |
+ // Sanity checking the type of the connection. |
+ EXPECT_TRUE(ep1_ch1()->selected_connection() != nullptr); |
+ EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); |
+ EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); |
+ |
+ // Tell the socket server to block packets (returning EWOULDBLOCK). |
+ virtual_socket_server()->SetSendingBlocked(true); |
+ const char* data = "test"; |
+ int len = static_cast<int>(strlen(data)); |
+ EXPECT_EQ(-1, SendData(ep1_ch1(), data, len)); |
+ |
+ // Reset |ready_to_send_| flag, which is set to true if the event fires as it |
+ // should. |
+ GetEndpoint(0)->ready_to_send_ = false; |
+ virtual_socket_server()->SetSendingBlocked(false); |
+ EXPECT_TRUE(GetEndpoint(0)->ready_to_send_); |
+ EXPECT_EQ(len, SendData(ep1_ch1(), data, len)); |
+} |
+ |
// Test what happens when we have 2 users behind the same NAT. This can lead |
// to interesting behavior because the STUN server will only give out the |
// address of the outermost NAT. |