|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test Character Movement (including nsTextFrame::PeekOffsetCharacter)</title> |
|
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
|
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
8 </head> |
|
9 <body> |
|
10 <p id="display"></p> |
|
11 <div id="content" style="display: block"> |
|
12 <div contentEditable id="editor"></div> |
|
13 </div> |
|
14 <pre id="test"> |
|
15 <script class="testbody" type="text/javascript;version=1.7"> |
|
16 |
|
17 SimpleTest.waitForExplicitFinish(); |
|
18 |
|
19 if (navigator.userAgent.indexOf("Windows NT 6.2") >= 0) { |
|
20 todo(false, "Too many intermittent failures on Windows 8 (bug 886781)"); |
|
21 SimpleTest.finish(); |
|
22 } else { |
|
23 setTimeout(focusing, 0); |
|
24 } |
|
25 |
|
26 function focusing() { |
|
27 document.getElementById("editor").focus(); |
|
28 // This seems to be necessary because the selection is not set up properly otherwise |
|
29 setTimeout(test, 0); |
|
30 } |
|
31 |
|
32 function test() { |
|
33 var sel = window.getSelection(); |
|
34 var editor = document.getElementById("editor"); |
|
35 |
|
36 function testRight(node, offset) { |
|
37 synthesizeKey("VK_RIGHT", {}); |
|
38 is(sel.anchorNode, node, "Right movement broken in " + editor.innerHTML); |
|
39 is(sel.anchorOffset, offset, "Right movement broken in " + editor.innerHTML); |
|
40 } |
|
41 |
|
42 function testLeft(node, offset) { |
|
43 synthesizeKey("VK_LEFT", {}); |
|
44 is(sel.anchorNode, node, "Left movement broken in " + editor.innerHTML); |
|
45 is(sel.anchorOffset, offset, "Left movement broken in " + editor.innerHTML); |
|
46 } |
|
47 |
|
48 editor.innerHTML = "H K"; |
|
49 sel.collapse(editor.firstChild, 0); |
|
50 testRight(editor.firstChild, 1); |
|
51 testRight(editor.firstChild, 2); |
|
52 testRight(editor.firstChild, 3); |
|
53 testLeft(editor.firstChild, 2); |
|
54 testLeft(editor.firstChild, 1); |
|
55 testLeft(editor.firstChild, 0); |
|
56 |
|
57 editor.innerHTML = "<b>H</b> K"; |
|
58 sel.collapse(editor.firstChild.firstChild, 0); |
|
59 testRight(editor.firstChild.firstChild, 1); |
|
60 testRight(editor.firstChild.nextSibling, 1); |
|
61 testRight(editor.firstChild.nextSibling, 2); |
|
62 testLeft(editor.firstChild.nextSibling, 1); |
|
63 testLeft(editor.firstChild.nextSibling, 0); |
|
64 testLeft(editor.firstChild.firstChild, 0); |
|
65 |
|
66 editor.innerHTML = "H <br>K"; |
|
67 sel.collapse(editor.firstChild, 0); |
|
68 testRight(editor.firstChild, 1); |
|
69 testRight(editor.firstChild, 2); |
|
70 testRight(editor.firstChild.nextSibling.nextSibling, 0); |
|
71 testRight(editor.firstChild.nextSibling.nextSibling, 1); |
|
72 testLeft(editor.firstChild.nextSibling.nextSibling, 0); |
|
73 testLeft(editor, 1); |
|
74 testLeft(editor.firstChild, 1); |
|
75 testLeft(editor.firstChild, 0); |
|
76 |
|
77 editor.innerHTML = "<pre>aa\nbb</pre>"; |
|
78 sel.collapse(editor.firstChild.firstChild, 0); |
|
79 testRight(editor.firstChild.firstChild, 1); |
|
80 // at the end of the first line, before the \n |
|
81 testRight(editor.firstChild.firstChild, 2); |
|
82 testRight(editor.firstChild.firstChild, 3); |
|
83 testRight(editor.firstChild.firstChild, 4); |
|
84 testLeft(editor.firstChild.firstChild, 3); |
|
85 // at the end of the first line, before the \n |
|
86 testLeft(editor.firstChild.firstChild, 2); |
|
87 testLeft(editor.firstChild.firstChild, 1); |
|
88 testLeft(editor.firstChild.firstChild, 0); |
|
89 |
|
90 SimpleTest.finish(); |
|
91 } |
|
92 |
|
93 |
|
94 </script> |
|
95 </pre> |
|
96 </body> |
|
97 </html> |