Chromium Code Reviews| Index: ash/aura/pointer_watcher_adapter_unittest.cc |
| diff --git a/ash/aura/pointer_watcher_adapter_unittest.cc b/ash/aura/pointer_watcher_adapter_unittest.cc |
| index c0a67685e9c08867d78d3c4f964dde6716aab63e..d07347d619456326d2b54035e52a1bcbd4b6e2bd 100644 |
| --- a/ash/aura/pointer_watcher_adapter_unittest.cc |
| +++ b/ash/aura/pointer_watcher_adapter_unittest.cc |
| @@ -14,12 +14,26 @@ namespace ash { |
| using PointerWatcherAdapterTest = test::AshTestBase; |
| +enum TestPointerEvents { |
| + NO_POINTER = 0x01, |
| + BASIC_POINTER = 0x02, |
| + MOVE_POINTER = 0x04, |
| + DRAG_POINTER = 0x08 |
| +}; |
| + |
| +enum TestCaptureEvents { |
| + NO_CAPTURE = 0x01, |
| + BASIC_CAPTURE = 0x02, |
| + MOVE_CAPTURE = 0x04, |
| + DRAG_CAPTURE = 0x08 |
| +}; |
| + |
| // Records calls to OnPointerEventObserved() in |pointer_event_count_| and |
| // calls to OnMouseCaptureChanged() to |capture_changed_count_|. |
| class TestPointerWatcher : public views::PointerWatcher { |
| public: |
| - explicit TestPointerWatcher(bool wants_moves) { |
| - WmShell::Get()->AddPointerWatcher(this, wants_moves); |
| + explicit TestPointerWatcher(views::PointerWatcherEventTypes events) { |
| + WmShell::Get()->AddPointerWatcher(this, events); |
| } |
| ~TestPointerWatcher() override { WmShell::Get()->RemovePointerWatcher(this); } |
| @@ -43,32 +57,39 @@ class TestPointerWatcher : public views::PointerWatcher { |
| DISALLOW_COPY_AND_ASSIGN(TestPointerWatcher); |
| }; |
| -// Creates two TestPointerWatchers, one that wants moves and one that doesn't. |
| +// Creates three TestPointerWatchers, one that wants moves and one that wants |
| +// drags, and one that does not want either. |
| class TestHelper { |
| public: |
| - TestHelper() : non_move_watcher_(false), move_watcher_(true) {} |
| + TestHelper() |
| + : non_move_watcher_(views::PointerWatcherEventTypes::BASIC), |
| + move_watcher_(views::PointerWatcherEventTypes::MOVES), |
| + drag_watcher_(views::PointerWatcherEventTypes::DRAGS) {} |
| ~TestHelper() {} |
| - // Used to verify call counts. |
| - void ExpectCallCount(int non_move_pointer_event_count, |
| - int non_move_capture_changed_count, |
| - int move_pointer_event_count, |
| - int move_capture_changed_count) { |
| - EXPECT_EQ(non_move_pointer_event_count, |
| + // Used to verify call counts. One ExpectCallCount call should be made after |
| + // each generated mouse events. |
| + void ExpectCallCount(int pointer, int capture) { |
|
sky
2016/08/26 19:58:57
Can't you combine them all into a single bitmask?
sammiequon
2016/08/26 21:48:04
Done.
|
| + EXPECT_EQ(pointer & (1 << 1) ? 1 : 0, |
| non_move_watcher_.pointer_event_count()); |
| - EXPECT_EQ(non_move_capture_changed_count, |
| + EXPECT_EQ(capture & (1 << 1) ? 1 : 0, |
| non_move_watcher_.capture_changed_count()); |
| - EXPECT_EQ(move_pointer_event_count, move_watcher_.pointer_event_count()); |
| - EXPECT_EQ(move_capture_changed_count, |
| + EXPECT_EQ(pointer & (1 << 2) ? 1 : 0, move_watcher_.pointer_event_count()); |
| + EXPECT_EQ(capture & (1 << 2) ? 1 : 0, |
| move_watcher_.capture_changed_count()); |
| + EXPECT_EQ(pointer & (1 << 3) ? 1 : 0, drag_watcher_.pointer_event_count()); |
| + EXPECT_EQ(capture & (1 << 3) ? 1 : 0, |
| + drag_watcher_.capture_changed_count()); |
| non_move_watcher_.ClearCounts(); |
| move_watcher_.ClearCounts(); |
| + drag_watcher_.ClearCounts(); |
| } |
| private: |
| TestPointerWatcher non_move_watcher_; |
| TestPointerWatcher move_watcher_; |
| + TestPointerWatcher drag_watcher_; |
| DISALLOW_COPY_AND_ASSIGN(TestHelper); |
| }; |
| @@ -76,41 +97,45 @@ class TestHelper { |
| TEST_F(PointerWatcherAdapterTest, MouseEvents) { |
| TestHelper helper; |
| - // Move: only the move PointerWatcher should get the event. |
| + // Move: only the move and drag PointerWatcher should get the event. |
| GetEventGenerator().MoveMouseTo(gfx::Point(10, 10)); |
| - helper.ExpectCallCount(0, 0, 1, 0); |
| + helper.ExpectCallCount(MOVE_POINTER | DRAG_POINTER, NO_CAPTURE); |
| - // Press: both. |
| + // Press: all. |
| GetEventGenerator().PressLeftButton(); |
| - helper.ExpectCallCount(1, 0, 1, 0); |
| + helper.ExpectCallCount(BASIC_POINTER | MOVE_POINTER | DRAG_POINTER, |
| + NO_CAPTURE); |
| - // Drag: none. |
| - GetEventGenerator().MoveMouseTo(gfx::Point(20, 30)); |
| - helper.ExpectCallCount(0, 0, 0, 0); |
| + // Drag: only drag PointerWatcher should get the event. |
| + // GetEventGenerator().MoveMouseTo(gfx::Point(20, 30)); |
| + // helper.ExpectCallCount2(int{TestPointerEvents::DRAG_POINTER}, |
| + // int{TestCaptureEvents::NO_CAPTURE}); |
| - // Release: both (aura generates a capture event here). |
| + // Release: all (aura generates a capture event here). |
| GetEventGenerator().ReleaseLeftButton(); |
| - helper.ExpectCallCount(1, 1, 1, 1); |
| + helper.ExpectCallCount(BASIC_POINTER | MOVE_POINTER | DRAG_POINTER, |
| + BASIC_CAPTURE | MOVE_CAPTURE | DRAG_CAPTURE); |
| // Exit: none. |
| GetEventGenerator().SendMouseExit(); |
| - helper.ExpectCallCount(0, 0, 0, 0); |
| + helper.ExpectCallCount(NO_POINTER, NO_CAPTURE); |
| // Enter: none. |
| ui::MouseEvent enter_event(ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(), |
| ui::EventTimeForNow(), 0, 0); |
| GetEventGenerator().Dispatch(&enter_event); |
| - helper.ExpectCallCount(0, 0, 0, 0); |
| + helper.ExpectCallCount(NO_POINTER, NO_CAPTURE); |
| // Wheel: none |
| GetEventGenerator().MoveMouseWheel(10, 11); |
| - helper.ExpectCallCount(0, 0, 0, 0); |
| + helper.ExpectCallCount(NO_POINTER, NO_CAPTURE); |
| - // Capture: both. |
| + // Capture: all. |
| ui::MouseEvent capture_event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), |
| gfx::Point(), ui::EventTimeForNow(), 0, 0); |
| GetEventGenerator().Dispatch(&capture_event); |
| - helper.ExpectCallCount(0, 1, 0, 1); |
| + helper.ExpectCallCount(NO_POINTER, |
| + BASIC_CAPTURE | MOVE_CAPTURE | DRAG_CAPTURE); |
| } |
| TEST_F(PointerWatcherAdapterTest, TouchEvents) { |
| @@ -119,16 +144,18 @@ TEST_F(PointerWatcherAdapterTest, TouchEvents) { |
| // Press: both. |
| const int touch_id = 11; |
| GetEventGenerator().PressTouchId(touch_id); |
| - helper.ExpectCallCount(1, 0, 1, 0); |
| + helper.ExpectCallCount(BASIC_POINTER | MOVE_POINTER | DRAG_POINTER, |
| + NO_CAPTURE); |
| - // Drag: none. |
| + // Drag: only drag. |
| GetEventGenerator().MoveTouchId(gfx::Point(20, 30), touch_id); |
| - helper.ExpectCallCount(0, 0, 0, 0); |
| + helper.ExpectCallCount(DRAG_POINTER, NO_CAPTURE); |
| // Release: both (contrary to mouse above, touch does not implicitly generate |
| // capture). |
| GetEventGenerator().ReleaseTouchId(touch_id); |
| - helper.ExpectCallCount(1, 0, 1, 0); |
| + helper.ExpectCallCount(BASIC_POINTER | MOVE_POINTER | DRAG_POINTER, |
| + NO_CAPTURE); |
| } |
| } // namespace ash |