wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2013, Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "talk/app/webrtc/datachannel.h" |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 29 | #include "talk/app/webrtc/sctputils.h" |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 30 | #include "talk/app/webrtc/test/fakedatachannelprovider.h" |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 31 | #include "talk/base/gunit.h" |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 32 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 33 | using webrtc::DataChannel; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 34 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 35 | class FakeDataChannelObserver : public webrtc::DataChannelObserver { |
| 36 | public: |
jiayl@webrtc.org | 5dc51fb | 2014-05-29 15:33:54 +0000 | [diff] [blame^] | 37 | FakeDataChannelObserver() : messages_received_(0) {} |
| 38 | |
| 39 | void OnStateChange() {} |
| 40 | void OnMessage(const webrtc::DataBuffer& buffer) { |
| 41 | ++messages_received_; |
| 42 | } |
| 43 | |
| 44 | size_t messages_received() const { |
| 45 | return messages_received_; |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | size_t messages_received_; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 52 | class SctpDataChannelTest : public testing::Test { |
| 53 | protected: |
| 54 | SctpDataChannelTest() |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 55 | : webrtc_data_channel_( |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 56 | DataChannel::Create( |
| 57 | &provider_, cricket::DCT_SCTP, "test", init_)) { |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 58 | } |
| 59 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 60 | void SetChannelReady() { |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 61 | provider_.set_transport_available(true); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 62 | webrtc_data_channel_->OnTransportChannelCreated(); |
| 63 | if (webrtc_data_channel_->id() < 0) { |
| 64 | webrtc_data_channel_->SetSctpSid(0); |
| 65 | } |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 66 | provider_.set_ready_to_send(true); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 67 | } |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 68 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 69 | void AddObserver() { |
| 70 | observer_.reset(new FakeDataChannelObserver()); |
| 71 | webrtc_data_channel_->RegisterObserver(observer_.get()); |
| 72 | } |
| 73 | |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 74 | webrtc::InternalDataChannelInit init_; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 75 | FakeDataChannelProvider provider_; |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 76 | talk_base::scoped_ptr<FakeDataChannelObserver> observer_; |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 77 | talk_base::scoped_refptr<DataChannel> webrtc_data_channel_; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 80 | // Verifies that the data channel is connected to the transport after creation. |
| 81 | TEST_F(SctpDataChannelTest, ConnectedToTransportOnCreated) { |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 82 | provider_.set_transport_available(true); |
| 83 | talk_base::scoped_refptr<DataChannel> dc = DataChannel::Create( |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 84 | &provider_, cricket::DCT_SCTP, "test1", init_); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 85 | |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 86 | EXPECT_TRUE(provider_.IsConnected(dc.get())); |
| 87 | // The sid is not set yet, so it should not have added the streams. |
| 88 | EXPECT_FALSE(provider_.IsSendStreamAdded(dc->id())); |
| 89 | EXPECT_FALSE(provider_.IsRecvStreamAdded(dc->id())); |
| 90 | |
| 91 | dc->SetSctpSid(0); |
| 92 | EXPECT_TRUE(provider_.IsSendStreamAdded(dc->id())); |
| 93 | EXPECT_TRUE(provider_.IsRecvStreamAdded(dc->id())); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | // Verifies that the data channel is connected to the transport if the transport |
| 97 | // is not available initially and becomes available later. |
| 98 | TEST_F(SctpDataChannelTest, ConnectedAfterTransportBecomesAvailable) { |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 99 | EXPECT_FALSE(provider_.IsConnected(webrtc_data_channel_.get())); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 100 | |
| 101 | provider_.set_transport_available(true); |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 102 | webrtc_data_channel_->OnTransportChannelCreated(); |
| 103 | EXPECT_TRUE(provider_.IsConnected(webrtc_data_channel_.get())); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 104 | } |
| 105 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 106 | // Tests the state of the data channel. |
| 107 | TEST_F(SctpDataChannelTest, StateTransition) { |
| 108 | EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, |
| 109 | webrtc_data_channel_->state()); |
| 110 | SetChannelReady(); |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 111 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 112 | EXPECT_EQ(webrtc::DataChannelInterface::kOpen, webrtc_data_channel_->state()); |
| 113 | webrtc_data_channel_->Close(); |
| 114 | EXPECT_EQ(webrtc::DataChannelInterface::kClosed, |
| 115 | webrtc_data_channel_->state()); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 116 | // Verifies that it's disconnected from the transport. |
| 117 | EXPECT_FALSE(provider_.IsConnected(webrtc_data_channel_.get())); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 118 | } |
| 119 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 120 | // Tests that DataChannel::buffered_amount() is correct after the channel is |
| 121 | // blocked. |
| 122 | TEST_F(SctpDataChannelTest, BufferedAmountWhenBlocked) { |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 123 | SetChannelReady(); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 124 | webrtc::DataBuffer buffer("abcd"); |
| 125 | EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); |
| 126 | |
| 127 | EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount()); |
| 128 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 129 | provider_.set_send_blocked(true); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 130 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 131 | const int number_of_packets = 3; |
| 132 | for (int i = 0; i < number_of_packets; ++i) { |
| 133 | EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); |
| 134 | } |
| 135 | EXPECT_EQ(buffer.data.length() * number_of_packets, |
| 136 | webrtc_data_channel_->buffered_amount()); |
| 137 | } |
| 138 | |
| 139 | // Tests that the queued data are sent when the channel transitions from blocked |
| 140 | // to unblocked. |
| 141 | TEST_F(SctpDataChannelTest, QueuedDataSentWhenUnblocked) { |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 142 | SetChannelReady(); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 143 | webrtc::DataBuffer buffer("abcd"); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 144 | provider_.set_send_blocked(true); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 145 | EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); |
| 146 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 147 | provider_.set_send_blocked(false); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 148 | SetChannelReady(); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 149 | EXPECT_EQ(0U, webrtc_data_channel_->buffered_amount()); |
| 150 | } |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 151 | |
| 152 | // Tests that the queued control message is sent when channel is ready. |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 153 | TEST_F(SctpDataChannelTest, OpenMessageSent) { |
| 154 | // Initially the id is unassigned. |
| 155 | EXPECT_EQ(-1, webrtc_data_channel_->id()); |
| 156 | |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 157 | SetChannelReady(); |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 158 | EXPECT_GE(webrtc_data_channel_->id(), 0); |
| 159 | EXPECT_EQ(cricket::DMT_CONTROL, provider_.last_send_data_params().type); |
| 160 | EXPECT_EQ(provider_.last_send_data_params().ssrc, |
| 161 | static_cast<uint32>(webrtc_data_channel_->id())); |
wu@webrtc.org | 7818752 | 2013-10-07 23:32:02 +0000 | [diff] [blame] | 162 | } |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 163 | |
| 164 | // Tests that the DataChannel created after transport gets ready can enter OPEN |
| 165 | // state. |
| 166 | TEST_F(SctpDataChannelTest, LateCreatedChannelTransitionToOpen) { |
| 167 | SetChannelReady(); |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 168 | webrtc::InternalDataChannelInit init; |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 169 | init.id = 1; |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 170 | talk_base::scoped_refptr<DataChannel> dc = DataChannel::Create( |
| 171 | &provider_, cricket::DCT_SCTP, "test1", init); |
wu@webrtc.org | 07a6fbe | 2013-11-04 18:41:34 +0000 | [diff] [blame] | 172 | EXPECT_EQ(webrtc::DataChannelInterface::kConnecting, dc->state()); |
| 173 | EXPECT_TRUE_WAIT(webrtc::DataChannelInterface::kOpen == dc->state(), |
| 174 | 1000); |
| 175 | } |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 176 | |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 177 | // Tests that an unordered DataChannel sends data as ordered until the OPEN_ACK |
| 178 | // message is received. |
| 179 | TEST_F(SctpDataChannelTest, SendUnorderedAfterReceivesOpenAck) { |
| 180 | SetChannelReady(); |
| 181 | webrtc::InternalDataChannelInit init; |
| 182 | init.id = 1; |
| 183 | init.ordered = false; |
| 184 | talk_base::scoped_refptr<DataChannel> dc = DataChannel::Create( |
| 185 | &provider_, cricket::DCT_SCTP, "test1", init); |
| 186 | |
| 187 | EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); |
| 188 | |
| 189 | // Sends a message and verifies it's ordered. |
| 190 | webrtc::DataBuffer buffer("some data"); |
| 191 | ASSERT_TRUE(dc->Send(buffer)); |
| 192 | EXPECT_TRUE(provider_.last_send_data_params().ordered); |
| 193 | |
| 194 | // Emulates receiving an OPEN_ACK message. |
| 195 | cricket::ReceiveDataParams params; |
| 196 | params.ssrc = init.id; |
| 197 | params.type = cricket::DMT_CONTROL; |
| 198 | talk_base::Buffer payload; |
| 199 | webrtc::WriteDataChannelOpenAckMessage(&payload); |
| 200 | dc->OnDataReceived(NULL, params, payload); |
| 201 | |
| 202 | // Sends another message and verifies it's unordered. |
| 203 | ASSERT_TRUE(dc->Send(buffer)); |
| 204 | EXPECT_FALSE(provider_.last_send_data_params().ordered); |
| 205 | } |
| 206 | |
| 207 | // Tests that an unordered DataChannel sends unordered data after any DATA |
| 208 | // message is received. |
| 209 | TEST_F(SctpDataChannelTest, SendUnorderedAfterReceiveData) { |
| 210 | SetChannelReady(); |
| 211 | webrtc::InternalDataChannelInit init; |
| 212 | init.id = 1; |
| 213 | init.ordered = false; |
| 214 | talk_base::scoped_refptr<DataChannel> dc = DataChannel::Create( |
| 215 | &provider_, cricket::DCT_SCTP, "test1", init); |
| 216 | |
| 217 | EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); |
| 218 | |
| 219 | // Emulates receiving a DATA message. |
| 220 | cricket::ReceiveDataParams params; |
| 221 | params.ssrc = init.id; |
| 222 | params.type = cricket::DMT_TEXT; |
| 223 | webrtc::DataBuffer buffer("data"); |
| 224 | dc->OnDataReceived(NULL, params, buffer.data); |
| 225 | |
| 226 | // Sends a message and verifies it's unordered. |
| 227 | ASSERT_TRUE(dc->Send(buffer)); |
| 228 | EXPECT_FALSE(provider_.last_send_data_params().ordered); |
| 229 | } |
| 230 | |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 231 | // Tests that messages are sent with the right ssrc. |
| 232 | TEST_F(SctpDataChannelTest, SendDataSsrc) { |
| 233 | webrtc_data_channel_->SetSctpSid(1); |
| 234 | SetChannelReady(); |
| 235 | webrtc::DataBuffer buffer("data"); |
| 236 | EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); |
| 237 | EXPECT_EQ(1U, provider_.last_send_data_params().ssrc); |
| 238 | } |
| 239 | |
| 240 | // Tests that the incoming messages with wrong ssrcs are rejected. |
| 241 | TEST_F(SctpDataChannelTest, ReceiveDataWithInvalidSsrc) { |
| 242 | webrtc_data_channel_->SetSctpSid(1); |
| 243 | SetChannelReady(); |
| 244 | |
| 245 | AddObserver(); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 246 | |
| 247 | cricket::ReceiveDataParams params; |
| 248 | params.ssrc = 0; |
| 249 | webrtc::DataBuffer buffer("abcd"); |
| 250 | webrtc_data_channel_->OnDataReceived(NULL, params, buffer.data); |
jiayl@webrtc.org | 5dc51fb | 2014-05-29 15:33:54 +0000 | [diff] [blame^] | 251 | |
| 252 | EXPECT_EQ(0U, observer_->messages_received()); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | // Tests that the incoming messages with right ssrcs are acceted. |
| 256 | TEST_F(SctpDataChannelTest, ReceiveDataWithValidSsrc) { |
| 257 | webrtc_data_channel_->SetSctpSid(1); |
| 258 | SetChannelReady(); |
| 259 | |
| 260 | AddObserver(); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 261 | |
| 262 | cricket::ReceiveDataParams params; |
| 263 | params.ssrc = 1; |
| 264 | webrtc::DataBuffer buffer("abcd"); |
| 265 | |
| 266 | webrtc_data_channel_->OnDataReceived(NULL, params, buffer.data); |
jiayl@webrtc.org | 5dc51fb | 2014-05-29 15:33:54 +0000 | [diff] [blame^] | 267 | EXPECT_EQ(1U, observer_->messages_received()); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 268 | } |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 269 | |
| 270 | // Tests that no CONTROL message is sent if the datachannel is negotiated and |
| 271 | // not created from an OPEN message. |
| 272 | TEST_F(SctpDataChannelTest, NoMsgSentIfNegotiatedAndNotFromOpenMsg) { |
| 273 | webrtc::InternalDataChannelInit config; |
| 274 | config.id = 1; |
| 275 | config.negotiated = true; |
| 276 | config.open_handshake_role = webrtc::InternalDataChannelInit::kNone; |
| 277 | |
| 278 | SetChannelReady(); |
| 279 | talk_base::scoped_refptr<DataChannel> dc = DataChannel::Create( |
| 280 | &provider_, cricket::DCT_SCTP, "test1", config); |
| 281 | |
| 282 | EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); |
| 283 | EXPECT_EQ(0U, provider_.last_send_data_params().ssrc); |
| 284 | } |
| 285 | |
| 286 | // Tests that OPEN_ACK message is sent if the datachannel is created from an |
| 287 | // OPEN message. |
| 288 | TEST_F(SctpDataChannelTest, OpenAckSentIfCreatedFromOpenMessage) { |
| 289 | webrtc::InternalDataChannelInit config; |
| 290 | config.id = 1; |
| 291 | config.negotiated = true; |
| 292 | config.open_handshake_role = webrtc::InternalDataChannelInit::kAcker; |
| 293 | |
| 294 | SetChannelReady(); |
| 295 | talk_base::scoped_refptr<DataChannel> dc = DataChannel::Create( |
| 296 | &provider_, cricket::DCT_SCTP, "test1", config); |
| 297 | |
| 298 | EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); |
| 299 | |
| 300 | EXPECT_EQ(static_cast<unsigned int>(config.id), |
| 301 | provider_.last_send_data_params().ssrc); |
| 302 | EXPECT_EQ(cricket::DMT_CONTROL, provider_.last_send_data_params().type); |
| 303 | } |
| 304 | |
| 305 | // Tests the OPEN_ACK role assigned by InternalDataChannelInit. |
| 306 | TEST_F(SctpDataChannelTest, OpenAckRoleInitialization) { |
| 307 | webrtc::InternalDataChannelInit init; |
| 308 | EXPECT_EQ(webrtc::InternalDataChannelInit::kOpener, init.open_handshake_role); |
| 309 | EXPECT_FALSE(init.negotiated); |
| 310 | |
| 311 | webrtc::DataChannelInit base; |
| 312 | base.negotiated = true; |
| 313 | webrtc::InternalDataChannelInit init2(base); |
| 314 | EXPECT_EQ(webrtc::InternalDataChannelInit::kNone, init2.open_handshake_role); |
| 315 | } |
jiayl@webrtc.org | 5dc51fb | 2014-05-29 15:33:54 +0000 | [diff] [blame^] | 316 | |
| 317 | // Tests that the DataChannel is closed if the sending buffer is full. |
| 318 | TEST_F(SctpDataChannelTest, ClosedWhenSendBufferFull) { |
| 319 | SetChannelReady(); |
| 320 | webrtc::DataBuffer buffer("abcd"); |
| 321 | provider_.set_send_blocked(true); |
| 322 | |
| 323 | for (size_t i = 0; i < 101; ++i) { |
| 324 | EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); |
| 325 | } |
| 326 | |
| 327 | EXPECT_EQ(webrtc::DataChannelInterface::kClosed, |
| 328 | webrtc_data_channel_->state()); |
| 329 | } |
| 330 | |
| 331 | // Tests that the DataChannel is closed on transport errors. |
| 332 | TEST_F(SctpDataChannelTest, ClosedOnTransportError) { |
| 333 | SetChannelReady(); |
| 334 | webrtc::DataBuffer buffer("abcd"); |
| 335 | provider_.set_transport_error(); |
| 336 | |
| 337 | EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); |
| 338 | |
| 339 | EXPECT_EQ(webrtc::DataChannelInterface::kClosed, |
| 340 | webrtc_data_channel_->state()); |
| 341 | } |