Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: ipc/ipc_channel_reader_unittest.cc

Issue 1286253002: IPC: Add attachment brokering support to the message header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compile error. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc_channel_reader.cc ('k') | ipc/ipc_channel_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ipc/attachment_broker.h" 9 #include "ipc/attachment_broker.h"
10 #include "ipc/brokerable_attachment.h" 10 #include "ipc/brokerable_attachment.h"
11 #include "ipc/ipc_channel_reader.h" 11 #include "ipc/ipc_channel_reader.h"
12 #include "ipc/placeholder_brokerable_attachment.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
20 class MockAttachment : public BrokerableAttachment { 21 class MockAttachment : public BrokerableAttachment {
21 public: 22 public:
22 MockAttachment(int internal_state) : internal_state_(internal_state) {} 23 MockAttachment() {}
23 MockAttachment(BrokerableAttachment::AttachmentId id) 24 MockAttachment(BrokerableAttachment::AttachmentId id)
24 : BrokerableAttachment(id, true), internal_state_(-1) {} 25 : BrokerableAttachment(id) {}
25
26 void PopulateWithAttachment(const BrokerableAttachment* attachment) override {
27 const MockAttachment* mock_attachment =
28 static_cast<const MockAttachment*>(attachment);
29 internal_state_ = mock_attachment->internal_state_;
30 }
31 26
32 #if defined(OS_POSIX) 27 #if defined(OS_POSIX)
33 base::PlatformFile TakePlatformFile() override { 28 base::PlatformFile TakePlatformFile() override {
34 return base::PlatformFile(); 29 return base::PlatformFile();
35 } 30 }
36 #endif // OS_POSIX 31 #endif // OS_POSIX
37 32
38 BrokerableType GetBrokerableType() const override { return WIN_HANDLE; } 33 BrokerableType GetBrokerableType() const override { return WIN_HANDLE; }
39 34
40 private: 35 private:
41 ~MockAttachment() override {} 36 ~MockAttachment() override {}
42 // Internal state differentiates MockAttachments.
43 int internal_state_;
44 }; 37 };
45 38
46 class MockAttachmentBroker : public AttachmentBroker { 39 class MockAttachmentBroker : public AttachmentBroker {
47 public: 40 public:
48 typedef std::set<scoped_refptr<BrokerableAttachment>> AttachmentSet; 41 typedef std::set<scoped_refptr<BrokerableAttachment>> AttachmentSet;
49 42
50 bool SendAttachmentToProcess(const BrokerableAttachment* attachment, 43 bool SendAttachmentToProcess(const BrokerableAttachment* attachment,
51 base::ProcessId destination_process) override { 44 base::ProcessId destination_process) override {
52 return false; 45 return false;
53 } 46 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 Message* last_dispatched_message_; 91 Message* last_dispatched_message_;
99 AttachmentBroker* broker_; 92 AttachmentBroker* broker_;
100 }; 93 };
101 94
102 } // namespace 95 } // namespace
103 96
104 TEST(ChannelReaderTest, AttachmentAlreadyBrokered) { 97 TEST(ChannelReaderTest, AttachmentAlreadyBrokered) {
105 MockAttachmentBroker broker; 98 MockAttachmentBroker broker;
106 MockChannelReader reader; 99 MockChannelReader reader;
107 reader.set_broker(&broker); 100 reader.set_broker(&broker);
108 scoped_refptr<MockAttachment> attachment(new MockAttachment(5)); 101 scoped_refptr<MockAttachment> attachment(new MockAttachment);
109 broker.AddAttachment(attachment); 102 broker.AddAttachment(attachment);
110 103
111 Message* m = new Message; 104 Message* m = new Message;
112 MockAttachment* needs_brokering_attachment = 105 PlaceholderBrokerableAttachment* needs_brokering_attachment =
113 new MockAttachment(attachment->GetIdentifier()); 106 new PlaceholderBrokerableAttachment(attachment->GetIdentifier());
114 EXPECT_TRUE(m->WriteAttachment(needs_brokering_attachment)); 107 EXPECT_TRUE(m->WriteAttachment(needs_brokering_attachment));
115 reader.AddMessageForDispatch(m); 108 reader.AddMessageForDispatch(m);
116 EXPECT_EQ(ChannelReader::DISPATCH_FINISHED, reader.DispatchMessages()); 109 EXPECT_EQ(ChannelReader::DISPATCH_FINISHED, reader.DispatchMessages());
117 EXPECT_EQ(m, reader.get_last_dispatched_message()); 110 EXPECT_EQ(m, reader.get_last_dispatched_message());
118 } 111 }
119 112
120 TEST(ChannelReaderTest, AttachmentNotYetBrokered) { 113 TEST(ChannelReaderTest, AttachmentNotYetBrokered) {
121 MockAttachmentBroker broker; 114 MockAttachmentBroker broker;
122 MockChannelReader reader; 115 MockChannelReader reader;
123 reader.set_broker(&broker); 116 reader.set_broker(&broker);
124 scoped_refptr<MockAttachment> attachment(new MockAttachment(5)); 117 scoped_refptr<MockAttachment> attachment(new MockAttachment);
125 118
126 Message* m = new Message; 119 Message* m = new Message;
127 MockAttachment* needs_brokering_attachment = 120 PlaceholderBrokerableAttachment* needs_brokering_attachment =
128 new MockAttachment(attachment->GetIdentifier()); 121 new PlaceholderBrokerableAttachment(attachment->GetIdentifier());
129 EXPECT_TRUE(m->WriteAttachment(needs_brokering_attachment)); 122 EXPECT_TRUE(m->WriteAttachment(needs_brokering_attachment));
130 reader.AddMessageForDispatch(m); 123 reader.AddMessageForDispatch(m);
131 EXPECT_EQ(ChannelReader::DISPATCH_WAITING_ON_BROKER, 124 EXPECT_EQ(ChannelReader::DISPATCH_WAITING_ON_BROKER,
132 reader.DispatchMessages()); 125 reader.DispatchMessages());
133 EXPECT_EQ(nullptr, reader.get_last_dispatched_message()); 126 EXPECT_EQ(nullptr, reader.get_last_dispatched_message());
134 127
135 broker.AddAttachment(attachment); 128 broker.AddAttachment(attachment);
136 EXPECT_EQ(m, reader.get_last_dispatched_message()); 129 EXPECT_EQ(m, reader.get_last_dispatched_message());
137 } 130 }
138 131
139 } // namespace internal 132 } // namespace internal
140 } // namespace IPC 133 } // namespace IPC
141 #endif // USE_ATTACHMENT_BROKER 134 #endif // USE_ATTACHMENT_BROKER
OLDNEW
« no previous file with comments | « ipc/ipc_channel_reader.cc ('k') | ipc/ipc_channel_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698