OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <linux/input.h> |
| 6 #include <wayland-server.h> |
| 7 |
| 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/events/event.h" |
| 11 #include "ui/ozone/platform/wayland/fake_server.h" |
| 12 #include "ui/ozone/platform/wayland/mock_platform_window_delegate.h" |
| 13 #include "ui/ozone/platform/wayland/wayland_test.h" |
| 14 #include "ui/ozone/platform/wayland/wayland_window.h" |
| 15 |
| 16 using ::testing::SaveArg; |
| 17 using ::testing::_; |
| 18 |
| 19 namespace ui { |
| 20 |
| 21 class WaylandPointerTest : public WaylandTest { |
| 22 public: |
| 23 WaylandPointerTest() {} |
| 24 |
| 25 void SetUp() override { |
| 26 WaylandTest::SetUp(); |
| 27 |
| 28 wl_seat_send_capabilities(server.seat()->resource(), |
| 29 WL_SEAT_CAPABILITY_POINTER); |
| 30 |
| 31 Sync(); |
| 32 |
| 33 pointer = server.seat()->pointer.get(); |
| 34 ASSERT_TRUE(pointer); |
| 35 } |
| 36 |
| 37 protected: |
| 38 wl::MockPointer* pointer; |
| 39 |
| 40 private: |
| 41 DISALLOW_COPY_AND_ASSIGN(WaylandPointerTest); |
| 42 }; |
| 43 |
| 44 TEST_F(WaylandPointerTest, Leave) { |
| 45 MockPlatformWindowDelegate other_delegate; |
| 46 WaylandWindow other_window(&other_delegate, &display, |
| 47 gfx::Rect(0, 0, 10, 10)); |
| 48 gfx::AcceleratedWidget other_widget = gfx::kNullAcceleratedWidget; |
| 49 EXPECT_CALL(other_delegate, OnAcceleratedWidgetAvailable(_, _)) |
| 50 .WillOnce(SaveArg<0>(&other_widget)); |
| 51 ASSERT_TRUE(other_window.Initialize()); |
| 52 ASSERT_NE(other_widget, gfx::kNullAcceleratedWidget); |
| 53 |
| 54 Sync(); |
| 55 |
| 56 wl::MockSurface* other_surface = |
| 57 server.GetObject<wl::MockSurface>(other_widget); |
| 58 ASSERT_TRUE(other_surface); |
| 59 |
| 60 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0); |
| 61 wl_pointer_send_leave(pointer->resource(), 2, surface->resource()); |
| 62 wl_pointer_send_enter(pointer->resource(), 3, other_surface->resource(), 0, |
| 63 0); |
| 64 wl_pointer_send_button(pointer->resource(), 4, 1004, BTN_LEFT, |
| 65 WL_POINTER_BUTTON_STATE_PRESSED); |
| 66 EXPECT_CALL(delegate, DispatchEvent(_)).Times(0); |
| 67 |
| 68 // Do an extra Sync() here so that we process the second enter event before we |
| 69 // destroy |other_window|. |
| 70 Sync(); |
| 71 } |
| 72 |
| 73 ACTION_P(CloneEvent, ptr) { |
| 74 *ptr = Event::Clone(*arg0); |
| 75 } |
| 76 |
| 77 TEST_F(WaylandPointerTest, Motion) { |
| 78 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0); |
| 79 wl_pointer_send_motion(pointer->resource(), 1002, wl_fixed_from_double(10.75), |
| 80 wl_fixed_from_double(20.375)); |
| 81 |
| 82 scoped_ptr<Event> event; |
| 83 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 84 |
| 85 Sync(); |
| 86 |
| 87 ASSERT_TRUE(event); |
| 88 ASSERT_TRUE(event->IsMouseEvent()); |
| 89 auto mouse_event = static_cast<MouseEvent*>(event.get()); |
| 90 EXPECT_EQ(ET_MOUSE_MOVED, mouse_event->type()); |
| 91 EXPECT_EQ(0, mouse_event->button_flags()); |
| 92 EXPECT_EQ(0, mouse_event->changed_button_flags()); |
| 93 // TODO(forney): Once crbug.com/337827 is solved, compare with the fractional |
| 94 // coordinates sent above. |
| 95 EXPECT_EQ(gfx::PointF(10, 20), mouse_event->location_f()); |
| 96 EXPECT_EQ(gfx::PointF(10, 20), mouse_event->root_location_f()); |
| 97 } |
| 98 |
| 99 TEST_F(WaylandPointerTest, MotionDragged) { |
| 100 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0); |
| 101 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_MIDDLE, |
| 102 WL_POINTER_BUTTON_STATE_PRESSED); |
| 103 |
| 104 Sync(); |
| 105 |
| 106 scoped_ptr<Event> event; |
| 107 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 108 wl_pointer_send_motion(pointer->resource(), 1003, wl_fixed_from_int(400), |
| 109 wl_fixed_from_int(500)); |
| 110 |
| 111 Sync(); |
| 112 |
| 113 ASSERT_TRUE(event); |
| 114 ASSERT_TRUE(event->IsMouseEvent()); |
| 115 auto mouse_event = static_cast<MouseEvent*>(event.get()); |
| 116 EXPECT_EQ(ET_MOUSE_DRAGGED, mouse_event->type()); |
| 117 EXPECT_EQ(EF_MIDDLE_MOUSE_BUTTON, mouse_event->button_flags()); |
| 118 EXPECT_EQ(0, mouse_event->changed_button_flags()); |
| 119 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->location_f()); |
| 120 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->root_location_f()); |
| 121 } |
| 122 |
| 123 TEST_F(WaylandPointerTest, ButtonPress) { |
| 124 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 125 wl_fixed_from_int(200), wl_fixed_from_int(150)); |
| 126 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, |
| 127 WL_POINTER_BUTTON_STATE_PRESSED); |
| 128 |
| 129 Sync(); |
| 130 |
| 131 scoped_ptr<Event> event; |
| 132 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 133 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, |
| 134 WL_POINTER_BUTTON_STATE_PRESSED); |
| 135 |
| 136 Sync(); |
| 137 |
| 138 ASSERT_TRUE(event); |
| 139 ASSERT_TRUE(event->IsMouseEvent()); |
| 140 auto mouse_event = static_cast<MouseEvent*>(event.get()); |
| 141 EXPECT_EQ(ET_MOUSE_PRESSED, mouse_event->type()); |
| 142 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON, |
| 143 mouse_event->button_flags()); |
| 144 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags()); |
| 145 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->location_f()); |
| 146 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->root_location_f()); |
| 147 } |
| 148 |
| 149 TEST_F(WaylandPointerTest, ButtonRelease) { |
| 150 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 151 wl_fixed_from_int(50), wl_fixed_from_int(50)); |
| 152 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_BACK, |
| 153 WL_POINTER_BUTTON_STATE_PRESSED); |
| 154 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, |
| 155 WL_POINTER_BUTTON_STATE_PRESSED); |
| 156 |
| 157 Sync(); |
| 158 |
| 159 scoped_ptr<Event> event; |
| 160 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 161 wl_pointer_send_button(pointer->resource(), 4, 1004, BTN_LEFT, |
| 162 WL_POINTER_BUTTON_STATE_RELEASED); |
| 163 |
| 164 Sync(); |
| 165 |
| 166 ASSERT_TRUE(event); |
| 167 ASSERT_TRUE(event->IsMouseEvent()); |
| 168 auto mouse_event = static_cast<MouseEvent*>(event.get()); |
| 169 EXPECT_EQ(ET_MOUSE_RELEASED, mouse_event->type()); |
| 170 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON, |
| 171 mouse_event->button_flags()); |
| 172 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags()); |
| 173 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->location_f()); |
| 174 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->root_location_f()); |
| 175 } |
| 176 |
| 177 TEST_F(WaylandPointerTest, AxisVertical) { |
| 178 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 179 wl_fixed_from_int(0), wl_fixed_from_int(0)); |
| 180 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, |
| 181 WL_POINTER_BUTTON_STATE_PRESSED); |
| 182 |
| 183 Sync(); |
| 184 |
| 185 scoped_ptr<Event> event; |
| 186 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 187 // Wayland servers typically send a value of 10 per mouse wheel click. |
| 188 wl_pointer_send_axis(pointer->resource(), 1003, |
| 189 WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(20)); |
| 190 |
| 191 Sync(); |
| 192 |
| 193 ASSERT_TRUE(event); |
| 194 ASSERT_TRUE(event->IsMouseWheelEvent()); |
| 195 auto mouse_wheel_event = static_cast<MouseWheelEvent*>(event.get()); |
| 196 EXPECT_EQ(gfx::Vector2d(0, -2 * MouseWheelEvent::kWheelDelta), |
| 197 mouse_wheel_event->offset()); |
| 198 EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); |
| 199 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); |
| 200 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->location_f()); |
| 201 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->root_location_f()); |
| 202 } |
| 203 |
| 204 TEST_F(WaylandPointerTest, AxisHorizontal) { |
| 205 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 206 wl_fixed_from_int(50), wl_fixed_from_int(75)); |
| 207 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_LEFT, |
| 208 WL_POINTER_BUTTON_STATE_PRESSED); |
| 209 |
| 210 Sync(); |
| 211 |
| 212 scoped_ptr<Event> event; |
| 213 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 214 // Wayland servers typically send a value of 10 per mouse wheel click. |
| 215 wl_pointer_send_axis(pointer->resource(), 1003, |
| 216 WL_POINTER_AXIS_HORIZONTAL_SCROLL, |
| 217 wl_fixed_from_int(10)); |
| 218 |
| 219 Sync(); |
| 220 |
| 221 ASSERT_TRUE(event); |
| 222 ASSERT_TRUE(event->IsMouseWheelEvent()); |
| 223 auto mouse_wheel_event = static_cast<MouseWheelEvent*>(event.get()); |
| 224 EXPECT_EQ(gfx::Vector2d(MouseWheelEvent::kWheelDelta, 0), |
| 225 mouse_wheel_event->offset()); |
| 226 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); |
| 227 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); |
| 228 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->location_f()); |
| 229 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->root_location_f()); |
| 230 } |
| 231 |
| 232 } // namespace ui |
OLD | NEW |