| 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 = static_cast<MouseEvent*>(event.get()); | 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 // TODO(forney): Once crbug.com/337827 is solved, compare with the fractional | 93 // TODO(forney): Once crbug.com/337827 is solved, compare with the fractional |
| 94 // coordinates sent above. | 94 // coordinates sent above. |
| 95 EXPECT_EQ(gfx::PointF(10, 20), mouse_event->location_f()); | 95 EXPECT_EQ(gfx::PointF(10, 20), mouse_event->location_f()); |
| 96 EXPECT_EQ(gfx::PointF(10, 20), mouse_event->root_location_f()); | 96 EXPECT_EQ(gfx::PointF(10, 20), mouse_event->root_location_f()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST_F(WaylandPointerTest, MotionDragged) { | 99 TEST_F(WaylandPointerTest, MotionDragged) { |
| 100 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0); | 100 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), 0, 0); |
| 101 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_MIDDLE, | 101 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_MIDDLE, |
| 102 WL_POINTER_BUTTON_STATE_PRESSED); | 102 WL_POINTER_BUTTON_STATE_PRESSED); |
| 103 | 103 |
| 104 Sync(); | 104 Sync(); |
| 105 | 105 |
| 106 std::unique_ptr<Event> event; | 106 std::unique_ptr<Event> event; |
| 107 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); | 107 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 108 wl_pointer_send_motion(pointer->resource(), 1003, wl_fixed_from_int(400), | 108 wl_pointer_send_motion(pointer->resource(), 1003, wl_fixed_from_int(400), |
| 109 wl_fixed_from_int(500)); | 109 wl_fixed_from_int(500)); |
| 110 | 110 |
| 111 Sync(); | 111 Sync(); |
| 112 | 112 |
| 113 ASSERT_TRUE(event); | 113 ASSERT_TRUE(event); |
| 114 ASSERT_TRUE(event->IsMouseEvent()); | 114 ASSERT_TRUE(event->IsMouseEvent()); |
| 115 auto mouse_event = static_cast<MouseEvent*>(event.get()); | 115 auto mouse_event = event->AsMouseEvent(); |
| 116 EXPECT_EQ(ET_MOUSE_DRAGGED, mouse_event->type()); | 116 EXPECT_EQ(ET_MOUSE_DRAGGED, mouse_event->type()); |
| 117 EXPECT_EQ(EF_MIDDLE_MOUSE_BUTTON, mouse_event->button_flags()); | 117 EXPECT_EQ(EF_MIDDLE_MOUSE_BUTTON, mouse_event->button_flags()); |
| 118 EXPECT_EQ(0, mouse_event->changed_button_flags()); | 118 EXPECT_EQ(0, mouse_event->changed_button_flags()); |
| 119 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->location_f()); | 119 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->location_f()); |
| 120 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->root_location_f()); | 120 EXPECT_EQ(gfx::PointF(400, 500), mouse_event->root_location_f()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 TEST_F(WaylandPointerTest, ButtonPress) { | 123 TEST_F(WaylandPointerTest, ButtonPress) { |
| 124 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), | 124 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 125 wl_fixed_from_int(200), wl_fixed_from_int(150)); | 125 wl_fixed_from_int(200), wl_fixed_from_int(150)); |
| 126 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, | 126 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, |
| 127 WL_POINTER_BUTTON_STATE_PRESSED); | 127 WL_POINTER_BUTTON_STATE_PRESSED); |
| 128 | 128 |
| 129 Sync(); | 129 Sync(); |
| 130 | 130 |
| 131 std::unique_ptr<Event> event; | 131 std::unique_ptr<Event> event; |
| 132 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); | 132 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 133 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, | 133 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, |
| 134 WL_POINTER_BUTTON_STATE_PRESSED); | 134 WL_POINTER_BUTTON_STATE_PRESSED); |
| 135 | 135 |
| 136 Sync(); | 136 Sync(); |
| 137 | 137 |
| 138 ASSERT_TRUE(event); | 138 ASSERT_TRUE(event); |
| 139 ASSERT_TRUE(event->IsMouseEvent()); | 139 ASSERT_TRUE(event->IsMouseEvent()); |
| 140 auto mouse_event = static_cast<MouseEvent*>(event.get()); | 140 auto mouse_event = event->AsMouseEvent(); |
| 141 EXPECT_EQ(ET_MOUSE_PRESSED, mouse_event->type()); | 141 EXPECT_EQ(ET_MOUSE_PRESSED, mouse_event->type()); |
| 142 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON, | 142 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON, |
| 143 mouse_event->button_flags()); | 143 mouse_event->button_flags()); |
| 144 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_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()); | 145 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->location_f()); |
| 146 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->root_location_f()); | 146 EXPECT_EQ(gfx::PointF(200, 150), mouse_event->root_location_f()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 TEST_F(WaylandPointerTest, ButtonRelease) { | 149 TEST_F(WaylandPointerTest, ButtonRelease) { |
| 150 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), | 150 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 151 wl_fixed_from_int(50), wl_fixed_from_int(50)); | 151 wl_fixed_from_int(50), wl_fixed_from_int(50)); |
| 152 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_BACK, | 152 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_BACK, |
| 153 WL_POINTER_BUTTON_STATE_PRESSED); | 153 WL_POINTER_BUTTON_STATE_PRESSED); |
| 154 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, | 154 wl_pointer_send_button(pointer->resource(), 3, 1003, BTN_LEFT, |
| 155 WL_POINTER_BUTTON_STATE_PRESSED); | 155 WL_POINTER_BUTTON_STATE_PRESSED); |
| 156 | 156 |
| 157 Sync(); | 157 Sync(); |
| 158 | 158 |
| 159 std::unique_ptr<Event> event; | 159 std::unique_ptr<Event> event; |
| 160 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); | 160 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 161 wl_pointer_send_button(pointer->resource(), 4, 1004, BTN_LEFT, | 161 wl_pointer_send_button(pointer->resource(), 4, 1004, BTN_LEFT, |
| 162 WL_POINTER_BUTTON_STATE_RELEASED); | 162 WL_POINTER_BUTTON_STATE_RELEASED); |
| 163 | 163 |
| 164 Sync(); | 164 Sync(); |
| 165 | 165 |
| 166 ASSERT_TRUE(event); | 166 ASSERT_TRUE(event); |
| 167 ASSERT_TRUE(event->IsMouseEvent()); | 167 ASSERT_TRUE(event->IsMouseEvent()); |
| 168 auto mouse_event = static_cast<MouseEvent*>(event.get()); | 168 auto mouse_event = event->AsMouseEvent(); |
| 169 EXPECT_EQ(ET_MOUSE_RELEASED, mouse_event->type()); | 169 EXPECT_EQ(ET_MOUSE_RELEASED, mouse_event->type()); |
| 170 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON, | 170 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON, |
| 171 mouse_event->button_flags()); | 171 mouse_event->button_flags()); |
| 172 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_event->changed_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()); | 173 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->location_f()); |
| 174 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->root_location_f()); | 174 EXPECT_EQ(gfx::PointF(50, 50), mouse_event->root_location_f()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 TEST_F(WaylandPointerTest, AxisVertical) { | 177 TEST_F(WaylandPointerTest, AxisVertical) { |
| 178 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), | 178 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 179 wl_fixed_from_int(0), wl_fixed_from_int(0)); | 179 wl_fixed_from_int(0), wl_fixed_from_int(0)); |
| 180 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, | 180 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_RIGHT, |
| 181 WL_POINTER_BUTTON_STATE_PRESSED); | 181 WL_POINTER_BUTTON_STATE_PRESSED); |
| 182 | 182 |
| 183 Sync(); | 183 Sync(); |
| 184 | 184 |
| 185 std::unique_ptr<Event> event; | 185 std::unique_ptr<Event> event; |
| 186 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); | 186 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 187 // Wayland servers typically send a value of 10 per mouse wheel click. | 187 // Wayland servers typically send a value of 10 per mouse wheel click. |
| 188 wl_pointer_send_axis(pointer->resource(), 1003, | 188 wl_pointer_send_axis(pointer->resource(), 1003, |
| 189 WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(20)); | 189 WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_int(20)); |
| 190 | 190 |
| 191 Sync(); | 191 Sync(); |
| 192 | 192 |
| 193 ASSERT_TRUE(event); | 193 ASSERT_TRUE(event); |
| 194 ASSERT_TRUE(event->IsMouseWheelEvent()); | 194 ASSERT_TRUE(event->IsMouseWheelEvent()); |
| 195 auto mouse_wheel_event = static_cast<MouseWheelEvent*>(event.get()); | 195 auto mouse_wheel_event = event->AsMouseWheelEvent(); |
| 196 EXPECT_EQ(gfx::Vector2d(0, -2 * MouseWheelEvent::kWheelDelta), | 196 EXPECT_EQ(gfx::Vector2d(0, -2 * MouseWheelEvent::kWheelDelta), |
| 197 mouse_wheel_event->offset()); | 197 mouse_wheel_event->offset()); |
| 198 EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); | 198 EXPECT_EQ(EF_RIGHT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); |
| 199 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); | 199 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); |
| 200 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->location_f()); | 200 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->location_f()); |
| 201 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->root_location_f()); | 201 EXPECT_EQ(gfx::PointF(), mouse_wheel_event->root_location_f()); |
| 202 } | 202 } |
| 203 | 203 |
| 204 TEST_F(WaylandPointerTest, AxisHorizontal) { | 204 TEST_F(WaylandPointerTest, AxisHorizontal) { |
| 205 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), | 205 wl_pointer_send_enter(pointer->resource(), 1, surface->resource(), |
| 206 wl_fixed_from_int(50), wl_fixed_from_int(75)); | 206 wl_fixed_from_int(50), wl_fixed_from_int(75)); |
| 207 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_LEFT, | 207 wl_pointer_send_button(pointer->resource(), 2, 1002, BTN_LEFT, |
| 208 WL_POINTER_BUTTON_STATE_PRESSED); | 208 WL_POINTER_BUTTON_STATE_PRESSED); |
| 209 | 209 |
| 210 Sync(); | 210 Sync(); |
| 211 | 211 |
| 212 std::unique_ptr<Event> event; | 212 std::unique_ptr<Event> event; |
| 213 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); | 213 EXPECT_CALL(delegate, DispatchEvent(_)).WillOnce(CloneEvent(&event)); |
| 214 // Wayland servers typically send a value of 10 per mouse wheel click. | 214 // Wayland servers typically send a value of 10 per mouse wheel click. |
| 215 wl_pointer_send_axis(pointer->resource(), 1003, | 215 wl_pointer_send_axis(pointer->resource(), 1003, |
| 216 WL_POINTER_AXIS_HORIZONTAL_SCROLL, | 216 WL_POINTER_AXIS_HORIZONTAL_SCROLL, |
| 217 wl_fixed_from_int(10)); | 217 wl_fixed_from_int(10)); |
| 218 | 218 |
| 219 Sync(); | 219 Sync(); |
| 220 | 220 |
| 221 ASSERT_TRUE(event); | 221 ASSERT_TRUE(event); |
| 222 ASSERT_TRUE(event->IsMouseWheelEvent()); | 222 ASSERT_TRUE(event->IsMouseWheelEvent()); |
| 223 auto mouse_wheel_event = static_cast<MouseWheelEvent*>(event.get()); | 223 auto mouse_wheel_event = event->AsMouseWheelEvent(); |
| 224 EXPECT_EQ(gfx::Vector2d(MouseWheelEvent::kWheelDelta, 0), | 224 EXPECT_EQ(gfx::Vector2d(MouseWheelEvent::kWheelDelta, 0), |
| 225 mouse_wheel_event->offset()); | 225 mouse_wheel_event->offset()); |
| 226 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); | 226 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, mouse_wheel_event->button_flags()); |
| 227 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); | 227 EXPECT_EQ(0, mouse_wheel_event->changed_button_flags()); |
| 228 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->location_f()); | 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()); | 229 EXPECT_EQ(gfx::PointF(50, 75), mouse_wheel_event->root_location_f()); |
| 230 } | 230 } |
| 231 | 231 |
| 232 } // namespace ui | 232 } // namespace ui |
| OLD | NEW |