Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: content/common/input/input_param_traits_unittest.cc

Issue 2336803003: Make SyntheticPointerAction to flush the pointer action sequence (Closed)
Patch Set: controller Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 75
75 static void Compare(const SyntheticTapGestureParams* a, 76 static void Compare(const SyntheticTapGestureParams* a,
76 const SyntheticTapGestureParams* b) { 77 const SyntheticTapGestureParams* b) {
77 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type); 78 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type);
78 EXPECT_EQ(a->position, b->position); 79 EXPECT_EQ(a->position, b->position);
79 EXPECT_EQ(a->duration_ms, b->duration_ms); 80 EXPECT_EQ(a->duration_ms, b->duration_ms);
80 } 81 }
81 82
82 static void Compare(const SyntheticPointerActionParams* a, 83 static void Compare(const SyntheticPointerActionParams* a,
83 const SyntheticPointerActionParams* b) { 84 const SyntheticPointerActionParams* b) {
84 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type);
85 EXPECT_EQ(a->pointer_action_type(), b->pointer_action_type()); 85 EXPECT_EQ(a->pointer_action_type(), b->pointer_action_type());
86 if (a->pointer_action_type() == 86 if (a->pointer_action_type() ==
87 SyntheticPointerActionParams::PointerActionType::PRESS || 87 SyntheticPointerActionParams::PointerActionType::PRESS ||
88 a->pointer_action_type() == 88 a->pointer_action_type() ==
89 SyntheticPointerActionParams::PointerActionType::MOVE) { 89 SyntheticPointerActionParams::PointerActionType::MOVE) {
90 EXPECT_EQ(a->position(), b->position()); 90 EXPECT_EQ(a->position(), b->position());
91 } 91 }
92 if (a->pointer_action_type() != 92 if (a->pointer_action_type() !=
93 SyntheticPointerActionParams::PointerActionType::PROCESS && 93 SyntheticPointerActionParams::PointerActionType::PROCESS &&
94 a->pointer_action_type() != 94 a->pointer_action_type() !=
95 SyntheticPointerActionParams::PointerActionType::FINISH) { 95 SyntheticPointerActionParams::PointerActionType::FINISH) {
96 EXPECT_EQ(a->index(), b->index()); 96 EXPECT_EQ(a->index(), b->index());
97 } 97 }
98 } 98 }
99 99
100 static void Compare(const SyntheticPointerActionListParams* a,
101 const SyntheticPointerActionListParams* b) {
102 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type);
103 EXPECT_EQ(a->param_list.size(), b->param_list.size());
104 for (size_t i = 0; i < a->param_list.size(); ++i) {
105 Compare(&a->param_list[i], &b->param_list[i]);
106 }
107 }
108
100 static void Compare(const SyntheticGesturePacket* a, 109 static void Compare(const SyntheticGesturePacket* a,
101 const SyntheticGesturePacket* b) { 110 const SyntheticGesturePacket* b) {
102 ASSERT_EQ(!!a, !!b); 111 ASSERT_EQ(!!a, !!b);
103 if (!a) return; 112 if (!a) return;
104 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params()); 113 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params());
105 if (!a->gesture_params()) return; 114 if (!a->gesture_params()) return;
106 ASSERT_EQ(a->gesture_params()->GetGestureType(), 115 ASSERT_EQ(a->gesture_params()->GetGestureType(),
107 b->gesture_params()->GetGestureType()); 116 b->gesture_params()->GetGestureType());
108 switch (a->gesture_params()->GetGestureType()) { 117 switch (a->gesture_params()->GetGestureType()) {
109 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: 118 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE:
110 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()), 119 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()),
111 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params())); 120 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params()));
112 break; 121 break;
113 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE: 122 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE:
114 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()), 123 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()),
115 SyntheticSmoothDragGestureParams::Cast(b->gesture_params())); 124 SyntheticSmoothDragGestureParams::Cast(b->gesture_params()));
116 break; 125 break;
117 case SyntheticGestureParams::PINCH_GESTURE: 126 case SyntheticGestureParams::PINCH_GESTURE:
118 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()), 127 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()),
119 SyntheticPinchGestureParams::Cast(b->gesture_params())); 128 SyntheticPinchGestureParams::Cast(b->gesture_params()));
120 break; 129 break;
121 case SyntheticGestureParams::TAP_GESTURE: 130 case SyntheticGestureParams::TAP_GESTURE:
122 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()), 131 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()),
123 SyntheticTapGestureParams::Cast(b->gesture_params())); 132 SyntheticTapGestureParams::Cast(b->gesture_params()));
124 break; 133 break;
125 case SyntheticGestureParams::POINTER_ACTION: 134 case SyntheticGestureParams::POINTER_ACTION_LIST:
126 Compare(SyntheticPointerActionParams::Cast(a->gesture_params()), 135 Compare(SyntheticPointerActionListParams::Cast(a->gesture_params()),
127 SyntheticPointerActionParams::Cast(b->gesture_params())); 136 SyntheticPointerActionListParams::Cast(b->gesture_params()));
128 break; 137 break;
129 } 138 }
130 } 139 }
131 140
132 static void Verify(const InputEvents& events_in) { 141 static void Verify(const InputEvents& events_in) {
133 IPC::Message msg; 142 IPC::Message msg;
134 IPC::ParamTraits<InputEvents>::Write(&msg, events_in); 143 IPC::ParamTraits<InputEvents>::Write(&msg, events_in);
135 144
136 InputEvents events_out; 145 InputEvents events_out;
137 base::PickleIterator iter(msg); 146 base::PickleIterator iter(msg);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 gesture_params->position.SetPoint(798, 233); 276 gesture_params->position.SetPoint(798, 233);
268 gesture_params->duration_ms = 13; 277 gesture_params->duration_ms = 13;
269 ASSERT_EQ(SyntheticGestureParams::TAP_GESTURE, 278 ASSERT_EQ(SyntheticGestureParams::TAP_GESTURE,
270 gesture_params->GetGestureType()); 279 gesture_params->GetGestureType());
271 SyntheticGesturePacket packet_in; 280 SyntheticGesturePacket packet_in;
272 packet_in.set_gesture_params(std::move(gesture_params)); 281 packet_in.set_gesture_params(std::move(gesture_params));
273 282
274 Verify(packet_in); 283 Verify(packet_in);
275 } 284 }
276 285
277 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsMove) { 286 TEST_F(InputParamTraitsTest, SyntheticPointerActionListParams) {
278 std::unique_ptr<SyntheticPointerActionParams> gesture_params = 287 SyntheticPointerActionParams action_params(
279 base::MakeUnique<SyntheticPointerActionParams>( 288 SyntheticGestureParams::TOUCH_INPUT,
280 SyntheticPointerActionParams::PointerActionType::MOVE); 289 SyntheticPointerActionParams::PointerActionType::MOVE);
290 action_params.set_position(gfx::PointF(356, 287));
291 action_params.set_index(0);
292 std::unique_ptr<SyntheticPointerActionListParams> gesture_params =
293 base::MakeUnique<SyntheticPointerActionListParams>(action_params);
281 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; 294 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
282 gesture_params->set_position(gfx::PointF(356, 287)); 295
283 gesture_params->set_index(0); 296 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION_LIST,
284 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION,
285 gesture_params->GetGestureType()); 297 gesture_params->GetGestureType());
286 SyntheticGesturePacket packet_in; 298 SyntheticGesturePacket packet_in;
287 packet_in.set_gesture_params(std::move(gesture_params)); 299 packet_in.set_gesture_params(std::move(gesture_params));
300
288 Verify(packet_in); 301 Verify(packet_in);
289 } 302 }
290 303
291 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsRelease) {
292 std::unique_ptr<SyntheticPointerActionParams> gesture_params =
293 base::MakeUnique<SyntheticPointerActionParams>(
294 SyntheticPointerActionParams::PointerActionType::RELEASE);
tdresser 2016/10/26 18:28:40 Should we still have release specific coverage, or
lanwei 2016/10/30 23:23:13 Thanks for catching this, I delete by accident.
295 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
296 gesture_params->set_index(0);
297 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION,
298 gesture_params->GetGestureType());
299 SyntheticGesturePacket packet_in;
300 packet_in.set_gesture_params(std::move(gesture_params));
301 Verify(packet_in);
302 }
303
304 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsProcess) {
305 std::unique_ptr<SyntheticPointerActionParams> gesture_params =
306 base::MakeUnique<SyntheticPointerActionParams>(
307 SyntheticPointerActionParams::PointerActionType::PROCESS);
308 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
309 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION,
310 gesture_params->GetGestureType());
311 SyntheticGesturePacket packet_in;
312 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 gesture_params->gesture_source_type = 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);
326 }
327
328 } // namespace 304 } // namespace
329 } // namespace content 305 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698