Commit 19361974 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Commit Bot

[Autofill Assistant] Handle value field in FormValueMatch.

Bug: b/119554665

Change-Id: I9087ab89ff72f083d9fc97512a539026551e4fb4
Reviewed-on: https://chromium-review.googlesource.com/c/1365441
Commit-Queue: Jordan Demeulenaere <jdemeulenaere@chromium.org>
Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614670}
parent 4bcb888a
......@@ -100,12 +100,13 @@ void ScriptPrecondition::Check(
batch_checks->AddElementCheck(kExistenceCheck, selector,
std::move(callback));
}
for (const auto& value_match : form_value_match_) {
for (size_t i = 0; i < form_value_match_.size(); i++) {
const auto& value_match = form_value_match_[i];
DCHECK(!value_match.element().selectors().empty());
batch_checks->AddFieldValueCheck(
Selector(value_match.element()),
base::BindOnce(&ScriptPrecondition::OnGetFieldValue,
weak_ptr_factory_.GetWeakPtr()));
weak_ptr_factory_.GetWeakPtr(), i));
}
}
......@@ -200,8 +201,21 @@ void ScriptPrecondition::OnCheckElementExists(bool exists) {
ReportCheckResult(exists);
}
void ScriptPrecondition::OnGetFieldValue(bool exists,
void ScriptPrecondition::OnGetFieldValue(int index,
bool exists,
const std::string& value) {
if (!exists) {
ReportCheckResult(false);
return;
}
// TODO(crbug.com/806868): Differentiate between empty value and failure.
const auto& value_match = form_value_match_[index];
if (value_match.has_value()) {
ReportCheckResult(value == value_match.value());
return;
}
ReportCheckResult(!value.empty());
}
......
......@@ -65,7 +65,7 @@ class ScriptPrecondition {
const std::map<std::string, ScriptStatusProto>& executed_scripts) const;
void OnCheckElementExists(bool exists);
void OnGetFieldValue(bool exists, const std::string& value);
void OnGetFieldValue(int index, bool exists, const std::string& value);
void ReportCheckResult(bool success);
std::vector<Selector> elements_exist_;
......
......@@ -322,6 +322,13 @@ TEST_F(ScriptPreconditionTest, FormValueMatch) {
match->mutable_element()->add_selectors("exists");
EXPECT_TRUE(Check(proto));
match->set_value("bar");
EXPECT_FALSE(Check(proto));
match->set_value("foo");
EXPECT_TRUE(Check(proto));
match->clear_value();
match->mutable_element()->set_selectors(0, "does_not_exist");
EXPECT_FALSE(Check(proto));
}
......
......@@ -156,6 +156,11 @@ message FormValueMatchProto {
// Required. The selector associated to the form element whose value should be
// checked.
optional ElementReferenceProto element = 1;
// Optional value. If specified, the element value must match the given value,
// even if it's empty. If not specified, we just check that the element value
// is non empty.
optional string value = 2;
}
enum PolicyType {
......
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