Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / paste-multiline-text-input.html
blobdd3b23a2ac22d85be268a10977144cbd87e9a811
1 <html>
2 <head>
3 <script>
4 if (window.testRunner)
5 window.testRunner.dumpAsText();
7 function getInput()
9 return document.getElementById('inputId');
12 var DEFAULT_LINE_1 = "line\t(1 of 2)\r\nline\t(2 of 2)";
13 var EXPECTED_LINE_1 = "line\t(1 of 2) line\t(2 of 2)";
15 var DEFAULT_LINE_2 = "null\0char";
16 var EXPECTED_LINE_2 = "null\0char";
18 var DEFAULT_LINE_3 = "line with trailing newlines\r\n\r\n";
19 var EXPECTED_LINE_3 = "line with trailing newlines";
21 var TEST_NAME_1 = "Multi-line test";
22 var TEST_NAME_2 = "Null char test";
23 var TEST_NAME_3 = "Trailing newline test";
25 function testMultiline()
27 log(TEST_NAME_1 + ":");
28 testInputField(DEFAULT_LINE_1, EXPECTED_LINE_1);
30 log(TEST_NAME_2 + ":");
31 testInputField(DEFAULT_LINE_2, EXPECTED_LINE_2);
33 log(TEST_NAME_3 + ":");
34 testInputField(DEFAULT_LINE_3, EXPECTED_LINE_3);
37 function testInputField(input_value, expected)
39 var input = getInput();
40 input.focus();
41 document.execCommand("SelectAll", false, null);
42 document.execCommand("InsertText", false, input_value);
43 var str = jsEscape(input.value);
44 if (str == jsEscape(expected))
45 log("PASS");
46 else
47 log("FAIL: " + str);
50 function log(str) {
51 var valueField = document.getElementById('console');
52 valueField.appendChild(document.createTextNode(str));
53 valueField.appendChild(document.createElement("br"));
56 function jsEscape(s)
58 // Partial
59 var replacements = [
60 ["\r", "\\r"],
61 ["\n", "\\n"],
62 ["\t", "\\t"],
63 ["\f", "\\f"],
64 ["\t", "\\t"],
65 ["\0", "\\0"]
68 for (var i = 0; i < replacements.length; ++i) {
69 var r = replacements[i];
70 s = s.replace(r[0], r[1]);
72 return s;
74 </script>
75 <style>
76 .pass { color: green; }
77 .fail { color: red; }
78 .code { font-family: monospace; }
79 </style>
80 </head>
81 <body onload="testMultiline()">
82 <h2>Test: This test verifies that text inputs will accept multiple lines of pasted text. You should see three tests "PASS" below.</h2>
83 <input id=inputId size=60 /><br>
84 <span class=code id=console></span>
85 </body>
86 </html>