mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-24 13:52:37 +00:00
Bug 596333 - Automatic spell checking not always functional after bug 240933; r=roc a=blocking-betaN+
This commit is contained in:
parent
3f3aa6f1ff
commit
b37718301c
@ -48,6 +48,7 @@ _TEST_FILES = \
|
||||
test_bug471722.html \
|
||||
test_bug569988.html \
|
||||
test_bug590554.html \
|
||||
test_bug596333.html \
|
||||
$(NULL)
|
||||
|
||||
# disables the key handling test on gtk2 because gtk2 overrides some key events
|
||||
|
134
editor/libeditor/text/tests/test_bug596333.html
Normal file
134
editor/libeditor/text/tests/test_bug596333.html
Normal file
@ -0,0 +1,134 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=596333
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 596333</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.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=596333">Mozilla Bug 596333</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 596333 **/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(function() SimpleTest.executeSoon(runTest));
|
||||
|
||||
var gMisspeltWords;
|
||||
|
||||
function getEditor() {
|
||||
var Ci = Components.interfaces;
|
||||
return document.getElementById("edit")
|
||||
.QueryInterface(Ci.nsIDOMNSEditableElement)
|
||||
.editor;
|
||||
}
|
||||
|
||||
function getSpellCheckSelection() {
|
||||
var editor = getEditor();
|
||||
var selcon = editor.selectionController;
|
||||
return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
|
||||
}
|
||||
|
||||
function append(str) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
var edit = document.getElementById("edit");
|
||||
edit.focus();
|
||||
var editor = getEditor();
|
||||
|
||||
for (var i = 0; i < str.length; ++i) {
|
||||
synthesizeKey(str[i], {});
|
||||
}
|
||||
}
|
||||
|
||||
function paste(str) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
var edit = document.getElementById("edit");
|
||||
var Cc = Components.classes, Ci = Components.interfaces;
|
||||
var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
|
||||
var s = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
|
||||
s.data = str;
|
||||
trans.setTransferData("text/unicode", s, str.length * 2);
|
||||
|
||||
getEditor().pasteTransferable(trans);
|
||||
}
|
||||
|
||||
function runTest() {
|
||||
gMisspeltWords = ["haz", "cheezburger"];
|
||||
is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for.");
|
||||
|
||||
var edit = document.getElementById("edit");
|
||||
append(" becaz I'm a lolcat!");
|
||||
SimpleTest.executeSoon(function() {
|
||||
gMisspeltWords.push("becaz");
|
||||
gMisspeltWords.push("lolcat");
|
||||
is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for.");
|
||||
|
||||
// Now, type an invalid word, and instead of hitting "space" at the end, just blur
|
||||
// the textarea and see if the spell check after the blur event catches it.
|
||||
append(" workd");
|
||||
edit.blur();
|
||||
SimpleTest.executeSoon(function() {
|
||||
gMisspeltWords.push("workd");
|
||||
is(isSpellingCheckOk(), true, "All misspellings after blur are accounted for.");
|
||||
|
||||
// Also, test the case when we're entering the first word in a textarea
|
||||
gMisspeltWords = ["workd"];
|
||||
edit.value = "";
|
||||
append("workd ");
|
||||
SimpleTest.executeSoon(function() {
|
||||
is(isSpellingCheckOk(), true, "Misspelling in the first entered word is accounted for.");
|
||||
|
||||
// Make sure that pasting would also trigger spell checking for the previous word
|
||||
gMisspeltWords = ["workd"];
|
||||
edit.value = "";
|
||||
append("workd");
|
||||
paste(" x");
|
||||
SimpleTest.executeSoon(function() {
|
||||
is(isSpellingCheckOk(), true, "Misspelling is accounted for after pasting.");
|
||||
|
||||
SimpleTest.finish();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function isSpellingCheckOk() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
|
||||
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>
|
||||
|
||||
<textarea id="edit">I can haz cheezburger</textarea>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -560,8 +560,25 @@ mozInlineSpellWordUtil::BuildSoftText()
|
||||
PRInt32 firstOffsetInNode = 0;
|
||||
PRInt32 checkBeforeOffset = mSoftBegin.mOffset;
|
||||
while (node) {
|
||||
if (ContainsDOMWordSeparator(node, checkBeforeOffset, &firstOffsetInNode))
|
||||
if (ContainsDOMWordSeparator(node, checkBeforeOffset, &firstOffsetInNode)) {
|
||||
if (node == mSoftBegin.mNode) {
|
||||
// If we find a word separator on the first node, look at the preceding
|
||||
// word on the text node as well.
|
||||
PRInt32 newOffset = 0;
|
||||
if (firstOffsetInNode > 0) {
|
||||
// Try to find the previous word boundary. We ignore the return value
|
||||
// of ContainsDOMWordSeparator here because there might be no preceding
|
||||
// word separator (such as when we're at the end of the first word in
|
||||
// the text node), in which case we just set the found offsets to 0.
|
||||
// Otherwise, ContainsDOMWordSeparator finds us the correct word
|
||||
// boundary so that we can avoid looking at too many words.
|
||||
ContainsDOMWordSeparator(node, firstOffsetInNode - 1, &newOffset);
|
||||
}
|
||||
firstOffsetInNode = newOffset;
|
||||
mSoftBegin.mOffset = newOffset;
|
||||
}
|
||||
break;
|
||||
}
|
||||
checkBeforeOffset = PR_INT32_MAX;
|
||||
if (IsBreakElement(mCSSView, node)) {
|
||||
// Since FindPrevNode follows tree *preorder*, we're about to traverse
|
||||
|
Loading…
x
Reference in New Issue
Block a user