Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Commit

Permalink
Bug 1491219 [wpt PR 13002] - Call capture event listeners in capturin…
Browse files Browse the repository at this point in the history
…g phase at shadow hosts, a=testonly

Automatic update from web-platform-testsCall capture event listeners in capturing phase at shadow hosts

Chromestatus entry is here: https://www.chromestatus.com/feature/5636327009681408

Per the discussion of whatwg/dom#685, Blink will try to align the event
dispatch behavior with other browsers; Call capture event listeners in capturing phase at shadow
hosts.

So far, Blink and WebKit call capture event listeners in *bubbling* phase, instead of
*capturing* phase, at shadow hosts.

Other browsers:
- Safari: Will try to change the behavior in the next Safari Technical Preview.
- Firefox: Already implemented the new behavior
- Edge: Strong public support for the new behavior.

This change is guard by CallCaptureListenersAtCapturePhaseAtShadowHosts flag, which is disabled
at this moment, to confirm that this CL doesn't cause any behavior change when the flag is disabled.

This CL adds a wpt for new behavior, which is now marked as [Failure] in Blink.

After this CL lands, I will flip the flag in a follow-up CL, with rebasing a very few existing
tests.

BUG=883650

Change-Id: I29938840aed4f3430d8b749cd4843176b8668b5d
Reviewed-on: https://chromium-review.googlesource.com/1212255
Commit-Queue: Hayato Ito <hayato@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591939}

--

wpt-commits: 9d63cfd82f428a999fb3cacffb2f940faa6a6b64
wpt-pr: 13002
  • Loading branch information
hayatoito authored and moz-wptsync-bot committed Sep 20, 2018
1 parent ebb6385 commit 528b7a8
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 10 deletions.
12 changes: 11 additions & 1 deletion testing/web-platform/meta/MANIFEST.json
Expand Up @@ -397743,6 +397743,12 @@
{}
]
],
"shadow-dom/event-dispatch-order.tentative.html": [
[
"/shadow-dom/event-dispatch-order.tentative.html",
{}
]
],
"shadow-dom/event-inside-shadow-tree.html": [
[
"/shadow-dom/event-inside-shadow-tree.html",
Expand Down Expand Up @@ -646238,6 +646244,10 @@
"2d6a5e36585b623a89b1e5f4e059d881027a0b94",
"testharness"
],
"shadow-dom/event-dispatch-order.tentative.html": [
"1e88740f53a2dc25d9650e4f54c3011e2b0e9355",
"testharness"
],
"shadow-dom/event-inside-shadow-tree.html": [
"a7405a59560c790c5708a7eaa4e65b6669adc0dd",
"testharness"
Expand Down Expand Up @@ -646307,7 +646317,7 @@
"support"
],
"shadow-dom/resources/shadow-dom.js": [
"3e55684dac1c4fbe1064c6d5d8b8d7ee86224921",
"192ad45413035ae629ba8158a5ceaca171af11fa",
"support"
],
"shadow-dom/scroll-to-the-fragment-in-shadow-tree.html": [
Expand Down
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<title>Shadow DOM: event dispatch order for capture and non-capture listerns at a shadow host</title>
<meta name="author" title="Hayato Ito" href="mailto:hayato@google.com">
<link rel="help" href="https://github.com/whatwg/dom/issues/685">
<link rel="help" href="https://github.com/whatwg/dom/pull/686">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/shadow-dom.js"></script>
<div id=host>
<template id=shadowroot data-mode=open>
<div id=target></div>
</template>
</div>
<script>
test(() => {
let nodes = createTestTree(host);
let log = dispatchEventWithLog(nodes, nodes.target,
new Event('my-event', { bubbles: true, composed: true }),
{ capture: true });
let path = ['target', 'shadowroot', 'host'];
assert_event_path_equals(log,
[['host', 'host', null, path, 'capture'],
['shadowroot', 'target', null, path, 'capture'],
['target', 'target', null, path, 'capture'],
['target', 'target', null, path, 'non-capture'],
['shadowroot', 'target', null, path, 'non-capture'],
['host', 'host', null, path, 'non-capture'],
]);
}, 'Event dispatch order: capture listerns should be called in capturing phase at a shadow host');
</script>
49 changes: 40 additions & 9 deletions testing/web-platform/tests/shadow-dom/resources/shadow-dom.js
Expand Up @@ -53,7 +53,9 @@ function createTestTree(node) {
return ids;
}

function dispatchEventWithLog(nodes, target, event) {
// TODO: Refactor this so that only interested results are recorded.
// Callers of this function would not be interested in every results.
function dispatchEventWithLog(nodes, target, event, options) {

function labelFor(e) {
return e.id || e.tagName;
Expand All @@ -70,15 +72,40 @@ function dispatchEventWithLog(nodes, target, event) {
if (!id)
continue;
attachedNodes.push(node);
node.addEventListener(event.type, (e) => {
if (options && options.capture) {
// Record [currentTarget, target, relatedTarget, composedPath(), 'capture' | 'non-capture']
// TODO: Support registering listeners in different orders.
// e.g. Register a non-capture listener at first, then register a capture listener.
node.addEventListener(event.type, (e) => {
log.push([id,
labelFor(e.target),
e.relatedTarget ? labelFor(e.relatedTarget) : null,
e.composedPath().map((n) => {
return labelFor(n);
}),
'capture']);
}, true);
node.addEventListener(event.type, (e) => {
log.push([id,
labelFor(e.target),
e.relatedTarget ? labelFor(e.relatedTarget) : null,
e.composedPath().map((n) => {
return labelFor(n);
}),
'non-capture']);
});
} else {
// Record [currentTarget, target, relatedTarget, composedPath()]
log.push([id,
labelFor(e.target),
e.relatedTarget ? labelFor(e.relatedTarget) : null,
e.composedPath().map((n) => {
return labelFor(n);
})]);
});
node.addEventListener(event.type, (e) => {
log.push([id,
labelFor(e.target),
e.relatedTarget ? labelFor(e.relatedTarget) : null,
e.composedPath().map((n) => {
return labelFor(n);
})]
);
});
}
}
}
target.dispatchEvent(event);
Expand Down Expand Up @@ -122,9 +149,13 @@ function dispatchUAEventWithLog(nodes, target, eventType, callback) {
function assert_event_path_equals(actual, expected) {
assert_equals(actual.length, expected.length);
for (let i = 0; i < actual.length; ++i) {
assert_equals(actual[i].length, expected[i].length);
assert_equals(actual[i][0], expected[i][0], 'currentTarget at ' + i + ' should be same');
assert_equals(actual[i][1], expected[i][1], 'target at ' + i + ' should be same');
assert_equals(actual[i][2], expected[i][2], 'relatedTarget at ' + i + ' should be same');
assert_array_equals(actual[i][3], expected[i][3], 'composedPath at ' + i + ' should be same');
if (actual[i][4]) {
assert_equals(actual[i][4], expected[i][4], 'listener type should be same at ' + i);
}
}
}

0 comments on commit 528b7a8

Please sign in to comment.