| 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
| 12 #include "ui/events/gestures/motion_event_impl.h" | 12 #include "ui/events/gestures/motion_event_aura.h" |
| 13 #include "ui/events/test/motion_event_test_utils.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 ui::TouchEvent TouchWithType(ui::EventType type, int id) { | 17 ui::TouchEvent TouchWithType(ui::EventType type, int id) { |
| 17 return ui::TouchEvent( | 18 return ui::TouchEvent( |
| 18 type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(0)); | 19 type, gfx::PointF(0, 0), id, base::TimeDelta::FromMilliseconds(0)); |
| 19 } | 20 } |
| 20 | 21 |
| 21 ui::TouchEvent TouchWithPosition(ui::EventType type, | 22 ui::TouchEvent TouchWithPosition(ui::EventType type, |
| 22 int id, | 23 int id, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 63 } |
| 63 | 64 |
| 64 base::TimeTicks MsToTicks(int ms) { | 65 base::TimeTicks MsToTicks(int ms) { |
| 65 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); | 66 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); |
| 66 } | 67 } |
| 67 | 68 |
| 68 } // namespace | 69 } // namespace |
| 69 | 70 |
| 70 namespace ui { | 71 namespace ui { |
| 71 | 72 |
| 72 TEST(MotionEventImplTest, PointerCountAndIds) { | 73 TEST(MotionEventAuraTest, PointerCountAndIds) { |
| 73 // Test that |PointerCount()| returns the correct number of pointers, and ids | 74 // Test that |PointerCount()| returns the correct number of pointers, and ids |
| 74 // are assigned correctly. | 75 // are assigned correctly. |
| 75 int ids[] = {4, 6, 1}; | 76 int ids[] = {4, 6, 1}; |
| 76 | 77 |
| 77 MotionEventImpl event; | 78 MotionEventAura event; |
| 78 EXPECT_EQ(0U, event.GetPointerCount()); | 79 EXPECT_EQ(0U, event.GetPointerCount()); |
| 79 | 80 |
| 80 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 81 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
| 81 event.OnTouch(press0); | 82 EXPECT_TRUE(event.OnTouch(press0)); |
| 82 EXPECT_EQ(1U, event.GetPointerCount()); | 83 EXPECT_EQ(1U, event.GetPointerCount()); |
| 83 | 84 |
| 84 EXPECT_EQ(ids[0], event.GetPointerId(0)); | 85 EXPECT_EQ(ids[0], event.GetPointerId(0)); |
| 85 | 86 |
| 86 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 87 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
| 87 event.OnTouch(press1); | 88 EXPECT_TRUE(event.OnTouch(press1)); |
| 88 EXPECT_EQ(2U, event.GetPointerCount()); | 89 EXPECT_EQ(2U, event.GetPointerCount()); |
| 89 | 90 |
| 90 EXPECT_EQ(ids[0], event.GetPointerId(0)); | 91 EXPECT_EQ(ids[0], event.GetPointerId(0)); |
| 91 EXPECT_EQ(ids[1], event.GetPointerId(1)); | 92 EXPECT_EQ(ids[1], event.GetPointerId(1)); |
| 92 | 93 |
| 93 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]); | 94 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]); |
| 94 event.OnTouch(press2); | 95 EXPECT_TRUE(event.OnTouch(press2)); |
| 95 EXPECT_EQ(3U, event.GetPointerCount()); | 96 EXPECT_EQ(3U, event.GetPointerCount()); |
| 96 | 97 |
| 97 EXPECT_EQ(ids[0], event.GetPointerId(0)); | 98 EXPECT_EQ(ids[0], event.GetPointerId(0)); |
| 98 EXPECT_EQ(ids[1], event.GetPointerId(1)); | 99 EXPECT_EQ(ids[1], event.GetPointerId(1)); |
| 99 EXPECT_EQ(ids[2], event.GetPointerId(2)); | 100 EXPECT_EQ(ids[2], event.GetPointerId(2)); |
| 100 | 101 |
| 101 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); | 102 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); |
| 102 event.OnTouch(release1); | 103 EXPECT_TRUE(event.OnTouch(release1)); |
| 103 event.CleanupRemovedTouchPoints(release1); | 104 event.CleanupRemovedTouchPoints(release1); |
| 104 EXPECT_EQ(2U, event.GetPointerCount()); | 105 EXPECT_EQ(2U, event.GetPointerCount()); |
| 105 | 106 |
| 106 EXPECT_EQ(ids[0], event.GetPointerId(0)); | 107 EXPECT_EQ(ids[0], event.GetPointerId(0)); |
| 107 EXPECT_EQ(ids[2], event.GetPointerId(1)); | 108 EXPECT_EQ(ids[2], event.GetPointerId(1)); |
| 108 | 109 |
| 109 // Test cloning of pointer count and id information. | 110 // Test cloning of pointer count and id information. |
| 110 // TODO(mustaq): Make a separate clone test | 111 // TODO(mustaq): Make a separate clone test, crbug.com/450655 |
| 111 scoped_ptr<MotionEvent> clone = event.Clone(); | 112 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 112 EXPECT_EQ(2U, clone->GetPointerCount()); | 113 EXPECT_EQ(2U, clone->GetPointerCount()); |
| 113 EXPECT_EQ(ids[0], clone->GetPointerId(0)); | 114 EXPECT_EQ(ids[0], clone->GetPointerId(0)); |
| 114 EXPECT_EQ(ids[2], clone->GetPointerId(1)); | 115 EXPECT_EQ(ids[2], clone->GetPointerId(1)); |
| 116 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); |
| 117 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
| 115 | 118 |
| 116 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 119 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
| 117 event.OnTouch(release0); | 120 EXPECT_TRUE(event.OnTouch(release0)); |
| 118 event.CleanupRemovedTouchPoints(release0); | 121 event.CleanupRemovedTouchPoints(release0); |
| 119 EXPECT_EQ(1U, event.GetPointerCount()); | 122 EXPECT_EQ(1U, event.GetPointerCount()); |
| 120 | 123 |
| 121 EXPECT_EQ(ids[2], event.GetPointerId(0)); | 124 EXPECT_EQ(ids[2], event.GetPointerId(0)); |
| 122 | 125 |
| 123 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); | 126 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); |
| 124 event.OnTouch(release2); | 127 EXPECT_TRUE(event.OnTouch(release2)); |
| 125 event.CleanupRemovedTouchPoints(release2); | 128 event.CleanupRemovedTouchPoints(release2); |
| 126 EXPECT_EQ(0U, event.GetPointerCount()); | 129 EXPECT_EQ(0U, event.GetPointerCount()); |
| 127 } | 130 } |
| 128 | 131 |
| 129 TEST(MotionEventImplTest, GetActionIndexAfterRemoval) { | 132 TEST(MotionEventAuraTest, GetActionIndexAfterRemoval) { |
| 130 // Test that |GetActionIndex()| returns the correct index when points have | 133 // Test that |GetActionIndex()| returns the correct index when points have |
| 131 // been removed. | 134 // been removed. |
| 132 int ids[] = {4, 6, 9}; | 135 int ids[] = {4, 6, 9}; |
| 133 | 136 |
| 134 MotionEventImpl event; | 137 MotionEventAura event; |
| 135 EXPECT_EQ(0U, event.GetPointerCount()); | 138 EXPECT_EQ(0U, event.GetPointerCount()); |
| 136 | 139 |
| 137 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 140 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
| 138 event.OnTouch(press0); | 141 EXPECT_TRUE(event.OnTouch(press0)); |
| 139 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 142 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
| 140 event.OnTouch(press1); | 143 EXPECT_TRUE(event.OnTouch(press1)); |
| 144 EXPECT_EQ(1, event.GetActionIndex()); |
| 141 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]); | 145 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]); |
| 142 event.OnTouch(press2); | 146 EXPECT_TRUE(event.OnTouch(press2)); |
| 147 EXPECT_EQ(2, event.GetActionIndex()); |
| 143 EXPECT_EQ(3U, event.GetPointerCount()); | 148 EXPECT_EQ(3U, event.GetPointerCount()); |
| 144 | 149 |
| 145 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); | 150 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); |
| 146 event.OnTouch(release1); | 151 EXPECT_TRUE(event.OnTouch(release1)); |
| 152 EXPECT_EQ(1, event.GetActionIndex()); |
| 147 event.CleanupRemovedTouchPoints(release1); | 153 event.CleanupRemovedTouchPoints(release1); |
| 148 EXPECT_EQ(1, event.GetActionIndex()); | |
| 149 EXPECT_EQ(2U, event.GetPointerCount()); | 154 EXPECT_EQ(2U, event.GetPointerCount()); |
| 150 | 155 |
| 151 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 156 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
| 152 event.OnTouch(release2); | 157 EXPECT_TRUE(event.OnTouch(release2)); |
| 158 EXPECT_EQ(0, event.GetActionIndex()); |
| 153 event.CleanupRemovedTouchPoints(release2); | 159 event.CleanupRemovedTouchPoints(release2); |
| 154 EXPECT_EQ(0, event.GetActionIndex()); | |
| 155 EXPECT_EQ(1U, event.GetPointerCount()); | 160 EXPECT_EQ(1U, event.GetPointerCount()); |
| 156 | 161 |
| 157 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); | 162 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); |
| 158 event.OnTouch(release0); | 163 EXPECT_TRUE(event.OnTouch(release0)); |
| 159 event.CleanupRemovedTouchPoints(release0); | 164 event.CleanupRemovedTouchPoints(release0); |
| 160 EXPECT_EQ(0U, event.GetPointerCount()); | 165 EXPECT_EQ(0U, event.GetPointerCount()); |
| 161 } | 166 } |
| 162 | 167 |
| 163 TEST(MotionEventImplTest, PointerLocations) { | 168 TEST(MotionEventAuraTest, PointerLocations) { |
| 164 // Test that location information is stored correctly. | 169 // Test that location information is stored correctly. |
| 165 MotionEventImpl event; | 170 MotionEventAura event; |
| 166 | 171 |
| 167 const float kRawOffsetX = 11.1f; | 172 const float kRawOffsetX = 11.1f; |
| 168 const float kRawOffsetY = 13.3f; | 173 const float kRawOffsetY = 13.3f; |
| 169 | 174 |
| 170 int ids[] = {15, 13}; | 175 int ids[] = {15, 13}; |
| 171 float x; | 176 float x; |
| 172 float y; | 177 float y; |
| 173 float raw_x; | 178 float raw_x; |
| 174 float raw_y; | 179 float raw_y; |
| 175 | 180 |
| 176 x = 14.4f; | 181 x = 14.4f; |
| 177 y = 17.3f; | 182 y = 17.3f; |
| 178 raw_x = x + kRawOffsetX; | 183 raw_x = x + kRawOffsetX; |
| 179 raw_y = y + kRawOffsetY; | 184 raw_y = y + kRawOffsetY; |
| 180 TouchEvent press0 = | 185 TouchEvent press0 = |
| 181 TouchWithPosition(ET_TOUCH_PRESSED, ids[0], x, y, raw_x, raw_y); | 186 TouchWithPosition(ET_TOUCH_PRESSED, ids[0], x, y, raw_x, raw_y); |
| 182 event.OnTouch(press0); | 187 EXPECT_TRUE(event.OnTouch(press0)); |
| 183 | 188 |
| 184 EXPECT_EQ(1U, event.GetPointerCount()); | 189 EXPECT_EQ(1U, event.GetPointerCount()); |
| 185 EXPECT_FLOAT_EQ(x, event.GetX(0)); | 190 EXPECT_FLOAT_EQ(x, event.GetX(0)); |
| 186 EXPECT_FLOAT_EQ(y, event.GetY(0)); | 191 EXPECT_FLOAT_EQ(y, event.GetY(0)); |
| 187 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0)); | 192 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0)); |
| 188 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0)); | 193 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0)); |
| 189 | 194 |
| 190 x = 17.8f; | 195 x = 17.8f; |
| 191 y = 12.1f; | 196 y = 12.1f; |
| 192 raw_x = x + kRawOffsetX; | 197 raw_x = x + kRawOffsetX; |
| 193 raw_y = y + kRawOffsetY; | 198 raw_y = y + kRawOffsetY; |
| 194 TouchEvent press1 = | 199 TouchEvent press1 = |
| 195 TouchWithPosition(ET_TOUCH_PRESSED, ids[1], x, y, raw_x, raw_y); | 200 TouchWithPosition(ET_TOUCH_PRESSED, ids[1], x, y, raw_x, raw_y); |
| 196 event.OnTouch(press1); | 201 EXPECT_TRUE(event.OnTouch(press1)); |
| 197 | 202 |
| 198 EXPECT_EQ(2U, event.GetPointerCount()); | 203 EXPECT_EQ(2U, event.GetPointerCount()); |
| 199 EXPECT_FLOAT_EQ(x, event.GetX(1)); | 204 EXPECT_FLOAT_EQ(x, event.GetX(1)); |
| 200 EXPECT_FLOAT_EQ(y, event.GetY(1)); | 205 EXPECT_FLOAT_EQ(y, event.GetY(1)); |
| 201 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); | 206 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); |
| 202 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); | 207 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); |
| 203 | 208 |
| 204 // Test cloning of pointer location information. | 209 // Test cloning of pointer location information. |
| 205 scoped_ptr<MotionEvent> clone = event.Clone(); | 210 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 206 { | 211 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); |
| 207 const MotionEventImpl* raw_clone_aura = | 212 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
| 208 static_cast<MotionEventImpl*>(clone.get()); | 213 EXPECT_EQ(2U, clone->GetPointerCount()); |
| 209 EXPECT_EQ(2U, raw_clone_aura->GetPointerCount()); | 214 EXPECT_FLOAT_EQ(x, clone->GetX(1)); |
| 210 EXPECT_FLOAT_EQ(x, raw_clone_aura->GetX(1)); | 215 EXPECT_FLOAT_EQ(y, clone->GetY(1)); |
| 211 EXPECT_FLOAT_EQ(y, raw_clone_aura->GetY(1)); | 216 EXPECT_FLOAT_EQ(raw_x, clone->GetRawX(1)); |
| 212 EXPECT_FLOAT_EQ(raw_x, raw_clone_aura->GetRawX(1)); | 217 EXPECT_FLOAT_EQ(raw_y, clone->GetRawY(1)); |
| 213 EXPECT_FLOAT_EQ(raw_y, raw_clone_aura->GetRawY(1)); | |
| 214 } | |
| 215 | 218 |
| 216 x = 27.9f; | 219 x = 27.9f; |
| 217 y = 22.3f; | 220 y = 22.3f; |
| 218 raw_x = x + kRawOffsetX; | 221 raw_x = x + kRawOffsetX; |
| 219 raw_y = y + kRawOffsetY; | 222 raw_y = y + kRawOffsetY; |
| 220 TouchEvent move1 = | 223 TouchEvent move1 = |
| 221 TouchWithPosition(ET_TOUCH_MOVED, ids[1], x, y, raw_x, raw_y); | 224 TouchWithPosition(ET_TOUCH_MOVED, ids[1], x, y, raw_x, raw_y); |
| 222 event.OnTouch(move1); | 225 EXPECT_TRUE(event.OnTouch(move1)); |
| 223 | 226 |
| 224 EXPECT_FLOAT_EQ(x, event.GetX(1)); | 227 EXPECT_FLOAT_EQ(x, event.GetX(1)); |
| 225 EXPECT_FLOAT_EQ(y, event.GetY(1)); | 228 EXPECT_FLOAT_EQ(y, event.GetY(1)); |
| 226 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); | 229 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); |
| 227 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); | 230 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); |
| 228 | 231 |
| 229 x = 34.6f; | 232 x = 34.6f; |
| 230 y = 23.8f; | 233 y = 23.8f; |
| 231 raw_x = x + kRawOffsetX; | 234 raw_x = x + kRawOffsetX; |
| 232 raw_y = y + kRawOffsetY; | 235 raw_y = y + kRawOffsetY; |
| 233 TouchEvent move0 = | 236 TouchEvent move0 = |
| 234 TouchWithPosition(ET_TOUCH_MOVED, ids[0], x, y, raw_x, raw_y); | 237 TouchWithPosition(ET_TOUCH_MOVED, ids[0], x, y, raw_x, raw_y); |
| 235 event.OnTouch(move0); | 238 EXPECT_TRUE(event.OnTouch(move0)); |
| 236 | 239 |
| 237 EXPECT_FLOAT_EQ(x, event.GetX(0)); | 240 EXPECT_FLOAT_EQ(x, event.GetX(0)); |
| 238 EXPECT_FLOAT_EQ(y, event.GetY(0)); | 241 EXPECT_FLOAT_EQ(y, event.GetY(0)); |
| 239 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0)); | 242 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(0)); |
| 240 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0)); | 243 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(0)); |
| 241 } | 244 } |
| 242 | 245 |
| 243 TEST(MotionEventImplTest, TapParams) { | 246 TEST(MotionEventAuraTest, TapParams) { |
| 244 // Test that touch params are stored correctly. | 247 // Test that touch params are stored correctly. |
| 245 MotionEventImpl event; | 248 MotionEventAura event; |
| 246 | 249 |
| 247 int ids[] = {15, 13}; | 250 int ids[] = {15, 13, 25, 23}; |
| 248 | 251 |
| 249 float radius_x; | 252 float radius_x; |
| 250 float radius_y; | 253 float radius_y; |
| 251 float rotation_angle; | 254 float rotation_angle; |
| 252 float pressure; | 255 float pressure; |
| 253 | 256 |
| 257 // Test case: radius_x > radius_y, rotation_angle < 90 |
| 254 radius_x = 123.45f; | 258 radius_x = 123.45f; |
| 255 radius_y = 67.89f; | 259 radius_y = 67.89f; |
| 256 rotation_angle = 23.f; | 260 rotation_angle = 23.f; |
| 257 pressure = 0.123f; | 261 pressure = 0.123f; |
| 258 TouchEvent press0 = TouchWithTapParams( | 262 TouchEvent press0 = TouchWithTapParams( |
| 259 ET_TOUCH_PRESSED, ids[0], radius_x, radius_y, rotation_angle, pressure); | 263 ET_TOUCH_PRESSED, ids[0], radius_x, radius_y, rotation_angle, pressure); |
| 260 event.OnTouch(press0); | 264 EXPECT_TRUE(event.OnTouch(press0)); |
| 261 | 265 |
| 262 EXPECT_EQ(1U, event.GetPointerCount()); | 266 EXPECT_EQ(1U, event.GetPointerCount()); |
| 263 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMajor(0) / 2); | 267 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMajor(0) / 2); |
| 264 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMinor(0) / 2); | 268 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMinor(0) / 2); |
| 265 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(0) * 180 / M_PI + 90); | 269 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(0) * 180 / M_PI + 90); |
| 266 EXPECT_FLOAT_EQ(pressure, event.GetPressure(0)); | 270 EXPECT_FLOAT_EQ(pressure, event.GetPressure(0)); |
| 267 | 271 |
| 272 // Test case: radius_x < radius_y, rotation_angle < 90 |
| 268 radius_x = 67.89f; | 273 radius_x = 67.89f; |
| 269 radius_y = 123.45f; | 274 radius_y = 123.45f; |
| 270 rotation_angle = 46.f; | 275 rotation_angle = 46.f; |
| 271 pressure = 0.456f; | 276 pressure = 0.456f; |
| 272 TouchEvent press1 = TouchWithTapParams( | 277 TouchEvent press1 = TouchWithTapParams( |
| 273 ET_TOUCH_PRESSED, ids[1], radius_x, radius_y, rotation_angle, pressure); | 278 ET_TOUCH_PRESSED, ids[1], radius_x, radius_y, rotation_angle, pressure); |
| 274 event.OnTouch(press1); | 279 EXPECT_TRUE(event.OnTouch(press1)); |
| 275 | 280 |
| 276 EXPECT_EQ(2U, event.GetPointerCount()); | 281 EXPECT_EQ(2U, event.GetPointerCount()); |
| 277 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); | 282 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); |
| 278 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); | 283 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); |
| 279 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); | 284 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); |
| 280 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); | 285 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); |
| 281 | 286 |
| 282 // Test cloning of tap params | 287 // Test cloning of tap params |
| 288 // TODO(mustaq): Make a separate clone test, crbug.com/450655 |
| 283 scoped_ptr<MotionEvent> clone = event.Clone(); | 289 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 284 { | 290 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); |
| 285 const MotionEventImpl* raw_clone_aura = | 291 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
| 286 static_cast<MotionEventImpl*>(clone.get()); | 292 EXPECT_EQ(2U, clone->GetPointerCount()); |
| 287 EXPECT_EQ(2U, raw_clone_aura->GetPointerCount()); | 293 EXPECT_FLOAT_EQ(radius_y, clone->GetTouchMajor(1) / 2); |
| 288 EXPECT_FLOAT_EQ(radius_y, raw_clone_aura->GetTouchMajor(1) / 2); | 294 EXPECT_FLOAT_EQ(radius_x, clone->GetTouchMinor(1) / 2); |
| 289 EXPECT_FLOAT_EQ(radius_x, raw_clone_aura->GetTouchMinor(1) / 2); | 295 EXPECT_FLOAT_EQ(rotation_angle, clone->GetOrientation(1) * 180 / M_PI); |
| 290 EXPECT_FLOAT_EQ( | 296 EXPECT_FLOAT_EQ(pressure, clone->GetPressure(1)); |
| 291 rotation_angle, raw_clone_aura->GetOrientation(1) * 180 / M_PI); | |
| 292 EXPECT_FLOAT_EQ(pressure, raw_clone_aura->GetPressure(1)); | |
| 293 } | |
| 294 | 297 |
| 298 // TODO(mustaq): The move test seems out-of-scope here, crbug.com/450655 |
| 295 radius_x = 76.98f; | 299 radius_x = 76.98f; |
| 296 radius_y = 321.54f; | 300 radius_y = 321.54f; |
| 297 rotation_angle = 64.f; | 301 rotation_angle = 64.f; |
| 298 pressure = 0.654f; | 302 pressure = 0.654f; |
| 299 TouchEvent move1 = TouchWithTapParams( | 303 TouchEvent move1 = TouchWithTapParams( |
| 300 ET_TOUCH_MOVED, ids[1], radius_x, radius_y, rotation_angle, pressure); | 304 ET_TOUCH_MOVED, ids[1], radius_x, radius_y, rotation_angle, pressure); |
| 301 event.OnTouch(move1); | 305 move1.set_location(gfx::Point(20, 21)); |
| 306 EXPECT_TRUE(event.OnTouch(move1)); |
| 302 | 307 |
| 303 EXPECT_EQ(2U, event.GetPointerCount()); | 308 EXPECT_EQ(2U, event.GetPointerCount()); |
| 304 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); | 309 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); |
| 305 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); | 310 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); |
| 306 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); | 311 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); |
| 307 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); | 312 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); |
| 313 |
| 314 // Test case: radius_x > radius_y, rotation_angle > 90 |
| 315 radius_x = 123.45f; |
| 316 radius_y = 67.89f; |
| 317 rotation_angle = 92.f; |
| 318 pressure = 0.789f; |
| 319 TouchEvent press2 = TouchWithTapParams( |
| 320 ET_TOUCH_PRESSED, ids[2], radius_x, radius_y, rotation_angle, pressure); |
| 321 EXPECT_TRUE(event.OnTouch(press2)); |
| 322 |
| 323 EXPECT_EQ(3U, event.GetPointerCount()); |
| 324 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMajor(2) / 2); |
| 325 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMinor(2) / 2); |
| 326 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(2) * 180 / M_PI + 90); |
| 327 EXPECT_FLOAT_EQ(pressure, event.GetPressure(2)); |
| 328 |
| 329 // Test case: radius_x < radius_y, rotation_angle > 90 |
| 330 radius_x = 67.89f; |
| 331 radius_y = 123.45f; |
| 332 rotation_angle = 135.f; |
| 333 pressure = 0.012f; |
| 334 TouchEvent press3 = TouchWithTapParams( |
| 335 ET_TOUCH_PRESSED, ids[3], radius_x, radius_y, rotation_angle, pressure); |
| 336 EXPECT_TRUE(event.OnTouch(press3)); |
| 337 |
| 338 EXPECT_EQ(4U, event.GetPointerCount()); |
| 339 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(3) / 2); |
| 340 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(3) / 2); |
| 341 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(3) * 180 / M_PI + 180); |
| 342 EXPECT_FLOAT_EQ(pressure, event.GetPressure(3)); |
| 308 } | 343 } |
| 309 | 344 |
| 310 TEST(MotionEventImplTest, Timestamps) { | 345 TEST(MotionEventAuraTest, Timestamps) { |
| 311 // Test that timestamp information is stored and converted correctly. | 346 // Test that timestamp information is stored and converted correctly. |
| 312 MotionEventImpl event; | 347 MotionEventAura event; |
| 313 int ids[] = {7, 13}; | 348 int ids[] = {7, 13}; |
| 314 int times_in_ms[] = {59436, 60263, 82175}; | 349 int times_in_ms[] = {59436, 60263, 82175}; |
| 315 | 350 |
| 316 TouchEvent press0 = TouchWithTime( | 351 TouchEvent press0 = TouchWithTime( |
| 317 ui::ET_TOUCH_PRESSED, ids[0], times_in_ms[0]); | 352 ui::ET_TOUCH_PRESSED, ids[0], times_in_ms[0]); |
| 318 event.OnTouch(press0); | 353 EXPECT_TRUE(event.OnTouch(press0)); |
| 319 EXPECT_EQ(MsToTicks(times_in_ms[0]), event.GetEventTime()); | 354 EXPECT_EQ(MsToTicks(times_in_ms[0]), event.GetEventTime()); |
| 320 | 355 |
| 321 TouchEvent press1 = TouchWithTime( | 356 TouchEvent press1 = TouchWithTime( |
| 322 ui::ET_TOUCH_PRESSED, ids[1], times_in_ms[1]); | 357 ui::ET_TOUCH_PRESSED, ids[1], times_in_ms[1]); |
| 323 event.OnTouch(press1); | 358 EXPECT_TRUE(event.OnTouch(press1)); |
| 324 EXPECT_EQ(MsToTicks(times_in_ms[1]), event.GetEventTime()); | 359 EXPECT_EQ(MsToTicks(times_in_ms[1]), event.GetEventTime()); |
| 325 | 360 |
| 326 TouchEvent move0 = TouchWithTime( | 361 TouchEvent move0 = TouchWithTime( |
| 327 ui::ET_TOUCH_MOVED, ids[0], times_in_ms[2]); | 362 ui::ET_TOUCH_MOVED, ids[0], times_in_ms[2]); |
| 328 event.OnTouch(move0); | 363 move0.set_location(gfx::PointF(12, 21)); |
| 364 EXPECT_TRUE(event.OnTouch(move0)); |
| 329 EXPECT_EQ(MsToTicks(times_in_ms[2]), event.GetEventTime()); | 365 EXPECT_EQ(MsToTicks(times_in_ms[2]), event.GetEventTime()); |
| 330 | 366 |
| 331 // Test cloning of timestamp information. | 367 // Test cloning of timestamp information. |
| 332 scoped_ptr<MotionEvent> clone = event.Clone(); | 368 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 333 EXPECT_EQ(MsToTicks(times_in_ms[2]), clone->GetEventTime()); | 369 EXPECT_EQ(MsToTicks(times_in_ms[2]), clone->GetEventTime()); |
| 334 } | 370 } |
| 335 | 371 |
| 336 TEST(MotionEventImplTest, CachedAction) { | 372 TEST(MotionEventAuraTest, CachedAction) { |
| 337 // Test that the cached action and cached action index are correct. | 373 // Test that the cached action and cached action index are correct. |
| 338 int ids[] = {4, 6}; | 374 int ids[] = {4, 6}; |
| 339 MotionEventImpl event; | 375 MotionEventAura event; |
| 340 | 376 |
| 341 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 377 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
| 342 event.OnTouch(press0); | 378 EXPECT_TRUE(event.OnTouch(press0)); |
| 343 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); | 379 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); |
| 344 EXPECT_EQ(1U, event.GetPointerCount()); | 380 EXPECT_EQ(1U, event.GetPointerCount()); |
| 345 | 381 |
| 346 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 382 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
| 347 event.OnTouch(press1); | 383 EXPECT_TRUE(event.OnTouch(press1)); |
| 348 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); | 384 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); |
| 349 EXPECT_EQ(1, event.GetActionIndex()); | 385 EXPECT_EQ(1, event.GetActionIndex()); |
| 350 EXPECT_EQ(2U, event.GetPointerCount()); | 386 EXPECT_EQ(2U, event.GetPointerCount()); |
| 351 | 387 |
| 352 // Test cloning of CachedAction information. | 388 // Test cloning of CachedAction information. |
| 353 scoped_ptr<MotionEvent> clone = event.Clone(); | 389 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 354 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, clone->GetAction()); | 390 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, clone->GetAction()); |
| 355 EXPECT_EQ(1, clone->GetActionIndex()); | 391 EXPECT_EQ(1, clone->GetActionIndex()); |
| 356 | 392 |
| 357 TouchEvent move0 = TouchWithType(ET_TOUCH_MOVED, ids[0]); | 393 TouchEvent move0 = TouchWithType(ET_TOUCH_MOVED, ids[0]); |
| 358 event.OnTouch(move0); | 394 move0.set_location(gfx::PointF(10, 12)); |
| 395 EXPECT_TRUE(event.OnTouch(move0)); |
| 359 EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction()); | 396 EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction()); |
| 360 EXPECT_EQ(2U, event.GetPointerCount()); | 397 EXPECT_EQ(2U, event.GetPointerCount()); |
| 361 | 398 |
| 362 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 399 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
| 363 event.OnTouch(release0); | 400 EXPECT_TRUE(event.OnTouch(release0)); |
| 364 EXPECT_EQ(MotionEvent::ACTION_POINTER_UP, event.GetAction()); | 401 EXPECT_EQ(MotionEvent::ACTION_POINTER_UP, event.GetAction()); |
| 365 EXPECT_EQ(2U, event.GetPointerCount()); | 402 EXPECT_EQ(2U, event.GetPointerCount()); |
| 366 event.CleanupRemovedTouchPoints(release0); | 403 event.CleanupRemovedTouchPoints(release0); |
| 367 EXPECT_EQ(1U, event.GetPointerCount()); | 404 EXPECT_EQ(1U, event.GetPointerCount()); |
| 368 | 405 |
| 369 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); | 406 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); |
| 370 event.OnTouch(release1); | 407 EXPECT_TRUE(event.OnTouch(release1)); |
| 371 EXPECT_EQ(MotionEvent::ACTION_UP, event.GetAction()); | 408 EXPECT_EQ(MotionEvent::ACTION_UP, event.GetAction()); |
| 372 EXPECT_EQ(1U, event.GetPointerCount()); | 409 EXPECT_EQ(1U, event.GetPointerCount()); |
| 373 event.CleanupRemovedTouchPoints(release1); | 410 event.CleanupRemovedTouchPoints(release1); |
| 374 EXPECT_EQ(0U, event.GetPointerCount()); | 411 EXPECT_EQ(0U, event.GetPointerCount()); |
| 375 } | 412 } |
| 376 | 413 |
| 377 TEST(MotionEventImplTest, Cancel) { | 414 TEST(MotionEventAuraTest, Cancel) { |
| 378 int ids[] = {4, 6}; | 415 int ids[] = {4, 6}; |
| 379 MotionEventImpl event; | 416 MotionEventAura event; |
| 380 | 417 |
| 381 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 418 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
| 382 event.OnTouch(press0); | 419 EXPECT_TRUE(event.OnTouch(press0)); |
| 383 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); | 420 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); |
| 384 EXPECT_EQ(1U, event.GetPointerCount()); | 421 EXPECT_EQ(1U, event.GetPointerCount()); |
| 385 | 422 |
| 386 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 423 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
| 387 event.OnTouch(press1); | 424 EXPECT_TRUE(event.OnTouch(press1)); |
| 388 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); | 425 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); |
| 389 EXPECT_EQ(1, event.GetActionIndex()); | 426 EXPECT_EQ(1, event.GetActionIndex()); |
| 390 EXPECT_EQ(2U, event.GetPointerCount()); | 427 EXPECT_EQ(2U, event.GetPointerCount()); |
| 391 | 428 |
| 392 scoped_ptr<MotionEvent> cancel = event.Cancel(); | 429 scoped_ptr<MotionEvent> cancel = event.Cancel(); |
| 393 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction()); | 430 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction()); |
| 394 EXPECT_EQ(2U, static_cast<MotionEventImpl*>(cancel.get())->GetPointerCount()); | 431 EXPECT_EQ(2U, cancel->GetPointerCount()); |
| 395 } | 432 } |
| 396 | 433 |
| 397 TEST(MotionEventImplTest, ToolType) { | 434 TEST(MotionEventAuraTest, ToolType) { |
| 398 MotionEventImpl event; | 435 MotionEventAura event; |
| 399 | 436 |
| 400 // For now, all pointers have an unknown tool type. | 437 // For now, all pointers have an unknown tool type. |
| 401 // TODO(jdduke): Expand this test when ui::TouchEvent identifies the source | 438 // TODO(jdduke): Expand this test when ui::TouchEvent identifies the source |
| 402 // touch type, crbug.com/404128. | 439 // touch type, crbug.com/404128. |
| 403 event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, 7)); | 440 EXPECT_TRUE(event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, 7))); |
| 404 ASSERT_EQ(1U, event.GetPointerCount()); | 441 ASSERT_EQ(1U, event.GetPointerCount()); |
| 405 EXPECT_EQ(MotionEvent::TOOL_TYPE_UNKNOWN, event.GetToolType(0)); | 442 EXPECT_EQ(MotionEvent::TOOL_TYPE_UNKNOWN, event.GetToolType(0)); |
| 406 } | 443 } |
| 407 | 444 |
| 408 TEST(MotionEventImplTest, Flags) { | 445 TEST(MotionEventAuraTest, Flags) { |
| 409 int ids[] = {7, 11}; | 446 int ids[] = {7, 11}; |
| 410 MotionEventImpl event; | 447 MotionEventAura event; |
| 411 | 448 |
| 412 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 449 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
| 413 press0.set_flags(EF_CONTROL_DOWN); | 450 press0.set_flags(EF_CONTROL_DOWN); |
| 414 event.OnTouch(press0); | 451 EXPECT_TRUE(event.OnTouch(press0)); |
| 415 EXPECT_EQ(EF_CONTROL_DOWN, event.GetFlags()); | 452 EXPECT_EQ(EF_CONTROL_DOWN, event.GetFlags()); |
| 416 | 453 |
| 417 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 454 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
| 418 press1.set_flags(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN); | 455 press1.set_flags(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN); |
| 419 event.OnTouch(press1); | 456 EXPECT_TRUE(event.OnTouch(press1)); |
| 420 EXPECT_EQ(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN, event.GetFlags()); | 457 EXPECT_EQ(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN, event.GetFlags()); |
| 421 } | 458 } |
| 422 | 459 |
| 460 // Once crbug.com/446852 is fixed, we should ignore redundant presses. |
| 461 TEST(MotionEventAuraTest, DoesntIgnoreRedundantPresses) { |
| 462 const int id = 7; |
| 463 const int position_1 = 10; |
| 464 const int position_2 = 23; |
| 465 |
| 466 MotionEventAura event; |
| 467 TouchEvent press1 = TouchWithPosition(ET_TOUCH_PRESSED, id, position_1, |
| 468 position_1, position_1, position_1); |
| 469 EXPECT_TRUE(event.OnTouch(press1)); |
| 470 TouchEvent press2 = TouchWithPosition(ET_TOUCH_PRESSED, id, position_2, |
| 471 position_2, position_2, position_2); |
| 472 EXPECT_TRUE(event.OnTouch(press2)); |
| 473 |
| 474 EXPECT_EQ(1U, event.GetPointerCount()); |
| 475 EXPECT_FLOAT_EQ(position_2, event.GetX(0)); |
| 476 } |
| 477 |
| 478 TEST(MotionEventAuraTest, IgnoresEventsWithoutPress) { |
| 479 int id = 7; |
| 480 MotionEventAura event; |
| 481 EXPECT_FALSE(event.OnTouch(TouchWithType(ET_TOUCH_MOVED, id))); |
| 482 } |
| 483 |
| 484 TEST(MotionEventAuraTest, IgnoresStationaryMoves) { |
| 485 int id = 7; |
| 486 MotionEventAura event; |
| 487 EXPECT_TRUE(event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, id))); |
| 488 TouchEvent move0 = TouchWithPosition(ET_TOUCH_PRESSED, id, 10, 20, 10, 20); |
| 489 EXPECT_TRUE(event.OnTouch(move0)); |
| 490 |
| 491 TouchEvent move1 = TouchWithPosition(ET_TOUCH_MOVED, id, 11, 21, 11, 21); |
| 492 EXPECT_TRUE(event.OnTouch(move1)); |
| 493 EXPECT_FALSE(event.OnTouch(move1)); |
| 494 } |
| 495 |
| 496 // Test after converting touch events into motion events, motion events should |
| 497 // have the same unique_event_id as touch events. |
| 498 TEST(MotionEventAuraTest, UniqueEventID) { |
| 499 MotionEventAura event; |
| 500 |
| 501 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, 3); |
| 502 EXPECT_TRUE(event.OnTouch(press0)); |
| 503 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); |
| 504 ASSERT_EQ(1U, event.GetPointerCount()); |
| 505 EXPECT_EQ(event.GetUniqueEventId(), press0.unique_event_id()); |
| 506 |
| 507 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, 6); |
| 508 EXPECT_TRUE(event.OnTouch(press1)); |
| 509 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); |
| 510 EXPECT_EQ(2U, event.GetPointerCount()); |
| 511 EXPECT_EQ(event.GetUniqueEventId(), press1.unique_event_id()); |
| 512 } |
| 513 |
| 423 } // namespace ui | 514 } // namespace ui |
| OLD | NEW |