Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / events / gesture_detection / motion_event_generic_unittest.cc
blob5c5866a31c21a28a35ae32e54de3cfe211e5003d
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 "testing/gtest/include/gtest/gtest.h"
6 #include "ui/events/gesture_detection/motion_event_generic.h"
8 namespace ui {
10 TEST(MotionEventGenericTest, Basic) {
11 base::TimeTicks event_time = base::TimeTicks::Now();
12 MotionEventGeneric event(
13 MotionEvent::ACTION_DOWN, event_time, PointerProperties());
14 EXPECT_EQ(1U, event.GetPointerCount());
15 EXPECT_EQ(0U, event.GetHistorySize());
16 EXPECT_EQ(event_time, event.GetEventTime());
18 event.PushPointer(PointerProperties(8.3f, 4.7f));
19 ASSERT_EQ(2U, event.GetPointerCount());
20 EXPECT_EQ(8.3f, event.GetX(1));
21 EXPECT_EQ(4.7f, event.GetY(1));
23 event.PushPointer(PointerProperties(2.3f, -3.7f));
24 ASSERT_EQ(3U, event.GetPointerCount());
25 EXPECT_EQ(2.3f, event.GetX(2));
26 EXPECT_EQ(-3.7f, event.GetY(2));
28 event.set_id(1);
29 EXPECT_EQ(1, event.GetId());
31 event.set_action(MotionEvent::ACTION_POINTER_DOWN);
32 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction());
34 event_time += base::TimeDelta::FromMilliseconds(5);
35 event.set_event_time(event_time);
36 EXPECT_EQ(event_time, event.GetEventTime());
38 event.set_button_state(MotionEvent::BUTTON_PRIMARY);
39 EXPECT_EQ(MotionEvent::BUTTON_PRIMARY, event.GetButtonState());
41 event.set_action_index(1);
42 EXPECT_EQ(1, event.GetActionIndex());
45 TEST(MotionEventGenericTest, Clone) {
46 MotionEventGeneric event(MotionEvent::ACTION_DOWN,
47 base::TimeTicks::Now(),
48 PointerProperties(8.3f, 4.7f));
49 event.set_id(1);
50 event.set_button_state(MotionEvent::BUTTON_PRIMARY);
52 scoped_ptr<MotionEvent> clone = event.Clone();
53 ASSERT_TRUE(clone);
54 EXPECT_EQ(event, *clone);
57 TEST(MotionEventGenericTest, Cancel) {
58 MotionEventGeneric event(MotionEvent::ACTION_UP,
59 base::TimeTicks::Now(),
60 PointerProperties(8.7f, 4.3f));
61 event.set_id(2);
62 event.set_button_state(MotionEvent::BUTTON_SECONDARY);
64 scoped_ptr<MotionEvent> cancel = event.Cancel();
65 event.set_action(MotionEvent::ACTION_CANCEL);
66 ASSERT_TRUE(cancel);
67 EXPECT_EQ(event, *cancel);
70 TEST(MotionEventGenericTest, FindPointerIndexOfId) {
71 base::TimeTicks event_time = base::TimeTicks::Now();
72 PointerProperties pointer;
73 pointer.id = 0;
74 MotionEventGeneric event0(MotionEvent::ACTION_DOWN, event_time, pointer);
75 EXPECT_EQ(0, event0.FindPointerIndexOfId(0));
76 EXPECT_EQ(-1, event0.FindPointerIndexOfId(1));
77 EXPECT_EQ(-1, event0.FindPointerIndexOfId(-1));
79 MotionEventGeneric event1(event0);
80 pointer.id = 7;
81 event1.PushPointer(pointer);
82 EXPECT_EQ(0, event1.FindPointerIndexOfId(0));
83 EXPECT_EQ(1, event1.FindPointerIndexOfId(7));
84 EXPECT_EQ(-1, event1.FindPointerIndexOfId(6));
85 EXPECT_EQ(-1, event1.FindPointerIndexOfId(1));
87 MotionEventGeneric event2(event1);
88 pointer.id = 3;
89 event2.PushPointer(pointer);
90 EXPECT_EQ(0, event2.FindPointerIndexOfId(0));
91 EXPECT_EQ(1, event2.FindPointerIndexOfId(7));
92 EXPECT_EQ(2, event2.FindPointerIndexOfId(3));
93 EXPECT_EQ(-1, event2.FindPointerIndexOfId(1));
94 EXPECT_EQ(-1, event2.FindPointerIndexOfId(2));
97 } // namespace ui