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 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 ui::PointerEvent* clone_as_ptr = clone->AsPointerEvent(); | 880 ui::PointerEvent* clone_as_ptr = clone->AsPointerEvent(); |
881 | 881 |
882 EXPECT_EQ(ptr_event.type(), clone_as_ptr->type()); | 882 EXPECT_EQ(ptr_event.type(), clone_as_ptr->type()); |
883 EXPECT_EQ(ptr_event.pointer_id(), clone_as_ptr->pointer_id()); | 883 EXPECT_EQ(ptr_event.pointer_id(), clone_as_ptr->pointer_id()); |
884 EXPECT_EQ(ptr_event.pointer_details(), clone_as_ptr->pointer_details()); | 884 EXPECT_EQ(ptr_event.pointer_details(), clone_as_ptr->pointer_details()); |
885 EXPECT_EQ(ptr_event.location(), clone_as_ptr->location()); | 885 EXPECT_EQ(ptr_event.location(), clone_as_ptr->location()); |
886 EXPECT_EQ(ptr_event.root_location(), clone_as_ptr->root_location()); | 886 EXPECT_EQ(ptr_event.root_location(), clone_as_ptr->root_location()); |
887 } | 887 } |
888 } | 888 } |
889 | 889 |
| 890 TEST(EventTest, PointerEventToMouseEvent) { |
| 891 const struct { |
| 892 ui::EventType in_type; |
| 893 ui::EventType out_type; |
| 894 gfx::Point location; |
| 895 gfx::Point root_location; |
| 896 int flags; |
| 897 } kTestData[] = { |
| 898 {ui::ET_POINTER_DOWN, ui::ET_MOUSE_PRESSED, gfx::Point(10, 20), |
| 899 gfx::Point(110, 120), 0}, |
| 900 {ui::ET_POINTER_MOVED, ui::ET_MOUSE_MOVED, gfx::Point(20, 10), |
| 901 gfx::Point(1, 2), EF_LEFT_MOUSE_BUTTON}, |
| 902 {ui::ET_POINTER_ENTERED, ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(), |
| 903 EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON}, |
| 904 {ui::ET_POINTER_EXITED, ui::ET_MOUSE_EXITED, gfx::Point(5, 1), |
| 905 gfx::Point(1, 5), EF_RIGHT_MOUSE_BUTTON}, |
| 906 {ui::ET_POINTER_UP, ui::ET_MOUSE_RELEASED, gfx::Point(1000, 1000), |
| 907 gfx::Point(14, 15), EF_MIDDLE_MOUSE_BUTTON}}; |
| 908 |
| 909 for (size_t i = 0; i < arraysize(kTestData); i++) { |
| 910 ui::PointerEvent pointer_event( |
| 911 kTestData[i].in_type, ui::EventPointerType::POINTER_TYPE_MOUSE, |
| 912 kTestData[i].location, kTestData[i].root_location, kTestData[i].flags, |
| 913 0, base::TimeDelta()); |
| 914 ui::MouseEvent mouse_event(pointer_event); |
| 915 |
| 916 EXPECT_EQ(kTestData[i].out_type, mouse_event.type()); |
| 917 EXPECT_EQ(kTestData[i].location, mouse_event.location()); |
| 918 EXPECT_EQ(kTestData[i].root_location, mouse_event.root_location()); |
| 919 EXPECT_EQ(kTestData[i].flags, mouse_event.flags()); |
| 920 } |
| 921 } |
| 922 |
| 923 TEST(EventTest, PointerEventToTouchEventType) { |
| 924 ui::EventType kTouchTypeMap[][2] = { |
| 925 {ui::ET_POINTER_DOWN, ui::ET_TOUCH_PRESSED}, |
| 926 {ui::ET_POINTER_MOVED, ui::ET_TOUCH_MOVED}, |
| 927 {ui::ET_POINTER_UP, ui::ET_TOUCH_RELEASED}, |
| 928 {ui::ET_POINTER_CANCELLED, ui::ET_TOUCH_CANCELLED}, |
| 929 }; |
| 930 |
| 931 for (size_t i = 0; i < arraysize(kTouchTypeMap); i++) { |
| 932 ui::PointerEvent pointer_event( |
| 933 kTouchTypeMap[i][0], ui::EventPointerType::POINTER_TYPE_TOUCH, |
| 934 gfx::Point(), gfx::Point(), 0, 0, base::TimeDelta()); |
| 935 ui::TouchEvent touch_event(pointer_event); |
| 936 |
| 937 EXPECT_EQ(kTouchTypeMap[i][1], touch_event.type()); |
| 938 } |
| 939 } |
| 940 |
| 941 TEST(EventTest, PointerEventToTouchEventDetails) { |
| 942 ui::PointerEvent pointer_event( |
| 943 ui::TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(12, 14), 0, 15, |
| 944 EventTimeForNow(), 11.5, 13.5, 13.0, 0.5)); |
| 945 ui::TouchEvent touch_event(pointer_event); |
| 946 |
| 947 EXPECT_EQ(pointer_event.location(), touch_event.location()); |
| 948 EXPECT_EQ(pointer_event.flags(), touch_event.flags()); |
| 949 EXPECT_EQ(pointer_event.pointer_id(), touch_event.touch_id()); |
| 950 EXPECT_EQ(pointer_event.pointer_details(), touch_event.pointer_details()); |
| 951 EXPECT_EQ(pointer_event.time_stamp(), touch_event.time_stamp()); |
| 952 } |
| 953 |
890 // Checks that Event.Latency.OS.TOUCH_PRESSED, TOUCH_MOVED, | 954 // Checks that Event.Latency.OS.TOUCH_PRESSED, TOUCH_MOVED, |
891 // and TOUCH_RELEASED histograms are computed properly. | 955 // and TOUCH_RELEASED histograms are computed properly. |
892 #if defined(USE_X11) | 956 #if defined(USE_X11) |
893 TEST(EventTest, EventLatencyOSTouchHistograms) { | 957 TEST(EventTest, EventLatencyOSTouchHistograms) { |
894 base::HistogramTester histogram_tester; | 958 base::HistogramTester histogram_tester; |
895 ScopedXI2Event scoped_xevent; | 959 ScopedXI2Event scoped_xevent; |
896 | 960 |
897 // SetUp for test | 961 // SetUp for test |
898 DeviceDataManagerX11::CreateInstance(); | 962 DeviceDataManagerX11::CreateInstance(); |
899 std::vector<int> devices; | 963 std::vector<int> devices; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 button_event->type = ButtonPress; | 998 button_event->type = ButtonPress; |
935 button_event->button = 4; // A valid wheel button number between min and max. | 999 button_event->button = 4; // A valid wheel button number between min and max. |
936 MouseWheelEvent mouse_ev(&native_event); | 1000 MouseWheelEvent mouse_ev(&native_event); |
937 | 1001 |
938 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); | 1002 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); |
939 #endif | 1003 #endif |
940 } | 1004 } |
941 | 1005 |
942 | 1006 |
943 } // namespace ui | 1007 } // namespace ui |
OLD | NEW |