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

Side by Side Diff: ui/events/gesture_detection/gesture_event_data_packet_unittest.cc

Issue 1989623002: Suppressed MEs for gestures from cancelled PEs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 6 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/gesture_detection/gesture_event_data_packet.h" 8 #include "ui/events/gesture_detection/gesture_event_data_packet.h"
9 #include "ui/events/test/motion_event_test_utils.h" 9 #include "ui/events/test/motion_event_test_utils.h"
10 10
11 using ui::test::MockMotionEvent; 11 using ui::test::MockMotionEvent;
12 12
13 namespace ui { 13 namespace ui {
14 namespace { 14 namespace {
15 15
16 const float kTouchX = 13.7f; 16 const float kTouchX = 13.7f;
17 const float kTouchY = 14.2f; 17 const float kTouchY = 14.2f;
18 const uint32_t uniqueTouchEventId = 1234U;
18 19
19 GestureEventData CreateGesture(EventType type) { 20 GestureEventData CreateGesture(EventType type) {
20 return GestureEventData(GestureEventDetails(type), 21 return GestureEventData(GestureEventDetails(type),
21 0, 22 0,
22 MotionEvent::TOOL_TYPE_FINGER, 23 MotionEvent::TOOL_TYPE_FINGER,
23 base::TimeTicks(), 24 base::TimeTicks(),
24 kTouchX, 25 kTouchX,
25 kTouchY, 26 kTouchY,
26 kTouchX + 5.f, 27 kTouchX + 5.f,
27 kTouchY + 10.f, 28 kTouchY + 10.f,
28 1, 29 1,
29 gfx::RectF(kTouchX - 1.f, kTouchY - 1.f, 2.f, 2.f), 30 gfx::RectF(kTouchX - 1.f, kTouchY - 1.f, 2.f, 2.f),
30 EF_NONE); 31 EF_NONE,
32 uniqueTouchEventId);
31 } 33 }
32 34
33 } // namespace 35 } // namespace
34 36
35 bool GestureEquals(const GestureEventData& lhs, const GestureEventData& rhs) { 37 bool GestureEqualsExceptForTouchId(const GestureEventData& lhs,
38 const GestureEventData& rhs) {
36 return lhs.type() == rhs.type() && 39 return lhs.type() == rhs.type() &&
37 lhs.motion_event_id == rhs.motion_event_id && 40 lhs.motion_event_id == rhs.motion_event_id &&
38 lhs.primary_tool_type == rhs.primary_tool_type && 41 lhs.primary_tool_type == rhs.primary_tool_type &&
39 lhs.time == rhs.time && lhs.x == rhs.x && lhs.y == rhs.y && 42 lhs.time == rhs.time && lhs.x == rhs.x && lhs.y == rhs.y &&
40 lhs.raw_x == rhs.raw_x && lhs.raw_y == rhs.raw_y; 43 lhs.raw_x == rhs.raw_x && lhs.raw_y == rhs.raw_y;
41 } 44 }
42 45
43 bool PacketEquals(const GestureEventDataPacket& lhs, 46 bool PacketEquals(const GestureEventDataPacket& lhs,
44 const GestureEventDataPacket& rhs) { 47 const GestureEventDataPacket& rhs) {
45 if (lhs.timestamp() != rhs.timestamp() || 48 if (lhs.timestamp() != rhs.timestamp() ||
46 lhs.gesture_count() != rhs.gesture_count() || 49 lhs.gesture_count() != rhs.gesture_count() ||
47 lhs.timestamp() != rhs.timestamp() || 50 lhs.timestamp() != rhs.timestamp() ||
48 lhs.gesture_source() != rhs.gesture_source() || 51 lhs.gesture_source() != rhs.gesture_source() ||
49 lhs.touch_location() != rhs.touch_location() || 52 lhs.touch_location() != rhs.touch_location() ||
50 lhs.raw_touch_location() != rhs.raw_touch_location()) 53 lhs.raw_touch_location() != rhs.raw_touch_location() ||
54 lhs.unique_touch_event_id() != rhs.unique_touch_event_id())
51 return false; 55 return false;
52 56
53 for (size_t i = 0; i < lhs.gesture_count(); ++i) { 57 for (size_t i = 0; i < lhs.gesture_count(); ++i) {
54 if (!GestureEquals(lhs.gesture(i), rhs.gesture(i))) 58 if (!GestureEqualsExceptForTouchId(lhs.gesture(i), rhs.gesture(i)))
59 return false;
60 if (lhs.gesture(i).unique_touch_event_id !=
61 rhs.gesture(i).unique_touch_event_id)
55 return false; 62 return false;
56 } 63 }
57 64
58 return true; 65 return true;
59 } 66 }
60 67
61 class GestureEventDataPacketTest : public testing::Test {}; 68 class GestureEventDataPacketTest : public testing::Test {};
62 69
63 TEST_F(GestureEventDataPacketTest, Basic) { 70 TEST_F(GestureEventDataPacketTest, Basic) {
64 base::TimeTicks touch_time = base::TimeTicks::Now(); 71 base::TimeTicks touch_time = base::TimeTicks::Now();
65 72
66 GestureEventDataPacket packet; 73 GestureEventDataPacket packet;
67 EXPECT_EQ(0U, packet.gesture_count()); 74 EXPECT_EQ(0U, packet.gesture_count());
68 EXPECT_EQ(GestureEventDataPacket::UNDEFINED, packet.gesture_source()); 75 EXPECT_EQ(GestureEventDataPacket::UNDEFINED, packet.gesture_source());
69 76
70 packet = GestureEventDataPacket::FromTouch( 77 packet = GestureEventDataPacket::FromTouch(
71 MockMotionEvent(MotionEvent::ACTION_DOWN, touch_time, kTouchX, kTouchY)); 78 MockMotionEvent(MotionEvent::ACTION_DOWN, touch_time, kTouchX, kTouchY));
72 EXPECT_TRUE(touch_time == packet.timestamp()); 79 EXPECT_TRUE(touch_time == packet.timestamp());
73 EXPECT_EQ(0U, packet.gesture_count()); 80 EXPECT_EQ(0U, packet.gesture_count());
74 EXPECT_EQ(gfx::PointF(kTouchX, kTouchY), packet.touch_location()); 81 EXPECT_EQ(gfx::PointF(kTouchX, kTouchY), packet.touch_location());
75 82
76 for (size_t i = ET_GESTURE_TYPE_START; i < ET_GESTURE_TYPE_END; ++i) { 83 for (size_t i = ET_GESTURE_TYPE_START; i < ET_GESTURE_TYPE_END; ++i) {
77 const EventType type = static_cast<EventType>(i); 84 const EventType type = static_cast<EventType>(i);
78 GestureEventData gesture = CreateGesture(type); 85 GestureEventData gesture = CreateGesture(type);
79 packet.Push(gesture); 86 packet.Push(gesture);
80 const size_t index = (i - ET_GESTURE_TYPE_START); 87 const size_t index = (i - ET_GESTURE_TYPE_START);
81 ASSERT_EQ(index + 1U, packet.gesture_count()); 88 ASSERT_EQ(index + 1U, packet.gesture_count());
82 EXPECT_TRUE(GestureEquals(gesture, packet.gesture(index))); 89 EXPECT_TRUE(GestureEqualsExceptForTouchId(gesture, packet.gesture(index)));
90 EXPECT_EQ(packet.unique_touch_event_id(),
91 packet.gesture(index).unique_touch_event_id);
83 } 92 }
84 } 93 }
85 94
86 TEST_F(GestureEventDataPacketTest, Copy) { 95 TEST_F(GestureEventDataPacketTest, Copy) {
87 GestureEventDataPacket packet0 = GestureEventDataPacket::FromTouch( 96 GestureEventDataPacket packet0 = GestureEventDataPacket::FromTouch(
88 MockMotionEvent(MotionEvent::ACTION_UP)); 97 MockMotionEvent(MotionEvent::ACTION_UP));
89 packet0.Push(CreateGesture(ET_GESTURE_TAP_DOWN)); 98 packet0.Push(CreateGesture(ET_GESTURE_TAP_DOWN));
90 packet0.Push(CreateGesture(ET_GESTURE_SCROLL_BEGIN)); 99 packet0.Push(CreateGesture(ET_GESTURE_SCROLL_BEGIN));
91 100
92 GestureEventDataPacket packet1 = packet0; 101 GestureEventDataPacket packet1 = packet0;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 135
127 GestureEventData gesture = CreateGesture(ET_GESTURE_TAP); 136 GestureEventData gesture = CreateGesture(ET_GESTURE_TAP);
128 packet = GestureEventDataPacket::FromTouchTimeout(gesture); 137 packet = GestureEventDataPacket::FromTouchTimeout(gesture);
129 EXPECT_EQ(GestureEventDataPacket::TOUCH_TIMEOUT, packet.gesture_source()); 138 EXPECT_EQ(GestureEventDataPacket::TOUCH_TIMEOUT, packet.gesture_source());
130 EXPECT_EQ(1U, packet.gesture_count()); 139 EXPECT_EQ(1U, packet.gesture_count());
131 EXPECT_EQ(base::TimeTicks(), packet.timestamp()); 140 EXPECT_EQ(base::TimeTicks(), packet.timestamp());
132 EXPECT_EQ(gfx::PointF(gesture.x, gesture.y), packet.touch_location()); 141 EXPECT_EQ(gfx::PointF(gesture.x, gesture.y), packet.touch_location());
133 } 142 }
134 143
135 } // namespace ui 144 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_event_data_packet.cc ('k') | ui/events/gesture_detection/gesture_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698