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