| 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" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 106 |
| 107 EXPECT_EQ(ids[0], event.GetPointerId(0)); | 107 EXPECT_EQ(ids[0], event.GetPointerId(0)); |
| 108 EXPECT_EQ(ids[2], event.GetPointerId(1)); | 108 EXPECT_EQ(ids[2], event.GetPointerId(1)); |
| 109 | 109 |
| 110 // Test cloning of pointer count and id information. | 110 // Test cloning of pointer count and id information. |
| 111 // TODO(mustaq): Make a separate clone test, crbug.com/450655 | 111 // TODO(mustaq): Make a separate clone test, crbug.com/450655 |
| 112 scoped_ptr<MotionEvent> clone = event.Clone(); | 112 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 113 EXPECT_EQ(2U, clone->GetPointerCount()); | 113 EXPECT_EQ(2U, clone->GetPointerCount()); |
| 114 EXPECT_EQ(ids[0], clone->GetPointerId(0)); | 114 EXPECT_EQ(ids[0], clone->GetPointerId(0)); |
| 115 EXPECT_EQ(ids[2], clone->GetPointerId(1)); | 115 EXPECT_EQ(ids[2], clone->GetPointerId(1)); |
| 116 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); |
| 116 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); | 117 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
| 117 | 118 |
| 118 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 119 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
| 119 EXPECT_TRUE(event.OnTouch(release0)); | 120 EXPECT_TRUE(event.OnTouch(release0)); |
| 120 event.CleanupRemovedTouchPoints(release0); | 121 event.CleanupRemovedTouchPoints(release0); |
| 121 EXPECT_EQ(1U, event.GetPointerCount()); | 122 EXPECT_EQ(1U, event.GetPointerCount()); |
| 122 | 123 |
| 123 EXPECT_EQ(ids[2], event.GetPointerId(0)); | 124 EXPECT_EQ(ids[2], event.GetPointerId(0)); |
| 124 | 125 |
| 125 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); | 126 TouchEvent release2 = TouchWithType(ET_TOUCH_RELEASED, ids[2]); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 EXPECT_TRUE(event.OnTouch(press1)); | 201 EXPECT_TRUE(event.OnTouch(press1)); |
| 201 | 202 |
| 202 EXPECT_EQ(2U, event.GetPointerCount()); | 203 EXPECT_EQ(2U, event.GetPointerCount()); |
| 203 EXPECT_FLOAT_EQ(x, event.GetX(1)); | 204 EXPECT_FLOAT_EQ(x, event.GetX(1)); |
| 204 EXPECT_FLOAT_EQ(y, event.GetY(1)); | 205 EXPECT_FLOAT_EQ(y, event.GetY(1)); |
| 205 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); | 206 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); |
| 206 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); | 207 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); |
| 207 | 208 |
| 208 // Test cloning of pointer location information. | 209 // Test cloning of pointer location information. |
| 209 scoped_ptr<MotionEvent> clone = event.Clone(); | 210 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 211 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); |
| 210 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); | 212 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
| 211 EXPECT_EQ(2U, clone->GetPointerCount()); | 213 EXPECT_EQ(2U, clone->GetPointerCount()); |
| 212 EXPECT_FLOAT_EQ(x, clone->GetX(1)); | 214 EXPECT_FLOAT_EQ(x, clone->GetX(1)); |
| 213 EXPECT_FLOAT_EQ(y, clone->GetY(1)); | 215 EXPECT_FLOAT_EQ(y, clone->GetY(1)); |
| 214 EXPECT_FLOAT_EQ(raw_x, clone->GetRawX(1)); | 216 EXPECT_FLOAT_EQ(raw_x, clone->GetRawX(1)); |
| 215 EXPECT_FLOAT_EQ(raw_y, clone->GetRawY(1)); | 217 EXPECT_FLOAT_EQ(raw_y, clone->GetRawY(1)); |
| 216 | 218 |
| 217 x = 27.9f; | 219 x = 27.9f; |
| 218 y = 22.3f; | 220 y = 22.3f; |
| 219 raw_x = x + kRawOffsetX; | 221 raw_x = x + kRawOffsetX; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 280 |
| 279 EXPECT_EQ(2U, event.GetPointerCount()); | 281 EXPECT_EQ(2U, event.GetPointerCount()); |
| 280 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); | 282 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); |
| 281 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); | 283 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); |
| 282 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); | 284 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); |
| 283 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); | 285 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); |
| 284 | 286 |
| 285 // Test cloning of tap params | 287 // Test cloning of tap params |
| 286 // TODO(mustaq): Make a separate clone test, crbug.com/450655 | 288 // TODO(mustaq): Make a separate clone test, crbug.com/450655 |
| 287 scoped_ptr<MotionEvent> clone = event.Clone(); | 289 scoped_ptr<MotionEvent> clone = event.Clone(); |
| 290 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); |
| 288 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); | 291 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
| 289 EXPECT_EQ(2U, clone->GetPointerCount()); | 292 EXPECT_EQ(2U, clone->GetPointerCount()); |
| 290 EXPECT_FLOAT_EQ(radius_y, clone->GetTouchMajor(1) / 2); | 293 EXPECT_FLOAT_EQ(radius_y, clone->GetTouchMajor(1) / 2); |
| 291 EXPECT_FLOAT_EQ(radius_x, clone->GetTouchMinor(1) / 2); | 294 EXPECT_FLOAT_EQ(radius_x, clone->GetTouchMinor(1) / 2); |
| 292 EXPECT_FLOAT_EQ(rotation_angle, clone->GetOrientation(1) * 180 / M_PI); | 295 EXPECT_FLOAT_EQ(rotation_angle, clone->GetOrientation(1) * 180 / M_PI); |
| 293 EXPECT_FLOAT_EQ(pressure, clone->GetPressure(1)); | 296 EXPECT_FLOAT_EQ(pressure, clone->GetPressure(1)); |
| 294 | 297 |
| 295 // TODO(mustaq): The move test seems out-of-scope here, crbug.com/450655 | 298 // TODO(mustaq): The move test seems out-of-scope here, crbug.com/450655 |
| 296 radius_x = 76.98f; | 299 radius_x = 76.98f; |
| 297 radius_y = 321.54f; | 300 radius_y = 321.54f; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 MotionEventAura event; | 486 MotionEventAura event; |
| 484 EXPECT_TRUE(event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, id))); | 487 EXPECT_TRUE(event.OnTouch(TouchWithType(ET_TOUCH_PRESSED, id))); |
| 485 TouchEvent move0 = TouchWithPosition(ET_TOUCH_PRESSED, id, 10, 20, 10, 20); | 488 TouchEvent move0 = TouchWithPosition(ET_TOUCH_PRESSED, id, 10, 20, 10, 20); |
| 486 EXPECT_TRUE(event.OnTouch(move0)); | 489 EXPECT_TRUE(event.OnTouch(move0)); |
| 487 | 490 |
| 488 TouchEvent move1 = TouchWithPosition(ET_TOUCH_MOVED, id, 11, 21, 11, 21); | 491 TouchEvent move1 = TouchWithPosition(ET_TOUCH_MOVED, id, 11, 21, 11, 21); |
| 489 EXPECT_TRUE(event.OnTouch(move1)); | 492 EXPECT_TRUE(event.OnTouch(move1)); |
| 490 EXPECT_FALSE(event.OnTouch(move1)); | 493 EXPECT_FALSE(event.OnTouch(move1)); |
| 491 } | 494 } |
| 492 | 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 |
| 493 } // namespace ui | 514 } // namespace ui |
| OLD | NEW |