| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); | 89 TouchEvent release1 = TouchWithType(ET_TOUCH_RELEASED, ids[1]); |
| 90 EXPECT_TRUE(event.OnTouch(release1)); | 90 EXPECT_TRUE(event.OnTouch(release1)); |
| 91 event.CleanupRemovedTouchPoints(release1); | 91 event.CleanupRemovedTouchPoints(release1); |
| 92 EXPECT_EQ(2U, event.GetPointerCount()); | 92 EXPECT_EQ(2U, event.GetPointerCount()); |
| 93 | 93 |
| 94 EXPECT_EQ(ids[0], event.GetPointerId(0)); | 94 EXPECT_EQ(ids[0], event.GetPointerId(0)); |
| 95 EXPECT_EQ(ids[2], event.GetPointerId(1)); | 95 EXPECT_EQ(ids[2], event.GetPointerId(1)); |
| 96 | 96 |
| 97 // Test cloning of pointer count and id information. | 97 // Test cloning of pointer count and id information. |
| 98 // TODO(mustaq): Make a separate clone test, crbug.com/450655 | 98 // TODO(mustaq): Make a separate clone test, crbug.com/450655 |
| 99 scoped_ptr<MotionEvent> clone = event.Clone(); | 99 std::unique_ptr<MotionEvent> clone = event.Clone(); |
| 100 EXPECT_EQ(2U, clone->GetPointerCount()); | 100 EXPECT_EQ(2U, clone->GetPointerCount()); |
| 101 EXPECT_EQ(ids[0], clone->GetPointerId(0)); | 101 EXPECT_EQ(ids[0], clone->GetPointerId(0)); |
| 102 EXPECT_EQ(ids[2], clone->GetPointerId(1)); | 102 EXPECT_EQ(ids[2], clone->GetPointerId(1)); |
| 103 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); | 103 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); |
| 104 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); | 104 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
| 105 | 105 |
| 106 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 106 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
| 107 EXPECT_TRUE(event.OnTouch(release0)); | 107 EXPECT_TRUE(event.OnTouch(release0)); |
| 108 event.CleanupRemovedTouchPoints(release0); | 108 event.CleanupRemovedTouchPoints(release0); |
| 109 EXPECT_EQ(1U, event.GetPointerCount()); | 109 EXPECT_EQ(1U, event.GetPointerCount()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 TouchWithPosition(ET_TOUCH_PRESSED, ids[1], x, y, raw_x, raw_y); | 187 TouchWithPosition(ET_TOUCH_PRESSED, ids[1], x, y, raw_x, raw_y); |
| 188 EXPECT_TRUE(event.OnTouch(press1)); | 188 EXPECT_TRUE(event.OnTouch(press1)); |
| 189 | 189 |
| 190 EXPECT_EQ(2U, event.GetPointerCount()); | 190 EXPECT_EQ(2U, event.GetPointerCount()); |
| 191 EXPECT_FLOAT_EQ(x, event.GetX(1)); | 191 EXPECT_FLOAT_EQ(x, event.GetX(1)); |
| 192 EXPECT_FLOAT_EQ(y, event.GetY(1)); | 192 EXPECT_FLOAT_EQ(y, event.GetY(1)); |
| 193 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); | 193 EXPECT_FLOAT_EQ(raw_x, event.GetRawX(1)); |
| 194 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); | 194 EXPECT_FLOAT_EQ(raw_y, event.GetRawY(1)); |
| 195 | 195 |
| 196 // Test cloning of pointer location information. | 196 // Test cloning of pointer location information. |
| 197 scoped_ptr<MotionEvent> clone = event.Clone(); | 197 std::unique_ptr<MotionEvent> clone = event.Clone(); |
| 198 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); | 198 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); |
| 199 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); | 199 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
| 200 EXPECT_EQ(2U, clone->GetPointerCount()); | 200 EXPECT_EQ(2U, clone->GetPointerCount()); |
| 201 EXPECT_FLOAT_EQ(x, clone->GetX(1)); | 201 EXPECT_FLOAT_EQ(x, clone->GetX(1)); |
| 202 EXPECT_FLOAT_EQ(y, clone->GetY(1)); | 202 EXPECT_FLOAT_EQ(y, clone->GetY(1)); |
| 203 EXPECT_FLOAT_EQ(raw_x, clone->GetRawX(1)); | 203 EXPECT_FLOAT_EQ(raw_x, clone->GetRawX(1)); |
| 204 EXPECT_FLOAT_EQ(raw_y, clone->GetRawY(1)); | 204 EXPECT_FLOAT_EQ(raw_y, clone->GetRawY(1)); |
| 205 | 205 |
| 206 x = 27.9f; | 206 x = 27.9f; |
| 207 y = 22.3f; | 207 y = 22.3f; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 268 |
| 269 EXPECT_EQ(2U, event.GetPointerCount()); | 269 EXPECT_EQ(2U, event.GetPointerCount()); |
| 270 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); | 270 EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(1) / 2); |
| 271 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); | 271 EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); |
| 272 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); | 272 EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); |
| 273 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); | 273 EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); |
| 274 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, event.GetToolType(1)); | 274 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, event.GetToolType(1)); |
| 275 | 275 |
| 276 // Test cloning of tap params | 276 // Test cloning of tap params |
| 277 // TODO(mustaq): Make a separate clone test, crbug.com/450655 | 277 // TODO(mustaq): Make a separate clone test, crbug.com/450655 |
| 278 scoped_ptr<MotionEvent> clone = event.Clone(); | 278 std::unique_ptr<MotionEvent> clone = event.Clone(); |
| 279 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); | 279 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId()); |
| 280 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); | 280 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); |
| 281 EXPECT_EQ(2U, clone->GetPointerCount()); | 281 EXPECT_EQ(2U, clone->GetPointerCount()); |
| 282 EXPECT_FLOAT_EQ(radius_y, clone->GetTouchMajor(1) / 2); | 282 EXPECT_FLOAT_EQ(radius_y, clone->GetTouchMajor(1) / 2); |
| 283 EXPECT_FLOAT_EQ(radius_x, clone->GetTouchMinor(1) / 2); | 283 EXPECT_FLOAT_EQ(radius_x, clone->GetTouchMinor(1) / 2); |
| 284 EXPECT_FLOAT_EQ(rotation_angle, clone->GetOrientation(1) * 180 / M_PI); | 284 EXPECT_FLOAT_EQ(rotation_angle, clone->GetOrientation(1) * 180 / M_PI); |
| 285 EXPECT_FLOAT_EQ(pressure, clone->GetPressure(1)); | 285 EXPECT_FLOAT_EQ(pressure, clone->GetPressure(1)); |
| 286 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, clone->GetToolType(1)); | 286 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, clone->GetToolType(1)); |
| 287 | 287 |
| 288 // TODO(mustaq): The move test seems out-of-scope here, crbug.com/450655 | 288 // TODO(mustaq): The move test seems out-of-scope here, crbug.com/450655 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 EXPECT_TRUE(event.OnTouch(press1)); | 351 EXPECT_TRUE(event.OnTouch(press1)); |
| 352 EXPECT_EQ(MsToTicks(times_in_ms[1]), event.GetEventTime()); | 352 EXPECT_EQ(MsToTicks(times_in_ms[1]), event.GetEventTime()); |
| 353 | 353 |
| 354 TouchEvent move0 = TouchWithTime( | 354 TouchEvent move0 = TouchWithTime( |
| 355 ui::ET_TOUCH_MOVED, ids[0], times_in_ms[2]); | 355 ui::ET_TOUCH_MOVED, ids[0], times_in_ms[2]); |
| 356 move0.set_location(gfx::Point(12, 21)); | 356 move0.set_location(gfx::Point(12, 21)); |
| 357 EXPECT_TRUE(event.OnTouch(move0)); | 357 EXPECT_TRUE(event.OnTouch(move0)); |
| 358 EXPECT_EQ(MsToTicks(times_in_ms[2]), event.GetEventTime()); | 358 EXPECT_EQ(MsToTicks(times_in_ms[2]), event.GetEventTime()); |
| 359 | 359 |
| 360 // Test cloning of timestamp information. | 360 // Test cloning of timestamp information. |
| 361 scoped_ptr<MotionEvent> clone = event.Clone(); | 361 std::unique_ptr<MotionEvent> clone = event.Clone(); |
| 362 EXPECT_EQ(MsToTicks(times_in_ms[2]), clone->GetEventTime()); | 362 EXPECT_EQ(MsToTicks(times_in_ms[2]), clone->GetEventTime()); |
| 363 } | 363 } |
| 364 | 364 |
| 365 TEST(MotionEventAuraTest, CachedAction) { | 365 TEST(MotionEventAuraTest, CachedAction) { |
| 366 // Test that the cached action and cached action index are correct. | 366 // Test that the cached action and cached action index are correct. |
| 367 int ids[] = {4, 6}; | 367 int ids[] = {4, 6}; |
| 368 MotionEventAura event; | 368 MotionEventAura event; |
| 369 | 369 |
| 370 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); | 370 TouchEvent press0 = TouchWithType(ET_TOUCH_PRESSED, ids[0]); |
| 371 EXPECT_TRUE(event.OnTouch(press0)); | 371 EXPECT_TRUE(event.OnTouch(press0)); |
| 372 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); | 372 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); |
| 373 EXPECT_EQ(1U, event.GetPointerCount()); | 373 EXPECT_EQ(1U, event.GetPointerCount()); |
| 374 | 374 |
| 375 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 375 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
| 376 EXPECT_TRUE(event.OnTouch(press1)); | 376 EXPECT_TRUE(event.OnTouch(press1)); |
| 377 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); | 377 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); |
| 378 EXPECT_EQ(1, event.GetActionIndex()); | 378 EXPECT_EQ(1, event.GetActionIndex()); |
| 379 EXPECT_EQ(2U, event.GetPointerCount()); | 379 EXPECT_EQ(2U, event.GetPointerCount()); |
| 380 | 380 |
| 381 // Test cloning of CachedAction information. | 381 // Test cloning of CachedAction information. |
| 382 scoped_ptr<MotionEvent> clone = event.Clone(); | 382 std::unique_ptr<MotionEvent> clone = event.Clone(); |
| 383 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, clone->GetAction()); | 383 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, clone->GetAction()); |
| 384 EXPECT_EQ(1, clone->GetActionIndex()); | 384 EXPECT_EQ(1, clone->GetActionIndex()); |
| 385 | 385 |
| 386 TouchEvent move0 = TouchWithType(ET_TOUCH_MOVED, ids[0]); | 386 TouchEvent move0 = TouchWithType(ET_TOUCH_MOVED, ids[0]); |
| 387 move0.set_location(gfx::Point(10, 12)); | 387 move0.set_location(gfx::Point(10, 12)); |
| 388 EXPECT_TRUE(event.OnTouch(move0)); | 388 EXPECT_TRUE(event.OnTouch(move0)); |
| 389 EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction()); | 389 EXPECT_EQ(MotionEvent::ACTION_MOVE, event.GetAction()); |
| 390 EXPECT_EQ(2U, event.GetPointerCount()); | 390 EXPECT_EQ(2U, event.GetPointerCount()); |
| 391 | 391 |
| 392 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); | 392 TouchEvent release0 = TouchWithType(ET_TOUCH_RELEASED, ids[0]); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 412 EXPECT_TRUE(event.OnTouch(press0)); | 412 EXPECT_TRUE(event.OnTouch(press0)); |
| 413 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); | 413 EXPECT_EQ(MotionEvent::ACTION_DOWN, event.GetAction()); |
| 414 EXPECT_EQ(1U, event.GetPointerCount()); | 414 EXPECT_EQ(1U, event.GetPointerCount()); |
| 415 | 415 |
| 416 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); | 416 TouchEvent press1 = TouchWithType(ET_TOUCH_PRESSED, ids[1]); |
| 417 EXPECT_TRUE(event.OnTouch(press1)); | 417 EXPECT_TRUE(event.OnTouch(press1)); |
| 418 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); | 418 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); |
| 419 EXPECT_EQ(1, event.GetActionIndex()); | 419 EXPECT_EQ(1, event.GetActionIndex()); |
| 420 EXPECT_EQ(2U, event.GetPointerCount()); | 420 EXPECT_EQ(2U, event.GetPointerCount()); |
| 421 | 421 |
| 422 scoped_ptr<MotionEvent> cancel = event.Cancel(); | 422 std::unique_ptr<MotionEvent> cancel = event.Cancel(); |
| 423 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction()); | 423 EXPECT_EQ(MotionEvent::ACTION_CANCEL, cancel->GetAction()); |
| 424 EXPECT_EQ(2U, cancel->GetPointerCount()); | 424 EXPECT_EQ(2U, cancel->GetPointerCount()); |
| 425 } | 425 } |
| 426 | 426 |
| 427 TEST(MotionEventAuraTest, ToolType) { | 427 TEST(MotionEventAuraTest, ToolType) { |
| 428 MotionEventAura event; | 428 MotionEventAura event; |
| 429 TouchEvent touch_event = TouchWithType(ET_TOUCH_PRESSED, 7); | 429 TouchEvent touch_event = TouchWithType(ET_TOUCH_PRESSED, 7); |
| 430 EXPECT_TRUE(event.OnTouch(touch_event)); | 430 EXPECT_TRUE(event.OnTouch(touch_event)); |
| 431 ASSERT_EQ(1U, event.GetPointerCount()); | 431 ASSERT_EQ(1U, event.GetPointerCount()); |
| 432 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, event.GetToolType(0)); | 432 EXPECT_EQ(MotionEvent::TOOL_TYPE_FINGER, event.GetToolType(0)); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 int id = i + kIdOffset; | 526 int id = i + kIdOffset; |
| 527 TouchEvent release = TouchWithType(ET_TOUCH_RELEASED, id); | 527 TouchEvent release = TouchWithType(ET_TOUCH_RELEASED, id); |
| 528 if (i < MotionEvent::MAX_TOUCH_POINT_COUNT) | 528 if (i < MotionEvent::MAX_TOUCH_POINT_COUNT) |
| 529 EXPECT_TRUE(event.OnTouch(release)); | 529 EXPECT_TRUE(event.OnTouch(release)); |
| 530 else | 530 else |
| 531 EXPECT_FALSE(event.OnTouch(release)); | 531 EXPECT_FALSE(event.OnTouch(release)); |
| 532 } | 532 } |
| 533 } | 533 } |
| 534 | 534 |
| 535 } // namespace ui | 535 } // namespace ui |
| OLD | NEW |