summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_label_input_controls.html
blob: fe9410b608fae1acc4467488690794101baa0c08 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=597650
-->
<head>
  <title>Test for Bug 597650</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=597650">Mozilla Bug 597650</a>
  <p id="display"></p>
  <div id="content">
    <label id="l">
      <input id="h"></input>
      <input type="text" id="i"></input>
    </label>
    <label id="lh" for="h"></label>
  </div>
  <pre id="test">
    <script class="testbody" type="text/javascript">
    /** Test for Bug 597650 **/
      label = document.getElementById("l");
      labelForH = document.getElementById("lh");
      inputI = document.getElementById("i");
      inputH = document.getElementById("h");

      var labelableTypes = ["text", "search", "tel", "url", "email", "password",
                            "datetime", "date", "month", "week", "time",
                            "number", "range", "color", "checkbox", "radio",
                            "file", "submit", "image", "reset", "button"];
      var nonLabelableTypes = ["hidden"];

      for (var i in labelableTypes) {
        test(labelableTypes[i], true);
      }

      for (var i in nonLabelableTypes) {
        test(nonLabelableTypes[i], false);
      }

      function test(type, isLabelable) {
        inputH.type = type;
        if (isLabelable) {
          testControl(label,     inputH, type, true);
          testControl(labelForH, inputH, type, true);
        } else {
          testControl(label,     inputI, type, false);
          testControl(labelForH, null,   type, false);

          inputH.type = "text";
          testControl(label,     inputH, "text", true);
          testControl(labelForH, inputH, "text", true);

          inputH.type = type;
          testControl(label,     inputI, type, false);
          testControl(labelForH, null,   type, false);

          label.removeChild(inputH);
          testControl(label, inputI, "text", true);

          var element = document.createElement('input');
          element.type = type;
          label.insertBefore(element, inputI);
          testControl(label, inputI, "text", true);
        }
      }

      function testControl(label, control, type, labelable) {
        if (labelable) {
          is(label.control, control, "Input controls of type " + type
                                   + " should be labeled");
        } else {
          is(label.control, control, "Input controls of type " + type
                                  + " should be ignored by <label>");
        }
      }
    </script>
  </pre>
  </body>
</html>