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.

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

mercurial