2007-11-07 20:07:00 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test Character Movement (including nsTextFrame::PeekOffsetCharacter)</title>
|
2009-05-06 13:46:04 -07:00
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
2007-11-07 20:07:00 -08:00
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: block">
|
|
|
|
<div contentEditable id="editor"></div>
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript;version=1.7">
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
// This seems to be necessary because the selection is not set up properly otherwise
|
2009-04-23 12:36:55 -07:00
|
|
|
setTimeout(test, 0);
|
2007-11-07 20:07:00 -08:00
|
|
|
|
|
|
|
function test() {
|
|
|
|
var sel = window.getSelection();
|
|
|
|
var editor = document.getElementById("editor");
|
|
|
|
|
|
|
|
function testRight(node, offset) {
|
|
|
|
synthesizeKey("VK_RIGHT", {});
|
|
|
|
is(sel.anchorNode, node, "Right movement broken in " + editor.innerHTML);
|
|
|
|
is(sel.anchorOffset, offset, "Right movement broken in " + editor.innerHTML);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testLeft(node, offset) {
|
|
|
|
synthesizeKey("VK_LEFT", {});
|
|
|
|
is(sel.anchorNode, node, "Left movement broken in " + editor.innerHTML);
|
|
|
|
is(sel.anchorOffset, offset, "Left movement broken in " + editor.innerHTML);
|
|
|
|
}
|
|
|
|
|
|
|
|
editor.innerHTML = "H K";
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 1);
|
|
|
|
testRight(editor.firstChild, 2);
|
|
|
|
testRight(editor.firstChild, 3);
|
|
|
|
testLeft(editor.firstChild, 2);
|
|
|
|
testLeft(editor.firstChild, 1);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = "<b>H</b> K";
|
|
|
|
sel.collapse(editor.firstChild.firstChild, 0);
|
|
|
|
testRight(editor.firstChild.firstChild, 1);
|
|
|
|
testRight(editor.firstChild.nextSibling, 1);
|
|
|
|
testRight(editor.firstChild.nextSibling, 2);
|
|
|
|
testLeft(editor.firstChild.nextSibling, 1);
|
|
|
|
testLeft(editor.firstChild.nextSibling, 0);
|
|
|
|
testLeft(editor.firstChild.firstChild, 0);
|
|
|
|
|
|
|
|
editor.innerHTML = "H <br>K";
|
|
|
|
sel.collapse(editor.firstChild, 0);
|
|
|
|
testRight(editor.firstChild, 1);
|
|
|
|
testRight(editor.firstChild, 2);
|
|
|
|
testRight(editor.firstChild.nextSibling.nextSibling, 0);
|
|
|
|
testRight(editor.firstChild.nextSibling.nextSibling, 1);
|
|
|
|
testLeft(editor.firstChild.nextSibling.nextSibling, 0);
|
|
|
|
testLeft(editor, 1);
|
|
|
|
testLeft(editor.firstChild, 1);
|
|
|
|
testLeft(editor.firstChild, 0);
|
|
|
|
|
2007-11-15 18:25:59 -08:00
|
|
|
editor.innerHTML = "<pre>aa\nbb</pre>";
|
|
|
|
sel.collapse(editor.firstChild.firstChild, 0);
|
|
|
|
testRight(editor.firstChild.firstChild, 1);
|
2010-07-13 18:49:16 -07:00
|
|
|
// at the end of the first line, before the \n
|
|
|
|
testRight(editor.firstChild.firstChild, 2);
|
2007-11-15 18:25:59 -08:00
|
|
|
testRight(editor.firstChild.firstChild, 3);
|
|
|
|
testRight(editor.firstChild.firstChild, 4);
|
|
|
|
testLeft(editor.firstChild.firstChild, 3);
|
2010-07-13 18:49:16 -07:00
|
|
|
// at the end of the first line, before the \n
|
|
|
|
testLeft(editor.firstChild.firstChild, 2);
|
2007-11-15 18:25:59 -08:00
|
|
|
testLeft(editor.firstChild.firstChild, 1);
|
|
|
|
testLeft(editor.firstChild.firstChild, 0);
|
|
|
|
|
2007-11-07 20:07:00 -08:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|