Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<html>
<!--
-->
<head>
<title>Test for Bug 678842</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=678842">Mozilla Bug 678842</a>
<p id="display"></p>
<iframe id="content"></iframe>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 678842 **/
SimpleTest.waitForExplicitFinish();
var content = document.getElementById("content");
// load a subframe containing an editor with a defined unknown lang. At first
// load, it will set dictionary to en-US. At second load, it will return current
// dictionary. So, we can check, dictionary is correctly remembered between
// loads.
var firstLoad = true;
var script;
var loadListener = async function(evt) {
if (firstLoad) {
script = SpecialPowers.loadChromeScript(function() {
/* eslint-env mozilla/chrome-script */
// eslint-disable-next-line mozilla/use-services
var dir = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
dir.append("tests");
dir.append("editor");
dir.append("spellchecker");
dir.append("tests");
var hunspell = Cc["@mozilla.org/spellchecker/engine;1"]
.getService(Ci.mozISpellCheckingEngine);
// Install en-GB dictionary.
let en_GB = dir.clone();
en_GB.append("en-GB");
hunspell.addDirectory(en_GB);
addMessageListener("en_GB-exists", () => en_GB.exists());
addMessageListener("destroy", () => hunspell.removeDirectory(en_GB));
});
is(await script.sendQuery("en_GB-exists"), true,
"true expected (en-GB directory should exist)");
}
var doc = evt.target.contentDocument;
var elem = doc.getElementById("textarea");
var editor = SpecialPowers.wrap(elem).editor;
editor.setSpellcheckUserOverride(true);
var inlineSpellChecker = editor.getInlineSpellChecker(true);
const { onSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
);
onSpellCheck(elem, async function() {
let spellchecker = inlineSpellChecker.spellChecker;
let currentDictionaries = spellchecker.getCurrentDictionaries();
is(currentDictionaries.length, 1, "expected one dictionary");
let currentDictionary = currentDictionaries[0];
if (firstLoad) {
firstLoad = false;
// First time around, the dictionary defaults to the locale.
is(currentDictionary, "en-US", "unexpected lang " + currentDictionary + " instead of en-US");
// Select en-GB.
spellchecker.setCurrentDictionaries(["en-GB"]).then(() => {
});
} else {
is(currentDictionary, "en-GB", "unexpected lang " + currentDictionary + " instead of en-GB");
content.removeEventListener("load", loadListener);
// Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
await script.sendQuery("destroy");
// This will clear the content preferences and reset "spellchecker.dictionary".
spellchecker.setCurrentDictionaries([]).then( () => {
SimpleTest.finish();
});
}
});
};
content.addEventListener("load", loadListener);
</script>
</pre>
</body>
</html>