<body contentEditable="true">
<p>Pasting a list item into the middle of another list item should split the target list
item into two with the pasted content in between.</p>
<ul>
    <li id="test">one two</li>
    <li>three four</li>
    <li><span style="background-color:green"><b>monsters walking cross the floor</b></span></li>
</ul>

<p id="results">FAIL</p>
</body>
<script src="../editing.js"></script>
<script>
function escapeHTML(text)
{
    return text.replace(/&/g, "&amp;").replace(/</g, "&lt;");
}

function editingTest()
{
    // Select the first list item.
    extendSelectionForwardByLineCommand();
    copyCommand();

    // Place the cursor between "three" and "four".
    moveSelectionForwardByLineCommand();
    moveSelectionForwardByWordCommand();

    pasteCommand();

    // Place the cursor between "walking" and "cross"
    moveSelectionForwardByLineCommand();
    for (var i = 0; i < 2; ++i)
        moveSelectionForwardByWordCommand();

    pasteCommand();

    // Verify that the list is as expected.
    var listItems = document.getElementsByTagName("li");
    var results = [
        "one two",
        "three",
        "one two",
        "four",
        "monsters walking",
        "one two",
        "cross the floor"
        ];
    if (listItems.length != 7)
        throw "Expected 7 list items, found " + listItems.length;
    for (var i = 0; i < results.length; ++i) {
        var actual = listItems[i].innerText.replace(/^\s+/g, "");
        if (results[i] != actual)
            throw "Unexpected list item: " + i + "," + results[i] + "," + listItems[i].innerText;
    }

    // Verify that the cursor is in the right place (at the beginning of 'cross the floor').
    var selection = window.getSelection();
    if (selection.baseNode != listItems[6].firstChild.firstChild.firstChild || selection.baseOffset != 0 || !selection.isCollapsed)
        throw "Wrong selection position";

    for (var i = 0; i < listItems.length; ++i) {
      listItems[i].innerHTML = listItems[i].innerHTML.replace(/&nbsp;/g, "");
      listItems[i].innerHTML += ": " + escapeHTML(listItems[i].innerHTML);
    }
}

if (window.internals)
      internals.settings.setEditingBehavior("mac");
runDumpAsTextEditingTest(false);
document.getElementById("results").innerText = "PASS";
</script>
