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
|
// Copyright 2023 The Chromium Authors
// 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/heuristic_source.h"
#include "base/strings/to_string.h"
#include "base/test/scoped_feature_list.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/dense_set.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
// Depending on `kAutofillModelPredictions`, the active heuristic source will
// differ.
//
// Currently, the available heuristic sources are the ML model and regexes.
// If the model predictions are disabled, then only regexes are used. If model
// predictions are enabled, `kAutofillMachineLearning` is also considered.
// Depending on `kAutofillModelPredictionsAreActive`, use
// `kAutofillMachineLearning` as the active heuristic source.
struct HeuristicSourceParams {
std::optional<bool> model_predictions_feature;
const HeuristicSource expected_active_source;
};
class HeuristicSourceTest
: public testing::TestWithParam<HeuristicSourceParams> {
public:
HeuristicSourceTest() {
const HeuristicSourceParams& test_case = GetParam();
std::vector<base::test::FeatureRefAndParams> enabled_features;
std::vector<base::test::FeatureRef> disabled_features;
if (test_case.model_predictions_feature.has_value()) {
std::string model_prediction_active =
base::ToString(test_case.model_predictions_feature.value());
enabled_features.push_back(
{features::kAutofillModelPredictions,
{{features::kAutofillModelPredictionsAreActive.name,
model_prediction_active}}});
} else {
disabled_features.push_back(features::kAutofillModelPredictions);
}
features_.InitWithFeaturesAndParameters(enabled_features,
disabled_features);
}
private:
base::test::ScopedFeatureList features_;
};
// TODO(crbug.com/373902907): Flaky on ios and android bots.
#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)
#define MAYBE_HeuristicSourceParams DISABLED_HeuristicSourceParams
#else
#define MAYBE_HeuristicSourceParams HeuristicSourceParams
#endif
TEST_P(HeuristicSourceTest, MAYBE_HeuristicSourceParams) {
const HeuristicSourceParams& test_case = GetParam();
EXPECT_EQ(GetActiveHeuristicSource(), test_case.expected_active_source);
}
INSTANTIATE_TEST_SUITE_P(
HeuristicSourceTest,
HeuristicSourceTest,
testing::Values(
HeuristicSourceParams{
.expected_active_source = HeuristicSource::kRegexes},
HeuristicSourceParams{.model_predictions_feature = true,
.expected_active_source =
HeuristicSource::kAutofillMachineLearning},
HeuristicSourceParams{
.model_predictions_feature = false,
.expected_active_source = HeuristicSource::kRegexes}));
} // namespace autofill
|