OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <meta charset="utf-8"> | 2 <meta charset="utf-8"> |
3 <title>HTML Test: labelable elements</title> | 3 <title>HTML Test: labelable elements</title> |
4 <link rel="author" title="Intel" href="http://www.intel.com/"> | 4 <link rel="author" title="Intel" href="http://www.intel.com/"> |
5 <script src="/resources/testharness.js"></script> | 5 <script src="/resources/testharness.js"></script> |
6 <script src="/resources/testharnessreport.js"></script> | 6 <script src="/resources/testharnessreport.js"></script> |
7 <div id="log"></div> | 7 <div id="log"></div> |
8 <form style="display:none"> | 8 <form style="display:none"> |
9 <output id="testoutput"></output> | 9 <output id="testoutput"></output> |
10 <label id="lbl0" for="testoutput"></label> | 10 <label id="lbl0" for="testoutput"></label> |
(...skipping 18 matching lines...) Expand all Loading... |
29 <label id="lbl9" for="testfieldset"></label> | 29 <label id="lbl9" for="testfieldset"></label> |
30 <label id="testlabel"></label> | 30 <label id="testlabel"></label> |
31 <label id="lbl10" for="testlabel"></label> | 31 <label id="lbl10" for="testlabel"></label> |
32 <object id="testobject"></object> | 32 <object id="testobject"></object> |
33 <label id="lbl11" for="testobject"></label> | 33 <label id="lbl11" for="testobject"></label> |
34 <img id="testimg"> | 34 <img id="testimg"> |
35 <label id="lbl12" for="testimg"></label> | 35 <label id="lbl12" for="testimg"></label> |
36 </form> | 36 </form> |
37 | 37 |
38 <script> | 38 <script> |
39 function testLabelsAttr(formElementId, labelElementId, hasLabels) { | 39 function testLabelsAttr(formElementId, labelElementId) { |
40 var elem = document.getElementById(formElementId); | 40 var elem = document.getElementById(formElementId); |
41 if (labelElementId) { | 41 if (labelElementId) { |
42 assert_equals(elem.labels.length, 1); | 42 assert_equals(elem.labels.length, 1); |
43 assert_equals(elem.labels[0].id, labelElementId); | 43 assert_equals(elem.labels[0].id, labelElementId); |
44 } else { | 44 } else { |
45 assert_equals(elem.labels.length, 0); | 45 assert_equals(elem.labels.length, 0); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 test(function() { | 49 test(function() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 test(function() { | 85 test(function() { |
86 testLabelsAttr("testButton", "lbl4"); | 86 testLabelsAttr("testButton", "lbl4"); |
87 }, "Check if the button element can access 'labels'"); | 87 }, "Check if the button element can access 'labels'"); |
88 | 88 |
89 test(function() { | 89 test(function() { |
90 assert_equals(document.getElementById("lbl5").control, null, "An input element
in hidden state should not be labelable."); | 90 assert_equals(document.getElementById("lbl5").control, null, "An input element
in hidden state should not be labelable."); |
91 }, "Check if the hidden input element is not a labelable element."); | 91 }, "Check if the hidden input element is not a labelable element."); |
92 | 92 |
93 test(function() { | 93 test(function() { |
94 testLabelsAttr("testHidden", null); | 94 var hiddenInput = document.getElementById("testHidden"); |
95 }, "Check if the hidden input element can access 'labels'"); | 95 assert_equals(hiddenInput.labels, null, "input[type=hidden] must have null .la
bels"); |
| 96 |
| 97 this.add_cleanup(function () { |
| 98 hiddenInput.type = "hidden"; |
| 99 }); |
| 100 |
| 101 hiddenInput.type = "text"; |
| 102 testLabelsAttr("testHidden", "lbl5"); |
| 103 var labels = hiddenInput.labels; |
| 104 |
| 105 hiddenInput.type = "hidden"; |
| 106 assert_equals(labels.length, 0, "Retained .labels NodeList should be empty aft
er input type changed to hidden"); |
| 107 |
| 108 hiddenInput.type = "checkbox"; |
| 109 assert_true(labels === hiddenInput.labels, ".labels property must return the [
SameObject] after input type is toggled back from 'hidden'"); |
| 110 assert_equals(hiddenInput.labels.length, 1, ".labels NodeList should contain t
he input after the input type is changed from 'hidden' to 'checkbox'"); |
| 111 }, "Check if the hidden input element has null 'labels'"); |
96 | 112 |
97 test(function() { | 113 test(function() { |
98 assert_equals(document.getElementById("lbl6").control.id, "testRadio", "An inp
ut element in radio state should be labelable."); | 114 assert_equals(document.getElementById("lbl6").control.id, "testRadio", "An inp
ut element in radio state should be labelable."); |
99 }, "Check if the input element in radio state is a labelable element"); | 115 }, "Check if the input element in radio state is a labelable element"); |
100 | 116 |
101 test(function() { | 117 test(function() { |
102 testLabelsAttr("testRadio", "lbl6"); | 118 testLabelsAttr("testRadio", "lbl6"); |
103 }, "Check if the input element in radio state can access 'labels'"); | 119 }, "Check if the input element in radio state can access 'labels'"); |
104 | 120 |
105 test(function() { | 121 test(function() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 164 |
149 test(function() { | 165 test(function() { |
150 assert_not_equals(document.getElementById("lbl9").control, document.getElement
ById("testimg")); | 166 assert_not_equals(document.getElementById("lbl9").control, document.getElement
ById("testimg")); |
151 assert_equals(document.getElementById("lbl12").control, null, "An img element
should not be labelable."); | 167 assert_equals(document.getElementById("lbl12").control, null, "An img element
should not be labelable."); |
152 }, "Check if the img element is not a labelable element"); | 168 }, "Check if the img element is not a labelable element"); |
153 | 169 |
154 test(function() { | 170 test(function() { |
155 assert_equals(document.getElementById("lbl9").labels, undefined); | 171 assert_equals(document.getElementById("lbl9").labels, undefined); |
156 }, "Check if the img element can access 'labels'"); | 172 }, "Check if the img element can access 'labels'"); |
157 </script> | 173 </script> |
OLD | NEW |