Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / editing / selection / paragraph-with-ruby.html
1 <p>
2     This is the paragraph before.
3 </p>
4 <p id="paragraph">
5     This paragraph contains an <ruby id="ruby">annotated <rt id="rt">annotation</rt></ruby> word.
6 </p>
7 <p>
8     This is the paragraph after.
9 </p>
10 <pre id="console">
11 </pre>
12 <script>
13     if (window.testRunner)
14         testRunner.dumpAsText();
15
16     function log(message)
17     {
18         document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
19     }
20
21     function positionAsString(node, offset)
22     {
23         if (node.nodeType === Node.TEXT_NODE)
24             return "\"" + node.data.trim() + "\"[" + offset + "]";
25         return node.tagName + "[" + offset + "]";
26     }
27
28     function testMovementToEndOfParagraph(node, offset)
29     {
30         var selection = getSelection();
31
32         selection.collapse(node, offset);
33         selection.modify("move", "forward", "paragraphBoundary");
34         if (selection.baseNode === paragraph.lastChild && selection.baseOffset === 6)
35             log("PASS: Reached the end of the paragraph starting from " + positionAsString(node, offset) + ".");
36         else
37             log("FAIL: Reached " + positionAsString(selection.baseNode, selection.baseOffset) + " instead "
38                 + "of the end of the paragraph starting from " + positionAsString(node, offset) + ".");
39     }
40
41     function testMovementToStartOfParagraph(node, offset)
42     {
43         var selection = getSelection();
44
45         selection.collapse(node, offset);
46         selection.modify("move", "backward", "paragraphBoundary");
47         if (selection.baseNode === paragraph.firstChild && selection.baseOffset === 5)
48             log("PASS: Reached the start of the paragraph starting from " + positionAsString(node, offset) + ".");
49         else
50             log("FAIL: Reached " + positionAsString(selection.baseNode, selection.baseOffset) + " instead "
51                 + "of the start of the paragraph starting from " + positionAsString(node, offset) + ".");
52     }
53
54     var paragraph = document.getElementById("paragraph");
55     var ruby = document.getElementById("ruby");
56     var rt = document.getElementById("rt");
57
58     testMovementToEndOfParagraph(paragraph, 0);
59     testMovementToEndOfParagraph(ruby, 0);
60     testMovementToEndOfParagraph(rt, 0);
61
62     testMovementToStartOfParagraph(paragraph, 2);
63     testMovementToStartOfParagraph(ruby, 2);
64     testMovementToStartOfParagraph(rt, 1);
65
66 </script>