test_label_input_controls.html (2738B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=597650 5 --> 6 <head> 7 <title>Test for Bug 597650</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=597650">Mozilla Bug 597650</a> 13 <p id="display"></p> 14 <div id="content"> 15 <label id="l"> 16 <input id="h"></input> 17 <input type="text" id="i"></input> 18 </label> 19 <label id="lh" for="h"></label> 20 </div> 21 <pre id="test"> 22 <script class="testbody" type="text/javascript"> 23 /** Test for Bug 597650 */ 24 label = document.getElementById("l"); 25 labelForH = document.getElementById("lh"); 26 inputI = document.getElementById("i"); 27 inputH = document.getElementById("h"); 28 29 var labelableTypes = ["text", "search", "tel", "url", "email", "password", 30 "datetime", "date", "month", "week", "time", 31 "number", "range", "color", "checkbox", "radio", 32 "file", "submit", "image", "reset", "button"]; 33 var nonLabelableTypes = ["hidden"]; 34 35 for (var i in labelableTypes) { 36 test(labelableTypes[i], true); 37 } 38 39 for (var i in nonLabelableTypes) { 40 test(nonLabelableTypes[i], false); 41 } 42 43 function test(type, isLabelable) { 44 inputH.type = type; 45 if (isLabelable) { 46 testControl(label, inputH, type, true); 47 testControl(labelForH, inputH, type, true); 48 } else { 49 testControl(label, inputI, type, false); 50 testControl(labelForH, null, type, false); 51 52 inputH.type = "text"; 53 testControl(label, inputH, "text", true); 54 testControl(labelForH, inputH, "text", true); 55 56 inputH.type = type; 57 testControl(label, inputI, type, false); 58 testControl(labelForH, null, type, false); 59 60 label.removeChild(inputH); 61 testControl(label, inputI, "text", true); 62 63 var element = document.createElement('input'); 64 element.type = type; 65 label.insertBefore(element, inputI); 66 testControl(label, inputI, "text", true); 67 } 68 } 69 70 function testControl(label, control, type, labelable) { 71 if (labelable) { 72 is(label.control, control, "Input controls of type " + type 73 + " should be labeled"); 74 } else { 75 is(label.control, control, "Input controls of type " + type 76 + " should be ignored by <label>"); 77 } 78 } 79 </script> 80 </pre> 81 </body> 82 </html>