blob: c3511ede59aecd4ee81f0295b858767fee0bc1d2 [file] [log] [blame]
<html>
<head>
<style>
.editing {
border: 2px solid red;
font-size: 24px;
}
</style>
<script src="../editing.js"></script>
<script src="../../resources/js-test-pre.js"></script>
<script src="resources/js-test-selection-shared.js"></script>
<script>
function editingTest(editingBehavior) {
if (window.internals)
internals.settings.setEditingBehavior(editingBehavior);
var startTarget = document.getElementById('start');
var endTarget = document.getElementById('end');
eventSender.mouseMoveTo(startTarget.offsetLeft, startTarget.offsetTop + 10);
// Double-click to select at word-granularity to workaround eventSender bug with selecting text at
// character granularity (i.e. that it just doesn't work).
eventSender.mouseDown();
eventSender.mouseUp();
eventSender.mouseDown();
eventSender.mouseMoveTo(endTarget.offsetLeft, endTarget.offsetTop + 10);
eventSender.mouseUp();
assertSelectionAt(startTarget.firstChild, 0, endTarget.firstChild, 2);
extendSelectionBackwardByCharacterCommand();
// On Win/Linux the anchor is be fixed after the mouse-selection and never changes.
// On Mac, the first character-granularity selection after a mouse-selection resets the anchor/focus.
if (editingBehavior == "mac")
assertSelectionAt(endTarget.firstChild, 2, startTarget.previousSibling, 1);
else
assertSelectionAt(startTarget.firstChild, 0, endTarget.firstChild, 1);
extendSelectionForwardByCharacterCommand();
if (editingBehavior == "mac")
assertSelectionAt(endTarget.firstChild, 2, startTarget.firstChild, 0);
else
assertSelectionAt(startTarget.firstChild, 0, endTarget.firstChild, 2);
extendSelectionForwardByLineBoundaryCommand();
if (editingBehavior == "mac")
assertSelectionAt(endTarget.nextSibling, 1, startTarget.firstChild, 0);
else
assertSelectionAt(startTarget.firstChild, 0, endTarget.nextSibling, 1);
extendSelectionBackwardByLineBoundaryCommand();
if (editingBehavior == "mac")
assertSelectionAt(endTarget.nextSibling, 1, startTarget.previousSibling, 0);
else
assertSelectionAt(startTarget.firstChild, 0, document.getElementById('test'), 4);
}
</script>
<title>Editing Test</title>
</head>
<body>
<div contenteditable id="root" class="editing">
<span id="test">a <span id="start">bc</span> <br>d <span id="end">ef</span> <br>ghi</span>
</div>
<div id="console"></div>
<script>
editingTest("mac");
editingTest("windows");
editingTest("unix");
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>