Index: ui/ozone/platform/wayland/wayland_pointer_unittest.cc |
diff --git a/ui/ozone/platform/wayland/wayland_pointer_unittest.cc b/ui/ozone/platform/wayland/wayland_pointer_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3e1bd040d2aef95a2e00604a19bf6f312064b781 |
--- /dev/null |
+++ b/ui/ozone/platform/wayland/wayland_pointer_unittest.cc |
@@ -0,0 +1,242 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <linux/input.h> |
+#include <wayland-server.h> |
+ |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/events/event.h" |
+#include "ui/ozone/platform/wayland/fake_server.h" |
+#include "ui/ozone/platform/wayland/mock_platform_window_delegate.h" |
+#include "ui/ozone/platform/wayland/wayland_display.h" |
+#include "ui/ozone/platform/wayland/wayland_window.h" |
+ |
+using ::testing::_; |
+ |
+namespace ui { |
+ |
+class WaylandPointerTest : public testing::Test { |
+ public: |
+ WaylandPointerTest() |
+ : window(&delegate, &display, gfx::Rect(0, 0, 800, 600)) {} |
+ |
+ void SetUp() override { |
+ ASSERT_TRUE(server.Start()); |
+ ASSERT_TRUE(display.Initialize()); |
+ ASSERT_TRUE(window.Initialize()); |
+ wl_display_roundtrip(display.display()); |
+ |
+ server.Pause(); |
+ |
+ surface = server.GetObject<wl::MockSurface>(window.GetWidget()); |
+ ASSERT_TRUE(surface); |
+ wl_seat_send_capabilities(server.seat()->resource(), |
+ WL_SEAT_CAPABILITY_POINTER); |
+ server.Flush(); |
+ |
+ Sync(); |
+ |
+ ASSERT_TRUE(surface->resource()); |
+ pointer = server.seat()->pointer.get(); |
+ ASSERT_TRUE(pointer); |
+ initialized = true; |
+ } |
+ |
+ void TearDown() override { |
+ server.Resume(); |
+ if (initialized) |
+ wl_display_roundtrip(display.display()); |
+ } |
+ |
+ void Sync() { |
+ server.Resume(); |
+ wl_display_roundtrip(display.display()); |
+ server.Pause(); |
+ } |
+ |
+ private: |
+ wl::FakeServer server; |
+ bool initialized = false; |
+ |
+ protected: |
+ WaylandDisplay display; |
+ MockPlatformWindowDelegate delegate; |
+ WaylandWindow window; |
+ |
+ wl::MockPointer* pointer; |
+ wl::MockSurface* surface; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(WaylandPointerTest); |
+}; |
+ |
+TEST_F(WaylandPointerTest, Leave) { |
+ wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0); |
+ wl_pointer_send_leave(pointer->resource(), 2, surface->resource()); |
+ wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, |
spang
2016/02/24 16:42:21
How can you get a button when the pointer isn't ov
Michael Forney
2016/02/24 19:32:21
If there are multiple platform windows created, so
spang
2016/02/25 23:14:32
Ok, let's do the 2 window test then so it's clear
Michael Forney
2016/02/26 01:25:52
Done.
This also helped me find a bug where we mig
|
+ WL_POINTER_BUTTON_STATE_PRESSED); |
+ EXPECT_CALL(delegate, DispatchEvent(_)).Times(0); |
+} |
+ |
+ACTION_P(CloneEvent, ptr) { |
+ *ptr = Event::Clone(*arg0); |
+} |
+ |
+TEST_F(WaylandPointerTest, Motion) { |
+ wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0); |
+ wl_pointer_send_motion(pointer->resource(), 1002, wl_fixed_from_double(10.75), |
+ wl_fixed_from_double(20.375)); |
+ |
+ scoped_ptr<Event> event; |
+ EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
+ |
+ Sync(); |
+ |
+ ASSERT_TRUE(event); |
+ ASSERT_TRUE(event->IsMouseEvent()); |
+ auto mouse_event = static_cast<MouseEvent*>(event.get()); |
+ EXPECT_EQ(ET_MOUSE_MOVED, mouse_event->type()); |
+ EXPECT_EQ(0, mouse_event->button_flags()); |
+ EXPECT_EQ(0, mouse_event->changed_button_flags()); |
+ // TODO(forney): Once crbug.com/337827 is solved, compare with the fractional |
+ // coordinates sent above. |
+ EXPECT_EQ(gfx::PointF(10, 20), mouse_event->location_f()); |
+ EXPECT_EQ(gfx::PointF(10, 20), mouse_event->root_location_f()); |
+} |
+ |
+TEST_F(WaylandPointerTest, MotionDragged) { |
+ wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0); |
+ wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_MIDDLE, |
+ WL_POINTER_BUTTON_STATE_PRESSED); |
+ |
+ Sync(); |
+ |
+ scoped_ptr<Event> event; |
+ EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
+ wl_pointer_send_motion(pointer->resource(), 1003, wl_fixed_from_int(400), |
+ wl_fixed_from_int(500)); |
+ |
+ Sync(); |
+ |
+ ASSERT_TRUE(event); |
+ ASSERT_TRUE(event->IsMouseEvent()); |
+ auto mouse_event = static_cast<MouseEvent*>(event.get()); |
+ EXPECT_EQ(ET_MOUSE_DRAGGED, mouse_event->type()); |
+ EXPECT_EQ(EF_MIDDLE_MOUSE_BUTTON, mouse_event->button_flags()); |
+ EXPECT_EQ(0, mouse_event->changed_button_flags()); |
+ EXPECT_EQ(gfx::PointF(400, 500), mouse_event->location_f()); |
+ EXPECT_EQ(gfx::PointF(400, 500), mouse_event->root_location_f()); |
+} |
+ |
+TEST_F(WaylandPointerTest, ButtonPress) { |
+ wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
+ wl_fixed_from_int(200), wl_fixed_from_int(150)); |
+ wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, |
+ WL_POINTER_BUTTON_STATE_PRESSED); |
+ |
+ Sync(); |
+ |
+ scoped_ptr<Event> event; |
+ EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
+ wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, |
+ WL_POINTER_BUTTON_STATE_PRESSED); |
+ |
+ Sync(); |
+ |
+ ASSERT_TRUE(event); |
+ ASSERT_TRUE(event->IsMouseEvent()); |
+ auto mouse_event = static_cast<MouseEvent*>(event.get()); |
+ EXPECT_EQ(ET_MOUSE_PRESSED, mouse_event->type()); |
+ EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON, |
+ mouse_event->button_flags()); |
+ EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags()); |
+ EXPECT_EQ(gfx::PointF(200, 150), mouse_event->location_f()); |
+ EXPECT_EQ(gfx::PointF(200, 150), mouse_event->root_location_f()); |
+} |
+ |
+TEST_F(WaylandPointerTest, ButtonRelease) { |
+ wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
+ wl_fixed_from_int(50), wl_fixed_from_int(50)); |
+ wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_BACK, |
+ WL_POINTER_BUTTON_STATE_PRESSED); |
+ wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, |
+ WL_POINTER_BUTTON_STATE_PRESSED); |
+ |
+ Sync(); |
+ |
+ scoped_ptr<Event> event; |
+ EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
+ wl_pointer_send_button(pointer->resource(), 4, 1004, BTN_LEFT, |
+ WL_POINTER_BUTTON_STATE_RELEASED); |
+ |
+ Sync(); |
+ |
+ ASSERT_TRUE(event); |
+ ASSERT_TRUE(event->IsMouseEvent()); |
+ auto mouse_event = static_cast<MouseEvent*>(event.get()); |
+ EXPECT_EQ(ET_MOUSE_RELEASED, mouse_event->type()); |
+ EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON, |
+ mouse_event->button_flags()); |
+ EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags()); |
+ EXPECT_EQ(gfx::PointF(50, 50), mouse_event->location_f()); |
+ EXPECT_EQ(gfx::PointF(50, 50), mouse_event->root_location_f()); |
+} |
+ |
+TEST_F(WaylandPointerTest, AxisVertical) { |
+ wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
+ wl_fixed_from_int(0), wl_fixed_from_int(0)); |
+ wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, |
+ WL_POINTER_BUTTON_STATE_PRESSED); |
+ |
+ Sync(); |
+ |
+ scoped_ptr<Event> event; |
+ EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
+ // Wayland servers typically send a value of 10 per mouse wheel click. |
+ wl_pointer_send_axis(pointer->resource(), 1003, |
+ WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(20)); |
+ |
+ Sync(); |
+ |
+ ASSERT_TRUE(event); |
+ ASSERT_TRUE(event->IsMouseWheelEvent()); |
+ auto mouse_wheel_event = static_cast<MouseWheelEvent*>(event.get()); |
+ EXPECT_EQ(gfx::Vector2d(0, -2 * MouseWheelEvent::kWheelDelta), |
+ mouse_wheel_event->offset()); |
+ EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); |
+ EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); |
+ EXPECT_EQ(gfx::PointF(), mouse_wheel_event->location_f()); |
+ EXPECT_EQ(gfx::PointF(), mouse_wheel_event->root_location_f()); |
+} |
+ |
+TEST_F(WaylandPointerTest, AxisHorizontal) { |
+ wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
+ wl_fixed_from_int(50), wl_fixed_from_int(75)); |
+ wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_LEFT, |
+ WL_POINTER_BUTTON_STATE_PRESSED); |
+ |
+ Sync(); |
+ |
+ scoped_ptr<Event> event; |
+ EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
+ // Wayland servers typically send a value of 10 per mouse wheel click. |
+ wl_pointer_send_axis(pointer->resource(), 1003, |
+ WL_POINTER_AXIS_HORIZONTAL_SCROLL, |
+ wl_fixed_from_int(10)); |
+ |
+ Sync(); |
+ |
+ ASSERT_TRUE(event); |
+ ASSERT_TRUE(event->IsMouseWheelEvent()); |
+ auto mouse_wheel_event = static_cast<MouseWheelEvent*>(event.get()); |
+ EXPECT_EQ(gfx::Vector2d(MouseWheelEvent::kWheelDelta, 0), |
+ mouse_wheel_event->offset()); |
+ EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); |
+ EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); |
+ EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->location_f()); |
+ EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->root_location_f()); |
+} |
+ |
+} // namespace ui |