1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2<html>
3<head>
4<style>
5#floating-list {
6 list-style: none;
7 width: 100%;
8}
9
10#floating-list li {
11 float: left;
12 padding: 10px;
13}
14</style>
15<link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
16<script>
17var successfullyParsed = false;
18</script>
19<script src="../../../../fast/js/resources/js-test-pre.js"></script>
20<script src="../editing.js" language="JavaScript" type="text/JavaScript" ></script>
21</head>
22<body id="body">
23<table width="100%">
24 <tr><th></th><th id="startWithCaretBrowsing">Col. Header 1</th><th>Col. Header 2</th></tr>
25 <tr><th>Row Header 1</th><td>One</td><td>Two</td></tr>
26 <tr><th>Row Header 2</th><td>Three</td><td>Four</td></tr>
27</table>
28<p id="paragraph">A paragraph between a 9-cell table and a list of three items.</p>
29<ul id="floating-list">
30 <li>Cat</li>
31 <li>Dog</li>
32 <li>Elephant</li>
33</ul>
34<br clear="all" />
35<div contenteditable>
36 <span id="startWithoutCaretBrowsing">- Foo</span><br />
37 <p>- Bar</p><br />
38</div>
39<p id="description"></p>
40<div id="console"></div>
41<script>
42description("This tests vertical caret navigation works as expected across tables and floating elements.");
43
44function checkWithCaretBrowsing() {
45
46 layoutTestController.overridePreference("WebKitEnableCaretBrowsing", true);
47
48 // Check down/up arrows.
49
50 // Set caret in the second cell of the table.
51 startPoint = document.getElementById("startWithCaretBrowsing");
52 window.getSelection().setPosition(startPoint.childNodes.item(0), 5);
53 shouldBe("getSelection().anchorNode.nodeValue", "'Col. Header 1'");
54 shouldBe("getSelection().baseOffset", "5");
55
56 // Move the caret down to the second row of the table.
57 eventSender.keyDown("downArrow");
58 shouldBe("getSelection().anchorNode.nodeValue", "'One'");
59 shouldBe("getSelection().baseOffset", "3");
60
61 // Move the caret down to the third row of the table.
62 eventSender.keyDown("downArrow");
63 shouldBe("getSelection().anchorNode.nodeValue", "'Three'");
64 shouldBe("getSelection().baseOffset", "5");
65
66 // Move the caret down to paragraph.
67 eventSender.keyDown("downArrow");
68 shouldBe("getSelection().anchorNode.nodeValue", "'A paragraph between a 9-cell table and a list of three items.'");
69 shouldBe("getSelection().baseOffset", "61");
70
71 // Move the caret down to the list of items.
72 paragraph = document.getElementById("paragraph");
73 window.getSelection().setPosition(paragraph.childNodes.item(0), 20);
74 eventSender.keyDown("downArrow");
75 shouldBe("getSelection().anchorNode.nodeValue", "'Elephant'");
76 shouldBe("getSelection().baseOffset", "0");
77
78 // Move the caret up a couple of lines.
79 eventSender.keyDown("upArrow");
80 eventSender.keyDown("upArrow");
81 shouldBe("getSelection().anchorNode.nodeValue", "'Row Header 2'");
82 shouldBe("getSelection().baseOffset", "6");
83
84 // Check up/down arrows + Shift.
85
86 // Selection inside the table.
87 eventSender.keyDown("upArrow", ["shiftKey"]);
88 range = getSelection().getRangeAt(0);
89 shouldBe("range.startContainer.nodeValue", "'Row Header 1'");
90 shouldBe("getSelection().baseOffset", "6");
91 shouldBe("range.endContainer.nodeValue", "'Row Header 2'");
92 shouldBe("getSelection().extentOffset", "6");
93
94 // Selection across the table and the paragraph.
95 eventSender.keyDown("downArrow", ["shiftKey"]);
96 eventSender.keyDown("downArrow", ["shiftKey"]);
97 range = getSelection().getRangeAt(0);
98 shouldBe("range.startContainer.nodeValue", "'Row Header 2'");
99 shouldBe("getSelection().baseOffset", "6");
100 shouldBe("range.endContainer.nodeValue", "'A paragraph between a 9-cell table and a list of three items.'");
101 shouldBe("getSelection().extentOffset", "20");
102}
103
104function checkWithoutCaretBrowsing() {
105 layoutTestController.dumpEditingCallbacks();
106 layoutTestController.overridePreference("WebKitEnableCaretBrowsing", false);
107
108 // Check MoveDown / MoveUp commands.
109
110 // Set caret in the second cell of the table.
111 startPoint = document.getElementById("startWithoutCaretBrowsing");
112 window.getSelection().setPosition(startPoint.childNodes.item(0), 3);
113
114 // Move down and up across the different lines inside the editable content.
115 layoutTestController.execCommand("MoveDown");
116 layoutTestController.execCommand("MoveDown");
117 layoutTestController.execCommand("MoveUp");
118 layoutTestController.execCommand("MoveUp");
119 layoutTestController.execCommand("MoveUp");
120}
121
122if (window.layoutTestController) {
123 layoutTestController.dumpAsText();
124
125 // We need to check with and without caret browsing activated to
126 // ensure no API breakage has happened with the MoveUp/Down commands.
127 checkWithCaretBrowsing();
128 checkWithoutCaretBrowsing();
129}
130
131successfullyParsed = true;
132</script>
133<script src="../../../../fast/js/resources/js-test-post.js"></script>
134</body>
135</html>