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