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

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

Issue 2860793003: Pass through tilt_x and tilt_y to blink (Closed)
Patch Set: Pass through tilt_x and tilt_y to blink Created 3 years, 7 months 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <cmath> 10 #include <cmath>
11 11
12 #include "content/browser/renderer_host/input/motion_event_web.h" 12 #include "content/browser/renderer_host/input/motion_event_web.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/events/blink/blink_event_util.h" 14 #include "ui/events/blink/blink_event_util.h"
15 #include "ui/events/gesture_detection/motion_event_generic.h" 15 #include "ui/events/gesture_detection/motion_event_generic.h"
16 #include "ui/events/test/motion_event_test_utils.h" 16 #include "ui/events/test/motion_event_test_utils.h"
17 17
18 using ui::MotionEvent; 18 using ui::MotionEvent;
19 using ui::MotionEventGeneric; 19 using ui::MotionEventGeneric;
20 using ui::PointerProperties; 20 using ui::PointerProperties;
21 21
22 namespace content { 22 namespace content {
23 23
24 TEST(MotionEventWebTest, Constructor) { 24 TEST(MotionEventWebTest, Constructor) {
25 const float pi = static_cast<float>(M_PI); 25 const float pi = static_cast<float>(M_PI);
26 const float orientations[] = { 26 const float orientations[] = {
27 -pi, -2.f * pi / 3, -pi / 2, -pi / 3, 0.f, pi / 3, pi / 2, 2.f * pi / 3}; 27 -pi, -2.f * pi / 3, -pi / 2, -pi / 3, 0.f, pi / 3, pi / 2, 2.f * pi / 3};
28 const float tilts[] = {0.f, pi / 4, pi / 3}; 28 const float tilts_x[] = {0.f, -180 / 4, -180 / 3};
29 const float tilts_y[] = {0.5f, 180 / 2, 180 / 3};
29 const MotionEvent::ToolType tool_types[] = {MotionEvent::TOOL_TYPE_FINGER, 30 const MotionEvent::ToolType tool_types[] = {MotionEvent::TOOL_TYPE_FINGER,
30 MotionEvent::TOOL_TYPE_STYLUS, 31 MotionEvent::TOOL_TYPE_STYLUS,
31 MotionEvent::TOOL_TYPE_MOUSE}; 32 MotionEvent::TOOL_TYPE_MOUSE};
32 33
33 base::TimeTicks event_time = base::TimeTicks::Now(); 34 base::TimeTicks event_time = base::TimeTicks::Now();
34 PointerProperties pp; 35 PointerProperties pp;
35 MotionEventGeneric generic_event(MotionEvent::ACTION_MOVE, event_time, pp); 36 MotionEventGeneric generic_event(MotionEvent::ACTION_MOVE, event_time, pp);
36 37
37 for (MotionEvent::ToolType tool_type : tool_types) { 38 for (MotionEvent::ToolType tool_type : tool_types) {
38 for (float orientation : orientations) { 39 for (float orientation : orientations) {
use mustaq_at_chromium.org 2017/05/15 19:46:53 We don't need nested testing anymore since event c
jkwang 2017/05/16 01:13:26 Done.
39 for (float tilt : tilts) { 40 for (size_t i = 0; i < arraysize(tilts_x); ++i) {
41 const float tilt_x = tilts_x[i];
42 const float tilt_y = tilts_y[i];
40 PointerProperties pp2; 43 PointerProperties pp2;
41 pp2.orientation = orientation; 44 pp2.orientation = orientation;
42 pp2.tilt = tilt; 45 pp2.tilt_x = tilt_x;
46 pp2.tilt_y = tilt_y;
43 pp2.tool_type = tool_type; 47 pp2.tool_type = tool_type;
44 size_t pointer_index = generic_event.PushPointer(pp2); 48 size_t pointer_index = generic_event.PushPointer(pp2);
45 EXPECT_GT(pointer_index, 0u); 49 EXPECT_GT(pointer_index, 0u);
46 50
47 blink::WebTouchEvent web_touch_event = 51 blink::WebTouchEvent web_touch_event =
48 CreateWebTouchEventFromMotionEvent(generic_event, true); 52 CreateWebTouchEventFromMotionEvent(generic_event, true);
49 53
50 MotionEventWeb event(web_touch_event); 54 MotionEventWeb event(web_touch_event);
51 EXPECT_EQ(tool_type, event.GetToolType(pointer_index)); 55 EXPECT_EQ(tool_type, event.GetToolType(pointer_index));
52 if (tool_type == MotionEvent::TOOL_TYPE_STYLUS) { 56 if (tool_type == MotionEvent::TOOL_TYPE_STYLUS) {
53 // Web touch event touch point tilt plane angles are stored as ints, 57 // Web touch event touch point tilt plane angles are stored as ints,
54 // thus the tilt precision is 1 degree and the error should not be 58 // thus the tilt precision is 1 degree and the error should not be
55 // greater than 0.5 degrees. 59 // greater than 0.5 degrees.
56 EXPECT_NEAR(tilt, event.GetTilt(pointer_index), 0.5f * M_PI / 180.f) 60 EXPECT_NEAR(tilt_x, event.GetTiltX(pointer_index), 0.5)
61 << " orientation=" << orientation;
62 EXPECT_NEAR(tilt_y, event.GetTiltY(pointer_index), 0.5)
57 << " orientation=" << orientation; 63 << " orientation=" << orientation;
58 } else { 64 } else {
59 EXPECT_EQ(0.f, event.GetTilt(pointer_index)); 65 EXPECT_EQ(0.f, event.GetTiltX(pointer_index));
66 EXPECT_EQ(0.f, event.GetTiltY(pointer_index));
60 } 67 }
61 if (tool_type == MotionEvent::TOOL_TYPE_STYLUS && tilt > 0.f) { 68 if (tool_type == MotionEvent::TOOL_TYPE_STYLUS && tilt_x > 0.f) {
62 // Full stylus tilt orientation information survives above event 69 // Full stylus tilt orientation information survives above event
63 // conversions only if there is a non-zero stylus tilt angle. 70 // conversions only if there is a non-zero stylus tilt angle.
64 // See: http://crbug.com/251330 71 // See: http://crbug.com/251330
65 EXPECT_NEAR(orientation, event.GetOrientation(pointer_index), 1e-4) 72 EXPECT_NEAR(orientation, event.GetOrientation(pointer_index), 1e-4)
66 << " tilt=" << tilt; 73 << " tilt_x=" << tilt_x << " tilt_y=" << tilt_y;
67 } else { 74 } else {
68 // For non-stylus pointers and for styluses with a zero tilt angle, 75 // For non-stylus pointers and for styluses with a zero tilt angle,
69 // orientation quadrant information is lost. 76 // orientation quadrant information is lost.
70 EXPECT_NEAR(fmod(orientation + M_PI + 1e-4, M_PI_2) - 1e-4, 77 EXPECT_NEAR(fmod(orientation + M_PI + 1e-4, M_PI_2) - 1e-4,
71 event.GetOrientation(pointer_index), 1e-4); 78 event.GetOrientation(pointer_index), 1e-4);
72 } 79 }
73 80
74 generic_event.RemovePointerAt(pointer_index); 81 generic_event.RemovePointerAt(pointer_index);
75 } 82 }
76 } 83 }
77 } 84 }
78 } 85 }
79 86
80 } // namespace content 87 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698