Index: third_party/WebKit/Source/core/events/PointerEventFactoryTest.cpp |
diff --git a/third_party/WebKit/Source/core/events/PointerEventFactoryTest.cpp b/third_party/WebKit/Source/core/events/PointerEventFactoryTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..32da63ac4118f17966d3a895d5cd3b938123fa5f |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/events/PointerEventFactoryTest.cpp |
@@ -0,0 +1,151 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "config.h" |
+#include "core/events/PointerEventFactory.h" |
+ |
+#include "core/frame/FrameView.h" |
+#include "core/page/Page.h" |
+#include "public/platform/WebPointerProperties.h" |
+#include <gtest/gtest.h> |
+ |
+namespace blink { |
+ |
+class PointerEventFactoryTest : public ::testing::Test { |
+protected: |
+ void SetUp() override; |
+ PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckTouchEvent( |
+ WebPointerProperties::PointerType, int id, |
+ int uid, bool isPrimary); |
+ PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckMouseEvent(int uid, bool isPrimary); |
+ |
+ |
+ 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.
|
+ public: |
+ PlatformTouchPointBuilder(WebPointerProperties::PointerType, int); |
+ }; |
+ PointerEventFactory m_pointerEventFactory; |
+ 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
|
+ unsigned m_mappedIdStart; |
+}; |
+ |
+void PointerEventFactoryTest::SetUp() |
+{ |
+ m_expectedMouseId = 1; |
+ m_mappedIdStart = 2; |
+ |
+} |
+ |
+PointerEventFactoryTest::PlatformTouchPointBuilder::PlatformTouchPointBuilder( |
+ WebPointerProperties::PointerType pointerType, int id) |
+{ |
+ m_pointerProperties.id = id; |
+ m_pointerProperties.pointerType = pointerType; |
+} |
+ |
+PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckTouchEvent( |
+ WebPointerProperties::PointerType pointerType, int id, |
+ 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.
|
+{ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create( |
+ EventTypeNames::pointerdown, PointerEventFactoryTest::PlatformTouchPointBuilder(pointerType, id), PlatformEvent::NoModifiers, 0, 0, 0, 0); |
+ EXPECT_EQ(pointerEvent->pointerId(), uid); |
+ EXPECT_EQ(pointerEvent->isPrimary(), isPrimary); |
+ return pointerEvent; |
+} |
+ |
+PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckMouseEvent(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.
|
+{ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create( |
+ EventTypeNames::pointerenter, PlatformMouseEvent(), nullptr, nullptr); |
+ EXPECT_EQ(pointerEvent->pointerId(), uid); |
+ EXPECT_EQ(pointerEvent->isPrimary(), isPrimary); |
+ return pointerEvent; |
+} |
+ |
+TEST_F(PointerEventFactoryTest, MousePointer) |
+{ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckMouseEvent(m_expectedMouseId, true); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckMouseEvent(m_expectedMouseId, true); |
+ |
+ m_pointerEventFactory.remove(pointerEvent1); |
+ |
+ createAndCheckMouseEvent(m_expectedMouseId, true); |
+ |
+ m_pointerEventFactory.remove(pointerEvent1); |
+ m_pointerEventFactory.remove(pointerEvent2); |
+} |
+ |
+TEST_F(PointerEventFactoryTest, TouchPointerPrimaryRemovedWhileAnotherIsThere) |
+{ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 1, m_mappedIdStart+1, false); |
+ |
+ m_pointerEventFactory.remove(pointerEvent1); |
+ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 2, m_mappedIdStart+2, false); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 1, m_mappedIdStart+1, false); |
+ |
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
|
+} |
+ |
+TEST_F(PointerEventFactoryTest, TouchPointerReleasedAndPressedAgain) |
+{ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 1, m_mappedIdStart+1, false); |
+ |
+ m_pointerEventFactory.remove(pointerEvent1); |
+ m_pointerEventFactory.remove(pointerEvent2); |
+ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 1, m_mappedIdStart+2, true); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart+3, false); |
+ |
+ m_pointerEventFactory.clear(); |
mustaq
2015/11/25 21:43:40
Great coverage of possible cases, thanks.
|
+ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent5 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 10, m_mappedIdStart+4, true); |
+ |
+} |
+ |
+TEST_F(PointerEventFactoryTest, TouchAndDrag) |
+{ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); |
+ |
+ m_pointerEventFactory.remove(pointerEvent1); |
+ m_pointerEventFactory.remove(pointerEvent2); |
+ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart+1, true); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent5 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart+1, true); |
+ |
+ m_pointerEventFactory.remove(pointerEvent1); |
+ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent6 = createAndCheckTouchEvent(WebPointerProperties::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.
|
+ |
+} |
+ |
+TEST_F(PointerEventFactoryTest, MouseAndTouchAndPen) |
+{ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent1 = createAndCheckMouseEvent(m_expectedMouseId, true); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent2 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart, true); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent3 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mappedIdStart+1, true); |
+ |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent4 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 1, m_mappedIdStart+2, false); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent5 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 2, m_mappedIdStart+3, false); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent6 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mappedIdStart+1, true); |
+ RefPtrWillBeRawPtr<PointerEvent> pointerEvent7 = createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 47213, m_mappedIdStart+4, false); |
+ |
+ m_pointerEventFactory.remove(pointerEvent2); |
+ m_pointerEventFactory.remove(pointerEvent4); |
+ m_pointerEventFactory.remove(pointerEvent5); |
+ |
+ createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 100, m_mappedIdStart+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.
|
+ |
+ m_pointerEventFactory.clear(); |
+ |
+ createAndCheckMouseEvent(m_expectedMouseId, true); |
+ createAndCheckTouchEvent(WebPointerProperties::PointerType::Touch, 0, m_mappedIdStart+6, true); |
+ createAndCheckTouchEvent(WebPointerProperties::PointerType::Pen, 0, m_mappedIdStart+7, true); |
+} |
+ |
+} // namespace blink |