Bug 1384358 - Avoid racy check of focus manager in content process, r=enndeakin

Previously this was safe, as the synthesized mouse event would be processed in
the child process, updating the focus state, in order - before the content
process would try to check its focus state. Now, thanks to multiple event queues
work, this isn't guaranteed.

This patch just adds retrying to the logic, so we retry up to 10 times, 100ms
apart. This should ensure that we don't incorrectly detect a test failure
intermittently.

MozReview-Commit-ID: J4uzl9jeafC
This commit is contained in:
Nika Layzell 2017-11-17 15:17:56 -05:00
Родитель 2a5bf45c56
Коммит c6f93a7aad
1 изменённых файлов: 19 добавлений и 6 удалений

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

@ -30,14 +30,27 @@ add_task(async function test() {
isnot(fm.focusedElement, document.getElementById("urlbar").inputField,
"Failed to move focus away from search bar: button=" + button);
await ContentTask.spawn(tab.linkedBrowser, button, function (button) {
await ContentTask.spawn(tab.linkedBrowser, button, async function (button) {
let fm = Components.classes["@mozilla.org/focus-manager;1"].
getService(Components.interfaces.nsIFocusManager);
getService(Components.interfaces.nsIFocusManager);
Assert.equal(content.document.activeElement.id, "willBeFocused",
"The input element isn't active element: button=" + button);
Assert.equal(fm.focusedElement, content.document.activeElement,
"The active element isn't focused element in App level: button=" + button);
let attempts = 10;
await new Promise(resolve => {
function check() {
if (attempts > 0 && content.document.activeElement.id != "willBeFocused") {
attempts--;
content.window.setTimeout(check, 100);
return;
}
Assert.equal(content.document.activeElement.id, "willBeFocused",
"The input element isn't active element: button=" + button);
Assert.equal(fm.focusedElement, content.document.activeElement,
"The active element isn't focused element in App level: button=" + button);
resolve();
}
check();
});
});
}