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 // Needed on Windows to get |M_PI| from <cmath>. | 5 // Needed on Windows to get |M_PI| from <cmath>. |
6 #ifdef _WIN32 | 6 #ifdef _WIN32 |
7 #define _USE_MATH_DEFINES | 7 #define _USE_MATH_DEFINES |
8 #endif | 8 #endif |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
11 | 11 |
12 #include "content/browser/renderer_host/input/web_input_event_util.h" | 12 #include "content/browser/renderer_host/input/web_input_event_util.h" |
13 #include "content/common/input/web_input_event_traits.h" | 13 #include "content/common/input/web_input_event_traits.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/events/event_constants.h" | 15 #include "ui/events/event_constants.h" |
16 #include "ui/events/gesture_detection/motion_event_generic.h" | 16 #include "ui/events/gesture_detection/motion_event_generic.h" |
17 | 17 |
18 using blink::WebInputEvent; | 18 using blink::WebInputEvent; |
19 using blink::WebTouchEvent; | 19 using blink::WebTouchEvent; |
20 using blink::WebTouchPoint; | 20 using blink::WebTouchPoint; |
21 using ui::MotionEvent; | 21 using ui::MotionEvent; |
22 using ui::MotionEventGeneric; | 22 using ui::MotionEventGeneric; |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
26 TEST(WebInputEventUtilTest, MotionEventConversion) { | 26 TEST(WebInputEventUtilTest, MotionEventConversion) { |
27 ui::PointerProperties pointer(5, 10); | 27 ui::PointerProperties pointer(5, 10, 40); |
28 pointer.id = 15; | 28 pointer.id = 15; |
29 pointer.raw_x = 20; | 29 pointer.raw_x = 20; |
30 pointer.raw_y = 25; | 30 pointer.raw_y = 25; |
31 pointer.pressure = 30; | 31 pointer.pressure = 30; |
32 pointer.touch_minor = 35; | 32 pointer.touch_minor = 35; |
33 pointer.touch_major = 40; | |
34 pointer.orientation = static_cast<float>(-M_PI / 2); | 33 pointer.orientation = static_cast<float>(-M_PI / 2); |
35 MotionEventGeneric event( | 34 MotionEventGeneric event( |
36 MotionEvent::ACTION_DOWN, base::TimeTicks::Now(), pointer); | 35 MotionEvent::ACTION_DOWN, base::TimeTicks::Now(), pointer); |
37 event.set_flags(ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); | 36 event.set_flags(ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
38 | 37 |
39 WebTouchEvent expected_event; | 38 WebTouchEvent expected_event; |
40 expected_event.type = WebInputEvent::TouchStart; | 39 expected_event.type = WebInputEvent::TouchStart; |
41 expected_event.touchesLength = 1; | 40 expected_event.touchesLength = 1; |
42 expected_event.timeStampSeconds = | 41 expected_event.timeStampSeconds = |
43 (event.GetEventTime() - base::TimeTicks()).InSecondsF(); | 42 (event.GetEventTime() - base::TimeTicks()).InSecondsF(); |
44 expected_event.modifiers = WebInputEvent::ShiftKey | WebInputEvent::AltKey; | 43 expected_event.modifiers = WebInputEvent::ShiftKey | WebInputEvent::AltKey; |
45 WebTouchPoint expected_pointer; | 44 WebTouchPoint expected_pointer; |
46 expected_pointer.id = pointer.id; | 45 expected_pointer.id = pointer.id; |
47 expected_pointer.state = WebTouchPoint::StatePressed; | 46 expected_pointer.state = WebTouchPoint::StatePressed; |
48 expected_pointer.position = blink::WebFloatPoint(pointer.x, pointer.y); | 47 expected_pointer.position = blink::WebFloatPoint(pointer.x, pointer.y); |
49 expected_pointer.screenPosition = | 48 expected_pointer.screenPosition = |
50 blink::WebFloatPoint(pointer.raw_x, pointer.raw_y); | 49 blink::WebFloatPoint(pointer.raw_x, pointer.raw_y); |
51 expected_pointer.radiusX = pointer.touch_major / 2.f; | 50 expected_pointer.radiusX = pointer.touch_major / 2.f; |
52 expected_pointer.radiusY = pointer.touch_minor / 2.f; | 51 expected_pointer.radiusY = pointer.touch_minor / 2.f; |
53 expected_pointer.rotationAngle = 0.f; | 52 expected_pointer.rotationAngle = 0.f; |
54 expected_pointer.force = pointer.pressure; | 53 expected_pointer.force = pointer.pressure; |
55 expected_event.touches[0] = expected_pointer; | 54 expected_event.touches[0] = expected_pointer; |
56 | 55 |
57 WebTouchEvent actual_event = CreateWebTouchEventFromMotionEvent(event); | 56 WebTouchEvent actual_event = CreateWebTouchEventFromMotionEvent(event); |
58 EXPECT_EQ(WebInputEventTraits::ToString(expected_event), | 57 EXPECT_EQ(WebInputEventTraits::ToString(expected_event), |
59 WebInputEventTraits::ToString(actual_event)); | 58 WebInputEventTraits::ToString(actual_event)); |
60 } | 59 } |
61 | 60 |
62 } // namespace content | 61 } // namespace content |
OLD | NEW |