Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / content / browser / renderer_host / input / motion_event_android_unittest.cc
blobf1c13308f38d688b2e5bd393a9f0996523da1f1d
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 "base/android/jni_android.h"
6 #include "content/browser/renderer_host/input/motion_event_android.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 using ui::MotionEvent;
11 namespace content {
12 namespace {
13 const float kPixToDip = 0.5f;
15 // Corresponds to ACTION_DOWN, see
16 // developer.android.com/reference/android/view/MotionEvent.html#ACTION_DOWN.
17 int kAndroidActionDown = 0;
19 // Corresponds to TOOL_TYPE_FINGER, see
20 // developer.android.com/reference/android/view/MotionEvent.html
21 // #TOOL_TYPE_FINGER.
22 int kAndroidToolTypeFinger = 1;
24 // Corresponds to BUTTON_PRIMARY, see
25 // developer.android.com/reference/android/view/MotionEvent.html#BUTTON_PRIMARY.
26 int kAndroidButtonPrimary = 1;
28 } // namespace
30 TEST(MotionEventAndroidTest, Constructor) {
31 int event_time_ms = 5;
32 base::TimeTicks event_time =
33 base::TimeTicks() + base::TimeDelta::FromMilliseconds(event_time_ms);
34 float x0 = 13.7;
35 float y0 = -7.13;
36 float x1 = -13.7;
37 float y1 = 7.13;
38 float raw_offset = 10.1f;
39 float touch_major0 = 5.3f;
40 float touch_major1 = 3.5f;
41 int p0 = 1;
42 int p1 = 2;
43 int pointer_count = 2;
44 int history_size = 0;
45 int action_index = -1;
46 base::android::ScopedJavaLocalRef<jobject> base_event_obj =
47 MotionEventAndroid::Obtain(
48 event_time, event_time, MotionEvent::ACTION_DOWN, x0, y0);
49 ASSERT_TRUE(base_event_obj.obj());
51 MotionEventAndroid event(kPixToDip,
52 base::android::AttachCurrentThread(),
53 base_event_obj.obj(),
54 event_time_ms,
55 kAndroidActionDown,
56 pointer_count,
57 history_size,
58 action_index,
59 x0,
60 y0,
61 x1,
62 y1,
63 p0,
64 p1,
65 touch_major0,
66 touch_major1,
67 x0 + raw_offset,
68 y0 - raw_offset,
69 kAndroidToolTypeFinger,
70 kAndroidToolTypeFinger,
71 kAndroidButtonPrimary);
73 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction());
74 EXPECT_EQ(event_time, event.GetEventTime());
75 EXPECT_EQ(x0 * kPixToDip, event.GetX(0));
76 EXPECT_EQ(y0 * kPixToDip, event.GetY(0));
77 EXPECT_EQ(x1 * kPixToDip, event.GetX(1));
78 EXPECT_EQ(y1 * kPixToDip, event.GetY(1));
79 EXPECT_FLOAT_EQ((x0 + raw_offset) * kPixToDip, event.GetRawX(0));
80 EXPECT_FLOAT_EQ((y0 - raw_offset) * kPixToDip, event.GetRawY(0));
81 EXPECT_FLOAT_EQ((x1 + raw_offset) * kPixToDip, event.GetRawX(1));
82 EXPECT_FLOAT_EQ((y1 - raw_offset) * kPixToDip, event.GetRawY(1));
83 EXPECT_EQ(touch_major0 * kPixToDip, event.GetTouchMajor(0));
84 EXPECT_EQ(touch_major1 * kPixToDip, event.GetTouchMajor(1));
85 EXPECT_EQ(p0, event.GetPointerId(0));
86 EXPECT_EQ(p1, event.GetPointerId(1));
87 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, event.GetToolType(0));
88 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, event.GetToolType(1));
89 EXPECT_EQ(MotionEvent::BUTTON_PRIMARY, event.GetButtonState());
90 EXPECT_EQ(static_cast<size_t>(pointer_count), event.GetPointerCount());
91 EXPECT_EQ(static_cast<size_t>(history_size), event.GetHistorySize());
92 EXPECT_EQ(action_index, event.GetActionIndex());
95 TEST(MotionEventAndroidTest, Clone) {
96 int event_time_ms = 5;
97 base::TimeTicks event_time =
98 base::TimeTicks() + base::TimeDelta::FromMilliseconds(event_time_ms);
99 float x = 13.7;
100 float y = -7.13;
101 float touch_major = 5.3f;
102 int pointer_count = 1;
103 int pointer_id = 1;
104 base::android::ScopedJavaLocalRef<jobject> event_obj =
105 MotionEventAndroid::Obtain(
106 event_time, event_time, MotionEvent::ACTION_DOWN, x, y);
107 ASSERT_TRUE(event_obj.obj());
109 MotionEventAndroid event(kPixToDip,
110 base::android::AttachCurrentThread(),
111 event_obj.obj(),
112 event_time_ms,
113 kAndroidActionDown,
114 pointer_count,
121 pointer_id,
123 touch_major,
124 0.f,
131 scoped_ptr<MotionEvent> clone = event.Clone();
132 EXPECT_EQ(event, *clone);
135 TEST(MotionEventAndroidTest, Cancel) {
136 int event_time_ms = 5;
137 base::TimeTicks event_time =
138 base::TimeTicks() + base::TimeDelta::FromMilliseconds(event_time_ms);
139 int pointer_count = 1;
140 float x = 13.7;
141 float y = -7.13;
142 base::android::ScopedJavaLocalRef<jobject> event_obj =
143 MotionEventAndroid::Obtain(
144 event_time, event_time, MotionEvent::ACTION_DOWN, x, y);
145 ASSERT_TRUE(event_obj.obj());
147 MotionEventAndroid event(kPixToDip,
148 base::android::AttachCurrentThread(),
149 event_obj.obj(),
150 event_time_ms,
151 kAndroidActionDown,
152 pointer_count,
161 0.f,
162 0.f,
169 scoped_ptr<MotionEvent> cancel_event = event.Cancel();
170 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel_event->GetAction());
171 EXPECT_EQ(event_time, cancel_event->GetEventTime());
172 EXPECT_EQ(x * kPixToDip, cancel_event->GetX(0));
173 EXPECT_EQ(y * kPixToDip, cancel_event->GetY(0));
174 EXPECT_EQ(static_cast<size_t>(pointer_count),
175 cancel_event->GetPointerCount());
176 EXPECT_EQ(0U, cancel_event->GetHistorySize());
179 } // namespace content