| 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 "blimp/net/test_common.h" | 5 #include "blimp/net/test_common.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 MockConnectionErrorObserver::~MockConnectionErrorObserver() {} | 64 MockConnectionErrorObserver::~MockConnectionErrorObserver() {} |
| 65 | 65 |
| 66 MockBlimpMessageProcessor::MockBlimpMessageProcessor() {} | 66 MockBlimpMessageProcessor::MockBlimpMessageProcessor() {} |
| 67 | 67 |
| 68 MockBlimpMessageProcessor::~MockBlimpMessageProcessor() {} | 68 MockBlimpMessageProcessor::~MockBlimpMessageProcessor() {} |
| 69 | 69 |
| 70 void MockBlimpMessageProcessor::ProcessMessage( | 70 void MockBlimpMessageProcessor::ProcessMessage( |
| 71 std::unique_ptr<BlimpMessage> message, | 71 std::unique_ptr<BlimpMessage> message, |
| 72 const net::CompletionCallback& callback) { | 72 const net::CompletionCallback& callback) { |
| 73 if (!test_callback_.is_null()) { |
| 74 test_callback_.Run(net::OK); |
| 75 } |
| 76 received_msg = *message; |
| 73 MockableProcessMessage(*message, callback); | 77 MockableProcessMessage(*message, callback); |
| 74 } | 78 } |
| 75 | 79 |
| 80 void MockBlimpMessageProcessor::SetTestCompletionCallback( |
| 81 const net::CompletionCallback& callback) { |
| 82 test_callback_ = callback; |
| 83 } |
| 84 |
| 76 std::string EncodeHeader(size_t size) { | 85 std::string EncodeHeader(size_t size) { |
| 77 std::unique_ptr<char[]> serialized(new char[kPacketHeaderSizeBytes]); | 86 std::unique_ptr<char[]> serialized(new char[kPacketHeaderSizeBytes]); |
| 78 uint32_t net_size = base::HostToNet32(size); | 87 uint32_t net_size = base::HostToNet32(size); |
| 79 memcpy(serialized.get(), &net_size, sizeof(net_size)); | 88 memcpy(serialized.get(), &net_size, sizeof(net_size)); |
| 80 return std::string(serialized.get(), kPacketHeaderSizeBytes); | 89 return std::string(serialized.get(), kPacketHeaderSizeBytes); |
| 81 } | 90 } |
| 82 | 91 |
| 83 bool BufferStartsWith(net::GrowableIOBuffer* buf, | 92 bool BufferStartsWith(net::GrowableIOBuffer* buf, |
| 84 size_t buf_size, | 93 size_t buf_size, |
| 85 const std::string& str) { | 94 const std::string& str) { |
| 86 return (buf_size >= str.size() && | 95 return (buf_size >= str.size() && |
| 87 str == std::string(buf->data(), str.size())); | 96 str == std::string(buf->data(), str.size())); |
| 88 } | 97 } |
| 89 | 98 |
| 90 } // namespace blimp | 99 } // namespace blimp |
| OLD | NEW |