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

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

Issue 2510133002: Add getCoalescedEvents API to PointerEvent (Closed)
Patch Set: rebase Created 4 years 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>
11 #include <gtest/gtest.h> 11 #include <gtest/gtest.h>
12 12
13 namespace blink { 13 namespace blink {
14 14
15 namespace {
16
17 const char* pointerTypeNameForWebPointPointerType(
18 WebPointerProperties::PointerType type) {
19 switch (type) {
20 case WebPointerProperties::PointerType::Unknown:
21 return "";
22 case WebPointerProperties::PointerType::Touch:
23 return "touch";
24 case WebPointerProperties::PointerType::Pen:
25 case WebPointerProperties::PointerType::Eraser:
26 return "pen";
27 case WebPointerProperties::PointerType::Mouse:
28 return "mouse";
29 }
30 NOTREACHED();
31 return "";
32 }
33 }
34
15 class PointerEventFactoryTest : public ::testing::Test { 35 class PointerEventFactoryTest : public ::testing::Test {
16 protected: 36 protected:
17 void SetUp() override; 37 void SetUp() override;
18 PointerEvent* createAndCheckTouchCancel(WebPointerProperties::PointerType, 38 PointerEvent* createAndCheckTouchCancel(WebPointerProperties::PointerType,
19 int rawId, 39 int rawId,
20 int uniqueId, 40 int uniqueId,
21 bool isPrimary); 41 bool isPrimary);
22 PointerEvent* createAndCheckTouchEvent( 42 PointerEvent* createAndCheckTouchEvent(
23 WebPointerProperties::PointerType, 43 WebPointerProperties::PointerType,
24 int rawId, 44 int rawId,
25 int uniqueId, 45 int uniqueId,
26 bool isPrimary, 46 bool isPrimary,
27 PlatformTouchPoint::TouchState = PlatformTouchPoint::TouchPressed); 47 PlatformTouchPoint::TouchState = PlatformTouchPoint::TouchPressed,
48 size_t coalescedEventCount = 0);
28 PointerEvent* createAndCheckMouseEvent( 49 PointerEvent* createAndCheckMouseEvent(
29 WebPointerProperties::PointerType, 50 WebPointerProperties::PointerType,
30 int rawId, 51 int rawId,
31 int uniqueId, 52 int uniqueId,
32 bool isPrimary, 53 bool isPrimary,
33 PlatformEvent::Modifiers = PlatformEvent::NoModifiers); 54 PlatformEvent::Modifiers = PlatformEvent::NoModifiers,
55 size_t coalescedEventCount = 0);
34 void createAndCheckPointerTransitionEvent(PointerEvent*, const AtomicString&); 56 void createAndCheckPointerTransitionEvent(PointerEvent*, const AtomicString&);
35 57
36 PointerEventFactory m_pointerEventFactory; 58 PointerEventFactory m_pointerEventFactory;
37 unsigned m_expectedMouseId; 59 unsigned m_expectedMouseId;
38 unsigned m_mappedIdStart; 60 unsigned m_mappedIdStart;
39 61
40 class PlatformTouchPointBuilder : public PlatformTouchPoint { 62 class PlatformTouchPointBuilder : public PlatformTouchPoint {
41 public: 63 public:
42 PlatformTouchPointBuilder(WebPointerProperties::PointerType, 64 PlatformTouchPointBuilder(WebPointerProperties::PointerType,
43 int, 65 int,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 100
79 PointerEvent* PointerEventFactoryTest::createAndCheckTouchCancel( 101 PointerEvent* PointerEventFactoryTest::createAndCheckTouchCancel(
80 WebPointerProperties::PointerType pointerType, 102 WebPointerProperties::PointerType pointerType,
81 int rawId, 103 int rawId,
82 int uniqueId, 104 int uniqueId,
83 bool isPrimary) { 105 bool isPrimary) {
84 PointerEvent* pointerEvent = 106 PointerEvent* pointerEvent =
85 m_pointerEventFactory.createPointerCancelEvent(uniqueId, pointerType); 107 m_pointerEventFactory.createPointerCancelEvent(uniqueId, pointerType);
86 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); 108 EXPECT_EQ(uniqueId, pointerEvent->pointerId());
87 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); 109 EXPECT_EQ(isPrimary, pointerEvent->isPrimary());
110 EXPECT_EQ(pointerTypeNameForWebPointPointerType(pointerType),
111 pointerEvent->pointerType());
88 return pointerEvent; 112 return pointerEvent;
89 } 113 }
90 114
91 void PointerEventFactoryTest::createAndCheckPointerTransitionEvent( 115 void PointerEventFactoryTest::createAndCheckPointerTransitionEvent(
92 PointerEvent* pointerEvent, 116 PointerEvent* pointerEvent,
93 const AtomicString& type) { 117 const AtomicString& type) {
94 PointerEvent* clonePointerEvent = 118 PointerEvent* clonePointerEvent =
95 m_pointerEventFactory.createPointerBoundaryEvent(pointerEvent, type, 119 m_pointerEventFactory.createPointerBoundaryEvent(pointerEvent, type,
96 nullptr); 120 nullptr);
97 EXPECT_EQ(clonePointerEvent->pointerType(), pointerEvent->pointerType()); 121 EXPECT_EQ(clonePointerEvent->pointerType(), pointerEvent->pointerType());
98 EXPECT_EQ(clonePointerEvent->pointerId(), pointerEvent->pointerId()); 122 EXPECT_EQ(clonePointerEvent->pointerId(), pointerEvent->pointerId());
99 EXPECT_EQ(clonePointerEvent->isPrimary(), pointerEvent->isPrimary()); 123 EXPECT_EQ(clonePointerEvent->isPrimary(), pointerEvent->isPrimary());
100 EXPECT_EQ(clonePointerEvent->type(), type); 124 EXPECT_EQ(clonePointerEvent->type(), type);
101 } 125 }
102 126
103 PointerEvent* PointerEventFactoryTest::createAndCheckTouchEvent( 127 PointerEvent* PointerEventFactoryTest::createAndCheckTouchEvent(
104 WebPointerProperties::PointerType pointerType, 128 WebPointerProperties::PointerType pointerType,
105 int rawId, 129 int rawId,
106 int uniqueId, 130 int uniqueId,
107 bool isPrimary, 131 bool isPrimary,
108 PlatformTouchPoint::TouchState state) { 132 PlatformTouchPoint::TouchState state,
133 size_t coalescedEventCount) {
134 Vector<PlatformTouchPoint> coalescedEvents;
135 for (size_t i = 0; i < coalescedEventCount; i++) {
136 coalescedEvents.append(PointerEventFactoryTest::PlatformTouchPointBuilder(
137 pointerType, rawId, state));
138 }
109 PointerEvent* pointerEvent = m_pointerEventFactory.create( 139 PointerEvent* pointerEvent = m_pointerEventFactory.create(
110 EventTypeNames::pointerdown,
111 PointerEventFactoryTest::PlatformTouchPointBuilder(pointerType, rawId, 140 PointerEventFactoryTest::PlatformTouchPointBuilder(pointerType, rawId,
112 state), 141 state),
113 PlatformEvent::NoModifiers, FloatSize(), FloatPoint(), nullptr); 142 coalescedEvents, PlatformEvent::NoModifiers, nullptr, nullptr);
114 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); 143 EXPECT_EQ(uniqueId, pointerEvent->pointerId());
115 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); 144 EXPECT_EQ(isPrimary, pointerEvent->isPrimary());
145 const char* expectedPointerType =
146 pointerTypeNameForWebPointPointerType(pointerType);
147 EXPECT_EQ(expectedPointerType, pointerEvent->pointerType());
148 EXPECT_EQ(coalescedEventCount, pointerEvent->getCoalescedEvents().size());
149 for (size_t i = 0; i < coalescedEventCount; i++) {
150 EXPECT_EQ(uniqueId, pointerEvent->getCoalescedEvents()[i]->pointerId());
151 EXPECT_EQ(isPrimary, pointerEvent->getCoalescedEvents()[i]->isPrimary());
152 EXPECT_EQ(expectedPointerType, pointerEvent->pointerType());
153 }
116 return pointerEvent; 154 return pointerEvent;
117 } 155 }
118 156
119 PointerEvent* PointerEventFactoryTest::createAndCheckMouseEvent( 157 PointerEvent* PointerEventFactoryTest::createAndCheckMouseEvent(
120 WebPointerProperties::PointerType pointerType, 158 WebPointerProperties::PointerType pointerType,
121 int rawId, 159 int rawId,
122 int uniqueId, 160 int uniqueId,
123 bool isPrimary, 161 bool isPrimary,
124 PlatformEvent::Modifiers modifiers) { 162 PlatformEvent::Modifiers modifiers,
163 size_t coalescedEventCount) {
164 Vector<PlatformMouseEvent> coalescedEvents;
165 for (size_t i = 0; i < coalescedEventCount; i++) {
166 coalescedEvents.append(PointerEventFactoryTest::PlatformMouseEventBuilder(
167 pointerType, rawId, modifiers));
168 }
125 PointerEvent* pointerEvent = m_pointerEventFactory.create( 169 PointerEvent* pointerEvent = m_pointerEventFactory.create(
126 EventTypeNames::mousedown, 170 coalescedEventCount ? EventTypeNames::mousemove
127 PlatformMouseEventBuilder(pointerType, rawId, modifiers), nullptr); 171 : EventTypeNames::mousedown,
172 PointerEventFactoryTest::PlatformMouseEventBuilder(pointerType, rawId,
173 modifiers),
174 coalescedEvents, nullptr);
128 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); 175 EXPECT_EQ(uniqueId, pointerEvent->pointerId());
129 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); 176 EXPECT_EQ(isPrimary, pointerEvent->isPrimary());
177 const char* expectedPointerType =
178 pointerTypeNameForWebPointPointerType(pointerType);
179 EXPECT_EQ(expectedPointerType, pointerEvent->pointerType());
180 EXPECT_EQ(coalescedEventCount, pointerEvent->getCoalescedEvents().size());
181 for (size_t i = 0; i < coalescedEventCount; i++) {
182 EXPECT_EQ(uniqueId, pointerEvent->getCoalescedEvents()[i]->pointerId());
183 EXPECT_EQ(isPrimary, pointerEvent->getCoalescedEvents()[i]->isPrimary());
184 EXPECT_EQ(expectedPointerType, pointerEvent->pointerType());
185 }
130 return pointerEvent; 186 return pointerEvent;
131 } 187 }
132 188
133 TEST_F(PointerEventFactoryTest, MousePointer) { 189 TEST_F(PointerEventFactoryTest, MousePointer) {
134 EXPECT_TRUE(m_pointerEventFactory.isActive(m_expectedMouseId)); 190 EXPECT_TRUE(m_pointerEventFactory.isActive(m_expectedMouseId));
135 EXPECT_FALSE(m_pointerEventFactory.isActiveButtonsState(m_expectedMouseId)); 191 EXPECT_FALSE(m_pointerEventFactory.isActiveButtonsState(m_expectedMouseId));
136 192
137 PointerEvent* pointerEvent1 = createAndCheckMouseEvent( 193 PointerEvent* pointerEvent1 = createAndCheckMouseEvent(
138 WebPointerProperties::PointerType::Mouse, 0, m_expectedMouseId, true); 194 WebPointerProperties::PointerType::Mouse, 0, m_expectedMouseId, true);
139 PointerEvent* pointerEvent2 = createAndCheckMouseEvent( 195 PointerEvent* pointerEvent2 = createAndCheckMouseEvent(
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 437 }
382 438
383 for (int i = 0; i < 100; ++i) { 439 for (int i = 0; i < 100; ++i) {
384 createAndCheckTouchEvent(WebPointerProperties::PointerType::Mouse, i, 440 createAndCheckTouchEvent(WebPointerProperties::PointerType::Mouse, i,
385 m_expectedMouseId, true); 441 m_expectedMouseId, true);
386 } 442 }
387 createAndCheckTouchCancel(WebPointerProperties::PointerType::Mouse, 0, 443 createAndCheckTouchCancel(WebPointerProperties::PointerType::Mouse, 0,
388 m_expectedMouseId, true); 444 m_expectedMouseId, true);
389 } 445 }
390 446
447 TEST_F(PointerEventFactoryTest, CoalescedEvents) {
448 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 0,
449 m_expectedMouseId, true, PlatformEvent::NoModifiers,
450 4);
451 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0,
452 m_mappedIdStart, true,
453 PlatformTouchPoint::TouchMoved, 3);
454 }
455
391 } // namespace blink 456 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698