Commit 65644ef9 authored by gogerald's avatar gogerald Committed by Commit Bot

[Autofill Assistant] Use touch tap instead of mouse click on Android

Bug: 806868
Change-Id: I4848426960e868b600e238b0cbc0edd8aa1f443b
Reviewed-on: https://chromium-review.googlesource.com/c/1331873Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607974}
parent d4f327ba
......@@ -55,9 +55,9 @@ class ActionDelegate {
virtual void WaitForElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) = 0;
// Click the element given by |selectors| on the web page.
virtual void ClickElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) = 0;
// Click or tap the element given by |selectors| on the web page.
virtual void ClickOrTapElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) = 0;
// Ask user to choose an address in personal data manager. GUID of the chosen
// address will be returned through callback, otherwise empty string if the
......
......@@ -38,7 +38,7 @@ void ClickAction::OnWaitForElement(ActionDelegate* delegate,
return;
}
delegate->ClickElement(
delegate->ClickOrTapElement(
ExtractVector(proto_.click().element_to_click().selectors()),
base::BindOnce(&::autofill_assistant::ClickAction::OnClick,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
......
......@@ -13,7 +13,8 @@
#include "components/autofill_assistant/browser/actions/action.h"
namespace autofill_assistant {
// An action to perform a mouse left button click on a given element on Web.
// An action to perform a mouse left button click on a given element on Web,
// which is implemented as a touch tap on Mobile.
class ClickAction : public Action {
public:
explicit ClickAction(const ActionProto& proto);
......
......@@ -34,7 +34,7 @@ class MockActionDelegate : public ActionDelegate {
base::OnceCallback<void(bool)>&));
MOCK_METHOD1(ShowStatusMessage, void(const std::string& message));
MOCK_METHOD2(ClickElement,
MOCK_METHOD2(ClickOrTapElement,
void(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback));
......
......@@ -24,13 +24,13 @@ class MockWebController : public WebController {
MOCK_METHOD1(LoadURL, void(const GURL&));
void ClickElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) override {
void ClickOrTapElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) override {
// Transforming callback into a references allows using RunOnceCallback on
// the argument.
OnClickElement(selectors, callback);
OnClickOrTapElement(selectors, callback);
}
MOCK_METHOD2(OnClickElement,
MOCK_METHOD2(OnClickOrTapElement,
void(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)>& callback));
......
......@@ -87,9 +87,11 @@ void ScriptExecutor::ShowStatusMessage(const std::string& message) {
delegate_->GetUiController()->ShowStatusMessage(message);
}
void ScriptExecutor::ClickElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) {
delegate_->GetWebController()->ClickElement(selectors, std::move(callback));
void ScriptExecutor::ClickOrTapElement(
const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) {
delegate_->GetWebController()->ClickOrTapElement(selectors,
std::move(callback));
}
void ScriptExecutor::GetPaymentInformation(
......
......@@ -75,8 +75,8 @@ class ScriptExecutor : public ActionDelegate {
void WaitForElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) override;
void ShowStatusMessage(const std::string& message) override;
void ClickElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) override;
void ClickOrTapElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) override;
void GetPaymentInformation(
payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback,
......
......@@ -45,7 +45,7 @@ class ScriptExecutorTest : public testing::Test,
// fail. The following makes a click action fail immediately
ON_CALL(mock_web_controller_, OnElementCheck(_, _, _))
.WillByDefault(RunOnceCallback<2>(true));
ON_CALL(mock_web_controller_, OnClickElement(_, _))
ON_CALL(mock_web_controller_, OnClickOrTapElement(_, _))
.WillByDefault(RunOnceCallback<1>(false));
ON_CALL(mock_web_controller_, OnFocusElement(_, _))
.WillByDefault(RunOnceCallback<1>(true));
......
......@@ -11,6 +11,7 @@
#include "base/callback.h"
#include "base/logging.h"
#include "base/task/post_task.h"
#include "build/build_config.h"
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/autofill/core/browser/credit_card.h"
......@@ -165,6 +166,17 @@ void WebController::LoadURL(const GURL& url) {
content::NavigationController::LoadURLParams(url));
}
void WebController::ClickOrTapElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) {
#if defined(OS_ANDROID)
TapElement(selectors, std::move(callback));
#else
// TODO(crbug.com/806868): Remove 'ClickElement' since this feature is only
// available on Android.
ClickElement(selectors, std::move(callback));
#endif
}
void WebController::ClickElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback) {
DCHECK(!selectors.empty());
......@@ -960,6 +972,14 @@ void WebController::OnClearFieldForDispatchKeyEvent(
return;
}
// TODO(crbug.com/806868): Substitute mouse click with touch tap.
//
// Note that 'KeyDown' will not be handled by the element immediately after
// touch tap. Add ~1 second delay before 'DispatchKeyDownEvent' in
// 'OnClickOrTapElementForDispatchKeyEvent' solved the problem, needs more
// investigation for this timing issue. One possible reason is that events
// from different devices are not guarranteed to be handled in order (needs a
// way to make sure previous events have been handled).
ClickElement(selectors,
base::BindOnce(&WebController::OnClickElementForDispatchKeyEvent,
weak_ptr_factory_.GetWeakPtr(), value,
......
......@@ -63,18 +63,12 @@ class WebController {
// been loaded.
virtual void LoadURL(const GURL& url);
// Perform a mouse left button click on the element given by |selectors| and
// return the result through callback.
// Perform a mouse left button click or a touch tap on the element given by
// |selectors| and return the result through callback.
// CSS selectors in |selectors| are ordered from top frame to the frame
// contains the element and the element.
virtual void ClickElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback);
// Perform a touch tap on the element given by |selectors| and return the
// result through callback. CSS selectors in |selectors| are ordered from top
// frame to the frame contains the element and the element.
virtual void TapElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback);
virtual void ClickOrTapElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback);
// Fill the address form given by |selectors| with the given address
// |profile|.
......@@ -165,6 +159,19 @@ class WebController {
private:
friend class WebControllerBrowserTest;
// Perform a mouse left button click on the element given by |selectors| and
// return the result through callback.
// CSS selectors in |selectors| are ordered from top frame to the frame
// contains the element and the element.
void ClickElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback);
// Perform a touch tap on the element given by |selectors| and return the
// result through callback. CSS selectors in |selectors| are ordered from top
// frame to the frame contains the element and the element.
void TapElement(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback);
struct FindElementResult {
FindElementResult() = default;
~FindElementResult() = default;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment