2 <script src="../../resources/js-test.js"></script>
4 description('Tests for writing and reading .type property of HTMLInputElement.');
6 var input = document.createElement('input');
8 // The default type is "text".
9 shouldBe('input.type', '"text"');
10 shouldBeNull("input.getAttribute('type')");
12 function check(value, expected, expectedAttributeValue)
15 if (input.type === expected)
16 testPassed('input.type for "' + value + '" is correctly "' + input.type + '".');
18 testFailed('input.type for "' + value + '" is incorrectly "' + input.type + '", should be "' + expected + '".');
20 if (typeof expectedAttributeValue === "undefined")
21 expectedAttributeValue = expected;
23 if (input.getAttribute('type') === expectedAttributeValue)
24 testPassed('input.getAttribute("type") for "' + value + '" is correctly "' + expectedAttributeValue + '".');
26 testFailed('input.getAttribute("type") for "' + value + '" is incorrectly "' + input.getAttribute('type') + '", should be "' + expectedAttributeValue + '".');
29 check("text", "text");
30 check("TEXT", "text", "TEXT"); // input.type must return a lower case value according to DOM Level 2.
31 check(" text ", "text", " text ");
32 check("button", "button");
33 check(" button ", "text", " button ");
34 check("checkbox", "checkbox");
35 check("email", "email");
36 check("file", "file");
37 check("hidden", "hidden");
38 check("image", "image");
39 check("isindex", "text", "isindex");
40 check("number", "number");
41 check("password", "password");
42 check("passwd", "text", "passwd");
43 check("radio", "radio");
44 check("range", "range");
45 check("reset", "reset");
46 check("search", "search");
47 check("submit", "submit");
49 check("telephone", "text", "telephone");
51 check("uri", "text", "uri");
53 // Empty and unknown value handling.
54 check("", "text", "");
55 check("x-unknown", "text", "x-unknown");
56 shouldBeNull("input.removeAttribute('type'); input.getAttribute('type')");