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 "content/common/input/input_event.h" | 10 #include "content/common/input/input_event.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 EXPECT_EQ(a->anchor, b->anchor); | 68 EXPECT_EQ(a->anchor, b->anchor); |
69 EXPECT_EQ(a->relative_pointer_speed_in_pixels_s, | 69 EXPECT_EQ(a->relative_pointer_speed_in_pixels_s, |
70 b->relative_pointer_speed_in_pixels_s); | 70 b->relative_pointer_speed_in_pixels_s); |
71 } | 71 } |
72 | 72 |
73 static void Compare(const SyntheticTapGestureParams* a, | 73 static void Compare(const SyntheticTapGestureParams* a, |
74 const SyntheticTapGestureParams* b) { | 74 const SyntheticTapGestureParams* b) { |
75 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type); | 75 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type); |
76 EXPECT_EQ(a->position, b->position); | 76 EXPECT_EQ(a->position, b->position); |
77 EXPECT_EQ(a->duration_ms, b->duration_ms); | 77 EXPECT_EQ(a->duration_ms, b->duration_ms); |
78 EXPECT_EQ(a->index, b->index); | |
79 EXPECT_EQ(a->pointer_action_type, b->pointer_action_type); | |
80 } | |
81 | |
82 static void Compare(const SyntheticPointerActionParams* a, | |
83 const SyntheticPointerActionParams* b) { | |
84 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type); | |
85 EXPECT_EQ(a->position, b->position); | |
86 EXPECT_EQ(a->duration_ms, b->duration_ms); | |
78 } | 87 } |
79 | 88 |
80 static void Compare(const SyntheticGesturePacket* a, | 89 static void Compare(const SyntheticGesturePacket* a, |
81 const SyntheticGesturePacket* b) { | 90 const SyntheticGesturePacket* b) { |
82 ASSERT_EQ(!!a, !!b); | 91 ASSERT_EQ(!!a, !!b); |
83 if (!a) return; | 92 if (!a) return; |
84 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params()); | 93 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params()); |
85 if (!a->gesture_params()) return; | 94 if (!a->gesture_params()) return; |
86 ASSERT_EQ(a->gesture_params()->GetGestureType(), | 95 ASSERT_EQ(a->gesture_params()->GetGestureType(), |
87 b->gesture_params()->GetGestureType()); | 96 b->gesture_params()->GetGestureType()); |
88 switch (a->gesture_params()->GetGestureType()) { | 97 switch (a->gesture_params()->GetGestureType()) { |
89 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: | 98 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: |
90 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()), | 99 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()), |
91 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params())); | 100 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params())); |
92 break; | 101 break; |
93 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE: | 102 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE: |
94 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()), | 103 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()), |
95 SyntheticSmoothDragGestureParams::Cast(b->gesture_params())); | 104 SyntheticSmoothDragGestureParams::Cast(b->gesture_params())); |
96 break; | 105 break; |
97 case SyntheticGestureParams::PINCH_GESTURE: | 106 case SyntheticGestureParams::PINCH_GESTURE: |
98 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()), | 107 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()), |
99 SyntheticPinchGestureParams::Cast(b->gesture_params())); | 108 SyntheticPinchGestureParams::Cast(b->gesture_params())); |
100 break; | 109 break; |
101 case SyntheticGestureParams::TAP_GESTURE: | 110 case SyntheticGestureParams::TAP_GESTURE: |
102 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()), | 111 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()), |
103 SyntheticTapGestureParams::Cast(b->gesture_params())); | 112 SyntheticTapGestureParams::Cast(b->gesture_params())); |
104 break; | 113 break; |
114 case SyntheticGestureParams::POINTER_ACTION: | |
115 Compare(SyntheticPointerActionParams::Cast(a->gesture_params()), | |
116 SyntheticPointerActionParams::Cast(b->gesture_params())); | |
117 break; | |
105 } | 118 } |
106 } | 119 } |
107 | 120 |
108 static void Verify(const InputEvents& events_in) { | 121 static void Verify(const InputEvents& events_in) { |
109 IPC::Message msg; | 122 IPC::Message msg; |
110 IPC::ParamTraits<InputEvents>::Write(&msg, events_in); | 123 IPC::ParamTraits<InputEvents>::Write(&msg, events_in); |
111 | 124 |
112 InputEvents events_out; | 125 InputEvents events_out; |
113 base::PickleIterator iter(msg); | 126 base::PickleIterator iter(msg); |
114 EXPECT_TRUE(IPC::ParamTraits<InputEvents>::Read(&msg, &iter, &events_out)); | 127 EXPECT_TRUE(IPC::ParamTraits<InputEvents>::Read(&msg, &iter, &events_out)); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 gesture_params->position.SetPoint(798, 233); | 256 gesture_params->position.SetPoint(798, 233); |
244 gesture_params->duration_ms = 13; | 257 gesture_params->duration_ms = 13; |
245 ASSERT_EQ(SyntheticGestureParams::TAP_GESTURE, | 258 ASSERT_EQ(SyntheticGestureParams::TAP_GESTURE, |
246 gesture_params->GetGestureType()); | 259 gesture_params->GetGestureType()); |
247 SyntheticGesturePacket packet_in; | 260 SyntheticGesturePacket packet_in; |
248 packet_in.set_gesture_params(std::move(gesture_params)); | 261 packet_in.set_gesture_params(std::move(gesture_params)); |
249 | 262 |
250 Verify(packet_in); | 263 Verify(packet_in); |
251 } | 264 } |
252 | 265 |
266 TEST_F(InputParamTraitsTest, SyntheticPointerActionParams) { | |
267 scoped_ptr<SyntheticPointerActionParams> gesture_params( | |
268 new SyntheticPointerActionParams); | |
269 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; | |
270 gesture_params->position.SetPoint(356, 287); | |
271 gesture_params->duration_ms = 16; | |
tdresser
2016/02/18 14:46:34
I don't think duration should be used for anything
lanwei
2016/02/26 18:39:26
Done.
| |
272 gesture_params->index = 1; | |
273 gesture_params->pointer_action_type = SyntheticGesture::PRESS; | |
274 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION, | |
275 gesture_params->GetGestureType()); | |
276 SyntheticGesturePacket packet_in; | |
277 packet_in.set_gesture_params(std::move(gesture_params)); | |
278 | |
279 Verify(packet_in); | |
280 } | |
281 | |
253 } // namespace | 282 } // namespace |
254 } // namespace content | 283 } // namespace content |
OLD | NEW |