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. **/
SpecialPowers.Cu.import("resource://gre/modules/InlineSpellChecker.jsm", window);
SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window);
const Ci = SpecialPowers.Ci;
function openContextMenuFor(element, shiftkey, shouldWaitForFocus) {
function openContextMenuFor(element, shiftkey, waitForSpellCheck) {
// Context menu should be closed before we open it again.
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 };
synthesizeMouse(element, 2, 2, eventDetails, element.ownerDocument.defaultView);
}
if (shouldWaitForFocus)
SimpleTest.executeSoon(actuallyOpenContextMenuFor);
if (waitForSpellCheck)
onSpellCheck(element, actuallyOpenContextMenuFor);
else
actuallyOpenContextMenuFor();
}
@ -608,7 +610,7 @@ function runTest(testNum) {
].concat(inspectItems));
contextMenu.ownerDocument.getElementById("spell-undo-add-to-dictionary").doCommand(); // Undo add to dictionary
closeContextMenu();
openContextMenuFor(contenteditable);
openContextMenuFor(contenteditable, false, true);
break;
case 18:
@ -633,7 +635,7 @@ function runTest(testNum) {
].concat(inspectItems));
closeContextMenu();
openContextMenuFor(inputspell); // Invoke context menu for next test.
openContextMenuFor(inputspell, false, true); // Invoke context menu for next test.
break;
case 19:

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

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

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

@ -27,15 +27,17 @@ var content = document.getElementById('content');
var firstLoad = true;
var loadListener = function(evt) {
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
var doc = evt.target.contentDocument;
var elem = doc.getElementById('textarea');
var editor = elem.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
editor.setSpellcheckUserOverride(true);
var inlineSpellChecker = editor.getInlineSpellChecker(true);
onSpellCheck(elem, function () {
var spellchecker = inlineSpellChecker.spellChecker;
var currentDictonary = "";
try {
currentDictonary = spellchecker.GetCurrentDictionary();
var currentDictonary = spellchecker.GetCurrentDictionary();
} catch(e) {}
if (!currentDictonary) {
@ -51,6 +53,7 @@ var loadListener = function(evt) {
content.removeEventListener('load', loadListener, false);
SimpleTest.finish();
}
});
}
content.addEventListener('load', loadListener, false);

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

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

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

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

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

@ -22,7 +22,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=596333
const Ci = SpecialPowers.Ci;
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() SimpleTest.executeSoon(runTest));
addLoadEvent(runTest);
var gMisspeltWords;
@ -71,13 +71,11 @@ function paste(str) {
function runOnFocus() {
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() {
onSpellCheck(edit, function () {
gMisspeltWords.push("becaz");
gMisspeltWords.push("lolcat");
is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for.");
@ -86,7 +84,7 @@ function runOnFocus() {
// the textarea and see if the spell check after the blur event catches it.
append(" workd");
edit.blur();
SimpleTest.executeSoon(function() {
onSpellCheck(edit, function () {
gMisspeltWords.push("workd");
is(isSpellingCheckOk(), true, "All misspellings after blur are accounted for.");
@ -94,7 +92,7 @@ function runOnFocus() {
gMisspeltWords = ["workd"];
edit.value = "";
append("workd ");
SimpleTest.executeSoon(function() {
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
@ -102,7 +100,7 @@ function runOnFocus() {
edit.value = "";
append("workd");
paste(" x");
SimpleTest.executeSoon(function() {
onSpellCheck(edit, function () {
is(isSpellingCheckOk(), true, "Misspelling is accounted for after pasting.");
SimpleTest.finish();
@ -110,14 +108,15 @@ function runOnFocus() {
});
});
});
});
}
function runTest()
{
var edit = document.getElementById("edit");
edit.addEventListener("focus", runOnFocus, false);
edit.focus();
SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window);
onSpellCheck(edit, runOnFocus);
}
function isSpellingCheckOk() {

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

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

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

@ -64,6 +64,9 @@ function RunTest() {
ok(map.exists());
hunspell.addDirectory(map);
Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
onSpellCheck(textbox, function () {
// test that base and map dictionaries are available
var dicts = getDictionaryList(editor);
isnot(dicts.indexOf("base_utf"), -1, "base is available");
@ -72,7 +75,7 @@ function RunTest() {
// select base dictionary
setCurrentDictionary(editor, "base_utf");
SimpleTest.executeSoon(function() {
onSpellCheck(textbox, function () {
// test that base dictionary is in use
is(getMisspelledWords(editor), "Frühstück" + "qwertyu", "base misspellings");
is(getCurrentDictionary(editor), "base_utf", "current dictionary");
@ -80,7 +83,7 @@ function RunTest() {
// select map dictionary
setCurrentDictionary(editor, "maputf");
SimpleTest.executeSoon(function() {
onSpellCheck(textbox, function () {
// test that map dictionary is in use
is(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings");
is(getCurrentDictionary(editor), "maputf", "current dictionary");
@ -88,7 +91,7 @@ function RunTest() {
// uninstall map dictionary
hunspell.removeDirectory(map);
SimpleTest.executeSoon(function() {
onSpellCheck(textbox, function () {
// test that map dictionary is not in use
isnot(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings");
isnot(getCurrentDictionary(editor), "maputf", "current dictionary");
@ -101,10 +104,13 @@ function RunTest() {
// uninstall base dictionary
hunspell.removeDirectory(base);
onSpellCheck(textbox, function () {
SimpleTest.finish();
});
});
});
});
});
}
]]>
</script>

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

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