Bug 1611360 - part 1: Make sure that test_bug1151186.html set focus to its window forcibly when the document does not receive focus event r=smaug

For testing the original symptom of bug 1151186, this test needs to set focus
to a `contenteditable` editor from `focus` event listener of the documen.
However, according to the oranges, `focus` event for the document is not fired
as expected only on Linux.  The reason is, the document sometimes does not get
focus automatically.  Therefore, this patch tries to listen `focus` event first
for keeping original path.  But if the document is not activated automatically,
sets focus to its window when next macro task runs.

Differential Revision: https://phabricator.services.mozilla.com/D62396

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2020-02-11 20:47:07 +00:00
Родитель ba4b5f43bc
Коммит 96766027db
2 изменённых файлов: 34 добавлений и 7 удалений

Просмотреть файл

@ -23,7 +23,6 @@ skip-if = toolkit != "windows"
[test_bug593307.xhtml]
support-files = window_bug593307_offscreen.xhtml window_bug593307_centerscreen.xhtml
[test_bug1151186.html]
skip-if = os == 'linux' && debug #Bug 1176038
[test_keycodes.xhtml]
[test_wheeltransaction.xhtml]
support-files = window_wheeltransaction.xhtml

Просмотреть файл

@ -9,22 +9,50 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1151186
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript">
<script>
/** Test for Bug 1151186 **/
SimpleTest.waitForExplicitFinish();
document.addEventListener("focus", () => {
// In this test, we want to check the IME enabled state in the `contenteditable`
// editor which is focused by `focus` event listener of the document.
// However, according to the random oranges filed as bug 1176038 and bug 1611360,
// `focus` event are sometimes not fired on the document and the reason is,
// the document sometimes not focused automatically. Therefore, this test
// will set focus the document when `focus` event is not fired until next
// macro task.
var focusEventFired = false;
function onFocus(event) {
is(event.target.nodeName, "#document", "focus event should be fired on the document node");
if (event.target != document) {
return;
}
focusEventFired = true;
document.getElementById("editor").focus();
SimpleTest.executeSoon(runTests);
});
}
document.addEventListener("focus", onFocus, {once: true});
// Register next macro task to check whether `focus` event of the document
// is fired as expected. If not, let's focus our window manually. Then,
// the `focus` event listener starts the test anyway.
setTimeout(() => {
if (focusEventFired) {
return; // We've gotten `focus` event as expected.
}
ok(!document.hasFocus(), "The document should not have focus yet");
info("Setting focus to the window forcibly...");
window.focus();
}, 0);
function runTests() {
let description = focusEventFired ?
"document got focused normally" :
"document got focused forcibly";
is(document.activeElement, document.getElementById("editor"),
"The div element should be focused");
`The div element should be focused (${description})`);
var utils = SpecialPowers.getDOMWindowUtils(window);
is(utils.IMEStatus, utils.IME_STATUS_ENABLED,
"IME should be enabled");
`IME should be enabled (${description})`);
SimpleTest.finish();
}
</script>