chromium/components/autofill/core/browser/autofill_form_test_utils.h

// Copyright 2020 The Chromium Authors
// 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_AUTOFILL_FORM_TEST_UTILS_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_FORM_TEST_UTILS_H_

#include <optional>
#include <vector>

#include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/common/autocomplete_parsing_util.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_field_data.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace autofill {
namespace test {

namespace {

// Default form url.
constexpr char kFormUrl[] =;

// Default form action url.
constexpr char kFormActionUrl[] =;

}  // namespace

namespace internal {

// Expected FormFieldData and type predictions are constructed based on these
// descriptions.
template <typename = void>
struct FieldDescription {};

// Attributes provided to the test form.
template <typename = void>
struct FormDescription {};

// Flags determining whether the corresponding check should be run on the test
// form.
template <typename = void>
struct TestFormFlags {};

// Expected field type values to be verified with the test form.
template <typename = void>
struct ExpectedFieldTypeValues {};

// Describes a test case for the parser.
template <typename = void>
struct FormStructureTestCase {};

}  // namespace internal

FieldDescription;
FormDescription;
FormStructureTestCase;

// Describes the |form_data|. Use this in SCOPED_TRACE if other logging
// messages might refer to the form.
testing::Message DescribeFormData(const FormData& form_data);

// Returns the form field relevant to the |role|.
FormFieldData CreateFieldByRole(FieldType role);

// Creates a FormFieldData to be fed to the parser.
FormFieldData GetFormFieldData(const FieldDescription& fd);

// Creates a FormData to be fed to the parser.
FormData GetFormData(const FormDescription& test_form_attributes);

// Creates a FormData with `field_types`.
FormData GetFormData(const std::vector<FieldType>& field_types);

// Extracts the heuristic types from the form description. If the heuristic type
// is not explicitly set for a given field it is extracted from the field's
// role.
std::vector<FieldType> GetHeuristicTypes(
    const FormDescription& form_description);

// Extracts the server types from the form description. If the server type
// is not explicitly set for field it is extracted from the fiel's role.
std::vector<FieldType> GetServerTypes(const FormDescription& form_description);

class FormStructureTest : public testing::Test {};

}  // namespace test
}  // namespace autofill

#endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_FORM_TEST_UTILS_H_