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/web/WebInputEvent.h" | 21 #include "third_party/WebKit/public/web/WebInputEvent.h" |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 namespace { | 24 namespace { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 EXPECT_EQ(a->position(), b->position()); | 91 EXPECT_EQ(a->position(), b->position()); |
91 } | 92 } |
92 if (a->pointer_action_type() != | 93 if (a->pointer_action_type() != |
93 SyntheticPointerActionParams::PointerActionType::PROCESS && | 94 SyntheticPointerActionParams::PointerActionType::PROCESS && |
94 a->pointer_action_type() != | 95 a->pointer_action_type() != |
95 SyntheticPointerActionParams::PointerActionType::FINISH) { | 96 SyntheticPointerActionParams::PointerActionType::FINISH) { |
96 EXPECT_EQ(a->index(), b->index()); | 97 EXPECT_EQ(a->index(), b->index()); |
97 } | 98 } |
98 } | 99 } |
99 | 100 |
| 101 static void Compare(const SyntheticPointerActionListParams* a, |
| 102 const SyntheticPointerActionListParams* b) { |
| 103 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type); |
| 104 EXPECT_EQ(a->param_list.size(), b->param_list.size()); |
| 105 for (size_t i = 0; i < a->param_list.size(); ++i) { |
| 106 Compare(&a->param_list[i], &b->param_list[i]); |
| 107 } |
| 108 } |
| 109 |
100 static void Compare(const SyntheticGesturePacket* a, | 110 static void Compare(const SyntheticGesturePacket* a, |
101 const SyntheticGesturePacket* b) { | 111 const SyntheticGesturePacket* b) { |
102 ASSERT_EQ(!!a, !!b); | 112 ASSERT_EQ(!!a, !!b); |
103 if (!a) return; | 113 if (!a) return; |
104 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params()); | 114 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params()); |
105 if (!a->gesture_params()) return; | 115 if (!a->gesture_params()) return; |
106 ASSERT_EQ(a->gesture_params()->GetGestureType(), | 116 ASSERT_EQ(a->gesture_params()->GetGestureType(), |
107 b->gesture_params()->GetGestureType()); | 117 b->gesture_params()->GetGestureType()); |
108 switch (a->gesture_params()->GetGestureType()) { | 118 switch (a->gesture_params()->GetGestureType()) { |
109 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: | 119 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: |
110 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()), | 120 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()), |
111 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params())); | 121 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params())); |
112 break; | 122 break; |
113 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE: | 123 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE: |
114 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()), | 124 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()), |
115 SyntheticSmoothDragGestureParams::Cast(b->gesture_params())); | 125 SyntheticSmoothDragGestureParams::Cast(b->gesture_params())); |
116 break; | 126 break; |
117 case SyntheticGestureParams::PINCH_GESTURE: | 127 case SyntheticGestureParams::PINCH_GESTURE: |
118 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()), | 128 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()), |
119 SyntheticPinchGestureParams::Cast(b->gesture_params())); | 129 SyntheticPinchGestureParams::Cast(b->gesture_params())); |
120 break; | 130 break; |
121 case SyntheticGestureParams::TAP_GESTURE: | 131 case SyntheticGestureParams::TAP_GESTURE: |
122 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()), | 132 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()), |
123 SyntheticTapGestureParams::Cast(b->gesture_params())); | 133 SyntheticTapGestureParams::Cast(b->gesture_params())); |
124 break; | 134 break; |
125 case SyntheticGestureParams::POINTER_ACTION: | 135 case SyntheticGestureParams::POINTER_ACTION: |
126 Compare(SyntheticPointerActionParams::Cast(a->gesture_params()), | 136 Compare(SyntheticPointerActionParams::Cast(a->gesture_params()), |
127 SyntheticPointerActionParams::Cast(b->gesture_params())); | 137 SyntheticPointerActionParams::Cast(b->gesture_params())); |
128 break; | 138 break; |
| 139 case SyntheticGestureParams::POINTER_ACTION_LIST: |
| 140 Compare(SyntheticPointerActionListParams::Cast(a->gesture_params()), |
| 141 SyntheticPointerActionListParams::Cast(b->gesture_params())); |
| 142 break; |
129 } | 143 } |
130 } | 144 } |
131 | 145 |
132 static void Verify(const InputEvents& events_in) { | 146 static void Verify(const InputEvents& events_in) { |
133 IPC::Message msg; | 147 IPC::Message msg; |
134 IPC::ParamTraits<InputEvents>::Write(&msg, events_in); | 148 IPC::ParamTraits<InputEvents>::Write(&msg, events_in); |
135 | 149 |
136 InputEvents events_out; | 150 InputEvents events_out; |
137 base::PickleIterator iter(msg); | 151 base::PickleIterator iter(msg); |
138 EXPECT_TRUE(IPC::ParamTraits<InputEvents>::Read(&msg, &iter, &events_out)); | 152 EXPECT_TRUE(IPC::ParamTraits<InputEvents>::Read(&msg, &iter, &events_out)); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 base::MakeUnique<SyntheticPointerActionParams>( | 332 base::MakeUnique<SyntheticPointerActionParams>( |
319 SyntheticPointerActionParams::PointerActionType::FINISH); | 333 SyntheticPointerActionParams::PointerActionType::FINISH); |
320 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | 334 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
321 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION, | 335 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION, |
322 gesture_params->GetGestureType()); | 336 gesture_params->GetGestureType()); |
323 SyntheticGesturePacket packet_in; | 337 SyntheticGesturePacket packet_in; |
324 packet_in.set_gesture_params(std::move(gesture_params)); | 338 packet_in.set_gesture_params(std::move(gesture_params)); |
325 Verify(packet_in); | 339 Verify(packet_in); |
326 } | 340 } |
327 | 341 |
| 342 TEST_F(InputParamTraitsTest, SyntheticPointerActionListParams) { |
| 343 SyntheticPointerActionParams action_params( |
| 344 SyntheticPointerActionParams::PointerActionType::MOVE); |
| 345 action_params.gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 346 action_params.set_position(gfx::PointF(356, 287)); |
| 347 action_params.set_index(0); |
| 348 std::unique_ptr<SyntheticPointerActionListParams> gesture_params = |
| 349 base::MakeUnique<SyntheticPointerActionListParams>(action_params); |
| 350 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 351 |
| 352 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION_LIST, |
| 353 gesture_params->GetGestureType()); |
| 354 SyntheticGesturePacket packet_in; |
| 355 packet_in.set_gesture_params(std::move(gesture_params)); |
| 356 |
| 357 Verify(packet_in); |
| 358 } |
| 359 |
328 } // namespace | 360 } // namespace |
329 } // namespace content | 361 } // namespace content |
OLD | NEW |