Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: blimp/net/test_common.cc

Issue 2439403003: Refactor BlimpConnection to TCPConnection (Closed)
Patch Set: Sync merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "blimp/net/test_common.h" 5 #include "blimp/net/test_common.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility>
8 9
9 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
10 #include "base/sys_byteorder.h" 11 #include "base/sys_byteorder.h"
11 #include "blimp/common/proto/blimp_message.pb.h" 12 #include "blimp/common/proto/blimp_message.pb.h"
12 #include "blimp/net/blimp_connection.h" 13 #include "blimp/net/blimp_connection.h"
13 #include "blimp/net/common.h" 14 #include "blimp/net/common.h"
14 #include "blimp/net/message_port.h" 15 #include "blimp/net/message_port.h"
15 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
16 17
17 namespace blimp { 18 namespace blimp {
18 19
19 MockStreamSocket::MockStreamSocket() {} 20 MockStreamSocket::MockStreamSocket() {}
20 21
21 MockStreamSocket::~MockStreamSocket() {} 22 MockStreamSocket::~MockStreamSocket() {}
22 23
23 MockTransport::MockTransport() {} 24 MockTransport::MockTransport() {}
24 25
26 std::unique_ptr<BlimpConnection> MockTransport::MakeConnection() {
27 return std::move(connection_);
28 }
29
30 void MockTransport::SetMockConnection(
31 std::unique_ptr<MockBlimpConnection> connection) {
32 connection_ = std::move(connection);
33 }
34
25 MockTransport::~MockTransport() {} 35 MockTransport::~MockTransport() {}
26 36
27 std::unique_ptr<MessagePort> MockTransport::TakeMessagePort() { 37 const char* MockTransport::GetName() const { return "mock"; }
28 return base::WrapUnique(TakeMessagePortPtr());
29 }
30
31 const char* MockTransport::GetName() const {
32 return "mock";
33 }
34 38
35 MockConnectionHandler::MockConnectionHandler() {} 39 MockConnectionHandler::MockConnectionHandler() {}
36 40
37 MockConnectionHandler::~MockConnectionHandler() {} 41 MockConnectionHandler::~MockConnectionHandler() {}
38 42
39 void MockConnectionHandler::HandleConnection( 43 void MockConnectionHandler::HandleConnection(
40 std::unique_ptr<BlimpConnection> connection) { 44 std::unique_ptr<BlimpConnection> connection) {
41 HandleConnectionPtr(connection.get()); 45 HandleConnectionPtr(connection.get());
42 } 46 }
43 47
(...skipping 23 matching lines...) Expand all
67 MockableProcessMessage(*message, callback); 71 MockableProcessMessage(*message, callback);
68 } 72 }
69 73
70 std::string EncodeHeader(size_t size) { 74 std::string EncodeHeader(size_t size) {
71 std::unique_ptr<char[]> serialized(new char[kPacketHeaderSizeBytes]); 75 std::unique_ptr<char[]> serialized(new char[kPacketHeaderSizeBytes]);
72 uint32_t net_size = base::HostToNet32(size); 76 uint32_t net_size = base::HostToNet32(size);
73 memcpy(serialized.get(), &net_size, sizeof(net_size)); 77 memcpy(serialized.get(), &net_size, sizeof(net_size));
74 return std::string(serialized.get(), kPacketHeaderSizeBytes); 78 return std::string(serialized.get(), kPacketHeaderSizeBytes);
75 } 79 }
76 80
77 bool BufferStartsWith(net::GrowableIOBuffer* buf, 81 bool BufferStartsWith(net::GrowableIOBuffer* buf, size_t buf_size,
78 size_t buf_size,
79 const std::string& str) { 82 const std::string& str) {
80 return (buf_size >= str.size() && 83 return (buf_size >= str.size() &&
81 str == std::string(buf->data(), str.size())); 84 str == std::string(buf->data(), str.size()));
82 } 85 }
83 86
84 } // namespace blimp 87 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698