summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/the-selectlist-element/selectlist-pseudo-open-closed.tentative.html
blob: 1d5a082c033052a59ab35b2e543187794311adfd (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<link rel=author href="mailto:jarhar@chromium.org">
<link rel=help href="https://github.com/openui/open-ui/issues/547">
<link rel=help href="https://drafts.csswg.org/selectors/#open-state">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<selectlist id=myselectlist>
  <button type=selectlist id=custombutton>button</button>
  <option>one</option>
  <option>two</option>
</selectlist>

<script>
test(() => {
  assert_false(myselectlist.matches(':open'),
    'Selectlist should not match :open while it is closed.');
  assert_true(myselectlist.matches(':closed'),
    'Selectlist should match :closed while it is closed.');

  custombutton.click();

  assert_true(myselectlist.matches(':open'),
    'Selectlist should match :open while it is open.');
  assert_false(myselectlist.matches(':closed'),
    'Selectlist should not match :closed while it is open.');
}, 'Selectlist should support :open and :closed pseudo selectors.');
</script>

<selectlist id=selectlistinvalidation>
  <button type=selectlist>button</button>
  <option>one</option>
  <option>two</option>
</selectlist>
<style>
selectlist:closed {
  background-color: red;
}
selectlist:open {
  background-color: green;
}
</style>

<script>
test(() => {
  const selectlist = document.getElementById('selectlistinvalidation');
  const button = selectlist.querySelector('button');
  const option = selectlist.querySelector('option');

  assert_equals(getComputedStyle(selectlist).backgroundColor, 'rgb(255, 0, 0)',
    'The style rules from :closed should apply when the selectlist is closed.');

  button.click();
  assert_equals(getComputedStyle(selectlist).backgroundColor, 'rgb(0, 128, 0)',
    'The style rules from :open should apply when the selectlist is open.');

  option.click();
  assert_equals(getComputedStyle(selectlist).backgroundColor, 'rgb(255, 0, 0)',
    'The style rules from :closed should apply when the selectlist is opened and closed again.');
}, 'Selectlist :open and :closed should invalidate correctly.');
</script>