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

Side by Side Diff: content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc

Issue 119323007: Add timestamps to synthesized events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove target variables in pinch; fix computation of total duration. Created 6 years, 11 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 | Annotate | Revision Log
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 "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"
(...skipping 25 matching lines...) Expand all
36 class MockSyntheticGesture : public SyntheticGesture { 36 class MockSyntheticGesture : public SyntheticGesture {
37 public: 37 public:
38 MockSyntheticGesture(bool* finished, int num_steps) 38 MockSyntheticGesture(bool* finished, int num_steps)
39 : finished_(finished), 39 : finished_(finished),
40 num_steps_(num_steps), 40 num_steps_(num_steps),
41 step_count_(0) { 41 step_count_(0) {
42 *finished_ = false; 42 *finished_ = false;
43 } 43 }
44 virtual ~MockSyntheticGesture() {} 44 virtual ~MockSyntheticGesture() {}
45 45
46 virtual Result ForwardInputEvents(const base::TimeDelta& interval, 46 virtual Result ForwardInputEvents(const base::TimeTicks& timestamp,
47 SyntheticGestureTarget* target) OVERRIDE { 47 SyntheticGestureTarget* target) OVERRIDE {
48 step_count_++; 48 step_count_++;
49 if (step_count_ == num_steps_) { 49 if (step_count_ == num_steps_) {
50 *finished_ = true; 50 *finished_ = true;
51 return SyntheticGesture::GESTURE_FINISHED; 51 return SyntheticGesture::GESTURE_FINISHED;
52 } else if (step_count_ > num_steps_) { 52 } else if (step_count_ > num_steps_) {
53 *finished_ = true; 53 *finished_ = true;
54 // Return arbitrary failure. 54 // Return arbitrary failure.
55 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; 55 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED;
56 } 56 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 bool started_; 264 bool started_;
265 }; 265 };
266 266
267 class MockSyntheticTapGestureTarget : public MockSyntheticGestureTarget { 267 class MockSyntheticTapGestureTarget : public MockSyntheticGestureTarget {
268 public: 268 public:
269 MockSyntheticTapGestureTarget() : state_(NOT_STARTED) {} 269 MockSyntheticTapGestureTarget() : state_(NOT_STARTED) {}
270 virtual ~MockSyntheticTapGestureTarget() {} 270 virtual ~MockSyntheticTapGestureTarget() {}
271 271
272 bool GestureFinished() const { return state_ == FINISHED; } 272 bool GestureFinished() const { return state_ == FINISHED; }
273 gfx::Point position() const { return position_; } 273 gfx::Point position() const { return position_; }
274 base::TimeDelta GetDuration() const { return stop_time_ - start_time_; }
274 275
275 protected: 276 protected:
276 enum GestureState { 277 enum GestureState {
277 NOT_STARTED, 278 NOT_STARTED,
278 STARTED, 279 STARTED,
279 FINISHED 280 FINISHED
280 }; 281 };
281 282
282 gfx::Point position_; 283 gfx::Point position_;
284 base::TimeDelta start_time_;
285 base::TimeDelta stop_time_;
283 GestureState state_; 286 GestureState state_;
284 }; 287 };
285 288
286 class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget { 289 class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget {
287 public: 290 public:
288 MockSyntheticTapTouchTarget() {} 291 MockSyntheticTapTouchTarget() {}
289 virtual ~MockSyntheticTapTouchTarget() {} 292 virtual ~MockSyntheticTapTouchTarget() {}
290 293
291 virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE { 294 virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE {
292 const blink::WebInputEvent* web_event = event.web_event.get(); 295 const blink::WebInputEvent* web_event = event.web_event.get();
293 ASSERT_TRUE(blink::WebInputEvent::isTouchEventType(web_event->type)); 296 ASSERT_TRUE(blink::WebInputEvent::isTouchEventType(web_event->type));
294 const blink::WebTouchEvent* touch_event = 297 const blink::WebTouchEvent* touch_event =
295 static_cast<const blink::WebTouchEvent*>(web_event); 298 static_cast<const blink::WebTouchEvent*>(web_event);
296 ASSERT_EQ(touch_event->touchesLength, (unsigned int)1); 299 ASSERT_EQ(touch_event->touchesLength, (unsigned int)1);
297 300
298 switch (state_) { 301 switch (state_) {
299 case NOT_STARTED: 302 case NOT_STARTED:
300 EXPECT_EQ(touch_event->type, blink::WebInputEvent::TouchStart); 303 EXPECT_EQ(touch_event->type, blink::WebInputEvent::TouchStart);
301 position_ = gfx::Point(touch_event->touches[0].position); 304 position_ = gfx::Point(touch_event->touches[0].position);
305 start_time_ = base::TimeDelta::FromMilliseconds(
306 static_cast<int64>(touch_event->timeStampSeconds * 1000));
302 state_ = STARTED; 307 state_ = STARTED;
303 break; 308 break;
304 case STARTED: 309 case STARTED:
305 EXPECT_EQ(touch_event->type, blink::WebInputEvent::TouchEnd); 310 EXPECT_EQ(touch_event->type, blink::WebInputEvent::TouchEnd);
306 EXPECT_EQ(position_, gfx::Point(touch_event->touches[0].position)); 311 EXPECT_EQ(position_, gfx::Point(touch_event->touches[0].position));
312 stop_time_ = base::TimeDelta::FromMilliseconds(
313 static_cast<int64>(touch_event->timeStampSeconds * 1000));
307 state_ = FINISHED; 314 state_ = FINISHED;
308 break; 315 break;
309 case FINISHED: 316 case FINISHED:
310 EXPECT_FALSE(true); 317 EXPECT_FALSE(true);
311 break; 318 break;
312 } 319 }
313 } 320 }
314 }; 321 };
315 322
316 class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget { 323 class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget {
317 public: 324 public:
318 MockSyntheticTapMouseTarget() {} 325 MockSyntheticTapMouseTarget() {}
319 virtual ~MockSyntheticTapMouseTarget() {} 326 virtual ~MockSyntheticTapMouseTarget() {}
320 327
321 virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE { 328 virtual void DispatchInputEventToPlatform(const InputEvent& event) OVERRIDE {
322 const blink::WebInputEvent* web_event = event.web_event.get(); 329 const blink::WebInputEvent* web_event = event.web_event.get();
323 ASSERT_TRUE(blink::WebInputEvent::isMouseEventType(web_event->type)); 330 ASSERT_TRUE(blink::WebInputEvent::isMouseEventType(web_event->type));
324 const blink::WebMouseEvent* mouse_event = 331 const blink::WebMouseEvent* mouse_event =
325 static_cast<const blink::WebMouseEvent*>(web_event); 332 static_cast<const blink::WebMouseEvent*>(web_event);
326 333
327 switch (state_) { 334 switch (state_) {
328 case NOT_STARTED: 335 case NOT_STARTED:
329 EXPECT_EQ(mouse_event->type, blink::WebInputEvent::MouseDown); 336 EXPECT_EQ(mouse_event->type, blink::WebInputEvent::MouseDown);
330 EXPECT_EQ(mouse_event->button, blink::WebMouseEvent::ButtonLeft); 337 EXPECT_EQ(mouse_event->button, blink::WebMouseEvent::ButtonLeft);
331 EXPECT_EQ(mouse_event->clickCount, 1); 338 EXPECT_EQ(mouse_event->clickCount, 1);
332 position_ = gfx::Point(mouse_event->x, mouse_event->y); 339 position_ = gfx::Point(mouse_event->x, mouse_event->y);
340 start_time_ = base::TimeDelta::FromMilliseconds(
341 static_cast<int64>(mouse_event->timeStampSeconds * 1000));
333 state_ = STARTED; 342 state_ = STARTED;
334 break; 343 break;
335 case STARTED: 344 case STARTED:
336 EXPECT_EQ(mouse_event->type, blink::WebInputEvent::MouseUp); 345 EXPECT_EQ(mouse_event->type, blink::WebInputEvent::MouseUp);
337 EXPECT_EQ(mouse_event->button, blink::WebMouseEvent::ButtonLeft); 346 EXPECT_EQ(mouse_event->button, blink::WebMouseEvent::ButtonLeft);
338 EXPECT_EQ(mouse_event->clickCount, 1); 347 EXPECT_EQ(mouse_event->clickCount, 1);
339 EXPECT_EQ(position_, gfx::Point(mouse_event->x, mouse_event->y)); 348 EXPECT_EQ(position_, gfx::Point(mouse_event->x, mouse_event->y));
349 stop_time_ = base::TimeDelta::FromMilliseconds(
350 static_cast<int64>(mouse_event->timeStampSeconds * 1000));
340 state_ = FINISHED; 351 state_ = FINISHED;
341 break; 352 break;
342 case FINISHED: 353 case FINISHED:
343 EXPECT_FALSE(true); 354 EXPECT_FALSE(true);
344 break; 355 break;
345 } 356 }
346 } 357 }
347 }; 358 };
348 359
349 class SyntheticGestureControllerTest : public testing::Test { 360 class SyntheticGestureControllerTest : public testing::Test {
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 scoped_ptr<SyntheticTapGesture> gesture(new SyntheticTapGesture(params)); 787 scoped_ptr<SyntheticTapGesture> gesture(new SyntheticTapGesture(params));
777 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); 788 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
778 FlushInputUntilComplete(); 789 FlushInputUntilComplete();
779 790
780 MockSyntheticTapTouchTarget* tap_target = 791 MockSyntheticTapTouchTarget* tap_target =
781 static_cast<MockSyntheticTapTouchTarget*>(target_); 792 static_cast<MockSyntheticTapTouchTarget*>(target_);
782 EXPECT_EQ(1, target_->num_success()); 793 EXPECT_EQ(1, target_->num_success());
783 EXPECT_EQ(0, target_->num_failure()); 794 EXPECT_EQ(0, target_->num_failure());
784 EXPECT_TRUE(tap_target->GestureFinished()); 795 EXPECT_TRUE(tap_target->GestureFinished());
785 EXPECT_EQ(tap_target->position(), params.position); 796 EXPECT_EQ(tap_target->position(), params.position);
797 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms);
786 EXPECT_GE(GetTotalTime(), 798 EXPECT_GE(GetTotalTime(),
787 base::TimeDelta::FromMilliseconds(params.duration_ms)); 799 base::TimeDelta::FromMilliseconds(params.duration_ms));
788 } 800 }
789 801
790 TEST_F(SyntheticGestureControllerTest, TapGestureMouse) { 802 TEST_F(SyntheticGestureControllerTest, TapGestureMouse) {
791 CreateControllerAndTarget<MockSyntheticTapMouseTarget>(); 803 CreateControllerAndTarget<MockSyntheticTapMouseTarget>();
792 804
793 SyntheticTapGestureParams params; 805 SyntheticTapGestureParams params;
794 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT; 806 params.gesture_source_type = SyntheticGestureParams::MOUSE_INPUT;
795 params.duration_ms = 79; 807 params.duration_ms = 79;
796 params.position.SetPoint(98, 123); 808 params.position.SetPoint(98, 123);
797 809
798 scoped_ptr<SyntheticTapGesture> gesture(new SyntheticTapGesture(params)); 810 scoped_ptr<SyntheticTapGesture> gesture(new SyntheticTapGesture(params));
799 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>()); 811 controller_->QueueSyntheticGesture(gesture.PassAs<SyntheticGesture>());
800 FlushInputUntilComplete(); 812 FlushInputUntilComplete();
801 813
802 MockSyntheticTapMouseTarget* tap_target = 814 MockSyntheticTapMouseTarget* tap_target =
803 static_cast<MockSyntheticTapMouseTarget*>(target_); 815 static_cast<MockSyntheticTapMouseTarget*>(target_);
804 EXPECT_EQ(1, target_->num_success()); 816 EXPECT_EQ(1, target_->num_success());
805 EXPECT_EQ(0, target_->num_failure()); 817 EXPECT_EQ(0, target_->num_failure());
806 EXPECT_TRUE(tap_target->GestureFinished()); 818 EXPECT_TRUE(tap_target->GestureFinished());
807 EXPECT_EQ(tap_target->position(), params.position); 819 EXPECT_EQ(tap_target->position(), params.position);
820 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms);
808 EXPECT_GE(GetTotalTime(), 821 EXPECT_GE(GetTotalTime(),
809 base::TimeDelta::FromMilliseconds(params.duration_ms)); 822 base::TimeDelta::FromMilliseconds(params.duration_ms));
810 } 823 }
811 824
812 } // namespace 825 } // namespace
813 826
814 } // namespace content 827 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698