| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/cast_channel/cast_socket.h" | 5 #include "extensions/browser/api/cast_channel/cast_socket.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 message->data.reset(base::BinaryValue::CreateWithCopiedBuffer( | 73 message->data.reset(base::BinaryValue::CreateWithCopiedBuffer( |
| 74 data.c_str(), data.size())); | 74 data.c_str(), data.size())); |
| 75 } | 75 } |
| 76 | 76 |
| 77 class MockCastSocketDelegate : public CastSocket::Delegate { | 77 class MockCastSocketDelegate : public CastSocket::Delegate { |
| 78 public: | 78 public: |
| 79 MOCK_METHOD3(OnError, | 79 MOCK_METHOD3(OnError, |
| 80 void(const CastSocket* socket, | 80 void(const CastSocket* socket, |
| 81 ChannelError error, | 81 ChannelError error, |
| 82 const LastErrors& last_errors)); | 82 const LastErrors& last_errors)); |
| 83 MOCK_METHOD2(OnMessage, void(const CastSocket* socket, | 83 MOCK_METHOD2(OnMessage, |
| 84 const MessageInfo& message)); | 84 void(const CastSocket* socket, const MessageInfo& message)); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 class MockTCPSocket : public net::TCPClientSocket { | 87 class MockTCPSocket : public net::TCPClientSocket { |
| 88 public: | 88 public: |
| 89 explicit MockTCPSocket(const net::MockConnect& connect_data) : | 89 explicit MockTCPSocket(const net::MockConnect& connect_data) : |
| 90 TCPClientSocket(net::AddressList(), NULL, net::NetLog::Source()), | 90 TCPClientSocket(net::AddressList(), NULL, net::NetLog::Source()), |
| 91 connect_data_(connect_data), | 91 connect_data_(connect_data), |
| 92 do_nothing_(false) { } | 92 do_nothing_(false) { } |
| 93 | 93 |
| 94 explicit MockTCPSocket(bool do_nothing) : | 94 explicit MockTCPSocket(bool do_nothing) : |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 number.push_back(0); | 197 number.push_back(0); |
| 198 number.push_back(1); | 198 number.push_back(1); |
| 199 return net::IPEndPoint(number, 8009); | 199 return net::IPEndPoint(number, 8009); |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Returns the size of the body (in bytes) of the given serialized message. | 202 // Returns the size of the body (in bytes) of the given serialized message. |
| 203 static size_t ComputeBodySize(const std::string& msg) { | 203 static size_t ComputeBodySize(const std::string& msg) { |
| 204 return msg.length() - MessageFramer::MessageHeader::header_size(); | 204 return msg.length() - MessageFramer::MessageHeader::header_size(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 virtual ~TestCastSocket() { | 207 virtual ~TestCastSocket() {} |
| 208 } | |
| 209 | 208 |
| 210 // Helpers to set mock results for various operations. | 209 // Helpers to set mock results for various operations. |
| 211 void SetupTcp1Connect(net::IoMode mode, int result) { | 210 void SetupTcp1Connect(net::IoMode mode, int result) { |
| 212 tcp_connect_data_[0].reset(new net::MockConnect(mode, result)); | 211 tcp_connect_data_[0].reset(new net::MockConnect(mode, result)); |
| 213 } | 212 } |
| 214 void SetupSsl1Connect(net::IoMode mode, int result) { | 213 void SetupSsl1Connect(net::IoMode mode, int result) { |
| 215 ssl_connect_data_[0].reset(new net::MockConnect(mode, result)); | 214 ssl_connect_data_[0].reset(new net::MockConnect(mode, result)); |
| 216 } | 215 } |
| 217 void SetupTcp2Connect(net::IoMode mode, int result) { | 216 void SetupTcp2Connect(net::IoMode mode, int result) { |
| 218 tcp_connect_data_[1].reset(new net::MockConnect(mode, result)); | 217 tcp_connect_data_[1].reset(new net::MockConnect(mode, result)); |
| (...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 A<const LastErrors&>())); | 1203 A<const LastErrors&>())); |
| 1205 ConnectHelper(); | 1204 ConnectHelper(); |
| 1206 | 1205 |
| 1207 EXPECT_EQ(cast_channel::READY_STATE_CLOSED, socket_->ready_state()); | 1206 EXPECT_EQ(cast_channel::READY_STATE_CLOSED, socket_->ready_state()); |
| 1208 EXPECT_EQ(cast_channel::CHANNEL_ERROR_INVALID_MESSAGE, | 1207 EXPECT_EQ(cast_channel::CHANNEL_ERROR_INVALID_MESSAGE, |
| 1209 socket_->error_state()); | 1208 socket_->error_state()); |
| 1210 } | 1209 } |
| 1211 } // namespace cast_channel | 1210 } // namespace cast_channel |
| 1212 } // namespace core_api | 1211 } // namespace core_api |
| 1213 } // namespace extensions | 1212 } // namespace extensions |
| OLD | NEW |