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

Side by Side Diff: content/common/input/web_input_event_traits_unittest.cc

Issue 200623003: Adopt "QuickScale" double-tap drag zoom code in the GestureProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Yeah... Created 6 years, 8 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 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 "content/common/input/web_input_event_traits.h" 5 #include "content/common/input/web_input_event_traits.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/WebKit/public/web/WebInputEvent.h" 8 #include "third_party/WebKit/public/web/WebInputEvent.h"
9 9
10 using blink::WebGestureEvent;
10 using blink::WebInputEvent; 11 using blink::WebInputEvent;
11 using blink::WebTouchEvent; 12 using blink::WebTouchEvent;
12 using blink::WebTouchPoint; 13 using blink::WebTouchPoint;
13 14
14 namespace content { 15 namespace content {
15 namespace { 16 namespace {
16 17
17 class WebInputEventTraitsTest : public testing::Test { 18 class WebInputEventTraitsTest : public testing::Test {
18 protected: 19 protected:
19 static WebTouchPoint Create(int id, WebTouchPoint::State state) { 20 static WebTouchPoint CreateTouchPoint(WebTouchPoint::State state, int id) {
20 WebTouchPoint touch; 21 WebTouchPoint touch;
22 touch.state = state;
21 touch.id = id; 23 touch.id = id;
22 touch.state = state;
23 return touch; 24 return touch;
24 } 25 }
25 26
26 static WebTouchEvent Create(WebInputEvent::Type type) { 27 static WebTouchEvent CreateTouch(WebInputEvent::Type type) {
27 return Create(type, 1); 28 return CreateTouch(type, 1);
28 } 29 }
29 30
30 static WebTouchEvent Create(WebInputEvent::Type type, unsigned touch_count) { 31 static WebTouchEvent CreateTouch(WebInputEvent::Type type,
32 unsigned touch_count) {
31 WebTouchEvent event; 33 WebTouchEvent event;
32 event.touchesLength = touch_count; 34 event.touchesLength = touch_count;
33 event.type = type; 35 event.type = type;
34 return event; 36 return event;
35 } 37 }
38
39 static WebGestureEvent CreateGesture(WebInputEvent::Type type,
40 float x,
41 float y) {
42 WebGestureEvent event;
43 event.type = type;
44 event.x = x;
45 event.y = y;
46 return event;
47 }
36 }; 48 };
37 49
38 TEST_F(WebInputEventTraitsTest, TouchEventCoalescing) { 50 TEST_F(WebInputEventTraitsTest, TouchEventCoalescing) {
39 WebTouchEvent touch0 = Create(WebInputEvent::TouchStart); 51 WebTouchEvent touch0 = CreateTouch(WebInputEvent::TouchStart);
40 WebTouchEvent touch1 = Create(WebInputEvent::TouchMove); 52 WebTouchEvent touch1 = CreateTouch(WebInputEvent::TouchMove);
41 53
42 // Non touch-moves won't coalesce. 54 // Non touch-moves won't coalesce.
43 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch0)); 55 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch0));
44 56
45 // Touches of different types won't coalesce. 57 // Touches of different types won't coalesce.
46 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1)); 58 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1));
47 59
48 // Touch moves with idential touch lengths and touch ids should coalesce. 60 // Touch moves with idential touch lengths and touch ids should coalesce.
49 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(touch1, touch1)); 61 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(touch1, touch1));
50 62
51 // Touch moves with different touch ids should not coalesce. 63 // Touch moves with different touch ids should not coalesce.
52 touch0 = Create(WebInputEvent::TouchMove); 64 touch0 = CreateTouch(WebInputEvent::TouchMove);
53 touch1 = Create(WebInputEvent::TouchMove); 65 touch1 = CreateTouch(WebInputEvent::TouchMove);
54 touch0.touches[0].id = 7; 66 touch0.touches[0].id = 7;
55 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1)); 67 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1));
56 touch0 = Create(WebInputEvent::TouchMove, 2); 68 touch0 = CreateTouch(WebInputEvent::TouchMove, 2);
57 touch1 = Create(WebInputEvent::TouchMove, 2); 69 touch1 = CreateTouch(WebInputEvent::TouchMove, 2);
58 touch0.touches[0].id = 1; 70 touch0.touches[0].id = 1;
59 touch1.touches[0].id = 0; 71 touch1.touches[0].id = 0;
60 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1)); 72 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1));
61 73
62 // Touch moves with different touch lengths should not coalesce. 74 // Touch moves with different touch lengths should not coalesce.
63 touch0 = Create(WebInputEvent::TouchMove, 1); 75 touch0 = CreateTouch(WebInputEvent::TouchMove, 1);
64 touch1 = Create(WebInputEvent::TouchMove, 2); 76 touch1 = CreateTouch(WebInputEvent::TouchMove, 2);
65 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1)); 77 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1));
66 78
67 // Touch moves with identical touch ids in different orders should coalesce. 79 // Touch moves with identical touch ids in different orders should coalesce.
68 touch0 = Create(WebInputEvent::TouchMove, 2); 80 touch0 = CreateTouch(WebInputEvent::TouchMove, 2);
69 touch1 = Create(WebInputEvent::TouchMove, 2); 81 touch1 = CreateTouch(WebInputEvent::TouchMove, 2);
70 touch0.touches[0] = touch1.touches[1] = Create(1, WebTouchPoint::StateMoved); 82 touch0.touches[0] = touch1.touches[1] =
71 touch0.touches[1] = touch1.touches[0] = Create(0, WebTouchPoint::StateMoved); 83 CreateTouchPoint(WebTouchPoint::StateMoved, 1);
84 touch0.touches[1] = touch1.touches[0] =
85 CreateTouchPoint(WebTouchPoint::StateMoved, 0);
72 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(touch0, touch1)); 86 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(touch0, touch1));
73 87
74 // Pointers with the same ID's should coalesce. 88 // Pointers with the same ID's should coalesce.
75 touch0 = Create(WebInputEvent::TouchMove, 2); 89 touch0 = CreateTouch(WebInputEvent::TouchMove, 2);
76 touch1 = Create(WebInputEvent::TouchMove, 2); 90 touch1 = CreateTouch(WebInputEvent::TouchMove, 2);
77 touch0.touches[0] = touch1.touches[1] = Create(1, WebTouchPoint::StateMoved); 91 touch0.touches[0] = touch1.touches[1] =
92 CreateTouchPoint(WebTouchPoint::StateMoved, 1);
78 WebInputEventTraits::Coalesce(touch0, &touch1); 93 WebInputEventTraits::Coalesce(touch0, &touch1);
79 ASSERT_EQ(1, touch1.touches[0].id); 94 ASSERT_EQ(1, touch1.touches[0].id);
80 ASSERT_EQ(0, touch1.touches[1].id); 95 ASSERT_EQ(0, touch1.touches[1].id);
81 EXPECT_EQ(WebTouchPoint::StateUndefined, touch1.touches[1].state); 96 EXPECT_EQ(WebTouchPoint::StateUndefined, touch1.touches[1].state);
82 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.touches[0].state); 97 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.touches[0].state);
83 98
84 // Movement from now-stationary pointers should be preserved. 99 // Movement from now-stationary pointers should be preserved.
85 touch0 = touch1 = Create(WebInputEvent::TouchMove, 2); 100 touch0 = touch1 = CreateTouch(WebInputEvent::TouchMove, 2);
86 touch0.touches[0] = Create(1, WebTouchPoint::StateMoved); 101 touch0.touches[0] = CreateTouchPoint(WebTouchPoint::StateMoved, 1);
87 touch1.touches[1] = Create(1, WebTouchPoint::StateStationary); 102 touch1.touches[1] = CreateTouchPoint(WebTouchPoint::StateStationary, 1);
88 touch0.touches[1] = Create(0, WebTouchPoint::StateStationary); 103 touch0.touches[1] = CreateTouchPoint(WebTouchPoint::StateStationary, 0);
89 touch1.touches[0] = Create(0, WebTouchPoint::StateMoved); 104 touch1.touches[0] = CreateTouchPoint(WebTouchPoint::StateMoved, 0);
90 WebInputEventTraits::Coalesce(touch0, &touch1); 105 WebInputEventTraits::Coalesce(touch0, &touch1);
91 ASSERT_EQ(1, touch1.touches[0].id); 106 ASSERT_EQ(1, touch1.touches[0].id);
92 ASSERT_EQ(0, touch1.touches[1].id); 107 ASSERT_EQ(0, touch1.touches[1].id);
93 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.touches[0].state); 108 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.touches[0].state);
94 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.touches[1].state); 109 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.touches[1].state);
95 } 110 }
96 111
112 TEST_F(WebInputEventTraitsTest, PinchEventCoalescing) {
113 WebGestureEvent pinch0 =
114 CreateGesture(WebInputEvent::GesturePinchBegin, 1, 1);
115 WebGestureEvent pinch1 =
116 CreateGesture(WebInputEvent::GesturePinchUpdate, 2, 2);
117
118 // Only GesturePinchUpdate's coalesce.
119 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(pinch0, pinch0));
120
121 // Pinch gestures of different types should not coalesce.
122 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(pinch0, pinch1));
123
124 // Pinches with different focal points should not coalesce.
125 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1);
126 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 2, 2);
127 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(pinch0, pinch1));
128 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch0));
129
130 // Coalesced scales are multiplicative.
131 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1);
132 pinch0.data.pinchUpdate.scale = 2.f;
133 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1);
134 pinch1.data.pinchUpdate.scale = 3.f;
135 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch0));
136 WebInputEventTraits::Coalesce(pinch0, &pinch1);
137 EXPECT_EQ(2.f * 3.f, pinch1.data.pinchUpdate.scale);
138 }
139
97 } // namespace 140 } // namespace
98 } // namespace content 141 } // namespace content
OLDNEW
« no previous file with comments | « content/common/input/web_input_event_traits.cc ('k') | ui/events/gesture_detection/gesture_config_helper_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698