| Index: ui/base/events/event_dispatcher_unittest.cc
|
| diff --git a/ui/base/events/event_dispatcher_unittest.cc b/ui/base/events/event_dispatcher_unittest.cc
|
| index c5e5ba2eb17c52866d8b46cfaf685e6ca370acfe..8bb059e45766da40f7a1accbce03a7884ee43f04 100644
|
| --- a/ui/base/events/event_dispatcher_unittest.cc
|
| +++ b/ui/base/events/event_dispatcher_unittest.cc
|
| @@ -10,26 +10,6 @@ namespace ui {
|
|
|
| namespace {
|
|
|
| -class TestEventDispatcher : public EventDispatcher {
|
| - public:
|
| - TestEventDispatcher() {}
|
| - virtual ~TestEventDispatcher() {}
|
| -
|
| - private:
|
| - // Overridden from EventDispatcher:
|
| - virtual bool CanDispatchToTarget(EventTarget* target) OVERRIDE {
|
| - return true;
|
| - }
|
| -
|
| - virtual void ProcessPreTargetList(EventHandlerList* list) OVERRIDE {
|
| - }
|
| -
|
| - virtual void ProcessPostTargetList(EventHandlerList* list) OVERRIDE {
|
| - }
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(TestEventDispatcher);
|
| -};
|
| -
|
| class TestTarget : public EventTarget {
|
| public:
|
| TestTarget() : parent_(NULL) {}
|
| @@ -67,50 +47,80 @@ class TestEventHandler : public EventHandler {
|
| public:
|
| TestEventHandler(int id)
|
| : id_(id),
|
| - event_result_(ER_UNHANDLED) {
|
| + event_result_(ER_UNHANDLED),
|
| + expected_phase_(EP_NONE) {
|
| }
|
|
|
| virtual ~TestEventHandler() {}
|
|
|
| - void ReceivedEventForTarget(EventTarget* target) {
|
| - static_cast<TestTarget*>(target)->AddHandlerId(id_);
|
| + void ReceivedEvent(Event* event) {
|
| + EXPECT_EQ(expected_phase_, event->phase());
|
| + static_cast<TestTarget*>(event->target())->AddHandlerId(id_);
|
| }
|
|
|
| void set_event_result(EventResult result) { event_result_ = result; }
|
| + void set_expected_phase(EventPhase phase) { expected_phase_ = phase; }
|
|
|
| private:
|
| // Overridden from EventHandler:
|
| virtual EventResult OnKeyEvent(KeyEvent* event) OVERRIDE {
|
| - ReceivedEventForTarget(event->target());
|
| + ReceivedEvent(event);
|
| return event_result_;
|
| }
|
|
|
| virtual EventResult OnMouseEvent(MouseEvent* event) OVERRIDE {
|
| - ReceivedEventForTarget(event->target());
|
| + ReceivedEvent(event);
|
| return event_result_;
|
| }
|
|
|
| virtual EventResult OnScrollEvent(ScrollEvent* event) OVERRIDE {
|
| - ReceivedEventForTarget(event->target());
|
| + ReceivedEvent(event);
|
| return event_result_;
|
| }
|
|
|
| virtual TouchStatus OnTouchEvent(TouchEvent* event) OVERRIDE {
|
| - ReceivedEventForTarget(event->target());
|
| + ReceivedEvent(event);
|
| return ui::TOUCH_STATUS_UNKNOWN;
|
| }
|
|
|
| virtual EventResult OnGestureEvent(GestureEvent* event) OVERRIDE {
|
| - ReceivedEventForTarget(event->target());
|
| + ReceivedEvent(event);
|
| return event_result_;
|
| }
|
|
|
| int id_;
|
| EventResult event_result_;
|
| + EventPhase expected_phase_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(TestEventHandler);
|
| };
|
|
|
| +class TestEventDispatcher : public EventDispatcher {
|
| + public:
|
| + TestEventDispatcher() {}
|
| + virtual ~TestEventDispatcher() {}
|
| +
|
| + private:
|
| + // Overridden from EventDispatcher:
|
| + virtual bool CanDispatchToTarget(EventTarget* target) OVERRIDE {
|
| + return true;
|
| + }
|
| +
|
| + virtual void ProcessPreTargetList(EventHandlerList* list) OVERRIDE {
|
| + for (EventHandlerList::iterator i = list->begin(); i != list->end(); ++i) {
|
| + static_cast<TestEventHandler*>(*i)->set_expected_phase(EP_PRETARGET);
|
| + }
|
| + }
|
| +
|
| + virtual void ProcessPostTargetList(EventHandlerList* list) OVERRIDE {
|
| + for (EventHandlerList::iterator i = list->begin(); i != list->end(); ++i) {
|
| + static_cast<TestEventHandler*>(*i)->set_expected_phase(EP_POSTTARGET);
|
| + }
|
| + }
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestEventDispatcher);
|
| +};
|
| +
|
| } // namespace
|
|
|
| TEST(EventDispatcherTest, EventDispatchOrder) {
|
| @@ -135,24 +145,23 @@ TEST(EventDispatcherTest, EventDispatchOrder) {
|
|
|
| MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(3, 4),
|
| gfx::Point(3, 4), 0);
|
| + Event::DispatcherApi event_mod(&mouse);
|
| int result = dispatcher.ProcessEvent(&child, &mouse);
|
| EXPECT_FALSE(result & ER_CONSUMED);
|
| EXPECT_FALSE(result & ER_HANDLED);
|
|
|
| - // Note that the pre-handlers for the target itself (i.e. |child|) will not
|
| - // receive these events. This is for compatibility reasons for how
|
| - // event-filters behave in aura. The desired behaviour is that the
|
| - // pre-handlers for the target will receive the events before the target.
|
| - // http://crbug.com/147523
|
| - int expected[] = { 1, 2, 5, 6, 7, 8 };
|
| + int expected[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
| EXPECT_EQ(
|
| std::vector<int>(expected, expected + sizeof(expected) / sizeof(int)),
|
| child.handler_list());
|
|
|
| child.Reset();
|
| + event_mod.set_phase(EP_NONE);
|
| + event_mod.set_result(ER_UNHANDLED);
|
|
|
| h1.set_event_result(ER_HANDLED);
|
| result = dispatcher.ProcessEvent(&child, &mouse);
|
| + EXPECT_EQ(result, mouse.result());
|
| EXPECT_FALSE(result & ER_CONSUMED);
|
| EXPECT_TRUE(result & ER_HANDLED);
|
| EXPECT_EQ(
|
| @@ -160,10 +169,13 @@ TEST(EventDispatcherTest, EventDispatchOrder) {
|
| child.handler_list());
|
|
|
| child.Reset();
|
| + event_mod.set_phase(EP_NONE);
|
| + event_mod.set_result(ER_UNHANDLED);
|
|
|
| - int nexpected[] = { 1, 2, 5 };
|
| + int nexpected[] = { 1, 2, 3, 4, 5 };
|
| h5.set_event_result(ER_CONSUMED);
|
| result = dispatcher.ProcessEvent(&child, &mouse);
|
| + EXPECT_EQ(result, mouse.result());
|
| EXPECT_TRUE(result & ER_CONSUMED);
|
| EXPECT_TRUE(result & ER_HANDLED);
|
| EXPECT_EQ(
|
| @@ -171,10 +183,13 @@ TEST(EventDispatcherTest, EventDispatchOrder) {
|
| child.handler_list());
|
|
|
| child.Reset();
|
| + event_mod.set_phase(EP_NONE);
|
| + event_mod.set_result(ER_UNHANDLED);
|
|
|
| int exp[] = { 1 };
|
| h1.set_event_result(ER_CONSUMED);
|
| result = dispatcher.ProcessEvent(&child, &mouse);
|
| + EXPECT_EQ(result, mouse.result());
|
| EXPECT_TRUE(result & ER_CONSUMED);
|
| EXPECT_FALSE(result & ER_HANDLED);
|
| EXPECT_EQ(
|
|
|