Skip to content

Update CommandEvent tests to expect an uncomposed event #52276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
assert_true(event instanceof CommandEvent, "event is CommandEvent");
assert_equals(event.type, "command", "type");
assert_equals(event.bubbles, false, "bubbles");
assert_equals(event.composed, true, "composed");
assert_equals(event.composed, false, "composed");
assert_equals(event.isTrusted, true, "isTrusted");
assert_equals(event.command, "--custom-command", "command");
assert_equals(event.target, invokee, "target");
Expand All @@ -47,7 +47,7 @@
assert_true(event instanceof CommandEvent, "event is CommandEvent");
assert_equals(event.type, "command", "type");
assert_equals(event.bubbles, false, "bubbles");
assert_equals(event.composed, true, "composed");
assert_equals(event.composed, false, "composed");
assert_equals(event.isTrusted, true, "isTrusted");
assert_equals(event.command, "--custom-command", "command");
assert_equals(event.target, invokee, "target");
Expand All @@ -66,7 +66,7 @@
assert_true(event instanceof CommandEvent, "event is CommandEvent");
assert_equals(event.type, "command", "type");
assert_equals(event.bubbles, false, "bubbles");
assert_equals(event.composed, true, "composed");
assert_equals(event.composed, false, "composed");
assert_equals(event.isTrusted, true, "isTrusted");
assert_equals(event.command, command, "command");
assert_equals(event.target, invokee, "target");
Expand All @@ -82,7 +82,7 @@
assert_true(event instanceof CommandEvent, "event is CommandEvent");
assert_equals(event.type, "command", "type");
assert_equals(event.bubbles, false, "bubbles");
assert_equals(event.composed, true, "composed");
assert_equals(event.composed, false, "composed");
assert_equals(event.isTrusted, true, "isTrusted");
assert_equals(event.command, command, "command");
assert_equals(event.target, invokee, "target");
Expand Down Expand Up @@ -178,7 +178,7 @@
assert_true(event instanceof CommandEvent, "event is CommandEvent");
assert_equals(event.type, "command", "type");
assert_equals(event.bubbles, false, "bubbles");
assert_equals(event.composed, true, "composed");
assert_equals(event.composed, false, "composed");
assert_equals(event.isTrusted, true, "isTrusted");
assert_equals(event.command, "--custom-command", "command");
assert_equals(event.target, invokee, "target");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,7 @@
<script src="/resources/testharnessreport.js"></script>
<script src="resources/invoker-utils.js"></script>

<div id="div"></div>
<button id="button"></button>

<script>
test(function () {
const host = document.createElement("div");
const child = host.appendChild(document.createElement("p"));
const shadow = host.attachShadow({ mode: "closed" });
const slot = shadow.appendChild(document.createElement("slot"));
let childEvent = null;
let childEventTarget = null;
let childEventSource = null;
let hostEvent = null;
let hostEventTarget = null;
let hostEventSource = null;
slot.addEventListener(
"command",
(e) => {
childEvent = e;
childEventTarget = e.target;
childEventSource = e.source;
},
{ once: true },
);
host.addEventListener(
"command",
(e) => {
hostEvent = e;
hostEventTarget = e.target;
hostEventSource = e.source;
},
{ once: true },
);
const event = new CommandEvent("command", {
bubbles: true,
source: slot,
composed: true,
});
slot.dispatchEvent(event);
assert_true(childEvent instanceof CommandEvent, "slot saw invoke event");
assert_equals(
childEventTarget,
slot,
"target is child inside shadow boundary",
);
assert_equals(
childEventSource,
slot,
"source is child inside shadow boundary",
);
assert_equals(
hostEvent,
childEvent,
"event dispatch propagates across shadow boundary",
);
assert_equals(
hostEventTarget,
host,
"target is retargeted to shadowroot host",
);
assert_equals(
hostEventSource,
host,
"source is retargeted to shadowroot host",
);
}, "CommandEvent propagates across shadow boundaries retargeting source");

test(function (t) {
const host = document.createElement("div");
document.body.append(host);
Expand All @@ -96,6 +30,7 @@
);
button.click();
assert_true(event instanceof CommandEvent);
assert_equals(event.composed, false, "composed is false");
assert_equals(eventTarget, invokee, "target is invokee");
assert_equals(eventSource, host, "source is host");
}, "cross shadow CommandEvent retargets source to host element");
Expand Down
Loading