Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/protocol/channel_socket_adapter.h" | 5 #include "remoting/protocol/channel_socket_adapter.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
| 15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 #include "net/socket/socket.h" | 16 #include "net/socket/socket.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/webrtc/p2p/base/transportchannel.h" | 19 #include "third_party/webrtc/p2p/base/mockicetransport.h" |
| 20 | 20 |
| 21 using net::IOBuffer; | 21 using net::IOBuffer; |
| 22 | 22 |
| 23 using testing::_; | 23 using testing::_; |
| 24 using testing::Return; | 24 using testing::Return; |
| 25 using cricket::MockIceTransport; | |
|
Sergey Ulanov
2017/01/05 04:06:29
Please don't use 'using' here. Instead use fully-q
| |
| 25 | 26 |
| 26 namespace remoting { | 27 namespace remoting { |
| 27 namespace protocol { | 28 namespace protocol { |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 const int kBufferSize = 4096; | 31 const int kBufferSize = 4096; |
| 31 const char kTestData[] = "data"; | 32 const char kTestData[] = "data"; |
| 32 const int kTestDataSize = 4; | 33 const int kTestDataSize = 4; |
| 33 const int kTestError = -32123; | 34 const int kTestError = -32123; |
| 34 } // namespace | 35 } // namespace |
| 35 | 36 |
| 36 class MockTransportChannel : public cricket::TransportChannel { | |
| 37 public: | |
| 38 MockTransportChannel() : cricket::TransportChannel(std::string(), 0) { | |
| 39 set_writable(true); | |
| 40 } | |
| 41 | |
| 42 MOCK_METHOD4(SendPacket, int(const char* data, | |
| 43 size_t len, | |
| 44 const rtc::PacketOptions& options, | |
| 45 int flags)); | |
| 46 MOCK_METHOD2(SetOption, int(rtc::Socket::Option opt, int value)); | |
| 47 MOCK_METHOD0(GetError, int()); | |
| 48 MOCK_CONST_METHOD0(GetIceRole, cricket::IceRole()); | |
| 49 MOCK_METHOD1(GetStats, bool(cricket::ConnectionInfos* infos)); | |
| 50 MOCK_CONST_METHOD0(IsDtlsActive, bool()); | |
| 51 MOCK_CONST_METHOD1(GetSslRole, bool(rtc::SSLRole* role)); | |
| 52 MOCK_METHOD1(SetSrtpCiphers, bool(const std::vector<std::string>& ciphers)); | |
| 53 MOCK_METHOD1(GetSrtpCipher, bool(std::string* cipher)); | |
| 54 MOCK_METHOD1(GetSslCipher, bool(std::string* cipher)); | |
| 55 MOCK_CONST_METHOD0(GetLocalCertificate, | |
| 56 rtc::scoped_refptr<rtc::RTCCertificate>()); | |
| 57 | |
| 58 // This can't be a real mock method because gmock doesn't support move-only | |
| 59 // return values. | |
| 60 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate() | |
| 61 const override { | |
| 62 EXPECT_TRUE(false); // Never called. | |
| 63 return nullptr; | |
| 64 } | |
| 65 | |
| 66 MOCK_METHOD6(ExportKeyingMaterial, | |
| 67 bool(const std::string& label, | |
| 68 const uint8_t* context, | |
| 69 size_t context_len, | |
| 70 bool use_context, | |
| 71 uint8_t* result, | |
| 72 size_t result_len)); | |
| 73 }; | |
| 74 | |
| 75 class TransportChannelSocketAdapterTest : public testing::Test { | 37 class TransportChannelSocketAdapterTest : public testing::Test { |
| 76 public: | 38 public: |
| 77 TransportChannelSocketAdapterTest() | 39 TransportChannelSocketAdapterTest() |
| 78 : callback_(base::Bind(&TransportChannelSocketAdapterTest::Callback, | 40 : callback_(base::Bind(&TransportChannelSocketAdapterTest::Callback, |
| 79 base::Unretained(this))), | 41 base::Unretained(this))), |
| 80 callback_result_(0) { | 42 callback_result_(0) { |
| 81 } | 43 } |
| 82 | 44 |
| 83 protected: | 45 protected: |
| 84 void SetUp() override { | 46 void SetUp() override { |
| 85 target_.reset(new TransportChannelSocketAdapter(&channel_)); | 47 target_.reset(new TransportChannelSocketAdapter(&channel_)); |
| 86 } | 48 } |
| 87 | 49 |
| 88 void Callback(int result) { | 50 void Callback(int result) { |
| 89 callback_result_ = result; | 51 callback_result_ = result; |
| 90 } | 52 } |
| 91 | 53 |
| 92 MockTransportChannel channel_; | 54 MockIceTransport channel_; |
| 93 std::unique_ptr<TransportChannelSocketAdapter> target_; | 55 std::unique_ptr<TransportChannelSocketAdapter> target_; |
| 94 net::CompletionCallback callback_; | 56 net::CompletionCallback callback_; |
| 95 int callback_result_; | 57 int callback_result_; |
| 96 base::MessageLoopForIO message_loop_; | 58 base::MessageLoopForIO message_loop_; |
| 97 }; | 59 }; |
| 98 | 60 |
| 99 // Verify that Read() returns net::ERR_IO_PENDING. | 61 // Verify that Read() returns net::ERR_IO_PENDING. |
| 100 TEST_F(TransportChannelSocketAdapterTest, Read) { | 62 TEST_F(TransportChannelSocketAdapterTest, Read) { |
| 101 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize)); | 63 scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize)); |
| 102 | 64 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 | 106 |
| 145 EXPECT_CALL(channel_, GetError()) | 107 EXPECT_CALL(channel_, GetError()) |
| 146 .WillOnce(Return(EWOULDBLOCK)); | 108 .WillOnce(Return(EWOULDBLOCK)); |
| 147 | 109 |
| 148 int result = target_->Send(buffer.get(), kTestDataSize, callback_); | 110 int result = target_->Send(buffer.get(), kTestDataSize, callback_); |
| 149 ASSERT_EQ(net::OK, result); | 111 ASSERT_EQ(net::OK, result); |
| 150 } | 112 } |
| 151 | 113 |
| 152 } // namespace protocol | 114 } // namespace protocol |
| 153 } // namespace remoting | 115 } // namespace remoting |
| OLD | NEW |