2015-09-14 03:35:00 +03:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1204147
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 1204147</title>
|
2016-08-22 21:06:41 +03:00
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
|
2015-09-14 03:35:00 +03:00
|
|
|
</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;
|
2016-08-22 21:06:41 +03:00
|
|
|
var script;
|
2015-09-14 03:35:00 +03:00
|
|
|
|
Bug 1541557: Part 5 - Update callers of ChromeScript.sendSyncMessage to use sendQuery instead. r=nika
Since JSWindowActors don't have direct access to synchronous messaging,
ChromeScript callers are going to need to migrate to asynchronous messaging
and queries instead.
Since there's no comparable API to sendQuery for frame message managers, this
patch adds a stub that uses synchronous messaging, but makes the API appear
asynchronous, and migrates callers to use it instead of direct synchronous
messaging. This will be replaced with a true synchronous API in the actor
migration.
Fortunately, most of the time, this actually leads to simpler code. The
`sendQuery` API doesn't have the odd return value semantics of
`sendSyncMessage`, and can usually just be used as a drop-in replacement. Many
of the `sendSyncMessage` callers don't actually use the result, and can just
be changed to `sendAsyncMessage`. And many of the existing async messaging
users can be changed to just use `sendQuery` rather than sending messages and
adding response listeners.
However, the APZ code is an exception. It relies on intricate properties of
the event loop, and doesn't have an easy way to slot in promise handlers, so I
migrated it to using sync messaging via process message managers instead.
Differential Revision: https://phabricator.services.mozilla.com/D35055
--HG--
extra : rebase_source : d5707e87f293a831a5cf2e0b0a7e977090267f78
extra : source : 75ebd6fce136ab3bd0e591c2b8b2d06d3b5bf923
2019-06-12 22:40:51 +03:00
|
|
|
var loadListener = async function(evt) {
|
2015-09-14 03:35:00 +03:00
|
|
|
if (firstLoad) {
|
|
|
|
/* eslint-env mozilla/frame-script */
|
2016-08-22 21:06:41 +03:00
|
|
|
script = SpecialPowers.loadChromeScript(function() {
|
2015-09-14 03:35:00 +03:00
|
|
|
// eslint-disable-next-line mozilla/use-services
|
2016-08-22 21:06:41 +03:00
|
|
|
var dir = Cc["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Ci.nsIProperties)
|
|
|
|
.get("CurWorkD", Ci.nsIFile);
|
|
|
|
dir.append("tests");
|
|
|
|
dir.append("editor");
|
2018-03-02 06:57:54 +03:00
|
|
|
dir.append("spellchecker");
|
|
|
|
dir.append("tests");
|
2016-08-22 21:06:41 +03:00
|
|
|
|
|
|
|
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));
|
|
|
|
});
|
Bug 1541557: Part 5 - Update callers of ChromeScript.sendSyncMessage to use sendQuery instead. r=nika
Since JSWindowActors don't have direct access to synchronous messaging,
ChromeScript callers are going to need to migrate to asynchronous messaging
and queries instead.
Since there's no comparable API to sendQuery for frame message managers, this
patch adds a stub that uses synchronous messaging, but makes the API appear
asynchronous, and migrates callers to use it instead of direct synchronous
messaging. This will be replaced with a true synchronous API in the actor
migration.
Fortunately, most of the time, this actually leads to simpler code. The
`sendQuery` API doesn't have the odd return value semantics of
`sendSyncMessage`, and can usually just be used as a drop-in replacement. Many
of the `sendSyncMessage` callers don't actually use the result, and can just
be changed to `sendAsyncMessage`. And many of the existing async messaging
users can be changed to just use `sendQuery` rather than sending messages and
adding response listeners.
However, the APZ code is an exception. It relies on intricate properties of
the event loop, and doesn't have an easy way to slot in promise handlers, so I
migrated it to using sync messaging via process message managers instead.
Differential Revision: https://phabricator.services.mozilla.com/D35055
--HG--
extra : rebase_source : d5707e87f293a831a5cf2e0b0a7e977090267f78
extra : source : 75ebd6fce136ab3bd0e591c2b8b2d06d3b5bf923
2019-06-12 22:40:51 +03:00
|
|
|
is(await script.sendQuery("en_GB-exists"), true,
|
2016-08-22 21:06:41 +03:00
|
|
|
"true expected (en-GB directory should exist)");
|
2015-09-14 03:35:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var doc = evt.target.contentDocument;
|
|
|
|
var elem;
|
|
|
|
if (firstLoad) {
|
|
|
|
elem = doc.getElementById("en-GB");
|
|
|
|
} else {
|
|
|
|
elem = doc.getElementById("en-US");
|
|
|
|
}
|
|
|
|
|
2018-06-02 05:35:22 +03:00
|
|
|
var editor = SpecialPowers.wrap(elem).editor;
|
2015-09-14 03:35:00 +03:00
|
|
|
editor.setSpellcheckUserOverride(true);
|
|
|
|
var inlineSpellChecker = editor.getInlineSpellChecker(true);
|
|
|
|
|
2022-05-03 09:32:26 +03:00
|
|
|
const { onSpellCheck } = SpecialPowers.ChromeUtils.import(
|
|
|
|
"resource://testing-common/AsyncSpellCheckTestHelper.jsm"
|
|
|
|
);
|
|
|
|
onSpellCheck(elem, async function() {
|
2022-03-23 16:53:39 +03:00
|
|
|
let spellchecker = inlineSpellChecker.spellChecker;
|
|
|
|
let currentDictionaries = spellchecker.getCurrentDictionaries();
|
|
|
|
is(currentDictionaries.length, 1, "expected one dictionary");
|
|
|
|
let currentDictionary = currentDictionaries[0];
|
2015-09-14 03:35:00 +03:00
|
|
|
if (firstLoad) {
|
|
|
|
firstLoad = false;
|
|
|
|
|
|
|
|
// First time around, the element's language should be used.
|
2022-03-23 16:53:39 +03:00
|
|
|
is(currentDictionary, "en-GB", "unexpected lang " + currentDictionary + " instead of en-GB");
|
2015-09-14 03:35:00 +03:00
|
|
|
|
|
|
|
// 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).
|
2018-03-02 06:57:54 +03:00
|
|
|
content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug1204147_subframe2.html?firstload=false";
|
2015-09-14 03:35:00 +03:00
|
|
|
} 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.
|
2022-03-23 16:53:39 +03:00
|
|
|
is(currentDictionary, "en-US", "unexpected lang " + currentDictionary + " instead of en-US");
|
2015-09-14 03:35:00 +03:00
|
|
|
content.removeEventListener("load", loadListener);
|
|
|
|
|
|
|
|
// Remove the fake en-GB dictionary again, since it's otherwise picked up by later tests.
|
2022-03-23 16:53:39 +03:00
|
|
|
await script.sendQuery("destroy");
|
2015-09-14 03:35:00 +03:00
|
|
|
|
|
|
|
// Reset the preference, so the last value we set doesn't collide with the next test.
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
content.addEventListener("load", loadListener);
|
|
|
|
|
2018-03-02 06:57:54 +03:00
|
|
|
content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug1204147_subframe.html?firstload=true";
|
2015-09-14 03:35:00 +03:00
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|