| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "jingle/glue/channel_socket_adapter.h" | 8 #include "jingle/glue/channel_socket_adapter.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 class MockTransportChannel : public cricket::TransportChannel { | 30 class MockTransportChannel : public cricket::TransportChannel { |
| 31 public: | 31 public: |
| 32 MockTransportChannel() : cricket::TransportChannel(std::string(), 0) { | 32 MockTransportChannel() : cricket::TransportChannel(std::string(), 0) { |
| 33 set_writable(true); | 33 set_writable(true); |
| 34 set_readable(true); | 34 set_readable(true); |
| 35 } | 35 } |
| 36 | 36 |
| 37 MOCK_METHOD4(SendPacket, int(const char* data, | 37 MOCK_METHOD4(SendPacket, int(const char* data, |
| 38 size_t len, | 38 size_t len, |
| 39 const talk_base::PacketOptions& options, | 39 const rtc::PacketOptions& options, |
| 40 int flags)); | 40 int flags)); |
| 41 MOCK_METHOD2(SetOption, int(talk_base::Socket::Option opt, int value)); | 41 MOCK_METHOD2(SetOption, int(rtc::Socket::Option opt, int value)); |
| 42 MOCK_METHOD0(GetError, int()); | 42 MOCK_METHOD0(GetError, int()); |
| 43 MOCK_CONST_METHOD0(GetIceRole, cricket::IceRole()); | 43 MOCK_CONST_METHOD0(GetIceRole, cricket::IceRole()); |
| 44 MOCK_METHOD1(GetStats, bool(cricket::ConnectionInfos* infos)); | 44 MOCK_METHOD1(GetStats, bool(cricket::ConnectionInfos* infos)); |
| 45 MOCK_CONST_METHOD0(IsDtlsActive, bool()); | 45 MOCK_CONST_METHOD0(IsDtlsActive, bool()); |
| 46 MOCK_CONST_METHOD1(GetSslRole, bool(talk_base::SSLRole* role)); | 46 MOCK_CONST_METHOD1(GetSslRole, bool(rtc::SSLRole* role)); |
| 47 MOCK_METHOD1(SetSrtpCiphers, bool(const std::vector<std::string>& ciphers)); | 47 MOCK_METHOD1(SetSrtpCiphers, bool(const std::vector<std::string>& ciphers)); |
| 48 MOCK_METHOD1(GetSrtpCipher, bool(std::string* cipher)); | 48 MOCK_METHOD1(GetSrtpCipher, bool(std::string* cipher)); |
| 49 MOCK_CONST_METHOD1(GetLocalIdentity, bool(talk_base::SSLIdentity** identity)); | 49 MOCK_CONST_METHOD1(GetLocalIdentity, bool(rtc::SSLIdentity** identity)); |
| 50 MOCK_CONST_METHOD1(GetRemoteCertificate, | 50 MOCK_CONST_METHOD1(GetRemoteCertificate, |
| 51 bool(talk_base::SSLCertificate** cert)); | 51 bool(rtc::SSLCertificate** cert)); |
| 52 MOCK_METHOD6(ExportKeyingMaterial, bool(const std::string& label, | 52 MOCK_METHOD6(ExportKeyingMaterial, bool(const std::string& label, |
| 53 const uint8* context, | 53 const uint8* context, |
| 54 size_t context_len, | 54 size_t context_len, |
| 55 bool use_context, | 55 bool use_context, |
| 56 uint8* result, | 56 uint8* result, |
| 57 size_t result_len)); | 57 size_t result_len)); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 class TransportChannelSocketAdapterTest : public testing::Test { | 60 class TransportChannelSocketAdapterTest : public testing::Test { |
| 61 public: | 61 public: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 // Verify that Read() returns net::ERR_IO_PENDING. | 84 // Verify that Read() returns net::ERR_IO_PENDING. |
| 85 TEST_F(TransportChannelSocketAdapterTest, Read) { | 85 TEST_F(TransportChannelSocketAdapterTest, Read) { |
| 86 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize)); | 86 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize)); |
| 87 | 87 |
| 88 int result = target_->Read(buffer.get(), kBufferSize, callback_); | 88 int result = target_->Read(buffer.get(), kBufferSize, callback_); |
| 89 ASSERT_EQ(net::ERR_IO_PENDING, result); | 89 ASSERT_EQ(net::ERR_IO_PENDING, result); |
| 90 | 90 |
| 91 channel_.SignalReadPacket(&channel_, kTestData, kTestDataSize, | 91 channel_.SignalReadPacket(&channel_, kTestData, kTestDataSize, |
| 92 talk_base::CreatePacketTime(0), 0); | 92 rtc::CreatePacketTime(0), 0); |
| 93 EXPECT_EQ(kTestDataSize, callback_result_); | 93 EXPECT_EQ(kTestDataSize, callback_result_); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Verify that Read() after Close() returns error. | 96 // Verify that Read() after Close() returns error. |
| 97 TEST_F(TransportChannelSocketAdapterTest, ReadClose) { | 97 TEST_F(TransportChannelSocketAdapterTest, ReadClose) { |
| 98 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize)); | 98 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize)); |
| 99 | 99 |
| 100 int result = target_->Read(buffer.get(), kBufferSize, callback_); | 100 int result = target_->Read(buffer.get(), kBufferSize, callback_); |
| 101 ASSERT_EQ(net::ERR_IO_PENDING, result); | 101 ASSERT_EQ(net::ERR_IO_PENDING, result); |
| 102 | 102 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 128 .WillOnce(Return(SOCKET_ERROR)); | 128 .WillOnce(Return(SOCKET_ERROR)); |
| 129 | 129 |
| 130 EXPECT_CALL(channel_, GetError()) | 130 EXPECT_CALL(channel_, GetError()) |
| 131 .WillOnce(Return(EWOULDBLOCK)); | 131 .WillOnce(Return(EWOULDBLOCK)); |
| 132 | 132 |
| 133 int result = target_->Write(buffer.get(), kTestDataSize, callback_); | 133 int result = target_->Write(buffer.get(), kTestDataSize, callback_); |
| 134 ASSERT_EQ(net::OK, result); | 134 ASSERT_EQ(net::OK, result); |
| 135 } | 135 } |
| 136 | 136 |
| 137 } // namespace jingle_glue | 137 } // namespace jingle_glue |
| OLD | NEW |