Bug 1858082 - Wrap the drag service getter into a try block r=whimboo,webdriver-reviewers

The drag service is never instantiated if it's in the headless mode.
And in this case, `NS_ERROR_XPC_GS_RETURNED_FAILURE` exception is thrown.
Therefore, we need to wrap the service getter with a `try` block and
return `null` if it fails.

Differential Revision: https://phabricator.services.mozilla.com/D190580
This commit is contained in:
Masayuki Nakano 2023-10-11 12:32:18 +00:00
Родитель ea79997676
Коммит bf010881ca
3 изменённых файлов: 33 добавлений и 7 удалений

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

@ -16,9 +16,6 @@ export const event = {};
ChromeUtils.defineLazyGetter(lazy, "dblclickTimer", () => {
return Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
});
ChromeUtils.defineLazyGetter(event, "dragService", () => {
return Cc["@mozilla.org/widget/dragservice;1"].getService(Ci.nsIDragService);
});
const _eventUtils = new WeakMap();

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

@ -23,6 +23,22 @@ ChromeUtils.defineLazyGetter(lazy, "logger", () =>
lazy.Log.get(lazy.Log.TYPES.MARIONETTE)
);
// dragService may be null if it's in the headless mode (e.g., on Linux).
// It depends on the platform, though.
ChromeUtils.defineLazyGetter(lazy, "dragService", () => {
try {
return Cc["@mozilla.org/widget/dragservice;1"].getService(
Ci.nsIDragService
);
} catch (e) {
// If we're in the headless mode, the drag service may be never
// instantiated. In this case, an exception is thrown. Let's ignore
// any exceptions since without the drag service, nobody can create a
// drag session.
return null;
}
});
/** XUL elements that support disabled attribute. */
const DISABLED_ATTRIBUTE_SUPPORTED_XUL = new Set([
"ARROWSCROLLBOX",
@ -185,7 +201,7 @@ async function webdriverClickElement(el, a11y) {
win
);
if (lazy.event.dragService.getCurrentSession()) {
if (lazy.dragService?.getCurrentSession()) {
// Special handling is required if the mousemove started a drag session.
// In this case, mousedown event shouldn't be fired, and the mouseup should
// end the session. Therefore, we should synthesize only mouseup.

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

@ -579,10 +579,23 @@ function synthesizeTouch(aTarget, aOffsetX, aOffsetY, aEvent, aWindow) {
);
}
/**
* Return the drag service. Note that if we're in the headless mode, this
* may return null because the service may be never instantiated (e.g., on
* Linux).
*/
function getDragService() {
return _EU_Cc["@mozilla.org/widget/dragservice;1"].getService(
_EU_Ci.nsIDragService
);
try {
return _EU_Cc["@mozilla.org/widget/dragservice;1"].getService(
_EU_Ci.nsIDragService
);
} catch (e) {
// If we're in the headless mode, the drag service may be never
// instantiated. In this case, an exception is thrown. Let's ignore
// any exceptions since without the drag service, nobody can create a
// drag session.
return null;
}
}
/**