extensions/spellcheck/tests/chrome/test_add_remove_dictionaries.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3
michael@0 4 <window title="Add and remove dictionaries test"
michael@0 5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 6 onload="RunTest();">
michael@0 7
michael@0 8 <script type="application/javascript"
michael@0 9 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 10
michael@0 11 <script type="application/javascript">
michael@0 12 <![CDATA[
michael@0 13 SimpleTest.waitForExplicitFinish();
michael@0 14
michael@0 15 function getMisspelledWords(editor) {
michael@0 16 return editor.selectionController.getSelection(Components.interfaces.nsISelectionController.SELECTION_SPELLCHECK).toString();
michael@0 17 }
michael@0 18
michael@0 19 function getDictionaryList(editor) {
michael@0 20 var spellchecker = editor.getInlineSpellChecker(true).spellChecker;
michael@0 21 var o1 = {};
michael@0 22 spellchecker.GetDictionaryList(o1, {});
michael@0 23 return o1.value;
michael@0 24 }
michael@0 25
michael@0 26 function getCurrentDictionary(editor) {
michael@0 27 var spellchecker = editor.getInlineSpellChecker(true).spellChecker;
michael@0 28 return spellchecker.GetCurrentDictionary();
michael@0 29 }
michael@0 30
michael@0 31 function setCurrentDictionary(editor, dictionary) {
michael@0 32 var spellchecker = editor.getInlineSpellChecker(true).spellChecker;
michael@0 33 spellchecker.SetCurrentDictionary(dictionary);
michael@0 34 }
michael@0 35
michael@0 36 function RunTest() {
michael@0 37 var textbox = document.getElementById('textbox');
michael@0 38 textbox.focus();
michael@0 39 var editor = textbox.editor;
michael@0 40
michael@0 41 var dir = Components.classes["@mozilla.org/file/directory_service;1"].
michael@0 42 getService(Components.interfaces.nsIProperties).
michael@0 43 get("CurWorkD", Components.interfaces.nsIFile);
michael@0 44 dir.append("chrome");
michael@0 45 dir.append("extensions");
michael@0 46 dir.append("spellcheck");
michael@0 47 dir.append("tests");
michael@0 48 dir.append("chrome");
michael@0 49
michael@0 50 var hunspell = Components
michael@0 51 .classes["@mozilla.org/spellchecker/engine;1"]
michael@0 52 .getService(Components.interfaces.mozISpellCheckingEngine);
michael@0 53
michael@0 54 // install base dictionary
michael@0 55 var base = dir.clone();
michael@0 56 base.append("base");
michael@0 57 ok(base.exists());
michael@0 58 hunspell.addDirectory(base);
michael@0 59
michael@0 60 // install map dictionary
michael@0 61 var map = dir.clone();
michael@0 62 map.append("map");
michael@0 63 ok(map.exists());
michael@0 64 hunspell.addDirectory(map);
michael@0 65
michael@0 66 Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm");
michael@0 67 onSpellCheck(textbox, function () {
michael@0 68
michael@0 69 // test that base and map dictionaries are available
michael@0 70 var dicts = getDictionaryList(editor);
michael@0 71 isnot(dicts.indexOf("base_utf"), -1, "base is available");
michael@0 72 isnot(dicts.indexOf("maputf"), -1, "map is available");
michael@0 73
michael@0 74 // select base dictionary
michael@0 75 setCurrentDictionary(editor, "base_utf");
michael@0 76
michael@0 77 onSpellCheck(textbox, function () {
michael@0 78 // test that base dictionary is in use
michael@0 79 is(getMisspelledWords(editor), "Frühstück" + "qwertyu", "base misspellings");
michael@0 80 is(getCurrentDictionary(editor), "base_utf", "current dictionary");
michael@0 81
michael@0 82 // select map dictionary
michael@0 83 setCurrentDictionary(editor, "maputf");
michael@0 84
michael@0 85 onSpellCheck(textbox, function () {
michael@0 86 // test that map dictionary is in use
michael@0 87 is(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings");
michael@0 88 is(getCurrentDictionary(editor), "maputf", "current dictionary");
michael@0 89
michael@0 90 // uninstall map dictionary
michael@0 91 hunspell.removeDirectory(map);
michael@0 92
michael@0 93 onSpellCheck(textbox, function () {
michael@0 94 // test that map dictionary is not in use
michael@0 95 isnot(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings");
michael@0 96 isnot(getCurrentDictionary(editor), "maputf", "current dictionary");
michael@0 97
michael@0 98 // test that base dictionary is available and map dictionary is unavailable
michael@0 99 var dicts = getDictionaryList(editor);
michael@0 100 isnot(dicts.indexOf("base_utf"), -1, "base is available");
michael@0 101 is(dicts.indexOf("maputf"), -1, "map is unavailable");
michael@0 102
michael@0 103 // uninstall base dictionary
michael@0 104 hunspell.removeDirectory(base);
michael@0 105
michael@0 106 onSpellCheck(textbox, function () {
michael@0 107 SimpleTest.finish();
michael@0 108 });
michael@0 109 });
michael@0 110 });
michael@0 111 });
michael@0 112 });
michael@0 113 }
michael@0 114 ]]>
michael@0 115 </script>
michael@0 116 <textbox id="textbox" spellcheck="true" value="created imply Frühstück tomorrow qwertyu"/>
michael@0 117 </window>

mercurial