summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/constraints/radio-valueMissing.html
blob: a02b6b96454f28c7ebd6ebfbedd604b67e8b1d77 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html>
<head>
  <title>valueMissing property on the input[type=radio] element</title>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type">
  <meta content="valueMissing property on the input[type=radio] element" name="description">
  <link href="https://html.spec.whatwg.org/multipage/#dom-validitystate-valuemissing" rel="help">
  <link href="https://html.spec.whatwg.org/multipage/#radio-button-state-(type%3Dradio)%3Asuffering-from-being-missing" rel="help">
  <script src="/resources/testharness.js"></script>
  <script src="/resources/testharnessreport.js"></script>
</head>
<body>
  <div id="log"></div>

  <form style="display: none">
    <input type="radio" name="group1" id="radio1">
    <input type="radio" name="group1" id="radio2">

    <input type="radio" name="group2" required id="radio3">
    <input type="radio" name="group2" id="radio4">

    <input type="radio" name="group3" required checked id="radio5">
    <input type="radio" name="group3" id="radio6">

    <input type="radio" name="group4" required id="radio7">
    <input type="radio" name="group4" checked id="radio8">
    <input type="radio" name="group4" id="radio9">

    <input type="radio" name="group5" required disabled id="radio10">
    <input type="radio" name="group5" id="radio11">

    <input type="radio" name="group6" required checked disabled id="radio12">
    <input type="radio" name="group6" id="radio13">
  </form>

  <script type="text/javascript">
    var cases = [
      {
        name: "The required attribute is not set",
        group: ["radio1", "radio2"],
        expected: false
      },
      {
        name: "One of the radios is required, but none checked",
        group: ["radio3", "radio4"],
        expected: true
      },
      {
        name: "One of the radios is required and checked",
        group: ["radio5", "radio6"],
        expected: false
      },
      {
        name: "One of the radios is required and another one is checked",
        group: ["radio7", "radio8", "radio9"],
        expected: false
      },
      {
        name: "One of the radios is required and disabled, but none checked",
        group: ["radio10", "radio11"],
        expected: true
      },
      {
        name: "One of the radios is required, checked and disabled",
        group: ["radio12", "radio13"],
        expected: false
      }
    ];

    for (var info of cases) {
      test(function () {
        for (var id of info.group) {
          var radio = document.getElementById(id);

          assert_class_string(radio.validity, "ValidityState",
            "HTMLInputElement.validity must be a ValidityState instance");

          if (info.expected) {
            assert_true(radio.validity.valueMissing,
              "The " + id + ".validity.valueMissing should be true");
          } else {
            assert_false(radio.validity.valueMissing,
              "The " + id + ".validity.valueMissing should be false");
          }
        }
      }, info.name);
    }
  </script>
</body>
</html>