test_mozistextfield.html (2740B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=565538 5 --> 6 <head> 7 <title>Test for Bug 565538</title> 8 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=565538">Mozilla Bug 565538</a> 13 <p id="display"></p> 14 <pre id="test"> 15 <script type="application/javascript"> 16 17 /** Test for Bug 565538 */ 18 19 var gElementTestData = [ 20 /* element result */ 21 ['input', true], 22 ['button', false], 23 ['fieldset', false], 24 ['label', false], 25 ['option', false], 26 ['optgroup', false], 27 ['output', false], 28 ['legend', false], 29 ['select', false], 30 ['textarea', false], 31 ['object', false], 32 ]; 33 34 var gInputTestData = [ 35 /* type result */ 36 ['password', true], 37 ['tel', true], 38 ['text', true], 39 ['button', false], 40 ['checkbox', false], 41 ['file', false], 42 ['hidden', false], 43 ['reset', false], 44 ['image', false], 45 ['radio', false], 46 ['submit', false], 47 ['search', true], 48 ['email', true], 49 ['url', true], 50 ['number', false], 51 ['range', false], 52 ['date', false], 53 ['time', false], 54 ['color', false], 55 ['month', false], 56 ['week', false], 57 ['datetime-local', false], 58 ]; 59 60 function checkMozIsTextFieldDefined(aElement, aResult) 61 { 62 var element = document.createElement(aElement); 63 64 var msg = "mozIsTextField should be " 65 if (aResult) { 66 msg += "defined"; 67 } else { 68 msg += "undefined"; 69 } 70 71 is('mozIsTextField' in element, aResult, msg); 72 } 73 74 function checkMozIsTextFieldValue(aInput, aResult) 75 { 76 is(aInput.mozIsTextField(false), aResult, 77 "mozIsTextField(false) should return " + aResult); 78 79 if (aInput.type == 'password') { 80 ok(!aInput.mozIsTextField(true), 81 "mozIsTextField(true) should return false for password"); 82 } else { 83 is(aInput.mozIsTextField(true), aResult, 84 "mozIsTextField(true) should return " + aResult); 85 } 86 } 87 88 function checkMozIsTextFieldValueTodo(aInput, aResult) 89 { 90 todo_is(aInput.mozIsTextField(false), aResult, 91 "mozIsTextField(false) should return " + aResult); 92 todo_is(aInput.mozIsTextField(true), aResult, 93 "mozIsTextField(true) should return " + aResult); 94 } 95 96 // Check if the method is defined for the correct elements. 97 for (data of gElementTestData) { 98 checkMozIsTextFieldDefined(data[0], data[1]); 99 } 100 101 // Check if the method returns the correct value. 102 var input = document.createElement('input'); 103 for (data of gInputTestData) { 104 input.type = data[0]; 105 checkMozIsTextFieldValue(input, data[1]); 106 } 107 108 </script> 109 </pre> 110 </body> 111 </html>