Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Unified Diff: third_party/WebKit/Source/web/tests/WebInputEventConversionTest.cpp

Issue 2646163002: Remove PlatformTouchEvent/Point and use WebTouchEvent/Point instead (Closed)
Patch Set: Fix nit Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/tests/WebInputEventConversionTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/WebInputEventConversionTest.cpp b/third_party/WebKit/Source/web/tests/WebInputEventConversionTest.cpp
index 54c6c7d18c4086d82308aac69e7372510d1879b0..4de6fd5a38f6f92e2c3e22aea24e4b6ebce72488 100644
--- a/third_party/WebKit/Source/web/tests/WebInputEventConversionTest.cpp
+++ b/third_party/WebKit/Source/web/tests/WebInputEventConversionTest.cpp
@@ -102,202 +102,6 @@ TEST(WebInputEventConversionTest, WebMouseEventBuilder) {
EXPECT_EQ(WebInputEvent::Undefined, mouse.type());
}
-TEST(WebInputEventConversionTest, WebTouchEventBuilder) {
- const std::string baseURL("http://www.test0.com/");
- const std::string fileName("fixed_layout.html");
-
- URLTestHelpers::registerMockedURLFromBaseURL(
- WebString::fromUTF8(baseURL.c_str()),
- WebString::fromUTF8("fixed_layout.html"));
- FrameTestHelpers::WebViewHelper webViewHelper;
- WebViewImpl* webViewImpl =
- webViewHelper.initializeAndLoad(baseURL + fileName, true);
- int pageWidth = 640;
- int pageHeight = 480;
- webViewImpl->resize(WebSize(pageWidth, pageHeight));
- webViewImpl->updateAllLifecyclePhases();
-
- Document* document =
- toLocalFrame(webViewImpl->page()->mainFrame())->document();
- LocalDOMWindow* domWindow = document->domWindow();
- LayoutViewItem documentLayoutView = document->layoutViewItem();
-
- WebTouchPoint p0, p1;
- p0.id = 1;
- p1.id = 2;
- p0.screenPosition = WebFloatPoint(100.f, 50.f);
- p1.screenPosition = WebFloatPoint(150.f, 25.f);
- p0.position = WebFloatPoint(10.f, 10.f);
- p1.position = WebFloatPoint(5.f, 5.f);
- p0.radiusX = p1.radiusY = 10.f;
- p0.radiusY = p1.radiusX = 5.f;
- p0.rotationAngle = p1.rotationAngle = 1.f;
- p0.force = p1.force = 25.f;
-
- Touch* touch0 = Touch::create(toLocalFrame(webViewImpl->page()->mainFrame()),
- document, p0.id, p0.screenPosition, p0.position,
- FloatSize(p0.radiusX, p0.radiusY),
- p0.rotationAngle, p0.force, String());
- Touch* touch1 = Touch::create(toLocalFrame(webViewImpl->page()->mainFrame()),
- document, p1.id, p1.screenPosition, p1.position,
- FloatSize(p1.radiusX, p1.radiusY),
- p1.rotationAngle, p1.force, String());
-
- // Test touchstart.
- {
- TouchList* touchList = TouchList::create();
- touchList->append(touch0);
- TouchEvent* touchEvent = TouchEvent::create(
- touchList, touchList, touchList, EventTypeNames::touchstart, domWindow,
- PlatformEvent::NoModifiers, false, false, true, TimeTicks(),
- TouchActionAuto, WebPointerProperties::PointerType::Touch);
-
- WebTouchEventBuilder webTouchBuilder(documentLayoutView, *touchEvent);
- ASSERT_EQ(1u, webTouchBuilder.touchesLength);
- EXPECT_EQ(WebInputEvent::TouchStart, webTouchBuilder.type());
- EXPECT_EQ(WebTouchPoint::StatePressed, webTouchBuilder.touches[0].state);
- EXPECT_FLOAT_EQ(p0.screenPosition.x,
- webTouchBuilder.touches[0].screenPosition.x);
- EXPECT_FLOAT_EQ(p0.screenPosition.y,
- webTouchBuilder.touches[0].screenPosition.y);
- EXPECT_FLOAT_EQ(p0.position.x, webTouchBuilder.touches[0].position.x);
- EXPECT_FLOAT_EQ(p0.position.y, webTouchBuilder.touches[0].position.y);
- EXPECT_FLOAT_EQ(p0.radiusX, webTouchBuilder.touches[0].radiusX);
- EXPECT_FLOAT_EQ(p0.radiusY, webTouchBuilder.touches[0].radiusY);
- EXPECT_FLOAT_EQ(p0.rotationAngle, webTouchBuilder.touches[0].rotationAngle);
- EXPECT_FLOAT_EQ(p0.force, webTouchBuilder.touches[0].force);
- EXPECT_EQ(WebPointerProperties::PointerType::Touch,
- webTouchBuilder.touches[0].pointerType);
- EXPECT_EQ(WebInputEvent::EventNonBlocking, webTouchBuilder.dispatchType);
- }
-
- // Test cancelable touchstart.
- {
- TouchList* touchList = TouchList::create();
- touchList->append(touch0);
- TouchEvent* touchEvent = TouchEvent::create(
- touchList, touchList, touchList, EventTypeNames::touchstart, domWindow,
- PlatformEvent::NoModifiers, true, false, true, TimeTicks(),
- TouchActionAuto, WebPointerProperties::PointerType::Touch);
-
- WebTouchEventBuilder webTouchBuilder(documentLayoutView, *touchEvent);
- EXPECT_EQ(WebInputEvent::Blocking, webTouchBuilder.dispatchType);
- }
-
- // Test touchmove.
- {
- TouchList* activeTouchList = TouchList::create();
- TouchList* movedTouchList = TouchList::create();
- activeTouchList->append(touch0);
- activeTouchList->append(touch1);
- movedTouchList->append(touch0);
- TouchEvent* touchEvent = TouchEvent::create(
- activeTouchList, activeTouchList, movedTouchList,
- EventTypeNames::touchmove, domWindow, PlatformEvent::NoModifiers, false,
- false, true, TimeTicks(), TouchActionAuto,
- WebPointerProperties::PointerType::Touch);
-
- WebTouchEventBuilder webTouchBuilder(documentLayoutView, *touchEvent);
- ASSERT_EQ(2u, webTouchBuilder.touchesLength);
- EXPECT_EQ(WebInputEvent::TouchMove, webTouchBuilder.type());
- EXPECT_EQ(WebTouchPoint::StateMoved, webTouchBuilder.touches[0].state);
- EXPECT_EQ(WebTouchPoint::StateStationary, webTouchBuilder.touches[1].state);
- EXPECT_EQ(p0.id, webTouchBuilder.touches[0].id);
- EXPECT_EQ(p1.id, webTouchBuilder.touches[1].id);
- EXPECT_EQ(WebInputEvent::EventNonBlocking, webTouchBuilder.dispatchType);
- }
-
- // Test touchmove, different point yields same ordering.
- {
- TouchList* activeTouchList = TouchList::create();
- TouchList* movedTouchList = TouchList::create();
- activeTouchList->append(touch0);
- activeTouchList->append(touch1);
- movedTouchList->append(touch1);
- TouchEvent* touchEvent = TouchEvent::create(
- activeTouchList, activeTouchList, movedTouchList,
- EventTypeNames::touchmove, domWindow, PlatformEvent::NoModifiers, false,
- false, true, TimeTicks(), TouchActionAuto,
- WebPointerProperties::PointerType::Touch);
-
- WebTouchEventBuilder webTouchBuilder(documentLayoutView, *touchEvent);
- ASSERT_EQ(2u, webTouchBuilder.touchesLength);
- EXPECT_EQ(WebInputEvent::TouchMove, webTouchBuilder.type());
- EXPECT_EQ(WebTouchPoint::StateStationary, webTouchBuilder.touches[0].state);
- EXPECT_EQ(WebTouchPoint::StateMoved, webTouchBuilder.touches[1].state);
- EXPECT_EQ(p0.id, webTouchBuilder.touches[0].id);
- EXPECT_EQ(p1.id, webTouchBuilder.touches[1].id);
- EXPECT_EQ(WebInputEvent::EventNonBlocking, webTouchBuilder.dispatchType);
- }
-
- // Test touchend.
- {
- TouchList* activeTouchList = TouchList::create();
- TouchList* releasedTouchList = TouchList::create();
- activeTouchList->append(touch0);
- releasedTouchList->append(touch1);
- TouchEvent* touchEvent = TouchEvent::create(
- activeTouchList, activeTouchList, releasedTouchList,
- EventTypeNames::touchend, domWindow, PlatformEvent::NoModifiers, false,
- false, false, TimeTicks(), TouchActionAuto,
- WebPointerProperties::PointerType::Touch);
-
- WebTouchEventBuilder webTouchBuilder(documentLayoutView, *touchEvent);
- ASSERT_EQ(2u, webTouchBuilder.touchesLength);
- EXPECT_EQ(WebInputEvent::TouchEnd, webTouchBuilder.type());
- EXPECT_EQ(WebTouchPoint::StateStationary, webTouchBuilder.touches[0].state);
- EXPECT_EQ(WebTouchPoint::StateReleased, webTouchBuilder.touches[1].state);
- EXPECT_EQ(p0.id, webTouchBuilder.touches[0].id);
- EXPECT_EQ(p1.id, webTouchBuilder.touches[1].id);
- EXPECT_EQ(WebInputEvent::EventNonBlocking, webTouchBuilder.dispatchType);
- }
-
- // Test touchcancel.
- {
- TouchList* activeTouchList = TouchList::create();
- TouchList* cancelledTouchList = TouchList::create();
- cancelledTouchList->append(touch0);
- cancelledTouchList->append(touch1);
- TouchEvent* touchEvent = TouchEvent::create(
- activeTouchList, activeTouchList, cancelledTouchList,
- EventTypeNames::touchcancel, domWindow, PlatformEvent::NoModifiers,
- false, false, false, TimeTicks(), TouchActionAuto,
- WebPointerProperties::PointerType::Touch);
-
- WebTouchEventBuilder webTouchBuilder(documentLayoutView, *touchEvent);
- ASSERT_EQ(2u, webTouchBuilder.touchesLength);
- EXPECT_EQ(WebInputEvent::TouchCancel, webTouchBuilder.type());
- EXPECT_EQ(WebTouchPoint::StateCancelled, webTouchBuilder.touches[0].state);
- EXPECT_EQ(WebTouchPoint::StateCancelled, webTouchBuilder.touches[1].state);
- EXPECT_EQ(p0.id, webTouchBuilder.touches[0].id);
- EXPECT_EQ(p1.id, webTouchBuilder.touches[1].id);
- EXPECT_EQ(WebInputEvent::EventNonBlocking, webTouchBuilder.dispatchType);
- }
-
- // Test max point limit.
- {
- TouchList* touchList = TouchList::create();
- TouchList* changedTouchList = TouchList::create();
- for (int i = 0; i <= static_cast<int>(WebTouchEvent::kTouchesLengthCap) * 2;
- ++i) {
- Touch* touch = Touch::create(
- toLocalFrame(webViewImpl->page()->mainFrame()), document, i,
- p0.screenPosition, p0.position, FloatSize(p0.radiusX, p0.radiusY),
- p0.rotationAngle, p0.force, String());
- touchList->append(touch);
- changedTouchList->append(touch);
- }
- TouchEvent* touchEvent = TouchEvent::create(
- touchList, touchList, touchList, EventTypeNames::touchstart, domWindow,
- PlatformEvent::NoModifiers, false, false, true, TimeTicks(),
- TouchActionAuto, WebPointerProperties::PointerType::Touch);
-
- WebTouchEventBuilder webTouchBuilder(documentLayoutView, *touchEvent);
- ASSERT_EQ(static_cast<unsigned>(WebTouchEvent::kTouchesLengthCap),
- webTouchBuilder.touchesLength);
- }
-}
-
TEST(WebInputEventConversionTest, InputEventsScaling) {
const std::string baseURL("http://www.test1.com/");
const std::string fileName("fixed_layout.html");
@@ -512,17 +316,15 @@ TEST(WebInputEventConversionTest, InputEventsScaling) {
EXPECT_FLOAT_EQ(10.6f, webTouchEvent.touches[0].radiusX);
EXPECT_FLOAT_EQ(10.4f, webTouchEvent.touches[0].radiusY);
- PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent);
- EXPECT_FLOAT_EQ(10.6f,
- platformTouchBuilder.touchPoints()[0].screenPos().x());
- EXPECT_FLOAT_EQ(10.4f,
- platformTouchBuilder.touchPoints()[0].screenPos().y());
- EXPECT_FLOAT_EQ(5.3f, platformTouchBuilder.touchPoints()[0].pos().x());
- EXPECT_FLOAT_EQ(5.2f, platformTouchBuilder.touchPoints()[0].pos().y());
- EXPECT_FLOAT_EQ(5.3f,
- platformTouchBuilder.touchPoints()[0].radius().width());
- EXPECT_FLOAT_EQ(5.2f,
- platformTouchBuilder.touchPoints()[0].radius().height());
+ WebTouchEvent transformedEvent =
+ TransformWebTouchEvent(view, webTouchEvent);
+ WebTouchPoint transformedPoint = transformedEvent.touchPointInRootFrame(0);
+ EXPECT_FLOAT_EQ(10.6f, transformedPoint.screenPosition.x);
+ EXPECT_FLOAT_EQ(10.4f, transformedPoint.screenPosition.y);
+ EXPECT_FLOAT_EQ(5.3f, transformedPoint.position.x);
+ EXPECT_FLOAT_EQ(5.2f, transformedPoint.position.y);
+ EXPECT_FLOAT_EQ(5.3f, transformedPoint.radiusX);
+ EXPECT_FLOAT_EQ(5.2f, transformedPoint.radiusY);
}
// Reverse builders should *not* go back to physical pixels, as they are used
@@ -555,29 +357,6 @@ TEST(WebInputEventConversionTest, InputEventsScaling) {
WebMouseEventBuilder webMouseBuilder(view, documentLayoutView, *mouseEvent);
EXPECT_EQ(WebMouseEvent::Button::NoButton, webMouseBuilder.button);
}
-
- {
- Touch* touch =
- Touch::create(toLocalFrame(webViewImpl->page()->mainFrame()), document,
- 0, FloatPoint(10, 9.5), FloatPoint(3.5, 2),
- FloatSize(4, 4.5), 0, 0, String());
- TouchList* touchList = TouchList::create();
- touchList->append(touch);
- TouchEvent* touchEvent = TouchEvent::create(
- touchList, touchList, touchList, EventTypeNames::touchmove, domWindow,
- PlatformEvent::NoModifiers, false, false, true, TimeTicks(),
- TouchActionAuto, WebPointerProperties::PointerType::Touch);
-
- WebTouchEventBuilder webTouchBuilder(documentLayoutView, *touchEvent);
- ASSERT_EQ(1u, webTouchBuilder.touchesLength);
- EXPECT_EQ(10, webTouchBuilder.touches[0].screenPosition.x);
- EXPECT_FLOAT_EQ(9.5, webTouchBuilder.touches[0].screenPosition.y);
- EXPECT_FLOAT_EQ(3.5, webTouchBuilder.touches[0].position.x);
- EXPECT_FLOAT_EQ(2, webTouchBuilder.touches[0].position.y);
- EXPECT_FLOAT_EQ(4, webTouchBuilder.touches[0].radiusX);
- EXPECT_FLOAT_EQ(4.5, webTouchBuilder.touches[0].radiusY);
- EXPECT_EQ(WebInputEvent::EventNonBlocking, webTouchBuilder.dispatchType);
- }
}
TEST(WebInputEventConversionTest, InputEventsTransform) {
@@ -793,14 +572,16 @@ TEST(WebInputEventConversionTest, InputEventsTransform) {
webTouchEvent.touches[0].radiusX = 30;
webTouchEvent.touches[0].radiusY = 30;
- PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent);
- EXPECT_FLOAT_EQ(100, platformTouchBuilder.touchPoints()[0].screenPos().x());
- EXPECT_FLOAT_EQ(110, platformTouchBuilder.touchPoints()[0].screenPos().y());
- EXPECT_FLOAT_EQ(30, platformTouchBuilder.touchPoints()[0].pos().x());
- EXPECT_FLOAT_EQ(30, platformTouchBuilder.touchPoints()[0].pos().y());
- EXPECT_FLOAT_EQ(10, platformTouchBuilder.touchPoints()[0].radius().width());
- EXPECT_FLOAT_EQ(10,
- platformTouchBuilder.touchPoints()[0].radius().height());
+ WebTouchEvent transformedEvent =
+ TransformWebTouchEvent(view, webTouchEvent);
+
+ WebTouchPoint transformedPoint = transformedEvent.touchPointInRootFrame(0);
+ EXPECT_FLOAT_EQ(100, transformedPoint.screenPosition.x);
+ EXPECT_FLOAT_EQ(110, transformedPoint.screenPosition.y);
+ EXPECT_FLOAT_EQ(30, transformedPoint.position.x);
+ EXPECT_FLOAT_EQ(30, transformedPoint.position.y);
+ EXPECT_FLOAT_EQ(10, transformedPoint.radiusX);
+ EXPECT_FLOAT_EQ(10, transformedPoint.radiusY);
}
{
@@ -825,23 +606,26 @@ TEST(WebInputEventConversionTest, InputEventsTransform) {
events.push_back(&webTouchEvent1);
events.push_back(&webTouchEvent2);
- Vector<PlatformTouchEvent> coalescedevents =
- createPlatformTouchEventVector(view, events);
+ Vector<WebTouchEvent> coalescedevents =
+ TransformWebTouchEventVector(view, events);
EXPECT_EQ(events.size(), coalescedevents.size());
- EXPECT_FLOAT_EQ(100, coalescedevents[0].touchPoints()[0].screenPos().x());
- EXPECT_FLOAT_EQ(110, coalescedevents[0].touchPoints()[0].screenPos().y());
- EXPECT_FLOAT_EQ(30, coalescedevents[0].touchPoints()[0].pos().x());
- EXPECT_FLOAT_EQ(30, coalescedevents[0].touchPoints()[0].pos().y());
- EXPECT_FLOAT_EQ(10, coalescedevents[0].touchPoints()[0].radius().width());
- EXPECT_FLOAT_EQ(10, coalescedevents[0].touchPoints()[0].radius().height());
-
- EXPECT_FLOAT_EQ(130, coalescedevents[1].touchPoints()[0].screenPos().x());
- EXPECT_FLOAT_EQ(110, coalescedevents[1].touchPoints()[0].screenPos().y());
- EXPECT_FLOAT_EQ(40, coalescedevents[1].touchPoints()[0].pos().x());
- EXPECT_FLOAT_EQ(30, coalescedevents[1].touchPoints()[0].pos().y());
- EXPECT_FLOAT_EQ(20, coalescedevents[1].touchPoints()[0].radius().width());
- EXPECT_FLOAT_EQ(10, coalescedevents[1].touchPoints()[0].radius().height());
+ WebTouchPoint transformedPoint =
+ coalescedevents[0].touchPointInRootFrame(0);
+ EXPECT_FLOAT_EQ(100, transformedPoint.screenPosition.x);
+ EXPECT_FLOAT_EQ(110, transformedPoint.screenPosition.y);
+ EXPECT_FLOAT_EQ(30, transformedPoint.position.x);
+ EXPECT_FLOAT_EQ(30, transformedPoint.position.y);
+ EXPECT_FLOAT_EQ(10, transformedPoint.radiusX);
+ EXPECT_FLOAT_EQ(10, transformedPoint.radiusY);
+
+ transformedPoint = coalescedevents[1].touchPointInRootFrame(0);
+ EXPECT_FLOAT_EQ(130, transformedPoint.screenPosition.x);
+ EXPECT_FLOAT_EQ(110, transformedPoint.screenPosition.y);
+ EXPECT_FLOAT_EQ(40, transformedPoint.position.x);
+ EXPECT_FLOAT_EQ(30, transformedPoint.position.y);
+ EXPECT_FLOAT_EQ(20, transformedPoint.radiusX);
+ EXPECT_FLOAT_EQ(10, transformedPoint.radiusY);
}
}
@@ -983,15 +767,14 @@ TEST(WebInputEventConversionTest, VisualViewportOffset) {
EXPECT_FLOAT_EQ(10.6f, webTouchEvent.touches[0].position.x);
EXPECT_FLOAT_EQ(10.4f, webTouchEvent.touches[0].position.y);
- PlatformTouchEventBuilder platformTouchBuilder(view, webTouchEvent);
- EXPECT_FLOAT_EQ(10.6f,
- platformTouchBuilder.touchPoints()[0].screenPos().x());
- EXPECT_FLOAT_EQ(10.4f,
- platformTouchBuilder.touchPoints()[0].screenPos().y());
- EXPECT_FLOAT_EQ(5.3f + visualOffset.x(),
- platformTouchBuilder.touchPoints()[0].pos().x());
- EXPECT_FLOAT_EQ(5.2f + visualOffset.y(),
- platformTouchBuilder.touchPoints()[0].pos().y());
+ WebTouchEvent transformedTouchEvent =
+ TransformWebTouchEvent(view, webTouchEvent);
+ WebTouchPoint transformedPoint =
+ transformedTouchEvent.touchPointInRootFrame(0);
+ EXPECT_FLOAT_EQ(10.6f, transformedPoint.screenPosition.x);
+ EXPECT_FLOAT_EQ(10.4f, transformedPoint.screenPosition.y);
+ EXPECT_FLOAT_EQ(5.3f + visualOffset.x(), transformedPoint.position.x);
+ EXPECT_FLOAT_EQ(5.2f + visualOffset.y(), transformedPoint.position.y);
}
}
« no previous file with comments | « third_party/WebKit/Source/web/WebPluginContainerImpl.cpp ('k') | third_party/WebKit/public/platform/WebTouchEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698