test_add_remove_dictionaries.xhtml (4503B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 3 4 <window title="Add and remove dictionaries test" 5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 6 xmlns:html="http://www.w3.org/1999/xhtml" 7 onload="RunTest();"> 8 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 10 11 <!-- test results are displayed in the html:body --> 12 <body xmlns="http://www.w3.org/1999/xhtml"> 13 </body> 14 15 <script type="application/javascript"> 16 <![CDATA[ 17 SimpleTest.waitForExplicitFinish(); 18 19 function getMisspelledWords(editor) { 20 return editor.selectionController.getSelection(Ci.nsISelectionController.SELECTION_SPELLCHECK).toString(); 21 } 22 23 function getDictionaryList(editor) { 24 var spellchecker = editor.getInlineSpellChecker(true).spellChecker; 25 return spellchecker.GetDictionaryList(); 26 } 27 28 function getCurrentDictionary(editor) { 29 var spellchecker = editor.getInlineSpellChecker(true).spellChecker; 30 return spellchecker.getCurrentDictionaries()[0]; 31 } 32 33 function setCurrentDictionary(editor, dictionary) { 34 var spellchecker = editor.getInlineSpellChecker(true).spellChecker; 35 return spellchecker.setCurrentDictionaries([dictionary]); 36 } 37 38 function RunTest() { 39 var textbox = document.getElementById('textbox'); 40 textbox.focus(); 41 var editor = textbox.editor; 42 43 // eslint-disable-next-line mozilla/use-services 44 var dir = Cc["@mozilla.org/file/directory_service;1"]. 45 getService(Ci.nsIProperties). 46 get("CurWorkD", Ci.nsIFile); 47 dir.append("chrome"); 48 dir.append("extensions"); 49 dir.append("spellcheck"); 50 dir.append("tests"); 51 dir.append("chrome"); 52 53 var hunspell = Cc["@mozilla.org/spellchecker/engine;1"] 54 .getService(Ci.mozISpellCheckingEngine); 55 56 // install base dictionary 57 var base = dir.clone(); 58 base.append("base"); 59 ok(base.exists()); 60 hunspell.addDirectory(base); 61 62 // install map dictionary 63 var map = dir.clone(); 64 map.append("map"); 65 ok(map.exists()); 66 hunspell.addDirectory(map); 67 68 const {maybeOnSpellCheck} = ChromeUtils.importESModule( 69 "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"); 70 maybeOnSpellCheck(textbox, function () { 71 72 // test that base and map dictionaries are available 73 var dicts = getDictionaryList(editor); 74 isnot(dicts.indexOf("base-utf"), -1, "base is available"); 75 isnot(dicts.indexOf("maputf"), -1, "map is available"); 76 77 // select base dictionary 78 setCurrentDictionary(editor, "base-utf").then(() => { 79 /* eslint-disable no-useless-concat */ 80 maybeOnSpellCheck(textbox, function () { 81 // test that base dictionary is in use 82 is(getMisspelledWords(editor), "Frühstück" + "qwertyu", "base misspellings"); 83 is(getCurrentDictionary(editor), "base-utf", "current dictionary"); 84 85 // select map dictionary 86 setCurrentDictionary(editor, "maputf").then(() => { 87 // Focus again, so the spelling gets updated. 88 textbox.blur(); 89 textbox.focus(); 90 91 maybeOnSpellCheck(textbox, function () { 92 // test that map dictionary is in use 93 is(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings (1)"); 94 is(getCurrentDictionary(editor), "maputf", "current dictionary"); 95 96 // uninstall map dictionary 97 hunspell.removeDirectory(map); 98 99 // Focus again, so the spelling gets updated. 100 textbox.blur(); 101 textbox.focus(); 102 103 maybeOnSpellCheck(textbox, function () { 104 // test that map dictionary is not in use 105 isnot(getMisspelledWords(editor), "created" + "imply" + "tomorrow" + "qwertyu", "map misspellings (2)"); 106 isnot(getCurrentDictionary(editor), "maputf", "current dictionary"); 107 108 // test that base dictionary is available and map dictionary is unavailable 109 var dicts = getDictionaryList(editor); 110 isnot(dicts.indexOf("base-utf"), -1, "base is available"); 111 is(dicts.indexOf("maputf"), -1, "map is unavailable"); 112 113 // uninstall base dictionary 114 hunspell.removeDirectory(base); 115 116 maybeOnSpellCheck(textbox, function () { 117 SimpleTest.finish(); 118 }); 119 }); 120 }); 121 }); 122 }); 123 }); 124 }); 125 } 126 ]]> 127 </script> 128 <html:input id="textbox" spellcheck="true" value="created imply Frühstück tomorrow qwertyu"/> 129 </window>