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

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: Changes in synthetic_gesture_controller_unittest.cc Created 4 years, 9 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->position(), b->position());
tdresser 2016/03/23 15:09:25 Won't this fail for some types, due to the asserti
samuong 2016/03/29 20:51:25 Not sure if I'm talking about the same issue as Ti
tdresser 2016/03/30 13:52:22 That's separate from what I'm referring to (there
lanwei 2016/03/30 21:02:53 I checked the definition of EXPECT_EQ, it uses Poi
lanwei 2016/03/30 21:02:53 Thanks for catching this, I added the constraint w
tdresser 2016/03/31 12:25:31 The fact that we didn't catch this in any automate
85 EXPECT_EQ(a->index(), b->index());
86 EXPECT_EQ(a->pointer_action_type(), b->pointer_action_type());
87 }
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
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 SyntheticPointerActionParams::PointerActionType::MOVE));
270 gesture_params->gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
271 gesture_params->set_position(gfx::PointF(356, 287));
272 gesture_params->set_index(0);
273 ASSERT_EQ(SyntheticGestureParams::POINTER_ACTION,
274 gesture_params->GetGestureType());
275 SyntheticGesturePacket packet_in;
276 packet_in.set_gesture_params(std::move(gesture_params));
277 Verify(packet_in);
278 }
279
253 } // namespace 280 } // namespace
254 } // namespace content 281 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698