OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "ipc/ipc_message.h" | 10 #include "ipc/ipc_message.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } // namespace IPC | 42 } // namespace IPC |
43 | 43 |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
47 class QuitListener : public IPC::Listener { | 47 class QuitListener : public IPC::Listener { |
48 public: | 48 public: |
49 QuitListener() : bad_message_received_(false) {} | 49 QuitListener() : bad_message_received_(false) {} |
50 virtual ~QuitListener() {} | 50 virtual ~QuitListener() {} |
51 | 51 |
52 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 52 virtual bool OnMessageReceived(const IPC::Message& message) override { |
53 IPC_BEGIN_MESSAGE_MAP(QuitListener, message) | 53 IPC_BEGIN_MESSAGE_MAP(QuitListener, message) |
54 IPC_MESSAGE_HANDLER(WorkerMsg_Quit, OnQuit) | 54 IPC_MESSAGE_HANDLER(WorkerMsg_Quit, OnQuit) |
55 IPC_MESSAGE_HANDLER(TestMsg_BadMessage, OnBadMessage) | 55 IPC_MESSAGE_HANDLER(TestMsg_BadMessage, OnBadMessage) |
56 IPC_END_MESSAGE_MAP() | 56 IPC_END_MESSAGE_MAP() |
57 return true; | 57 return true; |
58 } | 58 } |
59 | 59 |
60 virtual void OnBadMessageReceived(const IPC::Message& message) OVERRIDE { | 60 virtual void OnBadMessageReceived(const IPC::Message& message) override { |
61 bad_message_received_ = true; | 61 bad_message_received_ = true; |
62 } | 62 } |
63 | 63 |
64 void OnQuit() { | 64 void OnQuit() { |
65 base::MessageLoop::current()->QuitWhenIdle(); | 65 base::MessageLoop::current()->QuitWhenIdle(); |
66 } | 66 } |
67 | 67 |
68 void OnBadMessage(const BadType& bad_type) { | 68 void OnBadMessage(const BadType& bad_type) { |
69 // Should never be called since IPC wouldn't be deserialized correctly. | 69 // Should never be called since IPC wouldn't be deserialized correctly. |
70 CHECK(false); | 70 CHECK(false); |
71 } | 71 } |
72 | 72 |
73 bool bad_message_received_; | 73 bool bad_message_received_; |
74 }; | 74 }; |
75 | 75 |
76 class ChannelReflectorListener : public IPC::Listener { | 76 class ChannelReflectorListener : public IPC::Listener { |
77 public: | 77 public: |
78 ChannelReflectorListener() : channel_(NULL) {} | 78 ChannelReflectorListener() : channel_(NULL) {} |
79 virtual ~ChannelReflectorListener() {} | 79 virtual ~ChannelReflectorListener() {} |
80 | 80 |
81 void Init(IPC::Channel* channel) { | 81 void Init(IPC::Channel* channel) { |
82 DCHECK(!channel_); | 82 DCHECK(!channel_); |
83 channel_ = channel; | 83 channel_ = channel; |
84 } | 84 } |
85 | 85 |
86 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 86 virtual bool OnMessageReceived(const IPC::Message& message) override { |
87 IPC_BEGIN_MESSAGE_MAP(ChannelReflectorListener, message) | 87 IPC_BEGIN_MESSAGE_MAP(ChannelReflectorListener, message) |
88 IPC_MESSAGE_HANDLER(TestMsg_Bounce, OnTestBounce) | 88 IPC_MESSAGE_HANDLER(TestMsg_Bounce, OnTestBounce) |
89 IPC_MESSAGE_HANDLER(TestMsg_SendBadMessage, OnSendBadMessage) | 89 IPC_MESSAGE_HANDLER(TestMsg_SendBadMessage, OnSendBadMessage) |
90 IPC_MESSAGE_HANDLER(UtilityMsg_Bounce, OnUtilityBounce) | 90 IPC_MESSAGE_HANDLER(UtilityMsg_Bounce, OnUtilityBounce) |
91 IPC_MESSAGE_HANDLER(WorkerMsg_Bounce, OnBounce) | 91 IPC_MESSAGE_HANDLER(WorkerMsg_Bounce, OnBounce) |
92 IPC_MESSAGE_HANDLER(WorkerMsg_Quit, OnQuit) | 92 IPC_MESSAGE_HANDLER(WorkerMsg_Quit, OnQuit) |
93 IPC_END_MESSAGE_MAP() | 93 IPC_END_MESSAGE_MAP() |
94 return true; | 94 return true; |
95 } | 95 } |
96 | 96 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 last_filter_event_(NONE), | 136 last_filter_event_(NONE), |
137 message_filtering_enabled_(false) {} | 137 message_filtering_enabled_(false) {} |
138 | 138 |
139 MessageCountFilter(uint32 supported_message_class) | 139 MessageCountFilter(uint32 supported_message_class) |
140 : messages_received_(0), | 140 : messages_received_(0), |
141 supported_message_class_(supported_message_class), | 141 supported_message_class_(supported_message_class), |
142 is_global_filter_(false), | 142 is_global_filter_(false), |
143 last_filter_event_(NONE), | 143 last_filter_event_(NONE), |
144 message_filtering_enabled_(false) {} | 144 message_filtering_enabled_(false) {} |
145 | 145 |
146 virtual void OnFilterAdded(IPC::Sender* sender) OVERRIDE { | 146 virtual void OnFilterAdded(IPC::Sender* sender) override { |
147 EXPECT_TRUE(sender); | 147 EXPECT_TRUE(sender); |
148 EXPECT_EQ(NONE, last_filter_event_); | 148 EXPECT_EQ(NONE, last_filter_event_); |
149 last_filter_event_ = FILTER_ADDED; | 149 last_filter_event_ = FILTER_ADDED; |
150 } | 150 } |
151 | 151 |
152 virtual void OnChannelConnected(int32_t peer_pid) OVERRIDE { | 152 virtual void OnChannelConnected(int32_t peer_pid) override { |
153 EXPECT_EQ(FILTER_ADDED, last_filter_event_); | 153 EXPECT_EQ(FILTER_ADDED, last_filter_event_); |
154 EXPECT_NE(static_cast<int32_t>(base::kNullProcessId), peer_pid); | 154 EXPECT_NE(static_cast<int32_t>(base::kNullProcessId), peer_pid); |
155 last_filter_event_ = CHANNEL_CONNECTED; | 155 last_filter_event_ = CHANNEL_CONNECTED; |
156 } | 156 } |
157 | 157 |
158 virtual void OnChannelError() OVERRIDE { | 158 virtual void OnChannelError() override { |
159 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_); | 159 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_); |
160 last_filter_event_ = CHANNEL_ERROR; | 160 last_filter_event_ = CHANNEL_ERROR; |
161 } | 161 } |
162 | 162 |
163 virtual void OnChannelClosing() OVERRIDE { | 163 virtual void OnChannelClosing() override { |
164 // We may or may not have gotten OnChannelError; if not, the last event has | 164 // We may or may not have gotten OnChannelError; if not, the last event has |
165 // to be OnChannelConnected. | 165 // to be OnChannelConnected. |
166 if (last_filter_event_ != CHANNEL_ERROR) | 166 if (last_filter_event_ != CHANNEL_ERROR) |
167 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_); | 167 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_); |
168 last_filter_event_ = CHANNEL_CLOSING; | 168 last_filter_event_ = CHANNEL_CLOSING; |
169 } | 169 } |
170 | 170 |
171 virtual void OnFilterRemoved() OVERRIDE { | 171 virtual void OnFilterRemoved() override { |
172 // If the channel didn't get a chance to connect, we might see the | 172 // If the channel didn't get a chance to connect, we might see the |
173 // OnFilterRemoved event with no other events preceding it. We still want | 173 // OnFilterRemoved event with no other events preceding it. We still want |
174 // OnFilterRemoved to be called to allow for deleting the Filter. | 174 // OnFilterRemoved to be called to allow for deleting the Filter. |
175 if (last_filter_event_ != NONE) | 175 if (last_filter_event_ != NONE) |
176 EXPECT_EQ(CHANNEL_CLOSING, last_filter_event_); | 176 EXPECT_EQ(CHANNEL_CLOSING, last_filter_event_); |
177 last_filter_event_ = FILTER_REMOVED; | 177 last_filter_event_ = FILTER_REMOVED; |
178 } | 178 } |
179 | 179 |
180 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 180 virtual bool OnMessageReceived(const IPC::Message& message) override { |
181 // We should always get the OnFilterAdded and OnChannelConnected events | 181 // We should always get the OnFilterAdded and OnChannelConnected events |
182 // prior to any messages. | 182 // prior to any messages. |
183 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_); | 183 EXPECT_EQ(CHANNEL_CONNECTED, last_filter_event_); |
184 | 184 |
185 if (!is_global_filter_) { | 185 if (!is_global_filter_) { |
186 EXPECT_EQ(supported_message_class_, IPC_MESSAGE_CLASS(message)); | 186 EXPECT_EQ(supported_message_class_, IPC_MESSAGE_CLASS(message)); |
187 } | 187 } |
188 ++messages_received_; | 188 ++messages_received_; |
189 | 189 |
190 if (!message_filtering_enabled_) | 190 if (!message_filtering_enabled_) |
191 return false; | 191 return false; |
192 | 192 |
193 bool handled = true; | 193 bool handled = true; |
194 IPC_BEGIN_MESSAGE_MAP(MessageCountFilter, message) | 194 IPC_BEGIN_MESSAGE_MAP(MessageCountFilter, message) |
195 IPC_MESSAGE_HANDLER(TestMsg_BadMessage, OnBadMessage) | 195 IPC_MESSAGE_HANDLER(TestMsg_BadMessage, OnBadMessage) |
196 IPC_MESSAGE_UNHANDLED(handled = false) | 196 IPC_MESSAGE_UNHANDLED(handled = false) |
197 IPC_END_MESSAGE_MAP() | 197 IPC_END_MESSAGE_MAP() |
198 return handled; | 198 return handled; |
199 } | 199 } |
200 | 200 |
201 void OnBadMessage(const BadType& bad_type) { | 201 void OnBadMessage(const BadType& bad_type) { |
202 // Should never be called since IPC wouldn't be deserialized correctly. | 202 // Should never be called since IPC wouldn't be deserialized correctly. |
203 CHECK(false); | 203 CHECK(false); |
204 } | 204 } |
205 | 205 |
206 virtual bool GetSupportedMessageClasses( | 206 virtual bool GetSupportedMessageClasses( |
207 std::vector<uint32>* supported_message_classes) const OVERRIDE { | 207 std::vector<uint32>* supported_message_classes) const override { |
208 if (is_global_filter_) | 208 if (is_global_filter_) |
209 return false; | 209 return false; |
210 supported_message_classes->push_back(supported_message_class_); | 210 supported_message_classes->push_back(supported_message_class_); |
211 return true; | 211 return true; |
212 } | 212 } |
213 | 213 |
214 void set_message_filtering_enabled(bool enabled) { | 214 void set_message_filtering_enabled(bool enabled) { |
215 message_filtering_enabled_ = enabled; | 215 message_filtering_enabled_ = enabled; |
216 } | 216 } |
217 | 217 |
218 size_t messages_received() const { return messages_received_; } | 218 size_t messages_received() const { return messages_received_; } |
219 FilterEvent last_filter_event() const { return last_filter_event_; } | 219 FilterEvent last_filter_event() const { return last_filter_event_; } |
220 | 220 |
221 private: | 221 private: |
222 virtual ~MessageCountFilter() {} | 222 virtual ~MessageCountFilter() {} |
223 | 223 |
224 size_t messages_received_; | 224 size_t messages_received_; |
225 uint32 supported_message_class_; | 225 uint32 supported_message_class_; |
226 bool is_global_filter_; | 226 bool is_global_filter_; |
227 | 227 |
228 FilterEvent last_filter_event_; | 228 FilterEvent last_filter_event_; |
229 bool message_filtering_enabled_; | 229 bool message_filtering_enabled_; |
230 }; | 230 }; |
231 | 231 |
232 class IPCChannelProxyTest : public IPCTestBase { | 232 class IPCChannelProxyTest : public IPCTestBase { |
233 public: | 233 public: |
234 IPCChannelProxyTest() {} | 234 IPCChannelProxyTest() {} |
235 virtual ~IPCChannelProxyTest() {} | 235 virtual ~IPCChannelProxyTest() {} |
236 | 236 |
237 virtual void SetUp() OVERRIDE { | 237 virtual void SetUp() override { |
238 IPCTestBase::SetUp(); | 238 IPCTestBase::SetUp(); |
239 | 239 |
240 Init("ChannelProxyClient"); | 240 Init("ChannelProxyClient"); |
241 | 241 |
242 thread_.reset(new base::Thread("ChannelProxyTestServerThread")); | 242 thread_.reset(new base::Thread("ChannelProxyTestServerThread")); |
243 base::Thread::Options options; | 243 base::Thread::Options options; |
244 options.message_loop_type = base::MessageLoop::TYPE_IO; | 244 options.message_loop_type = base::MessageLoop::TYPE_IO; |
245 thread_->StartWithOptions(options); | 245 thread_->StartWithOptions(options); |
246 | 246 |
247 listener_.reset(new QuitListener()); | 247 listener_.reset(new QuitListener()); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 376 |
377 SendQuitMessageAndWaitForIdle(); | 377 SendQuitMessageAndWaitForIdle(); |
378 EXPECT_TRUE(DidListenerGetBadMessage()); | 378 EXPECT_TRUE(DidListenerGetBadMessage()); |
379 } | 379 } |
380 | 380 |
381 class IPCChannelBadMessageTest : public IPCTestBase { | 381 class IPCChannelBadMessageTest : public IPCTestBase { |
382 public: | 382 public: |
383 IPCChannelBadMessageTest() {} | 383 IPCChannelBadMessageTest() {} |
384 virtual ~IPCChannelBadMessageTest() {} | 384 virtual ~IPCChannelBadMessageTest() {} |
385 | 385 |
386 virtual void SetUp() OVERRIDE { | 386 virtual void SetUp() override { |
387 IPCTestBase::SetUp(); | 387 IPCTestBase::SetUp(); |
388 | 388 |
389 Init("ChannelProxyClient"); | 389 Init("ChannelProxyClient"); |
390 | 390 |
391 listener_.reset(new QuitListener()); | 391 listener_.reset(new QuitListener()); |
392 CreateChannel(listener_.get()); | 392 CreateChannel(listener_.get()); |
393 ASSERT_TRUE(ConnectChannel()); | 393 ASSERT_TRUE(ConnectChannel()); |
394 | 394 |
395 ASSERT_TRUE(StartClient()); | 395 ASSERT_TRUE(StartClient()); |
396 } | 396 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 IPCTestBase::GetChannelName("ChannelProxyClient"), | 432 IPCTestBase::GetChannelName("ChannelProxyClient"), |
433 &listener)); | 433 &listener)); |
434 CHECK(channel->Connect()); | 434 CHECK(channel->Connect()); |
435 listener.Init(channel.get()); | 435 listener.Init(channel.get()); |
436 | 436 |
437 base::MessageLoop::current()->Run(); | 437 base::MessageLoop::current()->Run(); |
438 return 0; | 438 return 0; |
439 } | 439 } |
440 | 440 |
441 } // namespace | 441 } // namespace |
OLD | NEW |