| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <linux/input.h> | 5 #include <linux/input.h> |
| 6 #include <wayland-server.h> | 6 #include <wayland-server.h> |
| 7 | 7 |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 wl_pointer_send_motion(pointer->resource(), 1002, wl_fixed_from_double(10.75), | 79 wl_pointer_send_motion(pointer->resource(), 1002, wl_fixed_from_double(10.75), |
| 80 wl_fixed_from_double(20.375)); | 80 wl_fixed_from_double(20.375)); |
| 81 | 81 |
| 82 std::unique_ptr<Event> event; | 82 std::unique_ptr<Event> event; |
| 83 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); | 83 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 84 | 84 |
| 85 Sync(); | 85 Sync(); |
| 86 | 86 |
| 87 ASSERT_TRUE(event); | 87 ASSERT_TRUE(event); |
| 88 ASSERT_TRUE(event->IsMouseEvent()); | 88 ASSERT_TRUE(event->IsMouseEvent()); |
| 89 auto mouse_event = event->AsMouseEvent(); | 89 auto* mouse_event = event->AsMouseEvent(); |
| 90 EXPECT_EQ(ET_MOUSE_MOVED, mouse_event->type()); | 90 EXPECT_EQ(ET_MOUSE_MOVED, mouse_event->type()); |
| 91 EXPECT_EQ(0, mouse_event->button_flags()); | 91 EXPECT_EQ(0, mouse_event->button_flags()); |
| 92 EXPECT_EQ(0, mouse_event->changed_button_flags()); | 92 EXPECT_EQ(0, mouse_event->changed_button_flags()); |
| 93 EXPECT_EQ(gfx::PointF(10.75, 20.375), mouse_event->location_f()); | 93 EXPECT_EQ(gfx::PointF(10.75, 20.375), mouse_event->location_f()); |
| 94 EXPECT_EQ(gfx::PointF(10.75, 20.375), mouse_event->root_location_f()); | 94 EXPECT_EQ(gfx::PointF(10.75, 20.375), mouse_event->root_location_f()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST_F(WaylandPointerTest, MotionDragged) { | 97 TEST_F(WaylandPointerTest, MotionDragged) { |
| 98 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0); | 98 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0); |
| 99 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_MIDDLE, | 99 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_MIDDLE, |
| 100 WL_POINTER_BUTTON_STATE_PRESSED); | 100 WL_POINTER_BUTTON_STATE_PRESSED); |
| 101 | 101 |
| 102 Sync(); | 102 Sync(); |
| 103 | 103 |
| 104 std::unique_ptr<Event> event; | 104 std::unique_ptr<Event> event; |
| 105 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); | 105 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 106 wl_pointer_send_motion(pointer->resource(), 1003, wl_fixed_from_int(400), | 106 wl_pointer_send_motion(pointer->resource(), 1003, wl_fixed_from_int(400), |
| 107 wl_fixed_from_int(500)); | 107 wl_fixed_from_int(500)); |
| 108 | 108 |
| 109 Sync(); | 109 Sync(); |
| 110 | 110 |
| 111 ASSERT_TRUE(event); | 111 ASSERT_TRUE(event); |
| 112 ASSERT_TRUE(event->IsMouseEvent()); | 112 ASSERT_TRUE(event->IsMouseEvent()); |
| 113 auto mouse_event = event->AsMouseEvent(); | 113 auto* mouse_event = event->AsMouseEvent(); |
| 114 EXPECT_EQ(ET_MOUSE_DRAGGED, mouse_event->type()); | 114 EXPECT_EQ(ET_MOUSE_DRAGGED, mouse_event->type()); |
| 115 EXPECT_EQ(EF_MIDDLE_MOUSE_BUTTON, mouse_event->button_flags()); | 115 EXPECT_EQ(EF_MIDDLE_MOUSE_BUTTON, mouse_event->button_flags()); |
| 116 EXPECT_EQ(0, mouse_event->changed_button_flags()); | 116 EXPECT_EQ(0, mouse_event->changed_button_flags()); |
| 117 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->location_f()); | 117 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->location_f()); |
| 118 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->root_location_f()); | 118 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->root_location_f()); |
| 119 } | 119 } |
| 120 | 120 |
| 121 TEST_F(WaylandPointerTest, ButtonPress) { | 121 TEST_F(WaylandPointerTest, ButtonPress) { |
| 122 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), | 122 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 123 wl_fixed_from_int(200), wl_fixed_from_int(150)); | 123 wl_fixed_from_int(200), wl_fixed_from_int(150)); |
| 124 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, | 124 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, |
| 125 WL_POINTER_BUTTON_STATE_PRESSED); | 125 WL_POINTER_BUTTON_STATE_PRESSED); |
| 126 | 126 |
| 127 Sync(); | 127 Sync(); |
| 128 | 128 |
| 129 std::unique_ptr<Event> event; | 129 std::unique_ptr<Event> event; |
| 130 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); | 130 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 131 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, | 131 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, |
| 132 WL_POINTER_BUTTON_STATE_PRESSED); | 132 WL_POINTER_BUTTON_STATE_PRESSED); |
| 133 | 133 |
| 134 Sync(); | 134 Sync(); |
| 135 | 135 |
| 136 ASSERT_TRUE(event); | 136 ASSERT_TRUE(event); |
| 137 ASSERT_TRUE(event->IsMouseEvent()); | 137 ASSERT_TRUE(event->IsMouseEvent()); |
| 138 auto mouse_event = event->AsMouseEvent(); | 138 auto* mouse_event = event->AsMouseEvent(); |
| 139 EXPECT_EQ(ET_MOUSE_PRESSED, mouse_event->type()); | 139 EXPECT_EQ(ET_MOUSE_PRESSED, mouse_event->type()); |
| 140 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON, | 140 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON, |
| 141 mouse_event->button_flags()); | 141 mouse_event->button_flags()); |
| 142 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags()); | 142 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags()); |
| 143 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->location_f()); | 143 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->location_f()); |
| 144 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->root_location_f()); | 144 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->root_location_f()); |
| 145 } | 145 } |
| 146 | 146 |
| 147 TEST_F(WaylandPointerTest, ButtonRelease) { | 147 TEST_F(WaylandPointerTest, ButtonRelease) { |
| 148 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), | 148 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 149 wl_fixed_from_int(50), wl_fixed_from_int(50)); | 149 wl_fixed_from_int(50), wl_fixed_from_int(50)); |
| 150 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_BACK, | 150 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_BACK, |
| 151 WL_POINTER_BUTTON_STATE_PRESSED); | 151 WL_POINTER_BUTTON_STATE_PRESSED); |
| 152 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, | 152 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, |
| 153 WL_POINTER_BUTTON_STATE_PRESSED); | 153 WL_POINTER_BUTTON_STATE_PRESSED); |
| 154 | 154 |
| 155 Sync(); | 155 Sync(); |
| 156 | 156 |
| 157 std::unique_ptr<Event> event; | 157 std::unique_ptr<Event> event; |
| 158 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); | 158 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 159 wl_pointer_send_button(pointer->resource(), 4, 1004, BTN_LEFT, | 159 wl_pointer_send_button(pointer->resource(), 4, 1004, BTN_LEFT, |
| 160 WL_POINTER_BUTTON_STATE_RELEASED); | 160 WL_POINTER_BUTTON_STATE_RELEASED); |
| 161 | 161 |
| 162 Sync(); | 162 Sync(); |
| 163 | 163 |
| 164 ASSERT_TRUE(event); | 164 ASSERT_TRUE(event); |
| 165 ASSERT_TRUE(event->IsMouseEvent()); | 165 ASSERT_TRUE(event->IsMouseEvent()); |
| 166 auto mouse_event = event->AsMouseEvent(); | 166 auto* mouse_event = event->AsMouseEvent(); |
| 167 EXPECT_EQ(ET_MOUSE_RELEASED, mouse_event->type()); | 167 EXPECT_EQ(ET_MOUSE_RELEASED, mouse_event->type()); |
| 168 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON, | 168 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON, |
| 169 mouse_event->button_flags()); | 169 mouse_event->button_flags()); |
| 170 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags()); | 170 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_button_flags()); |
| 171 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->location_f()); | 171 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->location_f()); |
| 172 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->root_location_f()); | 172 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->root_location_f()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 TEST_F(WaylandPointerTest, AxisVertical) { | 175 TEST_F(WaylandPointerTest, AxisVertical) { |
| 176 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), | 176 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 177 wl_fixed_from_int(0), wl_fixed_from_int(0)); | 177 wl_fixed_from_int(0), wl_fixed_from_int(0)); |
| 178 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, | 178 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, |
| 179 WL_POINTER_BUTTON_STATE_PRESSED); | 179 WL_POINTER_BUTTON_STATE_PRESSED); |
| 180 | 180 |
| 181 Sync(); | 181 Sync(); |
| 182 | 182 |
| 183 std::unique_ptr<Event> event; | 183 std::unique_ptr<Event> event; |
| 184 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); | 184 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 185 // Wayland servers typically send a value of 10 per mouse wheel click. | 185 // Wayland servers typically send a value of 10 per mouse wheel click. |
| 186 wl_pointer_send_axis(pointer->resource(), 1003, | 186 wl_pointer_send_axis(pointer->resource(), 1003, |
| 187 WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(20)); | 187 WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(20)); |
| 188 | 188 |
| 189 Sync(); | 189 Sync(); |
| 190 | 190 |
| 191 ASSERT_TRUE(event); | 191 ASSERT_TRUE(event); |
| 192 ASSERT_TRUE(event->IsMouseWheelEvent()); | 192 ASSERT_TRUE(event->IsMouseWheelEvent()); |
| 193 auto mouse_wheel_event = event->AsMouseWheelEvent(); | 193 auto* mouse_wheel_event = event->AsMouseWheelEvent(); |
| 194 EXPECT_EQ(gfx::Vector2d(0, -2 * MouseWheelEvent::kWheelDelta), | 194 EXPECT_EQ(gfx::Vector2d(0, -2 * MouseWheelEvent::kWheelDelta), |
| 195 mouse_wheel_event->offset()); | 195 mouse_wheel_event->offset()); |
| 196 EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); | 196 EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); |
| 197 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); | 197 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); |
| 198 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->location_f()); | 198 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->location_f()); |
| 199 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->root_location_f()); | 199 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->root_location_f()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 TEST_F(WaylandPointerTest, AxisHorizontal) { | 202 TEST_F(WaylandPointerTest, AxisHorizontal) { |
| 203 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), | 203 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 204 wl_fixed_from_int(50), wl_fixed_from_int(75)); | 204 wl_fixed_from_int(50), wl_fixed_from_int(75)); |
| 205 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_LEFT, | 205 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_LEFT, |
| 206 WL_POINTER_BUTTON_STATE_PRESSED); | 206 WL_POINTER_BUTTON_STATE_PRESSED); |
| 207 | 207 |
| 208 Sync(); | 208 Sync(); |
| 209 | 209 |
| 210 std::unique_ptr<Event> event; | 210 std::unique_ptr<Event> event; |
| 211 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); | 211 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 212 // Wayland servers typically send a value of 10 per mouse wheel click. | 212 // Wayland servers typically send a value of 10 per mouse wheel click. |
| 213 wl_pointer_send_axis(pointer->resource(), 1003, | 213 wl_pointer_send_axis(pointer->resource(), 1003, |
| 214 WL_POINTER_AXIS_HORIZONTAL_SCROLL, | 214 WL_POINTER_AXIS_HORIZONTAL_SCROLL, |
| 215 wl_fixed_from_int(10)); | 215 wl_fixed_from_int(10)); |
| 216 | 216 |
| 217 Sync(); | 217 Sync(); |
| 218 | 218 |
| 219 ASSERT_TRUE(event); | 219 ASSERT_TRUE(event); |
| 220 ASSERT_TRUE(event->IsMouseWheelEvent()); | 220 ASSERT_TRUE(event->IsMouseWheelEvent()); |
| 221 auto mouse_wheel_event = event->AsMouseWheelEvent(); | 221 auto* mouse_wheel_event = event->AsMouseWheelEvent(); |
| 222 EXPECT_EQ(gfx::Vector2d(MouseWheelEvent::kWheelDelta, 0), | 222 EXPECT_EQ(gfx::Vector2d(MouseWheelEvent::kWheelDelta, 0), |
| 223 mouse_wheel_event->offset()); | 223 mouse_wheel_event->offset()); |
| 224 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); | 224 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); |
| 225 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); | 225 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); |
| 226 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->location_f()); | 226 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->location_f()); |
| 227 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->root_location_f()); | 227 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->root_location_f()); |
| 228 } | 228 } |
| 229 | 229 |
| 230 } // namespace ui | 230 } // namespace ui |
| OLD | NEW |