4 https://bugzilla.mozilla.org/show_bug.cgi?id=717433
7 <title>Test for Bug
717433</title>
8 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
12 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=717433">Mozilla Bug
717433</a>
14 <iframe id=
"content"></iframe>
18 <script class=
"testbody" type=
"text/javascript">
20 /** Test for Bug
717433 **/
21 SimpleTest.waitForExplicitFinish();
22 var content = document.getElementById(
"content");
23 // Load a subframe containing an editor with language
"en". At first
24 // load, it will set the dictionary to en-GB or en-US. We set the other one.
25 // At second load, it will return the current dictionary. We can check that the
26 // dictionary is correctly remembered between loads.
32 var loadListener = async function(evt) {
34 script = SpecialPowers.loadChromeScript(function() {
35 /* eslint-env mozilla/chrome-script */
36 // eslint-disable-next-line mozilla/use-services
37 var dir = Cc[
"@mozilla.org/file/directory_service;1"]
38 .getService(Ci.nsIProperties)
39 .get(
"CurWorkD", Ci.nsIFile);
42 dir.append(
"spellchecker");
45 var hunspell = Cc[
"@mozilla.org/spellchecker/engine;1"]
46 .getService(Ci.mozISpellCheckingEngine);
48 // Install en-GB dictionary.
49 var en_GB = dir.clone();
50 en_GB.append(
"en-GB");
51 hunspell.addDirectory(en_GB);
53 addMessageListener(
"en_GB-exists", () =
> en_GB.exists());
54 addMessageListener(
"destroy", () =
> hunspell.removeDirectory(en_GB));
56 is(await script.sendQuery(
"en_GB-exists"), true,
57 "true expected (en-GB directory should exist)");
60 var doc = evt.target.contentDocument;
61 var elem = doc.getElementById(
"textarea");
62 var editor = SpecialPowers.wrap(elem).editor;
63 editor.setSpellcheckUserOverride(true);
64 var inlineSpellChecker = editor.getInlineSpellChecker(true);
66 const { onSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
67 "resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
69 onSpellCheck(elem, async function() {
70 let spellchecker = inlineSpellChecker.spellChecker;
71 let currentDictionaries = spellchecker.getCurrentDictionaries();
73 is(currentDictionaries.length,
1,
"expected one dictionary");
74 let currentDictionary = currentDictionaries[
0];
79 // First time around, we get a random dictionary based on the language
"en".
80 if (currentDictionary ==
"en-GB") {
82 } else if (currentDictionary ==
"en-US") {
85 is(true, false,
"Neither en-US nor en-GB are current");
87 spellchecker.setCurrentDictionaries([expected]).then(() =
> {
88 content.src =
"http://mochi.test:8888/tests/editor/spellchecker/tests/bug717433_subframe.html?firstload=false";});
90 is(currentDictionary, expected, expected +
" expected");
91 content.removeEventListener(
"load", loadListener);
93 // Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
94 await script.sendQuery(
"destroy");
96 // This will clear the content preferences and reset
"spellchecker.dictionary".
97 spellchecker.setCurrentDictionaries([]).then(() =
> {
104 content.addEventListener(
"load", loadListener);
106 content.src =
"http://mochi.test:8888/tests/editor/spellchecker/tests/bug717433_subframe.html?firstload=true";