OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset="utf-8"> |
| 3 <title>HTML Test: The label element</title> |
| 4 <link rel="author" title="Intel" href="http://www.intel.com/"> |
| 5 <script src="../../../../../../resources/testharness.js"></script> |
| 6 <script src="../../../../../../resources/testharnessreport.js"></script> |
| 7 <div id="log"></div> |
| 8 <form id="fm" style="display:none"> |
| 9 <label id="lbl0" for="test0"></label> |
| 10 <b id="test0"></b> |
| 11 |
| 12 <input id="test1"></input> |
| 13 |
| 14 <label id="lbl1"> |
| 15 <a id="test2"></a> |
| 16 <div><input id="test3"></div> |
| 17 <input id="test4"> |
| 18 </label> |
| 19 |
| 20 <label id="lbl2" for="testx"> |
| 21 <input id="test5"> |
| 22 </label> |
| 23 |
| 24 <label id="lbl3" for="test6"> |
| 25 <b id="test6"></b> |
| 26 <input id="test6" class="class1"> |
| 27 </label> |
| 28 |
| 29 <label id="lbl4" for=""> |
| 30 <input id="" class="class2"> |
| 31 </label> |
| 32 |
| 33 <label id="lbl5" for="test7"></label> |
| 34 <input id="test7"> |
| 35 </form> |
| 36 |
| 37 <label id="lbl6" for="test7"></label> |
| 38 |
| 39 <script> |
| 40 |
| 41 //control attribute |
| 42 test(function () { |
| 43 assert_not_equals(document.getElementById("lbl0").control, document.getEleme
ntById("test0"), |
| 44 "An element that's not a labelable element can't be a labe
l element's labeled control."); |
| 45 assert_equals(document.getElementById("lbl0").control, null, |
| 46 "A label element whose 'for' attribute doesn't reference any l
abelable element shouldn't have any labeled control."); |
| 47 }, "A label element with a 'for' attribute should only be associated with a la
belable element."); |
| 48 |
| 49 test(function () { |
| 50 var label = document.createElement("label"); |
| 51 label.htmlFor = "test1"; |
| 52 assert_not_equals(label.control, document.getElementById("test1"), |
| 53 "A label element not in a document should not label an ele
ment in a document."); |
| 54 document.body.appendChild(label); |
| 55 assert_equals(label.control, document.getElementById("test1")); |
| 56 }, "A label element not in a document can not label any element in the documen
t."); |
| 57 |
| 58 test(function () { |
| 59 assert_equals(document.getElementById("lbl1").control, document.getElementBy
Id("test3"), |
| 60 "The first labelable descendant of a label element should be i
ts labeled control."); |
| 61 |
| 62 var input = document.createElement("input"); |
| 63 document.getElementById("lbl1").insertBefore(input, document.getElementById(
"test2")); |
| 64 assert_equals(document.getElementById("lbl1").control, input, |
| 65 "The first labelable descendant of a label element in tree ord
er should be its labeled control."); |
| 66 }, "The labeled control for a label element that has no 'for' attribute is the
first labelable element which is a descendant of that label element."); |
| 67 |
| 68 test(function () { |
| 69 assert_equals(document.getElementById("lbl2").control, null, |
| 70 "The label's 'control' property should return null if its 'for
' attribute points to an inexistent element."); |
| 71 }, "The 'for' attribute points to an inexistent id."); |
| 72 |
| 73 test(function () { |
| 74 assert_equals(document.getElementById("lbl3").control, null, "The label shou
ld have no control associated."); |
| 75 assert_equals(document.querySelector(".class1").labels.length, 0); |
| 76 }, "A non-control follows by a control with same ID."); |
| 77 |
| 78 test(function () { |
| 79 assert_equals(document.getElementById("lbl4").control, null, |
| 80 "A label element with an empty 'for' attribute should not asso
ciate with anything."); |
| 81 }, "The 'for' attribute is an empty string."); |
| 82 |
| 83 //labels attribute |
| 84 test(function () { |
| 85 var labels = document.getElementById("test7").labels; |
| 86 assert_true(labels instanceof NodeList, |
| 87 "A form control's 'labels' property should be an instance of a N
odeList."); |
| 88 assert_equals(labels.length, 2, |
| 89 "The number of labels associated with a form control should be
the number of label elements for which it is a labeled control."); |
| 90 assert_array_equals(labels, [document.getElementById("lbl5"), document.getEl
ementById("lbl6")], |
| 91 "The labels for a form control should be returned in tre
e order."); |
| 92 |
| 93 var newLabel = document.createElement("label"); |
| 94 newLabel.htmlFor = "test7"; |
| 95 document.getElementById("fm").insertBefore(newLabel, document.getElementById
("lbl0")); |
| 96 assert_array_equals(document.getElementById("test7").labels, [newLabel, docu
ment.getElementById("lbl5"), document.getElementById("lbl6")], |
| 97 "The labels for a form control should be returned in tre
e order."); |
| 98 }, "A form control has multiple labels."); |
| 99 |
| 100 test(function () { |
| 101 var labels = document.getElementById("test4").labels; |
| 102 assert_true(labels instanceof NodeList, "A form control's 'labels' property
should be an instance of a NodeList."); |
| 103 assert_equals(labels.length, 0, "The number of labels should be 0 if the ass
ociated form control isn't referenced by any <label>."); |
| 104 }, "A form control has no label 1."); |
| 105 |
| 106 test(function () { |
| 107 assert_equals(document.getElementById("test5").labels.length, 0, |
| 108 "The number of labels should be 0 if the form control has an a
ncestor label elment that the for attribute points to another control."); |
| 109 assert_equals(document.getElementById("lbl2").control, null, |
| 110 "The labeled cotrol should be associated with the control whos
e ID is equal to the value of the 'for' attribute."); |
| 111 }, "A form control has no label 2."); |
| 112 |
| 113 // form attribute |
| 114 test(function () { |
| 115 assert_equals(document.getElementById("lbl0").form, document.getElementById(
"fm"), |
| 116 "The 'form' property for a label with a form owner should retu
rn the form owner."); |
| 117 }, "A label's form attribute should return its form owner."); |
| 118 |
| 119 test(function () { |
| 120 assert_equals(document.getElementById("lbl6").form, null, |
| 121 "The 'form' property for a label without a form owner should r
eturn null."); |
| 122 }, "Check that the labels property of a form control with no label returns a z
ero-length NodeList."); |
| 123 |
| 124 </script> |
OLD | NEW |