test_label_control_attribute.html (3868B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=562932 5 --> 6 <head> 7 <title>Test for Bug 562932</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=562932">Mozilla Bug 562932</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 <!-- No @for, we have to check the content --> 16 <label id='l1'><input id='i1'></label> 17 <label id='l2'><input id='i2'><input></label> 18 <label id='l3'></label> 19 <label id='l4a'><fieldset id='f'>foo</fieldset></label> 20 <label id='l4b'><label id='l4c'><input id='i3'></label></label> 21 <label id='l4d'><label id='l4e'><input id='i3b'></label><input></label> 22 23 <!-- With @for, we do no check the content --> 24 <label id='l5' for='i1'></label> 25 <label id='l6' for='i4'></label> 26 <label id='l7' for='i4'><input></label> 27 <label id='l8' for='i1 i2'></label> 28 <label id='l9' for='i1 i2'><input></label> 29 <label id='l10' for='f'></label> 30 <label id='l11' for='i4'></label> 31 <label id='l12' for='i5'></label> 32 <label id='l13' for=''><input></label> 33 <!-- <label id='l14'> is created in script --> 34 </div> 35 <pre id="test"> 36 <script type="application/javascript"> 37 38 /** Test for Bug 562932 */ 39 40 function checkControl(aLabelId, aElementId, aMsg) 41 { 42 var element = null; 43 44 if (aElementId != null) { 45 element = document.getElementById(aElementId); 46 } 47 48 is(document.getElementById(aLabelId).control, element, aMsg); 49 } 50 51 ok('control' in document.createElement('label'), 52 "label element should have a control IDL attribute"); 53 54 checkControl('l1', 'i1', "label control should be the first form element"); 55 checkControl('l2', 'i2', "label control should be the first form element"); 56 checkControl('l3', null, "label control should be null when there is no child"); 57 checkControl('l4a', null, "label control should be null when there is no \ 58 labelable form element child"); 59 checkControl('l4b', 'i3', "label control should be the first labelable element \ 60 in tree order"); 61 checkControl('l4c', 'i3', "label control should be the first labelable element \ 62 in tree order"); 63 checkControl('l4d', 'i3b', "label control should be the first labelable element \ 64 in tree order"); 65 checkControl('l4e', 'i3b', "label control should be the first labelable element \ 66 in tree order"); 67 checkControl('l5', 'i1', "label control should be the id in @for"); 68 checkControl('l6', null, 69 "label control should be null if the id in @for is not valid"); 70 checkControl('l7', null, 71 "label control should be null if the id in @for is not valid"); 72 checkControl('l8', null, 73 "label control should be null if there are more than one id in @for"); 74 checkControl('l9', null, 75 "label control should be null if there are more than one id in @for"); 76 checkControl('l10', null, "label control should be null if the id in @for \ 77 is not an id from a labelable form element"); 78 79 var inputOutOfDocument = document.createElement('input'); 80 inputOutOfDocument.id = 'i4'; 81 checkControl('l11', null, "label control should be null if the id in @for \ 82 is not an id from an element in the document"); 83 84 var inputInDocument = document.createElement('input'); 85 inputInDocument.id = 'i5'; 86 document.getElementById('content').appendChild(inputInDocument); 87 checkControl('l12', 'i5', "label control should be the id in @for"); 88 89 checkControl('l13', null, "label control should be null if the id in @for \ 90 is empty"); 91 92 var labelOutOfDocument = document.createElement('label'); 93 labelOutOfDocument.htmlFor = 'i1'; 94 is(labelOutOfDocument.control, null, "out of document label shouldn't \ 95 labelize a form control"); 96 97 </script> 98 </pre> 99 </body> 100 </html>