| <!DOCTYPE HTML> |
| <script src="../../resources/js-test.js"></script> |
| <script> |
| description('Tests for writing and reading .type property of HTMLInputElement.'); |
| |
| var input = document.createElement('input'); |
| |
| // The default type is "text". |
| shouldBe('input.type', '"text"'); |
| shouldBeNull("input.getAttribute('type')"); |
| |
| function check(value, expected, expectedAttributeValue) |
| { |
| input.type = value; |
| if (input.type === expected) |
| testPassed('input.type for "' + value + '" is correctly "' + input.type + '".'); |
| else |
| testFailed('input.type for "' + value + '" is incorrectly "' + input.type + '", should be "' + expected + '".'); |
| |
| if (typeof expectedAttributeValue === "undefined") |
| expectedAttributeValue = expected; |
| |
| if (input.getAttribute('type') === expectedAttributeValue) |
| testPassed('input.getAttribute("type") for "' + value + '" is correctly "' + expectedAttributeValue + '".'); |
| else |
| testFailed('input.getAttribute("type") for "' + value + '" is incorrectly "' + input.getAttribute('type') + '", should be "' + expectedAttributeValue + '".'); |
| } |
| |
| check("text", "text"); |
| check("TEXT", "text", "TEXT"); // input.type must return a lower case value according to DOM Level 2. |
| check(" text ", "text", " text "); |
| check("button", "button"); |
| check(" button ", "text", " button "); |
| check("checkbox", "checkbox"); |
| check("email", "email"); |
| check("file", "file"); |
| check("hidden", "hidden"); |
| check("image", "image"); |
| check("isindex", "text", "isindex"); |
| check("number", "number"); |
| check("password", "password"); |
| check("passwd", "text", "passwd"); |
| check("radio", "radio"); |
| check("range", "range"); |
| check("reset", "reset"); |
| check("search", "search"); |
| check("submit", "submit"); |
| check("tel", "tel"); |
| check("telephone", "text", "telephone"); |
| check("url", "url"); |
| check("uri", "text", "uri"); |
| |
| // Empty and unknown value handling. |
| check("", "text", ""); |
| check("x-unknown", "text", "x-unknown"); |
| shouldBeNull("input.removeAttribute('type'); input.getAttribute('type')"); |
| </script> |