tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

show-picker-disabled-readonly.html (1983B)


      1 <!DOCTYPE html>
      2 <meta name=timeout content=long>
      3 <title>Test showPicker() disabled/readonly requirement</title>
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <script src="/resources/testdriver.js"></script>
      7 <script src="/resources/testdriver-vendor.js"></script>
      8 <body></body>
      9 <script type=module>
     10 import inputTypes from "./input-types.js";
     11 
     12 for (const inputType of inputTypes) {
     13  test(() => {
     14    const input = document.createElement("input");
     15    input.setAttribute("type", inputType);
     16    input.setAttribute("disabled", "");
     17 
     18    assert_throws_dom('InvalidStateError', () => { input.showPicker(); });
     19  }, `input[type=${inputType}] showPicker() throws when disabled`);
     20 }
     21 
     22 const noReadonlySupport = ['button', 'checkbox', 'color', 'file',
     23 'hidden', 'image', 'radio', 'range', 'reset', 'submit'];
     24 for (const inputType of inputTypes) {
     25  if (!noReadonlySupport.includes(inputType)) {
     26    promise_test(async () => {
     27      const input = document.createElement("input");
     28      input.setAttribute("type", inputType);
     29      input.setAttribute("readonly", "");
     30 
     31      await test_driver.bless('show picker');
     32      assert_throws_dom('InvalidStateError', () => { input.showPicker(); });
     33 
     34      assert_true(navigator.userActivation.isActive, 'User activation is not consumed for readonly showPicker() call');
     35    }, `input[type=${inputType}] showPicker() throws when readonly`);
     36  } else {
     37    promise_test(async () => {
     38      const input = document.createElement("input");
     39      input.setAttribute("type", inputType);
     40      input.setAttribute("readonly", "");
     41      document.body.appendChild(input);
     42 
     43      await test_driver.bless('show picker');
     44      input.showPicker();
     45      input.blur();
     46      input.remove();
     47 
     48      assert_false(navigator.userActivation.isActive, 'User activation is consumed for non-readonly showPicker() call');
     49    }, `input[type=${inputType}] showPicker() doesn't throw when readonly`);
     50  }
     51 }
     52 </script>