OLD | NEW |
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 class PointerEventFactoryTest : public ::testing::Test { | 15 class PointerEventFactoryTest : public ::testing::Test { |
16 protected: | 16 protected: |
17 void SetUp() override; | 17 void SetUp() override; |
18 PointerEvent* createAndCheckTouchCancel(WebPointerProperties::PointerType, | 18 PointerEvent* createAndCheckTouchCancel(WebPointerProperties::PointerType, |
19 int rawId, | 19 int rawId, |
20 int uniqueId, | 20 int uniqueId, |
21 bool isPrimary); | 21 bool isPrimary); |
22 PointerEvent* createAndCheckTouchEvent( | 22 PointerEvent* createAndCheckTouchEvent( |
23 WebPointerProperties::PointerType, | 23 WebPointerProperties::PointerType, |
24 int rawId, | 24 int rawId, |
25 int uniqueId, | 25 int uniqueId, |
26 bool isPrimary, | 26 bool isPrimary, |
27 PlatformTouchPoint::TouchState = PlatformTouchPoint::TouchPressed); | 27 PlatformTouchPoint::TouchState = PlatformTouchPoint::TouchPressed, |
| 28 size_t coalescedEventCount = 0); |
28 PointerEvent* createAndCheckMouseEvent( | 29 PointerEvent* createAndCheckMouseEvent( |
29 WebPointerProperties::PointerType, | 30 WebPointerProperties::PointerType, |
30 int rawId, | 31 int rawId, |
31 int uniqueId, | 32 int uniqueId, |
32 bool isPrimary, | 33 bool isPrimary, |
33 PlatformEvent::Modifiers = PlatformEvent::NoModifiers); | 34 PlatformEvent::Modifiers = PlatformEvent::NoModifiers, |
| 35 size_t coalescedEventCount = 0); |
34 void createAndCheckPointerTransitionEvent(PointerEvent*, const AtomicString&); | 36 void createAndCheckPointerTransitionEvent(PointerEvent*, const AtomicString&); |
35 | 37 |
36 PointerEventFactory m_pointerEventFactory; | 38 PointerEventFactory m_pointerEventFactory; |
37 unsigned m_expectedMouseId; | 39 unsigned m_expectedMouseId; |
38 unsigned m_mappedIdStart; | 40 unsigned m_mappedIdStart; |
39 | 41 |
40 class PlatformTouchPointBuilder : public PlatformTouchPoint { | 42 class PlatformTouchPointBuilder : public PlatformTouchPoint { |
41 public: | 43 public: |
42 PlatformTouchPointBuilder(WebPointerProperties::PointerType, | 44 PlatformTouchPointBuilder(WebPointerProperties::PointerType, |
43 int, | 45 int, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 EXPECT_EQ(clonePointerEvent->pointerId(), pointerEvent->pointerId()); | 100 EXPECT_EQ(clonePointerEvent->pointerId(), pointerEvent->pointerId()); |
99 EXPECT_EQ(clonePointerEvent->isPrimary(), pointerEvent->isPrimary()); | 101 EXPECT_EQ(clonePointerEvent->isPrimary(), pointerEvent->isPrimary()); |
100 EXPECT_EQ(clonePointerEvent->type(), type); | 102 EXPECT_EQ(clonePointerEvent->type(), type); |
101 } | 103 } |
102 | 104 |
103 PointerEvent* PointerEventFactoryTest::createAndCheckTouchEvent( | 105 PointerEvent* PointerEventFactoryTest::createAndCheckTouchEvent( |
104 WebPointerProperties::PointerType pointerType, | 106 WebPointerProperties::PointerType pointerType, |
105 int rawId, | 107 int rawId, |
106 int uniqueId, | 108 int uniqueId, |
107 bool isPrimary, | 109 bool isPrimary, |
108 PlatformTouchPoint::TouchState state) { | 110 PlatformTouchPoint::TouchState state, |
| 111 size_t coalescedEventCount) { |
| 112 Vector<PlatformTouchPoint> coalescedEvents; |
| 113 for (size_t i = 0; i < coalescedEventCount; i++) { |
| 114 coalescedEvents.append(PointerEventFactoryTest::PlatformTouchPointBuilder( |
| 115 pointerType, rawId, state)); |
| 116 } |
109 PointerEvent* pointerEvent = m_pointerEventFactory.create( | 117 PointerEvent* pointerEvent = m_pointerEventFactory.create( |
110 EventTypeNames::pointerdown, | |
111 PointerEventFactoryTest::PlatformTouchPointBuilder(pointerType, rawId, | 118 PointerEventFactoryTest::PlatformTouchPointBuilder(pointerType, rawId, |
112 state), | 119 state), |
113 PlatformEvent::NoModifiers, FloatSize(), FloatPoint(), nullptr); | 120 coalescedEvents, PlatformEvent::NoModifiers, nullptr, nullptr); |
114 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); | 121 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); |
115 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); | 122 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); |
| 123 EXPECT_EQ(coalescedEventCount, pointerEvent->getCoalescedEvents().size()); |
| 124 for (size_t i = 0; i < coalescedEventCount; i++) { |
| 125 EXPECT_EQ(uniqueId, pointerEvent->getCoalescedEvents()[i]->pointerId()); |
| 126 EXPECT_EQ(isPrimary, pointerEvent->getCoalescedEvents()[i]->isPrimary()); |
| 127 } |
116 return pointerEvent; | 128 return pointerEvent; |
117 } | 129 } |
118 | 130 |
119 PointerEvent* PointerEventFactoryTest::createAndCheckMouseEvent( | 131 PointerEvent* PointerEventFactoryTest::createAndCheckMouseEvent( |
120 WebPointerProperties::PointerType pointerType, | 132 WebPointerProperties::PointerType pointerType, |
121 int rawId, | 133 int rawId, |
122 int uniqueId, | 134 int uniqueId, |
123 bool isPrimary, | 135 bool isPrimary, |
124 PlatformEvent::Modifiers modifiers) { | 136 PlatformEvent::Modifiers modifiers, |
| 137 size_t coalescedEventCount) { |
| 138 Vector<PlatformMouseEvent> coalescedEvents; |
| 139 for (size_t i = 0; i < coalescedEventCount; i++) { |
| 140 coalescedEvents.append(PointerEventFactoryTest::PlatformMouseEventBuilder( |
| 141 pointerType, rawId, modifiers)); |
| 142 } |
125 PointerEvent* pointerEvent = m_pointerEventFactory.create( | 143 PointerEvent* pointerEvent = m_pointerEventFactory.create( |
126 EventTypeNames::mousedown, | 144 EventTypeNames::mousedown, |
127 PlatformMouseEventBuilder(pointerType, rawId, modifiers), nullptr); | 145 PointerEventFactoryTest::PlatformMouseEventBuilder(pointerType, rawId, |
| 146 modifiers), |
| 147 coalescedEvents, nullptr); |
128 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); | 148 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); |
129 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); | 149 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); |
| 150 EXPECT_EQ(coalescedEventCount, pointerEvent->getCoalescedEvents().size()); |
| 151 for (size_t i = 0; i < coalescedEventCount; i++) { |
| 152 EXPECT_EQ(uniqueId, pointerEvent->getCoalescedEvents()[i]->pointerId()); |
| 153 EXPECT_EQ(isPrimary, pointerEvent->getCoalescedEvents()[i]->isPrimary()); |
| 154 } |
| 155 |
130 return pointerEvent; | 156 return pointerEvent; |
131 } | 157 } |
132 | 158 |
133 TEST_F(PointerEventFactoryTest, MousePointer) { | 159 TEST_F(PointerEventFactoryTest, MousePointer) { |
134 EXPECT_TRUE(m_pointerEventFactory.isActive(m_expectedMouseId)); | 160 EXPECT_TRUE(m_pointerEventFactory.isActive(m_expectedMouseId)); |
135 EXPECT_FALSE(m_pointerEventFactory.isActiveButtonsState(m_expectedMouseId)); | 161 EXPECT_FALSE(m_pointerEventFactory.isActiveButtonsState(m_expectedMouseId)); |
136 | 162 |
137 PointerEvent* pointerEvent1 = createAndCheckMouseEvent( | 163 PointerEvent* pointerEvent1 = createAndCheckMouseEvent( |
138 WebPointerProperties::PointerType::Mouse, 0, m_expectedMouseId, true); | 164 WebPointerProperties::PointerType::Mouse, 0, m_expectedMouseId, true); |
139 PointerEvent* pointerEvent2 = createAndCheckMouseEvent( | 165 PointerEvent* pointerEvent2 = createAndCheckMouseEvent( |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 } | 407 } |
382 | 408 |
383 for (int i = 0; i < 100; ++i) { | 409 for (int i = 0; i < 100; ++i) { |
384 createAndCheckTouchEvent(WebPointerProperties::PointerType::Mouse, i, | 410 createAndCheckTouchEvent(WebPointerProperties::PointerType::Mouse, i, |
385 m_expectedMouseId, true); | 411 m_expectedMouseId, true); |
386 } | 412 } |
387 createAndCheckTouchCancel(WebPointerProperties::PointerType::Mouse, 0, | 413 createAndCheckTouchCancel(WebPointerProperties::PointerType::Mouse, 0, |
388 m_expectedMouseId, true); | 414 m_expectedMouseId, true); |
389 } | 415 } |
390 | 416 |
| 417 TEST_F(PointerEventFactoryTest, CoalescedEvents) { |
| 418 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 0, |
| 419 m_expectedMouseId, true, PlatformEvent::NoModifiers, |
| 420 4); |
| 421 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, |
| 422 m_mappedIdStart, true, |
| 423 PlatformTouchPoint::TouchPressed, 3); |
| 424 } |
| 425 |
391 } // namespace blink | 426 } // namespace blink |
OLD | NEW |