OLD | NEW |
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 #include "ui/events/gestures/gesture_provider_aura.h" | 5 #include "ui/events/gestures/gesture_provider_aura.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 GestureProviderAura* provider() { return provider_.get(); } | 32 GestureProviderAura* provider() { return provider_.get(); } |
33 | 33 |
34 private: | 34 private: |
35 std::unique_ptr<GestureConsumer> consumer_; | 35 std::unique_ptr<GestureConsumer> consumer_; |
36 std::unique_ptr<GestureProviderAura> provider_; | 36 std::unique_ptr<GestureProviderAura> provider_; |
37 base::MessageLoopForUI message_loop_; | 37 base::MessageLoopForUI message_loop_; |
38 }; | 38 }; |
39 | 39 |
40 TEST_F(GestureProviderAuraTest, IgnoresExtraPressEvents) { | 40 TEST_F(GestureProviderAuraTest, IgnoresExtraPressEvents) { |
41 base::TimeDelta time = ui::EventTimeForNow(); | 41 base::TimeTicks time = ui::EventTimeForNow(); |
42 TouchEvent press1(ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, time); | 42 TouchEvent press1(ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, time); |
43 EXPECT_TRUE(provider()->OnTouchEvent(&press1)); | 43 EXPECT_TRUE(provider()->OnTouchEvent(&press1)); |
44 | 44 |
45 time += base::TimeDelta::FromMilliseconds(10); | 45 time += base::TimeDelta::FromMilliseconds(10); |
46 TouchEvent press2(ET_TOUCH_PRESSED, gfx::Point(30, 40), 0, time); | 46 TouchEvent press2(ET_TOUCH_PRESSED, gfx::Point(30, 40), 0, time); |
47 EXPECT_FALSE(provider()->OnTouchEvent(&press2)); | 47 EXPECT_FALSE(provider()->OnTouchEvent(&press2)); |
48 } | 48 } |
49 | 49 |
50 TEST_F(GestureProviderAuraTest, IgnoresExtraMoveOrReleaseEvents) { | 50 TEST_F(GestureProviderAuraTest, IgnoresExtraMoveOrReleaseEvents) { |
51 base::TimeDelta time = ui::EventTimeForNow(); | 51 base::TimeTicks time = ui::EventTimeForNow(); |
52 TouchEvent press1(ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, time); | 52 TouchEvent press1(ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, time); |
53 EXPECT_TRUE(provider()->OnTouchEvent(&press1)); | 53 EXPECT_TRUE(provider()->OnTouchEvent(&press1)); |
54 | 54 |
55 time += base::TimeDelta::FromMilliseconds(10); | 55 time += base::TimeDelta::FromMilliseconds(10); |
56 TouchEvent release1(ET_TOUCH_RELEASED, gfx::Point(30, 40), 0, time); | 56 TouchEvent release1(ET_TOUCH_RELEASED, gfx::Point(30, 40), 0, time); |
57 EXPECT_TRUE(provider()->OnTouchEvent(&release1)); | 57 EXPECT_TRUE(provider()->OnTouchEvent(&release1)); |
58 | 58 |
59 time += base::TimeDelta::FromMilliseconds(10); | 59 time += base::TimeDelta::FromMilliseconds(10); |
60 TouchEvent release2(ET_TOUCH_RELEASED, gfx::Point(30, 45), 0, time); | 60 TouchEvent release2(ET_TOUCH_RELEASED, gfx::Point(30, 45), 0, time); |
61 EXPECT_FALSE(provider()->OnTouchEvent(&release1)); | 61 EXPECT_FALSE(provider()->OnTouchEvent(&release1)); |
62 | 62 |
63 time += base::TimeDelta::FromMilliseconds(10); | 63 time += base::TimeDelta::FromMilliseconds(10); |
64 TouchEvent move1(ET_TOUCH_MOVED, gfx::Point(70, 75), 0, time); | 64 TouchEvent move1(ET_TOUCH_MOVED, gfx::Point(70, 75), 0, time); |
65 EXPECT_FALSE(provider()->OnTouchEvent(&move1)); | 65 EXPECT_FALSE(provider()->OnTouchEvent(&move1)); |
66 } | 66 } |
67 | 67 |
68 TEST_F(GestureProviderAuraTest, IgnoresIdenticalMoveEvents) { | 68 TEST_F(GestureProviderAuraTest, IgnoresIdenticalMoveEvents) { |
69 const float kRadiusX = 20.f; | 69 const float kRadiusX = 20.f; |
70 const float kRadiusY = 30.f; | 70 const float kRadiusY = 30.f; |
71 const float kAngle = 0.321f; | 71 const float kAngle = 0.321f; |
72 const float kForce = 40.f; | 72 const float kForce = 40.f; |
73 const int kTouchId0 = 5; | 73 const int kTouchId0 = 5; |
74 const int kTouchId1 = 3; | 74 const int kTouchId1 = 3; |
75 | 75 |
76 base::TimeDelta time = ui::EventTimeForNow(); | 76 base::TimeTicks time = ui::EventTimeForNow(); |
77 TouchEvent press0_1(ET_TOUCH_PRESSED, gfx::Point(9, 10), kTouchId0, time); | 77 TouchEvent press0_1(ET_TOUCH_PRESSED, gfx::Point(9, 10), kTouchId0, time); |
78 EXPECT_TRUE(provider()->OnTouchEvent(&press0_1)); | 78 EXPECT_TRUE(provider()->OnTouchEvent(&press0_1)); |
79 | 79 |
80 TouchEvent press1_1(ET_TOUCH_PRESSED, gfx::Point(40, 40), kTouchId1, time); | 80 TouchEvent press1_1(ET_TOUCH_PRESSED, gfx::Point(40, 40), kTouchId1, time); |
81 EXPECT_TRUE(provider()->OnTouchEvent(&press1_1)); | 81 EXPECT_TRUE(provider()->OnTouchEvent(&press1_1)); |
82 | 82 |
83 time += base::TimeDelta::FromMilliseconds(10); | 83 time += base::TimeDelta::FromMilliseconds(10); |
84 TouchEvent move0_1(ET_TOUCH_MOVED, gfx::Point(10, 10), 0, kTouchId0, time, | 84 TouchEvent move0_1(ET_TOUCH_MOVED, gfx::Point(10, 10), 0, kTouchId0, time, |
85 kRadiusX, kRadiusY, kAngle, kForce); | 85 kRadiusX, kRadiusY, kAngle, kForce); |
86 EXPECT_TRUE(provider()->OnTouchEvent(&move0_1)); | 86 EXPECT_TRUE(provider()->OnTouchEvent(&move0_1)); |
(...skipping 24 matching lines...) Expand all Loading... |
111 time += base::TimeDelta::FromMilliseconds(10); | 111 time += base::TimeDelta::FromMilliseconds(10); |
112 TouchEvent move0_4(ET_TOUCH_MOVED, gfx::Point(), 0, kTouchId0, time, kRadiusX, | 112 TouchEvent move0_4(ET_TOUCH_MOVED, gfx::Point(), 0, kTouchId0, time, kRadiusX, |
113 kRadiusY + 1, kAngle, kForce); | 113 kRadiusY + 1, kAngle, kForce); |
114 move0_4.set_location_f(gfx::PointF(70, 75.1f)); | 114 move0_4.set_location_f(gfx::PointF(70, 75.1f)); |
115 move0_4.set_root_location_f(gfx::PointF(70, 75.1f)); | 115 move0_4.set_root_location_f(gfx::PointF(70, 75.1f)); |
116 } | 116 } |
117 | 117 |
118 // TODO(jdduke): Test whether event marked as scroll trigger. | 118 // TODO(jdduke): Test whether event marked as scroll trigger. |
119 | 119 |
120 } // namespace ui | 120 } // namespace ui |
OLD | NEW |