| Index: ui/events/platform/platform_event_source_unittest.cc
|
| diff --git a/ui/events/platform/platform_event_source_unittest.cc b/ui/events/platform/platform_event_source_unittest.cc
|
| index cdbd0c4b35cb07be1c96df7cb3420fac574c966f..2f91b9ed0efc4f5684d3461e822cf6fd3c921685 100644
|
| --- a/ui/events/platform/platform_event_source_unittest.cc
|
| +++ b/ui/events/platform/platform_event_source_unittest.cc
|
| @@ -11,6 +11,7 @@
|
| #include "base/run_loop.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "ui/events/platform/platform_event_dispatcher.h"
|
| +#include "ui/events/platform/platform_event_filter.h"
|
| #include "ui/events/platform/platform_event_observer.h"
|
| #include "ui/events/platform/scoped_event_dispatcher.h"
|
|
|
| @@ -136,6 +137,24 @@ class TestPlatformEventObserver : public PlatformEventObserver {
|
| DISALLOW_COPY_AND_ASSIGN(TestPlatformEventObserver);
|
| };
|
|
|
| +class TestPlatformEventFilter : public PlatformEventFilter {
|
| + public:
|
| + TestPlatformEventFilter() {
|
| + PlatformEventSource::GetInstance()->AddPlatformEventFilter(this);
|
| + }
|
| +
|
| + virtual ~TestPlatformEventFilter() {
|
| + PlatformEventSource::GetInstance()->RemovePlatformEventFilter(this);
|
| + }
|
| +
|
| + virtual bool ShouldDispatchEvent(const PlatformEvent& event) OVERRIDE {
|
| + return false;
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(TestPlatformEventFilter);
|
| +};
|
| +
|
| class PlatformEventTest : public testing::Test {
|
| public:
|
| PlatformEventTest() {}
|
| @@ -234,6 +253,29 @@ TEST_F(PlatformEventTest, ObserverBasic) {
|
| EXPECT_EQ(0u, list_observer.size());
|
| }
|
|
|
| +// Tests that filtered events are not observed or dispatched.
|
| +TEST_F(PlatformEventTest, FilterBasic) {
|
| + std::vector<int> list;
|
| + scoped_ptr<PlatformEvent> event(CreatePlatformEvent());
|
| + TestPlatformEventDispatcher dispatcher(1, &list);
|
| + TestPlatformEventObserver observer(2, &list);
|
| + source()->Dispatch(*event);
|
| + EXPECT_EQ(2u, list.size());
|
| + list.clear();
|
| + {
|
| + TestPlatformEventFilter filter;
|
| + scoped_ptr<PlatformEvent> event(CreatePlatformEvent());
|
| + source()->Dispatch(*event);
|
| + ASSERT_EQ(0u, list.size());
|
| + list.clear();
|
| + }
|
| +
|
| + list.clear();
|
| + event = CreatePlatformEvent();
|
| + source()->Dispatch(*event);
|
| + EXPECT_EQ(2u, list.size());
|
| +}
|
| +
|
| // Tests that observers receive events in the correct order.
|
| TEST_F(PlatformEventTest, ObserverOrder) {
|
| std::vector<int> list_observer;
|
|
|