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

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

Issue 1707943002: Add SyntheticPointerActionParams used in Chromedriver extension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add explicit to constructor Created 4 years, 8 months 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 "content/common/input/input_event.h" 10 #include "content/common/input/input_event.h"
11 #include "content/common/input/synthetic_gesture_params.h" 11 #include "content/common/input/synthetic_gesture_params.h"
12 #include "content/common/input/synthetic_pinch_gesture_params.h" 12 #include "content/common/input/synthetic_pinch_gesture_params.h"
13 #include "content/common/input/synthetic_pointer_action_params.h"
13 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" 14 #include "content/common/input/synthetic_smooth_drag_gesture_params.h"
14 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" 15 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
15 #include "content/common/input_messages.h" 16 #include "content/common/input_messages.h"
16 #include "ipc/ipc_message.h" 17 #include "ipc/ipc_message.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/WebKit/public/web/WebInputEvent.h" 19 #include "third_party/WebKit/public/web/WebInputEvent.h"
19 20
20 namespace content { 21 namespace content {
21 namespace { 22 namespace {
22 23
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 b->relative_pointer_speed_in_pixels_s); 71 b->relative_pointer_speed_in_pixels_s);
71 } 72 }
72 73
73 static void Compare(const SyntheticTapGestureParams* a, 74 static void Compare(const SyntheticTapGestureParams* a,
74 const SyntheticTapGestureParams* b) { 75 const SyntheticTapGestureParams* b) {
75 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type); 76 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type);
76 EXPECT_EQ(a->position, b->position); 77 EXPECT_EQ(a->position, b->position);
77 EXPECT_EQ(a->duration_ms, b->duration_ms); 78 EXPECT_EQ(a->duration_ms, b->duration_ms);
78 } 79 }
79 80
81 static void Compare(const SyntheticPointerActionParams* a,
82 const SyntheticPointerActionParams* b) {
83 EXPECT_EQ(a->gesture_source_type, b->gesture_source_type);
84 EXPECT_EQ(a->pointer_action_type(), b->pointer_action_type());
85 if (a->pointer_action_type() ==
86 SyntheticPointerActionParams::PointerActionType::PRESS ||
87 a->pointer_action_type() ==
88 SyntheticPointerActionParams::PointerActionType::MOVE) {
89 EXPECT_EQ(a->position(), b->position());
90 }
91 if (a->pointer_action_type() !=
92 SyntheticPointerActionParams::PointerActionType::PROCESS) {
93 EXPECT_EQ(a->index(), b->index());
94 }
95 }
96
80 static void Compare(const SyntheticGesturePacket* a, 97 static void Compare(const SyntheticGesturePacket* a,
81 const SyntheticGesturePacket* b) { 98 const SyntheticGesturePacket* b) {
82 ASSERT_EQ(!!a, !!b); 99 ASSERT_EQ(!!a, !!b);
83 if (!a) return; 100 if (!a) return;
84 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params()); 101 ASSERT_EQ(!!a->gesture_params(), !!b->gesture_params());
85 if (!a->gesture_params()) return; 102 if (!a->gesture_params()) return;
86 ASSERT_EQ(a->gesture_params()->GetGestureType(), 103 ASSERT_EQ(a->gesture_params()->GetGestureType(),
87 b->gesture_params()->GetGestureType()); 104 b->gesture_params()->GetGestureType());
88 switch (a->gesture_params()->GetGestureType()) { 105 switch (a->gesture_params()->GetGestureType()) {
89 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE: 106 case SyntheticGestureParams::SMOOTH_SCROLL_GESTURE:
90 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()), 107 Compare(SyntheticSmoothScrollGestureParams::Cast(a->gesture_params()),
91 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params())); 108 SyntheticSmoothScrollGestureParams::Cast(b->gesture_params()));
92 break; 109 break;
93 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE: 110 case SyntheticGestureParams::SMOOTH_DRAG_GESTURE:
94 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()), 111 Compare(SyntheticSmoothDragGestureParams::Cast(a->gesture_params()),
95 SyntheticSmoothDragGestureParams::Cast(b->gesture_params())); 112 SyntheticSmoothDragGestureParams::Cast(b->gesture_params()));
96 break; 113 break;
97 case SyntheticGestureParams::PINCH_GESTURE: 114 case SyntheticGestureParams::PINCH_GESTURE:
98 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()), 115 Compare(SyntheticPinchGestureParams::Cast(a->gesture_params()),
99 SyntheticPinchGestureParams::Cast(b->gesture_params())); 116 SyntheticPinchGestureParams::Cast(b->gesture_params()));
100 break; 117 break;
101 case SyntheticGestureParams::TAP_GESTURE: 118 case SyntheticGestureParams::TAP_GESTURE:
102 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()), 119 Compare(SyntheticTapGestureParams::Cast(a->gesture_params()),
103 SyntheticTapGestureParams::Cast(b->gesture_params())); 120 SyntheticTapGestureParams::Cast(b->gesture_params()));
104 break; 121 break;
122 case SyntheticGestureParams::POINTER_ACTION:
123 Compare(SyntheticPointerActionParams::Cast(a->gesture_params()),
124 SyntheticPointerActionParams::Cast(b->gesture_params()));
125 break;
105 } 126 }
106 } 127 }
107 128
108 static void Verify(const InputEvents& events_in) { 129 static void Verify(const InputEvents& events_in) {
109 IPC::Message msg; 130 IPC::Message msg;
110 IPC::ParamTraits<InputEvents>::Write(&msg, events_in); 131 IPC::ParamTraits<InputEvents>::Write(&msg, events_in);
111 132
112 InputEvents events_out; 133 InputEvents events_out;
113 base::PickleIterator iter(msg); 134 base::PickleIterator iter(msg);
114 EXPECT_TRUE(IPC::ParamTraits<InputEvents>::Read(&msg, &iter, &events_out)); 135 EXPECT_TRUE(IPC::ParamTraits<InputEvents>::Read(&msg, &iter, &events_out));
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 gesture_params->position.SetPoint(798, 233); 264 gesture_params->position.SetPoint(798, 233);
244 gesture_params->duration_ms = 13; 265 gesture_params->duration_ms = 13;
245 ASSERT_EQ(SyntheticGestureParams::TAP_GESTURE, 266 ASSERT_EQ(SyntheticGestureParams::TAP_GESTURE,
246 gesture_params->GetGestureType()); 267 gesture_params->GetGestureType());
247 SyntheticGesturePacket packet_in; 268 SyntheticGesturePacket packet_in;
248 packet_in.set_gesture_params(std::move(gesture_params)); 269 packet_in.set_gesture_params(std::move(gesture_params));
249 270
250 Verify(packet_in); 271 Verify(packet_in);
251 } 272 }
252 273
274 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsMove) {
275 scoped_ptr<SyntheticPointerActionParams> gesture_params(
276 new SyntheticPointerActionParams(
277 SyntheticPointerActionParams::PointerActionType::MOVE));
278 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
279 gesture_params->set_position(gfx::PointF(356, 287));
280 gesture_params->set_index(0);
281 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION,
282 gesture_params->GetGestureType());
283 SyntheticGesturePacket packet_in;
284 packet_in.set_gesture_params(std::move(gesture_params));
285 Verify(packet_in);
286 }
287
288 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsRelease) {
289 scoped_ptr<SyntheticPointerActionParams> gesture_params(
290 new SyntheticPointerActionParams(
291 SyntheticPointerActionParams::PointerActionType::RELEASE));
292 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
293 gesture_params->set_index(0);
294 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION,
295 gesture_params->GetGestureType());
296 SyntheticGesturePacket packet_in;
297 packet_in.set_gesture_params(std::move(gesture_params));
298 Verify(packet_in);
299 }
300
301 TEST_F(InputParamTraitsTest, SyntheticPointerActionParamsProcess) {
302 scoped_ptr<SyntheticPointerActionParams> gesture_params(
303 new SyntheticPointerActionParams(
304 SyntheticPointerActionParams::PointerActionType::PROCESS));
305 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
306 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION,
307 gesture_params->GetGestureType());
308 SyntheticGesturePacket packet_in;
309 packet_in.set_gesture_params(std::move(gesture_params));
310 Verify(packet_in);
311 }
312
253 } // namespace 313 } // namespace
254 } // namespace content 314 } // namespace content
OLDNEW
« no previous file with comments | « content/common/input/input_param_traits.cc ('k') | content/common/input/synthetic_gesture_params.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698