OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 &MockMDnsSocketFactory::SendToInternal)); | 82 &MockMDnsSocketFactory::SendToInternal)); |
83 | 83 |
84 ON_CALL(*new_socket, RecvFrom(_, _, _, _)) | 84 ON_CALL(*new_socket, RecvFrom(_, _, _, _)) |
85 .WillByDefault(Invoke( | 85 .WillByDefault(Invoke( |
86 this, | 86 this, |
87 &MockMDnsSocketFactory::RecvFromInternal)); | 87 &MockMDnsSocketFactory::RecvFromInternal)); |
88 | 88 |
89 sockets->push_back(new_socket.Pass()); | 89 sockets->push_back(new_socket.Pass()); |
90 } | 90 } |
91 | 91 |
92 void MockMDnsSocketFactory::SimulateReceive(const uint8* packet, int size) { | 92 void MockMDnsSocketFactory::SimulateReceive(const uint8_t* packet, int size) { |
93 DCHECK(recv_buffer_size_ >= size); | 93 DCHECK(recv_buffer_size_ >= size); |
94 DCHECK(recv_buffer_.get()); | 94 DCHECK(recv_buffer_.get()); |
95 DCHECK(!recv_callback_.is_null()); | 95 DCHECK(!recv_callback_.is_null()); |
96 | 96 |
97 memcpy(recv_buffer_->data(), packet, size); | 97 memcpy(recv_buffer_->data(), packet, size); |
98 CompletionCallback recv_callback = recv_callback_; | 98 CompletionCallback recv_callback = recv_callback_; |
99 recv_callback_.Reset(); | 99 recv_callback_.Reset(); |
100 recv_callback.Run(size); | 100 recv_callback.Run(size); |
101 } | 101 } |
102 | 102 |
103 int MockMDnsSocketFactory::RecvFromInternal( | 103 int MockMDnsSocketFactory::RecvFromInternal( |
104 IOBuffer* buffer, int size, | 104 IOBuffer* buffer, int size, |
105 IPEndPoint* address, | 105 IPEndPoint* address, |
106 const CompletionCallback& callback) { | 106 const CompletionCallback& callback) { |
107 recv_buffer_ = buffer; | 107 recv_buffer_ = buffer; |
108 recv_buffer_size_ = size; | 108 recv_buffer_size_ = size; |
109 recv_callback_ = callback; | 109 recv_callback_ = callback; |
110 return ERR_IO_PENDING; | 110 return ERR_IO_PENDING; |
111 } | 111 } |
112 | 112 |
113 int MockMDnsSocketFactory::SendToInternal( | 113 int MockMDnsSocketFactory::SendToInternal( |
114 const std::string& packet, const std::string& address, | 114 const std::string& packet, const std::string& address, |
115 const CompletionCallback& callback) { | 115 const CompletionCallback& callback) { |
116 OnSendTo(packet); | 116 OnSendTo(packet); |
117 return packet.size(); | 117 return packet.size(); |
118 } | 118 } |
119 | 119 |
120 } // namespace net | 120 } // namespace net |
OLD | NEW |