-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
form_structure_test_api.h
85 lines (69 loc) · 3.13 KB
/
form_structure_test_api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2022 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_FORM_STRUCTURE_TEST_API_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_STRUCTURE_TEST_API_H_
#include <string>
#include "base/containers/contains.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_piece.h"
#include "components/autofill/core/browser/form_structure.h"
namespace autofill {
// Exposes some testing operations for FormStructure.
class FormStructureTestApi {
public:
static void ParseApiQueryResponse(
base::StringPiece payload,
const std::vector<FormStructure*>& forms,
const std::vector<FormSignature>& queried_form_signatures,
AutofillMetrics::FormInteractionsUkmLogger* ukm_logger,
LogManager* log_manager = nullptr) {
FormStructure::ParseApiQueryResponse(
payload, forms, queried_form_signatures, ukm_logger, log_manager);
}
static void ProcessQueryResponse(
const AutofillQueryResponse& response,
const std::vector<FormStructure*>& forms,
const std::vector<FormSignature>& queried_form_signatures,
AutofillMetrics::FormInteractionsUkmLogger* form_interactions_ukm_logger,
LogManager* log_manager = nullptr) {
FormStructure::ProcessQueryResponse(
response, forms, queried_form_signatures, form_interactions_ukm_logger,
log_manager);
}
explicit FormStructureTestApi(FormStructure* form_structure)
: form_structure_(form_structure) {
DCHECK(form_structure_);
}
// Set the heuristic and server types for each field. The `heuristic_types`
// and `server_types` vectors must be aligned with the indices of the fields
// in the form. For each field in `heuristic_types` there must be exactly one
// `GetActivePatternSource()` prediction and any number of alternative
// predictions.
void SetFieldTypes(
const std::vector<std::vector<std::pair<PatternSource, ServerFieldType>>>&
heuristic_types,
const std::vector<ServerFieldType>& server_types);
// Set the heuristic and server types for each field. The `heuristic_types`
// and `server_types` vectors must be aligned with the indices of the fields
// in the form.
void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types,
const std::vector<ServerFieldType>& server_types);
const std::vector<std::unique_ptr<AutofillField>>& fields() {
return form_structure_->fields_;
}
void IdentifySections(bool has_author_specified_sections) {
form_structure_->IdentifySections(has_author_specified_sections);
}
bool phone_rationalized(const Section& section) const {
return base::Contains(form_structure_->phone_rationalized_, section);
}
void ParseFieldTypesWithPatterns(PatternSource pattern_source) {
return form_structure_->ParseFieldTypesWithPatterns(pattern_source,
nullptr);
}
private:
raw_ptr<FormStructure> form_structure_;
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_STRUCTURE_TEST_API_H_