Commit 033a80f6 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Autofill] Delete legacy_proto_bridge.*

After recent CLs, no conversion from legacy server proto to the new API
server protos is required.

This CL is getting rid of the code responsible for that.

Bug: 1114655
Change-Id: I98d04fca0a13a13b43a950bbcb4c3f400259115a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431044
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810701}
parent 6c57430b
......@@ -370,7 +370,6 @@ static_library("browser") {
]
deps = [
":autofill_address_rewriter_resources",
"proto:legacy_proto_bridge",
"//base",
"//base:i18n",
"//build:branding_buildflags",
......@@ -647,7 +646,6 @@ source_set("unit_tests") {
"payments/strike_database_integrator_test_strike_database_unittest.cc",
"payments/strike_database_unittest.cc",
"personal_data_manager_unittest.cc",
"proto/legacy_proto_bridge_unittest.cc",
"randomized_encoder_unittest.cc",
"rationalization_util_unittest.cc",
"ui/address_combobox_model_unittest.cc",
......@@ -706,7 +704,6 @@ source_set("unit_tests") {
":browser",
":test_support",
":unit_tests_bundle_data",
"proto:legacy_proto_bridge",
"//base",
"//base/test:test_support",
"//components/autofill/core/common",
......
......@@ -37,7 +37,6 @@
#include "components/autofill/core/browser/form_parsing/field_candidates.h"
#include "components/autofill/core/browser/form_parsing/form_field.h"
#include "components/autofill/core/browser/logging/log_manager.h"
#include "components/autofill/core/browser/proto/legacy_proto_bridge.h"
#include "components/autofill/core/browser/randomized_encoder.h"
#include "components/autofill/core/browser/rationalization_util.h"
#include "components/autofill/core/browser/validation.h"
......
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# Copyright 2016 The Chromium Authors.All rights reserved.
# Use of this source code is governed by a BSD - style license that can be
# found in the LICENSE file.
import("//third_party/libprotobuf-mutator/fuzzable_proto_library.gni")
......@@ -14,11 +14,3 @@ fuzzable_proto_library("proto") {
"strike_data.proto",
]
}
static_library("legacy_proto_bridge") {
sources = [
"legacy_proto_bridge.cc",
"legacy_proto_bridge.h",
]
deps = [ ":proto" ]
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/autofill/core/browser/proto/legacy_proto_bridge.h"
namespace autofill {
namespace {
AutofillPageQueryRequest::Form::Field CreateLegacyFieldFromApiField(
const AutofillQueryContents::Form::Field& legacy_field) {
AutofillPageQueryRequest::Form::Field api_field;
api_field.set_signature(legacy_field.signature());
api_field.set_name(legacy_field.name());
api_field.set_control_type(legacy_field.type());
if (legacy_field.has_field_metadata())
*api_field.mutable_metadata() = legacy_field.field_metadata();
return api_field;
}
AutofillPageQueryRequest::Form CreateApiFormFromLegacyForm(
const AutofillQueryContents::Form& legacy_form) {
AutofillPageQueryRequest::Form api_form;
api_form.set_signature(legacy_form.signature());
if (legacy_form.has_form_metadata())
*api_form.mutable_metadata() = legacy_form.form_metadata();
for (const auto& legacy_field : legacy_form.field()) {
*api_form.add_fields() = CreateLegacyFieldFromApiField(legacy_field);
}
return api_form;
}
AutofillQueryResponseContents::Field::FieldPrediction
CreateLegacyFieldPredictionFromApiPrediction(
const AutofillQueryResponse::FormSuggestion::FieldSuggestion::
FieldPrediction& api_field_prediction) {
AutofillQueryResponseContents::Field::FieldPrediction legacy_prediction;
legacy_prediction.set_type(api_field_prediction.type());
return legacy_prediction;
}
AutofillQueryResponseContents::Field CreateLegacyFieldFromApiField(
const AutofillQueryResponse::FormSuggestion::FieldSuggestion& api_field) {
AutofillQueryResponseContents::Field legacy_field;
legacy_field.set_overall_type_prediction(api_field.primary_type_prediction());
for (const auto& api_prediction : api_field.predictions()) {
AutofillQueryResponseContents::Field::FieldPrediction legacy_prediction =
CreateLegacyFieldPredictionFromApiPrediction(api_prediction);
legacy_prediction.set_may_use_prefilled_placeholder(
api_field.may_use_prefilled_placeholder());
*legacy_field.add_predictions() = legacy_prediction;
}
*legacy_field.mutable_password_requirements() =
api_field.password_requirements();
return legacy_field;
}
} // namespace
AutofillPageQueryRequest CreateApiRequestFromLegacyRequest(
const AutofillQueryContents& legacy_request) {
AutofillPageQueryRequest api_request;
*api_request.mutable_experiments() = legacy_request.experiments();
api_request.set_client_version(legacy_request.client_version());
for (const auto& legacy_form : legacy_request.form()) {
*api_request.add_forms() = CreateApiFormFromLegacyForm(legacy_form);
}
return api_request;
}
AutofillQueryResponseContents CreateLegacyResponseFromApiResponse(
const AutofillQueryResponse& api_response) {
AutofillQueryResponseContents legacy_response;
for (const auto& api_form : api_response.form_suggestions()) {
for (const auto& api_field : api_form.field_suggestions()) {
*legacy_response.add_field() = CreateLegacyFieldFromApiField(api_field);
}
}
return legacy_response;
}
} // namespace autofill
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_PROTO_LEGACY_PROTO_BRIDGE_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_PROTO_LEGACY_PROTO_BRIDGE_H_
#include "components/autofill/core/browser/proto/api_v1.pb.h"
#include "components/autofill/core/browser/proto/server.pb.h"
namespace autofill {
// Creates an API request from a legacy request.
autofill::AutofillPageQueryRequest CreateApiRequestFromLegacyRequest(
const AutofillQueryContents& legacy_request);
// Creates a legacy response from an API response.
AutofillQueryResponseContents CreateLegacyResponseFromApiResponse(
const autofill::AutofillQueryResponse& api_response);
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PROTO_LEGACY_PROTO_BRIDGE_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/autofill/core/browser/proto/legacy_proto_bridge.h"
#include "components/autofill/core/browser/proto/api_v1.pb.h"
#include "components/autofill/core/browser/proto/password_requirements.pb.h"
#include "components/autofill/core/browser/proto/server.pb.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
namespace {
using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::Property;
// Makes an arbitrary field metadata proto to be used for testing.
AutofillRandomizedFieldMetadata GetFieldMetadata() {
AutofillRandomizedFieldMetadata metadata;
AutofillRandomizedValue random_value;
random_value.set_encoding_type(AutofillRandomizedValue::BIT_0);
random_value.set_encoded_bits("1234");
*metadata.mutable_id() = std::move(random_value);
return metadata;
}
// Makes an arbitrary form metadata proto to be used for testing.
AutofillRandomizedFormMetadata GetformMetadata() {
AutofillRandomizedFormMetadata metadata;
AutofillRandomizedValue random_value;
random_value.set_encoding_type(AutofillRandomizedValue::BIT_1);
random_value.set_encoded_bits("5678");
*metadata.mutable_id() = std::move(random_value);
return metadata;
}
AutofillQueryContents::Form::Field MakeLegacyField(uint32_t signature,
const std::string& name,
const std::string& type) {
AutofillQueryContents::Form::Field field;
field.set_signature(signature);
field.set_name(name);
field.set_type(type);
*field.mutable_field_metadata() = GetFieldMetadata();
return field;
}
AutofillQueryResponse::FormSuggestion::FieldSuggestion MakeFieldSuggestion(
uint32_t field_signature,
uint32_t primary_type_prediction,
std::vector<uint32_t> predictions,
bool may_use_prefilled_placeholder,
PasswordRequirementsSpec password_requirements) {
AutofillQueryResponse::FormSuggestion::FieldSuggestion field_suggestion;
field_suggestion.set_field_signature(field_signature);
field_suggestion.set_primary_type_prediction(primary_type_prediction);
for (auto prediction : predictions) {
field_suggestion.add_predictions()->set_type(prediction);
}
field_suggestion.set_may_use_prefilled_placeholder(
may_use_prefilled_placeholder);
*field_suggestion.mutable_password_requirements() =
std::move(password_requirements);
return field_suggestion;
}
TEST(ProtoBridgeTest, TestCreateApiRequestFromLegacyRequest) {
AutofillQueryContents legacy_request;
legacy_request.set_client_version("dummy client v1");
legacy_request.add_experiments(1234);
legacy_request.add_experiments(5678);
AutofillQueryContents::Form* new_form = legacy_request.add_form();
new_form->set_signature(1234U);
*new_form->mutable_form_metadata() = GetformMetadata();
*new_form->add_field() = MakeLegacyField(1234U, "First Name", "text");
*new_form->add_field() = MakeLegacyField(5678U, "Last Name", "text");
new_form = legacy_request.add_form();
new_form->set_signature(5678U);
*new_form->mutable_form_metadata() = GetformMetadata();
*new_form->add_field() = MakeLegacyField(1234U, "Street Address", "text");
*new_form->add_field() = MakeLegacyField(5678U, "Zip Code", "text");
AutofillPageQueryRequest api_request =
CreateApiRequestFromLegacyRequest(legacy_request);
EXPECT_EQ(api_request.client_version(), "dummy client v1");
EXPECT_EQ(api_request.experiments(0), 1234);
EXPECT_EQ(api_request.experiments(1), 5678);
EXPECT_EQ(api_request.forms(0).signature(), 1234U);
EXPECT_EQ(api_request.forms(0).metadata().id().encoding_type(),
AutofillRandomizedValue::BIT_1);
EXPECT_EQ(api_request.forms(0).metadata().id().encoded_bits(), "5678");
EXPECT_EQ(api_request.forms(1).signature(), 5678U);
EXPECT_EQ(api_request.forms(1).metadata().id().encoding_type(),
AutofillRandomizedValue::BIT_1);
EXPECT_EQ(api_request.forms(1).metadata().id().encoded_bits(), "5678");
// Assert fields of form 0.
EXPECT_EQ(api_request.forms(0).fields(0).signature(), 1234U);
EXPECT_EQ(api_request.forms(0).fields(0).name(), "First Name");
EXPECT_EQ(api_request.forms(0).fields(0).control_type(), "text");
EXPECT_EQ(api_request.forms(0).fields(0).metadata().id().encoding_type(),
AutofillRandomizedValue::BIT_0);
EXPECT_EQ(api_request.forms(0).fields(0).metadata().id().encoded_bits(),
"1234");
EXPECT_EQ(api_request.forms(0).fields(1).signature(), 5678U);
EXPECT_EQ(api_request.forms(0).fields(1).name(), "Last Name");
EXPECT_EQ(api_request.forms(0).fields(1).control_type(), "text");
EXPECT_EQ(api_request.forms(0).fields(1).metadata().id().encoding_type(),
AutofillRandomizedValue::BIT_0);
EXPECT_EQ(api_request.forms(0).fields(1).metadata().id().encoded_bits(),
"1234");
// Assert fields of form 1.
EXPECT_EQ(api_request.forms(1).fields(0).signature(), 1234U);
EXPECT_EQ(api_request.forms(1).fields(0).name(), "Street Address");
EXPECT_EQ(api_request.forms(1).fields(0).control_type(), "text");
EXPECT_EQ(api_request.forms(1).fields(0).metadata().id().encoding_type(),
AutofillRandomizedValue::BIT_0);
EXPECT_EQ(api_request.forms(1).fields(0).metadata().id().encoded_bits(),
"1234");
EXPECT_EQ(api_request.forms(1).fields(1).signature(), 5678U);
EXPECT_EQ(api_request.forms(1).fields(1).name(), "Zip Code");
EXPECT_EQ(api_request.forms(1).fields(1).control_type(), "text");
EXPECT_EQ(api_request.forms(1).fields(1).metadata().id().encoding_type(),
AutofillRandomizedValue::BIT_0);
EXPECT_EQ(api_request.forms(1).fields(1).metadata().id().encoded_bits(),
"1234");
}
TEST(ProtoBridgeTest, CreateLegacyResponseFromApiResponse) {
constexpr uint32_t dummy_password_type = 1U;
constexpr uint32_t dummy_address_type = 2U;
constexpr uint32_t dummy_password_priority = 3U;
PasswordRequirementsSpec dummy_password_requirement_specs;
dummy_password_requirement_specs.set_priority(dummy_password_priority);
AutofillQueryResponse api_response;
// Add suggestions for form 0.
auto* form_suggestion = api_response.add_form_suggestions();
*form_suggestion->add_field_suggestions() = MakeFieldSuggestion(
/*field_signature=*/1234U,
/*primary_type_prediction=*/dummy_password_type,
/*predictions=*/{dummy_password_type, dummy_address_type},
/*may_use_prefilled_placeholder=*/true,
/*password_requirements=*/dummy_password_requirement_specs);
// Add suggestions for form 1.
form_suggestion = api_response.add_form_suggestions();
*form_suggestion->add_field_suggestions() = MakeFieldSuggestion(
/*field_signature=*/5678U, /*primary_type_prediction=*/dummy_address_type,
/*predictions=*/{dummy_address_type, dummy_password_type},
/*may_use_prefilled_placeholder=*/false,
/*password_requirements=*/dummy_password_requirement_specs);
AutofillQueryResponseContents legacy_response =
CreateLegacyResponseFromApiResponse(api_response);
// Assert fields of form 0 in legacy response.
EXPECT_EQ(legacy_response.field(0).overall_type_prediction(),
dummy_password_type);
EXPECT_THAT(
legacy_response.field(0).predictions(),
ElementsAre(
Property(&AutofillQueryResponseContents::Field::FieldPrediction::type,
Eq(dummy_password_type)),
Property(&AutofillQueryResponseContents::Field::FieldPrediction::type,
Eq(dummy_address_type))));
EXPECT_THAT(
legacy_response.field(0).predictions(),
ElementsAre(Property(&AutofillQueryResponseContents::Field::
FieldPrediction::may_use_prefilled_placeholder,
Eq(true)),
Property(&AutofillQueryResponseContents::Field::
FieldPrediction::may_use_prefilled_placeholder,
Eq(true))));
EXPECT_THAT(legacy_response.field(0).password_requirements(),
Property(&PasswordRequirementsSpec::priority,
Eq(dummy_password_priority)));
// Assert fields of form 1 in legacy response.
EXPECT_EQ(legacy_response.field(1).overall_type_prediction(),
dummy_address_type);
EXPECT_THAT(
legacy_response.field(1).predictions(),
ElementsAre(
Property(&AutofillQueryResponseContents::Field::FieldPrediction::type,
Eq(dummy_address_type)),
Property(&AutofillQueryResponseContents::Field::FieldPrediction::type,
Eq(dummy_password_type))));
EXPECT_THAT(
legacy_response.field(1).predictions(),
ElementsAre(Property(&AutofillQueryResponseContents::Field::
FieldPrediction::may_use_prefilled_placeholder,
Eq(false)),
Property(&AutofillQueryResponseContents::Field::
FieldPrediction::may_use_prefilled_placeholder,
Eq(false))));
EXPECT_THAT(legacy_response.field(1).password_requirements(),
Property(&PasswordRequirementsSpec::priority,
Eq(dummy_password_priority)));
}
} // namespace
} // namespace autofill
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