summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/the-selectlist-element/selectlist-button-type-behavior.tentative.html
blob: cc7eb62a6327e90a2d038e777612685e00edb746 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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>