| OLD | NEW | 
|   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[] = {-pi, -2.f * pi / 3, -pi / 2}; | 
|  27       -pi, -2.f * pi / 3, -pi / 2, -pi / 3, 0.f, pi / 3, pi / 2, 2.f * pi / 3}; |  27   const float tilts_x[] = {0.f, -180 / 4, -180 / 3}; | 
|  28   const float tilts[] = {0.f, pi / 4, pi / 3}; |  28   const float tilts_y[] = {0.5f, 180 / 2, 180 / 3}; | 
|  29   const MotionEvent::ToolType tool_types[] = {MotionEvent::TOOL_TYPE_FINGER, |  29   const MotionEvent::ToolType tool_types[] = {MotionEvent::TOOL_TYPE_FINGER, | 
|  30                                               MotionEvent::TOOL_TYPE_STYLUS, |  30                                               MotionEvent::TOOL_TYPE_STYLUS, | 
|  31                                               MotionEvent::TOOL_TYPE_MOUSE}; |  31                                               MotionEvent::TOOL_TYPE_MOUSE}; | 
|  32  |  32  | 
|  33   base::TimeTicks event_time = base::TimeTicks::Now(); |  33   base::TimeTicks event_time = base::TimeTicks::Now(); | 
|  34   PointerProperties pp; |  34   PointerProperties pp; | 
|  35   MotionEventGeneric generic_event(MotionEvent::ACTION_MOVE, event_time, pp); |  35   MotionEventGeneric generic_event(MotionEvent::ACTION_MOVE, event_time, pp); | 
 |  36   for (MotionEvent::ToolType tool_type : tool_types) { | 
 |  37     for (size_t i = 0; i < arraysize(tilts_x); ++i) { | 
 |  38       const float tilt_x = tilts_x[i]; | 
 |  39       const float tilt_y = tilts_y[i]; | 
 |  40       const float orientation = orientations[i]; | 
 |  41       PointerProperties pp2; | 
 |  42       pp2.orientation = orientation; | 
 |  43       pp2.tilt_x = tilt_x; | 
 |  44       pp2.tilt_y = tilt_y; | 
 |  45       pp2.tool_type = tool_type; | 
 |  46       size_t pointer_index = generic_event.PushPointer(pp2); | 
 |  47       EXPECT_GT(pointer_index, 0u); | 
|  36  |  48  | 
|  37   for (MotionEvent::ToolType tool_type : tool_types) { |  49       blink::WebTouchEvent web_touch_event = | 
|  38     for (float orientation : orientations) { |  50           CreateWebTouchEventFromMotionEvent(generic_event, true); | 
|  39       for (float tilt : tilts) { |  | 
|  40         PointerProperties pp2; |  | 
|  41         pp2.orientation = orientation; |  | 
|  42         pp2.tilt = tilt; |  | 
|  43         pp2.tool_type = tool_type; |  | 
|  44         size_t pointer_index = generic_event.PushPointer(pp2); |  | 
|  45         EXPECT_GT(pointer_index, 0u); |  | 
|  46  |  51  | 
|  47         blink::WebTouchEvent web_touch_event = |  52       MotionEventWeb event(web_touch_event); | 
|  48             CreateWebTouchEventFromMotionEvent(generic_event, true); |  53       EXPECT_EQ(tool_type, event.GetToolType(pointer_index)); | 
 |  54       if (tool_type == MotionEvent::TOOL_TYPE_STYLUS) { | 
 |  55         // Web touch event touch point tilt plane angles are stored as ints, | 
 |  56         // thus the tilt precision is 1 degree and the error should not be | 
 |  57         // greater than 0.5 degrees. | 
 |  58         EXPECT_NEAR(tilt_x, event.GetTiltX(pointer_index), 0.5) | 
 |  59             << " orientation=" << orientation; | 
 |  60         EXPECT_NEAR(tilt_y, event.GetTiltY(pointer_index), 0.5) | 
 |  61             << " orientation=" << orientation; | 
 |  62       } else { | 
 |  63         EXPECT_EQ(0.f, event.GetTiltX(pointer_index)); | 
 |  64         EXPECT_EQ(0.f, event.GetTiltY(pointer_index)); | 
 |  65       } | 
 |  66       if (tool_type == MotionEvent::TOOL_TYPE_STYLUS && tilt_x > 0.f) { | 
 |  67         // Full stylus tilt orientation information survives above event | 
 |  68         // conversions only if there is a non-zero stylus tilt angle. | 
 |  69         // See: http://crbug.com/251330 | 
 |  70         EXPECT_NEAR(orientation, event.GetOrientation(pointer_index), 1e-4) | 
 |  71             << " tilt_x=" << tilt_x << " tilt_y=" << tilt_y; | 
 |  72       } else { | 
 |  73         // For non-stylus pointers and for styluses with a zero tilt angle, | 
 |  74         // orientation quadrant information is lost. | 
 |  75         EXPECT_NEAR(fmod(orientation + M_PI + 1e-4, M_PI_2) - 1e-4, | 
 |  76                     event.GetOrientation(pointer_index), 1e-4); | 
 |  77       } | 
|  49  |  78  | 
|  50         MotionEventWeb event(web_touch_event); |  79       generic_event.RemovePointerAt(pointer_index); | 
|  51         EXPECT_EQ(tool_type, event.GetToolType(pointer_index)); |  | 
|  52         if (tool_type == MotionEvent::TOOL_TYPE_STYLUS) { |  | 
|  53           // 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 |  | 
|  55           // greater than 0.5 degrees. |  | 
|  56           EXPECT_NEAR(tilt, event.GetTilt(pointer_index), 0.5f * M_PI / 180.f) |  | 
|  57               << " orientation=" << orientation; |  | 
|  58         } else { |  | 
|  59           EXPECT_EQ(0.f, event.GetTilt(pointer_index)); |  | 
|  60         } |  | 
|  61         if (tool_type == MotionEvent::TOOL_TYPE_STYLUS && tilt > 0.f) { |  | 
|  62           // Full stylus tilt orientation information survives above event |  | 
|  63           // conversions only if there is a non-zero stylus tilt angle. |  | 
|  64           // See: http://crbug.com/251330 |  | 
|  65           EXPECT_NEAR(orientation, event.GetOrientation(pointer_index), 1e-4) |  | 
|  66               << " tilt=" << tilt; |  | 
|  67         } else { |  | 
|  68           // For non-stylus pointers and for styluses with a zero tilt angle, |  | 
|  69           // orientation quadrant information is lost. |  | 
|  70           EXPECT_NEAR(fmod(orientation + M_PI + 1e-4, M_PI_2) - 1e-4, |  | 
|  71                       event.GetOrientation(pointer_index), 1e-4); |  | 
|  72         } |  | 
|  73  |  | 
|  74         generic_event.RemovePointerAt(pointer_index); |  | 
|  75       } |  | 
|  76     } |  | 
|  77   } |  80   } | 
|  78 } |  81 } | 
 |  82 } | 
|  79  |  83  | 
|  80 }  // namespace content |  84 }  // namespace content | 
| OLD | NEW |