11cb0ef41Sopenharmony_ci<!doctype html>
21cb0ef41Sopenharmony_ci<title>Clicks on input element</title>
31cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script>
41cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script>
51cb0ef41Sopenharmony_ci<div id=dump style=display:none></div>
61cb0ef41Sopenharmony_ci<script>
71cb0ef41Sopenharmony_civar dump = document.getElementById("dump")
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_citest(t => {
101cb0ef41Sopenharmony_ci  const input = document.createElement("input");
111cb0ef41Sopenharmony_ci  input.type = "checkbox";
121cb0ef41Sopenharmony_ci  input.disabled = true;
131cb0ef41Sopenharmony_ci  const label = document.createElement("label");
141cb0ef41Sopenharmony_ci  label.append(input);
151cb0ef41Sopenharmony_ci  dump.append(label);
161cb0ef41Sopenharmony_ci  label.click();
171cb0ef41Sopenharmony_ci  assert_false(input.checked);
181cb0ef41Sopenharmony_ci}, "disabled checkbox should not be checked from label click");
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_citest(t => {
211cb0ef41Sopenharmony_ci  const input = document.createElement("input");
221cb0ef41Sopenharmony_ci  input.type = "radio";
231cb0ef41Sopenharmony_ci  input.disabled = true;
241cb0ef41Sopenharmony_ci  const label = document.createElement("label");
251cb0ef41Sopenharmony_ci  label.append(input);
261cb0ef41Sopenharmony_ci  dump.append(label);
271cb0ef41Sopenharmony_ci  label.click();
281cb0ef41Sopenharmony_ci  assert_false(input.checked);
291cb0ef41Sopenharmony_ci}, "disabled radio should not be checked from label click");
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_citest(t => {
321cb0ef41Sopenharmony_ci  const input = document.createElement("input");
331cb0ef41Sopenharmony_ci  input.type = "checkbox";
341cb0ef41Sopenharmony_ci  input.disabled = true;
351cb0ef41Sopenharmony_ci  const label = document.createElement("label");
361cb0ef41Sopenharmony_ci  label.append(input);
371cb0ef41Sopenharmony_ci  dump.append(label);
381cb0ef41Sopenharmony_ci  label.dispatchEvent(new MouseEvent("click"));
391cb0ef41Sopenharmony_ci  assert_false(input.checked);
401cb0ef41Sopenharmony_ci}, "disabled checkbox should not be checked from label click by dispatchEvent");
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_citest(t => {
431cb0ef41Sopenharmony_ci  const input = document.createElement("input");
441cb0ef41Sopenharmony_ci  input.type = "radio";
451cb0ef41Sopenharmony_ci  input.disabled = true;
461cb0ef41Sopenharmony_ci  const label = document.createElement("label");
471cb0ef41Sopenharmony_ci  label.append(input);
481cb0ef41Sopenharmony_ci  dump.append(label);
491cb0ef41Sopenharmony_ci  label.dispatchEvent(new MouseEvent("click"));
501cb0ef41Sopenharmony_ci  assert_false(input.checked);
511cb0ef41Sopenharmony_ci}, "disabled radio should not be checked from label click by dispatchEvent");
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_citest(t => {
541cb0ef41Sopenharmony_ci  const checkbox = dump.appendChild(document.createElement("input"));
551cb0ef41Sopenharmony_ci  checkbox.type = "checkbox";
561cb0ef41Sopenharmony_ci  checkbox.onclick = ev => {
571cb0ef41Sopenharmony_ci    checkbox.type = "date";
581cb0ef41Sopenharmony_ci    ev.preventDefault();
591cb0ef41Sopenharmony_ci  };
601cb0ef41Sopenharmony_ci  checkbox.dispatchEvent(new MouseEvent("click", { cancelable: true }));
611cb0ef41Sopenharmony_ci  assert_false(checkbox.checked);
621cb0ef41Sopenharmony_ci}, "checkbox morphed into another type should not mutate checked state");
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_citest(t => {
651cb0ef41Sopenharmony_ci  const radio1 = dump.appendChild(document.createElement("input"));
661cb0ef41Sopenharmony_ci  const radio2 = dump.appendChild(radio1.cloneNode());
671cb0ef41Sopenharmony_ci  radio1.type = radio2.type = "radio";
681cb0ef41Sopenharmony_ci  radio1.name = radio2.name = "foo";
691cb0ef41Sopenharmony_ci  radio2.checked = true;
701cb0ef41Sopenharmony_ci  radio1.onclick = ev => {
711cb0ef41Sopenharmony_ci    radio1.type = "date";
721cb0ef41Sopenharmony_ci    ev.preventDefault();
731cb0ef41Sopenharmony_ci  };
741cb0ef41Sopenharmony_ci  radio1.dispatchEvent(new MouseEvent("click", { cancelable: true }));
751cb0ef41Sopenharmony_ci  assert_false(radio1.checked);
761cb0ef41Sopenharmony_ci  assert_true(radio2.checked);
771cb0ef41Sopenharmony_ci}, "radio morphed into another type should not steal the existing checked state");
781cb0ef41Sopenharmony_ci</script>
79