OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 <android/input.h> | 5 #include <android/input.h> |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "content/browser/renderer_host/input/motion_event_android.h" | 8 #include "content/browser/renderer_host/input/motion_event_android.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/events/event_constants.h" | 10 #include "ui/events/event_constants.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 // Note that these tests avoid creating a Java instance of the MotionEvent, as | 34 // Note that these tests avoid creating a Java instance of the MotionEvent, as |
35 // we're primarily testing caching behavior, and the code necessary to | 35 // we're primarily testing caching behavior, and the code necessary to |
36 // construct a Java-backed MotionEvent itself adds unnecessary complexity. | 36 // construct a Java-backed MotionEvent itself adds unnecessary complexity. |
37 TEST(MotionEventAndroidTest, Constructor) { | 37 TEST(MotionEventAndroidTest, Constructor) { |
38 int event_time_ms = 5; | 38 int event_time_ms = 5; |
39 base::TimeTicks event_time = | 39 base::TimeTicks event_time = |
40 base::TimeTicks() + base::TimeDelta::FromMilliseconds(event_time_ms); | 40 base::TimeTicks() + base::TimeDelta::FromMilliseconds(event_time_ms); |
41 MotionEventAndroid::Pointer p0( | 41 MotionEventAndroid::Pointer p0( |
42 1, 13.7f, -7.13f, 5.3f, 1.2f, 0.1f, kAndroidToolTypeFinger); | 42 1, 13.7f, -7.13f, 5.3f, 1.2f, 0.1f, 0.2f, kAndroidToolTypeFinger); |
43 MotionEventAndroid::Pointer p1( | 43 MotionEventAndroid::Pointer p1( |
44 2, -13.7f, 7.13f, 3.5f, 12.1f, -0.1f, kAndroidToolTypeFinger); | 44 2, -13.7f, 7.13f, 3.5f, 12.1f, -0.1f, -0.4f, kAndroidToolTypeFinger); |
45 float raw_offset = -3.f; | 45 float raw_offset = -3.f; |
46 int pointer_count = 2; | 46 int pointer_count = 2; |
47 int history_size = 0; | 47 int history_size = 0; |
48 int action_index = -1; | 48 int action_index = -1; |
49 MotionEventAndroid event(kPixToDip, | 49 MotionEventAndroid event(kPixToDip, |
50 base::android::AttachCurrentThread(), | 50 base::android::AttachCurrentThread(), |
51 nullptr, | 51 nullptr, |
52 event_time_ms, | 52 event_time_ms, |
53 kAndroidActionDown, | 53 kAndroidActionDown, |
54 pointer_count, | 54 pointer_count, |
(...skipping 15 matching lines...) Expand all Loading... |
70 EXPECT_FLOAT_EQ((p0.pos_x_pixels + raw_offset) * kPixToDip, event.GetRawX(0)); | 70 EXPECT_FLOAT_EQ((p0.pos_x_pixels + raw_offset) * kPixToDip, event.GetRawX(0)); |
71 EXPECT_FLOAT_EQ((p0.pos_y_pixels - raw_offset) * kPixToDip, event.GetRawY(0)); | 71 EXPECT_FLOAT_EQ((p0.pos_y_pixels - raw_offset) * kPixToDip, event.GetRawY(0)); |
72 EXPECT_FLOAT_EQ((p1.pos_x_pixels + raw_offset) * kPixToDip, event.GetRawX(1)); | 72 EXPECT_FLOAT_EQ((p1.pos_x_pixels + raw_offset) * kPixToDip, event.GetRawX(1)); |
73 EXPECT_FLOAT_EQ((p1.pos_y_pixels - raw_offset) * kPixToDip, event.GetRawY(1)); | 73 EXPECT_FLOAT_EQ((p1.pos_y_pixels - raw_offset) * kPixToDip, event.GetRawY(1)); |
74 EXPECT_EQ(p0.touch_major_pixels * kPixToDip, event.GetTouchMajor(0)); | 74 EXPECT_EQ(p0.touch_major_pixels * kPixToDip, event.GetTouchMajor(0)); |
75 EXPECT_EQ(p1.touch_major_pixels * kPixToDip, event.GetTouchMajor(1)); | 75 EXPECT_EQ(p1.touch_major_pixels * kPixToDip, event.GetTouchMajor(1)); |
76 EXPECT_EQ(p0.touch_minor_pixels * kPixToDip, event.GetTouchMinor(0)); | 76 EXPECT_EQ(p0.touch_minor_pixels * kPixToDip, event.GetTouchMinor(0)); |
77 EXPECT_EQ(p1.touch_minor_pixels * kPixToDip, event.GetTouchMinor(1)); | 77 EXPECT_EQ(p1.touch_minor_pixels * kPixToDip, event.GetTouchMinor(1)); |
78 EXPECT_EQ(p0.orientation_rad, event.GetOrientation(0)); | 78 EXPECT_EQ(p0.orientation_rad, event.GetOrientation(0)); |
79 EXPECT_EQ(p1.orientation_rad, event.GetOrientation(1)); | 79 EXPECT_EQ(p1.orientation_rad, event.GetOrientation(1)); |
| 80 EXPECT_EQ(p0.tilt_rad, event.GetTilt(0)); |
| 81 EXPECT_EQ(p1.tilt_rad, event.GetTilt(1)); |
80 EXPECT_EQ(p0.id, event.GetPointerId(0)); | 82 EXPECT_EQ(p0.id, event.GetPointerId(0)); |
81 EXPECT_EQ(p1.id, event.GetPointerId(1)); | 83 EXPECT_EQ(p1.id, event.GetPointerId(1)); |
82 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, event.GetToolType(0)); | 84 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, event.GetToolType(0)); |
83 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, event.GetToolType(1)); | 85 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, event.GetToolType(1)); |
84 EXPECT_EQ(MotionEvent::BUTTON_PRIMARY, event.GetButtonState()); | 86 EXPECT_EQ(MotionEvent::BUTTON_PRIMARY, event.GetButtonState()); |
85 EXPECT_EQ(ui::EF_ALT_DOWN, event.GetFlags()); | 87 EXPECT_EQ(ui::EF_ALT_DOWN, event.GetFlags()); |
86 EXPECT_EQ(static_cast<size_t>(pointer_count), event.GetPointerCount()); | 88 EXPECT_EQ(static_cast<size_t>(pointer_count), event.GetPointerCount()); |
87 EXPECT_EQ(static_cast<size_t>(history_size), event.GetHistorySize()); | 89 EXPECT_EQ(static_cast<size_t>(history_size), event.GetHistorySize()); |
88 } | 90 } |
89 | 91 |
90 TEST(MotionEventAndroidTest, Clone) { | 92 TEST(MotionEventAndroidTest, Clone) { |
91 const int pointer_count = 1; | 93 const int pointer_count = 1; |
92 MotionEventAndroid::Pointer p0( | 94 MotionEventAndroid::Pointer p0( |
93 1, 13.7f, -7.13f, 5.3f, 1.2f, 0.1f, kAndroidToolTypeFinger); | 95 1, 13.7f, -7.13f, 5.3f, 1.2f, 0.1f, 0.2f, kAndroidToolTypeFinger); |
94 MotionEventAndroid::Pointer p1(0, 0, 0, 0, 0, 0, 0); | 96 MotionEventAndroid::Pointer p1(0, 0, 0, 0, 0, 0, 0, 0); |
95 MotionEventAndroid event(kPixToDip, | 97 MotionEventAndroid event(kPixToDip, |
96 base::android::AttachCurrentThread(), | 98 base::android::AttachCurrentThread(), |
97 nullptr, | 99 nullptr, |
98 0, | 100 0, |
99 kAndroidActionDown, | 101 kAndroidActionDown, |
100 pointer_count, | 102 pointer_count, |
101 0, | 103 0, |
102 0, | 104 0, |
103 0, | 105 0, |
104 0, | 106 0, |
105 0, | 107 0, |
106 0, | 108 0, |
107 p0, | 109 p0, |
108 p1); | 110 p1); |
109 | 111 |
110 scoped_ptr<MotionEvent> clone = event.Clone(); | 112 scoped_ptr<MotionEvent> clone = event.Clone(); |
111 EXPECT_EQ(ui::test::ToString(event), ui::test::ToString(*clone)); | 113 EXPECT_EQ(ui::test::ToString(event), ui::test::ToString(*clone)); |
112 } | 114 } |
113 | 115 |
114 TEST(MotionEventAndroidTest, Cancel) { | 116 TEST(MotionEventAndroidTest, Cancel) { |
115 const int event_time_ms = 5; | 117 const int event_time_ms = 5; |
116 const int pointer_count = 1; | 118 const int pointer_count = 1; |
117 MotionEventAndroid::Pointer p0( | 119 MotionEventAndroid::Pointer p0( |
118 1, 13.7f, -7.13f, 5.3f, 1.2f, 0.1f, kAndroidToolTypeFinger); | 120 1, 13.7f, -7.13f, 5.3f, 1.2f, 0.1f, 0.2f, kAndroidToolTypeFinger); |
119 MotionEventAndroid::Pointer p1(0, 0, 0, 0, 0, 0, 0); | 121 MotionEventAndroid::Pointer p1(0, 0, 0, 0, 0, 0, 0, 0); |
120 MotionEventAndroid event(kPixToDip, | 122 MotionEventAndroid event(kPixToDip, |
121 base::android::AttachCurrentThread(), | 123 base::android::AttachCurrentThread(), |
122 nullptr, | 124 nullptr, |
123 event_time_ms, | 125 event_time_ms, |
124 kAndroidActionDown, | 126 kAndroidActionDown, |
125 pointer_count, | 127 pointer_count, |
126 0, | 128 0, |
127 0, | 129 0, |
128 0, | 130 0, |
129 0, | 131 0, |
(...skipping 11 matching lines...) Expand all Loading... |
141 EXPECT_EQ(p0.pos_y_pixels * kPixToDip, cancel_event->GetY(0)); | 143 EXPECT_EQ(p0.pos_y_pixels * kPixToDip, cancel_event->GetY(0)); |
142 EXPECT_EQ(static_cast<size_t>(pointer_count), | 144 EXPECT_EQ(static_cast<size_t>(pointer_count), |
143 cancel_event->GetPointerCount()); | 145 cancel_event->GetPointerCount()); |
144 EXPECT_EQ(0U, cancel_event->GetHistorySize()); | 146 EXPECT_EQ(0U, cancel_event->GetHistorySize()); |
145 } | 147 } |
146 | 148 |
147 TEST(MotionEventAndroidTest, InvalidOrientationsSanitized) { | 149 TEST(MotionEventAndroidTest, InvalidOrientationsSanitized) { |
148 int pointer_count = 2; | 150 int pointer_count = 2; |
149 float orientation0 = 1e10f; | 151 float orientation0 = 1e10f; |
150 float orientation1 = std::numeric_limits<float>::quiet_NaN(); | 152 float orientation1 = std::numeric_limits<float>::quiet_NaN(); |
151 MotionEventAndroid::Pointer p0(0, 0, 0, 0, 0, orientation0, 0); | 153 MotionEventAndroid::Pointer p0(0, 0, 0, 0, 0, orientation0, 0, 0); |
152 MotionEventAndroid::Pointer p1(1, 0, 0, 0, 0, orientation1, 0); | 154 MotionEventAndroid::Pointer p1(1, 0, 0, 0, 0, orientation1, 0, 0); |
153 MotionEventAndroid event(kPixToDip, | 155 MotionEventAndroid event(kPixToDip, |
154 base::android::AttachCurrentThread(), | 156 base::android::AttachCurrentThread(), |
155 nullptr, | 157 nullptr, |
156 0, | 158 0, |
157 kAndroidActionDown, | 159 kAndroidActionDown, |
158 pointer_count, | 160 pointer_count, |
159 0, | 161 0, |
160 0, | 162 0, |
161 0, | 163 0, |
162 0, | 164 0, |
163 0, | 165 0, |
164 0, | 166 0, |
165 p0, | 167 p0, |
166 p1); | 168 p1); |
167 | 169 |
168 EXPECT_EQ(0.f, event.GetOrientation(0)); | 170 EXPECT_EQ(0.f, event.GetOrientation(0)); |
169 EXPECT_EQ(0.f, event.GetOrientation(1)); | 171 EXPECT_EQ(0.f, event.GetOrientation(1)); |
170 } | 172 } |
171 | 173 |
172 TEST(MotionEventAndroidTest, NonEmptyHistoryForNonMoveEventsSanitized) { | 174 TEST(MotionEventAndroidTest, NonEmptyHistoryForNonMoveEventsSanitized) { |
173 int pointer_count = 1; | 175 int pointer_count = 1; |
174 size_t history_size = 5; | 176 size_t history_size = 5; |
175 MotionEventAndroid::Pointer p0(0, 0, 0, 0, 0, 0, 0); | 177 MotionEventAndroid::Pointer p0(0, 0, 0, 0, 0, 0, 0, 0); |
176 MotionEventAndroid::Pointer p1(0, 0, 0, 0, 0, 0, 0); | 178 MotionEventAndroid::Pointer p1(0, 0, 0, 0, 0, 0, 0, 0); |
177 MotionEventAndroid event(kPixToDip, | 179 MotionEventAndroid event(kPixToDip, |
178 base::android::AttachCurrentThread(), | 180 base::android::AttachCurrentThread(), |
179 nullptr, | 181 nullptr, |
180 0, | 182 0, |
181 kAndroidActionDown, | 183 kAndroidActionDown, |
182 pointer_count, | 184 pointer_count, |
183 history_size, | 185 history_size, |
184 0, | 186 0, |
185 0, | 187 0, |
186 0, | 188 0, |
187 0, | 189 0, |
188 0, | 190 0, |
189 p0, | 191 p0, |
190 p1); | 192 p1); |
191 | 193 |
192 EXPECT_EQ(0U, event.GetHistorySize()); | 194 EXPECT_EQ(0U, event.GetHistorySize()); |
193 } | 195 } |
194 | 196 |
195 TEST(MotionEventAndroidTest, ActionIndexForPointerDown) { | 197 TEST(MotionEventAndroidTest, ActionIndexForPointerDown) { |
196 MotionEventAndroid::Pointer p0( | 198 MotionEventAndroid::Pointer p0( |
197 1, 13.7f, -7.13f, 5.3f, 1.2f, 0.1f, kAndroidToolTypeFinger); | 199 1, 13.7f, -7.13f, 5.3f, 1.2f, 0.1f, 0.2f, kAndroidToolTypeFinger); |
198 MotionEventAndroid::Pointer p1( | 200 MotionEventAndroid::Pointer p1( |
199 2, -13.7f, 7.13f, 3.5f, 12.1f, -0.1f, kAndroidToolTypeFinger); | 201 2, -13.7f, 7.13f, 3.5f, 12.1f, -0.1f, -0.4f, kAndroidToolTypeFinger); |
200 int pointer_count = 2; | 202 int pointer_count = 2; |
201 int history_size = 0; | 203 int history_size = 0; |
202 int action_index = 1; | 204 int action_index = 1; |
203 MotionEventAndroid event(kPixToDip, | 205 MotionEventAndroid event(kPixToDip, |
204 base::android::AttachCurrentThread(), | 206 base::android::AttachCurrentThread(), |
205 nullptr, | 207 nullptr, |
206 0, | 208 0, |
207 kAndroidActionPointerDown, | 209 kAndroidActionPointerDown, |
208 pointer_count, | 210 pointer_count, |
209 history_size, | 211 history_size, |
210 action_index, | 212 action_index, |
211 0, | 213 0, |
212 0, | 214 0, |
213 0, | 215 0, |
214 0, | 216 0, |
215 p0, | 217 p0, |
216 p1); | 218 p1); |
217 | 219 |
218 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); | 220 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); |
219 EXPECT_EQ(action_index, event.GetActionIndex()); | 221 EXPECT_EQ(action_index, event.GetActionIndex()); |
220 } | 222 } |
221 | 223 |
222 } // namespace content | 224 } // namespace content |
OLD | NEW |