Bug 949614 - Consolidate some spellchecking test code; r=ehsan

This commit is contained in:
Ms2ger 2015-04-14 15:26:14 +02:00
Родитель dd354aa828
Коммит 3688595ddd
7 изменённых файлов: 48 добавлений и 107 удалений

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

@ -4,6 +4,7 @@ support-files = green.png
[test_bug46555.html]
[test_bug366682.html]
support-files = spellcheck.js
[test_bug471319.html]
[test_bug483651.html]
[test_bug489202.xul]

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

@ -11,6 +11,7 @@ support-files =
file_bug674770-1.html
file_select_all_without_body.html
green.png
spellcheck.js
[test_bug200416.html]
[test_bug289384.html]

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

@ -0,0 +1,20 @@
function isSpellingCheckOk(aEditor, aMisspelledWords) {
var selcon = aEditor.selectionController;
var sel = selcon.getSelection(selcon.SELECTION_SPELLCHECK);
var numWords = sel.rangeCount;
is(numWords, aMisspelledWords.length, "Correct number of misspellings and words.");
if (numWords != aMisspelledWords.length) {
return false;
}
for (var i = 0; i < numWords; ++i) {
var word = sel.getRangeAt(i);
is(word, aMisspelledWords[i], "Misspelling is what we think it is.");
if (word != aMisspelledWords[i]) {
return false;
}
}
return true;
}

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

@ -8,6 +8,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=366682
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script src="spellcheck.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=366682">Mozilla Bug 366682</a>
@ -32,16 +33,14 @@ function editDoc() {
return getEdit().contentDocument;
}
function getSpellCheckSelection() {
function getEditor() {
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);
return editingSession.getEditorForWindow(win);
}
function runTest() {
@ -54,28 +53,10 @@ function runTest() {
}
function evalTest() {
is(isSpellingCheckOk(), true, "All misspellings accounted for.");
ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
"All misspellings accounted for.");
SimpleTest.finish();
}
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>

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

@ -8,6 +8,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=432225
<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>
<script src="spellcheck.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=432225">Mozilla Bug 432225</a>
@ -33,7 +34,7 @@ function editDoc() {
return getEdit().contentDocument;
}
function getSpellCheckSelection() {
function getEditor() {
var Ci = SpecialPowers.Ci;
var win = editDoc().defaultView;
var editingSession = SpecialPowers.wrap(win)
@ -41,9 +42,7 @@ function getSpellCheckSelection() {
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEditingSession);
var editor = editingSession.getEditorForWindow(win);
var selcon = editor.selectionController;
return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
return editingSession.getEditorForWindow(win);
}
function runTest() {
@ -53,7 +52,8 @@ function runTest() {
function addWords(aLimit) {
if (aLimit == 0) {
is(isSpellingCheckOk(), true, "All misspellings accounted for.");
ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
"All misspellings accounted for.");
SimpleTest.finish();
return;
}
@ -62,25 +62,6 @@ function addWords(aLimit) {
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>

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

@ -8,6 +8,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=484181
<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>
<script src="spellcheck.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=484181">Mozilla Bug 484181</a>
@ -35,14 +36,7 @@ function getEditor() {
return editingSession.getEditorForWindow(win);
}
function getSpellCheckSelection() {
var editor = getEditor();
var selcon = editor.selectionController;
return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
}
function append(str) {
var edit = document.getElementById("edit");
var editor = getEditor();
var sel = editor.selection;
@ -61,38 +55,20 @@ function runTest() {
SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window);
onSpellCheck(edit, function () {
is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for.");
ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
"All misspellings before editing are accounted for.");
append(" becaz I'm a lulcat!");
onSpellCheck(edit, function () {
gMisspeltWords.push("becaz");
gMisspeltWords.push("lulcat");
is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for.");
ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
"All misspellings after typing are accounted for.");
SimpleTest.finish();
});
});
}
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>

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

@ -8,6 +8,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=596333
<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>
<script src="spellcheck.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=596333">Mozilla Bug 596333</a>
@ -30,12 +31,6 @@ function getEditor() {
return SpecialPowers.wrap(document.getElementById("edit")).editor;
}
function getSpellCheckSelection() {
var editor = getEditor();
var selcon = editor.selectionController;
return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
}
function append(str) {
var edit = document.getElementById("edit");
edit.focus();
@ -70,12 +65,14 @@ function runOnFocus() {
var edit = document.getElementById("edit");
gMisspeltWords = ["haz", "cheezburger"];
is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for.");
ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
"All misspellings before editing are accounted for.");
append(" becaz I'm a lulcat!");
onSpellCheck(edit, function () {
gMisspeltWords.push("becaz");
gMisspeltWords.push("lulcat");
is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for.");
ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
"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.
@ -83,14 +80,16 @@ function runOnFocus() {
edit.blur();
onSpellCheck(edit, function () {
gMisspeltWords.push("workd");
is(isSpellingCheckOk(), true, "All misspellings after blur are accounted for.");
ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
"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.");
ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
"Misspelling in the first entered word is accounted for.");
// Make sure that pasting would also trigger spell checking for the previous word
gMisspeltWords = ["workd"];
@ -98,7 +97,8 @@ function runOnFocus() {
append("workd");
paste(" x");
onSpellCheck(edit, function () {
is(isSpellingCheckOk(), true, "Misspelling is accounted for after pasting.");
ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
"Misspelling is accounted for after pasting.");
SimpleTest.finish();
});
@ -115,25 +115,6 @@ function runTest()
SpecialPowers.Cu.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window);
onSpellCheck(edit, runOnFocus);
}
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>