1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/extensions/spellcheck/tests/chrome/test_add_remove_dictionaries.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,117 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 + 1.7 +<window title="Add and remove dictionaries test" 1.8 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.9 + onload="RunTest();"> 1.10 + 1.11 + <script type="application/javascript" 1.12 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.13 + 1.14 + <script type="application/javascript"> 1.15 + <![CDATA[ 1.16 +SimpleTest.waitForExplicitFinish(); 1.17 + 1.18 +function getMisspelledWords(editor) { 1.19 + return editor.selectionController.getSelection(Components.interfaces.nsISelectionController.SELECTION_SPELLCHECK).toString(); 1.20 +} 1.21 + 1.22 +function getDictionaryList(editor) { 1.23 + var spellchecker = editor.getInlineSpellChecker(true).spellChecker; 1.24 + var o1 = {}; 1.25 + spellchecker.GetDictionaryList(o1, {}); 1.26 + return o1.value; 1.27 +} 1.28 + 1.29 +function getCurrentDictionary(editor) { 1.30 + var spellchecker = editor.getInlineSpellChecker(true).spellChecker; 1.31 + return spellchecker.GetCurrentDictionary(); 1.32 +} 1.33 + 1.34 +function setCurrentDictionary(editor, dictionary) { 1.35 + var spellchecker = editor.getInlineSpellChecker(true).spellChecker; 1.36 + spellchecker.SetCurrentDictionary(dictionary); 1.37 +} 1.38 + 1.39 +function RunTest() { 1.40 + var textbox = document.getElementById('textbox'); 1.41 + textbox.focus(); 1.42 + var editor = textbox.editor; 1.43 + 1.44 + var dir = Components.classes["@mozilla.org/file/directory_service;1"]. 1.45 + getService(Components.interfaces.nsIProperties). 1.46 + get("CurWorkD", Components.interfaces.nsIFile); 1.47 + dir.append("chrome"); 1.48 + dir.append("extensions"); 1.49 + dir.append("spellcheck"); 1.50 + dir.append("tests"); 1.51 + dir.append("chrome"); 1.52 + 1.53 + var hunspell = Components 1.54 + .classes["@mozilla.org/spellchecker/engine;1"] 1.55 + .getService(Components.interfaces.mozISpellCheckingEngine); 1.56 + 1.57 + // install base dictionary 1.58 + var base = dir.clone(); 1.59 + base.append("base"); 1.60 + ok(base.exists()); 1.61 + hunspell.addDirectory(base); 1.62 + 1.63 + // install map dictionary 1.64 + var map = dir.clone(); 1.65 + map.append("map"); 1.66 + ok(map.exists()); 1.67 + hunspell.addDirectory(map); 1.68 + 1.69 + Components.utils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm"); 1.70 + onSpellCheck(textbox, function () { 1.71 + 1.72 + // test that base and map dictionaries are available 1.73 + var dicts = getDictionaryList(editor); 1.74 + isnot(dicts.indexOf("base_utf"), -1, "base is available"); 1.75 + isnot(dicts.indexOf("maputf"), -1, "map is available"); 1.76 + 1.77 + // select base dictionary 1.78 + setCurrentDictionary(editor, "base_utf"); 1.79 + 1.80 + onSpellCheck(textbox, function () { 1.81 + // test that base dictionary is in use 1.82 + is(getMisspelledWords(editor), "Frühstück" + "qwertyu", "base misspellings"); 1.83 + is(getCurrentDictionary(editor), "base_utf", "current dictionary"); 1.84 + 1.85 + // select map dictionary 1.86 + setCurrentDictionary(editor, "maputf"); 1.87 + 1.88 + onSpellCheck(textbox, function () { 1.89 + // test that map dictionary is in use 1.90 + is(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings"); 1.91 + is(getCurrentDictionary(editor), "maputf", "current dictionary"); 1.92 + 1.93 + // uninstall map dictionary 1.94 + hunspell.removeDirectory(map); 1.95 + 1.96 + onSpellCheck(textbox, function () { 1.97 + // test that map dictionary is not in use 1.98 + isnot(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings"); 1.99 + isnot(getCurrentDictionary(editor), "maputf", "current dictionary"); 1.100 + 1.101 + // test that base dictionary is available and map dictionary is unavailable 1.102 + var dicts = getDictionaryList(editor); 1.103 + isnot(dicts.indexOf("base_utf"), -1, "base is available"); 1.104 + is(dicts.indexOf("maputf"), -1, "map is unavailable"); 1.105 + 1.106 + // uninstall base dictionary 1.107 + hunspell.removeDirectory(base); 1.108 + 1.109 + onSpellCheck(textbox, function () { 1.110 + SimpleTest.finish(); 1.111 + }); 1.112 + }); 1.113 + }); 1.114 + }); 1.115 + }); 1.116 +} 1.117 + ]]> 1.118 + </script> 1.119 + <textbox id="textbox" spellcheck="true" value="created imply Frühstück tomorrow qwertyu"/> 1.120 +</window>