editor/libeditor/base/tests/test_bug795785.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 <html>
     2 <!--
     3 https://bugzilla.mozilla.org/show_bug.cgi?id=795785
     4 -->
     5 <head>
     6   <title>Test for Bug 795785</title>
     7   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
     8   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    11 </head>
    12 <body>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795785">Mozilla Bug 795785</a>
    14 <div id="display">
    15   <textarea id="textarea" style="overflow: hidden; height: 3em; width: 5em; word-wrap: normal;"></textarea>
    16   <div id="div" contenteditable style="overflow: hidden; height: 3em; width: 5em;"></div>
    17 </div>
    18 <div id="content" style="display: none">
    20 </div>
    21 <pre id="test">
    22 </pre>
    24 <script class="testbody" type="application/javascript">
    27 SimpleTest.waitForExplicitFinish();
    29 // Turn off spatial navigation because it hijacks arrow key events and VK_RETURN
    30 // events.
    31 SpecialPowers.setBoolPref("snav.enabled", false);
    33 SimpleTest.waitForFocus(runTests);
    35 var textarea = document.getElementById("textarea");
    36 var div = document.getElementById("div");
    38 function hitEventLoop(aFunc, aTimes)
    39 {
    40   if (--aTimes) {
    41     setTimeout(hitEventLoop, 0, aFunc, aTimes);
    42   } else {
    43     setTimeout(aFunc, 100);
    44   }
    45 }
    47 function doKeyEventTest(aElement, aElementDescription, aCallback)
    48 {
    49   aElement.focus();
    50   aElement.scrollTop = 0;
    51   hitEventLoop(function () {
    52     is(aElement.scrollTop, 0,
    53        aElementDescription + "'s scrollTop isn't 0");
    54     synthesizeKey("VK_RETURN", { });
    55     synthesizeKey("VK_RETURN", { });
    56     synthesizeKey("VK_RETURN", { });
    57     synthesizeKey("VK_RETURN", { });
    58     synthesizeKey("VK_RETURN", { });
    59     synthesizeKey("VK_RETURN", { });
    60     hitEventLoop(function () {
    61       isnot(aElement.scrollTop, 0,
    62             aElementDescription + " was not scrolled by inserting line breaks");
    63       var scrollTop = aElement.scrollTop;
    64       synthesizeKey("VK_UP", { });
    65       synthesizeKey("VK_UP", { });
    66       synthesizeKey("VK_UP", { });
    67       synthesizeKey("VK_UP", { });
    68       synthesizeKey("VK_UP", { });
    69       hitEventLoop(function () {
    70         isnot(aElement.scrollTop, scrollTop,
    71               aElementDescription + " was not scrolled by up key events");
    72         synthesizeKey("VK_DOWN", { });
    73         synthesizeKey("VK_DOWN", { });
    74         synthesizeKey("VK_DOWN", { });
    75         synthesizeKey("VK_DOWN", { });
    76         synthesizeKey("VK_DOWN", { });
    77         hitEventLoop(function () {
    78           is(aElement.scrollTop, scrollTop,
    79              aElementDescription + " was not scrolled by down key events");
    80           var longWord = "aaaaaaaaaaaaaaaaaaaa";
    81           sendString(longWord);
    82           hitEventLoop(function () {
    83             isnot(aElement.scrollLeft, 0,
    84                   aElementDescription + " was not scrolled by typing long word");
    85             var scrollLeft = aElement.scrollLeft;
    86             var i;
    87             for (i = 0; i < longWord.length; i++) {
    88               synthesizeKey("VK_LEFT", { });
    89             }
    90             hitEventLoop(function () {
    91               isnot(aElement.scrollLeft, scrollLeft,
    92                     aElementDescription + " was not scrolled by left key events");
    93               for (i = 0; i < longWord.length; i++) {
    94                 synthesizeKey("VK_RIGHT", { });
    95               }
    96               hitEventLoop(function () {
    97                 is(aElement.scrollLeft, scrollLeft,
    98                    aElementDescription + " was not scrolled by right key events");
    99                 aCallback();
   100               }, 20);
   101             }, 20);
   102           }, 20);
   103         }, 20);
   104       }, 20);
   105     }, 20);
   106   }, 20);
   107 }
   109 function doCompositionTest(aElement, aElementDescription, aCallback)
   110 {
   111   aElement.focus();
   112   aElement.scrollTop = 0;
   113   hitEventLoop(function () {
   114     is(aElement.scrollTop, 0,
   115        aElementDescription + "'s scrollTop isn't 0");
   116     synthesizeComposition({ type: "compositionstart" });
   117     var str = "Web \u958b\u767a\u8005\u306e\u7686\u3055\u3093\u306f\u3001" +
   118               "Firefox \u306b\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b HTML5" +
   119               " \u3084 CSS \u306e\u65b0\u6a5f\u80fd\u3092\u6d3b\u7528\u3059" +
   120               "\u308b\u3053\u3068\u3067\u3001\u9b45\u529b\u3042\u308b Web " +
   121               "\u30b5\u30a4\u30c8\u3084\u9769\u65b0\u7684\u306a Web \u30a2" +
   122               "\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u3088\u308a" +
   123               "\u77ed\u6642\u9593\u3067\u7c21\u5358\u306b\u4f5c\u6210\u3067" +
   124               "\u304d\u307e\u3059\u3002";
   125     synthesizeComposition({ type: "compositionupdate", data: str });
   126     synthesizeText({
   127         composition: {
   128           string: str,
   129           clauses: [
   130             { length: str.length, attr: COMPOSITION_ATTR_RAWINPUT }
   131           ]
   132         },
   133         caret: { start: str.length, length: 0 }
   134       });
   135     hitEventLoop(function () {
   136       isnot(aElement.scrollTop, 0,
   137             aElementDescription + " was not scrolled by composition");
   138       synthesizeComposition({ type: "compositionupdate", data: "" });
   139       synthesizeText({
   140         composition: { string: "", clauses: [ { length: 0, attr: 0 } ] },
   141         caret: { start: 0, length: 0 }
   142       });
   143       synthesizeComposition({ type: "compositionend", data: "" });
   144       hitEventLoop(function () {
   145         is(aElement.scrollTop, 0,
   146            aElementDescription + " was not scrolled back to the top by canceling composition");
   147         aCallback();
   148       }, 20);
   149     }, 20);
   150   }, 20);
   151 }
   153 function runTests()
   154 {
   155   doKeyEventTest(textarea, "textarea",
   156     function () {
   157       textarea.value = "";
   158       doKeyEventTest(div, "div (contenteditable)",
   159         function () {
   160           div.innerHTML = "";
   161           doCompositionTest(textarea, "textarea",
   162             function () {
   163               doCompositionTest(div, "div (contenteditable)",
   164                 function () {
   165                   SimpleTest.finish();
   166                 });
   167             });
   168         });
   169     });
   170 }
   172 </script>
   173 </body>
   175 </html>

mercurial