gecko/editor/libeditor/html/tests/test_bug484181.html

102 lines
2.8 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=484181
-->
<head>
<title>Test for Bug 484181</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=484181">Mozilla Bug 484181</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 484181 **/
SimpleTest.waitForExplicitFinish();
addLoadEvent(runTest);
var gMisspeltWords;
function getEditor() {
var Ci = Components.interfaces;
var win = window;
var editingSession = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIEditingSession);
return editingSession.getEditorForWindow(win);
}
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();
var sel = editor.selection;
sel.selectAllChildren(edit);
sel.collapseToEnd();
for (var i = 0; i < str.length; ++i) {
synthesizeKey(str[i], {});
}
}
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.");
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>
<div><div></div><div id="edit" contenteditable="true">I can haz cheezburger</div></div>
</body>
</html>