Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1499)

Side by Side Diff: content/browser/renderer_host/input/web_input_event_util_unittest.cc

Issue 712133003: Track whether a scroll sequence has been partially prevented (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/gesture_event_data.h"
16 #include "ui/events/gesture_detection/motion_event_generic.h" 17 #include "ui/events/gesture_detection/motion_event_generic.h"
18 #include "ui/events/gesture_event_details.h"
19 #include "ui/gfx/geometry/safe_integer_conversions.h"
17 20
18 using blink::WebInputEvent; 21 using blink::WebInputEvent;
19 using blink::WebTouchEvent; 22 using blink::WebTouchEvent;
20 using blink::WebTouchPoint; 23 using blink::WebTouchPoint;
21 using ui::MotionEvent; 24 using ui::MotionEvent;
22 using ui::MotionEventGeneric; 25 using ui::MotionEventGeneric;
23 26
24 namespace content { 27 namespace content {
25 28
26 TEST(WebInputEventUtilTest, MotionEventConversion) { 29 TEST(WebInputEventUtilTest, MotionEventConversion) {
(...skipping 24 matching lines...) Expand all
51 expected_pointer.radiusY = pointer.touch_minor / 2.f; 54 expected_pointer.radiusY = pointer.touch_minor / 2.f;
52 expected_pointer.rotationAngle = 0.f; 55 expected_pointer.rotationAngle = 0.f;
53 expected_pointer.force = pointer.pressure; 56 expected_pointer.force = pointer.pressure;
54 expected_event.touches[0] = expected_pointer; 57 expected_event.touches[0] = expected_pointer;
55 58
56 WebTouchEvent actual_event = CreateWebTouchEventFromMotionEvent(event); 59 WebTouchEvent actual_event = CreateWebTouchEventFromMotionEvent(event);
57 EXPECT_EQ(WebInputEventTraits::ToString(expected_event), 60 EXPECT_EQ(WebInputEventTraits::ToString(expected_event),
58 WebInputEventTraits::ToString(actual_event)); 61 WebInputEventTraits::ToString(actual_event));
59 } 62 }
60 63
64 TEST(WebInputEventUtilTest, ScrollUpdateConversion) {
65 int motion_event_id = 0;
66 MotionEvent::ToolType tool_type = MotionEvent::TOOL_TYPE_UNKNOWN;
67 base::TimeTicks timestamp = base::TimeTicks::Now();
68 gfx::Vector2dF delta(-5.f, 10.f);
69 gfx::PointF pos(1.f, 2.f);
70 gfx::PointF raw_pos(11.f, 12.f);
71 size_t touch_points = 1;
72 gfx::RectF rect(pos, gfx::SizeF());
73 int flags = 0;
74 ui::GestureEventDetails details(ui::ET_GESTURE_SCROLL_UPDATE,
75 delta.x(),
76 delta.y());
77 details.mark_previous_scroll_update_in_sequence_prevented();
78 ui::GestureEventData event(details,
79 motion_event_id,
80 tool_type,
81 timestamp,
82 pos.x(),
83 pos.y(),
84 raw_pos.x(),
85 raw_pos.y(),
86 touch_points,
87 rect,
88 flags);
89
90 blink::WebGestureEvent web_event =
91 CreateWebGestureEventFromGestureEventData(event);
92 EXPECT_EQ(WebInputEvent::GestureScrollUpdate, web_event.type);
93 EXPECT_EQ(0, web_event.modifiers);
94 EXPECT_EQ((timestamp - base::TimeTicks()).InSecondsF(),
95 web_event.timeStampSeconds);
96 EXPECT_EQ(gfx::ToFlooredInt(pos.x()), web_event.x);
97 EXPECT_EQ(gfx::ToFlooredInt(pos.y()), web_event.y);
98 EXPECT_EQ(gfx::ToFlooredInt(raw_pos.x()), web_event.globalX);
99 EXPECT_EQ(gfx::ToFlooredInt(raw_pos.y()), web_event.globalY);
100 EXPECT_EQ(blink::WebGestureDeviceTouchscreen, web_event.sourceDevice);
101 EXPECT_EQ(delta.x(), web_event.data.scrollUpdate.deltaX);
102 EXPECT_EQ(delta.y(), web_event.data.scrollUpdate.deltaY);
103 EXPECT_TRUE(web_event.data.scrollUpdate.previousUpdateInSequencePrevented);
104 }
105
61 } // namespace content 106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698