editor/libeditor/html/tests/test_bug790475.html

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=790475
     5 -->
     6 <head>
     7   <title>Test for Bug 790475</title>
     8   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    10   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    11 </head>
    12 <body>
    13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=790475">Mozilla Bug 790475</a>
    14 <p id="display"></p>
    15 <div id="content" style="display: none"></div>
    16 <pre id="test">
    17 <script type="application/javascript">
    19 /**
    20  * Test for Bug 790475
    21  *
    22  * Tests that inline spell checking works properly through adjacent text nodes.
    23  */
    25 SimpleTest.waitForExplicitFinish();
    26 addLoadEvent(runTest);
    28 var gMisspeltWords;
    30 function getEditor() {
    31   const Ci = SpecialPowers.Ci;
    32   var editingSession = SpecialPowers.wrap(window)
    33                                     .QueryInterface(Ci.nsIInterfaceRequestor)
    34                                     .getInterface(Ci.nsIWebNavigation)
    35                                     .QueryInterface(Ci.nsIInterfaceRequestor)
    36                                     .getInterface(Ci.nsIEditingSession);
    37   return editingSession.getEditorForWindow(window);
    38 }
    40 function getSpellCheckSelection() {
    41   var editor = getEditor();
    42   var selcon = editor.selectionController;
    43   return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
    44 }
    46 function runTest() {
    47   gMisspeltWords = [];
    48   var edit = document.getElementById("edit");
    49   edit.focus();
    51   SimpleTest.executeSoon(function() {
    52     gMisspeltWords = [];
    53     is(isSpellingCheckOk(), true, "Should not find any misspellings yet.");
    55     var newTextNode = document.createTextNode("ing string");
    56     edit.appendChild(newTextNode);
    57     var editor = getEditor();
    58     var sel = editor.selection;
    59     sel.collapse(newTextNode, newTextNode.textContent.length);
    60     synthesizeKey("!", {});
    62     edit.blur();
    64     SimpleTest.executeSoon(function() {
    65       is(isSpellingCheckOk(), true, "Should not have found any misspellings. ");
    66       SimpleTest.finish();
    67     });
    68   });
    69 }
    71 function isSpellingCheckOk() {
    72   var sel = getSpellCheckSelection();
    73   var numWords = sel.rangeCount;
    75   is(numWords, gMisspeltWords.length, "Correct number of misspellings and words.");
    77   if (numWords != gMisspeltWords.length)
    78     return false;
    80   for (var i = 0; i < numWords; i++) {
    81     var word = sel.getRangeAt(i);
    82     is (word, gMisspeltWords[i], "Misspelling is what we think it is.");
    83     if (word != gMisspeltWords[i])
    84       return false;
    85   }
    86   return true;
    87 }
    89 </script>
    90 </pre>
    92 <div id="edit" contenteditable="true">This is a test</div>
    94 </body>
    95 </html>

mercurial