<!DOCTYPE html>
<title>Test showPicker() disabled/readonly requirement</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<body></body>
<script type=module>
import inputTypes from "./input-types.js";

for (const inputType of inputTypes) {
  test(() => {
    const input = document.createElement("input");
    input.setAttribute("type", inputType);
    input.setAttribute("disabled", "");

    assert_throws_dom('InvalidStateError', () => { input.showPicker(); });
  }, `input[type=${inputType}] showPicker() throws when disabled`);
}

const noReadonlySupport = ['button', 'checkbox', 'color', 'file',
'hidden', 'image', 'radio', 'range', 'reset', 'submit'];
for (const inputType of inputTypes) {
  if (!noReadonlySupport.includes(inputType)) {
    test(() => {
      const input = document.createElement("input");
      input.setAttribute("type", inputType);
      input.setAttribute("readonly", "");

      assert_throws_dom('InvalidStateError', () => { input.showPicker(); });
    }, `input[type=${inputType}] showPicker() throws when readonly`);
  } else {
    test(() => {
      const input = document.createElement("input");
      input.setAttribute("type", inputType);
      input.setAttribute("readonly", "");

      // Missing user gesture activation throws.
      assert_throws_dom('NotAllowedError', () => { input.showPicker(); });
    }, `input[type=${inputType}] showPicker() doesn't throw when readonly`);
  }
}
</script>
