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 "ui/events/event.h" | 5 #include "ui/events/event.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 ui::TouchEvent touch_event_copy(touch_event); | 731 ui::TouchEvent touch_event_copy(touch_event); |
732 EXPECT_EQ(touch_event.pointer_details(), touch_event_copy.pointer_details()); | 732 EXPECT_EQ(touch_event.pointer_details(), touch_event_copy.pointer_details()); |
733 } | 733 } |
734 | 734 |
735 TEST(EventTest, PointerEventCanConvertFrom) { | 735 TEST(EventTest, PointerEventCanConvertFrom) { |
736 const gfx::Point point; | 736 const gfx::Point point; |
737 const base::TimeTicks time; | 737 const base::TimeTicks time; |
738 | 738 |
739 // Common mouse events can be converted. | 739 // Common mouse events can be converted. |
740 const EventType mouse_allowed[] = { | 740 const EventType mouse_allowed[] = { |
741 ET_MOUSE_PRESSED, | 741 ET_MOUSE_PRESSED, ET_MOUSE_DRAGGED, ET_MOUSE_MOVED, |
742 ET_MOUSE_DRAGGED, | 742 ET_MOUSE_ENTERED, ET_MOUSE_EXITED, ET_MOUSE_RELEASED, |
743 ET_MOUSE_MOVED, | 743 ET_MOUSEWHEEL, ET_MOUSE_CAPTURE_CHANGED, |
744 ET_MOUSE_ENTERED, | |
745 ET_MOUSE_EXITED, | |
746 ET_MOUSE_RELEASED | |
747 }; | 744 }; |
748 for (size_t i = 0; i < arraysize(mouse_allowed); i++) { | 745 for (size_t i = 0; i < arraysize(mouse_allowed); i++) { |
749 MouseEvent event(mouse_allowed[i], point, point, time, 0, 0); | 746 MouseEvent event(mouse_allowed[i], point, point, time, 0, 0); |
750 EXPECT_TRUE(PointerEvent::CanConvertFrom(event)); | 747 EXPECT_TRUE(PointerEvent::CanConvertFrom(event)); |
751 } | 748 } |
752 | 749 |
753 // Common touch events can be converted. | 750 // Common touch events can be converted. |
754 const EventType touch_allowed[] = { | 751 const EventType touch_allowed[] = { |
755 ET_TOUCH_PRESSED, | 752 ET_TOUCH_PRESSED, |
756 ET_TOUCH_MOVED, | 753 ET_TOUCH_MOVED, |
757 ET_TOUCH_RELEASED, | 754 ET_TOUCH_RELEASED, |
758 ET_TOUCH_CANCELLED | 755 ET_TOUCH_CANCELLED |
759 }; | 756 }; |
760 for (size_t i = 0; i < arraysize(touch_allowed); i++) { | 757 for (size_t i = 0; i < arraysize(touch_allowed); i++) { |
761 TouchEvent event(touch_allowed[i], point, 0, time); | 758 TouchEvent event(touch_allowed[i], point, 0, time); |
762 EXPECT_TRUE(PointerEvent::CanConvertFrom(event)); | 759 EXPECT_TRUE(PointerEvent::CanConvertFrom(event)); |
763 } | 760 } |
764 | 761 |
765 // Capture changes cannot be converted. | |
766 EXPECT_FALSE( | |
767 PointerEvent::CanConvertFrom( | |
768 MouseEvent(ET_MOUSE_CAPTURE_CHANGED, point, point, time, 0, 0))); | |
769 | |
770 // Wheel events cannot be converted. | |
771 EXPECT_FALSE( | |
772 PointerEvent::CanConvertFrom( | |
773 MouseWheelEvent(gfx::Vector2d(), point, point, time, 0, 0))); | |
774 | |
775 // Non-mouse non-touch events cannot be converted. | 762 // Non-mouse non-touch events cannot be converted. |
776 EXPECT_FALSE( | 763 EXPECT_FALSE( |
777 PointerEvent::CanConvertFrom( | 764 PointerEvent::CanConvertFrom( |
778 KeyEvent(ET_KEY_PRESSED, VKEY_SPACE, EF_NONE))); | 765 KeyEvent(ET_KEY_PRESSED, VKEY_SPACE, EF_NONE))); |
779 } | 766 } |
780 | 767 |
781 TEST(EventTest, PointerEventType) { | 768 TEST(EventTest, PointerEventType) { |
782 const ui::EventType kMouseTypeMap[][2] = { | 769 const ui::EventType kMouseTypeMap[][2] = { |
783 {ui::ET_MOUSE_PRESSED, ui::ET_POINTER_DOWN}, | 770 {ui::ET_MOUSE_PRESSED, ui::ET_POINTER_DOWN}, |
784 {ui::ET_MOUSE_DRAGGED, ui::ET_POINTER_MOVED}, | 771 {ui::ET_MOUSE_DRAGGED, ui::ET_POINTER_MOVED}, |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 XButtonEvent* button_event = &(native_event.xbutton); | 1007 XButtonEvent* button_event = &(native_event.xbutton); |
1021 button_event->type = ButtonPress; | 1008 button_event->type = ButtonPress; |
1022 button_event->button = 4; // A valid wheel button number between min and max. | 1009 button_event->button = 4; // A valid wheel button number between min and max. |
1023 MouseWheelEvent mouse_ev(&native_event); | 1010 MouseWheelEvent mouse_ev(&native_event); |
1024 | 1011 |
1025 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); | 1012 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); |
1026 #endif | 1013 #endif |
1027 } | 1014 } |
1028 | 1015 |
1029 } // namespace ui | 1016 } // namespace ui |
OLD | NEW |