OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Text input element</title> |
| 5 <link rel="author" title="Kinuko Yasuda" href="mailto:kinuko@chromium.org"> |
| 6 <link rel="help" href="https://html.spec.whatwg.org/multipage/#text-(type=te
xt)-state-and-search-state-(type=search)"> |
| 7 <script src="../../../../../../resources/testharness.js"></script> |
| 8 <script src="../../../../../../resources/testharnessreport.js"></script> |
| 9 </head> |
| 10 |
| 11 <body> |
| 12 <h1>Text input element</h1> |
| 13 <div style="display: none"> |
| 14 |
| 15 <input id="text" type="text" /> |
| 16 <input id="text_with_value" type="text" value="foo" /> |
| 17 |
| 18 <input id="search" type="search" /> |
| 19 <input id="search_with_value" type="search" value="foo" /> |
| 20 |
| 21 </div> |
| 22 <div id="log"></div> |
| 23 <script type="text/javascript"> |
| 24 var types = [ 'text', 'search' ]; |
| 25 |
| 26 for (var i = 0; i < types.length; ++i) { |
| 27 test( |
| 28 function() { |
| 29 assert_equals(document.getElementById(types[i]).value, ""); |
| 30 assert_equals(document.getElementById(types[i] + "_with_value").value,
"foo"); |
| 31 }, "Value returns the current value for " + types[i]); |
| 32 |
| 33 test( |
| 34 function() { |
| 35 document.getElementById(types[i]).value = "A"; |
| 36 assert_equals(document.getElementById(types[i]).value, "A"); |
| 37 document.getElementById(types[i]).value = "B"; |
| 38 }, "Setting value changes the current value for " + types[i]); |
| 39 |
| 40 test( |
| 41 function() { |
| 42 // Any LF (\n) must be stripped. |
| 43 document.getElementById(types[i]).value = "\nAB"; |
| 44 assert_equals(document.getElementById(types[i]).value, "AB"); |
| 45 document.getElementById(types[i]).value = "A\nB"; |
| 46 assert_equals(document.getElementById(types[i]).value, "AB"); |
| 47 document.getElementById(types[i]).value = "AB\n"; |
| 48 assert_equals(document.getElementById(types[i]).value, "AB"); |
| 49 |
| 50 // Any CR (\r) must be stripped. |
| 51 document.getElementById(types[i]).value = "\rAB"; |
| 52 assert_equals(document.getElementById(types[i]).value, "AB"); |
| 53 document.getElementById(types[i]).value = "A\rB"; |
| 54 assert_equals(document.getElementById(types[i]).value, "AB"); |
| 55 document.getElementById(types[i]).value = "AB\r"; |
| 56 assert_equals(document.getElementById(types[i]).value, "AB"); |
| 57 |
| 58 // Any combinations of LF CR must be stripped. |
| 59 document.getElementById(types[i]).value = "\r\nAB"; |
| 60 assert_equals(document.getElementById(types[i]).value, "AB"); |
| 61 document.getElementById(types[i]).value = "A\r\nB"; |
| 62 assert_equals(document.getElementById(types[i]).value, "AB"); |
| 63 document.getElementById(types[i]).value = "AB\r\n"; |
| 64 assert_equals(document.getElementById(types[i]).value, "AB"); |
| 65 document.getElementById(types[i]).value = "\r\nA\n\rB\r\n"; |
| 66 assert_equals(document.getElementById(types[i]).value, "AB"); |
| 67 }, "Value sanitization algorithm should strip line breaks for " + types[i]
); |
| 68 |
| 69 test( |
| 70 function() { |
| 71 assert_equals(document.getElementById(types[i]).files, null); |
| 72 }, "files attribute must return null for " + types[i]); |
| 73 |
| 74 test( |
| 75 function() { |
| 76 assert_equals(document.getElementById(types[i]).valueAsDate, null); |
| 77 }, "valueAsDate attribute must return null for " + types[i]); |
| 78 |
| 79 test( |
| 80 function() { |
| 81 assert_equals(document.getElementById(types[i]).valueAsNumber, NaN); |
| 82 }, "valueAsNumber attribute must return NaN for " + types[i]); |
| 83 |
| 84 test( |
| 85 function() { |
| 86 assert_equals(document.getElementById("text").list, null); |
| 87 }, "list attribute must return null for " + types[i]); |
| 88 |
| 89 test( |
| 90 function() { |
| 91 var el = document.getElementById(types[i]); |
| 92 assert_throws("InvalidStateError", function() { el.stepDown(); }, ""); |
| 93 }, "stepDown does not apply for " + types[i]); |
| 94 |
| 95 test( |
| 96 function() { |
| 97 var el = document.getElementById(types[i]); |
| 98 assert_throws("InvalidStateError", function() { el.stepUp(); }, ""); |
| 99 }, "stepUp does not apply for " + types[i]); |
| 100 } |
| 101 |
| 102 </script> |
| 103 </body> |
| 104 </html> |
OLD | NEW |