| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 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 |
| 11 #include <memory> |
| 12 |
| 11 #include "webrtc/api/test/peerconnectiontestwrapper.h" | 13 #include "webrtc/api/test/peerconnectiontestwrapper.h" |
| 12 // Notice that mockpeerconnectionobservers.h must be included after the above! | 14 // Notice that mockpeerconnectionobservers.h must be included after the above! |
| 13 #include "webrtc/api/test/mockpeerconnectionobservers.h" | 15 #include "webrtc/api/test/mockpeerconnectionobservers.h" |
| 14 #ifdef WEBRTC_ANDROID | 16 #ifdef WEBRTC_ANDROID |
| 15 #include "webrtc/api/test/androidtestinitializer.h" | 17 #include "webrtc/api/test/androidtestinitializer.h" |
| 16 #endif | 18 #endif |
| 17 #include "webrtc/base/gunit.h" | 19 #include "webrtc/base/gunit.h" |
| 18 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
| 19 #include "webrtc/base/ssladapter.h" | 21 #include "webrtc/base/ssladapter.h" |
| 20 #include "webrtc/base/thread.h" | 22 #include "webrtc/base/thread.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 caller_signaled_data_channels_.push_back(dc); | 107 caller_signaled_data_channels_.push_back(dc); |
| 106 } | 108 } |
| 107 | 109 |
| 108 void OnCalleeAddedDataChannel(DataChannelInterface* dc) { | 110 void OnCalleeAddedDataChannel(DataChannelInterface* dc) { |
| 109 callee_signaled_data_channels_.push_back(dc); | 111 callee_signaled_data_channels_.push_back(dc); |
| 110 } | 112 } |
| 111 | 113 |
| 112 // Tests that |dc1| and |dc2| can send to and receive from each other. | 114 // Tests that |dc1| and |dc2| can send to and receive from each other. |
| 113 void TestDataChannelSendAndReceive( | 115 void TestDataChannelSendAndReceive( |
| 114 DataChannelInterface* dc1, DataChannelInterface* dc2) { | 116 DataChannelInterface* dc1, DataChannelInterface* dc2) { |
| 115 rtc::scoped_ptr<webrtc::MockDataChannelObserver> dc1_observer( | 117 std::unique_ptr<webrtc::MockDataChannelObserver> dc1_observer( |
| 116 new webrtc::MockDataChannelObserver(dc1)); | 118 new webrtc::MockDataChannelObserver(dc1)); |
| 117 | 119 |
| 118 rtc::scoped_ptr<webrtc::MockDataChannelObserver> dc2_observer( | 120 std::unique_ptr<webrtc::MockDataChannelObserver> dc2_observer( |
| 119 new webrtc::MockDataChannelObserver(dc2)); | 121 new webrtc::MockDataChannelObserver(dc2)); |
| 120 | 122 |
| 121 static const std::string kDummyData = "abcdefg"; | 123 static const std::string kDummyData = "abcdefg"; |
| 122 webrtc::DataBuffer buffer(kDummyData); | 124 webrtc::DataBuffer buffer(kDummyData); |
| 123 EXPECT_TRUE(dc1->Send(buffer)); | 125 EXPECT_TRUE(dc1->Send(buffer)); |
| 124 EXPECT_EQ_WAIT(kDummyData, dc2_observer->last_message(), kMaxWait); | 126 EXPECT_EQ_WAIT(kDummyData, dc2_observer->last_message(), kMaxWait); |
| 125 | 127 |
| 126 EXPECT_TRUE(dc2->Send(buffer)); | 128 EXPECT_TRUE(dc2->Send(buffer)); |
| 127 EXPECT_EQ_WAIT(kDummyData, dc1_observer->last_message(), kMaxWait); | 129 EXPECT_EQ_WAIT(kDummyData, dc1_observer->last_message(), kMaxWait); |
| 128 | 130 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 rtc::scoped_refptr<DataChannelInterface> caller_dc_1( | 289 rtc::scoped_refptr<DataChannelInterface> caller_dc_1( |
| 288 caller_->CreateDataChannel("data", init)); | 290 caller_->CreateDataChannel("data", init)); |
| 289 rtc::scoped_refptr<DataChannelInterface> caller_dc_2( | 291 rtc::scoped_refptr<DataChannelInterface> caller_dc_2( |
| 290 caller_->CreateDataChannel("data", init)); | 292 caller_->CreateDataChannel("data", init)); |
| 291 | 293 |
| 292 Negotiate(); | 294 Negotiate(); |
| 293 WaitForConnection(); | 295 WaitForConnection(); |
| 294 WaitForDataChannelsToOpen(caller_dc_1, callee_signaled_data_channels_, 0); | 296 WaitForDataChannelsToOpen(caller_dc_1, callee_signaled_data_channels_, 0); |
| 295 WaitForDataChannelsToOpen(caller_dc_2, callee_signaled_data_channels_, 1); | 297 WaitForDataChannelsToOpen(caller_dc_2, callee_signaled_data_channels_, 1); |
| 296 | 298 |
| 297 rtc::scoped_ptr<webrtc::MockDataChannelObserver> dc_1_observer( | 299 std::unique_ptr<webrtc::MockDataChannelObserver> dc_1_observer( |
| 298 new webrtc::MockDataChannelObserver(callee_signaled_data_channels_[0])); | 300 new webrtc::MockDataChannelObserver(callee_signaled_data_channels_[0])); |
| 299 | 301 |
| 300 rtc::scoped_ptr<webrtc::MockDataChannelObserver> dc_2_observer( | 302 std::unique_ptr<webrtc::MockDataChannelObserver> dc_2_observer( |
| 301 new webrtc::MockDataChannelObserver(callee_signaled_data_channels_[1])); | 303 new webrtc::MockDataChannelObserver(callee_signaled_data_channels_[1])); |
| 302 | 304 |
| 303 const std::string message_1 = "hello 1"; | 305 const std::string message_1 = "hello 1"; |
| 304 const std::string message_2 = "hello 2"; | 306 const std::string message_2 = "hello 2"; |
| 305 | 307 |
| 306 caller_dc_1->Send(webrtc::DataBuffer(message_1)); | 308 caller_dc_1->Send(webrtc::DataBuffer(message_1)); |
| 307 EXPECT_EQ_WAIT(message_1, dc_1_observer->last_message(), kMaxWait); | 309 EXPECT_EQ_WAIT(message_1, dc_1_observer->last_message(), kMaxWait); |
| 308 | 310 |
| 309 caller_dc_2->Send(webrtc::DataBuffer(message_2)); | 311 caller_dc_2->Send(webrtc::DataBuffer(message_2)); |
| 310 EXPECT_EQ_WAIT(message_2, dc_2_observer->last_message(), kMaxWait); | 312 EXPECT_EQ_WAIT(message_2, dc_2_observer->last_message(), kMaxWait); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); | 366 WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); |
| 365 // This removes the reference to the remote data channel that we hold. | 367 // This removes the reference to the remote data channel that we hold. |
| 366 callee_signaled_data_channels_.clear(); | 368 callee_signaled_data_channels_.clear(); |
| 367 caller_dc->Close(); | 369 caller_dc->Close(); |
| 368 EXPECT_EQ_WAIT(DataChannelInterface::kClosed, caller_dc->state(), kMaxWait); | 370 EXPECT_EQ_WAIT(DataChannelInterface::kClosed, caller_dc->state(), kMaxWait); |
| 369 | 371 |
| 370 // Wait for a bit longer so the remote data channel will receive the | 372 // Wait for a bit longer so the remote data channel will receive the |
| 371 // close message and be destroyed. | 373 // close message and be destroyed. |
| 372 rtc::Thread::Current()->ProcessMessages(100); | 374 rtc::Thread::Current()->ProcessMessages(100); |
| 373 } | 375 } |
| OLD | NEW |