Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / input / web_input_event_util_unittest.cc
blob862d6c1486393143eb4d4026236233bc7be69290
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
3 // found in the LICENSE file.
5 // Needed on Windows to get |M_PI| from <cmath>.
6 #ifdef _WIN32
7 #define _USE_MATH_DEFINES
8 #endif
10 #include <cmath>
12 #include "content/browser/renderer_host/input/web_input_event_util.h"
13 #include "content/common/input/web_input_event_traits.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/events/blink/blink_event_util.h"
16 #include "ui/events/event_constants.h"
17 #include "ui/events/gesture_detection/gesture_event_data.h"
18 #include "ui/events/gesture_detection/motion_event_generic.h"
19 #include "ui/events/gesture_event_details.h"
20 #include "ui/gfx/geometry/safe_integer_conversions.h"
22 using blink::WebInputEvent;
23 using blink::WebTouchEvent;
24 using blink::WebTouchPoint;
25 using ui::MotionEvent;
26 using ui::MotionEventGeneric;
28 namespace content {
30 TEST(WebInputEventUtilTest, MotionEventConversion) {
31 ui::PointerProperties pointer(5, 10, 40);
32 pointer.id = 15;
33 pointer.raw_x = 20;
34 pointer.raw_y = 25;
35 pointer.pressure = 30;
36 pointer.touch_minor = 35;
37 pointer.orientation = static_cast<float>(-M_PI / 2);
38 MotionEventGeneric event(
39 MotionEvent::ACTION_DOWN, base::TimeTicks::Now(), pointer);
40 event.set_flags(ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
41 event.set_unique_event_id(123456U);
43 WebTouchEvent expected_event;
44 expected_event.type = WebInputEvent::TouchStart;
45 expected_event.touchesLength = 1;
46 expected_event.timeStampSeconds =
47 (event.GetEventTime() - base::TimeTicks()).InSecondsF();
48 expected_event.modifiers = WebInputEvent::ShiftKey | WebInputEvent::AltKey;
49 WebTouchPoint expected_pointer;
50 expected_pointer.id = pointer.id;
51 expected_pointer.state = WebTouchPoint::StatePressed;
52 expected_pointer.position = blink::WebFloatPoint(pointer.x, pointer.y);
53 expected_pointer.screenPosition =
54 blink::WebFloatPoint(pointer.raw_x, pointer.raw_y);
55 expected_pointer.radiusX = pointer.touch_major / 2.f;
56 expected_pointer.radiusY = pointer.touch_minor / 2.f;
57 expected_pointer.rotationAngle = 0.f;
58 expected_pointer.force = pointer.pressure;
59 expected_event.touches[0] = expected_pointer;
60 expected_event.uniqueTouchEventId = 123456U;
62 WebTouchEvent actual_event =
63 ui::CreateWebTouchEventFromMotionEvent(event, false);
64 EXPECT_EQ(WebInputEventTraits::ToString(expected_event),
65 WebInputEventTraits::ToString(actual_event));
68 TEST(WebInputEventUtilTest, ScrollUpdateConversion) {
69 int motion_event_id = 0;
70 MotionEvent::ToolType tool_type = MotionEvent::TOOL_TYPE_UNKNOWN;
71 base::TimeTicks timestamp = base::TimeTicks::Now();
72 gfx::Vector2dF delta(-5.f, 10.f);
73 gfx::PointF pos(1.f, 2.f);
74 gfx::PointF raw_pos(11.f, 12.f);
75 size_t touch_points = 1;
76 gfx::RectF rect(pos, gfx::SizeF());
77 int flags = 0;
78 ui::GestureEventDetails details(ui::ET_GESTURE_SCROLL_UPDATE,
79 delta.x(),
80 delta.y());
81 details.mark_previous_scroll_update_in_sequence_prevented();
82 ui::GestureEventData event(details,
83 motion_event_id,
84 tool_type,
85 timestamp,
86 pos.x(),
87 pos.y(),
88 raw_pos.x(),
89 raw_pos.y(),
90 touch_points,
91 rect,
92 flags);
94 blink::WebGestureEvent web_event =
95 ui::CreateWebGestureEventFromGestureEventData(event);
96 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, web_event.type);
97 EXPECT_EQ(0, web_event.modifiers);
98 EXPECT_EQ((timestamp - base::TimeTicks()).InSecondsF(),
99 web_event.timeStampSeconds);
100 EXPECT_EQ(gfx::ToFlooredInt(pos.x()), web_event.x);
101 EXPECT_EQ(gfx::ToFlooredInt(pos.y()), web_event.y);
102 EXPECT_EQ(gfx::ToFlooredInt(raw_pos.x()), web_event.globalX);
103 EXPECT_EQ(gfx::ToFlooredInt(raw_pos.y()), web_event.globalY);
104 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, web_event.sourceDevice);
105 EXPECT_EQ(delta.x(), web_event.data.scrollUpdate.deltaX);
106 EXPECT_EQ(delta.y(), web_event.data.scrollUpdate.deltaY);
107 EXPECT_TRUE(web_event.data.scrollUpdate.previousUpdateInSequencePrevented);
110 } // namespace content