testing/web-platform/tests/html/semantics/forms/the-select-element/customizable-select/select-pseudo-open.tentative.html
author dadaa <daisuke.akatsuka@birchill.co.jp>
Wed, 09 Jul 2025 04:53:58 +0000 (15 hours ago)
changeset 795836 a5500d271fe3a1fefb4d81d96fc4abd00d9eade7
parent 769410 1b409e3f28f9c6dc8646f9cf0ace117dac161908
permissions -rw-r--r--
Bug 1957280: Limit user's mouse amount for tree component r=places-reviewers,reusable-components-reviewers,masayuki,mstriemer Differential Revision: https://phabricator.services.mozilla.com/D251224
<!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>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<select id=myselect>
  <option>one</option>
  <option>two</option>
</select>

<style>
  select, ::picker(select) {
    appearance: base-select;
  }
</style>

<script>
promise_test(async () => {
  assert_true(CSS.supports('appearance', 'base-select'),
    'This test requires appearance:base-select in order to run.');

  assert_false(myselect.matches(':open'),
    'select should not match :open while it is closed.');
  await test_driver.click(myselect);

  assert_true(myselect.matches(':open'),
    'select should match :open while it is open.');
}, 'select should support :open pseudo selector.');
</script>

<select id=selectinvalidation>
  <option>one</option>
  <option>two</option>
</select>
<style>
select:not(:open) {
  background-color: red;
}
select:open {
  background-color: green;
}
</style>

<script>
promise_test(async () => {
  assert_true(CSS.supports('appearance', 'base-select'),
    'This test requires appearance:base-select in order to run.');

  const select = document.getElementById('selectinvalidation');
  const option = select.querySelector('option');

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

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

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