All PointerEvent.isTrusted is always false.
authorgraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Mar 2019 15:54:02 +0000 (15:54 +0000)
committergraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 29 Mar 2019 15:54:02 +0000 (15:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196075
<rdar://problem/49158778>

Reviewed by Chris Dumez.

Source/WebCore:

Test: pointerevents/ios/pointer-events-is-trusted.html

The constructors we were using for some PointerEvent::create() methods were using initializers which are expected to be used with JS APIs
and thus generate untrusted events. We switch to using constructors using dedicated parameters which will set isTrusted to true.

* dom/PointerEvent.cpp:
(WebCore::PointerEvent::create):
(WebCore::PointerEvent::createPointerCancelEvent):
(WebCore::PointerEvent::PointerEvent):
(WebCore::m_isPrimary):
(WebCore::m_pointerType):
* dom/PointerEvent.h:
* page/PointerCaptureController.cpp:
(WebCore::PointerCaptureController::cancelPointer):

LayoutTests:

Add tests to the macOS and iOS series of tests that check that isTrusted is indeed true. This uncovered a couple of issues with how some tests were written.

* pointerevents/ios/pointer-events-is-primary.html: Ensure we end both touches so that further tests run cleanly.
* pointerevents/ios/pointer-events-is-trusted-expected.txt: Added.
* pointerevents/ios/pointer-events-is-trusted.html: Added.
* pointerevents/mouse/pointer-event-basic-properties.html: Ensure we wait for the event to be handled before finishing the test.
* pointerevents/utils.js:
(prototype._handlePointerEvent):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243645 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/pointerevents/ios/pointer-events-is-primary.html
LayoutTests/pointerevents/ios/pointer-events-is-trusted-expected.txt [new file with mode: 0644]
LayoutTests/pointerevents/ios/pointer-events-is-trusted.html [new file with mode: 0644]
LayoutTests/pointerevents/mouse/pointer-event-basic-properties.html
LayoutTests/pointerevents/utils.js
Source/WebCore/ChangeLog
Source/WebCore/dom/PointerEvent.cpp
Source/WebCore/dom/PointerEvent.h
Source/WebCore/page/PointerCaptureController.cpp

index a390402..62b6fdc 100644 (file)
@@ -1,3 +1,20 @@
+2019-03-28  Antoine Quint  <graouts@apple.com>
+
+        All PointerEvent.isTrusted is always false.
+        https://bugs.webkit.org/show_bug.cgi?id=196075
+        <rdar://problem/49158778>
+
+        Reviewed by Chris Dumez.
+
+        Add tests to the macOS and iOS series of tests that check that isTrusted is indeed true. This uncovered a couple of issues with how some tests were written.
+
+        * pointerevents/ios/pointer-events-is-primary.html: Ensure we end both touches so that further tests run cleanly.
+        * pointerevents/ios/pointer-events-is-trusted-expected.txt: Added.
+        * pointerevents/ios/pointer-events-is-trusted.html: Added.
+        * pointerevents/mouse/pointer-event-basic-properties.html: Ensure we wait for the event to be handled before finishing the test.
+        * pointerevents/utils.js:
+        (prototype._handlePointerEvent):
+
 2019-03-29  Cathie Chen  <cathiechen@igalia.com>
 
         Implement ResizeObserver.
index 9dc5c79..3738e3a 100644 (file)
@@ -24,7 +24,8 @@ target_test((target, test) => {
         two.move({ x: 70, y: 70 }),
         one.move({ x: 30, y: 30 }),
         one.end(),
-        two.move({ x: 50, y: 50 })
+        two.move({ x: 50, y: 50 }),
+        two.end()
     ]).then(() => {
         eventTracker.assertMatchesEvents([
             { id: 1, type: "pointerdown", x: 10, y: 10, isPrimary: true },
diff --git a/LayoutTests/pointerevents/ios/pointer-events-is-trusted-expected.txt b/LayoutTests/pointerevents/ios/pointer-events-is-trusted-expected.txt
new file mode 100644 (file)
index 0000000..37dace5
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Testing that isTrusted is true for pointer events. 
+
diff --git a/LayoutTests/pointerevents/ios/pointer-events-is-trusted.html b/LayoutTests/pointerevents/ios/pointer-events-is-trusted.html
new file mode 100644 (file)
index 0000000..6514565
--- /dev/null
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset=utf-8>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+</head>
+<body>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../utils.js"></script>
+<script>
+
+'use strict';
+
+target_test({ width: "200px", height: "200px" }, (target, test) => {
+    const eventTracker = new EventTracker(target, ["pointerover", "pointerenter", "pointerdown", "pointerup", "pointerout", "pointerleave"]);
+
+    ui.tap({ x: 100, y: 100 }).then(() => {
+        eventTracker.assertMatchesEvents([
+            { type: "pointerover", isTrusted: true },
+            { type: "pointerenter", isTrusted: true },
+            { type: "pointerdown", isTrusted: true },
+            { type: "pointerup", isTrusted: true },
+            { type: "pointerout", isTrusted: true },
+            { type: "pointerleave", isTrusted: true },
+        ]);
+        test.done();
+    });
+}, `Testing that isTrusted is true for pointer events.`);
+
+</script>
+</body>
+</html>
\ No newline at end of file
index ff5500a..3a78108 100644 (file)
 'use strict';
 
 target_test((target, test) => {
-    eventSender.mouseMoveTo(50, 50);
-    eventSender.mouseDown();
-
     target.addEventListener("pointerdown", event => {
         assert_equals(event.pointerId, 1, "The pointer's identifier is 1.");
         assert_equals(event.pointerType, "mouse", "The pointer type is 'mouse'.");
         assert_true(event.isPrimary, "The pointer is the primary pointer.");
+        assert_true(event.isTrusted, "The event is trusted.");
+        test.done();
     });
 
-    test.done();
+    eventSender.mouseMoveTo(50, 50);
+    eventSender.mouseDown();
 }, `Testing the basic properties of a pointer event triggered by a mouse.`);
 
 </script>
index 9ae506f..9e31f8b 100644 (file)
@@ -67,7 +67,8 @@ class EventTracker
             type: event.type,
             x: event.clientX,
             y: event.clientY,
-            isPrimary: event.isPrimary
+            isPrimary: event.isPrimary,
+            isTrusted: event.isTrusted
         });
     }
 
index 08982fd..92fd964 100644 (file)
@@ -1,3 +1,26 @@
+2019-03-28  Antoine Quint  <graouts@apple.com>
+
+        All PointerEvent.isTrusted is always false.
+        https://bugs.webkit.org/show_bug.cgi?id=196075
+        <rdar://problem/49158778>
+
+        Reviewed by Chris Dumez.
+
+        Test: pointerevents/ios/pointer-events-is-trusted.html
+
+        The constructors we were using for some PointerEvent::create() methods were using initializers which are expected to be used with JS APIs
+        and thus generate untrusted events. We switch to using constructors using dedicated parameters which will set isTrusted to true.
+
+        * dom/PointerEvent.cpp:
+        (WebCore::PointerEvent::create):
+        (WebCore::PointerEvent::createPointerCancelEvent):
+        (WebCore::PointerEvent::PointerEvent):
+        (WebCore::m_isPrimary):
+        (WebCore::m_pointerType):
+        * dom/PointerEvent.h:
+        * page/PointerCaptureController.cpp:
+        (WebCore::PointerCaptureController::cancelPointer):
+
 2019-03-29  Philippe Normand  <pnormand@igalia.com>
 
         [GStreamer] imxvpudecoder detection and handling
index e02afe1..a5b7d1c 100644 (file)
@@ -71,6 +71,24 @@ static AtomicString pointerEventType(const AtomicString& mouseEventType)
     return nullAtom();
 }
 
+RefPtr<PointerEvent> PointerEvent::create(const MouseEvent& mouseEvent)
+{
+    auto type = pointerEventType(mouseEvent.type());
+    if (type.isEmpty())
+        return nullptr;
+
+    auto isEnterOrLeave = type == eventNames().pointerenterEvent || type == eventNames().pointerleaveEvent;
+    auto canBubble = isEnterOrLeave ? CanBubble::No : CanBubble::Yes;
+    auto isCancelable = isEnterOrLeave ? IsCancelable::No : IsCancelable::Yes;
+    auto isComposed = isEnterOrLeave ? IsComposed::No : IsComposed::Yes;
+    return adoptRef(*new PointerEvent(type, canBubble, isCancelable, isComposed, mouseEvent));
+}
+
+Ref<PointerEvent> PointerEvent::createPointerCancelEvent(PointerID pointerId, const String& pointerType)
+{
+    return adoptRef(*new PointerEvent(eventNames().pointercancelEvent, CanBubble::Yes, IsCancelable::No, IsComposed::Yes, pointerId, pointerType));
+}
+
 PointerEvent::PointerEvent() = default;
 
 PointerEvent::PointerEvent(const AtomicString& type, Init&& initializer)
@@ -88,35 +106,17 @@ PointerEvent::PointerEvent(const AtomicString& type, Init&& initializer)
 {
 }
 
-RefPtr<PointerEvent> PointerEvent::create(const MouseEvent& mouseEvent)
+PointerEvent::PointerEvent(const AtomicString& type, CanBubble canBubble, IsCancelable isCancelable, IsComposed isComposed, const MouseEvent& mouseEvent)
+    : MouseEvent(type, canBubble, isCancelable, isComposed, mouseEvent.view(), mouseEvent.detail(), mouseEvent.screenLocation(), { mouseEvent.clientX(), mouseEvent.clientY() }, mouseEvent.modifierKeys(), mouseEvent.button(), mouseEvent.buttons(), mouseEvent.syntheticClickType(), mouseEvent.relatedTarget())
+    , m_isPrimary(true)
 {
-    auto type = pointerEventType(mouseEvent.type());
-    if (type.isEmpty())
-        return nullptr;
-
-    auto isEnterOrLeave = type == eventNames().pointerenterEvent || type == eventNames().pointerleaveEvent;
+}
 
-    PointerEvent::Init init;
-    init.bubbles = !isEnterOrLeave;
-    init.cancelable = !isEnterOrLeave;
-    init.composed = !isEnterOrLeave;
-    init.view = mouseEvent.view();
-    init.ctrlKey = mouseEvent.ctrlKey();
-    init.shiftKey = mouseEvent.shiftKey();
-    init.altKey = mouseEvent.altKey();
-    init.metaKey = mouseEvent.metaKey();
-    init.modifierAltGraph = mouseEvent.altGraphKey();
-    init.modifierCapsLock = mouseEvent.capsLockKey();
-    init.screenX = mouseEvent.screenX();
-    init.screenY = mouseEvent.screenY();
-    init.clientX = mouseEvent.clientX();
-    init.clientY = mouseEvent.clientY();
-    init.button = mouseEvent.button();
-    init.buttons = mouseEvent.buttons();
-    init.relatedTarget = mouseEvent.relatedTarget();
-    init.isPrimary = true;
-
-    return PointerEvent::create(type, WTFMove(init));
+PointerEvent::PointerEvent(const AtomicString& type, CanBubble canBubble, IsCancelable isCancelable, IsComposed isComposed, PointerID pointerId, const String& pointerType)
+    : MouseEvent(type, canBubble, isCancelable, isComposed, nullptr, 0, { }, { }, { }, 0, 0, 0, nullptr)
+    , m_pointerId(pointerId)
+    , m_pointerType(pointerType)
+{
 }
 
 PointerEvent::~PointerEvent() = default;
index 2695508..578976d 100644 (file)
@@ -57,15 +57,6 @@ public:
         return adoptRef(*new PointerEvent(type, WTFMove(initializer)));
     }
 
-    static Ref<PointerEvent> create(const AtomicString& type, PointerID pointerId, String pointerType)
-    {
-        Init initializer;
-        initializer.bubbles = true;
-        initializer.pointerId = pointerId;
-        initializer.pointerType = pointerType;
-        return adoptRef(*new PointerEvent(type, WTFMove(initializer)));
-    }
-
     static Ref<PointerEvent> createForPointerCapture(const AtomicString& type, const PointerEvent& pointerEvent)
     {
         Init initializer;
@@ -82,6 +73,7 @@ public:
     }
 
     static RefPtr<PointerEvent> create(const MouseEvent&);
+    static Ref<PointerEvent> createPointerCancelEvent(PointerID, const String& pointerType);
 
 #if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
     static Ref<PointerEvent> create(const PlatformTouchEvent&, unsigned touchIndex, bool isPrimary, Ref<WindowProxy>&&);
@@ -113,6 +105,8 @@ public:
 private:
     PointerEvent();
     PointerEvent(const AtomicString&, Init&&);
+    PointerEvent(const AtomicString& type, CanBubble, IsCancelable, IsComposed, const MouseEvent&);
+    PointerEvent(const AtomicString& type, CanBubble, IsCancelable, IsComposed, PointerID, const String& pointerType);
 #if ENABLE(TOUCH_EVENTS) && PLATFORM(IOS_FAMILY)
     PointerEvent(const AtomicString& type, const PlatformTouchEvent&, IsCancelable isCancelable, unsigned touchIndex, bool isPrimary, Ref<WindowProxy>&&);
 #endif
index 93c09f9..7594175 100644 (file)
@@ -281,7 +281,7 @@ void PointerCaptureController::cancelPointer(PointerID pointerId, const IntPoint
     if (!target)
         return;
 
-    auto event = PointerEvent::create(eventNames().pointercancelEvent, pointerId, capturingData.pointerType);
+    auto event = PointerEvent::createPointerCancelEvent(pointerId, capturingData.pointerType);
     target->dispatchEvent(event);
     processPendingPointerCapture(WTFMove(event));
 }