[Autofill] Remove `*_TAG` types from tests

This CL prepares the tests for enabling kAutofillAiNoTagTypes.

Bug: 422563282
Change-Id: I7f806b4b6405e617a98c704339093365bb5ab4ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6662438
Reviewed-by: Jan Keitel <jkeitel@google.com>
Commit-Queue: Christoph Schwering <schwering@google.com>
Cr-Commit-Position: refs/heads/main@{#1477317}
diff --git a/components/autofill/core/browser/crowdsourcing/determine_possible_field_types_unittest.cc b/components/autofill/core/browser/crowdsourcing/determine_possible_field_types_unittest.cc
index 186bb3b4..71c2441a 100644
--- a/components/autofill/core/browser/crowdsourcing/determine_possible_field_types_unittest.cc
+++ b/components/autofill/core/browser/crowdsourcing/determine_possible_field_types_unittest.cc
@@ -349,7 +349,7 @@
  public:
   DeterminePossibleFieldTypesForUploadTest() {
     scoped_feature_list_.InitWithFeatures(
-        {features::kAutofillAiWithDataSchema,
+        {features::kAutofillAiWithDataSchema, features::kAutofillAiNoTagTypes,
          features::kAutofillAiVoteForFormatStringsFromSingleFields,
          features::kAutofillAiVoteForFormatStringsFromMultipleFields,
          features::kAutofillEnableLoyaltyCardsFilling},
@@ -732,10 +732,9 @@
       ExtractDatesInFields(form_structure->fields()), "en-US", *form_structure);
 
   EXPECT_THAT(form_structure->fields()[0]->possible_types(),
-              UnorderedElementsAre(PASSPORT_NAME_TAG, NAME_FIRST));
-  EXPECT_THAT(
-      form_structure->fields()[1]->possible_types(),
-      UnorderedElementsAre(PASSPORT_NAME_TAG, NAME_LAST, NAME_LAST_SECOND));
+              UnorderedElementsAre(NAME_FIRST));
+  EXPECT_THAT(form_structure->fields()[1]->possible_types(),
+              UnorderedElementsAre(NAME_LAST, NAME_LAST_SECOND));
   EXPECT_THAT(form_structure->fields()[2]->possible_types(),
               UnorderedElementsAre(PASSPORT_NUMBER));
   EXPECT_THAT(form_structure->fields()[3]->possible_types(),
@@ -1101,10 +1100,12 @@
  public:
   DetermineAvailableFieldTypesTest() {
     features_.InitWithFeatures(
-        {features::kAutofillAiWithDataSchema,
-         features::kAutofillEnableLoyaltyCardsFilling,
-         features::kAutofillEnableEmailOrLoyaltyCardsFilling},
-        {});
+        /*enabled_features=*/{features::kAutofillAiWithDataSchema,
+                              features::kAutofillAiNoTagTypes,
+                              features::kAutofillEnableLoyaltyCardsFilling,
+                              features::
+                                  kAutofillEnableEmailOrLoyaltyCardsFilling},
+        /*disabled_features=*/{});
   }
 
  protected:
@@ -1120,11 +1121,11 @@
       /*loyalty_cards=*/{},
       /*last_unlocked_credit_card_cvc=*/u"",
       /*app_locale=*/"en-US");
-  EXPECT_THAT(available_types,
-              UnorderedElementsAre(
-                  NAME_FULL, NAME_FIRST, NAME_LAST, NAME_LAST_SECOND,
-                  PASSPORT_NAME_TAG, PASSPORT_NUMBER, PASSPORT_EXPIRATION_DATE,
-                  PASSPORT_ISSUE_DATE, PASSPORT_ISSUING_COUNTRY));
+  EXPECT_THAT(
+      available_types,
+      UnorderedElementsAre(NAME_FULL, NAME_FIRST, NAME_LAST, NAME_LAST_SECOND,
+                           PASSPORT_NUMBER, PASSPORT_EXPIRATION_DATE,
+                           PASSPORT_ISSUE_DATE, PASSPORT_ISSUING_COUNTRY));
 }
 
 // Tests that loyalty cards are included in the set of available field types.
diff --git a/components/autofill/core/browser/data_model/autofill_ai/entity_instance_unittest.cc b/components/autofill/core/browser/data_model/autofill_ai/entity_instance_unittest.cc
index 9aac4947..b814b4a4 100644
--- a/components/autofill/core/browser/data_model/autofill_ai/entity_instance_unittest.cc
+++ b/components/autofill/core/browser/data_model/autofill_ai/entity_instance_unittest.cc
@@ -10,6 +10,7 @@
 #include "components/autofill/core/browser/data_model/autofill_ai/entity_type.h"
 #include "components/autofill/core/browser/field_types.h"
 #include "components/autofill/core/browser/test_utils/autofill_test_utils.h"
+#include "components/autofill/core/common/autofill_features.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -50,11 +51,14 @@
   }
 }
 
-// Tests that AttributeInstance appropriately handles various types in its
-// getters.
+// Tests that AttributeInstance::GetInfo() returns the value for the specified
+// subtype (as per AttributeType::field_subtypes()) and defaults to the overall
+// type (AttributeType::field_type()).
 TEST(AutofillEntityInstanceTest, Attributes_NormalizedType) {
+  base::test::ScopedFeatureList scoped_feature_list{
+      features::kAutofillAiNoTagTypes};
   AttributeInstance passport_name((AttributeType(kPassportName)));
-  passport_name.SetInfo(NAME_FULL, u"Some Name",
+  passport_name.SetInfo(NAME_FULL, u"John Doe",
                         /*app_locale=*/"", /*format_string=*/u"",
                         VerificationStatus::kObserved);
   passport_name.FinalizeInfo();
@@ -64,15 +68,11 @@
                           /*app_locale=*/"", /*format_string=*/u"",
                           VerificationStatus::kObserved);
 
-  // We can retrieve info from structured attributes when the provided type
-  // gives us the information that is missing from the attribute's generic type
-  // (In that case `PASSPORT_NAME_TAG`). Otherwise we do not
-  EXPECT_EQ(GetInfo(passport_name, NAME_FULL), u"Some Name");
-  EXPECT_TRUE(GetInfo(passport_name, ADDRESS_HOME_STREET_NAME).empty());
+  EXPECT_EQ(GetInfo(passport_name, NAME_FULL), u"John Doe");
+  EXPECT_EQ(GetInfo(passport_name, NAME_FIRST), u"John");
+  EXPECT_EQ(GetInfo(passport_name, NAME_LAST), u"Doe");
+  EXPECT_EQ(GetInfo(passport_name, ADDRESS_HOME_STREET_NAME), u"John Doe");
 
-  // Non-structured attributes, on the other hand, have the complete information
-  // needed to fetch the value from the attribute type. Hence we just ignore the
-  // type given to the getter.
   EXPECT_EQ(GetInfo(passport_number, PASSPORT_NUMBER), u"LR0123456");
   EXPECT_EQ(GetInfo(passport_number, ADDRESS_HOME_STREET_NAME), u"LR0123456");
 }
diff --git a/components/autofill/core/browser/data_model/autofill_ai/entity_type_unittest.cc b/components/autofill/core/browser/data_model/autofill_ai/entity_type_unittest.cc
index b9178f0c..2035969 100644
--- a/components/autofill/core/browser/data_model/autofill_ai/entity_type_unittest.cc
+++ b/components/autofill/core/browser/data_model/autofill_ai/entity_type_unittest.cc
@@ -4,7 +4,9 @@
 
 #include "components/autofill/core/browser/data_model/autofill_ai/entity_type.h"
 
+#include "base/test/scoped_feature_list.h"
 #include "components/autofill/core/browser/data_model/autofill_ai/entity_type_names.h"
+#include "components/autofill/core/common/autofill_features.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -15,9 +17,10 @@
 using ::testing::UnorderedElementsAre;
 
 TEST(AutofillAttributeTypeTest, Relationships) {
+  base::test::ScopedFeatureList scoped_feature_list{
+      features::kAutofillAiNoTagTypes};
   AttributeType a = AttributeType(AttributeTypeName::kPassportName);
   EXPECT_EQ(a.entity_type(), EntityType(EntityTypeName::kPassport));
-  EXPECT_EQ(a.field_type(), PASSPORT_NAME_TAG);
   EXPECT_THAT(a.field_subtypes(),
               UnorderedElementsAre(
                   NAME_HONORIFIC_PREFIX, NAME_FIRST, NAME_MIDDLE, NAME_LAST,
diff --git a/components/autofill/core/browser/filling/autofill_ai/field_filling_entity_util_unittest.cc b/components/autofill/core/browser/filling/autofill_ai/field_filling_entity_util_unittest.cc
index 0a91676..3ed3391c 100644
--- a/components/autofill/core/browser/filling/autofill_ai/field_filling_entity_util_unittest.cc
+++ b/components/autofill/core/browser/filling/autofill_ai/field_filling_entity_util_unittest.cc
@@ -67,16 +67,44 @@
     mojom::ActionPersistence action_persistence,
     const std::string& app_locale = kAppLocaleUS,
     AddressNormalizer* address_normalizer = nullptr) {
-  return autofill::GetFillValueForEntity(
-      entity,
+  std::vector<AutofillFieldWithAttributeType> fields_and_types =
       DetermineAttributeTypes(base::span_from_ref(field), field->section(),
-                              entity.type()),
-      *field, action_persistence, app_locale, address_normalizer);
+                              entity.type());
+
+  // For a name field fake that there are other fields that dynamically
+  // propagate to the name field.
+  if (GroupTypeOfFieldType(field->Type().GetStorableType()) ==
+          FieldTypeGroup::kName &&
+      base::FeatureList::IsEnabled(features::kAutofillAiNoTagTypes)) {
+    auto attribute_type = [&entity]() -> std::optional<AttributeType> {
+      switch (entity.type().name()) {
+        case EntityTypeName::kDriversLicense:
+          return AttributeType(AttributeTypeName::kDriversLicenseName);
+        case EntityTypeName::kPassport:
+          return AttributeType(AttributeTypeName::kPassportName);
+        case EntityTypeName::kVehicle:
+          return AttributeType(AttributeTypeName::kVehicleOwner);
+      }
+      return std::nullopt;
+    }();
+    if (attribute_type) {
+      fields_and_types.emplace_back(*field, *attribute_type);
+    }
+  }
+
+  return GetFillValueForEntity(entity, fields_and_types, *field,
+                               action_persistence, app_locale,
+                               address_normalizer);
 }
 
 class GetFieldsFillableByAutofillAiTest : public testing::Test {
  public:
   GetFieldsFillableByAutofillAiTest() {
+    scoped_feature_list_.InitWithFeatures(
+        /*enabled_features=*/{features::kAutofillAiWithDataSchema,
+                              features::kAutofillAiNoTagTypes},
+        /*disabled_features=*/{});
+
     client().set_entity_data_manager(std::make_unique<EntityDataManager>(
         helper_.autofill_webdata_service(), /*history_service=*/nullptr,
         /*strike_database=*/nullptr));
@@ -100,8 +128,7 @@
   FieldGlobalId field(size_t i) const { return form_.fields()[i]->global_id(); }
 
  private:
-  base::test::ScopedFeatureList scoped_feature_list_{
-      features::kAutofillAiWithDataSchema};
+  base::test::ScopedFeatureList scoped_feature_list_;
   base::test::TaskEnvironment task_environment_{
       base::test::TaskEnvironment::TimeSource::MOCK_TIME};
   test::AutofillUnitTestEnvironment autofill_environment_;
@@ -122,17 +149,17 @@
   // The name is absent in the entity.
   AddOrUpdateEntityInstance(test::GetPassportEntityInstance({.name = nullptr}));
   test_api(form()).SetFieldTypes({CREDIT_CARD_NAME_FULL, NAME_FULL},
-                                 {CREDIT_CARD_NAME_FULL, PASSPORT_NAME_TAG});
+                                 {CREDIT_CARD_NAME_FULL, NO_SERVER_DATA});
   EXPECT_THAT(GetFieldsFillableByAutofillAi(form(), client()), IsEmpty());
 }
 
 // If there is a fillable AI field, it is blocked.
 TEST_F(GetFieldsFillableByAutofillAiTest, FillableName) {
   AddOrUpdateEntityInstance(test::GetPassportEntityInstance());
-  test_api(form()).SetFieldTypes({CREDIT_CARD_NAME_FULL, NAME_FULL},
-                                 {CREDIT_CARD_NAME_FULL, PASSPORT_NAME_TAG});
+  test_api(form()).SetFieldTypes({NO_SERVER_DATA, NAME_FULL},
+                                 {PASSPORT_EXPIRATION_DATE, NO_SERVER_DATA});
   EXPECT_THAT(GetFieldsFillableByAutofillAi(form(), client()),
-              ElementsAre(field(1)));
+              ElementsAre(field(0), field(1)));
 }
 
 // If there is a fillable AI field, it is blocked.
@@ -151,22 +178,28 @@
   client().SetCanUseModelExecutionFeatures(false);
   AddOrUpdateEntityInstance(test::GetPassportEntityInstance());
   test_api(form()).SetFieldTypes({CREDIT_CARD_NAME_FULL, NAME_FULL},
-                                 {CREDIT_CARD_NAME_FULL, PASSPORT_NAME_TAG});
+                                 {CREDIT_CARD_NAME_FULL, NO_SERVER_DATA});
   EXPECT_THAT(GetFieldsFillableByAutofillAi(form(), client()), IsEmpty());
 }
 
 class GetFillValueForEntityTest : public testing::Test {
+ public:
+  GetFillValueForEntityTest() {
+    feature_list_.InitWithFeatures(
+        /*enabled_features=*/{features::kAutofillAiWithDataSchema,
+                              features::kAutofillAiNoTagTypes},
+        /*disabled_features=*/{});
+  }
+
  private:
-  base::test::ScopedFeatureList feature_list_{
-      features::kAutofillAiWithDataSchema};
+  base::test::ScopedFeatureList feature_list_;
   test::AutofillUnitTestEnvironment autofill_test_environment_;
 };
 
 TEST_F(GetFillValueForEntityTest, UnobfuscatedAttributes) {
   auto field = std::make_unique<AutofillField>();
   field->set_server_predictions(
-      {CreatePrediction(NAME_FIRST, FieldPrediction::SOURCE_AUTOFILL_DEFAULT),
-       CreatePrediction(PASSPORT_NAME_TAG)});
+      {CreatePrediction(NAME_FIRST, FieldPrediction::SOURCE_AUTOFILL_DEFAULT)});
   field->SetTypeTo(NAME_FIRST, AutofillPredictionSource::kServerCrowdsourcing);
 
   EntityInstance passport =
@@ -203,7 +236,6 @@
            {NAME_FIRST, u"Pippi"},
            {NAME_LAST, u"Långstrump"}}) {
     auto field = std::make_unique<AutofillField>();
-    field->set_server_predictions({CreatePrediction(PASSPORT_NAME_TAG)});
     field->SetTypeTo(type, AutofillPredictionSource::kServerCrowdsourcing);
 
     EXPECT_EQ(
diff --git a/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_import_utils_unittest.cc b/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_import_utils_unittest.cc
index 51c250e4..90be539b 100644
--- a/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_import_utils_unittest.cc
+++ b/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_import_utils_unittest.cc
@@ -108,9 +108,16 @@
 }
 
 class AutofillAiImportUtilsTest : public testing::Test {
+ public:
+  AutofillAiImportUtilsTest() {
+    feature_list_.InitWithFeatures(
+        /*enabled_features=*/{features::kAutofillAiWithDataSchema,
+                              features::kAutofillAiNoTagTypes},
+        /*disabled_features=*/{});
+  }
+
  private:
-  base::test::ScopedFeatureList feature_list_{
-      features::kAutofillAiWithDataSchema};
+  base::test::ScopedFeatureList feature_list_;
   test::AutofillUnitTestEnvironment autofill_environment_;
 };
 
@@ -121,8 +128,7 @@
   fields.push_back(CreateInput(FormControlType::kInputText,
                                FieldType::PASSPORT_NUMBER, "123"));
   fields.push_back(CreateInput(FormControlType::kInputText,
-                               FieldType::PASSPORT_NAME_TAG,
-                               "Karlsson on the Roof"));
+                               FieldType::NAME_FULL, "Karlsson on the Roof"));
   // Input fields for which the initial value is the same as the current value
   // are ignored during import.
   fields.push_back(CreateInput(FormControlType::kInputText,
diff --git a/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_manager_unittest.cc b/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_manager_unittest.cc
index 935e85e1..4e7340e 100644
--- a/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_manager_unittest.cc
+++ b/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_manager_unittest.cc
@@ -127,8 +127,10 @@
  public:
   AutofillAiManagerTest() {
     scoped_feature_list_.InitWithFeatures(
-        {features::kAutofillAiWithDataSchema, features::kAutofillAiServerModel},
-        {});
+        /*enabled_features=*/{features::kAutofillAiWithDataSchema,
+                              features::kAutofillAiNoTagTypes,
+                              features::kAutofillAiServerModel},
+        /*disabled_features=*/{});
     autofill_client().GetPersonalDataManager().SetPrefService(
         autofill_client().GetPrefs());
     autofill_client().set_entity_data_manager(
@@ -201,11 +203,10 @@
 TEST_F(AutofillAiManagerTest,
        GetSuggestionsTriggeringFieldIsAutofillAi_ReturnFillingSuggestion) {
   test::FormDescription form_description = {
-      .fields = {{.role = NAME_FIRST, .heuristic_type = NAME_FIRST}}};
+      .fields = {{.role = PASSPORT_NUMBER}}};
   FormData form = test::GetFormData(form_description);
   FormStructure form_structure = FormStructure(form);
-  AddPredictionsToFormStructure(form_structure,
-                                {{NAME_FIRST, PASSPORT_NAME_TAG}});
+  AddPredictionsToFormStructure(form_structure, {{PASSPORT_NUMBER}});
 
   AddOrUpdateEntityInstance(test::GetPassportEntityInstance());
   EXPECT_THAT(manager().GetSuggestions(form_structure, form.fields().front()),
@@ -302,8 +303,7 @@
       std::u16string passport_number = std::u16string(kDefaultPassportNumber),
       std::string url = std::string(kDefaultUrl)) {
     std::unique_ptr<FormStructure> form = CreateFormStructure(
-        {PASSPORT_NAME_TAG, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER},
-        std::move(url));
+        {NAME_FULL, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER}, std::move(url));
     form->field(0)->set_value(u"Jon Doe");
     form->field(1)->set_value(std::move(passport_number));
     return form;
@@ -312,8 +312,8 @@
   [[nodiscard]] std::unique_ptr<FormStructure> CreateVehicleForm(
       std::u16string license_plate = std::u16string(kDefaultLicensePlate),
       std::string url = std::string(kDefaultUrl)) {
-    std::unique_ptr<FormStructure> form = CreateFormStructure(
-        {VEHICLE_OWNER_TAG, VEHICLE_LICENSE_PLATE}, std::move(url));
+    std::unique_ptr<FormStructure> form =
+        CreateFormStructure({NAME_FULL, VEHICLE_LICENSE_PLATE}, std::move(url));
     form->field(0)->set_value(u"Jane Doe");
     form->field(1)->set_value(std::move(license_plate));
     return form;
@@ -642,7 +642,7 @@
 TEST_F(AutofillAiManagerImportFormTest,
        EntityContainsRequiredAttributes_ShowPromptAndAccept) {
   std::unique_ptr<FormStructure> form = CreateFormStructure(
-      {PASSPORT_NAME_TAG, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER});
+      {NAME_FULL, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER});
   form->field(0)->set_value(u"Jon Doe");
   form->field(1)->set_value(u"1234321");
 
@@ -678,7 +678,7 @@
 TEST_F(AutofillAiManagerImportFormTest,
        EntityContainsRequiredAttributes_ShowPromptAndDecline) {
   std::unique_ptr<FormStructure> form = CreateFormStructure(
-      {PASSPORT_NAME_TAG, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER});
+      {NAME_FULL, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER});
   // Set the filled values to be the same as the ones already stored.
   form->field(0)->set_value(u"Jon Doe");
   form->field(1)->set_value(u"1234321");
@@ -699,7 +699,7 @@
 TEST_F(AutofillAiManagerImportFormTest,
        EntityDoesNotContainRequiredAttributes_DoNotShowPrompt) {
   std::unique_ptr<FormStructure> form =
-      CreateFormStructure({PASSPORT_ISSUING_COUNTRY, PASSPORT_NAME_TAG});
+      CreateFormStructure({PASSPORT_ISSUING_COUNTRY, NAME_FULL});
   // Set the filled values to be the same as the ones already stored.
   form->field(0)->set_value(u"Germany");
   form->field(1)->set_value(u"1234321");
@@ -717,7 +717,7 @@
 TEST_F(AutofillAiManagerImportFormTest, EntityAlreadyStored_DoNotShowPrompt) {
   using enum AttributeTypeName;
   std::unique_ptr<FormStructure> form =
-      CreateFormStructure({DRIVERS_LICENSE_NAME_TAG, DRIVERS_LICENSE_NUMBER});
+      CreateFormStructure({NAME_FULL, DRIVERS_LICENSE_NUMBER});
   EntityInstance entity = test::GetDriversLicenseEntityInstance();
   // Set the filled values to be the same as the ones already stored.
   form->field(0)->set_value(
@@ -736,7 +736,7 @@
 
 TEST_F(AutofillAiManagerImportFormTest, NewEntity_ShowPromptAndAccept) {
   std::unique_ptr<FormStructure> form = CreateFormStructure(
-      {PASSPORT_NAME_TAG, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER});
+      {NAME_FULL, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER});
   EntityInstance existing_entity = test::GetPassportEntityInstance();
   AddOrUpdateEntityInstance(existing_entity);
   // Set the filled values to be different to the ones already stored.
@@ -780,9 +780,9 @@
   using enum AttributeTypeName;
   // The submitted form will have issue date info.
   std::unique_ptr<FormStructure> form =
-      CreateFormStructure({PASSPORT_NAME_TAG, PASSPORT_NUMBER,
-                           PASSPORT_ISSUE_DATE, PASSPORT_EXPIRATION_DATE,
-                           PASSPORT_EXPIRATION_DATE, PASSPORT_EXPIRATION_DATE});
+      CreateFormStructure({NAME_FULL, PASSPORT_NUMBER, PASSPORT_ISSUE_DATE,
+                           PASSPORT_EXPIRATION_DATE, PASSPORT_EXPIRATION_DATE,
+                           PASSPORT_EXPIRATION_DATE});
 
   // The current entity however does not.
   EntityInstance existing_entity_without_issue_and_expiry_dates =
diff --git a/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_suggestions_unittest.cc b/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_suggestions_unittest.cc
index b5311c7b..3fa374f 100644
--- a/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_suggestions_unittest.cc
+++ b/components/autofill/core/browser/integrators/autofill_ai/autofill_ai_suggestions_unittest.cc
@@ -17,11 +17,13 @@
 #include "components/autofill/core/browser/data_model/autofill_ai/entity_type.h"
 #include "components/autofill/core/browser/data_model/autofill_ai/entity_type_names.h"
 #include "components/autofill/core/browser/field_types.h"
+#include "components/autofill/core/browser/form_processing/autofill_ai/determine_attribute_types.h"
 #include "components/autofill/core/browser/form_structure.h"
 #include "components/autofill/core/browser/suggestions/suggestion_test_helpers.h"
 #include "components/autofill/core/browser/suggestions/suggestion_type.h"
 #include "components/autofill/core/browser/test_utils/autofill_form_test_utils.h"
 #include "components/autofill/core/browser/test_utils/autofill_test_utils.h"
+#include "components/autofill/core/common/autofill_features.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace autofill {
@@ -81,54 +83,54 @@
     entities_ = std::move(entities);
   }
 
-  // Sets the form to one whose `i`th field has types `multiple_field_types[i]`.
-  void SetForm(
-      const std::vector<std::vector<FieldType>>& multiple_field_types) {
+  // Sets the form to one whose `i`th field has type `field_types[i]`.
+  void SetForm(const std::vector<FieldType>& field_types) {
     test::FormDescription form_description;
-    for (std::vector<FieldType> field_types : multiple_field_types) {
-      FieldType type = field_types.empty() ? UNKNOWN_TYPE : field_types[0];
+    for (FieldType type : field_types) {
       form_description.fields.emplace_back(
           test::FieldDescription({.role = type}));
     }
     form_structure_.emplace(test::GetFormData(form_description));
-    CHECK_EQ(multiple_field_types.size(), form_structure_->field_count());
+    CHECK_EQ(field_types.size(), form_structure_->field_count());
     for (size_t i = 0; i < form_structure_->field_count(); i++) {
-      form_structure_->field(i)->set_server_predictions(
-          base::ToVector(multiple_field_types[i], [](FieldType type) {
-            FieldPrediction prediction;
-            prediction.set_type(type);
-            return prediction;
-          }));
+      form_structure_->field(i)->set_server_predictions({[&] {
+        FieldPrediction prediction;
+        prediction.set_type(field_types[i]);
+        return prediction;
+      }()});
     }
   }
 
-  // Sets the form to one whose `i`th field has type `field_types[i]`.
-  void SetForm(const std::vector<FieldType>& field_types) {
-    SetForm(base::ToVector(field_types, [](FieldType type) {
-      return std::vector<FieldType>({type});
-    }));
-  }
-
   AutofillField& field(size_t i) { return *form_structure_->fields()[i]; }
 
   std::optional<std::u16string> GetFillValueForField(
       const Suggestion::AutofillAiPayload& payload,
       const AutofillField& field) {
-    auto entity_it =
-        std::ranges::find(entities_, payload.guid, &EntityInstance::guid);
-    if (entity_it == entities_.end()) {
+    auto it = std::ranges::find(entities_, payload.guid, &EntityInstance::guid);
+    if (it == entities_.end()) {
       return std::nullopt;
     }
-    auto attribute_it = std::ranges::find_if(
-        entity_it->attributes(), [&field](const AttributeInstance& attribute) {
-          return attribute.type().field_type() ==
-                 field.GetAutofillAiServerTypePredictions();
-        });
-    if (attribute_it == entity_it->attributes().end()) {
+    const EntityInstance& entity = *it;
+
+    std::vector<AutofillFieldWithAttributeType> fields_and_types =
+        DetermineAttributeTypes(*form_structure_, field.section(),
+                                entity.type());
+    auto jt = std::ranges::find(fields_and_types, field.global_id(),
+                                [](const AutofillFieldWithAttributeType& f) {
+                                  return f.field->global_id();
+                                });
+    if (jt == fields_and_types.end()) {
       return std::nullopt;
     }
-    return attribute_it->GetInfo(field.Type().GetStorableType(), kAppLocaleUS,
-                                 field.format_string());
+    const AttributeType type = jt->type;
+
+    base::optional_ref<const AttributeInstance> attribute =
+        entity.attribute(type);
+    if (!attribute) {
+      return std::nullopt;
+    }
+    return attribute->GetInfo(field.Type().GetStorableType(), kAppLocaleUS,
+                              field.format_string());
   }
 
   std::vector<Suggestion> CreateFillingSuggestions(const AutofillField& field) {
@@ -137,6 +139,8 @@
   }
 
  private:
+  base::test::ScopedFeatureList scoped_feature_list_{
+      features::kAutofillAiNoTagTypes};
   test::AutofillUnitTestEnvironment autofill_test_environment_;
   std::vector<EntityInstance> entities_;
   std::optional<FormStructure> form_structure_;
@@ -163,12 +167,12 @@
 TEST_F(AutofillAiSuggestionsTest, GetFillingSuggestion_PassportEntity) {
   EntityInstance passport_entity = MakePassportWithRandomGuid();
   SetEntities({passport_entity});
-  SetForm({PASSPORT_NAME_TAG, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER});
+  SetForm({NAME_FULL, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER});
 
   std::vector<Suggestion> suggestions = CreateFillingSuggestions(field(0));
 
   // There should be only one suggestion whose main text matches the entity
-  // value for the PASSPORT_NAME_TAG.
+  // value for the passport name.
   EXPECT_THAT(suggestions,
               SuggestionsAre(HasMainText(GetPassportName(passport_entity))));
 
@@ -194,7 +198,7 @@
       MakePassportWithRandomGuid({.name = u"Harry Potter"});
 
   SetEntities({passport_prefix_matches, passport_prefix_does_not_match});
-  SetForm({PASSPORT_NAME_TAG, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER});
+  SetForm({NAME_FULL, PASSPORT_NUMBER, PHONE_HOME_WHOLE_NUMBER});
   field(0).set_value(u"J");
 
   // There should be only one suggestion whose main text matches is a prefix of
@@ -219,7 +223,7 @@
        GetFillingSuggestion_SkipFieldsThatDoNotMatchTheTriggeringFieldSection) {
   EntityInstance passport_entity = MakePassportWithRandomGuid();
   SetEntities({passport_entity});
-  SetForm({PASSPORT_NAME_TAG, PASSPORT_NUMBER});
+  SetForm({PASSPORT_NUMBER, PASSPORT_EXPIRATION_DATE});
 
   field(0).set_section(Section::FromAutocomplete(Section::Autocomplete("foo")));
   field(1).set_section(Section::FromAutocomplete(Section::Autocomplete("bar")));
@@ -227,14 +231,15 @@
 
   std::vector<Suggestion> suggestions = CreateFillingSuggestions(field(0));
   EXPECT_THAT(suggestions,
-              SuggestionsAre(HasMainText(GetPassportName(passport_entity))));
+              SuggestionsAre(HasMainText(GetPassportNumber(passport_entity))));
+  EXPECT_THAT(suggestions, SuggestionsAre(HasLabel(u"Passport")));
 
   const Suggestion::AutofillAiPayload* payload =
       std::get_if<Suggestion::AutofillAiPayload>(&suggestions[0].payload);
   ASSERT_TRUE(payload);
   // The triggering/first field is of Autofill AI type.
   EXPECT_EQ(GetFillValueForField(*payload, field(0)),
-            GetPassportName(passport_entity));
+            GetPassportNumber(passport_entity));
 }
 
 // Tests that there are no suggestions if the existing entities don't match the
@@ -243,7 +248,7 @@
   EntityInstance drivers_license_entity =
       test::GetDriversLicenseEntityInstance();
   SetEntities({drivers_license_entity});
-  SetForm({PASSPORT_NAME_TAG});
+  SetForm({NAME_FULL, PASSPORT_NUMBER});
   EXPECT_THAT(CreateFillingSuggestions(field(0)), IsEmpty());
 }
 
@@ -259,9 +264,7 @@
   ASSERT_EQ(name->GetInfo(NAME_FIRST, kAppLocaleUS, std::nullopt), u"");
   ASSERT_EQ(name->GetInfo(NAME_LAST, kAppLocaleUS, std::nullopt), u"Miller");
 
-  SetForm({{NAME_FIRST, PASSPORT_NAME_TAG},
-           {NAME_LAST, PASSPORT_NAME_TAG},
-           {PASSPORT_NUMBER}});
+  SetForm({NAME_FIRST, NAME_LAST, PASSPORT_NUMBER});
 
   EXPECT_THAT(CreateFillingSuggestions(field(0)), IsEmpty());
   EXPECT_THAT(CreateFillingSuggestions(field(1)), Not(IsEmpty()));
@@ -276,7 +279,7 @@
   EntityInstance passport4 =
       MakePassportWithRandomGuid({.expiry_date = nullptr});
   SetEntities({passport1, passport2, passport3, passport4});
-  SetForm({PASSPORT_NAME_TAG, PASSPORT_NUMBER, PASSPORT_ISSUING_COUNTRY});
+  SetForm({NAME_FULL, PASSPORT_NUMBER, PASSPORT_ISSUING_COUNTRY});
 
   // `passport3` is deduped because there is no expiry date in the form and its
   // remaining attributes are a subset of `passport1`.
@@ -301,7 +304,7 @@
 
 TEST_F(AutofillAiSuggestionsTest, LabelGeneration_SingleEntity_NoLabelAdded) {
   SetEntities({MakePassportWithRandomGuid()});
-  SetForm({PASSPORT_NUMBER, PASSPORT_NAME_TAG});
+  SetForm({PASSPORT_NUMBER, NAME_FULL});
   EXPECT_THAT(CreateFillingSuggestions(field(0)),
               SuggestionsAre(HasLabel(u"Passport")));
 }
@@ -329,7 +332,7 @@
   SetEntities({MakePassportWithRandomGuid(),
                MakePassportWithRandomGuid(
                    {.name = u"Machado de Assis", .number = u"123"})});
-  SetForm({PASSPORT_NUMBER, PASSPORT_NAME_TAG});
+  SetForm({PASSPORT_NUMBER, NAME_FULL});
   EXPECT_THAT(CreateFillingSuggestions(field(0)),
               SuggestionsAre(HasLabel(u"Passport · Pippi Långstrump"),
                              HasLabel(u"Passport · Machado de Assis")));
@@ -345,7 +348,7 @@
                    {.name = u"Machado de Assis", .country = u"Brazil"})});
 
   // Note that passport name is the first at the rank of disambiguating texts.
-  SetForm({PASSPORT_NAME_TAG, PASSPORT_ISSUING_COUNTRY});
+  SetForm({NAME_FULL, PASSPORT_ISSUING_COUNTRY});
   EXPECT_THAT(CreateFillingSuggestions(field(0)),
               SuggestionsAre(HasLabel(u"Passport"), HasLabel(u"Passport")));
 }
@@ -359,7 +362,7 @@
                MakePassportWithRandomGuid({.country = u"Brazil"})});
 
   // Note that passport name is the first at the rank of disambiguating texts.
-  SetForm({PASSPORT_NAME_TAG, PASSPORT_ISSUING_COUNTRY});
+  SetForm({NAME_FULL, PASSPORT_ISSUING_COUNTRY});
   EXPECT_THAT(CreateFillingSuggestions(field(0)),
               SuggestionsAre(HasLabel(u"Passport · Sweden"),
                              HasLabel(u"Passport · Brazil")));
@@ -392,7 +395,7 @@
   SetEntities({MakeVehicleWithRandomGuid(),
                MakeVehicleWithRandomGuid({.model = u"Series 3"}),
                MakeVehicleWithRandomGuid({.name = u"Diego Maradona"})});
-  SetForm({VEHICLE_LICENSE_PLATE, VEHICLE_MODEL, VEHICLE_OWNER_TAG});
+  SetForm({VEHICLE_LICENSE_PLATE, VEHICLE_MODEL, NAME_FULL});
   EXPECT_THAT(CreateFillingSuggestions(field(0)),
               SuggestionsAre(HasLabel(u"Vehicle · Series 2 · Knecht Ruprecht"),
                              HasLabel(u"Vehicle · Series 3 · Knecht Ruprecht"),
@@ -422,7 +425,7 @@
     LabelGeneration_TwoSuggestions_PassportsWithDifferentExpiryDates_DoNotAddDifferentiatingLabel) {
   SetEntities({MakePassportWithRandomGuid(),
                MakePassportWithRandomGuid({.expiry_date = u"2018-12-29"})});
-  SetForm({PASSPORT_NUMBER, PASSPORT_ISSUING_COUNTRY, PASSPORT_NAME_TAG,
+  SetForm({PASSPORT_NUMBER, PASSPORT_ISSUING_COUNTRY, NAME_FULL,
            PASSPORT_EXPIRATION_DATE});
   EXPECT_THAT(CreateFillingSuggestions(field(0)),
               SuggestionsAre(HasLabel(u"Passport"), HasLabel(u"Passport")));