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.

     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">
    17 SimpleTest.waitForExplicitFinish();
    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 }
    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 }
    32 function test() {
    33   var sel = window.getSelection();
    34   var editor = document.getElementById("editor");
    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   }
    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   }
    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);
    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);
    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);
    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);
    90   SimpleTest.finish();
    91 }
    94 </script>
    95 </pre>
    96 </body>
    97 </html>

mercurial