selectlist: support <button type=selectlist>

In the new selectlist architecture, any descendant <button
type=selectlist> should get the behavior of opening the listbox.

Bug: 1121840
Change-Id: Ib9f4efdcdec706e6750c38534d163be8d065390d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4796450
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1189620}
diff --git a/html/semantics/forms/the-selectlist-element/button-type-selectlist-appearance-ref.html b/html/semantics/forms/the-selectlist-element/button-type-selectlist-appearance-ref.html
new file mode 100644
index 0000000..fd7f2b7
--- /dev/null
+++ b/html/semantics/forms/the-selectlist-element/button-type-selectlist-appearance-ref.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<button>button</button>
diff --git a/html/semantics/forms/the-selectlist-element/button-type-selectlist-appearance.tentative.html b/html/semantics/forms/the-selectlist-element/button-type-selectlist-appearance.tentative.html
new file mode 100644
index 0000000..3ab7044
--- /dev/null
+++ b/html/semantics/forms/the-selectlist-element/button-type-selectlist-appearance.tentative.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<link rel=author href="mailto:jarhar@chromium.org">
+<link rel=help href="https://github.com/openui/open-ui/issues/702">
+<link rel=match href="button-type-selectlist-appearance-ref.html">
+
+<button type=selectlist>button</button>
diff --git a/html/semantics/forms/the-selectlist-element/selectlist-button-type-appearance-ref.html b/html/semantics/forms/the-selectlist-element/selectlist-button-type-appearance-ref.html
new file mode 100644
index 0000000..37d4b1b
--- /dev/null
+++ b/html/semantics/forms/the-selectlist-element/selectlist-button-type-appearance-ref.html
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<button>hello world</button>
diff --git a/html/semantics/forms/the-selectlist-element/selectlist-button-type-appearance.tentative.html b/html/semantics/forms/the-selectlist-element/selectlist-button-type-appearance.tentative.html
new file mode 100644
index 0000000..50ad339
--- /dev/null
+++ b/html/semantics/forms/the-selectlist-element/selectlist-button-type-appearance.tentative.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<link rel=author href="mailto:jarhar@chromium.org">
+<link rel=help href="https://github.com/openui/open-ui/issues/702">
+<link rel=match href="selectlist-button-type-appearance-ref.html">
+
+<selectlist>
+  <button type=selectlist>hello world</button>
+</selectlist>
diff --git a/html/semantics/forms/the-selectlist-element/selectlist-button-type-behavior.tentative.html b/html/semantics/forms/the-selectlist-element/selectlist-button-type-behavior.tentative.html
new file mode 100644
index 0000000..cc7eb62
--- /dev/null
+++ b/html/semantics/forms/the-selectlist-element/selectlist-button-type-behavior.tentative.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<link rel=author href="mailto:jarhar@chromium.org">
+<link rel=help href="https://github.com/openui/open-ui/issues/702">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-actions.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+
+<selectlist>
+  <button type=selectlist id=b1>first button</button>
+  <button type=selectlist id=b2>second button</button>
+  <button id=b3>third button</button>
+  <option>option</option>
+</selectlist>
+
+<script>
+const ESC = '\uE00C'
+
+promise_test(async () => {
+  const selectlist = document.querySelector('selectlist');
+  const b1 = document.getElementById('b1');
+  const b2 = document.getElementById('b2');
+  const b3 = document.getElementById('b3');
+
+  assert_false(selectlist.open, 'The selectlist should start closed.');
+  await test_driver.click(b1);
+  assert_true(selectlist.open, 'The selectlist should get opened when the button is clicked.');
+
+  await test_driver.send_keys(selectlist, ESC);
+  assert_false(selectlist.open, 'Pressing escape should close the selectlist.');
+
+  await test_driver.click(b2);
+  assert_true(selectlist.open, 'The selectlist should get opened when a second type=selectlist button is clicked.');
+  await test_driver.send_keys(selectlist, ESC);
+  assert_false(selectlist.open, 'Pressing escape should close the selectlist.');
+
+  await test_driver.click(b3);
+  assert_false(selectlist.open, 'Clicking a button witout type=selectlist should not open the listbox.');
+
+  b1.removeAttribute('type');
+  await test_driver.click(b1);
+  assert_false(selectlist.open, 'If the button is not type=selectlist, it should not open the selectlist.');
+}, '<button type=selectlist> should open the parent selectlist when clicked.');
+</script>