Commit 920741ee authored by sandromaggi's avatar sandromaggi Committed by Commit Bot

[Autofill Assistant] Let backend know what data is available

Letting the backend know what data has been requested and is currently
available. This helps debugging Autofill issues and can be used to
control the field setting action (crrev/c/2435084) from the backend.

Bug: b/169521597, b/167491545
Change-Id: I11b5e17906c162cb4ab51bc01f385c88695087bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2435384
Commit-Queue: Sandro Maggi <sandromaggi@google.com>
Reviewed-by: default avatarMarian Fechete <marianfe@google.com>
Cr-Commit-Position: refs/heads/master@{#811982}
parent 7e5b0e61
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "components/autofill/core/browser/geo/address_i18n.h" #include "components/autofill/core/browser/geo/address_i18n.h"
#include "components/autofill_assistant/browser/actions/action_delegate.h" #include "components/autofill_assistant/browser/actions/action_delegate.h"
#include "components/autofill_assistant/browser/client_status.h" #include "components/autofill_assistant/browser/client_status.h"
#include "components/autofill_assistant/browser/field_formatter.h"
#include "components/autofill_assistant/browser/metrics.h" #include "components/autofill_assistant/browser/metrics.h"
#include "components/autofill_assistant/browser/service.pb.h" #include "components/autofill_assistant/browser/service.pb.h"
#include "components/autofill_assistant/browser/user_data_util.h" #include "components/autofill_assistant/browser/user_data_util.h"
...@@ -385,6 +386,18 @@ void SetInitialUserDataForAdditionalSection( ...@@ -385,6 +386,18 @@ void SetInitialUserDataForAdditionalSection(
break; break;
} }
} }
void AddNonEmptyFieldNames(
const autofill::AutofillProfile* profile,
google::protobuf::RepeatedPtrField<std::string>* dest) {
DCHECK(profile != nullptr);
const auto& map = autofill_assistant::field_formatter::CreateAutofillMappings(
*profile, /* locale= */ "en-US");
for (const auto& it : map) {
*dest->Add() = it.first;
}
}
} // namespace } // namespace
namespace autofill_assistant { namespace autofill_assistant {
...@@ -1107,17 +1120,42 @@ void CollectUserDataAction::WriteProcessedAction(UserData* user_data, ...@@ -1107,17 +1120,42 @@ void CollectUserDataAction::WriteProcessedAction(UserData* user_data,
auto* selected_profile = user_data->selected_address( auto* selected_profile = user_data->selected_address(
contact_details_proto.contact_details_name()); contact_details_proto.contact_details_name());
if (contact_details_proto.request_payer_name() && if (selected_profile != nullptr) {
selected_profile != nullptr) { AddNonEmptyFieldNames(
Metrics::RecordPaymentRequestFirstNameOnly( selected_profile,
selected_profile->GetRawInfo(autofill::NAME_LAST).empty()); processed_action_proto_->mutable_collect_user_data_result()
} ->mutable_non_empty_contact_field());
if (contact_details_proto.request_payer_email() && if (contact_details_proto.request_payer_name()) {
selected_profile != nullptr) { Metrics::RecordPaymentRequestFirstNameOnly(
processed_action_proto_->mutable_collect_user_data_result() selected_profile->GetRawInfo(autofill::NAME_LAST).empty());
->set_payer_email(base::UTF16ToUTF8( }
selected_profile->GetRawInfo(autofill::EMAIL_ADDRESS)));
if (contact_details_proto.request_payer_email()) {
processed_action_proto_->mutable_collect_user_data_result()
->set_payer_email(base::UTF16ToUTF8(
selected_profile->GetRawInfo(autofill::EMAIL_ADDRESS)));
}
}
}
if (!proto().collect_user_data().shipping_address_name().empty()) {
auto* selected_shipping_address = user_data->selected_address(
proto().collect_user_data().shipping_address_name());
if (selected_shipping_address != nullptr) {
AddNonEmptyFieldNames(
selected_shipping_address,
processed_action_proto_->mutable_collect_user_data_result()
->mutable_non_empty_shipping_address_field());
}
}
if (!proto().collect_user_data().billing_address_name().empty()) {
auto* selected_billing_address = user_data->selected_address(
proto().collect_user_data().billing_address_name());
if (selected_billing_address != nullptr) {
AddNonEmptyFieldNames(
selected_billing_address,
processed_action_proto_->mutable_collect_user_data_result()
->mutable_non_empty_billing_address_field());
} }
} }
......
...@@ -8,10 +8,12 @@ ...@@ -8,10 +8,12 @@
#include "base/guid.h" #include "base/guid.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/gmock_callback_support.h" #include "base/test/gmock_callback_support.h"
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "components/autofill/core/browser/autofill_test_utils.h" #include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill_assistant/browser/actions/mock_action_delegate.h" #include "components/autofill_assistant/browser/actions/mock_action_delegate.h"
#include "components/autofill_assistant/browser/mock_personal_data_manager.h" #include "components/autofill_assistant/browser/mock_personal_data_manager.h"
#include "components/autofill_assistant/browser/mock_website_login_manager.h" #include "components/autofill_assistant/browser/mock_website_login_manager.h"
...@@ -51,6 +53,7 @@ using ::testing::_; ...@@ -51,6 +53,7 @@ using ::testing::_;
using ::testing::ElementsAre; using ::testing::ElementsAre;
using ::testing::Eq; using ::testing::Eq;
using ::testing::Invoke; using ::testing::Invoke;
using ::testing::IsSupersetOf;
using ::testing::Property; using ::testing::Property;
using ::testing::Return; using ::testing::Return;
using ::testing::SizeIs; using ::testing::SizeIs;
...@@ -618,12 +621,31 @@ TEST_F(CollectUserDataActionTest, SelectContactDetails) { ...@@ -618,12 +621,31 @@ TEST_F(CollectUserDataActionTest, SelectContactDetails) {
.Run(&user_data_, &user_model_); .Run(&user_data_, &user_model_);
})); }));
EXPECT_CALL(callback_, std::vector<std::string> expected_non_empty_fields = {
Run(Pointee(AllOf( base::NumberToString(
Property(&ProcessedActionProto::status, ACTION_APPLIED), static_cast<int>(autofill::ServerFieldType::NAME_FULL)),
Property(&ProcessedActionProto::collect_user_data_result, base::NumberToString(
Property(&CollectUserDataResultProto::payer_email, static_cast<int>(autofill::ServerFieldType::NAME_FIRST)),
"marion@me.xyz")))))); base::NumberToString(
static_cast<int>(autofill::ServerFieldType::NAME_MIDDLE)),
base::NumberToString(
static_cast<int>(autofill::ServerFieldType::NAME_LAST)),
base::NumberToString(
static_cast<int>(autofill::ServerFieldType::EMAIL_ADDRESS)),
base::NumberToString(static_cast<int>(
autofill::ServerFieldType::PHONE_HOME_WHOLE_NUMBER))};
EXPECT_CALL(
callback_,
Run(Pointee(AllOf(
Property(&ProcessedActionProto::status, ACTION_APPLIED),
Property(
&ProcessedActionProto::collect_user_data_result,
AllOf(
Property(&CollectUserDataResultProto::payer_email,
"marion@me.xyz"),
Property(&CollectUserDataResultProto::non_empty_contact_field,
IsSupersetOf(expected_non_empty_fields))))))));
CollectUserDataAction action(&mock_action_delegate_, action_proto); CollectUserDataAction action(&mock_action_delegate_, action_proto);
action.ProcessAction(callback_.Get()); action.ProcessAction(callback_.Get());
...@@ -733,13 +755,25 @@ TEST_F(CollectUserDataActionTest, SelectPaymentMethod) { ...@@ -733,13 +755,25 @@ TEST_F(CollectUserDataActionTest, SelectPaymentMethod) {
.Run(&user_data_, &user_model_); .Run(&user_data_, &user_model_);
})); }));
std::vector<std::string> expected_non_empty_fields = {
base::NumberToString(
static_cast<int>(autofill::ServerFieldType::NAME_FIRST)),
base::NumberToString(
static_cast<int>(autofill::ServerFieldType::NAME_MIDDLE)),
base::NumberToString(
static_cast<int>(autofill::ServerFieldType::NAME_LAST))};
EXPECT_CALL( EXPECT_CALL(
callback_, callback_,
Run(Pointee(AllOf( Run(Pointee(AllOf(
Property(&ProcessedActionProto::status, ACTION_APPLIED), Property(&ProcessedActionProto::status, ACTION_APPLIED),
Property(&ProcessedActionProto::collect_user_data_result, Property(
Property(&CollectUserDataResultProto::card_issuer_network, &ProcessedActionProto::collect_user_data_result,
"visa")))))); AllOf(Property(&CollectUserDataResultProto::card_issuer_network,
"visa"),
Property(&CollectUserDataResultProto::
non_empty_billing_address_field,
IsSupersetOf(expected_non_empty_fields))))))));
CollectUserDataAction action(&mock_action_delegate_, action_proto); CollectUserDataAction action(&mock_action_delegate_, action_proto);
action.ProcessAction(callback_.Get()); action.ProcessAction(callback_.Get());
...@@ -747,6 +781,53 @@ TEST_F(CollectUserDataActionTest, SelectPaymentMethod) { ...@@ -747,6 +781,53 @@ TEST_F(CollectUserDataActionTest, SelectPaymentMethod) {
EXPECT_THAT(user_data_.selected_card_->Compare(credit_card), Eq(0)); EXPECT_THAT(user_data_.selected_card_->Compare(credit_card), Eq(0));
} }
TEST_F(CollectUserDataActionTest, SelectShippingAddress) {
ActionProto action_proto;
auto* collect_user_data_proto = action_proto.mutable_collect_user_data();
collect_user_data_proto->set_request_terms_and_conditions(false);
collect_user_data_proto->set_shipping_address_name(kMemoryLocation);
autofill::AutofillProfile shipping_address(base::GenerateGUID(), kFakeUrl);
autofill::test::SetProfileInfo(&shipping_address, "Marion", "Mitchell",
"Morrison", "marion@me.xyz", "Fox",
"123 Zoo St.", "unit 5", "Hollywood", "CA",
"91601", "US", "16505678910");
ON_CALL(mock_action_delegate_, CollectUserData(_))
.WillByDefault(
Invoke([=](CollectUserDataOptions* collect_user_data_options) {
user_data_.selected_addresses_[kMemoryLocation] =
std::make_unique<autofill::AutofillProfile>(shipping_address);
std::move(collect_user_data_options->confirm_callback)
.Run(&user_data_, &user_model_);
}));
std::vector<std::string> expected_non_empty_fields = {
base::NumberToString(
static_cast<int>(autofill::ServerFieldType::NAME_FIRST)),
base::NumberToString(
static_cast<int>(autofill::ServerFieldType::NAME_MIDDLE)),
base::NumberToString(
static_cast<int>(autofill::ServerFieldType::NAME_LAST))};
EXPECT_CALL(
callback_,
Run(Pointee(AllOf(
Property(&ProcessedActionProto::status, ACTION_APPLIED),
Property(
&ProcessedActionProto::collect_user_data_result,
Property(
&CollectUserDataResultProto::non_empty_shipping_address_field,
IsSupersetOf(expected_non_empty_fields)))))));
CollectUserDataAction action(&mock_action_delegate_, action_proto);
action.ProcessAction(callback_.Get());
EXPECT_TRUE(user_data_.has_selected_address(kMemoryLocation));
EXPECT_EQ(user_data_.selected_addresses_[kMemoryLocation]->Compare(
shipping_address),
0);
}
TEST_F(CollectUserDataActionTest, MandatoryPostalCodeWithoutErrorMessageFails) { TEST_F(CollectUserDataActionTest, MandatoryPostalCodeWithoutErrorMessageFails) {
ActionProto action_proto; ActionProto action_proto;
action_proto.mutable_collect_user_data()->set_request_payment_method(true); action_proto.mutable_collect_user_data()->set_request_payment_method(true);
......
...@@ -560,6 +560,12 @@ message CollectUserDataResultProto { ...@@ -560,6 +560,12 @@ message CollectUserDataResultProto {
optional bool shown_to_user = 16; optional bool shown_to_user = 16;
// Indicates that the chosen login option was missing the username. // Indicates that the chosen login option was missing the username.
optional bool login_missing_username = 17; optional bool login_missing_username = 17;
// Indicates what profile data is available for the Contact.
repeated string non_empty_contact_field = 18;
// Indicates what profile data is available for the Shipping address.
repeated string non_empty_shipping_address_field = 19;
// Indicates what profile data is available for the Billing address.
repeated string non_empty_billing_address_field = 20;
reserved 7, 8; reserved 7, 8;
} }
......
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