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 <set> | 7 #include <set> |
8 | 8 |
| 9 #include "crypto/random.h" |
9 #include "ipc/attachment_broker.h" | 10 #include "ipc/attachment_broker.h" |
10 #include "ipc/brokerable_attachment.h" | 11 #include "ipc/brokerable_attachment.h" |
11 #include "ipc/ipc_channel_reader.h" | 12 #include "ipc/ipc_channel_reader.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 #if USE_ATTACHMENT_BROKER | 15 #if USE_ATTACHMENT_BROKER |
15 namespace IPC { | 16 namespace IPC { |
16 namespace internal { | 17 namespace internal { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
| 21 BrokerableAttachment::AttachmentId GenerateAttachementId() { |
| 22 BrokerableAttachment::AttachmentId result; |
| 23 crypto::RandBytes(result.nonce, BrokerableAttachment::kNonceSize); |
| 24 return result; |
| 25 } |
| 26 |
20 class MockAttachment : public BrokerableAttachment { | 27 class MockAttachment : public BrokerableAttachment { |
21 public: | 28 public: |
22 MockAttachment(int internal_state) : internal_state_(internal_state) {} | 29 MockAttachment(int internal_state) |
| 30 : BrokerableAttachment(GenerateAttachementId(), true), |
| 31 internal_state_(internal_state) {} |
23 MockAttachment(BrokerableAttachment::AttachmentId id) | 32 MockAttachment(BrokerableAttachment::AttachmentId id) |
24 : BrokerableAttachment(id, true), internal_state_(-1) {} | 33 : BrokerableAttachment(id, true), internal_state_(-1) {} |
25 | 34 |
26 void PopulateWithAttachment(const BrokerableAttachment* attachment) override { | 35 void PopulateWithAttachment(const BrokerableAttachment* attachment) override { |
27 const MockAttachment* mock_attachment = | 36 const MockAttachment* mock_attachment = |
28 static_cast<const MockAttachment*>(attachment); | 37 static_cast<const MockAttachment*>(attachment); |
29 internal_state_ = mock_attachment->internal_state_; | 38 internal_state_ = mock_attachment->internal_state_; |
30 } | 39 } |
31 | 40 |
32 #if defined(OS_POSIX) | 41 #if defined(OS_POSIX) |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 reader.DispatchMessages()); | 141 reader.DispatchMessages()); |
133 EXPECT_EQ(nullptr, reader.get_last_dispatched_message()); | 142 EXPECT_EQ(nullptr, reader.get_last_dispatched_message()); |
134 | 143 |
135 broker.AddAttachment(attachment); | 144 broker.AddAttachment(attachment); |
136 EXPECT_EQ(m, reader.get_last_dispatched_message()); | 145 EXPECT_EQ(m, reader.get_last_dispatched_message()); |
137 } | 146 } |
138 | 147 |
139 } // namespace internal | 148 } // namespace internal |
140 } // namespace IPC | 149 } // namespace IPC |
141 #endif // USE_ATTACHMENT_BROKER | 150 #endif // USE_ATTACHMENT_BROKER |
OLD | NEW |