Bug 432225 - Spell Checker does not always identify misspelled words; r+sr=peterv
authorChris Pearce <chris@pearce.org.nz>
Sat, 01 Nov 2008 01:30:45 +0100
changeset 21162 5587400a222e81838c6684d1a10f3ed9c21dad6c
parent 21161 cdb84fbfb5bb9d407c47f36b426972eb0c579b22
child 21163 78b60e831d3c69108a8daa8d1145059e9830fd3e
push idunknown
push userunknown
push dateunknown
bugs432225
milestone1.9.1b2pre
Bug 432225 - Spell Checker does not always identify misspelled words; r+sr=peterv
editor/libeditor/html/nsHTMLEditRules.cpp
editor/libeditor/html/tests/Makefile.in
editor/libeditor/html/tests/test_bug432225.html
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -544,23 +544,16 @@ nsHTMLEditRules::AfterEditInner(PRInt32 
       mHTMLEditor->mTypeInState->UpdateSelState(selection);
       res = ReapplyCachedStyles();
       if (NS_FAILED(res)) return res;
       res = ClearCachedStyles();
       if (NS_FAILED(res)) return res;
     }    
   }
 
-  // Ensure range offsets are up to date.
-  if (mDocChangeRange) {
-    mDocChangeRange->GetStartContainer(getter_AddRefs(rangeStartParent));
-    mDocChangeRange->GetEndContainer(getter_AddRefs(rangeEndParent));
-    mDocChangeRange->GetStartOffset(&rangeStartOffset);
-    mDocChangeRange->GetEndOffset(&rangeEndOffset);
-  }
   res = mHTMLEditor->HandleInlineSpellCheck(action, selection, 
                                             mRangeItem.startNode, mRangeItem.startOffset,
                                             rangeStartParent, rangeStartOffset,
                                             rangeEndParent, rangeEndOffset);
   if (NS_FAILED(res)) 
     return res;
 
   // detect empty doc
--- a/editor/libeditor/html/tests/Makefile.in
+++ b/editor/libeditor/html/tests/Makefile.in
@@ -40,14 +40,15 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = editor/libeditor/html/tests
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES = \
+		test_bug432225.html \
 		test_bug456244.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
 
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/html/tests/test_bug432225.html
@@ -0,0 +1,96 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=432225
+-->
+<head>
+  <title>Test for Bug 432225</title>
+  <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>  
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=432225">Mozilla Bug 432225</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 432225 **/
+
+SimpleTest.waitForExplicitFinish();
+addLoadEvent(runTest);
+
+var gMisspeltWords = [];
+
+function getEdit() {
+  return document.getElementById('edit');
+}
+
+function editDoc() {
+  return getEdit().contentDocument;
+}
+
+function getSpellCheckSelection() {
+  var Ci = Components.interfaces;
+  var win = editDoc().defaultView;
+  var editingSession = win.QueryInterface(Ci.nsIInterfaceRequestor)
+                          .getInterface(Ci.nsIWebNavigation)
+                          .QueryInterface(Ci.nsIInterfaceRequestor)
+                          .getInterface(Ci.nsIEditingSession);
+  var editor = editingSession.getEditorForWindow(win);
+  var selcon = editor.selectionController;
+  return selcon.getSelection(selcon.SELECTION_SPELLCHECK);  
+}
+
+function runTest() {
+  editDoc().designMode = "on";
+  setTimeout(function() { addWords(100); }, 0);
+}  
+ 
+function addWords(aLimit) {
+  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+  if (aLimit == 0) {
+    is(isSpellingCheckOk(), true, "All misspellings accounted for.");
+    SimpleTest.finish();
+    return;
+  }
+  getEdit().focus();
+  sendChar('a', editDoc());
+  sendChar('a', editDoc());
+  sendChar(' ', editDoc());
+  sendChar('O', editDoc());
+  sendChar('K', editDoc());
+  sendChar(' ', editDoc());
+  gMisspeltWords.push("aa");
+  setTimeout(function() { addWords(aLimit-1); }, 0);
+}
+
+function isSpellingCheckOk() {
+  var sel = getSpellCheckSelection();
+  var numWords = sel.rangeCount;
+  
+  is(numWords, gMisspeltWords.length, "Correct number of misspellings and words.");
+  
+  if (numWords != gMisspeltWords.length) 
+    return false;
+  
+  for (var i=0; i<numWords; i++) {
+    var word = sel.getRangeAt(i);
+    is (word, gMisspeltWords[i], "Misspelling is what we think it is.");
+    if (word != gMisspeltWords[i])
+      return false;
+  }
+  return true;
+}
+
+</script>
+</pre>
+
+<iframe id="edit" width="200" height="100" src="about:blank"></iframe>
+
+</body>
+</html>