tor-browser

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

input-checkbox-switch.tentative.window.js (2518B)


      1 test(t => {
      2  const input = document.body.appendChild(document.createElement("input"));
      3  t.add_cleanup(() => input.remove());
      4  input.type = "checkbox";
      5  input.switch = true;
      6  input.indeterminate = true;
      7 
      8  assert_false(input.matches(":indeterminate"));
      9 }, "Switch control does not match :indeterminate");
     10 
     11 test(t => {
     12  const input = document.body.appendChild(document.createElement("input"));
     13  t.add_cleanup(() => input.remove());
     14  input.type = "checkbox";
     15  input.switch = true;
     16  input.indeterminate = true;
     17 
     18  assert_false(input.matches(":indeterminate"));
     19 
     20  input.switch = false;
     21  assert_true(input.matches(":indeterminate"));
     22 }, "Checkbox that is no longer a switch control does match :indeterminate");
     23 
     24 test(t => {
     25  const input = document.body.appendChild(document.createElement("input"));
     26  t.add_cleanup(() => input.remove());
     27  input.type = "checkbox";
     28  input.indeterminate = true;
     29 
     30  assert_true(input.matches(":indeterminate"));
     31 
     32  input.setAttribute("switch", "blah");
     33  assert_false(input.matches(":indeterminate"));
     34 }, "Checkbox that becomes a switch control does not match :indeterminate");
     35 
     36 test(t => {
     37  const input = document.body.appendChild(document.createElement("input"));
     38  t.add_cleanup(() => input.remove());
     39  input.type = "checkbox";
     40  input.indeterminate = true;
     41 
     42  assert_true(document.body.matches(":has(:indeterminate)"));
     43 
     44  input.switch = true;
     45  assert_false(document.body.matches(":has(:indeterminate)"));
     46 }, "Parent of a checkbox that becomes a switch control does not match :has(:indeterminate)");
     47 
     48 test(t => {
     49  const input = document.body.appendChild(document.createElement("input"));
     50  t.add_cleanup(() => input.remove());
     51  input.type = "checkbox";
     52  input.switch = true
     53  input.checked = true;
     54 
     55  assert_true(document.body.matches(":has(:checked)"));
     56 
     57  input.switch = false;
     58  assert_true(document.body.matches(":has(:checked)"));
     59 
     60  input.checked = false;
     61  assert_false(document.body.matches(":has(:checked)"));
     62 }, "Parent of a switch control that becomes a checkbox continues to match :has(:checked)");
     63 
     64 test(t => {
     65  const input = document.body.appendChild(document.createElement("input"));
     66  t.add_cleanup(() => input.remove());
     67  input.type = "checkbox";
     68  input.switch = true;
     69  input.indeterminate = true;
     70  assert_false(input.matches(":indeterminate"));
     71  input.type = "text";
     72  input.removeAttribute("switch");
     73  input.type = "checkbox";
     74  assert_true(input.matches(":indeterminate"));
     75 }, "A switch control that becomes a checkbox in a roundabout way");