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 8f95473edfeec783507e27ffe978ca8f1458f7c6..675cb2b3486d0223931a5ce55d47d5d14e502b2d 100644 |
--- a/ash/aura/pointer_watcher_adapter_unittest.cc |
+++ b/ash/aura/pointer_watcher_adapter_unittest.cc |
@@ -14,13 +14,20 @@ namespace ash { |
using PointerWatcherAdapterTest = test::AshTestBase; |
+enum TestPointerCaptureEvents { |
+ NONE = 0x01, |
+ BASIC = 0x02, |
+ MOVE = 0x04, |
+ DRAG = 0x08 |
+}; |
+ |
// Records calls to OnPointerEventObserved() in |mouse_wheel_event_count| for a |
// mouse wheel event, in |capture_changed_count_| for a mouse capture change |
// event and in |pointer_event_count_| for all other pointer events. |
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); } |
@@ -53,38 +60,58 @@ 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), |
sky
2016/08/31 23:27:39
These names are now confusing. It should be basic_
sammiequon
2016/09/01 00:49:24
Done.
|
+ 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 non_move_mouse_wheel_event_count, |
- int move_pointer_event_count, |
- int move_capture_changed_count, |
- int move_mouse_wheel_event_count) { |
- EXPECT_EQ(non_move_pointer_event_count, |
+ // Used to verify call counts. One ExpectCallCount call should be made after |
+ // each generated mouse events. |pointer_bitmask| defines which events are |
+ // expected to have happened and |capture_bitmask| defines which captures are |
+ // expected to have happened and |wheel_bitmask| defines which wheel movements |
+ // are expected to have happened. |
+ void ExpectCallCount(int pointer_bitmask, |
sky
2016/08/31 23:27:39
I'm confused by what you have here. I would expect
sammiequon
2016/09/01 00:49:24
Done.
|
+ int capture_bitmask, |
+ int wheel_bitmask) { |
+ // Check if the first bit is set. If set that means a basic event for the |
+ // non move watcher is expected to have happened. |
+ EXPECT_EQ(pointer_bitmask & BASIC ? 1 : 0, |
non_move_watcher_.pointer_event_count()); |
- EXPECT_EQ(non_move_capture_changed_count, |
+ EXPECT_EQ(capture_bitmask & BASIC ? 1 : 0, |
non_move_watcher_.capture_changed_count()); |
- EXPECT_EQ(non_move_mouse_wheel_event_count, |
+ EXPECT_EQ(wheel_bitmask & BASIC ? 1 : 0, |
non_move_watcher_.mouse_wheel_event_count()); |
- EXPECT_EQ(move_pointer_event_count, move_watcher_.pointer_event_count()); |
- EXPECT_EQ(move_capture_changed_count, |
+ // Check if the second bit is set. If set that means a move event for the |
+ // move watcher is expected to have happened. |
+ EXPECT_EQ(pointer_bitmask & MOVE ? 1 : 0, |
+ move_watcher_.pointer_event_count()); |
+ EXPECT_EQ(capture_bitmask & MOVE ? 1 : 0, |
move_watcher_.capture_changed_count()); |
- EXPECT_EQ(move_mouse_wheel_event_count, |
+ EXPECT_EQ(wheel_bitmask & MOVE ? 1 : 0, |
move_watcher_.mouse_wheel_event_count()); |
+ // Check if the third bit is set. If set that means a drag event for the |
+ // drag watcher is expected to have happened. |
+ EXPECT_EQ(pointer_bitmask & DRAG ? 1 : 0, |
+ drag_watcher_.pointer_event_count()); |
+ EXPECT_EQ(capture_bitmask & DRAG ? 1 : 0, |
+ drag_watcher_.capture_changed_count()); |
+ EXPECT_EQ(wheel_bitmask & DRAG ? 1 : 0, |
+ drag_watcher_.mouse_wheel_event_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); |
}; |
@@ -92,41 +119,41 @@ 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, 0, 1, 0, 0); |
+ helper.ExpectCallCount(MOVE | DRAG, NONE, NONE); |
- // Press: both. |
+ // Press: all. |
GetEventGenerator().PressLeftButton(); |
- helper.ExpectCallCount(1, 0, 0, 1, 0, 0); |
+ helper.ExpectCallCount(BASIC | MOVE | DRAG, NONE, NONE); |
- // Drag: none. |
+ // Drag: only drag PointerWatcher should get the event. |
GetEventGenerator().MoveMouseTo(gfx::Point(20, 30)); |
- helper.ExpectCallCount(0, 0, 0, 0, 0, 0); |
+ helper.ExpectCallCount(DRAG, NONE, NONE); |
- // Release: both (aura generates a capture event here). |
+ // Release: all (aura generates a capture event here). |
GetEventGenerator().ReleaseLeftButton(); |
- helper.ExpectCallCount(1, 1, 0, 1, 1, 0); |
+ helper.ExpectCallCount(BASIC | MOVE | DRAG, BASIC | MOVE | DRAG, NONE); |
// Exit: none. |
GetEventGenerator().SendMouseExit(); |
- helper.ExpectCallCount(0, 0, 0, 0, 0, 0); |
+ helper.ExpectCallCount(NONE, NONE, NONE); |
// 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, 0, 0); |
+ helper.ExpectCallCount(NONE, NONE, NONE); |
// Wheel: both |
GetEventGenerator().MoveMouseWheel(10, 11); |
- helper.ExpectCallCount(0, 0, 1, 0, 0, 1); |
+ helper.ExpectCallCount(NONE, NONE, BASIC | MOVE | DRAG); |
- // 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, 0, 1, 0); |
+ helper.ExpectCallCount(NONE, BASIC | MOVE | DRAG, NONE); |
} |
TEST_F(PointerWatcherAdapterTest, TouchEvents) { |
@@ -135,16 +162,16 @@ TEST_F(PointerWatcherAdapterTest, TouchEvents) { |
// Press: both. |
const int touch_id = 11; |
GetEventGenerator().PressTouchId(touch_id); |
- helper.ExpectCallCount(1, 0, 0, 1, 0, 0); |
+ helper.ExpectCallCount(BASIC | MOVE | DRAG, NONE, NONE); |
- // Drag: none. |
+ // Drag: only drag. |
GetEventGenerator().MoveTouchId(gfx::Point(20, 30), touch_id); |
- helper.ExpectCallCount(0, 0, 0, 0, 0, 0); |
+ helper.ExpectCallCount(DRAG, NONE, NONE); |
// Release: both (contrary to mouse above, touch does not implicitly generate |
// capture). |
GetEventGenerator().ReleaseTouchId(touch_id); |
- helper.ExpectCallCount(1, 0, 0, 1, 0, 0); |
+ helper.ExpectCallCount(BASIC | MOVE | DRAG, NONE, NONE); |
} |
} // namespace ash |