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

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

Issue 999423003: Set the unique_event_id when converting from TouchEvent to WebTouchEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "ui/events/event_constants.h" 6 #include "ui/events/event_constants.h"
7 #include "ui/events/gesture_detection/motion_event_generic.h" 7 #include "ui/events/gesture_detection/motion_event_generic.h"
8 #include "ui/events/test/motion_event_test_utils.h" 8 #include "ui/events/test/motion_event_test_utils.h"
9 9
10 namespace ui { 10 namespace ui {
11 11
12 TEST(MotionEventGenericTest, Basic) { 12 TEST(MotionEventGenericTest, Basic) {
13 base::TimeTicks event_time = base::TimeTicks::Now(); 13 base::TimeTicks event_time = base::TimeTicks::Now();
14 MotionEventGeneric event( 14 MotionEventGeneric event(
15 MotionEvent::ACTION_DOWN, event_time, PointerProperties()); 15 MotionEvent::ACTION_DOWN, event_time, PointerProperties());
16 EXPECT_EQ(1U, event.GetPointerCount()); 16 EXPECT_EQ(1U, event.GetPointerCount());
17 EXPECT_EQ(0U, event.GetHistorySize()); 17 EXPECT_EQ(0U, event.GetHistorySize());
18 EXPECT_EQ(event_time, event.GetEventTime()); 18 EXPECT_EQ(event_time, event.GetEventTime());
19 19
20 DCHECK_NE(0U, event.GetUniqueEventId());
21 event.set_unique_event_id(123456U);
22 EXPECT_EQ(123456U, event.GetUniqueEventId());
23
20 event.PushPointer(PointerProperties(8.3f, 4.7f, 0.9f)); 24 event.PushPointer(PointerProperties(8.3f, 4.7f, 0.9f));
21 ASSERT_EQ(2U, event.GetPointerCount()); 25 ASSERT_EQ(2U, event.GetPointerCount());
22 EXPECT_EQ(8.3f, event.GetX(1)); 26 EXPECT_EQ(8.3f, event.GetX(1));
23 EXPECT_EQ(4.7f, event.GetY(1)); 27 EXPECT_EQ(4.7f, event.GetY(1));
24 28
25 event.PushPointer(PointerProperties(2.3f, -3.7f, 5.8f)); 29 event.PushPointer(PointerProperties(2.3f, -3.7f, 5.8f));
26 ASSERT_EQ(3U, event.GetPointerCount()); 30 ASSERT_EQ(3U, event.GetPointerCount());
27 EXPECT_EQ(2.3f, event.GetX(2)); 31 EXPECT_EQ(2.3f, event.GetX(2));
28 EXPECT_EQ(-3.7f, event.GetY(2)); 32 EXPECT_EQ(-3.7f, event.GetY(2));
29 33
30 event.set_id(1); 34 event.pointer(0).id = 3;
31 EXPECT_EQ(1, event.GetId()); 35 EXPECT_EQ(3, event.GetPointerId(0));
32 36
33 event.set_action(MotionEvent::ACTION_POINTER_DOWN); 37 event.set_action(MotionEvent::ACTION_POINTER_DOWN);
34 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction()); 38 EXPECT_EQ(MotionEvent::ACTION_POINTER_DOWN, event.GetAction());
35 39
36 event_time += base::TimeDelta::FromMilliseconds(5); 40 event_time += base::TimeDelta::FromMilliseconds(5);
37 event.set_event_time(event_time); 41 event.set_event_time(event_time);
38 EXPECT_EQ(event_time, event.GetEventTime()); 42 EXPECT_EQ(event_time, event.GetEventTime());
39 43
40 event.set_button_state(MotionEvent::BUTTON_PRIMARY); 44 event.set_button_state(MotionEvent::BUTTON_PRIMARY);
41 EXPECT_EQ(MotionEvent::BUTTON_PRIMARY, event.GetButtonState()); 45 EXPECT_EQ(MotionEvent::BUTTON_PRIMARY, event.GetButtonState());
(...skipping 29 matching lines...) Expand all
71 EXPECT_EQ(2.f, event.GetHistoricalTouchMajor(1, 0)); 75 EXPECT_EQ(2.f, event.GetHistoricalTouchMajor(1, 0));
72 EXPECT_EQ(4.8f, event.GetHistoricalX(2, 0)); 76 EXPECT_EQ(4.8f, event.GetHistoricalX(2, 0));
73 EXPECT_EQ(9.6f, event.GetHistoricalY(2, 0)); 77 EXPECT_EQ(9.6f, event.GetHistoricalY(2, 0));
74 EXPECT_EQ(3.f, event.GetHistoricalTouchMajor(2, 0)); 78 EXPECT_EQ(3.f, event.GetHistoricalTouchMajor(2, 0));
75 } 79 }
76 80
77 TEST(MotionEventGenericTest, Clone) { 81 TEST(MotionEventGenericTest, Clone) {
78 MotionEventGeneric event(MotionEvent::ACTION_DOWN, 82 MotionEventGeneric event(MotionEvent::ACTION_DOWN,
79 base::TimeTicks::Now(), 83 base::TimeTicks::Now(),
80 PointerProperties(8.3f, 4.7f, 2.f)); 84 PointerProperties(8.3f, 4.7f, 2.f));
81 event.set_id(1);
82 event.set_button_state(MotionEvent::BUTTON_PRIMARY); 85 event.set_button_state(MotionEvent::BUTTON_PRIMARY);
83 86
84 scoped_ptr<MotionEvent> clone = event.Clone(); 87 scoped_ptr<MotionEvent> clone = event.Clone();
85 ASSERT_TRUE(clone); 88 ASSERT_TRUE(clone);
89 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId());
86 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); 90 EXPECT_EQ(test::ToString(event), test::ToString(*clone));
87 } 91 }
88 92
89 TEST(MotionEventGenericTest, CloneWithHistory) { 93 TEST(MotionEventGenericTest, CloneWithHistory) {
90 base::TimeTicks event_time = base::TimeTicks::Now(); 94 base::TimeTicks event_time = base::TimeTicks::Now();
91 base::TimeTicks historical_event_time = 95 base::TimeTicks historical_event_time =
92 event_time - base::TimeDelta::FromMilliseconds(5); 96 event_time - base::TimeDelta::FromMilliseconds(5);
93 97
94 PointerProperties pointer(8.3f, 4.7f, 10.1f); 98 PointerProperties pointer(8.3f, 4.7f, 10.1f);
95 MotionEventGeneric event(MotionEvent::ACTION_MOVE, event_time, pointer); 99 MotionEventGeneric event(MotionEvent::ACTION_MOVE, event_time, pointer);
96 100
97 PointerProperties historical_pointer(3.4f, -4.3f, 11.5); 101 PointerProperties historical_pointer(3.4f, -4.3f, 11.5);
98 scoped_ptr<MotionEvent> historical_event(new MotionEventGeneric( 102 scoped_ptr<MotionEvent> historical_event(new MotionEventGeneric(
99 MotionEvent::ACTION_MOVE, historical_event_time, historical_pointer)); 103 MotionEvent::ACTION_MOVE, historical_event_time, historical_pointer));
100 104
101 event.PushHistoricalEvent(historical_event.Pass()); 105 event.PushHistoricalEvent(historical_event.Pass());
102 EXPECT_EQ(1U, event.GetHistorySize()); 106 EXPECT_EQ(1U, event.GetHistorySize());
103 107
104 scoped_ptr<MotionEvent> clone = event.Clone(); 108 scoped_ptr<MotionEvent> clone = event.Clone();
105 ASSERT_TRUE(clone); 109 ASSERT_TRUE(clone);
110 EXPECT_EQ(event.GetUniqueEventId(), clone->GetUniqueEventId());
106 EXPECT_EQ(test::ToString(event), test::ToString(*clone)); 111 EXPECT_EQ(test::ToString(event), test::ToString(*clone));
107 } 112 }
108 113
109 TEST(MotionEventGenericTest, Cancel) { 114 TEST(MotionEventGenericTest, Cancel) {
110 MotionEventGeneric event(MotionEvent::ACTION_UP, 115 MotionEventGeneric event(MotionEvent::ACTION_UP,
111 base::TimeTicks::Now(), 116 base::TimeTicks::Now(),
112 PointerProperties(8.7f, 4.3f, 1.f)); 117 PointerProperties(8.7f, 4.3f, 1.f));
113 event.set_id(2);
114 event.set_button_state(MotionEvent::BUTTON_SECONDARY); 118 event.set_button_state(MotionEvent::BUTTON_SECONDARY);
115 119
116 scoped_ptr<MotionEvent> cancel = event.Cancel(); 120 scoped_ptr<MotionEvent> cancel = event.Cancel();
117 event.set_action(MotionEvent::ACTION_CANCEL); 121 event.set_action(MotionEvent::ACTION_CANCEL);
118 ASSERT_TRUE(cancel); 122 ASSERT_TRUE(cancel);
123 EXPECT_NE(event.GetUniqueEventId(), cancel->GetUniqueEventId());
119 EXPECT_EQ(test::ToString(event), test::ToString(*cancel)); 124 EXPECT_EQ(test::ToString(event), test::ToString(*cancel));
120 } 125 }
121 126
122 TEST(MotionEventGenericTest, FindPointerIndexOfId) { 127 TEST(MotionEventGenericTest, FindPointerIndexOfId) {
123 base::TimeTicks event_time = base::TimeTicks::Now(); 128 base::TimeTicks event_time = base::TimeTicks::Now();
124 PointerProperties pointer; 129 PointerProperties pointer;
125 pointer.id = 0; 130 pointer.id = 0;
126 MotionEventGeneric event0(MotionEvent::ACTION_DOWN, event_time, pointer); 131 MotionEventGeneric event0(MotionEvent::ACTION_DOWN, event_time, pointer);
127 EXPECT_EQ(0, event0.FindPointerIndexOfId(0)); 132 EXPECT_EQ(0, event0.FindPointerIndexOfId(0));
128 EXPECT_EQ(-1, event0.FindPointerIndexOfId(1)); 133 EXPECT_EQ(-1, event0.FindPointerIndexOfId(1));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 ASSERT_EQ(2U, event.GetHistorySize()); 218 ASSERT_EQ(2U, event.GetHistorySize());
214 ASSERT_EQ(2U, event.GetPointerCount()); 219 ASSERT_EQ(2U, event.GetPointerCount());
215 220
216 // Do a basic smoke exercise of event stringification to ensure things don't 221 // Do a basic smoke exercise of event stringification to ensure things don't
217 // explode in the process. 222 // explode in the process.
218 std::string event_string = test::ToString(event); 223 std::string event_string = test::ToString(event);
219 EXPECT_FALSE(event_string.empty()); 224 EXPECT_FALSE(event_string.empty());
220 } 225 }
221 226
222 } // namespace ui 227 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/motion_event_generic.cc ('k') | ui/events/gestures/motion_event_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698