editor/libeditor/text/tests/test_bug830600.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
     3    - License, v. 2.0. If a copy of the MPL was not distributed with this
     4    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     5 <html>
     6 <!--
     7 https://bugzilla.mozilla.org/show_bug.cgi?id=830600
     8 -->
     9 <head>
    10   <title>Test for Bug 830600</title>
    11   <script type="application/javascript"
    12           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    13   <script type="application/javascript"
    14           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    15   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
    16 </head>
    18 <body>
    19   <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=830600">Mozilla Bug 830600</a>
    20   <p id="display"></p>
    21   <div id="content" style="display: none">
    22   </div>
    23   <input type="text" id="t1" />
    24   <pre id="test">
    25     <script type="application/javascript;version=1.7">
    27       /** Test for Bug 830600 **/
    28       SimpleTest.waitForExplicitFinish();
    29       SimpleTest.waitForFocus(function() {
    30         const Ci = Components.interfaces;
    31         function test(str, expected, callback) {
    32           var t = document.getElementById("t1");
    33           t.QueryInterface(Ci.nsIDOMNSEditableElement);
    34           t.focus();
    35           t.value = "";
    36           t.editor.QueryInterface(Ci.nsIPlaintextEditor);
    37           var origNewlineHandling = t.editor.newlineHandling;
    38           t.editor.newlineHandling = Ci.nsIPlaintextEditor.eNewlinesStripSurroundingWhitespace
    39           SimpleTest.waitForClipboard(str,
    40             function() {
    41               Components.classes["@mozilla.org/widget/clipboardhelper;1"]
    42                         .getService(Components.interfaces.nsIClipboardHelper)
    43                         .copyString(str, document);
    44             },
    45             function() {
    46               synthesizeKey("V", {accelKey: true});
    47               is(t.value, expected, "New line handling works correctly");
    48               t.value = "";
    49               callback();
    50             },
    51             function() {
    52               ok(false, "Failed to copy the string");
    53               SimpleTest.finish();
    54             }
    55           );
    56         }
    58         function runNextTest() {
    59           if (tests.length) {
    60             var currentTest = tests.shift();
    61             test(currentTest[0], currentTest[1], runNextTest);
    62           } else {
    63             SimpleTest.finish();
    64           }
    65         }
    67         var tests = [
    68           ["abc", "abc"],
    69           ["\n", ""],
    70           [" \n", ""],
    71           ["\n ", ""],
    72           [" \n ", ""],
    73           [" a", " a"],
    74           ["a ", "a "],
    75           [" a ", " a "],
    76           [" \nabc", "abc"],
    77           ["\n abc", "abc"],
    78           [" \n abc", "abc"],
    79           [" \nabc ", "abc "],
    80           ["\n abc ", "abc "],
    81           [" \n abc ", "abc "],
    82           ["abc\n ", "abc"],
    83           ["abc \n", "abc"],
    84           ["abc \n ", "abc"],
    85           [" abc\n ", " abc"],
    86           [" abc \n", " abc"],
    87           [" abc \n ", " abc"],
    88           [" abc  \n  def \n ", " abcdef"],
    89           ["\n abc  \n  def \n ", "abcdef"],
    90           [" \n abc  \n  def ", "abcdef "],
    91           [" abc\n\ndef ", " abcdef "],
    92           [" abc \n\n def ", " abcdef "],
    93         ];
    95         runNextTest();
    96       });
    98    </script>
    99   </pre>
   100 </body>
   101 </html>

mercurial