Title: [196520] trunk
Revision
196520
Author
jiewen_...@apple.com
Date
2016-02-12 15:25:02 -0800 (Fri, 12 Feb 2016)

Log Message

WebKit should expose the DOM 4 Event.isTrusted property
https://bugs.webkit.org/show_bug.cgi?id=76121
<rdar://problem/22558494>

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/dom/events/Event-constructors-expected.txt:
* web-platform-tests/dom/events/Event-dispatch-redispatch-expected.txt:
* web-platform-tests/dom/events/Event-initEvent-expected.txt:
* web-platform-tests/dom/events/ProgressEvent-expected.txt:
* web-platform-tests/dom/interfaces-expected.txt:
* web-platform-tests/dom/nodes/Document-createEvent-expected.txt:
* web-platform-tests/html/dom/interfaces-expected.txt:
* web-platform-tests/html/semantics/forms/the-button-element/button-events-expected.txt:

Source/WebCore:

Implements Event.isTrusted. The implementation here is slitely different from and better than
the DOM specification. Here Event.isTrusted will be initialized differently depending on the
callers of the constructors/create methods. If the caller is from user agent, the isTrusted
will be true. Otherwise, it will be false. Since a user agent dispatched event can be catched
and re-initialized/redispatched by the bindings, the flag will be unset at *Event::init*Event
and EventTarget::dispatchEventForBindings. As currently there is no way to let user agent to
dispatch a bindings created event, therefore we ensure that the Event.isTrusted is set for
events dispatched by user agent, and unset for those by bindings.

EventTarget::dispatchEvent(Event*, ExceptionCode&) is renamed to EventTarget::dispatchEventForBindings
in this patch as well. So that, together with the improved design of the API, developers in
the future will be less likely using a wrong dispatchEvent method and setting Event.isTrusted
incorrectly comparing to the DOM design.

After this patch, all events that are created by user agent should be dispatched by
EventTarget::dispatchEvent, and those are created by bindings should be dispatched by
EventTarget::dispatchEventForBindings.

Some of the changes in this patch referred Blink r198996:
https://codereview.chromium.org/1241613004

Test: imported/blink/fast/events/event-trusted.html

* bindings/scripts/CodeGeneratorGObject.pm:
(GenerateEventTargetIface):
* dom/Event.cpp:
(WebCore::Event::Event):
(WebCore::Event::initEvent):
* dom/Event.h:
(WebCore::Event::isTrusted):
(WebCore::Event::setUntrusted):
* dom/Event.idl:
* dom/EventTarget.cpp:
(WebCore::EventTarget::dispatchEventForBindings):
(WebCore::EventTarget::dispatchEvent): Deleted.
* dom/EventTarget.h:
* dom/EventTarget.idl:
* page/DOMWindow.idl:
* page/EventHandler.cpp:
(WebCore::EventHandler::dispatchDragEvent):
* workers/WorkerGlobalScope.idl:

Source/WebKit/win:

* DOMCoreClasses.cpp:
(DOMNode::dispatchEvent):
(DOMWindow::dispatchEvent):

LayoutTests:

* fast/dom/unforgeable-attributes-expected.txt:
* fast/xmlhttprequest/xmlhttprequest-get-expected.txt:
* http/tests/workers/worker-importScriptsOnError-expected.txt:
* imported/blink/fast/events/event-trusted-expected.txt: Added.
* imported/blink/fast/events/event-trusted.html: Added.
* platform/ios-simulator/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (196519 => 196520)


--- trunk/LayoutTests/ChangeLog	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/ChangeLog	2016-02-12 23:25:02 UTC (rev 196520)
@@ -1,3 +1,18 @@
+2016-02-12  Jiewen Tan  <jiewen_...@apple.com>
+
+        WebKit should expose the DOM 4 Event.isTrusted property
+        https://bugs.webkit.org/show_bug.cgi?id=76121
+        <rdar://problem/22558494>
+
+        Reviewed by Darin Adler.
+
+        * fast/dom/unforgeable-attributes-expected.txt:
+        * fast/xmlhttprequest/xmlhttprequest-get-expected.txt:
+        * http/tests/workers/worker-importScriptsOnError-expected.txt:
+        * imported/blink/fast/events/event-trusted-expected.txt: Added.
+        * imported/blink/fast/events/event-trusted.html: Added.
+        * platform/ios-simulator/TestExpectations:
+
 2016-02-12  Brady Eidson  <beid...@apple.com>
 
         Modern IDB: Simplify the relationship between IDBObjectStore and IDBIndex.

Modified: trunk/LayoutTests/fast/dom/unforgeable-attributes-expected.txt (196519 => 196520)


--- trunk/LayoutTests/fast/dom/unforgeable-attributes-expected.txt	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/fast/dom/unforgeable-attributes-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -4,7 +4,10 @@
 
 
 Event.isTrusted
-FAIL Unsupported property.
+PASS testObject.hasOwnProperty(testPropertyName) is true
+PASS testObject.__proto__.hasOwnProperty(testPropertyName) is false
+PASS Object.defineProperty(testObject, testPropertyName, { value: 'test' }) threw exception TypeError: Attempting to change access mechanism for an unconfigurable property..
+PASS Object.getOwnPropertyDescriptor(testObject, testPropertyName).configurable is false
 
 Document.location
 PASS testObject.hasOwnProperty(testPropertyName) is true

Modified: trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-get-expected.txt (196519 => 196520)


--- trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-get-expected.txt	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/fast/xmlhttprequest/xmlhttprequest-get-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -53,6 +53,7 @@
 initEvent : 'function initEvent() {
     [native code]
 }'
+isTrusted : 'true'
 lengthComputable : 'true'
 loaded : '174'
 position : '174'

Modified: trunk/LayoutTests/http/tests/workers/worker-importScriptsOnError-expected.txt (196519 => 196520)


--- trunk/LayoutTests/http/tests/workers/worker-importScriptsOnError-expected.txt	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/http/tests/workers/worker-importScriptsOnError-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -32,6 +32,7 @@
 eventPhase: 2,
 filename: http://127.0.0.1:8000/workers/resources/worker-importScripts-error.js,
 initEvent: function initEvent() { [native code] },
+isTrusted: true,
 lineno: 2,
 message: Error: Script error.,
 preventDefault: function preventDefault() { [native code] },

Added: trunk/LayoutTests/imported/blink/fast/events/event-trusted-expected.txt (0 => 196520)


--- trunk/LayoutTests/imported/blink/fast/events/event-trusted-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/events/event-trusted-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -0,0 +1,14 @@
+This tests that isTrusted returns the correct value under certain situations.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.createEvent('Event').isTrusted is false
+PASS createAndInitEvent().isTrusted is false
+PASS originalEvent.isTrusted is true
+PASS redispatched is true
+PASS originalEvent.isTrusted is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/imported/blink/fast/events/event-trusted.html (0 => 196520)


--- trunk/LayoutTests/imported/blink/fast/events/event-trusted.html	                        (rev 0)
+++ trunk/LayoutTests/imported/blink/fast/events/event-trusted.html	2016-02-12 23:25:02 UTC (rev 196520)
@@ -0,0 +1,41 @@
+<input id="test-checkbox" type="checkbox"/>
+<script src=""
+<script>
+description("This tests that isTrusted returns the correct value under certain situations.")
+
+var redispatched = false;
+
+function createAndInitEvent() {
+    var e = document.createEvent('Event');
+    e.initEvent(false, false, false);
+    return e;
+}
+
+shouldBeFalse("document.createEvent('Event').isTrusted");
+shouldBeFalse("createAndInitEvent().isTrusted");
+
+function originalDispatch(e) {
+    originalEvent = e;
+}
+
+function redispatch(e) {
+    redispatched = true;
+}
+
+var element = document.getElementById("test-checkbox");
+if (window.eventSender) {
+    element.addEventListener('click', originalDispatch);
+    eventSender.mouseMoveTo(element.offsetLeft, element.offsetTop);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+
+    shouldBeTrue("originalEvent.isTrusted");
+    element.removeEventListener('click', originalDispatch);
+    element.addEventListener('click', redispatch);
+
+    element.dispatchEvent(originalEvent);
+    shouldBeTrue("redispatched");
+    shouldBeFalse("originalEvent.isTrusted");
+}
+
+</script>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (196519 => 196520)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-02-12 23:25:02 UTC (rev 196520)
@@ -1,3 +1,20 @@
+2016-02-12  Jiewen Tan  <jiewen_...@apple.com>
+
+        WebKit should expose the DOM 4 Event.isTrusted property
+        https://bugs.webkit.org/show_bug.cgi?id=76121
+        <rdar://problem/22558494>
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/dom/events/Event-constructors-expected.txt:
+        * web-platform-tests/dom/events/Event-dispatch-redispatch-expected.txt:
+        * web-platform-tests/dom/events/Event-initEvent-expected.txt:
+        * web-platform-tests/dom/events/ProgressEvent-expected.txt:
+        * web-platform-tests/dom/interfaces-expected.txt:
+        * web-platform-tests/dom/nodes/Document-createEvent-expected.txt:
+        * web-platform-tests/html/dom/interfaces-expected.txt:
+        * web-platform-tests/html/semantics/forms/the-button-element/button-events-expected.txt:
+
 2016-02-11  Chris Dumez  <cdu...@apple.com>
 
         [Web IDL] interfaces should inherit EventTarget instead of duplicating the EventTarget API

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-constructors-expected.txt (196519 => 196520)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-constructors-expected.txt	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-constructors-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -1,8 +1,8 @@
 
 PASS Event constructors 
 PASS Event constructors 1 
-FAIL Event constructors 2 assert_equals: expected (boolean) false but got (undefined) undefined
-FAIL Event constructors 3 assert_equals: expected (boolean) false but got (undefined) undefined
+PASS Event constructors 2 
+PASS Event constructors 3 
 FAIL Event constructors 4 Constructor requires 'new' operator
 PASS Event constructors 5 
 PASS Event constructors 6 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-redispatch-expected.txt (196519 => 196520)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-redispatch-expected.txt	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-redispatch-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -1,3 +1,3 @@
 
-FAIL EventTarget#dispatchEvent(): redispatching a native event assert_true: Should be trusted when first handled expected true got undefined
+PASS EventTarget#dispatchEvent(): redispatching a native event 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-initEvent-expected.txt (196519 => 196520)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-initEvent-expected.txt	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-initEvent-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -1,8 +1,8 @@
 
-FAIL Properties of initEvent(type, true, true) assert_equals: isTrusted expected (boolean) false but got (undefined) undefined
-FAIL Properties of initEvent(type, true, false) assert_equals: isTrusted expected (boolean) false but got (undefined) undefined
-FAIL Properties of initEvent(type, false, true) assert_equals: isTrusted expected (boolean) false but got (undefined) undefined
-FAIL Properties of initEvent(type, false, false) assert_equals: isTrusted expected (boolean) false but got (undefined) undefined
+PASS Properties of initEvent(type, true, true) 
+PASS Properties of initEvent(type, true, false) 
+PASS Properties of initEvent(type, false, true) 
+PASS Properties of initEvent(type, false, false) 
 PASS Calling initEvent multiple times (getting type). 
 PASS Calling initEvent multiple times (not getting type). 
 PASS Calling initEvent must not have an effect during dispatching. 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/ProgressEvent-expected.txt (196519 => 196520)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/ProgressEvent-expected.txt	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/ProgressEvent-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -1,4 +1,4 @@
 
-FAIL Default event values. assert_equals: expected (boolean) false but got (undefined) undefined
+PASS Default event values. 
 PASS document.createEvent() should not work with ProgressEvent. 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt (196519 => 196520)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -43,7 +43,7 @@
 PASS Event interface: document.createEvent("Event") must inherit property "cancelable" with the proper type (11) 
 PASS Event interface: document.createEvent("Event") must inherit property "preventDefault" with the proper type (12) 
 PASS Event interface: document.createEvent("Event") must inherit property "defaultPrevented" with the proper type (13) 
-FAIL Event interface: document.createEvent("Event") must have own property "isTrusted" assert_own_property: expected property "isTrusted" missing
+PASS Event interface: document.createEvent("Event") must have own property "isTrusted" 
 PASS Event interface: document.createEvent("Event") must inherit property "timeStamp" with the proper type (15) 
 PASS Event interface: document.createEvent("Event") must inherit property "initEvent" with the proper type (16) 
 FAIL Event interface: calling initEvent(DOMString,boolean,boolean) on document.createEvent("Event") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
@@ -65,7 +65,7 @@
 PASS Event interface: new Event("foo") must inherit property "cancelable" with the proper type (11) 
 PASS Event interface: new Event("foo") must inherit property "preventDefault" with the proper type (12) 
 PASS Event interface: new Event("foo") must inherit property "defaultPrevented" with the proper type (13) 
-FAIL Event interface: new Event("foo") must have own property "isTrusted" assert_own_property: expected property "isTrusted" missing
+PASS Event interface: new Event("foo") must have own property "isTrusted" 
 PASS Event interface: new Event("foo") must inherit property "timeStamp" with the proper type (15) 
 PASS Event interface: new Event("foo") must inherit property "initEvent" with the proper type (16) 
 FAIL Event interface: calling initEvent(DOMString,boolean,boolean) on new Event("foo") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
@@ -99,7 +99,7 @@
 PASS Event interface: new CustomEvent("foo") must inherit property "cancelable" with the proper type (11) 
 PASS Event interface: new CustomEvent("foo") must inherit property "preventDefault" with the proper type (12) 
 PASS Event interface: new CustomEvent("foo") must inherit property "defaultPrevented" with the proper type (13) 
-FAIL Event interface: new CustomEvent("foo") must have own property "isTrusted" assert_own_property: expected property "isTrusted" missing
+PASS Event interface: new CustomEvent("foo") must have own property "isTrusted" 
 PASS Event interface: new CustomEvent("foo") must inherit property "timeStamp" with the proper type (15) 
 PASS Event interface: new CustomEvent("foo") must inherit property "initEvent" with the proper type (16) 
 FAIL Event interface: calling initEvent(DOMString,boolean,boolean) on new CustomEvent("foo") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createEvent-expected.txt (196519 => 196520)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createEvent-expected.txt	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/nodes/Document-createEvent-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -1,34 +1,34 @@
 
 PASS CustomEvent should be an alias for CustomEvent. 
-FAIL createEvent('CustomEvent') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('CustomEvent') should be initialized correctly. 
 PASS customevent should be an alias for CustomEvent. 
-FAIL createEvent('customevent') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('customevent') should be initialized correctly. 
 PASS CUSTOMEVENT should be an alias for CustomEvent. 
-FAIL createEvent('CUSTOMEVENT') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('CUSTOMEVENT') should be initialized correctly. 
 PASS Event should be an alias for Event. 
-FAIL createEvent('Event') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('Event') should be initialized correctly. 
 PASS event should be an alias for Event. 
-FAIL createEvent('event') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('event') should be initialized correctly. 
 PASS EVENT should be an alias for Event. 
-FAIL createEvent('EVENT') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('EVENT') should be initialized correctly. 
 PASS Events should be an alias for Event. 
-FAIL createEvent('Events') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('Events') should be initialized correctly. 
 PASS events should be an alias for Event. 
-FAIL createEvent('events') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('events') should be initialized correctly. 
 PASS EVENTS should be an alias for Event. 
-FAIL createEvent('EVENTS') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('EVENTS') should be initialized correctly. 
 PASS HTMLEvents should be an alias for Event. 
-FAIL createEvent('HTMLEvents') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('HTMLEvents') should be initialized correctly. 
 PASS htmlevents should be an alias for Event. 
-FAIL createEvent('htmlevents') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('htmlevents') should be initialized correctly. 
 PASS HTMLEVENTS should be an alias for Event. 
-FAIL createEvent('HTMLEVENTS') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('HTMLEVENTS') should be initialized correctly. 
 PASS KeyboardEvent should be an alias for KeyboardEvent. 
-FAIL createEvent('KeyboardEvent') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('KeyboardEvent') should be initialized correctly. 
 PASS keyboardevent should be an alias for KeyboardEvent. 
-FAIL createEvent('keyboardevent') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('keyboardevent') should be initialized correctly. 
 PASS KEYBOARDEVENT should be an alias for KeyboardEvent. 
-FAIL createEvent('KEYBOARDEVENT') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('KEYBOARDEVENT') should be initialized correctly. 
 FAIL KeyEvents should be an alias for KeyboardEvent. NotSupportedError: DOM Exception 9
 FAIL createEvent('KeyEvents') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
 FAIL keyevents should be an alias for KeyboardEvent. NotSupportedError: DOM Exception 9
@@ -36,23 +36,23 @@
 FAIL KEYEVENTS should be an alias for KeyboardEvent. NotSupportedError: DOM Exception 9
 FAIL createEvent('KEYEVENTS') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
 PASS MessageEvent should be an alias for MessageEvent. 
-FAIL createEvent('MessageEvent') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('MessageEvent') should be initialized correctly. 
 PASS messageevent should be an alias for MessageEvent. 
-FAIL createEvent('messageevent') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('messageevent') should be initialized correctly. 
 PASS MESSAGEEVENT should be an alias for MessageEvent. 
-FAIL createEvent('MESSAGEEVENT') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('MESSAGEEVENT') should be initialized correctly. 
 PASS MouseEvent should be an alias for MouseEvent. 
-FAIL createEvent('MouseEvent') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('MouseEvent') should be initialized correctly. 
 PASS mouseevent should be an alias for MouseEvent. 
-FAIL createEvent('mouseevent') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('mouseevent') should be initialized correctly. 
 PASS MOUSEEVENT should be an alias for MouseEvent. 
-FAIL createEvent('MOUSEEVENT') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('MOUSEEVENT') should be initialized correctly. 
 PASS MouseEvents should be an alias for MouseEvent. 
-FAIL createEvent('MouseEvents') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('MouseEvents') should be initialized correctly. 
 PASS mouseevents should be an alias for MouseEvent. 
-FAIL createEvent('mouseevents') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('mouseevents') should be initialized correctly. 
 PASS MOUSEEVENTS should be an alias for MouseEvent. 
-FAIL createEvent('MOUSEEVENTS') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('MOUSEEVENTS') should be initialized correctly. 
 FAIL TouchEvent should be an alias for TouchEvent. NotSupportedError: DOM Exception 9
 FAIL createEvent('TouchEvent') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
 FAIL touchevent should be an alias for TouchEvent. NotSupportedError: DOM Exception 9
@@ -60,16 +60,16 @@
 FAIL TOUCHEVENT should be an alias for TouchEvent. NotSupportedError: DOM Exception 9
 FAIL createEvent('TOUCHEVENT') should be initialized correctly. undefined is not an object (evaluating 'ev.type')
 PASS UIEvent should be an alias for UIEvent. 
-FAIL createEvent('UIEvent') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('UIEvent') should be initialized correctly. 
 PASS uievent should be an alias for UIEvent. 
-FAIL createEvent('uievent') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('uievent') should be initialized correctly. 
 PASS UIEVENT should be an alias for UIEvent. 
-FAIL createEvent('UIEVENT') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('UIEVENT') should be initialized correctly. 
 PASS UIEvents should be an alias for UIEvent. 
-FAIL createEvent('UIEvents') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('UIEvents') should be initialized correctly. 
 PASS uievents should be an alias for UIEvent. 
-FAIL createEvent('uievents') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('uievents') should be initialized correctly. 
 PASS UIEVENTS should be an alias for UIEvent. 
-FAIL createEvent('UIEVENTS') should be initialized correctly. assert_equals: isTrusted should be initialized to false expected (boolean) false but got (undefined) undefined
+PASS createEvent('UIEVENTS') should be initialized correctly. 
 PASS Should throw NOT_SUPPORTED_ERR for unrecognized arguments 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt (196519 => 196520)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -4167,7 +4167,7 @@
 PASS Event interface: new PopStateEvent("popstate", { data: {} }) must inherit property "cancelable" with the proper type (11) 
 PASS Event interface: new PopStateEvent("popstate", { data: {} }) must inherit property "preventDefault" with the proper type (12) 
 PASS Event interface: new PopStateEvent("popstate", { data: {} }) must inherit property "defaultPrevented" with the proper type (13) 
-FAIL Event interface: new PopStateEvent("popstate", { data: {} }) must have own property "isTrusted" assert_own_property: expected property "isTrusted" missing
+PASS Event interface: new PopStateEvent("popstate", { data: {} }) must have own property "isTrusted" 
 PASS Event interface: new PopStateEvent("popstate", { data: {} }) must inherit property "timeStamp" with the proper type (15) 
 PASS Event interface: new PopStateEvent("popstate", { data: {} }) must inherit property "initEvent" with the proper type (16) 
 FAIL Event interface: calling initEvent(DOMString,boolean,boolean) on new PopStateEvent("popstate", { data: {} }) with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {
@@ -4495,7 +4495,7 @@
 PASS Event interface: new CloseEvent("close") must inherit property "cancelable" with the proper type (11) 
 PASS Event interface: new CloseEvent("close") must inherit property "preventDefault" with the proper type (12) 
 PASS Event interface: new CloseEvent("close") must inherit property "defaultPrevented" with the proper type (13) 
-FAIL Event interface: new CloseEvent("close") must have own property "isTrusted" assert_own_property: expected property "isTrusted" missing
+PASS Event interface: new CloseEvent("close") must have own property "isTrusted" 
 PASS Event interface: new CloseEvent("close") must inherit property "timeStamp" with the proper type (15) 
 PASS Event interface: new CloseEvent("close") must inherit property "initEvent" with the proper type (16) 
 FAIL Event interface: calling initEvent(DOMString,boolean,boolean) on new CloseEvent("close") with too few arguments must throw TypeError assert_throws: Called with 0 arguments function "function () {

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-button-element/button-events-expected.txt (196519 => 196520)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-button-element/button-events-expected.txt	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/the-button-element/button-events-expected.txt	2016-02-12 23:25:02 UTC (rev 196520)
@@ -1,5 +1,5 @@
 
-FAIL The submit event must be fired when click a button in submit status assert_true: The isTrusted attribute of the submit event should be true. expected true got undefined
-FAIL The reset event must be fired when click a button in reset status assert_true: The isTrusted attribute of the reset event should be true. expected true got undefined
+PASS The submit event must be fired when click a button in submit status 
+PASS The reset event must be fired when click a button in reset status 
 FAIL The show event must be fired when click a button in menu status assert_equals: The button type should be 'menu'. expected "menu" but got "submit"
 

Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (196519 => 196520)


--- trunk/LayoutTests/platform/ios-simulator/TestExpectations	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations	2016-02-12 23:25:02 UTC (rev 196520)
@@ -2942,3 +2942,5 @@
 webkit.org/b/153762 fast/regions/text-break-properties.html [ Skip ]
 
 webkit.org/b/153029 fast/css-generated-content/details-summary-before-after.html [ Failure ]
+
+webkit.org/b/76121 imported/blink/fast/events/event-trusted.html [ Skip ]
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (196519 => 196520)


--- trunk/Source/WebCore/ChangeLog	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebCore/ChangeLog	2016-02-12 23:25:02 UTC (rev 196520)
@@ -1,3 +1,53 @@
+2016-02-12  Jiewen Tan  <jiewen_...@apple.com>
+
+        WebKit should expose the DOM 4 Event.isTrusted property
+        https://bugs.webkit.org/show_bug.cgi?id=76121
+        <rdar://problem/22558494>
+
+        Reviewed by Darin Adler.
+
+        Implements Event.isTrusted. The implementation here is slitely different from and better than
+        the DOM specification. Here Event.isTrusted will be initialized differently depending on the
+        callers of the constructors/create methods. If the caller is from user agent, the isTrusted
+        will be true. Otherwise, it will be false. Since a user agent dispatched event can be catched
+        and re-initialized/redispatched by the bindings, the flag will be unset at *Event::init*Event
+        and EventTarget::dispatchEventForBindings. As currently there is no way to let user agent to
+        dispatch a bindings created event, therefore we ensure that the Event.isTrusted is set for
+        events dispatched by user agent, and unset for those by bindings.
+
+        EventTarget::dispatchEvent(Event*, ExceptionCode&) is renamed to EventTarget::dispatchEventForBindings
+        in this patch as well. So that, together with the improved design of the API, developers in
+        the future will be less likely using a wrong dispatchEvent method and setting Event.isTrusted
+        incorrectly comparing to the DOM design.
+
+        After this patch, all events that are created by user agent should be dispatched by
+        EventTarget::dispatchEvent, and those are created by bindings should be dispatched by
+        EventTarget::dispatchEventForBindings.
+
+        Some of the changes in this patch referred Blink r198996:
+        https://codereview.chromium.org/1241613004
+
+        Test: imported/blink/fast/events/event-trusted.html
+
+        * bindings/scripts/CodeGeneratorGObject.pm:
+        (GenerateEventTargetIface):
+        * dom/Event.cpp:
+        (WebCore::Event::Event):
+        (WebCore::Event::initEvent):
+        * dom/Event.h:
+        (WebCore::Event::isTrusted):
+        (WebCore::Event::setUntrusted):
+        * dom/Event.idl:
+        * dom/EventTarget.cpp:
+        (WebCore::EventTarget::dispatchEventForBindings):
+        (WebCore::EventTarget::dispatchEvent): Deleted.
+        * dom/EventTarget.h:
+        * dom/EventTarget.idl:
+        * page/DOMWindow.idl:
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::dispatchDragEvent):
+        * workers/WorkerGlobalScope.idl:
+
 2016-02-12  Brady Eidson  <beid...@apple.com>
 
         Modern IDB: IDBObjectStore and IDBIndex need to be ActiveDOMObjects.

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm (196519 => 196520)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm	2016-02-12 23:25:02 UTC (rev 196520)
@@ -1630,7 +1630,7 @@
     push(@cBodyProperties, "    WebCore::Event* coreEvent = WebKit::core(event);\n");
     push(@cBodyProperties, "    WebCore::${interfaceName}* coreTarget = static_cast<WebCore::${interfaceName}*>(WEBKIT_DOM_OBJECT(target)->coreObject);\n\n");
     push(@cBodyProperties, "    WebCore::ExceptionCode ec = 0;\n");
-    push(@cBodyProperties, "    gboolean result = coreTarget->dispatchEvent(coreEvent, ec);\n");
+    push(@cBodyProperties, "    gboolean result = coreTarget->dispatchEventForBindings(coreEvent, ec);\n");
     push(@cBodyProperties, "    if (ec) {\n        WebCore::ExceptionCodeDescription description(ec);\n");
     push(@cBodyProperties, "        g_set_error_literal(error, g_quark_from_string(\"WEBKIT_DOM\"), description.code, description.name);\n    }\n");
     push(@cBodyProperties, "    return result;\n");

Modified: trunk/Source/WebCore/dom/Event.cpp (196519 => 196520)


--- trunk/Source/WebCore/dom/Event.cpp	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebCore/dom/Event.cpp	2016-02-12 23:25:02 UTC (rev 196520)
@@ -39,6 +39,7 @@
     , m_type(eventType)
     , m_canBubble(canBubbleArg)
     , m_cancelable(cancelableArg)
+    , m_isTrusted(true)
     , m_createTime(convertSecondsToDOMTimeStamp(currentTime()))
 {
 }
@@ -48,6 +49,7 @@
     , m_type(eventType)
     , m_canBubble(canBubbleArg)
     , m_cancelable(cancelableArg)
+    , m_isTrusted(true)
     , m_createTime(convertSecondsToDOMTimeStamp(timestamp))
 {
 }
@@ -74,6 +76,7 @@
     m_propagationStopped = false;
     m_immediatePropagationStopped = false;
     m_defaultPrevented = false;
+    m_isTrusted = false;
 
     m_type = eventTypeArg;
     m_canBubble = canBubbleArg;

Modified: trunk/Source/WebCore/dom/Event.h (196519 => 196520)


--- trunk/Source/WebCore/dom/Event.h	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebCore/dom/Event.h	2016-02-12 23:25:02 UTC (rev 196520)
@@ -118,6 +118,9 @@
 
     void stopPropagation() { m_propagationStopped = true; }
     void stopImmediatePropagation() { m_immediatePropagationStopped = true; }
+
+    bool isTrusted() const { return m_isTrusted; }
+    void setUntrusted() { m_isTrusted = false; }
     
     // IE Extensions
     EventTarget* srcElement() const { return target(); } // MSIE extension - "the object that fired the event"
@@ -201,6 +204,7 @@
     bool m_defaultPrevented { false };
     bool m_defaultHandled { false };
     bool m_cancelBubble { false };
+    bool m_isTrusted { false };
 
     unsigned short m_eventPhase { 0 };
     EventTarget* m_currentTarget { nullptr };

Modified: trunk/Source/WebCore/dom/Event.idl (196519 => 196520)


--- trunk/Source/WebCore/dom/Event.idl	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebCore/dom/Event.idl	2016-02-12 23:25:02 UTC (rev 196520)
@@ -69,6 +69,8 @@
     readonly attribute boolean defaultPrevented;
     void stopImmediatePropagation();
 
+    [Unforgeable] readonly attribute boolean isTrusted;
+
     // IE Extensions
     readonly attribute EventTarget      srcElement;
     [ImplementedAs=legacyReturnValue] attribute boolean returnValue;

Modified: trunk/Source/WebCore/dom/EventTarget.cpp (196519 => 196520)


--- trunk/Source/WebCore/dom/EventTarget.cpp	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebCore/dom/EventTarget.cpp	2016-02-12 23:25:02 UTC (rev 196520)
@@ -134,13 +134,15 @@
     return removeEventListener(eventType, listener, false);
 }
 
-bool EventTarget::dispatchEvent(Event* event, ExceptionCode& ec)
+bool EventTarget::dispatchEventForBindings(Event* event, ExceptionCode& ec)
 {
     if (!event) {
         ec = TypeError;
         return false;
     }
 
+    event->setUntrusted();
+
     if (!event->isInitialized() || event->isBeingDispatched()) {
         ec = INVALID_STATE_ERR;
         return false;

Modified: trunk/Source/WebCore/dom/EventTarget.h (196519 => 196520)


--- trunk/Source/WebCore/dom/EventTarget.h	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebCore/dom/EventTarget.h	2016-02-12 23:25:02 UTC (rev 196520)
@@ -125,7 +125,7 @@
     virtual bool removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture);
     virtual void removeAllEventListeners();
     virtual bool dispatchEvent(Event&);
-    bool dispatchEvent(Event*, ExceptionCode&); // DOM API
+    bool dispatchEventForBindings(Event*, ExceptionCode&); // DOM API
     virtual void uncaughtExceptionInEventHandler();
 
     // Used for legacy "onEvent" attribute APIs.

Modified: trunk/Source/WebCore/dom/EventTarget.idl (196519 => 196520)


--- trunk/Source/WebCore/dom/EventTarget.idl	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebCore/dom/EventTarget.idl	2016-02-12 23:25:02 UTC (rev 196520)
@@ -28,5 +28,5 @@
 ] interface EventTarget {
     [ObjCLegacyUnnamedParameters] void addEventListener(DOMString type, EventListener listener, optional boolean useCapture);
     [ObjCLegacyUnnamedParameters] void removeEventListener(DOMString type, EventListener listener, optional boolean useCapture);
-    [RaisesException] boolean dispatchEvent(Event event);
+    [ImplementedAs=dispatchEventForBindings, RaisesException] boolean dispatchEvent(Event event);
 };

Modified: trunk/Source/WebCore/page/DOMWindow.idl (196519 => 196520)


--- trunk/Source/WebCore/page/DOMWindow.idl	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebCore/page/DOMWindow.idl	2016-02-12 23:25:02 UTC (rev 196520)
@@ -189,7 +189,7 @@
     // EventTarget interface
     [Custom] void addEventListener(DOMString type, EventListener listener, optional boolean useCapture);
     [Custom] void removeEventListener(DOMString type, EventListener listener, optional boolean useCapture);
-    [RaisesException] boolean dispatchEvent(Event event);
+    [ImplementedAs=dispatchEventForBindings, RaisesException] boolean dispatchEvent(Event event);
 
     void captureEvents(/*in long eventFlags*/);
     void releaseEvents(/*in long eventFlags*/);

Modified: trunk/Source/WebCore/page/EventHandler.cpp (196519 => 196520)


--- trunk/Source/WebCore/page/EventHandler.cpp	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2016-02-12 23:25:02 UTC (rev 196520)
@@ -2105,7 +2105,7 @@
         return false;
 
     view->disableLayerFlushThrottlingTemporarilyForInteraction();
-    RefPtr<MouseEvent> me = MouseEvent::create(eventType,
+    Ref<MouseEvent> me = MouseEvent::create(eventType,
         true, true, event.timestamp(), m_frame.document()->defaultView(),
         0, event.globalPosition().x(), event.globalPosition().y(), event.position().x(), event.position().y(),
 #if ENABLE(POINTER_LOCK)
@@ -2114,7 +2114,7 @@
         event.ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(),
         0, 0, event.force(), dataTransfer);
 
-    dragTarget.dispatchEvent(me.get(), IGNORE_EXCEPTION);
+    dragTarget.dispatchEvent(me);
     return me->defaultPrevented();
 }
 

Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.idl (196519 => 196520)


--- trunk/Source/WebCore/workers/WorkerGlobalScope.idl	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.idl	2016-02-12 23:25:02 UTC (rev 196520)
@@ -52,7 +52,7 @@
 
     void addEventListener(DOMString type, EventListener listener, optional boolean useCapture);
     void removeEventListener(DOMString type, EventListener listener, optional boolean useCapture);
-    [RaisesException] boolean dispatchEvent(Event event);
+    [ImplementedAs=dispatchEventForBindings, RaisesException] boolean dispatchEvent(Event event);
 
     // Additional constructors
 

Modified: trunk/Source/WebKit/win/ChangeLog (196519 => 196520)


--- trunk/Source/WebKit/win/ChangeLog	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebKit/win/ChangeLog	2016-02-12 23:25:02 UTC (rev 196520)
@@ -1,3 +1,15 @@
+2016-02-12  Jiewen Tan  <jiewen_...@apple.com>
+
+        WebKit should expose the DOM 4 Event.isTrusted property
+        https://bugs.webkit.org/show_bug.cgi?id=76121
+        <rdar://problem/22558494>
+
+        Reviewed by Darin Adler.
+
+        * DOMCoreClasses.cpp:
+        (DOMNode::dispatchEvent):
+        (DOMWindow::dispatchEvent):
+
 2016-02-11  Antti Koivisto  <an...@apple.com>
 
         Try to fix windows build.

Modified: trunk/Source/WebKit/win/DOMCoreClasses.cpp (196519 => 196520)


--- trunk/Source/WebKit/win/DOMCoreClasses.cpp	2016-02-12 23:16:57 UTC (rev 196519)
+++ trunk/Source/WebKit/win/DOMCoreClasses.cpp	2016-02-12 23:25:02 UTC (rev 196520)
@@ -441,7 +441,7 @@
         return hr;
 
     WebCore::ExceptionCode ec = 0;
-    *result = m_node->dispatchEvent(domEvent->coreEvent(), ec) ? TRUE : FALSE;
+    *result = m_node->dispatchEventForBindings(domEvent->coreEvent(), ec) ? TRUE : FALSE;
     return ec ? E_FAIL : S_OK;
 }
 
@@ -938,7 +938,7 @@
         return hr;
 
     WebCore::ExceptionCode ec = 0;
-    *result = m_window->dispatchEvent(domEvent->coreEvent(), ec) ? TRUE : FALSE;
+    *result = m_window->dispatchEventForBindings(domEvent->coreEvent(), ec) ? TRUE : FALSE;
     return ec ? E_FAIL : S_OK;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to