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