Explicitly set editingBehavior in some tests.
[WebKit-https.git] / LayoutTests / editing / pasteboard / paste-list-004.html
1 <body contentEditable="true">
2 <p>Pasting a list item into the middle of another list item should split the target list
3 item into two with the pasted content in between.</p>
4 <ul>
5     <li id="test">one two</li>
6     <li>three four</li>
7     <li><span style="background-color:green"><b>monsters walking cross the floor</b></span></li>
8 </ul>
9
10 <p id="results">FAIL</p>
11 </body>
12 <script src="../editing.js"></script>
13 <script>
14 function escapeHTML(text)
15 {
16     return text.replace(/&/g, "&amp;").replace(/</g, "&lt;");
17 }
18
19 function editingTest()
20 {
21     // Select the first list item.
22     extendSelectionForwardByLineCommand();
23     copyCommand();
24
25     // Place the cursor between "three" and "four".
26     moveSelectionForwardByLineCommand();
27     moveSelectionForwardByWordCommand();
28
29     pasteCommand();
30
31     // Place the cursor between "walking" and "cross"
32     moveSelectionForwardByLineCommand();
33     for (var i = 0; i < 2; ++i)
34         moveSelectionForwardByWordCommand();
35
36     pasteCommand();
37
38     // Verify that the list is as expected.
39     var listItems = document.getElementsByTagName("li");
40     var results = [
41         "one two",
42         "three",
43         "one two",
44         "four",
45         "monsters walking",
46         "one two",
47         "cross the floor"
48         ];
49     if (listItems.length != 7)
50         throw "Expected 7 list items, found " + listItems.length;
51     for (var i = 0; i < results.length; ++i) {
52         var actual = listItems[i].innerText.replace(/^\s+/g, "");
53         if (results[i] != actual)
54             throw "Unexpected list item: " + i + "," + results[i] + "," + listItems[i].innerText;
55     }
56
57     // Verify that the cursor is in the right place (at the beginning of 'cross the floor').
58     var selection = window.getSelection();
59     if (selection.baseNode != listItems[6].firstChild.firstChild.firstChild || selection.baseOffset != 0 || !selection.isCollapsed)
60         throw "Wrong selection position";
61
62     for (var i = 0; i < listItems.length; ++i) {
63       listItems[i].innerHTML = listItems[i].innerHTML.replace(/&nbsp;/g, "");
64       listItems[i].innerHTML += ": " + escapeHTML(listItems[i].innerHTML);
65     }
66 }
67
68 if (window.internals)
69       internals.settings.setEditingBehavior("mac");
70 runDumpAsTextEditingTest(false);
71 document.getElementById("results").innerText = "PASS";
72 </script>