summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/the-input-element/input-type-checkbox.html
blob: 7dd2f26b12c459405b8e6c59563f09cc1ec15c0c (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE HTML>
<head>
<title>input type checkbox</title>
<link rel="author" title="Gary Gao" href="mailto:angrytoast@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#checkbox-state-(type=checkbox)">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div style="display:none;">
  <input id="checkbox_default" type="checkbox" width="20" />

  <input id="checkbox_checked" type="checkbox" checked />

  <input id="checkbox_indeterminate" type="checkbox" />

  <input id="checkbox_default_value" type="checkbox" />
</div>

<div id="log"></div>

<script>
  var checkbox_default = document.getElementById('checkbox_default'),
      checkbox_checked = document.getElementById('checkbox_checked'),
      checkbox_indeterminate = document.getElementById('checkbox_indeterminate'),
      checkbox_default_value = document.getElementById('checkbox_default_value');

  test(function() {
    assert_false(checkbox_default.checked);
  }, "default checkbox has no checkedness state");

  test(function() {
    assert_true(checkbox_checked.checked);
  }, "checkbox with initial state set to checked has checkedness state");

  test(function() {
    checkbox_default.checked = 'chicken'
    assert_true(checkbox_default.checked);
  }, "changing the checked attribute to a string sets the checkedness state");

  test(function() {
    assert_false(checkbox_indeterminate.indeterminate);
  }, "a checkbox has an indeterminate state set to false onload");

  test(function() {
    checkbox_indeterminate.indeterminate = true,
    assert_true(checkbox_indeterminate.indeterminate);
  }, "on setting, a checkbox's indeterminate state must be set to the new value and returns the last value it was set to");

  test(function() {
    assert_equals(checkbox_default_value.value, 'on');
  }, "default/on: on getting, if the element has a value attribute, it must return that attribute's value; otherwise, it must return the string 'on'");

  test(function() {
    checkbox_default_value.value = 'chicken'
    assert_equals(checkbox_default_value.value, 'chicken');
  }, "on getting, if the element has a value attribute, it must return that attribute's value");
</script>

</body>