test_async_UpdateCurrentDictionary.html (2020B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=856270 5 --> 6 <head> 7 <title>Test for Bug 856270 - Async UpdateCurrentDictionary</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=856270">Mozilla Bug 856270</a> 13 <p id="display"></p> 14 <div id="content"> 15 <textarea id="editor" spellcheck="true"></textarea> 16 </div> 17 <pre id="test"> 18 <script class="testbody" type="text/javascript"> 19 20 SimpleTest.waitForExplicitFinish(); 21 addLoadEvent(start); 22 23 function start() { 24 var textarea = document.getElementById("editor"); 25 textarea.focus(); 26 27 const { onSpellCheck } = SpecialPowers.ChromeUtils.importESModule( 28 "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs" 29 ) 30 onSpellCheck(textarea, function() { 31 var isc = SpecialPowers.wrap(textarea).editor.getInlineSpellChecker(false); 32 ok(isc, "Inline spell checker should exist after focus and spell check"); 33 var sc = isc.spellChecker; 34 35 sc.setCurrentDictionaries(["testing-XX"]).then(() => { 36 is(true, false, "Setting a non-existent dictionary should fail"); 37 }, () => { 38 let currentDictionaries = sc.getCurrentDictionaries(); 39 40 is(currentDictionaries.length, 0, "expected no dictionaries"); 41 // First, set the lang attribute on the textarea, call Update, and make 42 // sure the spell checker's language was updated appropriately. 43 var lang = "en-US"; 44 textarea.setAttribute("lang", lang); 45 sc.UpdateCurrentDictionary(function() { 46 currentDictionaries = sc.getCurrentDictionaries(); 47 is(currentDictionaries.length, 1, "expected one dictionary"); 48 is(sc.getCurrentDictionaries()[0], lang, 49 "UpdateCurrentDictionary should set the current dictionary."); 50 sc.setCurrentDictionaries([]).then(() => { 51 SimpleTest.finish(); 52 }); 53 }); 54 }); 55 }); 56 } 57 </script> 58 </pre> 59 </body> 60 </html>