Title: [224125] trunk
Revision
224125
Author
[email protected]
Date
2017-10-27 12:56:04 -0700 (Fri, 27 Oct 2017)

Log Message

DOMWindow::dispatchEvent() does not reset the event's dispatch flag
https://bugs.webkit.org/show_bug.cgi?id=178897

Reviewed by Darin Adler.

Source/WebCore:

Make sure we reset the currentTarget, dispatch flag, phase and propagation flags
after dispatching an event on a Window, as per:
- https://dom.spec.whatwg.org/#concept-event-dispatch

This behavior is consistent with Firefox.

Test: fast/events/window-load-initEvent.html

* page/DOMWindow.cpp:
(WebCore::DOMWindow::dispatchEvent):

LayoutTests:

Add layout test coverage. I have verified that this test is passing in Firefox.

* fast/events/window-load-initEvent-expected.txt: Added.
* fast/events/window-load-initEvent.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (224124 => 224125)


--- trunk/LayoutTests/ChangeLog	2017-10-27 19:10:24 UTC (rev 224124)
+++ trunk/LayoutTests/ChangeLog	2017-10-27 19:56:04 UTC (rev 224125)
@@ -1,3 +1,15 @@
+2017-10-27  Chris Dumez  <[email protected]>
+
+        DOMWindow::dispatchEvent() does not reset the event's dispatch flag
+        https://bugs.webkit.org/show_bug.cgi?id=178897
+
+        Reviewed by Darin Adler.
+
+        Add layout test coverage. I have verified that this test is passing in Firefox.
+
+        * fast/events/window-load-initEvent-expected.txt: Added.
+        * fast/events/window-load-initEvent.html: Added.
+
 2017-10-27  Ryan Haddad  <[email protected]>
 
         Move TestExpectation for imported/w3c/web-platform-tests/XMLHttpRequest/open-url-worker-origin.htm.

Added: trunk/LayoutTests/fast/events/window-load-initEvent-expected.txt (0 => 224125)


--- trunk/LayoutTests/fast/events/window-load-initEvent-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/window-load-initEvent-expected.txt	2017-10-27 19:56:04 UTC (rev 224125)
@@ -0,0 +1,45 @@
+Tests the behavior of dispatchEvent() on a Window
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+* Received load event
+PASS testEvent.type is "load"
+PASS testEvent.bubbles is false
+PASS testEvent.cancelable is false
+PASS testEvent.composed is false
+PASS testEvent.isTrusted is true
+PASS testEvent.eventPhase is Event.AT_TARGET
+PASS testEvent.target is window.document
+PASS testEvent.currentTarget is window
+PASS testEvent.cancelBubble is false
+testEvent.initEvent('foo', true, true)
+PASS testEvent.type is "load"
+PASS testEvent.bubbles is false
+PASS testEvent.cancelable is false
+PASS testEvent.isTrusted is true
+testEvent.stopPropagation()
+PASS testEvent.cancelBubble is true
+* Event is no longer being dispatched
+PASS testEvent.type is "load"
+PASS testEvent.bubbles is false
+PASS testEvent.cancelable is false
+PASS testEvent.composed is false
+PASS testEvent.isTrusted is true
+PASS testEvent.eventPhase is Event.NONE
+PASS testEvent.target is window.document
+PASS testEvent.currentTarget is null
+PASS testEvent.cancelBubble is false
+testEvent.initEvent('bar', true, true)
+PASS testEvent.type is "bar"
+PASS testEvent.bubbles is true
+PASS testEvent.cancelable is true
+PASS testEvent.composed is false
+PASS testEvent.isTrusted is false
+PASS testEvent.eventPhase is Event.NONE
+PASS testEvent.target is null
+PASS testEvent.currentTarget is null
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/events/window-load-initEvent.html (0 => 224125)


--- trunk/LayoutTests/fast/events/window-load-initEvent.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/window-load-initEvent.html	2017-10-27 19:56:04 UTC (rev 224125)
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Tests the behavior of dispatchEvent() on a Window");
+jsTestIsAsync = true;
+
+_onload_ = function(e) {
+    testEvent = e;
+
+    debug("* Received load event");
+    shouldBeEqualToString("testEvent.type", "load");
+    shouldBeFalse("testEvent.bubbles");
+    shouldBeFalse("testEvent.cancelable");
+    shouldBeFalse("testEvent.composed");
+    shouldBeTrue("testEvent.isTrusted");
+    shouldBe("testEvent.eventPhase", "Event.AT_TARGET");
+    shouldBe("testEvent.target", "window.document");
+    shouldBe("testEvent.currentTarget", "window");
+    shouldBeFalse("testEvent.cancelBubble");
+
+    // Should fail because the event is being dispatched.
+    evalAndLog("testEvent.initEvent('foo', true, true)");
+
+    shouldBeEqualToString("testEvent.type", "load");
+    shouldBeFalse("testEvent.bubbles");
+    shouldBeFalse("testEvent.cancelable");
+    shouldBeTrue("testEvent.isTrusted");
+
+    evalAndLog("testEvent.stopPropagation()");
+    shouldBeTrue("testEvent.cancelBubble");
+
+    setTimeout(function() {
+        debug("* Event is no longer being dispatched");
+        shouldBeEqualToString("testEvent.type", "load");
+        shouldBeFalse("testEvent.bubbles");
+        shouldBeFalse("testEvent.cancelable");
+        shouldBeFalse("testEvent.composed");
+        shouldBeTrue("testEvent.isTrusted");
+        shouldBe("testEvent.eventPhase", "Event.NONE");
+        shouldBe("testEvent.target", "window.document");
+        shouldBeNull("testEvent.currentTarget");
+        shouldBeFalse("testEvent.cancelBubble");
+
+        evalAndLog("testEvent.initEvent('bar', true, true)");
+        shouldBeEqualToString("testEvent.type", "bar");
+        shouldBeTrue("testEvent.bubbles");
+        shouldBeTrue("testEvent.cancelable");
+        shouldBeFalse("testEvent.composed");
+        shouldBeFalse("testEvent.isTrusted");
+        shouldBe("testEvent.eventPhase", "Event.NONE");
+        shouldBeNull("testEvent.target");
+        shouldBeNull("testEvent.currentTarget");
+
+        finishJSTest();
+    }, 0);
+}
+</script>
+<script src=""
+</html>

Modified: trunk/LayoutTests/platform/mac/inspector/model/remote-object-dom-expected.txt (224124 => 224125)


--- trunk/LayoutTests/platform/mac/inspector/model/remote-object-dom-expected.txt	2017-10-27 19:10:24 UTC (rev 224124)
+++ trunk/LayoutTests/platform/mac/inspector/model/remote-object-dom-expected.txt	2017-10-27 19:56:04 UTC (rev 224125)
@@ -30,12 +30,13 @@
       {
         "_name": "currentTarget",
         "_type": "object",
-        "_value": "Window"
+        "_subtype": "null",
+        "_value": "null"
       },
       {
         "_name": "eventPhase",
         "_type": "number",
-        "_value": "2"
+        "_value": "0"
       }
     ],
     "_entries": null

Modified: trunk/Source/WebCore/ChangeLog (224124 => 224125)


--- trunk/Source/WebCore/ChangeLog	2017-10-27 19:10:24 UTC (rev 224124)
+++ trunk/Source/WebCore/ChangeLog	2017-10-27 19:56:04 UTC (rev 224125)
@@ -1,3 +1,21 @@
+2017-10-27  Chris Dumez  <[email protected]>
+
+        DOMWindow::dispatchEvent() does not reset the event's dispatch flag
+        https://bugs.webkit.org/show_bug.cgi?id=178897
+
+        Reviewed by Darin Adler.
+
+        Make sure we reset the currentTarget, dispatch flag, phase and propagation flags
+        after dispatching an event on a Window, as per:
+        - https://dom.spec.whatwg.org/#concept-event-dispatch
+
+        This behavior is consistent with Firefox.
+
+        Test: fast/events/window-load-initEvent.html
+
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::dispatchEvent):
+
 2017-10-27  Keith Miller  <[email protected]>
 
         Move iOS specific sources to unified sources

Modified: trunk/Source/WebCore/page/DOMWindow.cpp (224124 => 224125)


--- trunk/Source/WebCore/page/DOMWindow.cpp	2017-10-27 19:10:24 UTC (rev 224124)
+++ trunk/Source/WebCore/page/DOMWindow.cpp	2017-10-27 19:56:04 UTC (rev 224125)
@@ -2012,6 +2012,10 @@
 
     InspectorInstrumentation::didDispatchEventOnWindow(cookie);
 
+    event.setCurrentTarget(nullptr);
+    event.setEventPhase(Event::NONE);
+    event.resetPropagationFlags();
+
     return result;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to