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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/time/time.h" | 6 #include "base/time/time.h" |
7 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 7 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
8 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" | 8 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
9 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 9 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
10 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" | 10 #include "content/browser/renderer_host/input/synthetic_pinch_gesture.h" |
11 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" | 11 #include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" |
12 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" | 12 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" |
13 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 13 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
14 #include "content/common/input/input_event.h" | |
15 #include "content/common/input/synthetic_pinch_gesture_params.h" | 14 #include "content/common/input/synthetic_pinch_gesture_params.h" |
16 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 15 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
17 #include "content/common/input/synthetic_tap_gesture_params.h" | 16 #include "content/common/input/synthetic_tap_gesture_params.h" |
18 #include "content/public/test/mock_render_process_host.h" | 17 #include "content/public/test/mock_render_process_host.h" |
19 #include "content/public/test/test_browser_context.h" | 18 #include "content/public/test/test_browser_context.h" |
20 #include "content/test/test_render_view_host.h" | 19 #include "content/test/test_render_view_host.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "third_party/WebKit/public/web/WebInputEvent.h" | 21 #include "third_party/WebKit/public/web/WebInputEvent.h" |
23 #include "ui/gfx/point.h" | 22 #include "ui/gfx/point.h" |
24 #include "ui/gfx/point_f.h" | 23 #include "ui/gfx/point_f.h" |
25 #include "ui/gfx/vector2d.h" | 24 #include "ui/gfx/vector2d.h" |
26 #include "ui/gfx/vector2d_f.h" | 25 #include "ui/gfx/vector2d_f.h" |
27 | 26 |
| 27 using blink::WebInputEvent; |
| 28 using blink::WebMouseEvent; |
| 29 using blink::WebMouseWheelEvent; |
| 30 using blink::WebTouchEvent; |
| 31 |
28 namespace content { | 32 namespace content { |
29 | 33 |
30 namespace { | 34 namespace { |
31 | 35 |
32 const int kFlushInputRateInMs = 16; | 36 const int kFlushInputRateInMs = 16; |
33 const int kPointerAssumedStoppedTimeMs = 43; | 37 const int kPointerAssumedStoppedTimeMs = 43; |
34 const int kTouchSlopInDips = 7; | 38 const int kTouchSlopInDips = 7; |
35 | 39 |
36 class MockSyntheticGesture : public SyntheticGesture { | 40 class MockSyntheticGesture : public SyntheticGesture { |
37 public: | 41 public: |
(...skipping 29 matching lines...) Expand all Loading... |
67 class MockSyntheticGestureTarget : public SyntheticGestureTarget { | 71 class MockSyntheticGestureTarget : public SyntheticGestureTarget { |
68 public: | 72 public: |
69 MockSyntheticGestureTarget() | 73 MockSyntheticGestureTarget() |
70 : num_success_(0), | 74 : num_success_(0), |
71 num_failure_(0), | 75 num_failure_(0), |
72 flush_requested_(false), | 76 flush_requested_(false), |
73 pointer_assumed_stopped_time_ms_(kPointerAssumedStoppedTimeMs) {} | 77 pointer_assumed_stopped_time_ms_(kPointerAssumedStoppedTimeMs) {} |
74 virtual ~MockSyntheticGestureTarget() {} | 78 virtual ~MockSyntheticGestureTarget() {} |
75 | 79 |
76 // SyntheticGestureTarget: | 80 // SyntheticGestureTarget: |
77 virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE {} | 81 virtual void DispatchInputEventToPlatform( |
| 82 const WebInputEvent& event) OVERRIDE {} |
78 | 83 |
79 virtual void OnSyntheticGestureCompleted( | 84 virtual void OnSyntheticGestureCompleted( |
80 SyntheticGesture::Result result) OVERRIDE { | 85 SyntheticGesture::Result result) OVERRIDE { |
81 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); | 86 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); |
82 if (result == SyntheticGesture::GESTURE_FINISHED) | 87 if (result == SyntheticGesture::GESTURE_FINISHED) |
83 num_success_++; | 88 num_success_++; |
84 else | 89 else |
85 num_failure_++; | 90 num_failure_++; |
86 } | 91 } |
87 | 92 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 protected: | 142 protected: |
138 gfx::Vector2dF scroll_distance_; | 143 gfx::Vector2dF scroll_distance_; |
139 }; | 144 }; |
140 | 145 |
141 class MockSyntheticSmoothScrollMouseTarget | 146 class MockSyntheticSmoothScrollMouseTarget |
142 : public MockSyntheticSmoothScrollGestureTarget { | 147 : public MockSyntheticSmoothScrollGestureTarget { |
143 public: | 148 public: |
144 MockSyntheticSmoothScrollMouseTarget() {} | 149 MockSyntheticSmoothScrollMouseTarget() {} |
145 virtual ~MockSyntheticSmoothScrollMouseTarget() {} | 150 virtual ~MockSyntheticSmoothScrollMouseTarget() {} |
146 | 151 |
147 virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE { | 152 virtual void DispatchInputEventToPlatform( |
148 const blink::WebInputEvent* web_event = event.web_event.get(); | 153 const WebInputEvent& event) OVERRIDE { |
149 ASSERT_EQ(web_event->type, blink::WebInputEvent::MouseWheel); | 154 ASSERT_EQ(event.type, WebInputEvent::MouseWheel); |
150 const blink::WebMouseWheelEvent* mouse_wheel_event = | 155 const WebMouseWheelEvent& mouse_wheel_event = |
151 static_cast<const blink::WebMouseWheelEvent*>(web_event); | 156 static_cast<const WebMouseWheelEvent&>(event); |
152 scroll_distance_ -= gfx::Vector2dF(mouse_wheel_event->deltaX, | 157 scroll_distance_ -= gfx::Vector2dF(mouse_wheel_event.deltaX, |
153 mouse_wheel_event->deltaY); | 158 mouse_wheel_event.deltaY); |
154 } | 159 } |
155 }; | 160 }; |
156 | 161 |
157 class MockSyntheticSmoothScrollTouchTarget | 162 class MockSyntheticSmoothScrollTouchTarget |
158 : public MockSyntheticSmoothScrollGestureTarget { | 163 : public MockSyntheticSmoothScrollGestureTarget { |
159 public: | 164 public: |
160 MockSyntheticSmoothScrollTouchTarget() | 165 MockSyntheticSmoothScrollTouchTarget() |
161 : started_(false) {} | 166 : started_(false) {} |
162 virtual ~MockSyntheticSmoothScrollTouchTarget() {} | 167 virtual ~MockSyntheticSmoothScrollTouchTarget() {} |
163 | 168 |
164 virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE { | 169 virtual void DispatchInputEventToPlatform( |
165 const blink::WebInputEvent* web_event = event.web_event.get(); | 170 const WebInputEvent& event) OVERRIDE { |
166 ASSERT_TRUE(blink::WebInputEvent::isTouchEventType(web_event->type)); | 171 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
167 const blink::WebTouchEvent* touch_event = | 172 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
168 static_cast<const blink::WebTouchEvent*>(web_event); | 173 ASSERT_EQ(touch_event.touchesLength, 1U); |
169 ASSERT_EQ(touch_event->touchesLength, (unsigned int)1); | |
170 | 174 |
171 if (!started_) { | 175 if (!started_) { |
172 ASSERT_EQ(touch_event->type, blink::WebInputEvent::TouchStart); | 176 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); |
173 anchor_.SetPoint(touch_event->touches[0].position.x, | 177 anchor_.SetPoint(touch_event.touches[0].position.x, |
174 touch_event->touches[0].position.y); | 178 touch_event.touches[0].position.y); |
175 started_ = true; | 179 started_ = true; |
176 } else { | 180 } else { |
177 ASSERT_NE(touch_event->type, blink::WebInputEvent::TouchStart); | 181 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart); |
178 ASSERT_NE(touch_event->type, blink::WebInputEvent::TouchCancel); | 182 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel); |
179 // Ignore move events. | 183 // Ignore move events. |
180 | 184 |
181 if (touch_event->type == blink::WebInputEvent::TouchEnd) | 185 if (touch_event.type == WebInputEvent::TouchEnd) |
182 scroll_distance_ = | 186 scroll_distance_ = |
183 anchor_ - gfx::PointF(touch_event->touches[0].position.x, | 187 anchor_ - gfx::PointF(touch_event.touches[0].position.x, |
184 touch_event->touches[0].position.y); | 188 touch_event.touches[0].position.y); |
185 } | 189 } |
186 } | 190 } |
187 | 191 |
188 protected: | 192 protected: |
189 gfx::Point anchor_; | 193 gfx::Point anchor_; |
190 bool started_; | 194 bool started_; |
191 }; | 195 }; |
192 | 196 |
193 class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { | 197 class MockSyntheticPinchTouchTarget : public MockSyntheticGestureTarget { |
194 public: | 198 public: |
195 enum ZoomDirection { | 199 enum ZoomDirection { |
196 ZOOM_DIRECTION_UNKNOWN, | 200 ZOOM_DIRECTION_UNKNOWN, |
197 ZOOM_IN, | 201 ZOOM_IN, |
198 ZOOM_OUT | 202 ZOOM_OUT |
199 }; | 203 }; |
200 | 204 |
201 MockSyntheticPinchTouchTarget() | 205 MockSyntheticPinchTouchTarget() |
202 : total_num_pixels_covered_(0), | 206 : total_num_pixels_covered_(0), |
203 last_pointer_distance_(0), | 207 last_pointer_distance_(0), |
204 zoom_direction_(ZOOM_DIRECTION_UNKNOWN), | 208 zoom_direction_(ZOOM_DIRECTION_UNKNOWN), |
205 started_(false) {} | 209 started_(false) {} |
206 virtual ~MockSyntheticPinchTouchTarget() {} | 210 virtual ~MockSyntheticPinchTouchTarget() {} |
207 | 211 |
208 virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE { | 212 virtual void DispatchInputEventToPlatform( |
209 const blink::WebInputEvent* web_event = event.web_event.get(); | 213 const WebInputEvent& event) OVERRIDE { |
210 ASSERT_TRUE(blink::WebInputEvent::isTouchEventType(web_event->type)); | 214 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
211 const blink::WebTouchEvent* touch_event = | 215 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
212 static_cast<const blink::WebTouchEvent*>(web_event); | 216 ASSERT_EQ(touch_event.touchesLength, 2U); |
213 ASSERT_EQ(touch_event->touchesLength, (unsigned int)2); | |
214 | 217 |
215 if (!started_) { | 218 if (!started_) { |
216 ASSERT_EQ(touch_event->type, blink::WebInputEvent::TouchStart); | 219 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); |
217 | 220 |
218 start_0_ = gfx::Point(touch_event->touches[0].position); | 221 start_0_ = gfx::Point(touch_event.touches[0].position); |
219 start_1_ = gfx::Point(touch_event->touches[1].position); | 222 start_1_ = gfx::Point(touch_event.touches[1].position); |
220 last_pointer_distance_ = (start_0_ - start_1_).Length(); | 223 last_pointer_distance_ = (start_0_ - start_1_).Length(); |
221 | 224 |
222 started_ = true; | 225 started_ = true; |
223 } else { | 226 } else { |
224 ASSERT_NE(touch_event->type, blink::WebInputEvent::TouchStart); | 227 ASSERT_NE(touch_event.type, WebInputEvent::TouchStart); |
225 ASSERT_NE(touch_event->type, blink::WebInputEvent::TouchCancel); | 228 ASSERT_NE(touch_event.type, WebInputEvent::TouchCancel); |
226 | 229 |
227 gfx::PointF current_0 = gfx::Point(touch_event->touches[0].position); | 230 gfx::PointF current_0 = gfx::Point(touch_event.touches[0].position); |
228 gfx::PointF current_1 = gfx::Point(touch_event->touches[1].position); | 231 gfx::PointF current_1 = gfx::Point(touch_event.touches[1].position); |
229 | 232 |
230 total_num_pixels_covered_ = | 233 total_num_pixels_covered_ = |
231 (current_0 - start_0_).Length() + (current_1 - start_1_).Length(); | 234 (current_0 - start_0_).Length() + (current_1 - start_1_).Length(); |
232 float pointer_distance = (current_0 - current_1).Length(); | 235 float pointer_distance = (current_0 - current_1).Length(); |
233 | 236 |
234 if (last_pointer_distance_ != pointer_distance) { | 237 if (last_pointer_distance_ != pointer_distance) { |
235 if (zoom_direction_ == ZOOM_DIRECTION_UNKNOWN) | 238 if (zoom_direction_ == ZOOM_DIRECTION_UNKNOWN) |
236 zoom_direction_ = | 239 zoom_direction_ = |
237 ComputeZoomDirection(last_pointer_distance_, pointer_distance); | 240 ComputeZoomDirection(last_pointer_distance_, pointer_distance); |
238 else | 241 else |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 base::TimeDelta start_time_; | 287 base::TimeDelta start_time_; |
285 base::TimeDelta stop_time_; | 288 base::TimeDelta stop_time_; |
286 GestureState state_; | 289 GestureState state_; |
287 }; | 290 }; |
288 | 291 |
289 class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget { | 292 class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget { |
290 public: | 293 public: |
291 MockSyntheticTapTouchTarget() {} | 294 MockSyntheticTapTouchTarget() {} |
292 virtual ~MockSyntheticTapTouchTarget() {} | 295 virtual ~MockSyntheticTapTouchTarget() {} |
293 | 296 |
294 virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE { | 297 virtual void DispatchInputEventToPlatform( |
295 const blink::WebInputEvent* web_event = event.web_event.get(); | 298 const WebInputEvent& event) OVERRIDE { |
296 ASSERT_TRUE(blink::WebInputEvent::isTouchEventType(web_event->type)); | 299 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); |
297 const blink::WebTouchEvent* touch_event = | 300 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); |
298 static_cast<const blink::WebTouchEvent*>(web_event); | 301 ASSERT_EQ(touch_event.touchesLength, 1U); |
299 ASSERT_EQ(touch_event->touchesLength, (unsigned int)1); | |
300 | 302 |
301 switch (state_) { | 303 switch (state_) { |
302 case NOT_STARTED: | 304 case NOT_STARTED: |
303 EXPECT_EQ(touch_event->type, blink::WebInputEvent::TouchStart); | 305 EXPECT_EQ(touch_event.type, WebInputEvent::TouchStart); |
304 position_ = gfx::Point(touch_event->touches[0].position); | 306 position_ = gfx::Point(touch_event.touches[0].position); |
305 start_time_ = base::TimeDelta::FromMilliseconds( | 307 start_time_ = base::TimeDelta::FromMilliseconds( |
306 static_cast<int64>(touch_event->timeStampSeconds * 1000)); | 308 static_cast<int64>(touch_event.timeStampSeconds * 1000)); |
307 state_ = STARTED; | 309 state_ = STARTED; |
308 break; | 310 break; |
309 case STARTED: | 311 case STARTED: |
310 EXPECT_EQ(touch_event->type, blink::WebInputEvent::TouchEnd); | 312 EXPECT_EQ(touch_event.type, WebInputEvent::TouchEnd); |
311 EXPECT_EQ(position_, gfx::Point(touch_event->touches[0].position)); | 313 EXPECT_EQ(position_, gfx::Point(touch_event.touches[0].position)); |
312 stop_time_ = base::TimeDelta::FromMilliseconds( | 314 stop_time_ = base::TimeDelta::FromMilliseconds( |
313 static_cast<int64>(touch_event->timeStampSeconds * 1000)); | 315 static_cast<int64>(touch_event.timeStampSeconds * 1000)); |
314 state_ = FINISHED; | 316 state_ = FINISHED; |
315 break; | 317 break; |
316 case FINISHED: | 318 case FINISHED: |
317 EXPECT_FALSE(true); | 319 EXPECT_FALSE(true); |
318 break; | 320 break; |
319 } | 321 } |
320 } | 322 } |
321 }; | 323 }; |
322 | 324 |
323 class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget { | 325 class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget { |
324 public: | 326 public: |
325 MockSyntheticTapMouseTarget() {} | 327 MockSyntheticTapMouseTarget() {} |
326 virtual ~MockSyntheticTapMouseTarget() {} | 328 virtual ~MockSyntheticTapMouseTarget() {} |
327 | 329 |
328 virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE { | 330 virtual void DispatchInputEventToPlatform( |
329 const blink::WebInputEvent* web_event = event.web_event.get(); | 331 const WebInputEvent& event) OVERRIDE { |
330 ASSERT_TRUE(blink::WebInputEvent::isMouseEventType(web_event->type)); | 332 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type)); |
331 const blink::WebMouseEvent* mouse_event = | 333 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); |
332 static_cast<const blink::WebMouseEvent*>(web_event); | |
333 | 334 |
334 switch (state_) { | 335 switch (state_) { |
335 case NOT_STARTED: | 336 case NOT_STARTED: |
336 EXPECT_EQ(mouse_event->type, blink::WebInputEvent::MouseDown); | 337 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseDown); |
337 EXPECT_EQ(mouse_event->button, blink::WebMouseEvent::ButtonLeft); | 338 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft); |
338 EXPECT_EQ(mouse_event->clickCount, 1); | 339 EXPECT_EQ(mouse_event.clickCount, 1); |
339 position_ = gfx::Point(mouse_event->x, mouse_event->y); | 340 position_ = gfx::Point(mouse_event.x, mouse_event.y); |
340 start_time_ = base::TimeDelta::FromMilliseconds( | 341 start_time_ = base::TimeDelta::FromMilliseconds( |
341 static_cast<int64>(mouse_event->timeStampSeconds * 1000)); | 342 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); |
342 state_ = STARTED; | 343 state_ = STARTED; |
343 break; | 344 break; |
344 case STARTED: | 345 case STARTED: |
345 EXPECT_EQ(mouse_event->type, blink::WebInputEvent::MouseUp); | 346 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseUp); |
346 EXPECT_EQ(mouse_event->button, blink::WebMouseEvent::ButtonLeft); | 347 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft); |
347 EXPECT_EQ(mouse_event->clickCount, 1); | 348 EXPECT_EQ(mouse_event.clickCount, 1); |
348 EXPECT_EQ(position_, gfx::Point(mouse_event->x, mouse_event->y)); | 349 EXPECT_EQ(position_, gfx::Point(mouse_event.x, mouse_event.y)); |
349 stop_time_ = base::TimeDelta::FromMilliseconds( | 350 stop_time_ = base::TimeDelta::FromMilliseconds( |
350 static_cast<int64>(mouse_event->timeStampSeconds * 1000)); | 351 static_cast<int64>(mouse_event.timeStampSeconds * 1000)); |
351 state_ = FINISHED; | 352 state_ = FINISHED; |
352 break; | 353 break; |
353 case FINISHED: | 354 case FINISHED: |
354 EXPECT_FALSE(true); | 355 EXPECT_FALSE(true); |
355 break; | 356 break; |
356 } | 357 } |
357 } | 358 } |
358 }; | 359 }; |
359 | 360 |
360 class SyntheticGestureControllerTest : public testing::Test { | 361 class SyntheticGestureControllerTest : public testing::Test { |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 EXPECT_TRUE(tap_target->GestureFinished()); | 819 EXPECT_TRUE(tap_target->GestureFinished()); |
819 EXPECT_EQ(tap_target->position(), params.position); | 820 EXPECT_EQ(tap_target->position(), params.position); |
820 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); | 821 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); |
821 EXPECT_GE(GetTotalTime(), | 822 EXPECT_GE(GetTotalTime(), |
822 base::TimeDelta::FromMilliseconds(params.duration_ms)); | 823 base::TimeDelta::FromMilliseconds(params.duration_ms)); |
823 } | 824 } |
824 | 825 |
825 } // namespace | 826 } // namespace |
826 | 827 |
827 } // namespace content | 828 } // namespace content |
OLD | NEW |