blob: 30253e73766aee2ee148cdf7a250ce116f71e778 [file] [log] [blame]
<html>
<head>
<style>
.editing {
margin: 10; padding: 0;
}
</style>
<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
<script>
function editingTest() {
typeCharacterCommand('1');
typeCharacterCommand('2');
boldCommand();
typeCharacterCommand('3');
italicCommand();
typeCharacterCommand('4');
typeCharacterCommand('5');
typeCharacterCommand('6');
italicCommand();
boldCommand();
insertParagraphCommand();
typeCharacterCommand('l');
typeCharacterCommand('i');
typeCharacterCommand('n');
typeCharacterCommand('e');
typeCharacterCommand(' ');
typeCharacterCommand('t');
typeCharacterCommand('w');
typeCharacterCommand('o');
insertLineBreakCommand();
insertLineBreakCommand();
typeCharacterCommand('a');
typeCharacterCommand('n');
typeCharacterCommand('d');
typeCharacterCommand(' ');
fontSizeCommand("6");
underlineCommand();
typeCharacterCommand('t');
typeCharacterCommand('h');
typeCharacterCommand('r');
typeCharacterCommand('e');
typeCharacterCommand('e');
typeCharacterCommand(' ');
typeCharacterCommand(' ');
typeCharacterCommand(' ');
underlineCommand();
insertLineBreakCommand();
}
</script>
<title>Attributed String Test</title>
</head>
<body contenteditable id="root">
<div id="wrapper">
<div class="editing" id="test"></div>
</div>
<script>
runEditingTest();
</script>
<script type="text/javascript">
var console_messages = document.createElement("ol");
function log(message)
{
var item = document.createElement("li");
item.appendChild(document.createTextNode(String(message).replace(/0x[0-9a-fA-F]{8}/g, "0xXXXXXXXX")));
console_messages.appendChild(item);
}
if (window.testRunner) {
try {
testRunner.dumpAsText();
log("Actual HTML:");
log("<pre>" + document.getElementById("wrapper").innerHTML + "</pre>");
window.getSelection().setPosition(document.body, 0);
log("(0, 0): " + textInputController.attributedSubstringFromRange(0, 0));
log("(0, 0) length: " + textInputController.attributedSubstringFromRange(0, 0).length());
log("(0, 2): " + textInputController.attributedSubstringFromRange(0, 2));
log("(0, 2) length: " + textInputController.attributedSubstringFromRange(0, 2).length());
log("(1, 2): " + textInputController.attributedSubstringFromRange(1, 2));
log("(1, 2) length: " + textInputController.attributedSubstringFromRange(1, 2).length());
log("(0, 3): " + textInputController.attributedSubstringFromRange(0, 3));
log("(0, 3) length: " + textInputController.attributedSubstringFromRange(0, 3).length());
log("(0, 6): " + textInputController.attributedSubstringFromRange(0, 6));
log("(0, 6) length: " + textInputController.attributedSubstringFromRange(0, 6).length());
log("(0, 7): " + textInputController.attributedSubstringFromRange(0, 7));
log("(0, 7) length: " + textInputController.attributedSubstringFromRange(0, 7).length()); // should be 7 characters!
log("(0, 31): " + textInputController.attributedSubstringFromRange(0, 31));
log("(0, 31) length: " + textInputController.attributedSubstringFromRange(0, 31).length()); // actual length IS 31
log("(0, 100): " + textInputController.attributedSubstringFromRange(0, 100));
log("(0, 100) length: " + textInputController.attributedSubstringFromRange(0, 100).length()); // should be 31 characters!
log("(1, 100): " + textInputController.attributedSubstringFromRange(1, 100));
log("(1, 100) length: " + textInputController.attributedSubstringFromRange(1, 100).length()); // should be 30 characters!
log("(2, 3): " + textInputController.attributedSubstringFromRange(2, 3));
log("(2, 3) length: " + textInputController.attributedSubstringFromRange(2, 3).length());
log("(5, 1): " + textInputController.attributedSubstringFromRange(5, 1));
log("(5, 1) length: " + textInputController.attributedSubstringFromRange(5, 1).length());
log("(5, 2): " + textInputController.attributedSubstringFromRange(5, 2));
log("(5, 2) length: " + textInputController.attributedSubstringFromRange(5, 2).length());
log("(5, 5): " + textInputController.attributedSubstringFromRange(5, 5));
log("(5, 5) length: " + textInputController.attributedSubstringFromRange(5, 5).length());
log("(15, 14): " + textInputController.attributedSubstringFromRange(15, 14));
log("(15, 14) length: " + textInputController.attributedSubstringFromRange(15, 14).length()); // should be 14 characters!
log("(100, 0): " + textInputController.attributedSubstringFromRange(100, 0)); // should be undefined
log("(100, 100): " + textInputController.attributedSubstringFromRange(100, 100)); // should be undefined
} catch (ex) {
log("Exception: " + ex.description);
}
var console = document.createElement("p");
console.appendChild(console_messages);
document.body.appendChild(console);
} else {
document.write("(cannot run interactively)");
}
</script>
</body>
</html>