OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "ui/events/event.h" | 7 #include "ui/events/event.h" |
8 #include "ui/events/event_utils.h" | 8 #include "ui/events/event_utils.h" |
9 #include "ui/events/keycodes/dom/dom_code.h" | 9 #include "ui/events/keycodes/dom/dom_code.h" |
10 #include "ui/events/keycodes/dom/keycode_converter.h" | 10 #include "ui/events/keycodes/dom/keycode_converter.h" |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 } | 599 } |
600 | 600 |
601 { | 601 { |
602 const float angle_too_big = 400; | 602 const float angle_too_big = 400; |
603 TouchEvent event(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, 0, time, | 603 TouchEvent event(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, 0, time, |
604 radius_x, radius_y, angle_too_big, 0); | 604 radius_x, radius_y, angle_too_big, 0); |
605 EXPECT_FLOAT_EQ(400 - 360, event.rotation_angle()); | 605 EXPECT_FLOAT_EQ(400 - 360, event.rotation_angle()); |
606 } | 606 } |
607 } | 607 } |
608 | 608 |
| 609 TEST(EventTest, PointerEventDetailsTouch) { |
| 610 ui::TouchEvent touch_event_plain(ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, |
| 611 ui::EventTimeForNow()); |
| 612 |
| 613 EXPECT_EQ(EventPointerType::POINTER_TYPE_TOUCH, |
| 614 touch_event_plain.pointer_details().pointer_type()); |
| 615 EXPECT_EQ(0.0f, touch_event_plain.pointer_details().radius_x()); |
| 616 EXPECT_EQ(0.0f, touch_event_plain.pointer_details().radius_y()); |
| 617 EXPECT_EQ(0.0f, touch_event_plain.pointer_details().force()); |
| 618 EXPECT_EQ(0.0f, touch_event_plain.pointer_details().tilt_x()); |
| 619 EXPECT_EQ(0.0f, touch_event_plain.pointer_details().tilt_y()); |
| 620 |
| 621 EXPECT_EQ(0.0f, touch_event_plain.radius_x()); |
| 622 EXPECT_EQ(0.0f, touch_event_plain.radius_y()); |
| 623 EXPECT_EQ(0.0f, touch_event_plain.force()); |
| 624 |
| 625 ui::TouchEvent touch_event_with_details(ET_TOUCH_PRESSED, gfx::Point(0, 0), 0, |
| 626 0, ui::EventTimeForNow(), 10.0f, 5.0f, |
| 627 0.0f, 15.0f); |
| 628 |
| 629 EXPECT_EQ(EventPointerType::POINTER_TYPE_TOUCH, |
| 630 touch_event_with_details.pointer_details().pointer_type()); |
| 631 EXPECT_EQ(10.0f, touch_event_with_details.pointer_details().radius_x()); |
| 632 EXPECT_EQ(5.0f, touch_event_with_details.pointer_details().radius_y()); |
| 633 EXPECT_EQ(15.0f, touch_event_with_details.pointer_details().force()); |
| 634 EXPECT_EQ(0.0f, touch_event_with_details.pointer_details().tilt_x()); |
| 635 EXPECT_EQ(0.0f, touch_event_with_details.pointer_details().tilt_y()); |
| 636 |
| 637 ui::TouchEvent touch_event_copy(touch_event_with_details); |
| 638 EXPECT_EQ(EventPointerType::POINTER_TYPE_TOUCH, |
| 639 touch_event_copy.pointer_details().pointer_type()); |
| 640 EXPECT_EQ(10.0f, touch_event_copy.pointer_details().radius_x()); |
| 641 EXPECT_EQ(5.0f, touch_event_copy.pointer_details().radius_y()); |
| 642 EXPECT_EQ(15.0f, touch_event_copy.pointer_details().force()); |
| 643 EXPECT_EQ(0.0f, touch_event_copy.pointer_details().tilt_x()); |
| 644 EXPECT_EQ(0.0f, touch_event_copy.pointer_details().tilt_y()); |
| 645 } |
| 646 |
| 647 TEST(EventTest, PointerEventDetailsMouse) { |
| 648 ui::MouseEvent mouse_event(ET_MOUSE_PRESSED, gfx::PointF(0, 0), |
| 649 gfx::PointF(0, 0), ui::EventTimeForNow(), 0, 0); |
| 650 |
| 651 EXPECT_EQ(EventPointerType::POINTER_TYPE_MOUSE, |
| 652 mouse_event.pointer_details().pointer_type()); |
| 653 EXPECT_EQ(0.0f, mouse_event.pointer_details().radius_x()); |
| 654 EXPECT_EQ(0.0f, mouse_event.pointer_details().radius_y()); |
| 655 EXPECT_EQ(0.0f, mouse_event.pointer_details().force()); |
| 656 EXPECT_EQ(0.0f, mouse_event.pointer_details().tilt_x()); |
| 657 EXPECT_EQ(0.0f, mouse_event.pointer_details().tilt_y()); |
| 658 |
| 659 ui::MouseEvent mouse_event_copy(mouse_event); |
| 660 EXPECT_EQ(EventPointerType::POINTER_TYPE_MOUSE, |
| 661 mouse_event_copy.pointer_details().pointer_type()); |
| 662 EXPECT_EQ(0.0f, mouse_event_copy.pointer_details().radius_x()); |
| 663 EXPECT_EQ(0.0f, mouse_event_copy.pointer_details().radius_y()); |
| 664 EXPECT_EQ(0.0f, mouse_event_copy.pointer_details().force()); |
| 665 EXPECT_EQ(0.0f, mouse_event_copy.pointer_details().tilt_x()); |
| 666 EXPECT_EQ(0.0f, mouse_event_copy.pointer_details().tilt_y()); |
| 667 } |
| 668 |
| 669 TEST(EventTest, PointerEventDetailsStylus) { |
| 670 ui::MouseEvent stylus_event(ET_MOUSE_PRESSED, gfx::PointF(0, 0), |
| 671 gfx::PointF(0, 0), ui::EventTimeForNow(), 0, 0); |
| 672 stylus_event.set_pointer_type(EventPointerType::POINTER_TYPE_PEN); |
| 673 stylus_event.set_force(21.0f); |
| 674 stylus_event.set_tilt_x(45.0f); |
| 675 stylus_event.set_tilt_y(-45.0f); |
| 676 |
| 677 EXPECT_EQ(EventPointerType::POINTER_TYPE_PEN, |
| 678 stylus_event.pointer_details().pointer_type()); |
| 679 EXPECT_EQ(21.0f, stylus_event.pointer_details().force()); |
| 680 EXPECT_EQ(45.0f, stylus_event.pointer_details().tilt_x()); |
| 681 EXPECT_EQ(-45.0f, stylus_event.pointer_details().tilt_y()); |
| 682 EXPECT_EQ(0.0f, stylus_event.pointer_details().radius_x()); |
| 683 EXPECT_EQ(0.0f, stylus_event.pointer_details().radius_y()); |
| 684 |
| 685 ui::MouseEvent stylus_event_copy(stylus_event); |
| 686 EXPECT_EQ(EventPointerType::POINTER_TYPE_PEN, |
| 687 stylus_event_copy.pointer_details().pointer_type()); |
| 688 EXPECT_EQ(21.0f, stylus_event_copy.pointer_details().force()); |
| 689 EXPECT_EQ(45.0f, stylus_event_copy.pointer_details().tilt_x()); |
| 690 EXPECT_EQ(-45.0f, stylus_event_copy.pointer_details().tilt_y()); |
| 691 EXPECT_EQ(0.0f, stylus_event_copy.pointer_details().radius_x()); |
| 692 EXPECT_EQ(0.0f, stylus_event_copy.pointer_details().radius_y()); |
| 693 } |
| 694 |
609 } // namespace ui | 695 } // namespace ui |
OLD | NEW |