Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // MSVC++ requires this to be set before any other includes to get M_PI. | |
| 6 #define _USE_MATH_DEFINES | |
| 7 | |
| 8 #include <cmath> | |
| 9 | |
| 10 #include "content/browser/renderer_host/input/motion_event_web.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "ui/events/blink/blink_event_util.h" | |
| 13 #include "ui/events/gesture_detection/motion_event_generic.h" | |
| 14 #include "ui/events/test/motion_event_test_utils.h" | |
| 15 | |
| 16 using ui::MotionEvent; | |
| 17 using ui::MotionEventGeneric; | |
| 18 using ui::PointerProperties; | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 TEST(MotionEventWebTest, Constructor) { | |
| 23 const float pi = static_cast<float>(M_PI); | |
| 24 const float orientations[] = { | |
| 25 -pi, -2.f * pi / 3, -pi / 3, 0.f, pi / 3, 2.f * pi / 3}; | |
| 26 const float tilts[] = {0.f, pi / 4, pi / 3}; | |
| 27 const MotionEvent::ToolType tool_types[] = {MotionEvent::TOOL_TYPE_FINGER, | |
| 28 MotionEvent::TOOL_TYPE_STYLUS, | |
| 29 MotionEvent::TOOL_TYPE_MOUSE}; | |
| 30 | |
| 31 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 32 PointerProperties pp; | |
| 33 MotionEventGeneric generic_event(MotionEvent::ACTION_MOVE, event_time, pp); | |
| 34 | |
| 35 for (MotionEvent::ToolType tool_type : tool_types) { | |
| 36 for (float orientation : orientations) { | |
| 37 for (float tilt : tilts) { | |
| 38 PointerProperties pp2; | |
| 39 pp2.orientation = orientation; | |
| 40 pp2.tilt = tilt; | |
| 41 pp2.tool_type = tool_type; | |
| 42 size_t pointer_index = generic_event.PushPointer(pp2); | |
| 43 EXPECT_GT(pointer_index, 0u); | |
| 44 | |
| 45 blink::WebTouchEvent web_touch_event = | |
| 46 CreateWebTouchEventFromMotionEvent(generic_event, true); | |
| 47 | |
| 48 MotionEventWeb event(web_touch_event); | |
| 49 EXPECT_EQ(tool_type, event.GetToolType(pointer_index)); | |
| 50 if (tool_type == MotionEvent::TOOL_TYPE_STYLUS) { | |
| 51 // Web touch event touch point tilt plane angles are stored as ints, | |
| 52 // thus the tilt precision is 1 degree and the error should not be | |
| 53 // greater than 0.5 degrees. | |
| 54 EXPECT_NEAR(tilt, event.GetTilt(pointer_index), 0.5f * M_PI / 180.f) | |
| 55 << " orientation=" << orientation; | |
| 56 } else { | |
| 57 EXPECT_EQ(0.f, event.GetTilt(pointer_index)); | |
| 58 } | |
| 59 if (tool_type == MotionEvent::TOOL_TYPE_STYLUS && tilt > 0.f) { | |
| 60 // Full stylus tilt orientation information survives above event | |
| 61 // conversions only if there is a non-zero stylus tilt angle. | |
|
mustaq
2015/10/30 14:58:14
Please add a ref to crbug.com/493728 here. I think
e_hakkinen
2015/10/30 15:45:24
Done.
| |
| 62 EXPECT_NEAR(orientation, event.GetOrientation(pointer_index), 1e-4) | |
| 63 << " tilt=" << tilt; | |
| 64 } else { | |
| 65 // For non-stylus pointers and for styluses with a zero tilt angle, | |
| 66 // orientation quadrant information is lost. | |
| 67 EXPECT_NEAR(fmod(orientation + M_PI, M_PI_2), | |
| 68 event.GetOrientation(pointer_index), 1e-4); | |
| 69 } | |
| 70 | |
| 71 generic_event.RemovePointerAt(pointer_index); | |
| 72 } | |
| 73 } | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 } // namespace content | |
| OLD | NEW |