1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/test/test_movement_by_characters.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,97 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test Character Movement (including nsTextFrame::PeekOffsetCharacter)</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 +</head> 1.12 +<body> 1.13 +<p id="display"></p> 1.14 +<div id="content" style="display: block"> 1.15 +<div contentEditable id="editor"></div> 1.16 +</div> 1.17 +<pre id="test"> 1.18 +<script class="testbody" type="text/javascript;version=1.7"> 1.19 + 1.20 +SimpleTest.waitForExplicitFinish(); 1.21 + 1.22 +if (navigator.userAgent.indexOf("Windows NT 6.2") >= 0) { 1.23 + todo(false, "Too many intermittent failures on Windows 8 (bug 886781)"); 1.24 + SimpleTest.finish(); 1.25 +} else { 1.26 + setTimeout(focusing, 0); 1.27 +} 1.28 + 1.29 +function focusing() { 1.30 + document.getElementById("editor").focus(); 1.31 + // This seems to be necessary because the selection is not set up properly otherwise 1.32 + setTimeout(test, 0); 1.33 +} 1.34 + 1.35 +function test() { 1.36 + var sel = window.getSelection(); 1.37 + var editor = document.getElementById("editor"); 1.38 + 1.39 + function testRight(node, offset) { 1.40 + synthesizeKey("VK_RIGHT", {}); 1.41 + is(sel.anchorNode, node, "Right movement broken in " + editor.innerHTML); 1.42 + is(sel.anchorOffset, offset, "Right movement broken in " + editor.innerHTML); 1.43 + } 1.44 + 1.45 + function testLeft(node, offset) { 1.46 + synthesizeKey("VK_LEFT", {}); 1.47 + is(sel.anchorNode, node, "Left movement broken in " + editor.innerHTML); 1.48 + is(sel.anchorOffset, offset, "Left movement broken in " + editor.innerHTML); 1.49 + } 1.50 + 1.51 + editor.innerHTML = "H K"; 1.52 + sel.collapse(editor.firstChild, 0); 1.53 + testRight(editor.firstChild, 1); 1.54 + testRight(editor.firstChild, 2); 1.55 + testRight(editor.firstChild, 3); 1.56 + testLeft(editor.firstChild, 2); 1.57 + testLeft(editor.firstChild, 1); 1.58 + testLeft(editor.firstChild, 0); 1.59 + 1.60 + editor.innerHTML = "<b>H</b> K"; 1.61 + sel.collapse(editor.firstChild.firstChild, 0); 1.62 + testRight(editor.firstChild.firstChild, 1); 1.63 + testRight(editor.firstChild.nextSibling, 1); 1.64 + testRight(editor.firstChild.nextSibling, 2); 1.65 + testLeft(editor.firstChild.nextSibling, 1); 1.66 + testLeft(editor.firstChild.nextSibling, 0); 1.67 + testLeft(editor.firstChild.firstChild, 0); 1.68 + 1.69 + editor.innerHTML = "H <br>K"; 1.70 + sel.collapse(editor.firstChild, 0); 1.71 + testRight(editor.firstChild, 1); 1.72 + testRight(editor.firstChild, 2); 1.73 + testRight(editor.firstChild.nextSibling.nextSibling, 0); 1.74 + testRight(editor.firstChild.nextSibling.nextSibling, 1); 1.75 + testLeft(editor.firstChild.nextSibling.nextSibling, 0); 1.76 + testLeft(editor, 1); 1.77 + testLeft(editor.firstChild, 1); 1.78 + testLeft(editor.firstChild, 0); 1.79 + 1.80 + editor.innerHTML = "<pre>aa\nbb</pre>"; 1.81 + sel.collapse(editor.firstChild.firstChild, 0); 1.82 + testRight(editor.firstChild.firstChild, 1); 1.83 + // at the end of the first line, before the \n 1.84 + testRight(editor.firstChild.firstChild, 2); 1.85 + testRight(editor.firstChild.firstChild, 3); 1.86 + testRight(editor.firstChild.firstChild, 4); 1.87 + testLeft(editor.firstChild.firstChild, 3); 1.88 + // at the end of the first line, before the \n 1.89 + testLeft(editor.firstChild.firstChild, 2); 1.90 + testLeft(editor.firstChild.firstChild, 1); 1.91 + testLeft(editor.firstChild.firstChild, 0); 1.92 + 1.93 + SimpleTest.finish(); 1.94 +} 1.95 + 1.96 + 1.97 +</script> 1.98 +</pre> 1.99 +</body> 1.100 +</html>