summaryrefslogtreecommitdiffstats
path: root/extensions/spellcheck/tests/chrome/test_add_remove_dictionaries.xhtml
diff options
context:
space:
mode:
Diffstat (limited to 'extensions/spellcheck/tests/chrome/test_add_remove_dictionaries.xhtml')
-rw-r--r--extensions/spellcheck/tests/chrome/test_add_remove_dictionaries.xhtml129
1 files changed, 129 insertions, 0 deletions
diff --git a/extensions/spellcheck/tests/chrome/test_add_remove_dictionaries.xhtml b/extensions/spellcheck/tests/chrome/test_add_remove_dictionaries.xhtml
new file mode 100644
index 0000000000..ae3f42aa67
--- /dev/null
+++ b/extensions/spellcheck/tests/chrome/test_add_remove_dictionaries.xhtml
@@ -0,0 +1,129 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+
+<window title="Add and remove dictionaries test"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ onload="RunTest();">
+
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+ <!-- test results are displayed in the html:body -->
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ </body>
+
+ <script type="application/javascript">
+ <![CDATA[
+SimpleTest.waitForExplicitFinish();
+
+function getMisspelledWords(editor) {
+ return editor.selectionController.getSelection(Ci.nsISelectionController.SELECTION_SPELLCHECK).toString();
+}
+
+function getDictionaryList(editor) {
+ var spellchecker = editor.getInlineSpellChecker(true).spellChecker;
+ return spellchecker.GetDictionaryList();
+}
+
+function getCurrentDictionary(editor) {
+ var spellchecker = editor.getInlineSpellChecker(true).spellChecker;
+ return spellchecker.getCurrentDictionaries()[0];
+}
+
+function setCurrentDictionary(editor, dictionary) {
+ var spellchecker = editor.getInlineSpellChecker(true).spellChecker;
+ return spellchecker.setCurrentDictionaries([dictionary]);
+}
+
+function RunTest() {
+ var textbox = document.getElementById('textbox');
+ textbox.focus();
+ var editor = textbox.editor;
+
+ // 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("chrome");
+ dir.append("extensions");
+ dir.append("spellcheck");
+ dir.append("tests");
+ dir.append("chrome");
+
+ var hunspell = Cc["@mozilla.org/spellchecker/engine;1"]
+ .getService(Ci.mozISpellCheckingEngine);
+
+ // install base dictionary
+ var base = dir.clone();
+ base.append("base");
+ ok(base.exists());
+ hunspell.addDirectory(base);
+
+ // install map dictionary
+ var map = dir.clone();
+ map.append("map");
+ ok(map.exists());
+ hunspell.addDirectory(map);
+
+ const {maybeOnSpellCheck} = ChromeUtils.import(
+ "resource://testing-common/AsyncSpellCheckTestHelper.jsm");
+ maybeOnSpellCheck(textbox, function () {
+
+ // test that base and map dictionaries are available
+ var dicts = getDictionaryList(editor);
+ isnot(dicts.indexOf("base-utf"), -1, "base is available");
+ isnot(dicts.indexOf("maputf"), -1, "map is available");
+
+ // select base dictionary
+ setCurrentDictionary(editor, "base-utf").then(() => {
+ /* eslint-disable no-useless-concat */
+ maybeOnSpellCheck(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");
+
+ // select map dictionary
+ setCurrentDictionary(editor, "maputf").then(() => {
+ // Focus again, so the spelling gets updated.
+ textbox.blur();
+ textbox.focus();
+
+ maybeOnSpellCheck(textbox, function () {
+ // test that map dictionary is in use
+ is(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings (1)");
+ is(getCurrentDictionary(editor), "maputf", "current dictionary");
+
+ // uninstall map dictionary
+ hunspell.removeDirectory(map);
+
+ // Focus again, so the spelling gets updated.
+ textbox.blur();
+ textbox.focus();
+
+ maybeOnSpellCheck(textbox, function () {
+ // test that map dictionary is not in use
+ isnot(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings (2)");
+ isnot(getCurrentDictionary(editor), "maputf", "current dictionary");
+
+ // test that base dictionary is available and map dictionary is unavailable
+ var dicts = getDictionaryList(editor);
+ isnot(dicts.indexOf("base-utf"), -1, "base is available");
+ is(dicts.indexOf("maputf"), -1, "map is unavailable");
+
+ // uninstall base dictionary
+ hunspell.removeDirectory(base);
+
+ maybeOnSpellCheck(textbox, function () {
+ SimpleTest.finish();
+ });
+ });
+ });
+ });
+ });
+ });
+ });
+}
+ ]]>
+ </script>
+ <html:input id="textbox" spellcheck="true" value="created imply Frühstück tomorrow qwertyu"/>
+</window>