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) { | |
mustaq
2016/11/21 20:53:53
May be pass id[], isPrimary[] and pointerType[] an
Navid Zolghadr
2016/11/21 21:31:21
I'm a little confused here. What throw? The code n
| |
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()); | |
mustaq
2016/11/21 20:53:53
Also check pointerType. Same for the container ("d
| |
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 coalescedEventCount ? EventTypeNames::mousemove |
127 PlatformMouseEventBuilder(pointerType, rawId, modifiers), nullptr); | 145 : EventTypeNames::mousedown, |
146 PointerEventFactoryTest::PlatformMouseEventBuilder(pointerType, rawId, | |
147 modifiers), | |
148 coalescedEvents, nullptr); | |
128 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); | 149 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); |
129 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); | 150 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); |
151 EXPECT_EQ(coalescedEventCount, pointerEvent->getCoalescedEvents().size()); | |
152 for (size_t i = 0; i < coalescedEventCount; i++) { | |
153 EXPECT_EQ(uniqueId, pointerEvent->getCoalescedEvents()[i]->pointerId()); | |
154 EXPECT_EQ(isPrimary, pointerEvent->getCoalescedEvents()[i]->isPrimary()); | |
155 } | |
156 | |
130 return pointerEvent; | 157 return pointerEvent; |
131 } | 158 } |
132 | 159 |
133 TEST_F(PointerEventFactoryTest, MousePointer) { | 160 TEST_F(PointerEventFactoryTest, MousePointer) { |
134 EXPECT_TRUE(m_pointerEventFactory.isActive(m_expectedMouseId)); | 161 EXPECT_TRUE(m_pointerEventFactory.isActive(m_expectedMouseId)); |
135 EXPECT_FALSE(m_pointerEventFactory.isActiveButtonsState(m_expectedMouseId)); | 162 EXPECT_FALSE(m_pointerEventFactory.isActiveButtonsState(m_expectedMouseId)); |
136 | 163 |
137 PointerEvent* pointerEvent1 = createAndCheckMouseEvent( | 164 PointerEvent* pointerEvent1 = createAndCheckMouseEvent( |
138 WebPointerProperties::PointerType::Mouse, 0, m_expectedMouseId, true); | 165 WebPointerProperties::PointerType::Mouse, 0, m_expectedMouseId, true); |
139 PointerEvent* pointerEvent2 = createAndCheckMouseEvent( | 166 PointerEvent* pointerEvent2 = createAndCheckMouseEvent( |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 } | 408 } |
382 | 409 |
383 for (int i = 0; i < 100; ++i) { | 410 for (int i = 0; i < 100; ++i) { |
384 createAndCheckTouchEvent(WebPointerProperties::PointerType::Mouse, i, | 411 createAndCheckTouchEvent(WebPointerProperties::PointerType::Mouse, i, |
385 m_expectedMouseId, true); | 412 m_expectedMouseId, true); |
386 } | 413 } |
387 createAndCheckTouchCancel(WebPointerProperties::PointerType::Mouse, 0, | 414 createAndCheckTouchCancel(WebPointerProperties::PointerType::Mouse, 0, |
388 m_expectedMouseId, true); | 415 m_expectedMouseId, true); |
389 } | 416 } |
390 | 417 |
418 TEST_F(PointerEventFactoryTest, CoalescedEvents) { | |
419 createAndCheckMouseEvent(WebPointerProperties::PointerType::Mouse, 0, | |
420 m_expectedMouseId, true, PlatformEvent::NoModifiers, | |
421 4); | |
422 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, | |
423 m_mappedIdStart, true, | |
424 PlatformTouchPoint::TouchMoved, 3); | |
425 } | |
426 | |
391 } // namespace blink | 427 } // namespace blink |
OLD | NEW |