| 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_aura.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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 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, *clone); |
| 115 | 117 |
| 116 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 118 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
| 117 event.OnTouch(release0); | 119 event.OnTouch(release0); |
| 118 event.CleanupRemovedTouchPoints(release0); | 120 event.CleanupRemovedTouchPoints(release0); |
| 119 EXPECT_EQ(1U, event.GetPointerCount()); | 121 EXPECT_EQ(1U, event.GetPointerCount()); |
| 120 | 122 |
| 121 EXPECT_EQ(ids[2], event.GetPointerId(0)); | 123 EXPECT_EQ(ids[2], event.GetPointerId(0)); |
| 122 | 124 |
| 123 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); | 125 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); |
| 124 event.OnTouch(release2); | 126 event.OnTouch(release2); |
| 125 event.CleanupRemovedTouchPoints(release2); | 127 event.CleanupRemovedTouchPoints(release2); |
| 126 EXPECT_EQ(0U, event.GetPointerCount()); | 128 EXPECT_EQ(0U, event.GetPointerCount()); |
| 127 } | 129 } |
| 128 | 130 |
| 129 TEST(MotionEventAuraTest, GetActionIndexAfterRemoval) { | 131 TEST(MotionEventAuraTest, GetActionIndexAfterRemoval) { |
| 130 // Test that |GetActionIndex()| returns the correct index when points have | 132 // Test that |GetActionIndex()| returns the correct index when points have |
| 131 // been removed. | 133 // been removed. |
| 132 int ids[] = {4, 6, 9}; | 134 int ids[] = {4, 6, 9}; |
| 133 | 135 |
| 134 MotionEventAura event; | 136 MotionEventAura event; |
| 135 EXPECT_EQ(0U, event.GetPointerCount()); | 137 EXPECT_EQ(0U, event.GetPointerCount()); |
| 136 | 138 |
| 137 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 139 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
| 138 event.OnTouch(press0); | 140 event.OnTouch(press0); |
| 139 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 141 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
| 140 event.OnTouch(press1); | 142 event.OnTouch(press1); |
| 143 EXPECT_EQ(1, event.GetActionIndex()); |
| 141 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]); | 144 TouchEvent press2 = TouchWithType(ET_TOUCH_PRESSED, ids[2]); |
| 142 event.OnTouch(press2); | 145 event.OnTouch(press2); |
| 146 EXPECT_EQ(2, event.GetActionIndex()); |
| 143 EXPECT_EQ(3U, event.GetPointerCount()); | 147 EXPECT_EQ(3U, event.GetPointerCount()); |
| 144 | 148 |
| 145 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); | 149 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); |
| 146 event.OnTouch(release1); | 150 event.OnTouch(release1); |
| 151 EXPECT_EQ(1, event.GetActionIndex()); |
| 147 event.CleanupRemovedTouchPoints(release1); | 152 event.CleanupRemovedTouchPoints(release1); |
| 148 EXPECT_EQ(1, event.GetActionIndex()); | |
| 149 EXPECT_EQ(2U, event.GetPointerCount()); | 153 EXPECT_EQ(2U, event.GetPointerCount()); |
| 150 | 154 |
| 151 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 155 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
| 152 event.OnTouch(release2); | 156 event.OnTouch(release2); |
| 157 EXPECT_EQ(0, event.GetActionIndex()); |
| 153 event.CleanupRemovedTouchPoints(release2); | 158 event.CleanupRemovedTouchPoints(release2); |
| 154 EXPECT_EQ(0, event.GetActionIndex()); | |
| 155 EXPECT_EQ(1U, event.GetPointerCount()); | 159 EXPECT_EQ(1U, event.GetPointerCount()); |
| 156 | 160 |
| 157 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); | 161 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); |
| 158 event.OnTouch(release0); | 162 event.OnTouch(release0); |
| 159 event.CleanupRemovedTouchPoints(release0); | 163 event.CleanupRemovedTouchPoints(release0); |
| 160 EXPECT_EQ(0U, event.GetPointerCount()); | 164 EXPECT_EQ(0U, event.GetPointerCount()); |
| 161 } | 165 } |
| 162 | 166 |
| 163 TEST(MotionEventAuraTest, PointerLocations) { | 167 TEST(MotionEventAuraTest, PointerLocations) { |
| 164 // Test that location information is stored correctly. | 168 // Test that location information is stored correctly. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 201 |
| 198 EXPECT_EQ(2U, event.GetPointerCount()); | 202 EXPECT_EQ(2U, event.GetPointerCount()); |
| 199 EXPECT_FLOAT_EQ(x, event.GetX(1)); | 203 EXPECT_FLOAT_EQ(x, event.GetX(1)); |
| 200 EXPECT_FLOAT_EQ(y, event.GetY(1)); | 204 EXPECT_FLOAT_EQ(y, event.GetY(1)); |
| 201 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); | 205 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); |
| 202 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); | 206 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); |
| 203 | 207 |
| 204 // Test cloning of pointer location information. | 208 // Test cloning of pointer location information. |
| 205 scoped_ptr<MotionEvent> clone = event.Clone(); | 209 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 206 { | 210 { |
| 207 const MotionEventAura* raw_clone_aura = | 211 EXPECT_EQ(event, *clone); |
| 208 static_cast<MotionEventAura*>(clone.get()); | 212 EXPECT_EQ(2U, clone->GetPointerCount()); |
| 209 EXPECT_EQ(2U, raw_clone_aura->GetPointerCount()); | 213 EXPECT_FLOAT_EQ(x, clone->GetX(1)); |
| 210 EXPECT_FLOAT_EQ(x, raw_clone_aura->GetX(1)); | 214 EXPECT_FLOAT_EQ(y, clone->GetY(1)); |
| 211 EXPECT_FLOAT_EQ(y, raw_clone_aura->GetY(1)); | 215 EXPECT_FLOAT_EQ(raw_x, clone->GetRawX(1)); |
| 212 EXPECT_FLOAT_EQ(raw_x, raw_clone_aura->GetRawX(1)); | 216 EXPECT_FLOAT_EQ(raw_y, clone->GetRawY(1)); |
| 213 EXPECT_FLOAT_EQ(raw_y, raw_clone_aura->GetRawY(1)); | |
| 214 } | 217 } |
| 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 event.OnTouch(move1); |
| 223 | 226 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 278 |
| 276 EXPECT_EQ(2U, event.GetPointerCount()); | 279 EXPECT_EQ(2U, event.GetPointerCount()); |
| 277 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); | 280 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); |
| 278 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); | 281 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); |
| 279 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); | 282 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); |
| 280 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); | 283 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); |
| 281 | 284 |
| 282 // Test cloning of tap params | 285 // Test cloning of tap params |
| 283 scoped_ptr<MotionEvent> clone = event.Clone(); | 286 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 284 { | 287 { |
| 285 const MotionEventAura* raw_clone_aura = | 288 EXPECT_EQ(event, *clone); |
| 286 static_cast<MotionEventAura*>(clone.get()); | 289 EXPECT_EQ(2U, clone->GetPointerCount()); |
| 287 EXPECT_EQ(2U, raw_clone_aura->GetPointerCount()); | 290 EXPECT_FLOAT_EQ(radius_y, clone->GetTouchMajor(1) / 2); |
| 288 EXPECT_FLOAT_EQ(radius_y, raw_clone_aura->GetTouchMajor(1) / 2); | 291 EXPECT_FLOAT_EQ(radius_x, clone->GetTouchMinor(1) / 2); |
| 289 EXPECT_FLOAT_EQ(radius_x, raw_clone_aura->GetTouchMinor(1) / 2); | 292 EXPECT_FLOAT_EQ(rotation_angle, clone->GetOrientation(1) * 180 / M_PI); |
| 290 EXPECT_FLOAT_EQ( | 293 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 } |
| 294 | 295 |
| 295 radius_x = 76.98f; | 296 radius_x = 76.98f; |
| 296 radius_y = 321.54f; | 297 radius_y = 321.54f; |
| 297 rotation_angle = 64.f; | 298 rotation_angle = 64.f; |
| 298 pressure = 0.654f; | 299 pressure = 0.654f; |
| 299 TouchEvent move1 = TouchWithTapParams( | 300 TouchEvent move1 = TouchWithTapParams( |
| 300 ET_TOUCH_MOVED, ids[1], radius_x, radius_y, rotation_angle, pressure); | 301 ET_TOUCH_MOVED, ids[1], radius_x, radius_y, rotation_angle, pressure); |
| 301 event.OnTouch(move1); | 302 event.OnTouch(move1); |
| 302 | 303 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 EXPECT_EQ(1U, event.GetPointerCount()); | 385 EXPECT_EQ(1U, event.GetPointerCount()); |
| 385 | 386 |
| 386 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 387 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
| 387 event.OnTouch(press1); | 388 event.OnTouch(press1); |
| 388 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); | 389 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); |
| 389 EXPECT_EQ(1, event.GetActionIndex()); | 390 EXPECT_EQ(1, event.GetActionIndex()); |
| 390 EXPECT_EQ(2U, event.GetPointerCount()); | 391 EXPECT_EQ(2U, event.GetPointerCount()); |
| 391 | 392 |
| 392 scoped_ptr<MotionEvent> cancel = event.Cancel(); | 393 scoped_ptr<MotionEvent> cancel = event.Cancel(); |
| 393 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction()); | 394 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction()); |
| 394 EXPECT_EQ(2U, static_cast<MotionEventAura*>(cancel.get())->GetPointerCount()); | 395 EXPECT_EQ(2U, cancel->GetPointerCount()); |
| 395 } | 396 } |
| 396 | 397 |
| 397 TEST(MotionEventAuraTest, ToolType) { | 398 TEST(MotionEventAuraTest, ToolType) { |
| 398 MotionEventAura event; | 399 MotionEventAura event; |
| 399 | 400 |
| 400 // For now, all pointers have an unknown tool type. | 401 // For now, all pointers have an unknown tool type. |
| 401 // TODO(jdduke): Expand this test when ui::TouchEvent identifies the source | 402 // TODO(jdduke): Expand this test when ui::TouchEvent identifies the source |
| 402 // touch type, crbug.com/404128. | 403 // touch type, crbug.com/404128. |
| 403 event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, 7)); | 404 event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, 7)); |
| 404 ASSERT_EQ(1U, event.GetPointerCount()); | 405 ASSERT_EQ(1U, event.GetPointerCount()); |
| 405 EXPECT_EQ(MotionEvent::TOOL_TYPE_UNKNOWN, event.GetToolType(0)); | 406 EXPECT_EQ(MotionEvent::TOOL_TYPE_UNKNOWN, event.GetToolType(0)); |
| 406 } | 407 } |
| 407 | 408 |
| 408 TEST(MotionEventAuraTest, Flags) { | 409 TEST(MotionEventAuraTest, Flags) { |
| 409 int ids[] = {7, 11}; | 410 int ids[] = {7, 11}; |
| 410 MotionEventAura event; | 411 MotionEventAura event; |
| 411 | 412 |
| 412 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 413 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
| 413 press0.set_flags(EF_CONTROL_DOWN); | 414 press0.set_flags(EF_CONTROL_DOWN); |
| 414 event.OnTouch(press0); | 415 event.OnTouch(press0); |
| 415 EXPECT_EQ(EF_CONTROL_DOWN, event.GetFlags()); | 416 EXPECT_EQ(EF_CONTROL_DOWN, event.GetFlags()); |
| 416 | 417 |
| 417 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 418 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
| 418 press1.set_flags(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN); | 419 press1.set_flags(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN); |
| 419 event.OnTouch(press1); | 420 event.OnTouch(press1); |
| 420 EXPECT_EQ(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN, event.GetFlags()); | 421 EXPECT_EQ(EF_CONTROL_DOWN | EF_CAPS_LOCK_DOWN, event.GetFlags()); |
| 421 } | 422 } |
| 422 | 423 |
| 423 } // namespace ui | 424 } // namespace ui |
| OLD | NEW |