diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /editor/spellchecker/tests/test_bug1204147.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | editor/spellchecker/tests/test_bug1204147.html | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/editor/spellchecker/tests/test_bug1204147.html b/editor/spellchecker/tests/test_bug1204147.html new file mode 100644 index 0000000000..3d5f0e120f --- /dev/null +++ b/editor/spellchecker/tests/test_bug1204147.html @@ -0,0 +1,115 @@ +<!DOCTYPE html> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1204147 +--> +<head> + <title>Test for Bug 1204147</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" href="/tests/SimpleTest/test.css"> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1204147">Mozilla Bug 1204147</a> +<p id="display"></p> +<iframe id="content"></iframe> +</div> + +<pre id="test"> +<script class="testbody" type="text/javascript"> + +/** Test for Bug 1204147 **/ +SimpleTest.waitForExplicitFinish(); +var content = document.getElementById("content"); +// Load a subframe containing an editor with using "en-GB". At first +// load, it will set the dictionary to "en-GB". The bug was that a content preference +// was also created. At second load, we check the dictionary for another element, +// one that should use "en-US". With the bug corrected, we get "en-US", before +// we got "en-GB" from the content preference. + +var firstLoad = true; +var script; + +var loadListener = async function(evt) { + if (firstLoad) { + script = SpecialPowers.loadChromeScript(function() { + /* eslint-env mozilla/chrome-script */ + // eslint-disable-next-line mozilla/use-services + var dir = Cc["@mozilla.org/file/directory_service;1"] + .getService(Ci.nsIProperties) + .get("CurWorkD", Ci.nsIFile); + dir.append("tests"); + dir.append("editor"); + dir.append("spellchecker"); + dir.append("tests"); + + var hunspell = Cc["@mozilla.org/spellchecker/engine;1"] + .getService(Ci.mozISpellCheckingEngine); + + // Install en-GB dictionary. + let en_GB = dir.clone(); + en_GB.append("en-GB"); + hunspell.addDirectory(en_GB); + + addMessageListener("en_GB-exists", () => en_GB.exists()); + addMessageListener("destroy", () => hunspell.removeDirectory(en_GB)); + }); + is(await script.sendQuery("en_GB-exists"), true, + "true expected (en-GB directory should exist)"); + } + + var doc = evt.target.contentDocument; + var elem; + if (firstLoad) { + elem = doc.getElementById("en-GB"); + } else { + elem = doc.getElementById("en-US"); + } + + var editor = SpecialPowers.wrap(elem).editor; + editor.setSpellcheckUserOverride(true); + var inlineSpellChecker = editor.getInlineSpellChecker(true); + + const { onSpellCheck } = SpecialPowers.ChromeUtils.import( + "resource://testing-common/AsyncSpellCheckTestHelper.jsm" + ); + onSpellCheck(elem, async function() { + let spellchecker = inlineSpellChecker.spellChecker; + let currentDictionaries = spellchecker.getCurrentDictionaries(); + is(currentDictionaries.length, 1, "expected one dictionary"); + let currentDictionary = currentDictionaries[0]; + if (firstLoad) { + firstLoad = false; + + // First time around, the element's language should be used. + is(currentDictionary, "en-GB", "unexpected lang " + currentDictionary + " instead of en-GB"); + + // Note that on second load, we load a different page, which does NOT have the trouble-causing + // contenteditable in it. Sadly, loading the same page with the trouble-maker in it + // doesn't allow the retrieval of the spell check dictionary used for the element, + // because the trouble-maker causes the 'global' spell check dictionary to be set to "en-GB" + // (since it picks the first one from the list) before we have the chance to retrieve + // the dictionary for the element (which happens asynchonously after the spell check has completed). + content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug1204147_subframe2.html?firstload=false"; + } else { + // Second time around, the element should default to en-US. + // Without the fix, the first run sets the content preference to en-GB for the whole site. + is(currentDictionary, "en-US", "unexpected lang " + currentDictionary + " instead of en-US"); + content.removeEventListener("load", loadListener); + + // Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests. + await script.sendQuery("destroy"); + + // Reset the preference, so the last value we set doesn't collide with the next test. + SimpleTest.finish(); + } + }); +}; + +content.addEventListener("load", loadListener); + +content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug1204147_subframe.html?firstload=true"; + +</script> +</pre> +</body> +</html> |