| 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 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckTouchCancel( | 18 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckTouchCancel( |
| 19 WebPointerProperties::PointerType, int rawId, | 19 WebPointerProperties::PointerType, int rawId, |
| 20 int uniqueId, bool isPrimary, | 20 int uniqueId, bool isPrimary, |
| 21 PlatformTouchPoint::State = PlatformTouchPoint::TouchReleased); | 21 PlatformTouchPoint::TouchState = PlatformTouchPoint::TouchReleased); |
| 22 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckTouchEvent( | 22 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckTouchEvent( |
| 23 WebPointerProperties::PointerType, int rawId, | 23 WebPointerProperties::PointerType, int rawId, |
| 24 int uniqueId, bool isPrimary, | 24 int uniqueId, bool isPrimary, |
| 25 PlatformTouchPoint::State = PlatformTouchPoint::TouchPressed); | 25 PlatformTouchPoint::TouchState = PlatformTouchPoint::TouchPressed); |
| 26 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckMouseEvent( | 26 PassRefPtrWillBeRawPtr<PointerEvent> createAndCheckMouseEvent( |
| 27 WebPointerProperties::PointerType, int rawId, | 27 WebPointerProperties::PointerType, int rawId, |
| 28 int uniqueId, bool isPrimary, | 28 int uniqueId, bool isPrimary, |
| 29 PlatformEvent::Modifiers = PlatformEvent::NoModifiers); | 29 PlatformEvent::Modifiers = PlatformEvent::NoModifiers); |
| 30 void cloneAndCheckPointerEvent( | 30 void cloneAndCheckPointerEvent( |
| 31 PassRefPtrWillBeRawPtr<PointerEvent>, | 31 PassRefPtrWillBeRawPtr<PointerEvent>, |
| 32 const AtomicString&); | 32 const AtomicString&); |
| 33 | 33 |
| 34 PointerEventFactory m_pointerEventFactory; | 34 PointerEventFactory m_pointerEventFactory; |
| 35 unsigned m_expectedMouseId; | 35 unsigned m_expectedMouseId; |
| 36 unsigned m_mappedIdStart; | 36 unsigned m_mappedIdStart; |
| 37 | 37 |
| 38 class PlatformTouchPointBuilder : public PlatformTouchPoint { | 38 class PlatformTouchPointBuilder : public PlatformTouchPoint { |
| 39 public: | 39 public: |
| 40 PlatformTouchPointBuilder(WebPointerProperties::PointerType, int, | 40 PlatformTouchPointBuilder(WebPointerProperties::PointerType, int, |
| 41 PlatformTouchPoint::State); | 41 PlatformTouchPoint::TouchState); |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 class PlatformMouseEventBuilder : public PlatformMouseEvent { | 44 class PlatformMouseEventBuilder : public PlatformMouseEvent { |
| 45 public: | 45 public: |
| 46 PlatformMouseEventBuilder(WebPointerProperties::PointerType, int, | 46 PlatformMouseEventBuilder(WebPointerProperties::PointerType, int, |
| 47 PlatformEvent::Modifiers); | 47 PlatformEvent::Modifiers); |
| 48 }; | 48 }; |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 void PointerEventFactoryTest::SetUp() | 51 void PointerEventFactoryTest::SetUp() |
| 52 { | 52 { |
| 53 m_expectedMouseId = 1; | 53 m_expectedMouseId = 1; |
| 54 m_mappedIdStart = 2; | 54 m_mappedIdStart = 2; |
| 55 } | 55 } |
| 56 | 56 |
| 57 PointerEventFactoryTest::PlatformTouchPointBuilder::PlatformTouchPointBuilder( | 57 PointerEventFactoryTest::PlatformTouchPointBuilder::PlatformTouchPointBuilder( |
| 58 WebPointerProperties::PointerType pointerType, int id, | 58 WebPointerProperties::PointerType pointerType, int id, |
| 59 PlatformTouchPoint::State state) | 59 PlatformTouchPoint::TouchState state) |
| 60 { | 60 { |
| 61 m_pointerProperties.id = id; | 61 m_pointerProperties.id = id; |
| 62 m_pointerProperties.pointerType = pointerType; | 62 m_pointerProperties.pointerType = pointerType; |
| 63 m_pointerProperties.force = 1.0; | 63 m_pointerProperties.force = 1.0; |
| 64 m_state = state; | 64 m_state = state; |
| 65 } | 65 } |
| 66 | 66 |
| 67 PointerEventFactoryTest::PlatformMouseEventBuilder::PlatformMouseEventBuilder( | 67 PointerEventFactoryTest::PlatformMouseEventBuilder::PlatformMouseEventBuilder( |
| 68 WebPointerProperties::PointerType pointerType, int id, | 68 WebPointerProperties::PointerType pointerType, int id, |
| 69 PlatformEvent::Modifiers modifiers) | 69 PlatformEvent::Modifiers modifiers) |
| 70 { | 70 { |
| 71 m_pointerProperties.pointerType = pointerType; | 71 m_pointerProperties.pointerType = pointerType; |
| 72 m_pointerProperties.id = id; | 72 m_pointerProperties.id = id; |
| 73 m_modifiers = modifiers; | 73 m_modifiers = modifiers; |
| 74 } | 74 } |
| 75 | 75 |
| 76 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckTouc
hCancel( | 76 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckTouc
hCancel( |
| 77 WebPointerProperties::PointerType pointerType, int rawId, | 77 WebPointerProperties::PointerType pointerType, int rawId, |
| 78 int uniqueId, bool isPrimary, | 78 int uniqueId, bool isPrimary, |
| 79 PlatformTouchPoint::State state) | 79 PlatformTouchPoint::TouchState state) |
| 80 { | 80 { |
| 81 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create
PointerCancel( | 81 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create
PointerCancel( |
| 82 PointerEventFactoryTest::PlatformTouchPointBuilder(pointerType, rawId, s
tate)); | 82 PointerEventFactoryTest::PlatformTouchPointBuilder(pointerType, rawId, s
tate)); |
| 83 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); | 83 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); |
| 84 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); | 84 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); |
| 85 return pointerEvent; | 85 return pointerEvent; |
| 86 } | 86 } |
| 87 | 87 |
| 88 void PointerEventFactoryTest::cloneAndCheckPointerEvent( | 88 void PointerEventFactoryTest::cloneAndCheckPointerEvent( |
| 89 PassRefPtrWillBeRawPtr<PointerEvent> prpPointerEvent, | 89 PassRefPtrWillBeRawPtr<PointerEvent> prpPointerEvent, |
| 90 const AtomicString& type) | 90 const AtomicString& type) |
| 91 { | 91 { |
| 92 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = prpPointerEvent; | 92 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = prpPointerEvent; |
| 93 RefPtrWillBeRawPtr<PointerEvent> clonePointerEvent = | 93 RefPtrWillBeRawPtr<PointerEvent> clonePointerEvent = |
| 94 m_pointerEventFactory.create(pointerEvent, type, nullptr); | 94 m_pointerEventFactory.create(pointerEvent, type, nullptr); |
| 95 EXPECT_EQ(clonePointerEvent->pointerType(), pointerEvent->pointerType()); | 95 EXPECT_EQ(clonePointerEvent->pointerType(), pointerEvent->pointerType()); |
| 96 EXPECT_EQ(clonePointerEvent->pointerId(), pointerEvent->pointerId()); | 96 EXPECT_EQ(clonePointerEvent->pointerId(), pointerEvent->pointerId()); |
| 97 EXPECT_EQ(clonePointerEvent->isPrimary(), pointerEvent->isPrimary()); | 97 EXPECT_EQ(clonePointerEvent->isPrimary(), pointerEvent->isPrimary()); |
| 98 EXPECT_EQ(clonePointerEvent->type(), type); | 98 EXPECT_EQ(clonePointerEvent->type(), type); |
| 99 } | 99 } |
| 100 | 100 |
| 101 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckTouc
hEvent( | 101 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckTouc
hEvent( |
| 102 WebPointerProperties::PointerType pointerType, | 102 WebPointerProperties::PointerType pointerType, |
| 103 int rawId, int uniqueId, bool isPrimary, | 103 int rawId, int uniqueId, bool isPrimary, |
| 104 PlatformTouchPoint::State state) | 104 PlatformTouchPoint::TouchState state) |
| 105 { | 105 { |
| 106 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create
( | 106 RefPtrWillBeRawPtr<PointerEvent> pointerEvent = m_pointerEventFactory.create
( |
| 107 EventTypeNames::pointerdown, PointerEventFactoryTest::PlatformTouchPoint
Builder(pointerType, rawId, state), PlatformEvent::NoModifiers, 0, 0, 0, 0); | 107 EventTypeNames::pointerdown, PointerEventFactoryTest::PlatformTouchPoint
Builder(pointerType, rawId, state), PlatformEvent::NoModifiers, 0, 0, 0, 0); |
| 108 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); | 108 EXPECT_EQ(uniqueId, pointerEvent->pointerId()); |
| 109 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); | 109 EXPECT_EQ(isPrimary, pointerEvent->isPrimary()); |
| 110 return pointerEvent; | 110 return pointerEvent; |
| 111 } | 111 } |
| 112 | 112 |
| 113 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckMous
eEvent( | 113 PassRefPtrWillBeRawPtr<PointerEvent> PointerEventFactoryTest::createAndCheckMous
eEvent( |
| 114 WebPointerProperties::PointerType pointerType, | 114 WebPointerProperties::PointerType pointerType, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 createAndCheckMouseEvent(WebPointerProperties::PointerType::Touch, i, m_
mappedIdStart+i, i == 0); | 317 createAndCheckMouseEvent(WebPointerProperties::PointerType::Touch, i, m_
mappedIdStart+i, i == 0); |
| 318 } | 318 } |
| 319 | 319 |
| 320 for (int i = 0; i < 100; ++i) { | 320 for (int i = 0; i < 100; ++i) { |
| 321 createAndCheckTouchEvent(WebPointerProperties::PointerType::Mouse, i, m_
expectedMouseId, true); | 321 createAndCheckTouchEvent(WebPointerProperties::PointerType::Mouse, i, m_
expectedMouseId, true); |
| 322 } | 322 } |
| 323 createAndCheckTouchCancel(WebPointerProperties::PointerType::Mouse, 0, m_exp
ectedMouseId, true); | 323 createAndCheckTouchCancel(WebPointerProperties::PointerType::Mouse, 0, m_exp
ectedMouseId, true); |
| 324 } | 324 } |
| 325 | 325 |
| 326 } // namespace blink | 326 } // namespace blink |
| OLD | NEW |