test_bug1773802.html (3283B)
1 <!DOCTYPE html> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1773802 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1773802</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="/tests/SimpleTest/EventUtils.js"></script> 11 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 12 </head> 13 <body> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1773802">Mozilla Bug 1773802</a> 15 <p id="display"></p> 16 </div> 17 18 <textarea id="editor">correct правильный, incarrect непровильный</textarea> 19 20 <pre id="test"> 21 <script class="testbody" type="text/javascript"> 22 23 const Ci = SpecialPowers.Ci; 24 25 let { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.importESModule( 26 "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs" 27 ); 28 29 function getMisspelledWords(editor) { 30 return editor.selectionController.getSelection(Ci.nsISelectionController.SELECTION_SPELLCHECK).toString(); 31 } 32 33 /** Test for Bug 1773802 */ 34 SimpleTest.waitForExplicitFinish(); 35 addLoadEvent(start); 36 async function start() { 37 let script = SpecialPowers.loadChromeScript(() => { 38 /* eslint-env mozilla/chrome-script */ 39 // eslint-disable-next-line mozilla/use-services 40 let dir = Cc["@mozilla.org/file/directory_service;1"] 41 .getService(Ci.nsIProperties) 42 .get("CurWorkD", Ci.nsIFile); 43 dir.append("tests"); 44 dir.append("editor"); 45 dir.append("spellchecker"); 46 dir.append("tests"); 47 48 let hunspell = Cc["@mozilla.org/spellchecker/engine;1"] 49 .getService(Ci.mozISpellCheckingEngine); 50 51 // Install ru-RU dictionary. 52 let ru_RU = dir.clone(); 53 ru_RU.append("ru-RU"); 54 hunspell.addDirectory(ru_RU); 55 56 addMessageListener("destroy", () => hunspell.removeDirectory(ru_RU)); 57 addMessageListener("ru_RU-exists", () => ru_RU.exists()); 58 }); 59 is(await script.sendQuery("ru_RU-exists"), true, 60 "true expected (ru_RU directory should exist)"); 61 62 let textarea = document.getElementById("editor"); 63 let editor = SpecialPowers.wrap(textarea).editor; 64 textarea.focus(); 65 66 maybeOnSpellCheck(textarea, () => { 67 let isc = SpecialPowers.wrap(textarea).editor.getInlineSpellChecker(false); 68 ok(isc, "Inline spell checker should exist after focus and spell check"); 69 let spellchecker = isc.spellChecker; 70 71 spellchecker.setCurrentDictionaries(["en-US", "ru-RU"]).then(async () => { 72 textarea.blur(); 73 textarea.focus(); 74 maybeOnSpellCheck(textarea, async function() { 75 let currentDictionaries = spellchecker.getCurrentDictionaries(); 76 77 is(currentDictionaries.length, 2, "expected two dictionaries"); 78 is(currentDictionaries[0], "en-US", "expected en-US"); 79 is(currentDictionaries[1], "ru-RU", "expected ru-RU"); 80 is(getMisspelledWords(editor), "incarrectнепровильный", "some misspelled words expected: incarrect непровильный"); 81 82 // Remove the fake ru_RU dictionary again. 83 await script.sendQuery("destroy"); 84 85 // This will clear the content preferences and reset "spellchecker.dictionary". 86 spellchecker.setCurrentDictionaries([]).then(() => { 87 SimpleTest.finish(); 88 }); 89 }); 90 }); 91 }); 92 } 93 </script> 94 </pre> 95 </body> 96 </html>