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 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, nullptr)); | 902 ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, nullptr)); |
903 } | 903 } |
904 | 904 |
905 TEST(EventTest, PointerEventToMouseEvent) { | 905 TEST(EventTest, PointerEventToMouseEvent) { |
906 const struct { | 906 const struct { |
907 ui::EventType in_type; | 907 ui::EventType in_type; |
908 ui::EventType out_type; | 908 ui::EventType out_type; |
909 gfx::Point location; | 909 gfx::Point location; |
910 gfx::Point root_location; | 910 gfx::Point root_location; |
911 int flags; | 911 int flags; |
| 912 int changed_button_flags; |
912 } kTestData[] = { | 913 } kTestData[] = { |
913 {ui::ET_POINTER_DOWN, ui::ET_MOUSE_PRESSED, gfx::Point(10, 20), | 914 {ui::ET_POINTER_DOWN, ui::ET_MOUSE_PRESSED, gfx::Point(10, 20), |
914 gfx::Point(110, 120), 0}, | 915 gfx::Point(110, 120), 0, 0}, |
915 {ui::ET_POINTER_MOVED, ui::ET_MOUSE_MOVED, gfx::Point(20, 10), | 916 {ui::ET_POINTER_MOVED, ui::ET_MOUSE_MOVED, gfx::Point(20, 10), |
916 gfx::Point(1, 2), 0}, | 917 gfx::Point(1, 2), 0, 0}, |
917 {ui::ET_POINTER_MOVED, ui::ET_MOUSE_DRAGGED, gfx::Point(20, 10), | 918 {ui::ET_POINTER_MOVED, ui::ET_MOUSE_DRAGGED, gfx::Point(20, 10), |
918 gfx::Point(1, 2), EF_LEFT_MOUSE_BUTTON}, | 919 gfx::Point(1, 2), EF_LEFT_MOUSE_BUTTON, 0}, |
919 {ui::ET_POINTER_MOVED, ui::ET_MOUSE_DRAGGED, gfx::Point(20, 10), | 920 {ui::ET_POINTER_MOVED, ui::ET_MOUSE_DRAGGED, gfx::Point(20, 10), |
920 gfx::Point(1, 2), EF_RIGHT_MOUSE_BUTTON}, | 921 gfx::Point(1, 2), EF_RIGHT_MOUSE_BUTTON, 0}, |
921 {ui::ET_POINTER_MOVED, ui::ET_MOUSE_DRAGGED, gfx::Point(20, 10), | 922 {ui::ET_POINTER_MOVED, ui::ET_MOUSE_DRAGGED, gfx::Point(20, 10), |
922 gfx::Point(1, 2), EF_MIDDLE_MOUSE_BUTTON}, | 923 gfx::Point(1, 2), EF_MIDDLE_MOUSE_BUTTON, 0}, |
923 {ui::ET_POINTER_ENTERED, ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(), | 924 {ui::ET_POINTER_ENTERED, ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(), |
924 EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON}, | 925 EF_MIDDLE_MOUSE_BUTTON | EF_RIGHT_MOUSE_BUTTON, 0}, |
925 {ui::ET_POINTER_EXITED, ui::ET_MOUSE_EXITED, gfx::Point(5, 1), | 926 {ui::ET_POINTER_EXITED, ui::ET_MOUSE_EXITED, gfx::Point(5, 1), |
926 gfx::Point(1, 5), EF_RIGHT_MOUSE_BUTTON}, | 927 gfx::Point(1, 5), EF_RIGHT_MOUSE_BUTTON, 0}, |
927 {ui::ET_POINTER_UP, ui::ET_MOUSE_RELEASED, gfx::Point(1000, 1000), | 928 {ui::ET_POINTER_UP, ui::ET_MOUSE_RELEASED, gfx::Point(1000, 1000), |
928 gfx::Point(14, 15), EF_MIDDLE_MOUSE_BUTTON}}; | 929 gfx::Point(14, 15), EF_MIDDLE_MOUSE_BUTTON, EF_MIDDLE_MOUSE_BUTTON}}; |
929 | 930 |
930 for (size_t i = 0; i < arraysize(kTestData); i++) { | 931 for (size_t i = 0; i < arraysize(kTestData); i++) { |
931 ui::PointerEvent pointer_event( | 932 ui::PointerEvent pointer_event( |
932 kTestData[i].in_type, kTestData[i].location, kTestData[i].root_location, | 933 kTestData[i].in_type, kTestData[i].location, kTestData[i].root_location, |
933 kTestData[i].flags, 0, | 934 kTestData[i].flags, 0, kTestData[i].changed_button_flags, |
934 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), | 935 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), |
935 base::TimeTicks()); | 936 base::TimeTicks()); |
936 ui::MouseEvent mouse_event(pointer_event); | 937 ui::MouseEvent mouse_event(pointer_event); |
937 | 938 |
938 EXPECT_EQ(kTestData[i].out_type, mouse_event.type()); | 939 EXPECT_EQ(kTestData[i].out_type, mouse_event.type()); |
939 EXPECT_EQ(kTestData[i].location, mouse_event.location()); | 940 EXPECT_EQ(kTestData[i].location, mouse_event.location()); |
940 EXPECT_EQ(kTestData[i].root_location, mouse_event.root_location()); | 941 EXPECT_EQ(kTestData[i].root_location, mouse_event.root_location()); |
941 EXPECT_EQ(kTestData[i].flags, mouse_event.flags()); | 942 EXPECT_EQ(kTestData[i].flags, mouse_event.flags()); |
| 943 EXPECT_EQ(kTestData[i].changed_button_flags, |
| 944 mouse_event.changed_button_flags()); |
942 } | 945 } |
943 } | 946 } |
944 | 947 |
945 TEST(EventTest, PointerEventToTouchEventType) { | 948 TEST(EventTest, PointerEventToTouchEventType) { |
946 ui::EventType kTouchTypeMap[][2] = { | 949 ui::EventType kTouchTypeMap[][2] = { |
947 {ui::ET_POINTER_DOWN, ui::ET_TOUCH_PRESSED}, | 950 {ui::ET_POINTER_DOWN, ui::ET_TOUCH_PRESSED}, |
948 {ui::ET_POINTER_MOVED, ui::ET_TOUCH_MOVED}, | 951 {ui::ET_POINTER_MOVED, ui::ET_TOUCH_MOVED}, |
949 {ui::ET_POINTER_UP, ui::ET_TOUCH_RELEASED}, | 952 {ui::ET_POINTER_UP, ui::ET_TOUCH_RELEASED}, |
950 {ui::ET_POINTER_CANCELLED, ui::ET_TOUCH_CANCELLED}, | 953 {ui::ET_POINTER_CANCELLED, ui::ET_TOUCH_CANCELLED}, |
951 }; | 954 }; |
952 | 955 |
953 for (size_t i = 0; i < arraysize(kTouchTypeMap); i++) { | 956 for (size_t i = 0; i < arraysize(kTouchTypeMap); i++) { |
954 ui::PointerEvent pointer_event( | 957 ui::PointerEvent pointer_event( |
955 kTouchTypeMap[i][0], gfx::Point(), gfx::Point(), 0, 0, | 958 kTouchTypeMap[i][0], gfx::Point(), gfx::Point(), 0, 0, 0, |
956 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), | 959 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), |
957 base::TimeTicks()); | 960 base::TimeTicks()); |
958 ui::TouchEvent touch_event(pointer_event); | 961 ui::TouchEvent touch_event(pointer_event); |
959 | 962 |
960 EXPECT_EQ(kTouchTypeMap[i][1], touch_event.type()); | 963 EXPECT_EQ(kTouchTypeMap[i][1], touch_event.type()); |
961 } | 964 } |
962 } | 965 } |
963 | 966 |
964 TEST(EventTest, PointerEventToTouchEventDetails) { | 967 TEST(EventTest, PointerEventToTouchEventDetails) { |
965 ui::PointerEvent pointer_event( | 968 ui::PointerEvent pointer_event( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 XButtonEvent* button_event = &(native_event.xbutton); | 1023 XButtonEvent* button_event = &(native_event.xbutton); |
1021 button_event->type = ButtonPress; | 1024 button_event->type = ButtonPress; |
1022 button_event->button = 4; // A valid wheel button number between min and max. | 1025 button_event->button = 4; // A valid wheel button number between min and max. |
1023 MouseWheelEvent mouse_ev(&native_event); | 1026 MouseWheelEvent mouse_ev(&native_event); |
1024 | 1027 |
1025 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); | 1028 histogram_tester.ExpectTotalCount("Event.Latency.OS.MOUSE_WHEEL", 1); |
1026 #endif | 1029 #endif |
1027 } | 1030 } |
1028 | 1031 |
1029 } // namespace ui | 1032 } // namespace ui |
OLD | NEW |