Chromium Code Reviews| 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->gesture_source_type(), b->gesture_source_type()); |
| 86 EXPECT_EQ(a->pointer_action_type(), b->pointer_action_type()); | 87 EXPECT_EQ(a->pointer_action_type(), b->pointer_action_type()); |
| 87 if (a->pointer_action_type() == | 88 if (a->pointer_action_type() == |
| 88 SyntheticPointerActionParams::PointerActionType::PRESS || | 89 SyntheticPointerActionParams::PointerActionType::PRESS || |
| 89 a->pointer_action_type() == | 90 a->pointer_action_type() == |
| 90 SyntheticPointerActionParams::PointerActionType::MOVE) { | 91 SyntheticPointerActionParams::PointerActionType::MOVE) { |
| 91 EXPECT_EQ(a->position(), b->position()); | 92 EXPECT_EQ(a->position(), b->position()); |
| 92 } | 93 } |
| 93 if (a->pointer_action_type() != | 94 EXPECT_EQ(a->index(), b->index()); |
| 94 SyntheticPointerActionParams::PointerActionType::FINISH) { | 95 } |
| 95 EXPECT_EQ(a->index(), b->index()); | 96 |
| 97 static void Compare(const SyntheticPointerActionListParams* a, | |
| 98 const SyntheticPointerActionListParams* b) { | |
| 99 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type); | |
| 100 EXPECT_EQ(a->params.size(), b->params.size()); | |
| 101 for (size_t i = 0; i < a->params.size(); ++i) { | |
| 102 EXPECT_EQ(a->params[i].size(), b->params[i].size()); | |
| 103 for (size_t j = 0; j < a->params[i].size(); ++j) { | |
| 104 Compare(&a->params[i][j], &b->params[i][j]); | |
| 105 } | |
| 96 } | 106 } |
| 97 } | 107 } |
| 98 | 108 |
| 99 static void Compare(const SyntheticGesturePacket* a, | 109 static void Compare(const SyntheticGesturePacket* a, |
| 100 const SyntheticGesturePacket* b) { | 110 const SyntheticGesturePacket* b) { |
| 101 ASSERT_EQ(!!a, !!b); | 111 ASSERT_EQ(!!a, !!b); |
| 102 if (!a) return; | 112 if (!a) return; |
| 103 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params()); | 113 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params()); |
| 104 if (!a->gesture_params()) return; | 114 if (!a->gesture_params()) return; |
| 105 ASSERT_EQ(a->gesture_params()->GetGestureType(), | 115 ASSERT_EQ(a->gesture_params()->GetGestureType(), |
| 106 b->gesture_params()->GetGestureType()); | 116 b->gesture_params()->GetGestureType()); |
| 107 switch (a->gesture_params()->GetGestureType()) { | 117 switch (a->gesture_params()->GetGestureType()) { |
| 108 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: | 118 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: |
| 109 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()), | 119 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()), |
| 110 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params())); | 120 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params())); |
| 111 break; | 121 break; |
| 112 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE: | 122 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE: |
| 113 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()), | 123 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()), |
| 114 SyntheticSmoothDragGestureParams::Cast(b->gesture_params())); | 124 SyntheticSmoothDragGestureParams::Cast(b->gesture_params())); |
| 115 break; | 125 break; |
| 116 case SyntheticGestureParams::PINCH_GESTURE: | 126 case SyntheticGestureParams::PINCH_GESTURE: |
| 117 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()), | 127 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()), |
| 118 SyntheticPinchGestureParams::Cast(b->gesture_params())); | 128 SyntheticPinchGestureParams::Cast(b->gesture_params())); |
| 119 break; | 129 break; |
| 120 case SyntheticGestureParams::TAP_GESTURE: | 130 case SyntheticGestureParams::TAP_GESTURE: |
| 121 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()), | 131 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()), |
| 122 SyntheticTapGestureParams::Cast(b->gesture_params())); | 132 SyntheticTapGestureParams::Cast(b->gesture_params())); |
| 123 break; | 133 break; |
| 124 case SyntheticGestureParams::POINTER_ACTION: | 134 case SyntheticGestureParams::POINTER_ACTION_LIST: |
| 125 Compare(SyntheticPointerActionParams::Cast(a->gesture_params()), | 135 Compare(SyntheticPointerActionListParams::Cast(a->gesture_params()), |
| 126 SyntheticPointerActionParams::Cast(b->gesture_params())); | 136 SyntheticPointerActionListParams::Cast(b->gesture_params())); |
| 127 break; | 137 break; |
| 128 } | 138 } |
| 129 } | 139 } |
| 130 | 140 |
| 131 static void Verify(const InputEvents& events_in) { | 141 static void Verify(const InputEvents& events_in) { |
| 132 IPC::Message msg; | 142 IPC::Message msg; |
| 133 IPC::ParamTraits<InputEvents>::Write(&msg, events_in); | 143 IPC::ParamTraits<InputEvents>::Write(&msg, events_in); |
| 134 | 144 |
| 135 InputEvents events_out; | 145 InputEvents events_out; |
| 136 base::PickleIterator iter(msg); | 146 base::PickleIterator iter(msg); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 gesture_params->position.SetPoint(798, 233); | 276 gesture_params->position.SetPoint(798, 233); |
| 267 gesture_params->duration_ms = 13; | 277 gesture_params->duration_ms = 13; |
| 268 ASSERT_EQ(SyntheticGestureParams::TAP_GESTURE, | 278 ASSERT_EQ(SyntheticGestureParams::TAP_GESTURE, |
| 269 gesture_params->GetGestureType()); | 279 gesture_params->GetGestureType()); |
| 270 SyntheticGesturePacket packet_in; | 280 SyntheticGesturePacket packet_in; |
| 271 packet_in.set_gesture_params(std::move(gesture_params)); | 281 packet_in.set_gesture_params(std::move(gesture_params)); |
| 272 | 282 |
| 273 Verify(packet_in); | 283 Verify(packet_in); |
| 274 } | 284 } |
| 275 | 285 |
| 276 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsMove) { | 286 TEST_F(InputParamTraitsTest, SyntheticPointerActionListParamsMove) { |
| 277 std::unique_ptr<SyntheticPointerActionParams> gesture_params = | 287 SyntheticPointerActionParams action_params( |
| 278 base::MakeUnique<SyntheticPointerActionParams>( | 288 SyntheticPointerActionParams::PointerActionType::MOVE, |
| 279 SyntheticPointerActionParams::PointerActionType::MOVE, | 289 SyntheticGestureParams::TOUCH_INPUT); |
| 280 SyntheticGestureParams::TOUCH_INPUT); | 290 action_params.set_position(gfx::PointF(356, 287)); |
| 281 gesture_params->set_position(gfx::PointF(356, 287)); | 291 action_params.set_index(0); |
| 282 gesture_params->set_index(0); | 292 SyntheticPointerActionListParams params; |
| 283 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION, | 293 params.PushPointerActionParams(action_params); |
| 294 std::unique_ptr<SyntheticPointerActionListParams> gesture_params = | |
| 295 base::MakeUnique<SyntheticPointerActionListParams>(params); | |
|
Navid Zolghadr
2016/12/06 17:05:38
Could we just pass the "action_params" to MakeUniq
lanwei
2016/12/07 19:04:27
Done.
| |
| 296 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
| 297 | |
| 298 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION_LIST, | |
| 284 gesture_params->GetGestureType()); | 299 gesture_params->GetGestureType()); |
| 285 SyntheticGesturePacket packet_in; | 300 SyntheticGesturePacket packet_in; |
| 286 packet_in.set_gesture_params(std::move(gesture_params)); | 301 packet_in.set_gesture_params(std::move(gesture_params)); |
| 287 Verify(packet_in); | 302 Verify(packet_in); |
| 288 } | 303 } |
| 289 | 304 |
| 290 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsRelease) { | 305 TEST_F(InputParamTraitsTest, SyntheticPointerActionListParamsPressRelease) { |
| 291 std::unique_ptr<SyntheticPointerActionParams> gesture_params = | 306 SyntheticPointerActionParams action_params( |
| 292 base::MakeUnique<SyntheticPointerActionParams>( | 307 SyntheticPointerActionParams::PointerActionType::PRESS, |
| 293 SyntheticPointerActionParams::PointerActionType::RELEASE, | 308 SyntheticGestureParams::TOUCH_INPUT); |
| 294 SyntheticGestureParams::TOUCH_INPUT); | 309 action_params.set_index(0); |
| 295 gesture_params->set_index(0); | 310 SyntheticPointerActionListParams params; |
| 296 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION, | 311 params.PushPointerActionParams(action_params); |
| 312 action_params.set_pointer_action_type( | |
| 313 SyntheticPointerActionParams::PointerActionType::RELEASE); | |
| 314 params.PushPointerActionParams(action_params); | |
| 315 std::unique_ptr<SyntheticPointerActionListParams> gesture_params = | |
| 316 base::MakeUnique<SyntheticPointerActionListParams>(params); | |
| 317 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
| 318 | |
| 319 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION_LIST, | |
| 297 gesture_params->GetGestureType()); | 320 gesture_params->GetGestureType()); |
| 298 SyntheticGesturePacket packet_in; | 321 SyntheticGesturePacket packet_in; |
| 299 packet_in.set_gesture_params(std::move(gesture_params)); | 322 packet_in.set_gesture_params(std::move(gesture_params)); |
| 300 Verify(packet_in); | 323 Verify(packet_in); |
| 301 } | 324 } |
| 302 | 325 |
| 303 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsProcess) { | 326 TEST_F(InputParamTraitsTest, SyntheticPointerActionListParamsTwoPresses) { |
| 304 std::unique_ptr<SyntheticPointerActionParams> gesture_params = | 327 SyntheticPointerActionParams action_params( |
| 305 base::MakeUnique<SyntheticPointerActionParams>( | 328 SyntheticPointerActionParams::PointerActionType::PRESS, |
| 306 SyntheticPointerActionParams::PointerActionType::IDLE, | 329 SyntheticGestureParams::TOUCH_INPUT); |
| 307 SyntheticGestureParams::TOUCH_INPUT); | 330 action_params.set_index(0); |
| 308 gesture_params->set_index(0); | 331 SyntheticPointerActionListParams params; |
| 309 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION, | 332 params.PushPointerActionParams(action_params); |
| 333 action_params.set_index(1); | |
| 334 params.PushPointerActionParams(0, action_params); | |
| 335 std::unique_ptr<SyntheticPointerActionListParams> gesture_params = | |
| 336 base::MakeUnique<SyntheticPointerActionListParams>(params); | |
| 337 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
| 338 | |
| 339 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION_LIST, | |
| 310 gesture_params->GetGestureType()); | 340 gesture_params->GetGestureType()); |
| 311 SyntheticGesturePacket packet_in; | 341 SyntheticGesturePacket packet_in; |
| 312 packet_in.set_gesture_params(std::move(gesture_params)); | 342 packet_in.set_gesture_params(std::move(gesture_params)); |
| 313 Verify(packet_in); | |
| 314 } | |
| 315 | |
| 316 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsFinish) { | |
| 317 std::unique_ptr<SyntheticPointerActionParams> gesture_params = | |
| 318 base::MakeUnique<SyntheticPointerActionParams>( | |
| 319 SyntheticPointerActionParams::PointerActionType::FINISH, | |
| 320 SyntheticGestureParams::TOUCH_INPUT); | |
| 321 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION, | |
| 322 gesture_params->GetGestureType()); | |
| 323 SyntheticGesturePacket packet_in; | |
| 324 packet_in.set_gesture_params(std::move(gesture_params)); | |
| 325 Verify(packet_in); | 343 Verify(packet_in); |
| 326 } | 344 } |
| 327 | 345 |
| 328 } // namespace | 346 } // namespace |
| 329 } // namespace content | 347 } // namespace content |
| OLD | NEW |