| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/common/input/input_param_traits.h" | 5 #include "content/common/input/input_param_traits.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "content/common/input/input_event.h" | 11 #include "content/common/input/input_event.h" |
| 12 #include "content/common/input/synthetic_gesture_params.h" | 12 #include "content/common/input/synthetic_gesture_params.h" |
| 13 #include "content/common/input/synthetic_pinch_gesture_params.h" | 13 #include "content/common/input/synthetic_pinch_gesture_params.h" |
| 14 #include "content/common/input/synthetic_pointer_action_list_params.h" |
| 14 #include "content/common/input/synthetic_pointer_action_params.h" | 15 #include "content/common/input/synthetic_pointer_action_params.h" |
| 15 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" | 16 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
| 16 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 17 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
| 17 #include "content/common/input_messages.h" | 18 #include "content/common/input_messages.h" |
| 18 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "third_party/WebKit/public/platform/WebGestureEvent.h" | 21 #include "third_party/WebKit/public/platform/WebGestureEvent.h" |
| 21 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 22 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 76 |
| 76 static void Compare(const SyntheticTapGestureParams* a, | 77 static void Compare(const SyntheticTapGestureParams* a, |
| 77 const SyntheticTapGestureParams* b) { | 78 const SyntheticTapGestureParams* b) { |
| 78 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type); | 79 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type); |
| 79 EXPECT_EQ(a->position, b->position); | 80 EXPECT_EQ(a->position, b->position); |
| 80 EXPECT_EQ(a->duration_ms, b->duration_ms); | 81 EXPECT_EQ(a->duration_ms, b->duration_ms); |
| 81 } | 82 } |
| 82 | 83 |
| 83 static void Compare(const SyntheticPointerActionParams* a, | 84 static void Compare(const SyntheticPointerActionParams* a, |
| 84 const SyntheticPointerActionParams* b) { | 85 const SyntheticPointerActionParams* b) { |
| 85 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type); | |
| 86 EXPECT_EQ(a->pointer_action_type(), b->pointer_action_type()); | 86 EXPECT_EQ(a->pointer_action_type(), b->pointer_action_type()); |
| 87 if (a->pointer_action_type() == | 87 if (a->pointer_action_type() == |
| 88 SyntheticPointerActionParams::PointerActionType::PRESS || | 88 SyntheticPointerActionParams::PointerActionType::PRESS || |
| 89 a->pointer_action_type() == | 89 a->pointer_action_type() == |
| 90 SyntheticPointerActionParams::PointerActionType::MOVE) { | 90 SyntheticPointerActionParams::PointerActionType::MOVE) { |
| 91 EXPECT_EQ(a->position(), b->position()); | 91 EXPECT_EQ(a->position(), b->position()); |
| 92 } | 92 } |
| 93 if (a->pointer_action_type() != | 93 EXPECT_EQ(a->index(), b->index()); |
| 94 SyntheticPointerActionParams::PointerActionType::FINISH) { | 94 } |
| 95 EXPECT_EQ(a->index(), b->index()); | 95 |
| 96 static void Compare(const SyntheticPointerActionListParams* a, |
| 97 const SyntheticPointerActionListParams* b) { |
| 98 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type); |
| 99 EXPECT_EQ(a->params.size(), b->params.size()); |
| 100 for (size_t i = 0; i < a->params.size(); ++i) { |
| 101 EXPECT_EQ(a->params[i].size(), b->params[i].size()); |
| 102 for (size_t j = 0; j < a->params[i].size(); ++j) { |
| 103 Compare(&a->params[i][j], &b->params[i][j]); |
| 104 } |
| 96 } | 105 } |
| 97 } | 106 } |
| 98 | 107 |
| 99 static void Compare(const SyntheticGesturePacket* a, | 108 static void Compare(const SyntheticGesturePacket* a, |
| 100 const SyntheticGesturePacket* b) { | 109 const SyntheticGesturePacket* b) { |
| 101 ASSERT_EQ(!!a, !!b); | 110 ASSERT_EQ(!!a, !!b); |
| 102 if (!a) return; | 111 if (!a) return; |
| 103 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params()); | 112 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params()); |
| 104 if (!a->gesture_params()) return; | 113 if (!a->gesture_params()) return; |
| 105 ASSERT_EQ(a->gesture_params()->GetGestureType(), | 114 ASSERT_EQ(a->gesture_params()->GetGestureType(), |
| 106 b->gesture_params()->GetGestureType()); | 115 b->gesture_params()->GetGestureType()); |
| 107 switch (a->gesture_params()->GetGestureType()) { | 116 switch (a->gesture_params()->GetGestureType()) { |
| 108 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: | 117 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: |
| 109 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()), | 118 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()), |
| 110 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params())); | 119 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params())); |
| 111 break; | 120 break; |
| 112 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE: | 121 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE: |
| 113 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()), | 122 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()), |
| 114 SyntheticSmoothDragGestureParams::Cast(b->gesture_params())); | 123 SyntheticSmoothDragGestureParams::Cast(b->gesture_params())); |
| 115 break; | 124 break; |
| 116 case SyntheticGestureParams::PINCH_GESTURE: | 125 case SyntheticGestureParams::PINCH_GESTURE: |
| 117 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()), | 126 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()), |
| 118 SyntheticPinchGestureParams::Cast(b->gesture_params())); | 127 SyntheticPinchGestureParams::Cast(b->gesture_params())); |
| 119 break; | 128 break; |
| 120 case SyntheticGestureParams::TAP_GESTURE: | 129 case SyntheticGestureParams::TAP_GESTURE: |
| 121 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()), | 130 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()), |
| 122 SyntheticTapGestureParams::Cast(b->gesture_params())); | 131 SyntheticTapGestureParams::Cast(b->gesture_params())); |
| 123 break; | 132 break; |
| 124 case SyntheticGestureParams::POINTER_ACTION: | 133 case SyntheticGestureParams::POINTER_ACTION_LIST: |
| 125 Compare(SyntheticPointerActionParams::Cast(a->gesture_params()), | 134 Compare(SyntheticPointerActionListParams::Cast(a->gesture_params()), |
| 126 SyntheticPointerActionParams::Cast(b->gesture_params())); | 135 SyntheticPointerActionListParams::Cast(b->gesture_params())); |
| 127 break; | 136 break; |
| 128 } | 137 } |
| 129 } | 138 } |
| 130 | 139 |
| 131 static void Verify(const InputEvents& events_in) { | 140 static void Verify(const InputEvents& events_in) { |
| 132 IPC::Message msg; | 141 IPC::Message msg; |
| 133 IPC::ParamTraits<InputEvents>::Write(&msg, events_in); | 142 IPC::ParamTraits<InputEvents>::Write(&msg, events_in); |
| 134 | 143 |
| 135 InputEvents events_out; | 144 InputEvents events_out; |
| 136 base::PickleIterator iter(msg); | 145 base::PickleIterator iter(msg); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 gesture_params->position.SetPoint(798, 233); | 275 gesture_params->position.SetPoint(798, 233); |
| 267 gesture_params->duration_ms = 13; | 276 gesture_params->duration_ms = 13; |
| 268 ASSERT_EQ(SyntheticGestureParams::TAP_GESTURE, | 277 ASSERT_EQ(SyntheticGestureParams::TAP_GESTURE, |
| 269 gesture_params->GetGestureType()); | 278 gesture_params->GetGestureType()); |
| 270 SyntheticGesturePacket packet_in; | 279 SyntheticGesturePacket packet_in; |
| 271 packet_in.set_gesture_params(std::move(gesture_params)); | 280 packet_in.set_gesture_params(std::move(gesture_params)); |
| 272 | 281 |
| 273 Verify(packet_in); | 282 Verify(packet_in); |
| 274 } | 283 } |
| 275 | 284 |
| 276 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsMove) { | 285 TEST_F(InputParamTraitsTest, SyntheticPointerActionListParamsMove) { |
| 277 std::unique_ptr<SyntheticPointerActionParams> gesture_params = | 286 SyntheticPointerActionParams action_params( |
| 278 base::MakeUnique<SyntheticPointerActionParams>( | 287 SyntheticPointerActionParams::PointerActionType::MOVE); |
| 279 SyntheticPointerActionParams::PointerActionType::MOVE, | 288 action_params.set_position(gfx::PointF(356, 287)); |
| 280 SyntheticGestureParams::TOUCH_INPUT); | 289 action_params.set_index(0); |
| 281 gesture_params->set_position(gfx::PointF(356, 287)); | 290 std::unique_ptr<SyntheticPointerActionListParams> gesture_params = |
| 282 gesture_params->set_index(0); | 291 base::MakeUnique<SyntheticPointerActionListParams>(); |
| 283 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION, | 292 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 293 gesture_params->PushPointerActionParams(action_params); |
| 294 |
| 295 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION_LIST, |
| 284 gesture_params->GetGestureType()); | 296 gesture_params->GetGestureType()); |
| 285 SyntheticGesturePacket packet_in; | 297 SyntheticGesturePacket packet_in; |
| 286 packet_in.set_gesture_params(std::move(gesture_params)); | 298 packet_in.set_gesture_params(std::move(gesture_params)); |
| 287 Verify(packet_in); | 299 Verify(packet_in); |
| 288 } | 300 } |
| 289 | 301 |
| 290 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsRelease) { | 302 TEST_F(InputParamTraitsTest, SyntheticPointerActionListParamsPressRelease) { |
| 291 std::unique_ptr<SyntheticPointerActionParams> gesture_params = | 303 std::unique_ptr<SyntheticPointerActionListParams> gesture_params = |
| 292 base::MakeUnique<SyntheticPointerActionParams>( | 304 base::MakeUnique<SyntheticPointerActionListParams>(); |
| 293 SyntheticPointerActionParams::PointerActionType::RELEASE, | 305 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 294 SyntheticGestureParams::TOUCH_INPUT); | 306 SyntheticPointerActionParams action_params( |
| 295 gesture_params->set_index(0); | 307 SyntheticPointerActionParams::PointerActionType::PRESS); |
| 296 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION, | 308 action_params.set_index(0); |
| 309 gesture_params->PushPointerActionParams(action_params); |
| 310 action_params.set_pointer_action_type( |
| 311 SyntheticPointerActionParams::PointerActionType::RELEASE); |
| 312 gesture_params->PushPointerActionParams(action_params); |
| 313 |
| 314 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION_LIST, |
| 297 gesture_params->GetGestureType()); | 315 gesture_params->GetGestureType()); |
| 298 SyntheticGesturePacket packet_in; | 316 SyntheticGesturePacket packet_in; |
| 299 packet_in.set_gesture_params(std::move(gesture_params)); | 317 packet_in.set_gesture_params(std::move(gesture_params)); |
| 300 Verify(packet_in); | 318 Verify(packet_in); |
| 301 } | 319 } |
| 302 | 320 |
| 303 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsProcess) { | 321 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsIdle) { |
| 304 std::unique_ptr<SyntheticPointerActionParams> gesture_params = | 322 std::unique_ptr<SyntheticPointerActionListParams> gesture_params = |
| 305 base::MakeUnique<SyntheticPointerActionParams>( | 323 base::MakeUnique<SyntheticPointerActionListParams>(); |
| 306 SyntheticPointerActionParams::PointerActionType::IDLE, | 324 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 307 SyntheticGestureParams::TOUCH_INPUT); | 325 SyntheticPointerActionParams action_params( |
| 308 gesture_params->set_index(0); | 326 SyntheticPointerActionParams::PointerActionType::IDLE); |
| 309 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION, | 327 action_params.set_index(0); |
| 328 gesture_params->PushPointerActionParams(action_params); |
| 329 |
| 330 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION_LIST, |
| 310 gesture_params->GetGestureType()); | 331 gesture_params->GetGestureType()); |
| 311 SyntheticGesturePacket packet_in; | 332 SyntheticGesturePacket packet_in; |
| 312 packet_in.set_gesture_params(std::move(gesture_params)); | 333 packet_in.set_gesture_params(std::move(gesture_params)); |
| 313 Verify(packet_in); | 334 Verify(packet_in); |
| 314 } | 335 } |
| 315 | 336 |
| 316 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsFinish) { | 337 TEST_F(InputParamTraitsTest, SyntheticPointerActionListParamsTwoPresses) { |
| 317 std::unique_ptr<SyntheticPointerActionParams> gesture_params = | 338 SyntheticPointerActionListParams::ParamList param_list; |
| 318 base::MakeUnique<SyntheticPointerActionParams>( | 339 SyntheticPointerActionParams action_params( |
| 319 SyntheticPointerActionParams::PointerActionType::FINISH, | 340 SyntheticPointerActionParams::PointerActionType::PRESS); |
| 320 SyntheticGestureParams::TOUCH_INPUT); | 341 action_params.set_index(0); |
| 321 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION, | 342 param_list.push_back(action_params); |
| 343 action_params.set_index(1); |
| 344 param_list.push_back(action_params); |
| 345 std::unique_ptr<SyntheticPointerActionListParams> gesture_params = |
| 346 base::MakeUnique<SyntheticPointerActionListParams>(param_list); |
| 347 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 348 |
| 349 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION_LIST, |
| 322 gesture_params->GetGestureType()); | 350 gesture_params->GetGestureType()); |
| 323 SyntheticGesturePacket packet_in; | 351 SyntheticGesturePacket packet_in; |
| 324 packet_in.set_gesture_params(std::move(gesture_params)); | 352 packet_in.set_gesture_params(std::move(gesture_params)); |
| 325 Verify(packet_in); | 353 Verify(packet_in); |
| 326 } | 354 } |
| 327 | 355 |
| 328 } // namespace | 356 } // namespace |
| 329 } // namespace content | 357 } // namespace content |
| OLD | NEW |