layout/generic/test/test_movement_by_characters.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial