Bug 856270 - Update spell checking to use nsIContentPrefService2 (part 3: update other tests). r=ehsan

This commit is contained in:
Drew Willcoxon 2013-06-05 17:07:54 -07:00
Родитель 93d9483a6c
Коммит 8966c4d61e
9 изменённых файлов: 156 добавлений и 143 удалений

Просмотреть файл

@ -21,10 +21,11 @@ Browser context menu tests.
/** Test for Login Manager: multiple login autocomplete. **/ /** Test for Login Manager: multiple login autocomplete. **/
SpecialPowers.Cu.import("resource://gre/modules/InlineSpellChecker.jsm", window); SpecialPowers.Cu.import("resource://gre/modules/InlineSpellChecker.jsm", window);
SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window);
const Ci = SpecialPowers.Ci; const Ci = SpecialPowers.Ci;
function openContextMenuFor(element, shiftkey, shouldWaitForFocus) { function openContextMenuFor(element, shiftkey, waitForSpellCheck) {
// Context menu should be closed before we open it again. // Context menu should be closed before we open it again.
is(SpecialPowers.wrap(contextMenu).state, "closed", "checking if popup is closed"); is(SpecialPowers.wrap(contextMenu).state, "closed", "checking if popup is closed");
@ -39,8 +40,9 @@ function openContextMenuFor(element, shiftkey, shouldWaitForFocus) {
var eventDetails = { type : "contextmenu", button : 2, shiftKey : shiftkey }; var eventDetails = { type : "contextmenu", button : 2, shiftKey : shiftkey };
synthesizeMouse(element, 2, 2, eventDetails, element.ownerDocument.defaultView); synthesizeMouse(element, 2, 2, eventDetails, element.ownerDocument.defaultView);
} }
if (shouldWaitForFocus)
SimpleTest.executeSoon(actuallyOpenContextMenuFor); if (waitForSpellCheck)
onSpellCheck(element, actuallyOpenContextMenuFor);
else else
actuallyOpenContextMenuFor(); actuallyOpenContextMenuFor();
} }
@ -608,7 +610,7 @@ function runTest(testNum) {
].concat(inspectItems)); ].concat(inspectItems));
contextMenu.ownerDocument.getElementById("spell-undo-add-to-dictionary").doCommand(); // Undo add to dictionary contextMenu.ownerDocument.getElementById("spell-undo-add-to-dictionary").doCommand(); // Undo add to dictionary
closeContextMenu(); closeContextMenu();
openContextMenuFor(contenteditable); openContextMenuFor(contenteditable, false, true);
break; break;
case 18: case 18:
@ -633,7 +635,7 @@ function runTest(testNum) {
].concat(inspectItems)); ].concat(inspectItems));
closeContextMenu(); closeContextMenu();
openContextMenuFor(inputspell); // Invoke context menu for next test. openContextMenuFor(inputspell, false, true); // Invoke context menu for next test.
break; break;
case 19: case 19:

Просмотреть файл

@ -20,28 +20,31 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=338427
/** Test for Bug 338427 **/ /** Test for Bug 338427 **/
function init() { function init() {
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
var textarea = document.getElementById("editor"); var textarea = document.getElementById("editor");
var editor = textarea.editor; var editor = textarea.editor;
var spellchecker = editor.getInlineSpellChecker(true); var spellchecker = editor.getInlineSpellChecker(true);
spellchecker.enableRealTimeSpell = true; spellchecker.enableRealTimeSpell = true;
var list = {}, count = {};
spellchecker.spellChecker.GetDictionaryList(list, count);
if (count.value === 0) {
return; // no dictionary, no test possible
}
var lang = list.value[0];
spellchecker.spellChecker.SetCurrentDictionary(lang);
textarea.addEventListener("focus", function() {
var dictionary = "";
try {
dictionary = spellchecker.spellChecker.GetCurrentDictionary();
} catch(e) {}
is(dictionary, lang, "Unexpected spell check dictionary");
SimpleTest.finish();
}, false);
textarea.focus(); textarea.focus();
onSpellCheck(textarea, function () {
var list = {}, count = {};
spellchecker.spellChecker.GetDictionaryList(list, count);
ok(count.value > 0, "At least one dictionary should be present");
var lang = list.value[0];
spellchecker.spellChecker.SetCurrentDictionary(lang);
onSpellCheck(textarea, function () {
try {
var dictionary =
spellchecker.spellChecker.GetCurrentDictionary();
} catch(e) {}
is(dictionary, lang, "Unexpected spell check dictionary");
SimpleTest.finish();
});
});
} }
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();

Просмотреть файл

@ -27,30 +27,33 @@ var content = document.getElementById('content');
var firstLoad = true; var firstLoad = true;
var loadListener = function(evt) { var loadListener = function(evt) {
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
var doc = evt.target.contentDocument; var doc = evt.target.contentDocument;
var elem = doc.getElementById('textarea'); var elem = doc.getElementById('textarea');
var editor = elem.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor; var editor = elem.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
editor.setSpellcheckUserOverride(true); editor.setSpellcheckUserOverride(true);
var inlineSpellChecker = editor.getInlineSpellChecker(true); var inlineSpellChecker = editor.getInlineSpellChecker(true);
var spellchecker = inlineSpellChecker.spellChecker;
var currentDictonary = "";
try {
currentDictonary = spellchecker.GetCurrentDictionary();
} catch(e) {}
if (!currentDictonary) { onSpellCheck(elem, function () {
spellchecker.SetCurrentDictionary('en-US'); var spellchecker = inlineSpellChecker.spellChecker;
} try {
var currentDictonary = spellchecker.GetCurrentDictionary();
} catch(e) {}
if (firstLoad) { if (!currentDictonary) {
firstLoad = false; spellchecker.SetCurrentDictionary('en-US');
is (currentDictonary, "", "unexpected lang " + currentDictonary); }
content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug678842_subframe.html?firstload=false';
} else { if (firstLoad) {
is (currentDictonary, "en-US", "unexpected lang " + currentDictonary + " instead of en-US"); firstLoad = false;
content.removeEventListener('load', loadListener, false); is (currentDictonary, "", "unexpected lang " + currentDictonary);
SimpleTest.finish(); content.src = 'http://mochi.test:8888/tests/editor/composer/test/bug678842_subframe.html?firstload=false';
} } else {
is (currentDictonary, "en-US", "unexpected lang " + currentDictonary + " instead of en-US");
content.removeEventListener('load', loadListener, false);
SimpleTest.finish();
}
});
} }
content.addEventListener('load', loadListener, false); content.addEventListener('load', loadListener, false);

Просмотреть файл

@ -48,7 +48,9 @@ function runTest() {
editDoc().body.innerHTML = "<div>errror and an other errror</div>"; editDoc().body.innerHTML = "<div>errror and an other errror</div>";
gMisspeltWords = ["errror", "errror"]; gMisspeltWords = ["errror", "errror"];
editDoc().designMode = "on"; editDoc().designMode = "on";
setTimeout(function() { evalTest(); }, 0);
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
onSpellCheck(editDoc().documentElement, evalTest);
} }
function evalTest() { function evalTest() {

Просмотреть файл

@ -59,17 +59,19 @@ function runTest() {
gMisspeltWords = ["haz", "cheezburger"]; gMisspeltWords = ["haz", "cheezburger"];
var edit = document.getElementById("edit"); var edit = document.getElementById("edit");
edit.focus(); edit.focus();
SimpleTest.executeSoon(function() {
is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for.");
append(" becaz I'm a lolcat!"); SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window);
SimpleTest.executeSoon(function() { onSpellCheck(edit, function () {
is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for.");
append(" becaz I'm a lolcat!");
onSpellCheck(edit, function () {
gMisspeltWords.push("becaz"); gMisspeltWords.push("becaz");
gMisspeltWords.push("lolcat"); gMisspeltWords.push("lolcat");
is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for."); is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for.");
SimpleTest.finish(); SimpleTest.finish();
}); });
}); });
} }

Просмотреть файл

@ -22,7 +22,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=596333
const Ci = SpecialPowers.Ci; const Ci = SpecialPowers.Ci;
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
addLoadEvent(function() SimpleTest.executeSoon(runTest)); addLoadEvent(runTest);
var gMisspeltWords; var gMisspeltWords;
@ -71,42 +71,39 @@ function paste(str) {
function runOnFocus() { function runOnFocus() {
var edit = document.getElementById("edit"); var edit = document.getElementById("edit");
edit.removeEventListener("focus", runOnFocus, false);
SimpleTest.executeSoon(function() {
gMisspeltWords = ["haz", "cheezburger"];
is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for.");
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 gMisspeltWords = ["haz", "cheezburger"];
// the textarea and see if the spell check after the blur event catches it. is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for.");
append(" workd"); append(" becaz I'm a lolcat!");
edit.blur(); onSpellCheck(edit, function () {
SimpleTest.executeSoon(function() { gMisspeltWords.push("becaz");
gMisspeltWords.push("workd"); gMisspeltWords.push("lolcat");
is(isSpellingCheckOk(), true, "All misspellings after blur are accounted for."); is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for.");
// Also, test the case when we're entering the first word in a textarea // 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();
onSpellCheck(edit, 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 ");
onSpellCheck(edit, 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"]; gMisspeltWords = ["workd"];
edit.value = ""; edit.value = "";
append("workd "); append("workd");
SimpleTest.executeSoon(function() { paste(" x");
is(isSpellingCheckOk(), true, "Misspelling in the first entered word is accounted for."); onSpellCheck(edit, function () {
is(isSpellingCheckOk(), true, "Misspelling is accounted for after pasting.");
// Make sure that pasting would also trigger spell checking for the previous word SimpleTest.finish();
gMisspeltWords = ["workd"];
edit.value = "";
append("workd");
paste(" x");
SimpleTest.executeSoon(function() {
is(isSpellingCheckOk(), true, "Misspelling is accounted for after pasting.");
SimpleTest.finish();
});
}); });
}); });
}); });
@ -116,8 +113,10 @@ function runOnFocus() {
function runTest() function runTest()
{ {
var edit = document.getElementById("edit"); var edit = document.getElementById("edit");
edit.addEventListener("focus", runOnFocus, false);
edit.focus(); edit.focus();
SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window);
onSpellCheck(edit, runOnFocus);
} }
function isSpellingCheckOk() { function isSpellingCheckOk() {

Просмотреть файл

@ -30,42 +30,31 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=636465
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
function runTest() { function runTest() {
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
var x = document.getElementById("x"); var x = document.getElementById("x");
x.focus(); x.focus();
setTimeout(function(){ onSpellCheck(x, function () {
x.blur(); x.blur();
setTimeout(function(){ var spellCheckTrue = snapshotWindow(window);
var spellCheckTrue = snapshotWindow(window); x.setAttribute("spellcheck", "false");
x.setAttribute("spellcheck", "false"); var spellCheckFalse = snapshotWindow(window);
setTimeout(function(){ x.setAttribute("spellcheck", "true");
setTimeout(function(){ x.focus();
var spellCheckFalse = snapshotWindow(window); onSpellCheck(x, function () {
x.setAttribute("spellcheck", "true"); x.blur();
x.focus(); var spellCheckTrueAgain = snapshotWindow(window);
setTimeout(function(){ x.removeAttribute("spellcheck");
x.blur(); var spellCheckNone = snapshotWindow(window);
setTimeout(function(){ var after = snapshotWindow(window);
var spellCheckTrueAgain = snapshotWindow(window); ok(compareSnapshots(spellCheckTrue, spellCheckFalse, false)[0],
x.removeAttribute("spellcheck"); "Setting the spellcheck attribute to false should work");
setTimeout(function(){ ok(compareSnapshots(spellCheckTrue, spellCheckTrueAgain, true)[0],
setTimeout(function(){ "Setting the spellcheck attribute back to true should work");
var spellCheckNone = snapshotWindow(window); ok(compareSnapshots(spellCheckNone, spellCheckFalse, true)[0],
var after = snapshotWindow(window); "Unsetting the spellcheck attribute should work");
ok(compareSnapshots(spellCheckTrue, spellCheckFalse, false)[0], SimpleTest.finish();
"Setting the spellcheck attribute to false should work"); });
ok(compareSnapshots(spellCheckTrue, spellCheckTrueAgain, true)[0], });
"Setting the spellcheck attribute back to true should work");
ok(compareSnapshots(spellCheckNone, spellCheckFalse, true)[0],
"Unsetting the spellcheck attribute should work");
SimpleTest.finish();
},0);
},0);
},0);
},0);
},0);
},0);
},0);
},0);
} }
]]> ]]>
</script> </script>

Просмотреть файл

@ -64,44 +64,50 @@ function RunTest() {
ok(map.exists()); ok(map.exists());
hunspell.addDirectory(map); hunspell.addDirectory(map);
// test that base and map dictionaries are available Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
var dicts = getDictionaryList(editor); onSpellCheck(textbox, function () {
isnot(dicts.indexOf("base_utf"), -1, "base is available");
isnot(dicts.indexOf("maputf"), -1, "map is available");
// select base dictionary // test that base and map dictionaries are available
setCurrentDictionary(editor, "base_utf"); var dicts = getDictionaryList(editor);
isnot(dicts.indexOf("base_utf"), -1, "base is available");
isnot(dicts.indexOf("maputf"), -1, "map is available");
SimpleTest.executeSoon(function() { // select base dictionary
// test that base dictionary is in use setCurrentDictionary(editor, "base_utf");
is(getMisspelledWords(editor), "Frühstück" + "qwertyu", "base misspellings");
is(getCurrentDictionary(editor), "base_utf", "current dictionary");
// select map dictionary onSpellCheck(textbox, function () {
setCurrentDictionary(editor, "maputf"); // test that base dictionary is in use
is(getMisspelledWords(editor), "Frühstück" + "qwertyu", "base misspellings");
is(getCurrentDictionary(editor), "base_utf", "current dictionary");
SimpleTest.executeSoon(function() { // select map dictionary
// test that map dictionary is in use setCurrentDictionary(editor, "maputf");
is(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings");
is(getCurrentDictionary(editor), "maputf", "current dictionary");
// uninstall map dictionary onSpellCheck(textbox, function () {
hunspell.removeDirectory(map); // test that map dictionary is in use
is(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings");
is(getCurrentDictionary(editor), "maputf", "current dictionary");
SimpleTest.executeSoon(function() { // uninstall map dictionary
// test that map dictionary is not in use hunspell.removeDirectory(map);
isnot(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings");
isnot(getCurrentDictionary(editor), "maputf", "current dictionary");
// test that base dictionary is available and map dictionary is unavailable onSpellCheck(textbox, function () {
var dicts = getDictionaryList(editor); // test that map dictionary is not in use
isnot(dicts.indexOf("base_utf"), -1, "base is available"); isnot(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings");
is(dicts.indexOf("maputf"), -1, "map is unavailable"); isnot(getCurrentDictionary(editor), "maputf", "current dictionary");
// uninstall base dictionary // test that base dictionary is available and map dictionary is unavailable
hunspell.removeDirectory(base); var dicts = getDictionaryList(editor);
isnot(dicts.indexOf("base_utf"), -1, "base is available");
is(dicts.indexOf("maputf"), -1, "map is unavailable");
SimpleTest.finish(); // uninstall base dictionary
hunspell.removeDirectory(base);
onSpellCheck(textbox, function () {
SimpleTest.finish();
});
});
}); });
}); });
}); });

Просмотреть файл

@ -40,7 +40,10 @@ function startTests()
textbox.focus(); textbox.focus();
testNum = 0; testNum = 0;
SimpleTest.executeSoon( function() { bringUpContextMenu(textbox); }); Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
onSpellCheck(textbox, function () {
bringUpContextMenu(textbox);
});
} }
function runContextMenuTest() function runContextMenuTest()
@ -65,7 +68,9 @@ function runContextMenuTest()
contextMenu.hidePopup(); contextMenu.hidePopup();
testNum++; testNum++;
SimpleTest.executeSoon( function() {bringUpContextMenu(textbox); }); // Bring up the menu again to invoke the next test onSpellCheck(textbox, function () {
bringUpContextMenu(textbox);
});
break; break;
case 1: // "Undo Add to Dictionary" button case 1: // "Undo Add to Dictionary" button
@ -78,7 +83,9 @@ function runContextMenuTest()
undoAddDict.doCommand(); undoAddDict.doCommand();
contextMenu.hidePopup(); contextMenu.hidePopup();
SimpleTest.finish(); onSpellCheck(textbox, function () {
SimpleTest.finish();
});
break; break;
} }
}); });