test_bug1761273.html (3260B)
1 <!DOCTYPE html> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1761273 5 --> 6 <head> 7 <title>Test for Bug 1761273</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1761273">Mozilla Bug 1761273</a> 14 <p id="display"></p> 15 </div> 16 17 <textarea id="editor" lang="en-US">heute ist ein guter Tag - today is a good day</textarea> 18 19 <pre id="test"> 20 <script class="testbody" type="text/javascript"> 21 22 const Ci = SpecialPowers.Ci; 23 24 let { 25 getDictionaryContentPref, 26 onSpellCheck, 27 } = SpecialPowers.ChromeUtils.importESModule( 28 "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs" 29 ); 30 31 /** Test for Bug 1402822 */ 32 SimpleTest.waitForExplicitFinish(); 33 addLoadEvent(start); 34 async function start() { 35 let script = SpecialPowers.loadChromeScript(() => { 36 /* eslint-env mozilla/chrome-script */ 37 // eslint-disable-next-line mozilla/use-services 38 let dir = Cc["@mozilla.org/file/directory_service;1"] 39 .getService(Ci.nsIProperties) 40 .get("CurWorkD", Ci.nsIFile); 41 dir.append("tests"); 42 dir.append("editor"); 43 dir.append("spellchecker"); 44 dir.append("tests"); 45 46 let hunspell = Cc["@mozilla.org/spellchecker/engine;1"] 47 .getService(Ci.mozISpellCheckingEngine); 48 49 // Install de-DE dictionary. 50 let de_DE = dir.clone(); 51 de_DE.append("de-DE"); 52 hunspell.addDirectory(de_DE); 53 54 addMessageListener("destroy", () => hunspell.removeDirectory(de_DE)); 55 addMessageListener("de_DE-exists", () => de_DE.exists()); 56 }); 57 is(await script.sendQuery("de_DE-exists"), true, 58 "true expected (de_DE directory should exist)"); 59 60 let textarea = document.getElementById("editor"); 61 textarea.focus(); 62 63 onSpellCheck(textarea, async () => { 64 let isc = SpecialPowers.wrap(textarea).editor.getInlineSpellChecker(true); 65 ok(isc, "Inline spell checker should exist after focus and spell check"); 66 let spellchecker = isc.spellChecker; 67 68 // Setting the language to the language of the texteditor should not set the 69 // content preference. 70 await spellchecker.setCurrentDictionaries(["en-US"]); 71 let dictionaryContentPref = await getDictionaryContentPref(); 72 is(dictionaryContentPref, "", "Content pref should be empty"); 73 74 await spellchecker.setCurrentDictionaries(["en-US", "de-DE"]); 75 dictionaryContentPref = await getDictionaryContentPref(); 76 is(dictionaryContentPref, "en-US,de-DE,", "Content pref should be en-US,de-DE,"); 77 78 await spellchecker.setCurrentDictionaries(["de-DE"]); 79 dictionaryContentPref = await getDictionaryContentPref(); 80 is(dictionaryContentPref, "de-DE,", "Content pref should be de-DE,"); 81 82 // Remove the fake de_DE dictionary again. 83 await script.sendQuery("destroy"); 84 85 // This will clear the content preferences and reset "spellchecker.dictionary". 86 await spellchecker.setCurrentDictionaries([]); 87 dictionaryContentPref = await getDictionaryContentPref(); 88 is(dictionaryContentPref, "", "Content pref should be empty"); 89 90 SimpleTest.finish(); 91 }); 92 } 93 </script> 94 </pre> 95 </body> 96 </html>