[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / common / input / gesture_event_stream_validator_unittest.cc
blob88484ef372fa53fd26f44f4ec9d676bfe2668171
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/input/gesture_event_stream_validator.h"
7 #include "content/common/input/synthetic_web_input_event_builders.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using blink::WebInputEvent;
11 using blink::WebGestureEvent;
13 namespace content {
14 namespace {
16 const blink::WebGestureDevice kDefaultGestureDevice =
17 blink::WebGestureDeviceTouchscreen;
19 blink::WebGestureEvent Build(WebInputEvent::Type type) {
20 blink::WebGestureEvent event =
21 SyntheticWebGestureEventBuilder::Build(type, kDefaultGestureDevice);
22 // Default to providing a (valid) non-zero fling velocity.
23 if (type == WebInputEvent::GestureFlingStart)
24 event.data.flingStart.velocityX = 5;
25 return event;
28 } // namespace
30 TEST(GestureEventStreamValidator, ValidScroll) {
31 GestureEventStreamValidator validator;
32 std::string error_msg;
33 WebGestureEvent event;
35 event = Build(WebInputEvent::GestureScrollBegin);
36 EXPECT_TRUE(validator.Validate(event, &error_msg));
37 EXPECT_TRUE(error_msg.empty());
39 event = Build(WebInputEvent::GestureScrollUpdate);
40 EXPECT_TRUE(validator.Validate(event, &error_msg));
41 EXPECT_TRUE(error_msg.empty());
43 event = Build(WebInputEvent::GestureScrollEnd);
44 EXPECT_TRUE(validator.Validate(event, &error_msg));
45 EXPECT_TRUE(error_msg.empty());
48 TEST(GestureEventStreamValidator, InvalidScroll) {
49 GestureEventStreamValidator validator;
50 std::string error_msg;
51 WebGestureEvent event;
53 // No preceding ScrollBegin.
54 event = Build(WebInputEvent::GestureScrollUpdate);
55 EXPECT_FALSE(validator.Validate(event, &error_msg));
56 EXPECT_FALSE(error_msg.empty());
58 // No preceding ScrollBegin.
59 event = Build(WebInputEvent::GestureScrollEnd);
60 EXPECT_FALSE(validator.Validate(event, &error_msg));
61 EXPECT_FALSE(error_msg.empty());
63 event = Build(WebInputEvent::GestureScrollBegin);
64 EXPECT_TRUE(validator.Validate(event, &error_msg));
65 EXPECT_TRUE(error_msg.empty());
67 // Already scrolling.
68 event = Build(WebInputEvent::GestureScrollBegin);
69 EXPECT_FALSE(validator.Validate(event, &error_msg));
70 EXPECT_FALSE(error_msg.empty());
72 event = Build(WebInputEvent::GestureScrollEnd);
73 EXPECT_TRUE(validator.Validate(event, &error_msg));
74 EXPECT_TRUE(error_msg.empty());
76 // Scroll already ended.
77 event = Build(WebInputEvent::GestureScrollEnd);
78 EXPECT_FALSE(validator.Validate(event, &error_msg));
79 EXPECT_FALSE(error_msg.empty());
82 TEST(GestureEventStreamValidator, ValidFling) {
83 GestureEventStreamValidator validator;
84 std::string error_msg;
85 WebGestureEvent event;
87 event = Build(WebInputEvent::GestureScrollBegin);
88 EXPECT_TRUE(validator.Validate(event, &error_msg));
89 EXPECT_TRUE(error_msg.empty());
91 event = Build(WebInputEvent::GestureFlingStart);
92 EXPECT_TRUE(validator.Validate(event, &error_msg));
93 EXPECT_TRUE(error_msg.empty());
96 TEST(GestureEventStreamValidator, InvalidFling) {
97 GestureEventStreamValidator validator;
98 std::string error_msg;
99 WebGestureEvent event;
101 // No preceding ScrollBegin.
102 event = Build(WebInputEvent::GestureFlingStart);
103 EXPECT_FALSE(validator.Validate(event, &error_msg));
104 EXPECT_FALSE(error_msg.empty());
106 // Zero velocity.
107 event = Build(WebInputEvent::GestureScrollBegin);
108 EXPECT_TRUE(validator.Validate(event, &error_msg));
109 EXPECT_TRUE(error_msg.empty());
111 event = Build(WebInputEvent::GestureFlingStart);
112 event.data.flingStart.velocityX = 0;
113 event.data.flingStart.velocityY = 0;
114 EXPECT_FALSE(validator.Validate(event, &error_msg));
115 EXPECT_FALSE(error_msg.empty());
118 TEST(GestureEventStreamValidator, ValidPinch) {
119 GestureEventStreamValidator validator;
120 std::string error_msg;
121 WebGestureEvent event;
123 event = Build(WebInputEvent::GesturePinchBegin);
124 EXPECT_TRUE(validator.Validate(event, &error_msg));
125 EXPECT_TRUE(error_msg.empty());
127 event = Build(WebInputEvent::GesturePinchUpdate);
128 EXPECT_TRUE(validator.Validate(event, &error_msg));
129 EXPECT_TRUE(error_msg.empty());
131 event = Build(WebInputEvent::GesturePinchEnd);
132 EXPECT_TRUE(validator.Validate(event, &error_msg));
133 EXPECT_TRUE(error_msg.empty());
136 TEST(GestureEventStreamValidator, InvalidPinch) {
137 GestureEventStreamValidator validator;
138 std::string error_msg;
139 WebGestureEvent event;
141 // No preceding PinchBegin.
142 event = Build(WebInputEvent::GesturePinchUpdate);
143 EXPECT_FALSE(validator.Validate(event, &error_msg));
144 EXPECT_FALSE(error_msg.empty());
146 event = Build(WebInputEvent::GesturePinchBegin);
147 EXPECT_TRUE(validator.Validate(event, &error_msg));
148 EXPECT_TRUE(error_msg.empty());
150 // ScrollBegin while pinching.
151 event = Build(WebInputEvent::GestureScrollBegin);
152 EXPECT_FALSE(validator.Validate(event, &error_msg));
153 EXPECT_FALSE(error_msg.empty());
155 // ScrollEnd while pinching.
156 event = Build(WebInputEvent::GestureScrollEnd);
157 EXPECT_FALSE(validator.Validate(event, &error_msg));
158 EXPECT_FALSE(error_msg.empty());
160 // Pinch already begun.
161 event = Build(WebInputEvent::GesturePinchBegin);
162 EXPECT_FALSE(validator.Validate(event, &error_msg));
163 EXPECT_FALSE(error_msg.empty());
165 event = Build(WebInputEvent::GesturePinchEnd);
166 EXPECT_TRUE(validator.Validate(event, &error_msg));
167 EXPECT_TRUE(error_msg.empty());
169 // Pinch already ended.
170 event = Build(WebInputEvent::GesturePinchEnd);
171 EXPECT_FALSE(validator.Validate(event, &error_msg));
172 EXPECT_FALSE(error_msg.empty());
175 TEST(GestureEventStreamValidator, ValidTap) {
176 GestureEventStreamValidator validator;
177 std::string error_msg;
178 WebGestureEvent event;
180 event = Build(WebInputEvent::GestureTapDown);
181 EXPECT_TRUE(validator.Validate(event, &error_msg));
182 EXPECT_TRUE(error_msg.empty());
184 event = Build(WebInputEvent::GestureTapCancel);
185 EXPECT_TRUE(validator.Validate(event, &error_msg));
186 EXPECT_TRUE(error_msg.empty());
188 event = Build(WebInputEvent::GestureTapDown);
189 EXPECT_TRUE(validator.Validate(event, &error_msg));
190 EXPECT_TRUE(error_msg.empty());
192 event = Build(WebInputEvent::GestureTapUnconfirmed);
193 EXPECT_TRUE(validator.Validate(event, &error_msg));
194 EXPECT_TRUE(error_msg.empty());
196 event = Build(WebInputEvent::GestureTapCancel);
197 EXPECT_TRUE(validator.Validate(event, &error_msg));
198 EXPECT_TRUE(error_msg.empty());
200 event = Build(WebInputEvent::GestureTapDown);
201 EXPECT_TRUE(validator.Validate(event, &error_msg));
202 EXPECT_TRUE(error_msg.empty());
204 event = Build(WebInputEvent::GestureTap);
205 EXPECT_TRUE(validator.Validate(event, &error_msg));
206 EXPECT_TRUE(error_msg.empty());
208 // DoubleTap does not require a TapDown (unlike Tap, TapUnconfirmed and
209 // TapCancel).
210 event = Build(WebInputEvent::GestureDoubleTap);
211 EXPECT_TRUE(validator.Validate(event, &error_msg));
212 EXPECT_TRUE(error_msg.empty());
215 TEST(GestureEventStreamValidator, InvalidTap) {
216 GestureEventStreamValidator validator;
217 std::string error_msg;
218 WebGestureEvent event;
220 // No preceding TapDown.
221 event = Build(WebInputEvent::GestureTapUnconfirmed);
222 EXPECT_FALSE(validator.Validate(event, &error_msg));
223 EXPECT_FALSE(error_msg.empty());
225 event = Build(WebInputEvent::GestureTapCancel);
226 EXPECT_FALSE(validator.Validate(event, &error_msg));
227 EXPECT_FALSE(error_msg.empty());
229 event = Build(WebInputEvent::GestureTap);
230 EXPECT_FALSE(validator.Validate(event, &error_msg));
231 EXPECT_FALSE(error_msg.empty());
233 // TapDown already terminated.
234 event = Build(WebInputEvent::GestureTapDown);
235 EXPECT_TRUE(validator.Validate(event, &error_msg));
236 EXPECT_TRUE(error_msg.empty());
238 event = Build(WebInputEvent::GestureDoubleTap);
239 EXPECT_TRUE(validator.Validate(event, &error_msg));
240 EXPECT_TRUE(error_msg.empty());
242 event = Build(WebInputEvent::GestureTapCancel);
243 EXPECT_FALSE(validator.Validate(event, &error_msg));
244 EXPECT_FALSE(error_msg.empty());
246 // TapDown already terminated.
247 event = Build(WebInputEvent::GestureTapDown);
248 EXPECT_TRUE(validator.Validate(event, &error_msg));
249 EXPECT_TRUE(error_msg.empty());
251 event = Build(WebInputEvent::GestureTap);
252 EXPECT_TRUE(validator.Validate(event, &error_msg));
253 EXPECT_TRUE(error_msg.empty());
255 event = Build(WebInputEvent::GestureTapCancel);
256 EXPECT_FALSE(validator.Validate(event, &error_msg));
257 EXPECT_FALSE(error_msg.empty());
260 } // namespace content