Title: [200536] trunk/LayoutTests
Revision
200536
Author
[email protected]
Date
2016-05-06 20:51:46 -0700 (Fri, 06 May 2016)

Log Message

MouseEvent's offsetX and offsetY should be based on relative target
https://bugs.webkit.org/show_bug.cgi?id=157444
<rdar://problem/24396408>

Reviewed by Darin Adler.

Add a W3C style testharness.js test for adjusting offsetX and offsetY to the adjusted target
since our existing behavior matches the spec as well as Chrome's behavior:
http://w3c.github.io/webcomponents/spec/shadow/#event-dispatch

* fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY-expected.txt: Added.
* fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (200535 => 200536)


--- trunk/LayoutTests/ChangeLog	2016-05-07 03:08:18 UTC (rev 200535)
+++ trunk/LayoutTests/ChangeLog	2016-05-07 03:51:46 UTC (rev 200536)
@@ -1,3 +1,18 @@
+2016-05-06  Ryosuke Niwa  <[email protected]>
+
+        MouseEvent's offsetX and offsetY should be based on relative target
+        https://bugs.webkit.org/show_bug.cgi?id=157444
+        <rdar://problem/24396408>
+
+        Reviewed by Darin Adler.
+
+        Add a W3C style testharness.js test for adjusting offsetX and offsetY to the adjusted target
+        since our existing behavior matches the spec as well as Chrome's behavior:
+        http://w3c.github.io/webcomponents/spec/shadow/#event-dispatch
+
+        * fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY-expected.txt: Added.
+        * fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY.html: Added.
+
 2016-05-06  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Improve console.count()

Added: trunk/LayoutTests/fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY-expected.txt (0 => 200536)


--- trunk/LayoutTests/fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY-expected.txt	2016-05-07 03:51:46 UTC (rev 200536)
@@ -0,0 +1,6 @@
+Click here
+
+PASS MouseEvent's offsetX and offsetY attributes must be relative to the target. 
+PASS MouseEvent's offsetX and offsetY attributes must be relative to the shadow host when an event is dispatched inside its shadow tree. 
+PASS MouseEvent's offsetX and offsetY attributes must be relative to the target when an event is dispatched on a slotted content. 
+

Added: trunk/LayoutTests/fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY.html (0 => 200536)


--- trunk/LayoutTests/fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY.html	                        (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/MouseEvent-prototype-offsetX-offsetY.html	2016-05-07 03:51:46 UTC (rev 200536)
@@ -0,0 +1,155 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Shadow DOM: MouseEvent's offsetX and offsetY attributes must be relative to the relative target.</title>
+<meta name="author" title="Ryosuke Niwa" href=""
+<meta name="assert" content="The MouseEvent offsetX and offsetY attributes must return the coordinates relative to the origin of the padding edge of the relative target">
+<link rel="help" href=""
+<script src=""
+<script src=""
+<script src=""
+<link rel='stylesheet' href=''>
+</head>
+<body>
+<style>
+html, body { padding: 0; margin: 0; }
+my-host { display: block; width: 180px; height: 80px; margin: 10px 20px; padding: 10px; background: #ccc; }
+#log { margin: 1rem; }
+</style>
+<my-host></my-host>
+<div id="log"></div>
+<script>
+
+var shadowStyle = '#container { width: 160px; height: 60px; padding: 10px; background: yellow; } #target { margin-left: 5px; background: orange; }';
+var host = document.querySelector('my-host');
+
+function attachLoggers(targets)
+{
+    var eventLogs = [];
+    for (var i = 0; i < targets.length; i++) {
+        targets[i].addEventListener('mousedown', function (event) {
+            eventLogs.push({current: this, target: event.target, offsetX: event.offsetX, offsetY: event.offsetY});
+        });
+    }
+    return eventLogs;
+}
+
+test(function () {
+    host.innerHTML = '<style>' + shadowStyle + '</style><div id="container"><span id="target">Click here</div></div>';
+
+    var target = host.querySelector('#target');
+    var container = host.querySelector('#container');
+
+    var eventLogs = attachLoggers([target, container, host, document.body]);
+    var mouseEvent = new MouseEvent('mousedown', {clientX: 51, clientY: 37, scoped: false, bubbles: true});
+    target.dispatchEvent(mouseEvent);
+
+    assert_equals(host.offsetLeft, 20, 'The host must be at (20px, 10px)');
+    assert_equals(host.offsetTop, 10, 'The host must be at (20px, 10px)');
+    assert_equals(target.offsetLeft, 45, 'The target must be at (45px, 30px)');
+    assert_equals(target.offsetTop, 30, 'The target must be at (45px, 30px)');
+
+    assert_equals(eventLogs[0].current, target);
+    assert_equals(eventLogs[0].target, target);
+    assert_equals(eventLogs[0].offsetX, 21); // Padding edge of target is at (30px, 20px)
+    assert_equals(eventLogs[0].offsetY, 17);
+
+    assert_equals(eventLogs[1].current, container);
+    assert_equals(eventLogs[1].target, target);
+    assert_equals(eventLogs[1].offsetX, 21);
+    assert_equals(eventLogs[1].offsetY, 17);
+
+    assert_equals(eventLogs[2].current, host);
+    assert_equals(eventLogs[2].target, target);
+    assert_equals(eventLogs[2].offsetX, 21);
+    assert_equals(eventLogs[2].offsetY, 17);
+
+    assert_equals(eventLogs[3].current, document.body);
+    assert_equals(eventLogs[3].target, target);
+    assert_equals(eventLogs[3].offsetX, 21);
+    assert_equals(eventLogs[3].offsetY, 17);
+}, 'MouseEvent\'s offsetX and offsetY attributes must be relative to the target.');
+
+var shadowRoot = host.attachShadow({mode: 'closed'});
+test(function () {
+    shadowRoot.innerHTML = '<style>' + shadowStyle + '</style><div id="container"><span id="target">Click here</div></div>';
+
+    var target = shadowRoot.querySelector('#target');
+    var container = shadowRoot.querySelector('#container');
+
+    var eventLogs = attachLoggers([target, container, shadowRoot, host, document.body]);
+    var mouseEvent = new MouseEvent('mousedown', {clientX: 51, clientY: 37, scoped: false, bubbles: true});
+    target.dispatchEvent(mouseEvent);
+
+    assert_equals(host.offsetLeft, 20, 'The host must be at (20px, 10px)');
+    assert_equals(host.offsetTop, 10, 'The host must be at (20px, 10px)');
+    assert_equals(target.offsetLeft, 45, 'The target must be at (45px, 30px)');
+    assert_equals(target.offsetTop, 30, 'The target must be at (45px, 30px)');
+
+    assert_equals(eventLogs[0].current, target);
+    assert_equals(eventLogs[0].target, target);
+    assert_equals(eventLogs[0].offsetX, 21); // Padding edge of target is at (30px, 20px)
+    assert_equals(eventLogs[0].offsetY, 17);
+
+    assert_equals(eventLogs[1].current, container);
+    assert_equals(eventLogs[1].target, target);
+    assert_equals(eventLogs[1].offsetX, 21);
+    assert_equals(eventLogs[1].offsetY, 17);
+
+    assert_equals(eventLogs[3].current, host);
+    assert_equals(eventLogs[3].target, host);
+    assert_equals(eventLogs[3].offsetX, 31); // Padding edge of host is at (20px, 10px)
+    assert_equals(eventLogs[3].offsetY, 27);
+
+    assert_equals(eventLogs[4].current, document.body);
+    assert_equals(eventLogs[4].target, host);
+    assert_equals(eventLogs[4].offsetX, 31);
+    assert_equals(eventLogs[4].offsetY, 27);
+}, 'MouseEvent\'s offsetX and offsetY attributes must be relative to the shadow host when an event is dispatched inside its shadow tree.');
+
+test(function () {
+    shadowRoot.innerHTML = '<style>' + shadowStyle + '</style><div id="container"><slot></slot></div>';
+    host.innerHTML = '<style>' + shadowStyle + '</style><div id="target">Click here</div>';
+
+    var target = host.querySelector('#target');
+    var container = shadowRoot.querySelector('#container');
+
+    var eventLogs = attachLoggers([target, container, shadowRoot, host, document.body]);
+    var mouseEvent = new MouseEvent('mousedown', {clientX: 51, clientY: 37, scoped: false, bubbles: true});
+    target.dispatchEvent(mouseEvent);
+
+    assert_equals(host.offsetLeft, 20, 'The host must be at (20px, 10px)');
+    assert_equals(host.offsetTop, 10, 'The host must be at (20px, 10px)');
+    assert_equals(target.offsetLeft, 45, 'The target must be at (45px, 30px)');
+    assert_equals(target.offsetTop, 30, 'The target must be at (45px, 30px)');
+
+    assert_equals(eventLogs[0].current, target);
+    assert_equals(eventLogs[0].target, target);
+    assert_equals(eventLogs[0].target.offsetParent, document.body);
+    assert_equals(eventLogs[0].offsetX, 6); // Padding edge of target is at (45px, 30px)
+    assert_equals(eventLogs[0].offsetY, 7);
+
+    assert_equals(eventLogs[1].current, container);
+    assert_equals(eventLogs[1].target, target);
+    assert_equals(eventLogs[1].offsetX, 6);
+    assert_equals(eventLogs[1].offsetY, 7);
+
+    assert_equals(eventLogs[2].current, shadowRoot);
+    assert_equals(eventLogs[2].target, target);
+    assert_equals(eventLogs[2].offsetX, 6);
+    assert_equals(eventLogs[2].offsetY, 7);
+
+    assert_equals(eventLogs[3].current, host);
+    assert_equals(eventLogs[3].target, target);
+    assert_equals(eventLogs[3].offsetX, 6);
+    assert_equals(eventLogs[3].offsetY, 7);
+
+    assert_equals(eventLogs[4].current, document.body);
+    assert_equals(eventLogs[4].target, target);
+    assert_equals(eventLogs[4].offsetX, 6);
+    assert_equals(eventLogs[4].offsetY, 7);
+}, 'MouseEvent\'s offsetX and offsetY attributes must be relative to the target when an event is dispatched on a slotted content.');
+
+</script>
+</body>
+</html>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to