tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug790475.html (2316B)


      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 src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10  <script 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">
     18 
     19 /**
     20 * Test for Bug 790475
     21 *
     22 * Tests that inline spell checking works properly through adjacent text nodes.
     23 */
     24 
     25 SimpleTest.waitForExplicitFinish();
     26 addLoadEvent(runTest);
     27 
     28 var gMisspeltWords;
     29 
     30 function getEditor() {
     31  var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
     32  return editingSession.getEditorForWindow(window);
     33 }
     34 
     35 function getSpellCheckSelection() {
     36  var editor = getEditor();
     37  var selcon = editor.selectionController;
     38  return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
     39 }
     40 
     41 function runTest() {
     42  gMisspeltWords = [];
     43  var edit = document.getElementById("edit");
     44  edit.focus();
     45 
     46  SimpleTest.executeSoon(function() {
     47    gMisspeltWords = [];
     48    is(isSpellingCheckOk(), true, "Should not find any misspellings yet.");
     49 
     50    var newTextNode = document.createTextNode("ing string");
     51    edit.appendChild(newTextNode);
     52    var editor = getEditor();
     53    var sel = editor.selection;
     54    sel.collapse(newTextNode, newTextNode.textContent.length);
     55    sendString("!");
     56 
     57    edit.blur();
     58 
     59    SimpleTest.executeSoon(function() {
     60      is(isSpellingCheckOk(), true, "Should not have found any misspellings. ");
     61      SimpleTest.finish();
     62    });
     63  });
     64 }
     65 
     66 function isSpellingCheckOk() {
     67  var sel = getSpellCheckSelection();
     68  var numWords = sel.rangeCount;
     69 
     70  is(numWords, gMisspeltWords.length, "Correct number of misspellings and words.");
     71 
     72  if (numWords != gMisspeltWords.length)
     73    return false;
     74 
     75  for (var i = 0; i < numWords; i++) {
     76    var word = sel.getRangeAt(i);
     77    is(word, gMisspeltWords[i], "Misspelling is what we think it is.");
     78    if (word != gMisspeltWords[i])
     79      return false;
     80  }
     81  return true;
     82 }
     83 
     84 </script>
     85 </pre>
     86 
     87 <div id="edit" contenteditable="true">This is a test</div>
     88 
     89 </body>
     90 </html>