Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / renderer_host / input / web_input_event_util_unittest.cc
blob0ea59b13063a071e9db18b6426beea44facca32f
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);
42 WebTouchEvent expected_event;
43 expected_event.type = WebInputEvent::TouchStart;
44 expected_event.touchesLength = 1;
45 expected_event.timeStampSeconds =
46 (event.GetEventTime() - base::TimeTicks()).InSecondsF();
47 expected_event.modifiers = WebInputEvent::ShiftKey | WebInputEvent::AltKey;
48 WebTouchPoint expected_pointer;
49 expected_pointer.id = pointer.id;
50 expected_pointer.state = WebTouchPoint::StatePressed;
51 expected_pointer.position = blink::WebFloatPoint(pointer.x, pointer.y);
52 expected_pointer.screenPosition =
53 blink::WebFloatPoint(pointer.raw_x, pointer.raw_y);
54 expected_pointer.radiusX = pointer.touch_major / 2.f;
55 expected_pointer.radiusY = pointer.touch_minor / 2.f;
56 expected_pointer.rotationAngle = 0.f;
57 expected_pointer.force = pointer.pressure;
58 expected_event.touches[0] = expected_pointer;
60 WebTouchEvent actual_event =
61 ui::CreateWebTouchEventFromMotionEvent(event, false);
62 EXPECT_EQ(WebInputEventTraits::ToString(expected_event),
63 WebInputEventTraits::ToString(actual_event));
66 TEST(WebInputEventUtilTest, ScrollUpdateConversion) {
67 int motion_event_id = 0;
68 MotionEvent::ToolType tool_type = MotionEvent::TOOL_TYPE_UNKNOWN;
69 base::TimeTicks timestamp = base::TimeTicks::Now();
70 gfx::Vector2dF delta(-5.f, 10.f);
71 gfx::PointF pos(1.f, 2.f);
72 gfx::PointF raw_pos(11.f, 12.f);
73 size_t touch_points = 1;
74 gfx::RectF rect(pos, gfx::SizeF());
75 int flags = 0;
76 ui::GestureEventDetails details(ui::ET_GESTURE_SCROLL_UPDATE,
77 delta.x(),
78 delta.y());
79 details.mark_previous_scroll_update_in_sequence_prevented();
80 ui::GestureEventData event(details,
81 motion_event_id,
82 tool_type,
83 timestamp,
84 pos.x(),
85 pos.y(),
86 raw_pos.x(),
87 raw_pos.y(),
88 touch_points,
89 rect,
90 flags);
92 blink::WebGestureEvent web_event =
93 ui::CreateWebGestureEventFromGestureEventData(event);
94 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, web_event.type);
95 EXPECT_EQ(0, web_event.modifiers);
96 EXPECT_EQ((timestamp - base::TimeTicks()).InSecondsF(),
97 web_event.timeStampSeconds);
98 EXPECT_EQ(gfx::ToFlooredInt(pos.x()), web_event.x);
99 EXPECT_EQ(gfx::ToFlooredInt(pos.y()), web_event.y);
100 EXPECT_EQ(gfx::ToFlooredInt(raw_pos.x()), web_event.globalX);
101 EXPECT_EQ(gfx::ToFlooredInt(raw_pos.y()), web_event.globalY);
102 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, web_event.sourceDevice);
103 EXPECT_EQ(delta.x(), web_event.data.scrollUpdate.deltaX);
104 EXPECT_EQ(delta.y(), web_event.data.scrollUpdate.deltaY);
105 EXPECT_TRUE(web_event.data.scrollUpdate.previousUpdateInSequencePrevented);
108 } // namespace content