OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 #include "core/events/PointerEventFactory.h" | |
7 | |
8 #include "core/frame/FrameView.h" | |
9 #include "core/page/Page.h" | |
10 #include "public/platform/WebPointerProperties.h" | |
11 #include <gtest/gtest.h> | |
12 | |
13 namespace blink { | |
14 | |
15 class PointerEventFactoryTest : public ::testing::Test { | |
16 protected: | |
17 void SetUp() override; | |
18 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckTouchEvent( | |
19 WebPointerProperties::PointerType, int id, | |
20 int uid, bool isPrimary); | |
21 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckMouseEvent(int uid, bool isPrimary); | |
22 | |
23 | |
24 class PlatformTouchPointBuilder : public PlatformTouchPoint { | |
mustaq
2015/11/25 21:43:40
Please move the inner class def to the end of the
Navid Zolghadr
2015/11/26 20:15:10
Sure.
| |
25 public: | |
26 PlatformTouchPointBuilder(WebPointerProperties::PointerType, int); | |
27 }; | |
28 PointerEventFactory m_pointerEventFactory; | |
29 unsigned m_expectedMouseId; | |
mustaq
2015/11/25 21:43:40
private? const?
Navid Zolghadr
2015/11/26 20:15:09
None of them is possible. As initializing the vari
| |
30 unsigned m_mappedIdStart; | |
31 }; | |
32 | |
33 void PointerEventFactoryTest::SetUp() | |
34 { | |
35 m_expectedMouseId = 1; | |
36 m_mappedIdStart = 2; | |
37 | |
38 } | |
39 | |
40 PointerEventFactoryTest::PlatformTouchPointBuilder::PlatformTouchPointBuilder( | |
41 WebPointerProperties::PointerType pointerType, int id) | |
42 { | |
43 m_pointerProperties.id = id; | |
44 m_pointerProperties.pointerType = pointerType; | |
45 } | |
46 | |
47 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckTouc hEvent( | |
48 WebPointerProperties::PointerType pointerType, int id, | |
49 int uid, bool isPrimary) | |
mustaq
2015/11/25 21:43:40
Please clarify the names id vs uid. I would prefer
Navid Zolghadr
2015/11/25 22:22:59
Done.
| |
50 { | |
51 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create ( | |
52 EventTypeNames::pointerdown, PointerEventFactoryTest::PlatformTouchPoint Builder(pointerType, id), PlatformEvent::NoModifiers, 0, 0, 0, 0); | |
53 EXPECT_EQ(pointerEvent->pointerId(), uid); | |
54 EXPECT_EQ(pointerEvent->isPrimary(), isPrimary); | |
55 return pointerEvent; | |
56 } | |
57 | |
58 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckMous eEvent(int uid, bool isPrimary) | |
mustaq
2015/11/25 21:43:40
- Include pointerType in parameter, and add a test
Navid Zolghadr
2015/11/25 22:22:59
Done.
| |
59 { | |
60 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create ( | |
61 EventTypeNames::pointerenter, PlatformMouseEvent(), nullptr, nullptr); | |
62 EXPECT_EQ(pointerEvent->pointerId(), uid); | |
63 EXPECT_EQ(pointerEvent->isPrimary(), isPrimary); | |
64 return pointerEvent; | |
65 } | |
66 | |
67 TEST_F(PointerEventFactoryTest, MousePointer) | |
68 { | |
69 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckMouseEvent(m_ expectedMouseId, true); | |
70 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckMouseEvent(m_ expectedMouseId, true); | |
71 | |
72 m_pointerEventFactory.remove(pointerEvent1); | |
73 | |
74 createAndCheckMouseEvent(m_expectedMouseId, true); | |
75 | |
76 m_pointerEventFactory.remove(pointerEvent1); | |
77 m_pointerEventFactory.remove(pointerEvent2); | |
78 } | |
79 | |
80 TEST_F(PointerEventFactoryTest, TouchPointerPrimaryRemovedWhileAnotherIsThere) | |
81 { | |
82 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); | |
83 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+1, false); | |
84 | |
85 m_pointerEventFactory.remove(pointerEvent1); | |
86 | |
87 RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 2, m_mappedIdStart+2, false); | |
88 RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+1, false); | |
89 | |
mustaq
2015/11/25 21:43:40
Can remove the last empty line in the function. Or
Navid Zolghadr
2015/11/25 22:22:59
I was copying it from the other test class. I thou
| |
90 } | |
91 | |
92 TEST_F(PointerEventFactoryTest, TouchPointerReleasedAndPressedAgain) | |
93 { | |
94 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); | |
95 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+1, false); | |
96 | |
97 m_pointerEventFactory.remove(pointerEvent1); | |
98 m_pointerEventFactory.remove(pointerEvent2); | |
99 | |
100 RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+2, true); | |
101 RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart+3, false); | |
102 | |
103 m_pointerEventFactory.clear(); | |
mustaq
2015/11/25 21:43:40
Great coverage of possible cases, thanks.
| |
104 | |
105 RefPtrWillBeRawPtr<PointerEvent> pointerEvent5 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 10, m_mappedIdStart+4, true); | |
106 | |
107 } | |
108 | |
109 TEST_F(PointerEventFactoryTest, TouchAndDrag) | |
110 { | |
111 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); | |
112 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); | |
113 RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); | |
114 | |
115 m_pointerEventFactory.remove(pointerEvent1); | |
116 m_pointerEventFactory.remove(pointerEvent2); | |
117 | |
118 RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart+1, true); | |
119 RefPtrWillBeRawPtr<PointerEvent> pointerEvent5 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart+1, true); | |
120 | |
121 m_pointerEventFactory.remove(pointerEvent1); | |
122 | |
123 RefPtrWillBeRawPtr<PointerEvent> pointerEvent6 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart+1, true); | |
mustaq
2015/11/25 21:43:40
Shouldn't we expect m_mappedIdStart+2 here?
Navid Zolghadr
2015/11/25 22:22:59
I'll add a comment to explain what happened here.
| |
124 | |
125 } | |
126 | |
127 TEST_F(PointerEventFactoryTest, MouseAndTouchAndPen) | |
128 { | |
129 RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckMouseEvent(m_ expectedMouseId, true); | |
130 RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); | |
131 RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Pen, 0, m_mappedIdStart+1, true); | |
132 | |
133 RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 1, m_mappedIdStart+2, false); | |
134 RefPtrWillBeRawPtr<PointerEvent> pointerEvent5 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Touch, 2, m_mappedIdStart+3, false); | |
135 RefPtrWillBeRawPtr<PointerEvent> pointerEvent6 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Pen, 0, m_mappedIdStart+1, true); | |
136 RefPtrWillBeRawPtr<PointerEvent> pointerEvent7 = createAndCheckTouchEvent(We bPointerProperties::PointerType::Pen, 47213, m_mappedIdStart+4, false); | |
137 | |
138 m_pointerEventFactory.remove(pointerEvent2); | |
139 m_pointerEventFactory.remove(pointerEvent4); | |
140 m_pointerEventFactory.remove(pointerEvent5); | |
141 | |
142 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 100, m_ma ppedIdStart+5, true); | |
mustaq
2015/11/25 21:43:40
Please do a similar test for a new "primary" of ty
Navid Zolghadr
2015/11/25 22:22:59
Done.
| |
143 | |
144 m_pointerEventFactory.clear(); | |
145 | |
146 createAndCheckMouseEvent(m_expectedMouseId, true); | |
147 createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mapp edIdStart+6, true); | |
148 createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mapped IdStart+7, true); | |
149 } | |
150 | |
151 } // namespace blink | |
OLD | NEW |