Skip to content

Commit 89a5856

Browse files
keithamuschromium-wpt-export-bot
authored andcommitted
Rename & refactor invoker commands to reflect new spec decisions.
Invoker commands now live solely on HTMLButtonElement, and have been dropped from HTMLInputElement. This was discussed and resolved + minuted in Jul 18 WHATNOT meeting: whatwg/html#10471 (comment)) Words must be separated with dashes. This was discussed and resolved + minuted in Jul 18 WHATNOT meeting: whatwg/html#10471 (comment)) "Custom" commands now require a double dash (`--`) prefix. This was discussed & resolved + minuted in the Jul 25 OpenUI meeting: openui/open-ui#969 (comment) In addition, CommandEvent#invoker is now renamed to CommandEvent#source as discussed and resolved + minuted in Jul 18 WHATNOT meeting: whatwg/html#10471 (comment)) This CL updates the tests & implementation to follow these changes. The changes can also be found in the spec PR which reflects this updated status: whatwg/html#9841 Bug: 40284894 Change-Id: Iefa91a1736867239a21f8717aee1fcaaa54fdfd0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5839601 Reviewed-by: Mason Freed <[email protected]> Reviewed-by: Luke <[email protected]> Commit-Queue: Keith Cirkel <[email protected]> Cr-Commit-Position: refs/heads/main@{#1367705}
1 parent 39246a8 commit 89a5856

16 files changed

+189
-179
lines changed

html/semantics/invokers/interesttarget-on-popover-behavior.tentative.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
promise_test(async function (t) {
7272
t.add_cleanup(reset);
7373
assert_false(interestee.matches(":popover-open"));
74-
interestbutton.setAttribute("interestaction", "togglepopover");
74+
interestbutton.setAttribute("interestaction", "toggle-popover");
7575
await hoverOver(interestbutton);
7676
assert_true(interestee.matches(":popover-open"));
7777
}, "hover interest invoking (as togglepopover) closed popover opens");
@@ -80,15 +80,15 @@
8080
t.add_cleanup(reset);
8181
interestee.showPopover();
8282
assert_true(interestee.matches(":popover-open"));
83-
interestbutton.setAttribute("interestaction", "togglepopover");
83+
interestbutton.setAttribute("interestaction", "toggle-popover");
8484
await hoverOver(interestbutton);
8585
assert_false(interestee.matches(":popover-open"));
8686
}, "hover interest invoking (as togglepopover) open popover closes");
8787

8888
promise_test(async function (t) {
8989
t.add_cleanup(reset);
9090
assert_false(interestee.matches(":popover-open"));
91-
interestbutton.setAttribute("interestaction", "togglepopover");
91+
interestbutton.setAttribute("interestaction", "toggle-popover");
9292
interestbutton.focus();
9393
assert_true(interestee.matches(":popover-open"));
9494
}, "focus interest invoking (as togglepopover) closed popover opens");
@@ -97,15 +97,15 @@
9797
t.add_cleanup(reset);
9898
interestee.showPopover();
9999
assert_true(interestee.matches(":popover-open"));
100-
interestbutton.setAttribute("interestaction", "togglepopover");
100+
interestbutton.setAttribute("interestaction", "toggle-popover");
101101
interestbutton.focus();
102102
assert_false(interestee.matches(":popover-open"));
103103
}, "focus interest invoking (as togglepopover) open popover closes");
104104

105105
promise_test(async function (t) {
106106
t.add_cleanup(reset);
107107
assert_false(interestee.matches(":popover-open"));
108-
interestbutton.setAttribute("interestaction", "tOgGlEpOpOvEr");
108+
interestbutton.setAttribute("interestaction", "tOgGlE-pOpOvEr");
109109
interestbutton.focus();
110110
assert_true(interestee.matches(":popover-open"));
111111
}, "interest invoking (as togglepopover - case insensitive) closed popover opens");

html/semantics/invokers/invokeevent-dispatch-shadow.tentative.html

+15-15
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
const slot = shadow.appendChild(document.createElement("slot"));
2121
let childEvent = null;
2222
let childEventTarget = null;
23-
let childEventInvoker = null;
23+
let childEventSource = null;
2424
let hostEvent = null;
2525
let hostEventTarget = null;
26-
let hostEventInvoker = null;
26+
let hostEventSource = null;
2727
slot.addEventListener(
2828
"command",
2929
(e) => {
3030
childEvent = e;
3131
childEventTarget = e.target;
32-
childEventInvoker = e.invoker;
32+
childEventSource = e.source;
3333
},
3434
{ once: true },
3535
);
@@ -38,13 +38,13 @@
3838
(e) => {
3939
hostEvent = e;
4040
hostEventTarget = e.target;
41-
hostEventInvoker = e.invoker;
41+
hostEventSource = e.source;
4242
},
4343
{ once: true },
4444
);
4545
const event = new CommandEvent("command", {
4646
bubbles: true,
47-
invoker: slot,
47+
source: slot,
4848
composed: true,
4949
});
5050
slot.dispatchEvent(event);
@@ -55,9 +55,9 @@
5555
"target is child inside shadow boundary",
5656
);
5757
assert_equals(
58-
childEventInvoker,
58+
childEventSource,
5959
slot,
60-
"invoker is child inside shadow boundary",
60+
"source is child inside shadow boundary",
6161
);
6262
assert_equals(
6363
hostEvent,
@@ -70,11 +70,11 @@
7070
"target is retargeted to shadowroot host",
7171
);
7272
assert_equals(
73-
hostEventInvoker,
73+
hostEventSource,
7474
host,
75-
"invoker is retargeted to shadowroot host",
75+
"source is retargeted to shadowroot host",
7676
);
77-
}, "CommandEvent propagates across shadow boundaries retargeting invoker");
77+
}, "CommandEvent propagates across shadow boundaries retargeting source");
7878

7979
test(function (t) {
8080
const host = document.createElement("div");
@@ -84,22 +84,22 @@
8484
const button = shadow.appendChild(document.createElement("button"));
8585
const invokee = host.appendChild(document.createElement("div"));
8686
button.commandForElement = invokee;
87-
button.command = 'test-command';
87+
button.command = '--test-command';
8888
let event = null;
8989
let eventTarget = null;
90-
let eventInvoker = null;
90+
let eventSource = null;
9191
invokee.addEventListener(
9292
"command",
9393
(e) => {
9494
event = e;
9595
eventTarget = e.target;
96-
eventInvoker = e.invoker;
96+
eventSource = e.source;
9797
},
9898
{ once: true },
9999
);
100100
button.click();
101101
assert_true(event instanceof CommandEvent);
102102
assert_equals(eventTarget, invokee, "target is invokee");
103-
assert_equals(eventInvoker, host, "invoker is host");
104-
}, "cross shadow CommandEvent retargets invoker to host element");
103+
assert_equals(eventSource, host, "source is host");
104+
}, "cross shadow CommandEvent retargets source to host element");
105105
</script>

html/semantics/invokers/invokeevent-interface.tentative.html

+27-27
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
test(function () {
2323
const event = new CommandEvent("test");
24-
assert_equals(event.invoker, null);
25-
assert_readonly(event, "invoker", "readonly attribute value");
26-
}, "invoker is readonly defaulting to null");
24+
assert_equals(event.source, null);
25+
assert_readonly(event, "source", "readonly attribute value");
26+
}, "source is readonly defaulting to null");
2727

2828
test(function () {
2929
const event = new CommandEvent("test", { command: "sAmPle" });
@@ -87,80 +87,80 @@
8787
}, "command set to an object with a toString function");
8888

8989
test(function () {
90-
const eventInit = { command: "sample", invoker: document.body };
90+
const eventInit = { command: "sample", source: document.body };
9191
const event = new CommandEvent("test", eventInit);
9292
assert_equals(event.command, "sample");
93-
assert_equals(event.invoker, document.body);
93+
assert_equals(event.source, document.body);
9494
}, "CommandEventInit properties set value");
9595

9696
test(function () {
9797
const eventInit = {
9898
command: "open",
99-
invoker: document.getElementById("div"),
99+
source: document.getElementById("div"),
100100
};
101101
const event = new CommandEvent("beforetoggle", eventInit);
102102
assert_equals(event.command, "open");
103-
assert_equals(event.invoker, document.getElementById("div"));
103+
assert_equals(event.source, document.getElementById("div"));
104104
}, "CommandEventInit properties set value 2");
105105

106106
test(function () {
107107
const eventInit = {
108108
command: "closed",
109-
invoker: document.getElementById("button"),
109+
source: document.getElementById("button"),
110110
};
111111
const event = new CommandEvent("toggle", eventInit);
112112
assert_equals(event.command, "closed");
113-
assert_equals(event.invoker, document.getElementById("button"));
113+
assert_equals(event.source, document.getElementById("button"));
114114
}, "CommandEventInit properties set value 3");
115115

116116
test(function () {
117-
const event = new CommandEvent("test", { invoker: undefined });
118-
assert_equals(event.invoker, null);
119-
}, "invoker set to undefined");
117+
const event = new CommandEvent("test", { source: undefined });
118+
assert_equals(event.source, null);
119+
}, "source set to undefined");
120120

121121
test(function () {
122-
const event = new CommandEvent("test", { invoker: null });
123-
assert_equals(event.invoker, null);
124-
}, "invoker set to null");
122+
const event = new CommandEvent("test", { source: null });
123+
assert_equals(event.source, null);
124+
}, "source set to null");
125125

126126
test(function () {
127127
assert_throws_js(
128128
TypeError,
129129
function () {
130-
new CommandEvent("test", { invoker: false });
130+
new CommandEvent("test", { source: false });
131131
},
132-
"invoker is not an object",
132+
"source is not an object",
133133
);
134-
}, "invoker set to false");
134+
}, "source set to false");
135135

136136
test(function () {
137137
assert_throws_js(
138138
TypeError,
139139
function () {
140-
const event = new CommandEvent("test", { invoker: true });
140+
const event = new CommandEvent("test", { source: true });
141141
},
142-
"invoker is not an object",
142+
"source is not an object",
143143
);
144-
}, "invoker set to true");
144+
}, "source set to true");
145145

146146
test(function () {
147147
assert_throws_js(
148148
TypeError,
149149
function () {
150-
const event = new CommandEvent("test", { invoker: {} });
150+
const event = new CommandEvent("test", { source: {} });
151151
},
152-
"invoker is not an object",
152+
"source is not an object",
153153
);
154-
}, "invoker set to {}");
154+
}, "source set to {}");
155155

156156
test(function () {
157157
assert_throws_js(
158158
TypeError,
159159
function () {
160-
const eventInit = { command: "closed", invoker: new XMLHttpRequest() };
160+
const eventInit = { command: "closed", source: new XMLHttpRequest() };
161161
const event = new CommandEvent("toggle", eventInit);
162162
},
163-
"invoker is not an Element",
163+
"source is not an Element",
164164
);
165-
}, "invoker set to non-Element EventTarget");
165+
}, "source set to non-Element EventTarget");
166166
</script>

html/semantics/invokers/invoketarget-button-event-dispatch.tentative.html

+18-10
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
1111
<script src="resources/invoker-utils.js"></script>
1212

1313
<div id="invokee"></div>
14-
<button id="invokerbutton" commandfor="invokee" command="custom-command"></button>
14+
<button id="invokerbutton" commandfor="invokee" command="--custom-command"></button>
15+
<input type="button" id="invalidbutton" commandfor="invokee" command="--custom-command">
1516
<form id="aform"></form>
1617

1718
<script>
1819
aform.addEventListener('submit', (e) => (e.preventDefault()));
1920

2021
function resetState() {
2122
invokerbutton.setAttribute("commandfor", "invokee");
22-
invokerbutton.setAttribute("command", "custom-command");
23+
invokerbutton.setAttribute("command", "--custom-command");
2324
invokerbutton.removeAttribute("disabled");
2425
invokerbutton.removeAttribute("form");
2526
invokerbutton.removeAttribute("type");
@@ -34,13 +35,13 @@
3435
assert_equals(event.bubbles, false, "bubbles");
3536
assert_equals(event.composed, true, "composed");
3637
assert_equals(event.isTrusted, true, "isTrusted");
37-
assert_equals(event.command, "custom-command", "command");
38+
assert_equals(event.command, "--custom-command", "command");
3839
assert_equals(event.target, invokee, "target");
39-
assert_equals(event.invoker, invokerbutton, "invoker");
40+
assert_equals(event.source, invokerbutton, "invoker");
4041
}, "event dispatches on click");
4142

4243
// valid custom invokeactions
43-
["-foo", "foo-", "cAsE-cArRiEs", "-", "-a-", "a-b", "---", "show-picker"].forEach(
44+
["--foo", "--foo-", "--cAsE-cArRiEs", "--", "--a-", "--a-b", "---", "--show-picker"].forEach(
4445
(command) => {
4546
promise_test(async function (t) {
4647
t.add_cleanup(resetState);
@@ -55,7 +56,7 @@
5556
assert_equals(event.isTrusted, true, "isTrusted");
5657
assert_equals(event.command, command, "command");
5758
assert_equals(event.target, invokee, "target");
58-
assert_equals(event.invoker, invokerbutton, "invoker");
59+
assert_equals(event.source, invokerbutton, "invoker");
5960
}, `setting custom command property to ${command} (must include dash) sets event command`);
6061

6162
promise_test(async function (t) {
@@ -71,13 +72,13 @@
7172
assert_equals(event.isTrusted, true, "isTrusted");
7273
assert_equals(event.command, command, "command");
7374
assert_equals(event.target, invokee, "target");
74-
assert_equals(event.invoker, invokerbutton, "invoker");
75+
assert_equals(event.source, invokerbutton, "invoker");
7576
}, `setting custom command attribute to ${command} (must include dash) sets event command`);
7677
},
7778
);
7879

7980
// invalid custom invokeactions
80-
["foo", "foobar", "foo bar", "em—dash", "hidedocument"].forEach((command) => {
81+
["-foo", "-foo-", "foo-bar", "-foo bar", "—-emdash", "hidedocument"].forEach((command) => {
8182
promise_test(async function (t) {
8283
t.add_cleanup(resetState);
8384
let event = null;
@@ -117,6 +118,13 @@
117118
assert_false(called, "event was not called");
118119
}, "event does not dispatch if click:preventDefault is called");
119120

121+
promise_test(async function (t) {
122+
let event = null;
123+
invokee.addEventListener("command", (e) => (event = e), { once: true });
124+
await clickOn(invalidbutton);
125+
assert_equals(event, null, "command should not have fired");
126+
}, "event does not dispatch on input[type=button]");
127+
120128
promise_test(async function (t) {
121129
t.add_cleanup(resetState);
122130
let called = false;
@@ -155,12 +163,12 @@
155163
let event = null;
156164
svgInvokee.addEventListener("command", (e) => (event = e), { once: true });
157165
invokerbutton.setAttribute("commandfor", "svg-invokee");
158-
invokerbutton.setAttribute("command", "custom-command");
166+
invokerbutton.setAttribute("command", "--custom-command");
159167
assert_equals(invokerbutton.commandForElement, svgInvokee);
160168
await clickOn(invokerbutton);
161169
assert_not_equals(event, null, "event was called");
162170
assert_true(event instanceof CommandEvent, "event is CommandEvent");
163-
assert_equals(event.invoker, invokerbutton, "event.invoker is set to right element");
171+
assert_equals(event.source, invokerbutton, "event.invoker is set to right element");
164172
assert_equals(event.target, svgInvokee, "event.target is set to right element");
165173
}, "event dispatches if invokee is non-HTML Element");
166174
</script>

0 commit comments

Comments
 (0)