henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle SCTP |
| 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 <errno.h> |
| 29 | #include <stdarg.h> |
| 30 | #include <stdio.h> |
| 31 | #include <string> |
| 32 | |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame^] | 33 | #include "talk/app/webrtc/datachannelinterface.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 34 | #include "talk/base/buffer.h" |
| 35 | #include "talk/base/criticalsection.h" |
| 36 | #include "talk/base/gunit.h" |
| 37 | #include "talk/base/helpers.h" |
| 38 | #include "talk/base/messagehandler.h" |
| 39 | #include "talk/base/messagequeue.h" |
| 40 | #include "talk/base/scoped_ptr.h" |
| 41 | #include "talk/base/thread.h" |
| 42 | #include "talk/media/base/constants.h" |
| 43 | #include "talk/media/base/mediachannel.h" |
| 44 | #include "talk/media/sctp/sctpdataengine.h" |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame^] | 45 | #include "talk/media/sctp/sctputils.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | |
| 47 | enum { |
| 48 | MSG_PACKET = 1, |
| 49 | }; |
| 50 | |
| 51 | // Fake NetworkInterface that sends/receives sctp packets. The one in |
| 52 | // talk/media/base/fakenetworkinterface.h only works with rtp/rtcp. |
| 53 | class SctpFakeNetworkInterface : public cricket::MediaChannel::NetworkInterface, |
| 54 | public talk_base::MessageHandler { |
| 55 | public: |
| 56 | explicit SctpFakeNetworkInterface(talk_base::Thread* thread) |
| 57 | : thread_(thread), |
| 58 | dest_(NULL) { |
| 59 | } |
| 60 | |
| 61 | void SetDestination(cricket::DataMediaChannel* dest) { dest_ = dest; } |
| 62 | |
| 63 | protected: |
| 64 | // Called to send raw packet down the wire (e.g. SCTP an packet). |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 65 | virtual bool SendPacket(talk_base::Buffer* packet, |
| 66 | talk_base::DiffServCodePoint dscp) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::SendPacket"; |
| 68 | |
| 69 | // TODO(ldixon): Can/should we use Buffer.TransferTo here? |
| 70 | // Note: this assignment does a deep copy of data from packet. |
| 71 | talk_base::Buffer* buffer = new talk_base::Buffer(packet->data(), |
| 72 | packet->length()); |
| 73 | thread_->Post(this, MSG_PACKET, talk_base::WrapMessageData(buffer)); |
| 74 | LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::SendPacket, Posted message."; |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | // Called when a raw packet has been recieved. This passes the data to the |
| 79 | // code that will interpret the packet. e.g. to get the content payload from |
| 80 | // an SCTP packet. |
| 81 | virtual void OnMessage(talk_base::Message* msg) { |
| 82 | LOG(LS_VERBOSE) << "SctpFakeNetworkInterface::OnMessage"; |
| 83 | talk_base::Buffer* buffer = |
| 84 | static_cast<talk_base::TypedMessageData<talk_base::Buffer*>*>( |
| 85 | msg->pdata)->data(); |
| 86 | if (dest_) { |
| 87 | dest_->OnPacketReceived(buffer); |
| 88 | } |
| 89 | delete buffer; |
| 90 | } |
| 91 | |
| 92 | // Unsupported functions required to exist by NetworkInterface. |
| 93 | // TODO(ldixon): Refactor parent NetworkInterface class so these are not |
| 94 | // required. They are RTC specific and should be in an appropriate subclass. |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 95 | virtual bool SendRtcp(talk_base::Buffer* packet, |
| 96 | talk_base::DiffServCodePoint dscp) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 97 | LOG(LS_WARNING) << "Unsupported: SctpFakeNetworkInterface::SendRtcp."; |
| 98 | return false; |
| 99 | } |
| 100 | virtual int SetOption(SocketType type, talk_base::Socket::Option opt, |
| 101 | int option) { |
| 102 | LOG(LS_WARNING) << "Unsupported: SctpFakeNetworkInterface::SetOption."; |
| 103 | return 0; |
| 104 | } |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 105 | virtual void SetDefaultDSCPCode(talk_base::DiffServCodePoint dscp) { |
| 106 | LOG(LS_WARNING) << "Unsupported: SctpFakeNetworkInterface::SetOption."; |
| 107 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | |
| 109 | private: |
| 110 | // Not owned by this class. |
| 111 | talk_base::Thread* thread_; |
| 112 | cricket::DataMediaChannel* dest_; |
| 113 | }; |
| 114 | |
| 115 | // This is essentially a buffer to hold recieved data. It stores only the last |
| 116 | // received data. Calling OnDataReceived twice overwrites old data with the |
| 117 | // newer one. |
| 118 | // TODO(ldixon): Implement constraints, and allow new data to be added to old |
| 119 | // instead of replacing it. |
| 120 | class SctpFakeDataReceiver : public sigslot::has_slots<> { |
| 121 | public: |
| 122 | SctpFakeDataReceiver() : received_(false) {} |
| 123 | |
| 124 | void Clear() { |
| 125 | received_ = false; |
| 126 | last_data_ = ""; |
| 127 | last_params_ = cricket::ReceiveDataParams(); |
| 128 | } |
| 129 | |
| 130 | virtual void OnDataReceived(const cricket::ReceiveDataParams& params, |
| 131 | const char* data, size_t length) { |
| 132 | received_ = true; |
| 133 | last_data_ = std::string(data, length); |
| 134 | last_params_ = params; |
| 135 | } |
| 136 | |
| 137 | bool received() const { return received_; } |
| 138 | std::string last_data() const { return last_data_; } |
| 139 | cricket::ReceiveDataParams last_params() const { return last_params_; } |
| 140 | |
| 141 | private: |
| 142 | bool received_; |
| 143 | std::string last_data_; |
| 144 | cricket::ReceiveDataParams last_params_; |
| 145 | }; |
| 146 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 147 | class SignalReadyToSendObserver : public sigslot::has_slots<> { |
| 148 | public: |
| 149 | SignalReadyToSendObserver() : signaled_(false), writable_(false) {} |
| 150 | |
| 151 | void OnSignaled(bool writable) { |
| 152 | signaled_ = true; |
| 153 | writable_ = writable; |
| 154 | } |
| 155 | |
| 156 | bool IsSignaled(bool writable) { |
| 157 | return signaled_ && (writable_ == writable); |
| 158 | } |
| 159 | |
| 160 | private: |
| 161 | bool signaled_; |
| 162 | bool writable_; |
| 163 | }; |
| 164 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 165 | // SCTP Data Engine testing framework. |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame^] | 166 | class SctpDataMediaChannelTest : public testing::Test, |
| 167 | public sigslot::has_slots<> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 168 | protected: |
| 169 | virtual void SetUp() { |
| 170 | engine_.reset(new cricket::SctpDataEngine()); |
| 171 | } |
| 172 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 173 | void SetupConnectedChannels() { |
| 174 | net1_.reset(new SctpFakeNetworkInterface(talk_base::Thread::Current())); |
| 175 | net2_.reset(new SctpFakeNetworkInterface(talk_base::Thread::Current())); |
| 176 | recv1_.reset(new SctpFakeDataReceiver()); |
| 177 | recv2_.reset(new SctpFakeDataReceiver()); |
| 178 | chan1_.reset(CreateChannel(net1_.get(), recv1_.get())); |
| 179 | chan1_->set_debug_name("chan1/connector"); |
| 180 | chan2_.reset(CreateChannel(net2_.get(), recv2_.get())); |
| 181 | chan2_->set_debug_name("chan2/listener"); |
| 182 | // Setup two connected channels ready to send and receive. |
| 183 | net1_->SetDestination(chan2_.get()); |
| 184 | net2_->SetDestination(chan1_.get()); |
| 185 | |
| 186 | LOG(LS_VERBOSE) << "Channel setup ----------------------------- "; |
| 187 | chan1_->AddSendStream(cricket::StreamParams::CreateLegacy(1)); |
| 188 | chan2_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)); |
| 189 | |
| 190 | chan2_->AddSendStream(cricket::StreamParams::CreateLegacy(2)); |
| 191 | chan1_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)); |
| 192 | |
| 193 | LOG(LS_VERBOSE) << "Connect the channels -----------------------------"; |
| 194 | // chan1 wants to setup a data connection. |
| 195 | chan1_->SetReceive(true); |
| 196 | // chan1 will have sent chan2 a request to setup a data connection. After |
| 197 | // chan2 accepts the offer, chan2 connects to chan1 with the following. |
| 198 | chan2_->SetReceive(true); |
| 199 | chan2_->SetSend(true); |
| 200 | // Makes sure that network packets are delivered and simulates a |
| 201 | // deterministic and realistic small timing delay between the SetSend calls. |
| 202 | ProcessMessagesUntilIdle(); |
| 203 | |
| 204 | // chan1 and chan2 are now connected so chan1 enables sending to complete |
| 205 | // the creation of the connection. |
| 206 | chan1_->SetSend(true); |
| 207 | } |
| 208 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 209 | cricket::SctpDataMediaChannel* CreateChannel( |
| 210 | SctpFakeNetworkInterface* net, SctpFakeDataReceiver* recv) { |
| 211 | cricket::SctpDataMediaChannel* channel = |
| 212 | static_cast<cricket::SctpDataMediaChannel*>(engine_->CreateChannel( |
| 213 | cricket::DCT_SCTP)); |
| 214 | channel->SetInterface(net); |
| 215 | // When data is received, pass it to the SctpFakeDataReceiver. |
| 216 | channel->SignalDataReceived.connect( |
| 217 | recv, &SctpFakeDataReceiver::OnDataReceived); |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame^] | 218 | channel->SignalNewStreamReceived.connect( |
| 219 | this, &SctpDataMediaChannelTest::OnNewStreamReceived); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 220 | return channel; |
| 221 | } |
| 222 | |
| 223 | bool SendData(cricket::SctpDataMediaChannel* chan, uint32 ssrc, |
| 224 | const std::string& msg, |
| 225 | cricket::SendDataResult* result) { |
| 226 | cricket::SendDataParams params; |
| 227 | params.ssrc = ssrc; |
| 228 | return chan->SendData(params, talk_base::Buffer(msg.data(), msg.length()), result); |
| 229 | } |
| 230 | |
| 231 | bool ReceivedData(const SctpFakeDataReceiver* recv, uint32 ssrc, |
| 232 | const std::string& msg ) { |
| 233 | return (recv->received() && |
| 234 | recv->last_params().ssrc == ssrc && |
| 235 | recv->last_data() == msg); |
| 236 | } |
| 237 | |
| 238 | bool ProcessMessagesUntilIdle() { |
| 239 | talk_base::Thread* thread = talk_base::Thread::Current(); |
| 240 | while (!thread->empty()) { |
| 241 | talk_base::Message msg; |
| 242 | if (thread->Get(&msg, talk_base::kForever)) { |
| 243 | thread->Dispatch(&msg); |
| 244 | } |
| 245 | } |
| 246 | return !thread->IsQuitting(); |
| 247 | } |
| 248 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 249 | cricket::SctpDataMediaChannel* channel1() { return chan1_.get(); } |
| 250 | cricket::SctpDataMediaChannel* channel2() { return chan2_.get(); } |
| 251 | SctpFakeDataReceiver* receiver1() { return recv1_.get(); } |
| 252 | SctpFakeDataReceiver* receiver2() { return recv2_.get(); } |
| 253 | |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame^] | 254 | void OnNewStreamReceived(const std::string& label, |
| 255 | const webrtc::DataChannelInit& init) { |
| 256 | last_label_ = label; |
| 257 | last_dc_init_ = init; |
| 258 | } |
| 259 | std::string last_label() { return last_label_; } |
| 260 | webrtc::DataChannelInit last_dc_init() { return last_dc_init_; } |
| 261 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 262 | private: |
| 263 | talk_base::scoped_ptr<cricket::SctpDataEngine> engine_; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 264 | talk_base::scoped_ptr<SctpFakeNetworkInterface> net1_; |
| 265 | talk_base::scoped_ptr<SctpFakeNetworkInterface> net2_; |
| 266 | talk_base::scoped_ptr<SctpFakeDataReceiver> recv1_; |
| 267 | talk_base::scoped_ptr<SctpFakeDataReceiver> recv2_; |
| 268 | talk_base::scoped_ptr<cricket::SctpDataMediaChannel> chan1_; |
| 269 | talk_base::scoped_ptr<cricket::SctpDataMediaChannel> chan2_; |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame^] | 270 | std::string last_label_; |
| 271 | webrtc::DataChannelInit last_dc_init_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 272 | }; |
| 273 | |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 274 | // Verifies that SignalReadyToSend is fired. |
| 275 | TEST_F(SctpDataMediaChannelTest, SignalReadyToSend) { |
| 276 | SetupConnectedChannels(); |
| 277 | |
| 278 | SignalReadyToSendObserver signal_observer_1; |
| 279 | SignalReadyToSendObserver signal_observer_2; |
| 280 | |
| 281 | channel1()->SignalReadyToSend.connect(&signal_observer_1, |
| 282 | &SignalReadyToSendObserver::OnSignaled); |
| 283 | channel2()->SignalReadyToSend.connect(&signal_observer_2, |
| 284 | &SignalReadyToSendObserver::OnSignaled); |
| 285 | |
| 286 | cricket::SendDataResult result; |
| 287 | ASSERT_TRUE(SendData(channel1(), 1, "hello?", &result)); |
| 288 | EXPECT_EQ(cricket::SDR_SUCCESS, result); |
| 289 | EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hello?"), 1000); |
| 290 | ASSERT_TRUE(SendData(channel2(), 2, "hi chan1", &result)); |
| 291 | EXPECT_EQ(cricket::SDR_SUCCESS, result); |
| 292 | EXPECT_TRUE_WAIT(ReceivedData(receiver1(), 2, "hi chan1"), 1000); |
| 293 | |
| 294 | EXPECT_TRUE_WAIT(signal_observer_1.IsSignaled(true), 1000); |
| 295 | EXPECT_TRUE_WAIT(signal_observer_2.IsSignaled(true), 1000); |
| 296 | } |
| 297 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 298 | TEST_F(SctpDataMediaChannelTest, SendData) { |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 299 | SetupConnectedChannels(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 300 | |
| 301 | cricket::SendDataResult result; |
| 302 | LOG(LS_VERBOSE) << "chan1 sending: 'hello?' -----------------------------"; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 303 | ASSERT_TRUE(SendData(channel1(), 1, "hello?", &result)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 304 | EXPECT_EQ(cricket::SDR_SUCCESS, result); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 305 | EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hello?"), 1000); |
| 306 | LOG(LS_VERBOSE) << "recv2.received=" << receiver2()->received() |
| 307 | << "recv2.last_params.ssrc=" |
| 308 | << receiver2()->last_params().ssrc |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 309 | << "recv2.last_params.timestamp=" |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 310 | << receiver2()->last_params().ssrc |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 311 | << "recv2.last_params.seq_num=" |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 312 | << receiver2()->last_params().seq_num |
| 313 | << "recv2.last_data=" << receiver2()->last_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 314 | |
| 315 | LOG(LS_VERBOSE) << "chan2 sending: 'hi chan1' -----------------------------"; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 316 | ASSERT_TRUE(SendData(channel2(), 2, "hi chan1", &result)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 317 | EXPECT_EQ(cricket::SDR_SUCCESS, result); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 318 | EXPECT_TRUE_WAIT(ReceivedData(receiver1(), 2, "hi chan1"), 1000); |
| 319 | LOG(LS_VERBOSE) << "recv1.received=" << receiver1()->received() |
| 320 | << "recv1.last_params.ssrc=" |
| 321 | << receiver1()->last_params().ssrc |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 322 | << "recv1.last_params.timestamp=" |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 323 | << receiver1()->last_params().ssrc |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 324 | << "recv1.last_params.seq_num=" |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 325 | << receiver1()->last_params().seq_num |
| 326 | << "recv1.last_data=" << receiver1()->last_data(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 327 | |
| 328 | LOG(LS_VERBOSE) << "Closing down. -----------------------------"; |
| 329 | // Disconnects and closes socket, including setting receiving to false. |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 330 | channel1()->SetSend(false); |
| 331 | channel2()->SetSend(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 332 | LOG(LS_VERBOSE) << "Cleaning up. -----------------------------"; |
| 333 | } |
wu@webrtc.org | 1d1ffc9 | 2013-10-16 18:12:02 +0000 | [diff] [blame^] | 334 | |
| 335 | TEST_F(SctpDataMediaChannelTest, SendReceiveOpenMessage) { |
| 336 | SetupConnectedChannels(); |
| 337 | |
| 338 | std::string label("x"); |
| 339 | webrtc::DataChannelInit config; |
| 340 | config.id = 10; |
| 341 | |
| 342 | // Send the OPEN message on a unknown ssrc. |
| 343 | channel1()->AddSendStream(cricket::StreamParams::CreateLegacy(config.id)); |
| 344 | cricket::SendDataParams params; |
| 345 | params.ssrc = config.id; |
| 346 | params.type = cricket::DMT_CONTROL; |
| 347 | cricket::SendDataResult result; |
| 348 | talk_base::Buffer buffer; |
| 349 | ASSERT_TRUE(cricket::WriteDataChannelOpenMessage(label, config, &buffer)); |
| 350 | ASSERT_TRUE(channel1()->SendData(params, buffer, &result)); |
| 351 | // Send data on the new ssrc immediately after sending the OPEN message. |
| 352 | ASSERT_TRUE(SendData(channel1(), config.id, "hi chan2", &result)); |
| 353 | |
| 354 | // Verifies the received OPEN message. |
| 355 | EXPECT_TRUE_WAIT(last_label() == label, 1000); |
| 356 | EXPECT_EQ(config.id, last_dc_init().id); |
| 357 | EXPECT_EQ(true, last_dc_init().negotiated); |
| 358 | // Verifies the received data. |
| 359 | EXPECT_TRUE_WAIT(ReceivedData(receiver2(), config.id, "hi chan2"), 1000); |
| 360 | } |