2015-09-04 16:24:00 +03:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1200533
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 1200533</title>
|
2016-08-22 21:07:52 +03:00
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
|
2015-09-04 16:24:00 +03:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1200533">Mozilla Bug 1200533</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<iframe id="content"></iframe>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" ttype="application/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 1200533 **/
|
|
|
|
/** Visit the elements defined above and check the dictionary we got **/
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
2018-09-13 10:58:19 +03:00
|
|
|
var content = document.getElementById("content");
|
2015-09-04 16:24:00 +03:00
|
|
|
|
|
|
|
var tests = [
|
|
|
|
// text area, value of spellchecker.dictionary, result.
|
|
|
|
// Result: Document language.
|
|
|
|
[ "none", "", "en-US" ],
|
|
|
|
// Result: Element language.
|
|
|
|
[ "en-GB", "", "en-GB" ],
|
|
|
|
[ "en-gb", "", "en-GB" ],
|
|
|
|
// Result: Random en-*.
|
|
|
|
[ "en-ZA-not-avail", "", "*" ],
|
|
|
|
[ "en-generic", "", "*" ],
|
|
|
|
// Result: Locale.
|
|
|
|
[ "ko-not-avail", "", "en-US" ],
|
|
|
|
|
|
|
|
// Result: Preference value in all cases.
|
|
|
|
[ "en-ZA-not-avail", "en-AU", "en-AU" ],
|
|
|
|
[ "en-generic", "en-AU", "en-AU" ],
|
|
|
|
[ "ko-not-avail", "en-AU", "en-AU" ],
|
|
|
|
|
|
|
|
// Result: Random en-*.
|
|
|
|
[ "en-ZA-not-avail", "de-DE", "*" ],
|
|
|
|
[ "en-generic", "de-DE", "*" ],
|
|
|
|
// Result: Preference value.
|
|
|
|
[ "ko-not-avail", "de-DE", "de-DE" ],
|
|
|
|
];
|
|
|
|
|
|
|
|
var loadCount = 0;
|
2016-08-22 21:07:52 +03:00
|
|
|
var script;
|
2015-09-04 16:24: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-04 16:24:00 +03:00
|
|
|
if (loadCount == 0) {
|
2018-09-13 10:59:47 +03:00
|
|
|
/* eslint-env mozilla/frame-script */
|
2016-08-22 21:07:52 +03:00
|
|
|
script = SpecialPowers.loadChromeScript(function() {
|
2018-09-13 10:59:47 +03:00
|
|
|
// eslint-disable-next-line mozilla/use-services
|
2018-02-28 20:51:33 +03:00
|
|
|
var dir = Cc["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Ci.nsIProperties)
|
|
|
|
.get("CurWorkD", Ci.nsIFile);
|
2016-08-22 21:07:52 +03:00
|
|
|
dir.append("tests");
|
|
|
|
dir.append("editor");
|
2018-03-02 06:57:54 +03:00
|
|
|
dir.append("spellchecker");
|
|
|
|
dir.append("tests");
|
2016-08-22 21:07:52 +03:00
|
|
|
|
2018-02-28 20:51:33 +03:00
|
|
|
var hunspell = Cc["@mozilla.org/spellchecker/engine;1"]
|
|
|
|
.getService(Ci.mozISpellCheckingEngine);
|
2016-08-22 21:07:52 +03:00
|
|
|
|
|
|
|
// Install en-GB, en-AU and de-DE dictionaries.
|
|
|
|
var en_GB = dir.clone();
|
|
|
|
var en_AU = dir.clone();
|
|
|
|
var de_DE = dir.clone();
|
|
|
|
en_GB.append("en-GB");
|
|
|
|
en_AU.append("en-AU");
|
|
|
|
de_DE.append("de-DE");
|
|
|
|
hunspell.addDirectory(en_GB);
|
|
|
|
hunspell.addDirectory(en_AU);
|
|
|
|
hunspell.addDirectory(de_DE);
|
|
|
|
|
|
|
|
addMessageListener("check-existence",
|
|
|
|
() => [en_GB.exists(), en_AU.exists(),
|
|
|
|
de_DE.exists()]);
|
|
|
|
addMessageListener("destroy", () => {
|
|
|
|
hunspell.removeDirectory(en_GB);
|
|
|
|
hunspell.removeDirectory(en_AU);
|
|
|
|
hunspell.removeDirectory(de_DE);
|
|
|
|
});
|
|
|
|
});
|
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 existenceChecks = await script.sendQuery("check-existence");
|
2016-08-22 21:07:52 +03:00
|
|
|
is(existenceChecks[0], true, "true expected (en-GB directory should exist)");
|
|
|
|
is(existenceChecks[1], true, "true expected (en-AU directory should exist)");
|
|
|
|
is(existenceChecks[2], true, "true expected (de-DE directory should exist)");
|
2015-09-04 16:24:00 +03:00
|
|
|
}
|
|
|
|
|
2016-08-22 21:07:52 +03:00
|
|
|
SpecialPowers.pushPrefEnv({set: [["spellchecker.dictionary", tests[loadCount][1]]]},
|
2018-09-13 10:58:19 +03:00
|
|
|
function() { continueTest(evt); });
|
|
|
|
};
|
2015-09-04 16:24:00 +03:00
|
|
|
|
2016-08-22 21:07:52 +03:00
|
|
|
function continueTest(evt) {
|
2015-09-04 16:24:00 +03:00
|
|
|
var doc = evt.target.contentDocument;
|
|
|
|
var elem = doc.getElementById(tests[loadCount][0]);
|
2018-06-02 05:35:22 +03:00
|
|
|
var editor = SpecialPowers.wrap(elem).editor;
|
2015-09-04 16:24:00 +03:00
|
|
|
editor.setSpellcheckUserOverride(true);
|
|
|
|
var inlineSpellChecker = editor.getInlineSpellChecker(true);
|
|
|
|
|
2017-03-29 09:34:49 +03:00
|
|
|
SpecialPowers.Cu.import(
|
|
|
|
"resource://testing-common/AsyncSpellCheckTestHelper.jsm")
|
2018-09-13 10:58:19 +03:00
|
|
|
.onSpellCheck(elem, function() {
|
2015-09-04 16:24:00 +03:00
|
|
|
var spellchecker = inlineSpellChecker.spellChecker;
|
|
|
|
try {
|
|
|
|
var dict = spellchecker.GetCurrentDictionary();
|
2018-09-13 10:58:19 +03:00
|
|
|
} catch (e) {}
|
2015-09-04 16:24:00 +03:00
|
|
|
|
|
|
|
if (tests[loadCount][2] != "*") {
|
2018-09-13 10:58:19 +03:00
|
|
|
is(dict, tests[loadCount][2], "expected " + tests[loadCount][2]);
|
2015-09-04 16:24:00 +03:00
|
|
|
} else {
|
|
|
|
var gotEn = (dict == "en-GB" || dict == "en-AU" || dict == "en-US");
|
2018-09-13 10:58:19 +03:00
|
|
|
is(gotEn, true, "expected en-AU or en-GB or en-US");
|
2015-09-04 16:24:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
loadCount++;
|
|
|
|
if (loadCount < tests.length) {
|
|
|
|
// Load the iframe again.
|
2018-09-13 10:58:19 +03:00
|
|
|
content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug1200533_subframe.html?firstload=false";
|
2015-09-04 16:24:00 +03:00
|
|
|
} else {
|
|
|
|
// Remove the fake dictionaries again, since it's otherwise picked up by later tests.
|
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
|
|
|
script.sendAsyncMessage("destroy");
|
2015-09-04 16:24:00 +03:00
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-13 10:58:19 +03:00
|
|
|
content.addEventListener("load", loadListener);
|
2015-09-04 16:24:00 +03:00
|
|
|
|
2018-09-13 10:58:19 +03:00
|
|
|
content.src = "http://mochi.test:8888/tests/editor/spellchecker/tests/bug1200533_subframe.html?firstload=true";
|
2015-09-04 16:24:00 +03:00
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|