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

Side by Side Diff: third_party/WebKit/Source/core/events/PointerEventFactoryTest.cpp

Issue 2834183002: Add time stamp to the constructor of the events (Closed)
Patch Set: Created 3 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 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 #include "core/events/PointerEventFactory.h" 5 #include "core/events/PointerEventFactory.h"
6 6
7 #include "core/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/page/Page.h" 8 #include "core/page/Page.h"
9 #include "public/platform/WebPointerProperties.h" 9 #include "public/platform/WebPointerProperties.h"
10 #include <climits> 10 #include <climits>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 public: 63 public:
64 WebTouchPointBuilder(WebPointerProperties::PointerType, 64 WebTouchPointBuilder(WebPointerProperties::PointerType,
65 int, 65 int,
66 WebTouchPoint::State); 66 WebTouchPoint::State);
67 }; 67 };
68 68
69 class WebMouseEventBuilder : public WebMouseEvent { 69 class WebMouseEventBuilder : public WebMouseEvent {
70 public: 70 public:
71 WebMouseEventBuilder(WebPointerProperties::PointerType, 71 WebMouseEventBuilder(WebPointerProperties::PointerType,
72 int, 72 int,
73 WebInputEvent::Modifiers); 73 WebInputEvent::Modifiers,
74 double);
74 }; 75 };
75 }; 76 };
76 77
77 void PointerEventFactoryTest::SetUp() { 78 void PointerEventFactoryTest::SetUp() {
78 expected_mouse_id_ = 1; 79 expected_mouse_id_ = 1;
79 mapped_id_start_ = 2; 80 mapped_id_start_ = 2;
80 } 81 }
81 82
82 PointerEventFactoryTest::WebTouchPointBuilder::WebTouchPointBuilder( 83 PointerEventFactoryTest::WebTouchPointBuilder::WebTouchPointBuilder(
83 WebPointerProperties::PointerType pointer_type_param, 84 WebPointerProperties::PointerType pointer_type_param,
84 int id_param, 85 int id_param,
85 WebTouchPoint::State state_param) { 86 WebTouchPoint::State state_param) {
86 id = id_param; 87 id = id_param;
87 pointer_type = pointer_type_param; 88 pointer_type = pointer_type_param;
88 force = 1.0; 89 force = 1.0;
89 state = state_param; 90 state = state_param;
90 } 91 }
91 92
92 PointerEventFactoryTest::WebMouseEventBuilder::WebMouseEventBuilder( 93 PointerEventFactoryTest::WebMouseEventBuilder::WebMouseEventBuilder(
93 WebPointerProperties::PointerType pointer_type_param, 94 WebPointerProperties::PointerType pointer_type_param,
94 int id_param, 95 int id_param,
95 WebInputEvent::Modifiers modifiers_param) { 96 WebInputEvent::Modifiers modifiers_param,
97 double platform_time_stamp) {
96 pointer_type = pointer_type_param; 98 pointer_type = pointer_type_param;
97 id = id_param; 99 id = id_param;
98 modifiers_ = modifiers_param; 100 modifiers_ = modifiers_param;
99 frame_scale_ = 1; 101 frame_scale_ = 1;
102 time_stamp_seconds_ = platform_time_stamp;
100 } 103 }
101 104
102 PointerEvent* PointerEventFactoryTest::CreateAndCheckTouchCancel( 105 PointerEvent* PointerEventFactoryTest::CreateAndCheckTouchCancel(
103 WebPointerProperties::PointerType pointer_type, 106 WebPointerProperties::PointerType pointer_type,
104 int raw_id, 107 int raw_id,
105 int unique_id, 108 int unique_id,
106 bool is_primary) { 109 bool is_primary) {
107 PointerEvent* pointer_event = 110 PointerEvent* pointer_event =
108 pointer_event_factory_.CreatePointerCancelEvent(unique_id, pointer_type); 111 pointer_event_factory_.CreatePointerCancelEvent(unique_id, pointer_type);
109 EXPECT_EQ(unique_id, pointer_event->pointerId()); 112 EXPECT_EQ(unique_id, pointer_event->pointerId());
(...skipping 15 matching lines...) Expand all
125 EXPECT_EQ(clone_pointer_event->type(), type); 128 EXPECT_EQ(clone_pointer_event->type(), type);
126 } 129 }
127 130
128 PointerEvent* PointerEventFactoryTest::CreateAndCheckTouchEvent( 131 PointerEvent* PointerEventFactoryTest::CreateAndCheckTouchEvent(
129 WebPointerProperties::PointerType pointer_type, 132 WebPointerProperties::PointerType pointer_type,
130 int raw_id, 133 int raw_id,
131 int unique_id, 134 int unique_id,
132 bool is_primary, 135 bool is_primary,
133 WebTouchPoint::State state, 136 WebTouchPoint::State state,
134 size_t coalesced_event_count) { 137 size_t coalesced_event_count) {
135 Vector<WebTouchPoint> coalesced_events; 138 Vector<std::pair<WebTouchPoint, TimeTicks>> coalesced_events;
139 TimeTicks now = TimeTicks::Now();
136 for (size_t i = 0; i < coalesced_event_count; i++) { 140 for (size_t i = 0; i < coalesced_event_count; i++) {
137 coalesced_events.push_back(PointerEventFactoryTest::WebTouchPointBuilder( 141 coalesced_events.push_back(std::pair<WebTouchPoint, TimeTicks>(
138 pointer_type, raw_id, state)); 142 PointerEventFactoryTest::WebTouchPointBuilder(pointer_type, raw_id,
143 state),
144 now));
139 } 145 }
140 PointerEvent* pointer_event = pointer_event_factory_.Create( 146 PointerEvent* pointer_event = pointer_event_factory_.Create(
141 PointerEventFactoryTest::WebTouchPointBuilder(pointer_type, raw_id, 147 PointerEventFactoryTest::WebTouchPointBuilder(pointer_type, raw_id,
142 state), 148 state),
143 coalesced_events, WebInputEvent::kNoModifiers, nullptr, nullptr); 149 coalesced_events, WebInputEvent::kNoModifiers, now, nullptr, nullptr);
144 EXPECT_EQ(unique_id, pointer_event->pointerId()); 150 EXPECT_EQ(unique_id, pointer_event->pointerId());
145 EXPECT_EQ(is_primary, pointer_event->isPrimary()); 151 EXPECT_EQ(is_primary, pointer_event->isPrimary());
152 EXPECT_EQ(now, pointer_event->PlatformTimeStamp());
146 const char* expected_pointer_type = 153 const char* expected_pointer_type =
147 PointerTypeNameForWebPointPointerType(pointer_type); 154 PointerTypeNameForWebPointPointerType(pointer_type);
148 EXPECT_EQ(expected_pointer_type, pointer_event->pointerType()); 155 EXPECT_EQ(expected_pointer_type, pointer_event->pointerType());
149 EXPECT_EQ(coalesced_event_count, pointer_event->getCoalescedEvents().size()); 156 EXPECT_EQ(coalesced_event_count, pointer_event->getCoalescedEvents().size());
150 for (size_t i = 0; i < coalesced_event_count; i++) { 157 for (size_t i = 0; i < coalesced_event_count; i++) {
151 EXPECT_EQ(unique_id, pointer_event->getCoalescedEvents()[i]->pointerId()); 158 EXPECT_EQ(unique_id, pointer_event->getCoalescedEvents()[i]->pointerId());
152 EXPECT_EQ(is_primary, pointer_event->getCoalescedEvents()[i]->isPrimary()); 159 EXPECT_EQ(is_primary, pointer_event->getCoalescedEvents()[i]->isPrimary());
153 EXPECT_EQ(expected_pointer_type, pointer_event->pointerType()); 160 EXPECT_EQ(expected_pointer_type, pointer_event->pointerType());
161 EXPECT_EQ(now, pointer_event->PlatformTimeStamp());
154 } 162 }
155 return pointer_event; 163 return pointer_event;
156 } 164 }
157 165
158 PointerEvent* PointerEventFactoryTest::CreateAndCheckMouseEvent( 166 PointerEvent* PointerEventFactoryTest::CreateAndCheckMouseEvent(
159 WebPointerProperties::PointerType pointer_type, 167 WebPointerProperties::PointerType pointer_type,
160 int raw_id, 168 int raw_id,
161 int unique_id, 169 int unique_id,
162 bool is_primary, 170 bool is_primary,
163 WebInputEvent::Modifiers modifiers, 171 WebInputEvent::Modifiers modifiers,
164 size_t coalesced_event_count) { 172 size_t coalesced_event_count) {
165 Vector<WebMouseEvent> coalesced_events; 173 Vector<WebMouseEvent> coalesced_events;
174 double base_time = 123;
166 for (size_t i = 0; i < coalesced_event_count; i++) { 175 for (size_t i = 0; i < coalesced_event_count; i++) {
167 coalesced_events.push_back(PointerEventFactoryTest::WebMouseEventBuilder( 176 coalesced_events.push_back(PointerEventFactoryTest::WebMouseEventBuilder(
168 pointer_type, raw_id, modifiers)); 177 pointer_type, raw_id, modifiers, 123 + i));
169 } 178 }
170 PointerEvent* pointer_event = pointer_event_factory_.Create( 179 PointerEvent* pointer_event = pointer_event_factory_.Create(
171 coalesced_event_count ? EventTypeNames::mousemove 180 coalesced_event_count ? EventTypeNames::mousemove
172 : EventTypeNames::mousedown, 181 : EventTypeNames::mousedown,
173 PointerEventFactoryTest::WebMouseEventBuilder(pointer_type, raw_id, 182 PointerEventFactoryTest::WebMouseEventBuilder(pointer_type, raw_id,
174 modifiers), 183 modifiers, base_time),
175 coalesced_events, nullptr); 184 coalesced_events, nullptr);
176 EXPECT_EQ(unique_id, pointer_event->pointerId()); 185 EXPECT_EQ(unique_id, pointer_event->pointerId());
177 EXPECT_EQ(is_primary, pointer_event->isPrimary()); 186 EXPECT_EQ(is_primary, pointer_event->isPrimary());
187 EXPECT_EQ(TimeTicks::FromSeconds(base_time),
188 pointer_event->PlatformTimeStamp());
178 const char* expected_pointer_type = 189 const char* expected_pointer_type =
179 PointerTypeNameForWebPointPointerType(pointer_type); 190 PointerTypeNameForWebPointPointerType(pointer_type);
180 EXPECT_EQ(expected_pointer_type, pointer_event->pointerType()); 191 EXPECT_EQ(expected_pointer_type, pointer_event->pointerType());
181 EXPECT_EQ(coalesced_event_count, pointer_event->getCoalescedEvents().size()); 192 EXPECT_EQ(coalesced_event_count, pointer_event->getCoalescedEvents().size());
182 for (size_t i = 0; i < coalesced_event_count; i++) { 193 for (size_t i = 0; i < coalesced_event_count; i++) {
183 EXPECT_EQ(unique_id, pointer_event->getCoalescedEvents()[i]->pointerId()); 194 EXPECT_EQ(unique_id, pointer_event->getCoalescedEvents()[i]->pointerId());
184 EXPECT_EQ(is_primary, pointer_event->getCoalescedEvents()[i]->isPrimary()); 195 EXPECT_EQ(is_primary, pointer_event->getCoalescedEvents()[i]->isPrimary());
185 EXPECT_EQ(expected_pointer_type, pointer_event->pointerType()); 196 EXPECT_EQ(expected_pointer_type, pointer_event->pointerType());
197 EXPECT_EQ(TimeTicks::FromSeconds(base_time + i),
198 pointer_event->getCoalescedEvents()[i]->PlatformTimeStamp());
186 } 199 }
187 return pointer_event; 200 return pointer_event;
188 } 201 }
189 202
190 TEST_F(PointerEventFactoryTest, MousePointer) { 203 TEST_F(PointerEventFactoryTest, MousePointer) {
191 EXPECT_TRUE(pointer_event_factory_.IsActive(expected_mouse_id_)); 204 EXPECT_TRUE(pointer_event_factory_.IsActive(expected_mouse_id_));
192 EXPECT_FALSE(pointer_event_factory_.IsActiveButtonsState(expected_mouse_id_)); 205 EXPECT_FALSE(pointer_event_factory_.IsActiveButtonsState(expected_mouse_id_));
193 206
194 PointerEvent* pointer_event1 = CreateAndCheckMouseEvent( 207 PointerEvent* pointer_event1 = CreateAndCheckMouseEvent(
195 WebPointerProperties::PointerType::kMouse, 0, expected_mouse_id_, true); 208 WebPointerProperties::PointerType::kMouse, 0, expected_mouse_id_, true);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 TEST_F(PointerEventFactoryTest, CoalescedEvents) { 471 TEST_F(PointerEventFactoryTest, CoalescedEvents) {
459 CreateAndCheckMouseEvent(WebPointerProperties::PointerType::kMouse, 0, 472 CreateAndCheckMouseEvent(WebPointerProperties::PointerType::kMouse, 0,
460 expected_mouse_id_, true, 473 expected_mouse_id_, true,
461 WebInputEvent::kNoModifiers, 4); 474 WebInputEvent::kNoModifiers, 4);
462 CreateAndCheckTouchEvent(WebPointerProperties::PointerType::kTouch, 0, 475 CreateAndCheckTouchEvent(WebPointerProperties::PointerType::kTouch, 0,
463 mapped_id_start_, true, WebTouchPoint::kStateMoved, 476 mapped_id_start_, true, WebTouchPoint::kStateMoved,
464 3); 477 3);
465 } 478 }
466 479
467 } // namespace blink 480 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698