Commit cbd929a7 authored by sandromaggi's avatar sandromaggi Committed by Commit Bot

[Autofill Assistant] Forward the element

Bug: b/171782156
Change-Id: I032f22571e342e47a2d6c8b33ce735fab40acf88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2504313
Commit-Queue: Sandro Maggi <sandromaggi@google.com>
Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821720}
parent 0a7c19df
...@@ -91,9 +91,9 @@ void BatchElementChecker::Run(WebController* web_controller) { ...@@ -91,9 +91,9 @@ void BatchElementChecker::Run(WebController* web_controller) {
void BatchElementChecker::OnElementChecked( void BatchElementChecker::OnElementChecked(
std::vector<ElementCheckCallback>* callbacks, std::vector<ElementCheckCallback>* callbacks,
const ClientStatus& element_status, const ClientStatus& element_status,
std::unique_ptr<ElementFinder::Result> ignored_element) { std::unique_ptr<ElementFinder::Result> element_result) {
for (auto& callback : *callbacks) { for (auto& callback : *callbacks) {
std::move(callback).Run(element_status); std::move(callback).Run(element_status, *element_result);
} }
callbacks->clear(); callbacks->clear();
CheckDone(); CheckDone();
......
...@@ -29,10 +29,13 @@ class BatchElementChecker { ...@@ -29,10 +29,13 @@ class BatchElementChecker {
explicit BatchElementChecker(); explicit BatchElementChecker();
virtual ~BatchElementChecker(); virtual ~BatchElementChecker();
// Callback for AddElementCheck. Argument is true if the check passed. // Callback for AddElementCheck. Arguments are an ok client status if the
// check passed and an |ElementFinder::Result|.
// //
// An ElementCheckCallback must not delete its calling BatchElementChecker. // An ElementCheckCallback must not delete its calling BatchElementChecker.
using ElementCheckCallback = base::OnceCallback<void(const ClientStatus&)>; using ElementCheckCallback =
base::OnceCallback<void(const ClientStatus&,
const ElementFinder::Result&)>;
// Callback for AddFieldValueCheck. Argument is true is the element exists. // Callback for AddFieldValueCheck. Argument is true is the element exists.
// The string contains the field value, or an empty string if accessing the // The string contains the field value, or an empty string if accessing the
...@@ -74,11 +77,9 @@ class BatchElementChecker { ...@@ -74,11 +77,9 @@ class BatchElementChecker {
base::OnceCallback<void(const ClientStatus&, const std::string&)>)>; base::OnceCallback<void(const ClientStatus&, const std::string&)>)>;
// Gets called for each ElementCheck. // Gets called for each ElementCheck.
// TODO(b/171782156): The element is currently ignored, it will be forwarded
// to the caller through |ElementCheckCallback|.
void OnElementChecked(std::vector<ElementCheckCallback>* callbacks, void OnElementChecked(std::vector<ElementCheckCallback>* callbacks,
const ClientStatus& element_status, const ClientStatus& element_status,
std::unique_ptr<ElementFinder::Result> ignored_element); std::unique_ptr<ElementFinder::Result> element_result);
// Gets called for each FieldValueCheck. // Gets called for each FieldValueCheck.
void OnFindElementForGetFieldValue( void OnFindElementForGetFieldValue(
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "components/autofill_assistant/browser/actions/action_test_utils.h" #include "components/autofill_assistant/browser/actions/action_test_utils.h"
#include "components/autofill_assistant/browser/web/element_finder.h"
#include "components/autofill_assistant/browser/web/mock_web_controller.h" #include "components/autofill_assistant/browser/web/mock_web_controller.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -37,7 +38,8 @@ class BatchElementCheckerTest : public testing::Test { ...@@ -37,7 +38,8 @@ class BatchElementCheckerTest : public testing::Test {
void SetUp() override { test_util::MockFindAnyElement(mock_web_controller_); } void SetUp() override { test_util::MockFindAnyElement(mock_web_controller_); }
void OnElementExistenceCheck(const std::string& name, void OnElementExistenceCheck(const std::string& name,
const ClientStatus& result) { const ClientStatus& result,
const ElementFinder::Result& ignored_element) {
element_exists_results_[name] = result.ok(); element_exists_results_[name] = result.ok();
} }
...@@ -47,8 +49,10 @@ class BatchElementCheckerTest : public testing::Test { ...@@ -47,8 +49,10 @@ class BatchElementCheckerTest : public testing::Test {
base::Unretained(this), name); base::Unretained(this), name);
} }
void OnVisibilityRequirementCheck(const std::string& name, void OnVisibilityRequirementCheck(
const ClientStatus& result) { const std::string& name,
const ClientStatus& result,
const ElementFinder::Result& ignored_element) {
element_visible_results_[name] = result.ok(); element_visible_results_[name] = result.ok();
} }
......
...@@ -34,10 +34,10 @@ void ElementPrecondition::Check( ...@@ -34,10 +34,10 @@ void ElementPrecondition::Check(
// Empty selectors never match. // Empty selectors never match.
continue; continue;
} }
base::OnceCallback<void(const ClientStatus&)> callback = batch_checks->AddElementCheck(
result.selector,
base::BindOnce(&ElementPrecondition::OnCheckElementExists, base::BindOnce(&ElementPrecondition::OnCheckElementExists,
weak_ptr_factory_.GetWeakPtr(), i); weak_ptr_factory_.GetWeakPtr(), i));
batch_checks->AddElementCheck(result.selector, std::move(callback));
} }
batch_checks->AddAllDoneCallback( batch_checks->AddAllDoneCallback(
base::BindOnce(&ElementPrecondition::OnAllElementChecksDone, base::BindOnce(&ElementPrecondition::OnAllElementChecksDone,
...@@ -46,7 +46,8 @@ void ElementPrecondition::Check( ...@@ -46,7 +46,8 @@ void ElementPrecondition::Check(
void ElementPrecondition::OnCheckElementExists( void ElementPrecondition::OnCheckElementExists(
size_t result_index, size_t result_index,
const ClientStatus& element_status) { const ClientStatus& element_status,
const ElementFinder::Result& element_reference) {
if (result_index >= results_.size()) { if (result_index >= results_.size()) {
NOTREACHED(); NOTREACHED();
return; return;
...@@ -55,6 +56,7 @@ void ElementPrecondition::OnCheckElementExists( ...@@ -55,6 +56,7 @@ void ElementPrecondition::OnCheckElementExists(
result.match = element_status.ok(); result.match = element_status.ok();
// TODO(szermatt): Consider reporting element_status as an unexpected error // TODO(szermatt): Consider reporting element_status as an unexpected error
// right away if it is neither success nor ELEMENT_RESOLUTION_FAILED. // right away if it is neither success nor ELEMENT_RESOLUTION_FAILED.
// TODO(b/171782156): Store the element, if the status is ok.
} }
void ElementPrecondition::OnAllElementChecksDone( void ElementPrecondition::OnAllElementChecksDone(
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/autofill_assistant/browser/client_status.h" #include "components/autofill_assistant/browser/client_status.h"
#include "components/autofill_assistant/browser/selector.h" #include "components/autofill_assistant/browser/selector.h"
#include "components/autofill_assistant/browser/service.pb.h" #include "components/autofill_assistant/browser/service.pb.h"
#include "components/autofill_assistant/browser/web/element_finder.h"
namespace autofill_assistant { namespace autofill_assistant {
class BatchElementChecker; class BatchElementChecker;
...@@ -53,7 +54,8 @@ class ElementPrecondition { ...@@ -53,7 +54,8 @@ class ElementPrecondition {
void AddResults(const ElementConditionProto& proto); void AddResults(const ElementConditionProto& proto);
void OnCheckElementExists(size_t result_index, void OnCheckElementExists(size_t result_index,
const ClientStatus& element_status); const ClientStatus& element_status,
const ElementFinder::Result& element_reference);
void OnAllElementChecksDone( void OnAllElementChecksDone(
base::OnceCallback<void(const ClientStatus&, base::OnceCallback<void(const ClientStatus&,
......
...@@ -988,7 +988,17 @@ void ScriptExecutor::CheckElementMatches( ...@@ -988,7 +988,17 @@ void ScriptExecutor::CheckElementMatches(
const Selector& selector, const Selector& selector,
BatchElementChecker* checker, BatchElementChecker* checker,
base::OnceCallback<void(const ClientStatus&)> callback) { base::OnceCallback<void(const ClientStatus&)> callback) {
checker->AddElementCheck(selector, std::move(callback)); checker->AddElementCheck(
selector,
base::BindOnce(&ScriptExecutor::CheckElementMatchesCallback,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void ScriptExecutor::CheckElementMatchesCallback(
base::OnceCallback<void(const ClientStatus&)> callback,
const ClientStatus& status,
const ElementFinder::Result& ignored_element) {
std::move(callback).Run(status);
} }
void ScriptExecutor::OnShortWaitForElement( void ScriptExecutor::OnShortWaitForElement(
......
...@@ -400,6 +400,10 @@ class ScriptExecutor : public ActionDelegate, ...@@ -400,6 +400,10 @@ class ScriptExecutor : public ActionDelegate,
const Selector& selector, const Selector& selector,
BatchElementChecker* checker, BatchElementChecker* checker,
base::OnceCallback<void(const ClientStatus&)> callback); base::OnceCallback<void(const ClientStatus&)> callback);
void CheckElementMatchesCallback(
base::OnceCallback<void(const ClientStatus&)> callback,
const ClientStatus& status,
const ElementFinder::Result& ignored_element);
void OnShortWaitForElement( void OnShortWaitForElement(
base::OnceCallback<void(const ClientStatus&)> callback, base::OnceCallback<void(const ClientStatus&)> callback,
const ClientStatus& element_status, const ClientStatus& element_status,
......
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