summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/the-input-element/input-type-change-value.html
blob: 74aeef7cd514c4994e60495cc1247fe8c7c5333f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!doctype html>
<meta charset="utf-8">
<title>Input type switch from / to color</title>
<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
<link rel="author" href="https://mozilla.org" title="Mozilla">
<link rel="help" href="https://html.spec.whatwg.org/#input-type-change">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1833477">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
function runTest(focus) {
  let input = document.createElement("input");
  input.type = "color";
  document.body.appendChild(input);
  if (focus) {
    input.focus();
  }
  assert_equals(input.value, "#000000", "Invalid color should return a non-empty sanitized value");
  input.type = "text";
  assert_equals(input.value, "", "Value dirty flag should remain false");
  input.type = "color";
  input.value = "#ffffff";
  assert_equals(input.value, "#ffffff", "Valid color is returned");
  input.type = "text";
  assert_equals(input.value, "#ffffff", "Value dirty flag should remain true");
  if (focus) {
    assert_equals(document.activeElement, input, "Focus is preserved");
  }
}
test(() => runTest(false), "Without focus");
test(() => runTest(true), "With focus");
</script>