editor/libeditor/html/tests/test_bug790475.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/html/tests/test_bug790475.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=790475
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 790475</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=790475">Mozilla Bug 790475</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content" style="display: none"></div>
    1.19 +<pre id="test">
    1.20 +<script type="application/javascript">
    1.21 +
    1.22 +/**
    1.23 + * Test for Bug 790475
    1.24 + *
    1.25 + * Tests that inline spell checking works properly through adjacent text nodes.
    1.26 + */
    1.27 +
    1.28 +SimpleTest.waitForExplicitFinish();
    1.29 +addLoadEvent(runTest);
    1.30 +
    1.31 +var gMisspeltWords;
    1.32 +
    1.33 +function getEditor() {
    1.34 +  const Ci = SpecialPowers.Ci;
    1.35 +  var editingSession = SpecialPowers.wrap(window)
    1.36 +                                    .QueryInterface(Ci.nsIInterfaceRequestor)
    1.37 +                                    .getInterface(Ci.nsIWebNavigation)
    1.38 +                                    .QueryInterface(Ci.nsIInterfaceRequestor)
    1.39 +                                    .getInterface(Ci.nsIEditingSession);
    1.40 +  return editingSession.getEditorForWindow(window);
    1.41 +}
    1.42 +
    1.43 +function getSpellCheckSelection() {
    1.44 +  var editor = getEditor();
    1.45 +  var selcon = editor.selectionController;
    1.46 +  return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
    1.47 +}
    1.48 +
    1.49 +function runTest() {
    1.50 +  gMisspeltWords = [];
    1.51 +  var edit = document.getElementById("edit");
    1.52 +  edit.focus();
    1.53 +
    1.54 +  SimpleTest.executeSoon(function() {
    1.55 +    gMisspeltWords = [];
    1.56 +    is(isSpellingCheckOk(), true, "Should not find any misspellings yet.");
    1.57 +
    1.58 +    var newTextNode = document.createTextNode("ing string");
    1.59 +    edit.appendChild(newTextNode);
    1.60 +    var editor = getEditor();
    1.61 +    var sel = editor.selection;
    1.62 +    sel.collapse(newTextNode, newTextNode.textContent.length);
    1.63 +    synthesizeKey("!", {});
    1.64 +
    1.65 +    edit.blur();
    1.66 +
    1.67 +    SimpleTest.executeSoon(function() {
    1.68 +      is(isSpellingCheckOk(), true, "Should not have found any misspellings. ");
    1.69 +      SimpleTest.finish();
    1.70 +    });
    1.71 +  });
    1.72 +}
    1.73 +
    1.74 +function isSpellingCheckOk() {
    1.75 +  var sel = getSpellCheckSelection();
    1.76 +  var numWords = sel.rangeCount;
    1.77 +
    1.78 +  is(numWords, gMisspeltWords.length, "Correct number of misspellings and words.");
    1.79 +
    1.80 +  if (numWords != gMisspeltWords.length)
    1.81 +    return false;
    1.82 +
    1.83 +  for (var i = 0; i < numWords; i++) {
    1.84 +    var word = sel.getRangeAt(i);
    1.85 +    is (word, gMisspeltWords[i], "Misspelling is what we think it is.");
    1.86 +    if (word != gMisspeltWords[i])
    1.87 +      return false;
    1.88 +  }
    1.89 +  return true;
    1.90 +}
    1.91 +
    1.92 +</script>
    1.93 +</pre>
    1.94 +
    1.95 +<div id="edit" contenteditable="true">This is a test</div>
    1.96 +
    1.97 +</body>
    1.98 +</html>

mercurial