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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 |
| 8 #include <memory> |
7 #include <utility> | 9 #include <utility> |
8 | 10 |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
13 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
14 #include "device/serial/data_sender.h" | 16 #include "device/serial/data_sender.h" |
15 #include "device/serial/data_sink_receiver.h" | 17 #include "device/serial/data_sink_receiver.h" |
16 #include "device/serial/data_stream.mojom.h" | 18 #include "device/serial/data_stream.mojom.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 EventReceived(EVENT_SEND_SUCCESS); | 153 EventReceived(EVENT_SEND_SUCCESS); |
152 } | 154 } |
153 | 155 |
154 void OnSendError(uint32_t bytes_sent, int32_t error) { | 156 void OnSendError(uint32_t bytes_sent, int32_t error) { |
155 bytes_sent_ = bytes_sent; | 157 bytes_sent_ = bytes_sent; |
156 send_error_ = error; | 158 send_error_ = error; |
157 has_send_error_ = true; | 159 has_send_error_ = true; |
158 EventReceived(EVENT_SEND_ERROR); | 160 EventReceived(EVENT_SEND_ERROR); |
159 } | 161 } |
160 | 162 |
161 void OnDataToRead(scoped_ptr<ReadOnlyBuffer> buffer) { | 163 void OnDataToRead(std::unique_ptr<ReadOnlyBuffer> buffer) { |
162 read_buffer_ = std::move(buffer); | 164 read_buffer_ = std::move(buffer); |
163 read_buffer_contents_ = | 165 read_buffer_contents_ = |
164 std::string(read_buffer_->GetData(), read_buffer_->GetSize()); | 166 std::string(read_buffer_->GetData(), read_buffer_->GetSize()); |
165 EventReceived(EVENT_READ_BUFFER_READY); | 167 EventReceived(EVENT_READ_BUFFER_READY); |
166 } | 168 } |
167 | 169 |
168 bool Cancel(int32_t error) { | 170 bool Cancel(int32_t error) { |
169 return sender_->Cancel( | 171 return sender_->Cancel( |
170 error, base::Bind(&DataSinkTest::CancelAck, base::Unretained(this))); | 172 error, base::Bind(&DataSinkTest::CancelAck, base::Unretained(this))); |
171 } | 173 } |
172 | 174 |
173 void CancelAck() { EventReceived(EVENT_CANCEL_COMPLETE); } | 175 void CancelAck() { EventReceived(EVENT_CANCEL_COMPLETE); } |
174 | 176 |
175 void OnCancel(int32_t error) { | 177 void OnCancel(int32_t error) { |
176 cancel_error_ = error; | 178 cancel_error_ = error; |
177 EventReceived(EVENT_CANCEL_RECEIVED); | 179 EventReceived(EVENT_CANCEL_RECEIVED); |
178 } | 180 } |
179 | 181 |
180 protected: | 182 protected: |
181 static const int32_t kFatalError; | 183 static const int32_t kFatalError; |
182 static const uint32_t kBufferSize; | 184 static const uint32_t kBufferSize; |
183 scoped_ptr<base::MessageLoop> message_loop_; | 185 std::unique_ptr<base::MessageLoop> message_loop_; |
184 base::Closure stop_run_loop_; | 186 base::Closure stop_run_loop_; |
185 | 187 |
186 scoped_refptr<DataSinkReceiver> sink_receiver_; | 188 scoped_refptr<DataSinkReceiver> sink_receiver_; |
187 scoped_ptr<DataSender> sender_; | 189 std::unique_ptr<DataSender> sender_; |
188 | 190 |
189 uint32_t bytes_sent_; | 191 uint32_t bytes_sent_; |
190 int32_t send_error_; | 192 int32_t send_error_; |
191 bool has_send_error_; | 193 bool has_send_error_; |
192 int32_t cancel_error_; | 194 int32_t cancel_error_; |
193 scoped_ptr<ReadOnlyBuffer> read_buffer_; | 195 std::unique_ptr<ReadOnlyBuffer> read_buffer_; |
194 std::string read_buffer_contents_; | 196 std::string read_buffer_contents_; |
195 | 197 |
196 bool seen_connection_error_; | 198 bool seen_connection_error_; |
197 | 199 |
198 Event expected_event_; | 200 Event expected_event_; |
199 | 201 |
200 private: | 202 private: |
201 DISALLOW_COPY_AND_ASSIGN(DataSinkTest); | 203 DISALLOW_COPY_AND_ASSIGN(DataSinkTest); |
202 }; | 204 }; |
203 | 205 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 sender_.reset(); | 410 sender_.reset(); |
409 ExpectSendError(0, kFatalError); | 411 ExpectSendError(0, kFatalError); |
410 ExpectSendError(0, kFatalError); | 412 ExpectSendError(0, kFatalError); |
411 ExpectCancelResult(); | 413 ExpectCancelResult(); |
412 if (!seen_connection_error_) | 414 if (!seen_connection_error_) |
413 WaitForEvent(EVENT_ERROR); | 415 WaitForEvent(EVENT_ERROR); |
414 EXPECT_TRUE(seen_connection_error_); | 416 EXPECT_TRUE(seen_connection_error_); |
415 } | 417 } |
416 | 418 |
417 } // namespace device | 419 } // namespace device |
OLD | NEW |