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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "ipc/brokerable_attachment.h" |
15 #include "ipc/ipc_channel_reader.h" | 16 #include "ipc/ipc_channel_reader.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace IPC { | 19 namespace IPC { |
19 namespace internal { | 20 namespace internal { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 class MockChannelReader : public ChannelReader { | 24 class MockChannelReader : public ChannelReader { |
24 public: | 25 public: |
25 MockChannelReader() | 26 MockChannelReader() |
26 : ChannelReader(nullptr), last_dispatched_message_(nullptr) {} | 27 : ChannelReader(nullptr), last_dispatched_message_(nullptr) {} |
27 | 28 |
28 ReadState ReadData(char* buffer, int buffer_len, int* bytes_read) override { | 29 ReadState ReadData(char* buffer, int buffer_len, int* bytes_read) override { |
29 if (data_.empty()) | 30 if (data_.empty()) |
30 return READ_PENDING; | 31 return READ_PENDING; |
31 | 32 |
32 size_t read_len = std::min(static_cast<size_t>(buffer_len), data_.size()); | 33 size_t read_len = std::min(static_cast<size_t>(buffer_len), data_.size()); |
33 memcpy(buffer, data_.data(), read_len); | 34 memcpy(buffer, data_.data(), read_len); |
34 *bytes_read = static_cast<int>(read_len); | 35 *bytes_read = static_cast<int>(read_len); |
35 data_.erase(0, read_len); | 36 data_.erase(0, read_len); |
36 return READ_SUCCEEDED; | 37 return READ_SUCCEEDED; |
37 } | 38 } |
38 | 39 |
39 bool ShouldDispatchInputMessage(Message* msg) override { return true; } | 40 bool ShouldDispatchInputMessage(Message* msg) override { return true; } |
40 | 41 |
41 bool GetAttachments(Message* msg) override { return true; } | 42 bool GetNonBrokeredAttachments(Message* msg) override { return true; } |
42 | 43 |
43 bool DidEmptyInputBuffers() override { return true; } | 44 bool DidEmptyInputBuffers() override { return true; } |
44 | 45 |
45 void HandleInternalMessage(const Message& msg) override {} | 46 void HandleInternalMessage(const Message& msg) override {} |
46 | 47 |
47 void DispatchMessage(Message* m) override { last_dispatched_message_ = m; } | 48 void DispatchMessage(Message* m) override { last_dispatched_message_ = m; } |
48 | 49 |
49 Message* get_last_dispatched_message() { return last_dispatched_message_; } | 50 Message* get_last_dispatched_message() { return last_dispatched_message_; } |
50 | 51 |
51 void AppendData(const void* data, size_t size) { | 52 void AppendData(const void* data, size_t size) { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 reader.ProcessIncomingMessages()); | 241 reader.ProcessIncomingMessages()); |
241 | 242 |
242 // We determined message size for the second (partial) message, so | 243 // We determined message size for the second (partial) message, so |
243 // we resized the buffer to fit. | 244 // we resized the buffer to fit. |
244 EXPECT_GE(reader.input_overflow_buf_.capacity(), message2.size()); | 245 EXPECT_GE(reader.input_overflow_buf_.capacity(), message2.size()); |
245 } | 246 } |
246 } | 247 } |
247 | 248 |
248 } // namespace internal | 249 } // namespace internal |
249 } // namespace IPC | 250 } // namespace IPC |
OLD | NEW |