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/pickle.h" | 7 #include "base/pickle.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
10 #include "ipc/ipc_test_base.h" | 10 #include "ipc/ipc_test_base.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 262 |
263 bool DidListenerGetBadMessage() { | 263 bool DidListenerGetBadMessage() { |
264 return listener_->bad_message_received_; | 264 return listener_->bad_message_received_; |
265 } | 265 } |
266 | 266 |
267 private: | 267 private: |
268 scoped_ptr<base::Thread> thread_; | 268 scoped_ptr<base::Thread> thread_; |
269 scoped_ptr<QuitListener> listener_; | 269 scoped_ptr<QuitListener> listener_; |
270 }; | 270 }; |
271 | 271 |
272 TEST_F(IPCChannelProxyTest, MessageClassFilters) { | 272 #if defined(OS_ANDROID) |
| 273 #define MAYBE_MessageClassFilters DISABLED_MessageClassFilters |
| 274 #else |
| 275 #define MAYBE_MessageClassFilters MessageClassFilters |
| 276 #endif |
| 277 TEST_F(IPCChannelProxyTest, MAYBE_MessageClassFilters) { |
273 // Construct a filter per message class. | 278 // Construct a filter per message class. |
274 std::vector<scoped_refptr<MessageCountFilter> > class_filters; | 279 std::vector<scoped_refptr<MessageCountFilter> > class_filters; |
275 class_filters.push_back(make_scoped_refptr( | 280 class_filters.push_back(make_scoped_refptr( |
276 new MessageCountFilter(TestMsgStart))); | 281 new MessageCountFilter(TestMsgStart))); |
277 class_filters.push_back(make_scoped_refptr( | 282 class_filters.push_back(make_scoped_refptr( |
278 new MessageCountFilter(UtilityMsgStart))); | 283 new MessageCountFilter(UtilityMsgStart))); |
279 for (size_t i = 0; i < class_filters.size(); ++i) | 284 for (size_t i = 0; i < class_filters.size(); ++i) |
280 channel_proxy()->AddFilter(class_filters[i].get()); | 285 channel_proxy()->AddFilter(class_filters[i].get()); |
281 | 286 |
282 // Send a message for each class; each filter should receive just one message. | 287 // Send a message for each class; each filter should receive just one message. |
283 sender()->Send(new TestMsg_Bounce()); | 288 sender()->Send(new TestMsg_Bounce()); |
284 sender()->Send(new UtilityMsg_Bounce()); | 289 sender()->Send(new UtilityMsg_Bounce()); |
285 | 290 |
286 // Send some messages not assigned to a specific or valid message class. | 291 // Send some messages not assigned to a specific or valid message class. |
287 sender()->Send(new WorkerMsg_Bounce); | 292 sender()->Send(new WorkerMsg_Bounce); |
288 | 293 |
289 // Each filter should have received just the one sent message of the | 294 // Each filter should have received just the one sent message of the |
290 // corresponding class. | 295 // corresponding class. |
291 SendQuitMessageAndWaitForIdle(); | 296 SendQuitMessageAndWaitForIdle(); |
292 for (size_t i = 0; i < class_filters.size(); ++i) | 297 for (size_t i = 0; i < class_filters.size(); ++i) |
293 EXPECT_EQ(1U, class_filters[i]->messages_received()); | 298 EXPECT_EQ(1U, class_filters[i]->messages_received()); |
294 } | 299 } |
295 | 300 |
296 TEST_F(IPCChannelProxyTest, GlobalAndMessageClassFilters) { | 301 #if defined(OS_ANDROID) |
| 302 #define MAYBE_GlobalAndMessageClassFilters DISABLED_GlobalAndMessageClassFilters |
| 303 #else |
| 304 #define MAYBE_GlobalAndMessageClassFilters GlobalAndMessageClassFilters |
| 305 #endif |
| 306 TEST_F(IPCChannelProxyTest, MAYBE_GlobalAndMessageClassFilters) { |
297 // Add a class and global filter. | 307 // Add a class and global filter. |
298 scoped_refptr<MessageCountFilter> class_filter( | 308 scoped_refptr<MessageCountFilter> class_filter( |
299 new MessageCountFilter(TestMsgStart)); | 309 new MessageCountFilter(TestMsgStart)); |
300 class_filter->set_message_filtering_enabled(false); | 310 class_filter->set_message_filtering_enabled(false); |
301 channel_proxy()->AddFilter(class_filter.get()); | 311 channel_proxy()->AddFilter(class_filter.get()); |
302 | 312 |
303 scoped_refptr<MessageCountFilter> global_filter(new MessageCountFilter()); | 313 scoped_refptr<MessageCountFilter> global_filter(new MessageCountFilter()); |
304 global_filter->set_message_filtering_enabled(false); | 314 global_filter->set_message_filtering_enabled(false); |
305 channel_proxy()->AddFilter(global_filter.get()); | 315 channel_proxy()->AddFilter(global_filter.get()); |
306 | 316 |
307 // A message of class Test should be seen by both the global filter and | 317 // A message of class Test should be seen by both the global filter and |
308 // Test-specific filter. | 318 // Test-specific filter. |
309 sender()->Send(new TestMsg_Bounce); | 319 sender()->Send(new TestMsg_Bounce); |
310 | 320 |
311 // A message of a different class should be seen only by the global filter. | 321 // A message of a different class should be seen only by the global filter. |
312 sender()->Send(new UtilityMsg_Bounce); | 322 sender()->Send(new UtilityMsg_Bounce); |
313 | 323 |
314 // Flush all messages. | 324 // Flush all messages. |
315 SendQuitMessageAndWaitForIdle(); | 325 SendQuitMessageAndWaitForIdle(); |
316 | 326 |
317 // The class filter should have received only the class-specific message. | 327 // The class filter should have received only the class-specific message. |
318 EXPECT_EQ(1U, class_filter->messages_received()); | 328 EXPECT_EQ(1U, class_filter->messages_received()); |
319 | 329 |
320 // The global filter should have received both messages, as well as the final | 330 // The global filter should have received both messages, as well as the final |
321 // QUIT message. | 331 // QUIT message. |
322 EXPECT_EQ(3U, global_filter->messages_received()); | 332 EXPECT_EQ(3U, global_filter->messages_received()); |
323 } | 333 } |
324 | 334 |
325 TEST_F(IPCChannelProxyTest, FilterRemoval) { | 335 #if defined(OS_ANDROID) |
| 336 #define MAYBE_FilterRemoval DISABLED_FilterRemoval |
| 337 #else |
| 338 #define MAYBE_FilterRemoval FilterRemoval |
| 339 #endif |
| 340 TEST_F(IPCChannelProxyTest, MAYBE_FilterRemoval) { |
326 // Add a class and global filter. | 341 // Add a class and global filter. |
327 scoped_refptr<MessageCountFilter> class_filter( | 342 scoped_refptr<MessageCountFilter> class_filter( |
328 new MessageCountFilter(TestMsgStart)); | 343 new MessageCountFilter(TestMsgStart)); |
329 scoped_refptr<MessageCountFilter> global_filter(new MessageCountFilter()); | 344 scoped_refptr<MessageCountFilter> global_filter(new MessageCountFilter()); |
330 | 345 |
331 // Add and remove both types of filters. | 346 // Add and remove both types of filters. |
332 channel_proxy()->AddFilter(class_filter.get()); | 347 channel_proxy()->AddFilter(class_filter.get()); |
333 channel_proxy()->AddFilter(global_filter.get()); | 348 channel_proxy()->AddFilter(global_filter.get()); |
334 channel_proxy()->RemoveFilter(global_filter.get()); | 349 channel_proxy()->RemoveFilter(global_filter.get()); |
335 channel_proxy()->RemoveFilter(class_filter.get()); | 350 channel_proxy()->RemoveFilter(class_filter.get()); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( | 440 scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient( |
426 IPCTestBase::GetChannelName("ChannelProxyClient"), &listener, nullptr)); | 441 IPCTestBase::GetChannelName("ChannelProxyClient"), &listener, nullptr)); |
427 CHECK(channel->Connect()); | 442 CHECK(channel->Connect()); |
428 listener.Init(channel.get()); | 443 listener.Init(channel.get()); |
429 | 444 |
430 base::MessageLoop::current()->Run(); | 445 base::MessageLoop::current()->Run(); |
431 return 0; | 446 return 0; |
432 } | 447 } |
433 | 448 |
434 } // namespace | 449 } // namespace |
OLD | NEW |