Bug 1890689 apply drift correction to input rate instead of output rate r=pehrsons
[gecko.git] / editor / spellchecker / tests / test_bug717433.html
blob322e0d47d8ad9d571c2a02f972e6af021e31006d
1 <!DOCTYPE html>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=717433
5 -->
6 <head>
7 <title>Test for Bug 717433</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=717433">Mozilla Bug 717433</a>
13 <p id="display"></p>
14 <iframe id="content"></iframe>
16 </div>
17 <pre id="test">
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.
28 var firstLoad = true;
29 var expected = "";
30 var script;
32 var loadListener = async function(evt) {
33 if (firstLoad) {
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);
40 dir.append("tests");
41 dir.append("editor");
42 dir.append("spellchecker");
43 dir.append("tests");
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));
55 });
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];
76 if (firstLoad) {
77 firstLoad = false;
79 // First time around, we get a random dictionary based on the language "en".
80 if (currentDictionary == "en-GB") {
81 expected = "en-US";
82 } else if (currentDictionary == "en-US") {
83 expected = "en-GB";
84 } else {
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";});
89 } else {
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(() => {
98 SimpleTest.finish();
99 });
104 content.addEventListener("load", loadListener);
106 content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug717433_subframe.html?firstload=true";
108 </script>
109 </pre>
110 </body>
111 </html>