<script>
if (window.layoutTestController)
     layoutTestController.dumpEditingCallbacks();
</script>
<style>
td {
    border: 1px solid #aaa;
}
</style>

<body style="border: 1px solid red;" contenteditable="true"><table id="table" style="margin: 25px; border:10px solid #ccc; padding: 10px;"><tr><td>cell one</td><td>cell two</td></tr></table>
<ul id="console"></ul>
<script>
function log(message) {
    var console = document.getElementById("console");
    var li = document.createElement("li");
    var text = document.createTextNode(message);
    
    console.appendChild(li);
    li.appendChild(text);
}
if (!window.layoutTestController) {
    log("This test uses the eventSender to do mouse clicks.  To run it manually, click after the table, the caret should appear there (and not inside the table).  Then click inside the table.  The caret should appear inside it.");
    document.body.addEventListener("click", function() { var s = window.getSelection(); log("click @ " + event.clientX + ", " + event.clientY + " caret at: " + s.anchorNode + ", " + s.anchorOffset); }, true);
} else {
    window.layoutTestController.dumpAsText();
    var s, x, y, e, top, bottom, left, right;
    table = document.getElementById("table");

    top = table.offsetTop;
    left = table.offsetLeft;
    bottom = top + table.offsetHeight;
    right = left + table.offsetWidth;
    
    x = right + 5;
    y = (top + bottom) / 2;
    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();
    eventSender.mouseUp();
    s = window.getSelection();
    if (!(s.anchorNode == document.body && s.anchorOffset == 1))
        log("Failure: Clicking @ " + x + ", " + y + " after the table didn't put the caret after it.  Instead: " + s.anchorNode + ", " + s.anchorOffset);
    
    x = right - 5;
    y = (top + bottom) / 2;
    eventSender.leapForward(1000);
    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();
    eventSender.mouseUp();
    s = window.getSelection();
    if (s.anchorNode == document.body)
        log("Failure: Clicking @ " + x + ", " + y + " inside the table put the caret before or after it.  Instead: " + s.anchorNode + ", " + s.anchorOffset);
        
    x = left - 5;
    y = (top + bottom) / 2;
    eventSender.leapForward(1000);
    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();
    eventSender.mouseUp();
    s = window.getSelection();
    if (s.anchorNode != table || s.anchorOffset != 0)
    if (!(s.anchorNode == document.body && s.anchorOffset == 0))
        log("Failure: Clicking @ " + x + ", " + y + " before the table should be the caret before it.  Instead: " + s.anchorNode + ", " + s.anchorOffset);
        
    x = left + 5;
    y = (top + bottom) / 2;
    eventSender.leapForward(1000);
    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();
    eventSender.mouseUp();
    s = window.getSelection();
    if (s.anchorNode == document.body)
        log("Failure: Clicking @ " + x + ", " + y + " inside the table put the caret before or after it.  Instead: " + s.anchorNode + ", " + s.anchorOffset);
}
</script>
</body>
