Generalize app id hit test handling for any hit test event

R=hirokisato@chromium.org

Test: ChromeVox touch explore in Lacros
Change-Id: I2d63a445e3e00175194540a714861b5726e9d71c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3075403
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: Hiroki Sato <hirokisato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#909398}
diff --git a/extensions/renderer/resources/automation/automation_custom_bindings.js b/extensions/renderer/resources/automation/automation_custom_bindings.js
index e423be2..c4cbd35 100644
--- a/extensions/renderer/resources/automation/automation_custom_bindings.js
+++ b/extensions/renderer/resources/automation/automation_custom_bindings.js
@@ -265,9 +265,7 @@
     eventParams.targetID = privates(targetTree).impl.id;
   }
 
-  if (!privates(targetTree).impl.onAccessibilityEvent(eventParams)) {
-    return;
-  }
+  privates(targetTree).impl.onAccessibilityEvent(eventParams);
 
   // If we're not waiting on a callback to getTree(), we can early out here.
   if (!(id in idToCallback)) {
diff --git a/extensions/renderer/resources/automation/automation_node.js b/extensions/renderer/resources/automation/automation_node.js
index 1dd4721..0800310 100644
--- a/extensions/renderer/resources/automation/automation_node.js
+++ b/extensions/renderer/resources/automation/automation_node.js
@@ -965,7 +965,9 @@
   },
 
   hitTest: function(x, y, eventToFire) {
-    this.hitTestInternal(x, y, eventToFire);
+    // Set an empty callback to trigger onActionResult.
+    const callback = () => {};
+    this.hitTestInternal(x, y, eventToFire, callback);
   },
 
   hitTestWithReply: function(x, y, opt_callback) {
@@ -1875,21 +1877,21 @@
   onAccessibilityEvent: function(eventParams) {
     const targetNode = this.get(eventParams.targetID);
     if (targetNode) {
+      if (eventParams.actionRequestID != -1 &&
+          this.onActionResult(eventParams.actionRequestID, targetNode)) {
+        return;
+      }
+
       const targetNodeImpl = privates(targetNode).impl;
       targetNodeImpl.dispatchEvent(
           eventParams.eventType, eventParams.eventFrom,
           eventParams.eventFromAction, eventParams.mouseX, eventParams.mouseY,
           eventParams.intents);
-
-      if (eventParams.actionRequestID != -1) {
-        this.onActionResult(eventParams.actionRequestID, targetNode);
-      }
     } else {
       logging.WARNING('Got ' + eventParams.eventType +
                       ' event on unknown node: ' + eventParams.targetID +
                       '; this: ' + this.id);
     }
-    return true;
   },
 
   addActionResultCallback: function(actionType, opt_args, callback) {
@@ -1966,12 +1968,13 @@
           delete AutomationRootNodeImpl.actionRequestIDToCallback[requestID];
           privates(appNode).impl.performAction_(
               data.actionType, data.opt_args, data.callback);
-          return;
+          return true;
         }
       }
 
       data.callback(result);
       delete AutomationRootNodeImpl.actionRequestIDToCallback[requestID];
+      return false;
     }
   },