blob: f5f643c29cdd0d1fe6e708dd208c2d80dfddd8bf [file] [log] [blame]
<html>
<head>
<script>
if (window.testRunner)
window.testRunner.dumpAsText();
function getInput()
{
return document.getElementById('inputId');
}
var DEFAULT_LINE_1 = "line\t(1 of 2)\r\nline\t(2 of 2)";
var EXPECTED_LINE_1 = "line\t(1 of 2) line\t(2 of 2)";
// FIXME: Is this really expected behavior to truncate the string at a null byte?
// It doesn't match Firefox 4 and common sense.
var DEFAULT_LINE_2 = "null\0char";
var EXPECTED_LINE_2 = "null";
var DEFAULT_LINE_3 = "line with trailing newlines\r\n\r\n";
var EXPECTED_LINE_3 = "line with trailing newlines";
var TEST_NAME_1 = "Multi-line test";
var TEST_NAME_2 = "Null char test";
var TEST_NAME_3 = "Trailing newline test";
function testMultiline()
{
log(TEST_NAME_1 + ":");
testInputField(DEFAULT_LINE_1, EXPECTED_LINE_1);
log(TEST_NAME_2 + ":");
testInputField(DEFAULT_LINE_2, EXPECTED_LINE_2);
log(TEST_NAME_3 + ":");
testInputField(DEFAULT_LINE_3, EXPECTED_LINE_3);
}
function testInputField(input_value, expected)
{
var input = getInput();
input.focus();
document.execCommand("SelectAll", false, null);
document.execCommand("InsertText", false, input_value);
var str = jsEscape(input.value);
if (str == jsEscape(expected))
log("PASS");
else
log("FAIL: " + str);
}
function log(str) {
var valueField = document.getElementById('console');
valueField.appendChild(document.createTextNode(str));
valueField.appendChild(document.createElement("br"));
}
function jsEscape(s)
{
// Partial
var replacements = [
["\r", "\\r"],
["\n", "\\n"],
["\t", "\\t"],
["\f", "\\f"],
["\t", "\\t"],
["\0", "\\0"]
];
for (var i = 0; i < replacements.length; ++i) {
var r = replacements[i];
s = s.replace(r[0], r[1]);
}
return s;
}
</script>
<style>
.pass { color: green; }
.fail { color: red; }
.code { font-family: monospace; }
</style>
</head>
<body onload="testMultiline()">
<h2>Test: This test verifies that text inputs will accept multiple lines of pasted text. You should see three tests "PASS" below.</h2>
<input id=inputId size=60 /><br>
<span class=code id=console></span>
</body>
</html>