test_bug1205983.html (4671B)
1 <!DOCTYPE html> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1205983 5 --> 6 <head> 7 <title>Test for Bug 1205983</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=1205983">Mozilla Bug 1205983</a> 13 <p id="display"></p> 14 </div> 15 16 <div contenteditable id="de-DE" lang="de-DE" onfocus="deFocus()">German heute ist ein guter Tag</div> 17 <textarea id="en-US" lang="en-US" onfocus="enFocus()">Nogoodword today is a nice day</textarea> 18 19 <pre id="test"> 20 <script class="testbody" type="text/javascript"> 21 22 function getMisspelledWords(editor) { 23 return editor.selectionController.getSelection(SpecialPowers.Ci.nsISelectionController.SELECTION_SPELLCHECK).toString(); 24 } 25 26 var elem_de; 27 var editor_de; 28 var selcon_de; 29 var script; 30 31 var { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.importESModule( 32 "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs" 33 ); 34 35 /** Test for Bug 1205983 */ 36 SimpleTest.waitForExplicitFinish(); 37 SimpleTest.waitForFocus(async function() { 38 script = SpecialPowers.loadChromeScript(function() { 39 /* eslint-env mozilla/chrome-script */ 40 // eslint-disable-next-line mozilla/use-services 41 var dir = Cc["@mozilla.org/file/directory_service;1"] 42 .getService(Ci.nsIProperties) 43 .get("CurWorkD", Ci.nsIFile); 44 dir.append("tests"); 45 dir.append("editor"); 46 dir.append("spellchecker"); 47 dir.append("tests"); 48 49 var hunspell = Cc["@mozilla.org/spellchecker/engine;1"] 50 .getService(Ci.mozISpellCheckingEngine); 51 52 // Install de-DE dictionary. 53 var de_DE = dir.clone(); 54 de_DE.append("de-DE"); 55 hunspell.addDirectory(de_DE); 56 57 addMessageListener("de_DE-exists", () => de_DE.exists()); 58 addMessageListener("destroy", () => hunspell.removeDirectory(de_DE)); 59 }); 60 is(await script.sendQuery("de_DE-exists"), true, 61 "true expected (de_DE directory should exist)"); 62 63 document.getElementById("de-DE").focus(); 64 }); 65 66 function deFocus() { 67 elem_de = document.getElementById("de-DE"); 68 69 maybeOnSpellCheck(elem_de, function() { 70 var editingSession = SpecialPowers.wrap(window).docShell.editingSession; 71 editor_de = editingSession.getEditorForWindow(window); 72 selcon_de = editor_de.selectionController; 73 var sel = selcon_de.getSelection(selcon_de.SELECTION_SPELLCHECK); 74 75 // Check that we spelled in German, so there is only one misspelled word. 76 is(sel.toString(), "German", "one misspelled word expected: German"); 77 78 // Now focus the textarea, which requires English spelling. 79 document.getElementById("en-US").focus(); 80 }); 81 } 82 83 function enFocus() { 84 var elem_en = document.getElementById("en-US"); 85 var editor_en = 86 SpecialPowers.wrap(elem_en) 87 .editor; 88 editor_en.setSpellcheckUserOverride(true); 89 var inlineSpellChecker = editor_en.getInlineSpellChecker(true); 90 91 maybeOnSpellCheck(elem_en, async function() { 92 var spellchecker = inlineSpellChecker.spellChecker; 93 let currentDictionaries = spellchecker.getCurrentDictionaries(); 94 is(currentDictionaries.length, 1, "expected one dictionary"); 95 let currentDictionary = currentDictionaries[0]; 96 97 // Check that the English dictionary is loaded and that the spell check has worked. 98 is(currentDictionary, "en-US", "expected en-US"); 99 is(getMisspelledWords(editor_en), "Nogoodword", "one misspelled word expected: Nogoodword"); 100 101 // So far all was boring. The important thing is whether the spell check result 102 // in the de-DE editor is still the same. After losing focus, no spell check 103 // updates should take place there. 104 var sel = selcon_de.getSelection(selcon_de.SELECTION_SPELLCHECK); 105 is(sel.toString(), "German", "one misspelled word expected: German"); 106 107 // Remove the fake de_DE dictionary again. 108 await script.sendQuery("destroy"); 109 110 // Focus again, so the spelling gets updated, but before we need to kill the focus handler. 111 elem_de.onfocus = null; 112 elem_de.blur(); 113 elem_de.focus(); 114 115 // After removal, the de_DE editor should refresh the spelling with en-US. 116 maybeOnSpellCheck(elem_de, function() { 117 var endSel = selcon_de.getSelection(selcon_de.SELECTION_SPELLCHECK); 118 // eslint-disable-next-line no-useless-concat 119 is(endSel.toString(), "heute" + "ist" + "ein" + "guter", 120 "some misspelled words expected: heute ist ein guter"); 121 122 // If we don't reset this, we cause massive leaks. 123 selcon_de = null; 124 editor_de = null; 125 126 SimpleTest.finish(); 127 }); 128 }); 129 } 130 131 </script> 132 </pre> 133 </body> 134 </html>