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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
// 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 "base/test/metrics/histogram_tester.h"
#include "components/android_autofill/browser/android_form_event_logger.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
class AndroidFormEventLoggerTest : public testing::Test {
public:
~AndroidFormEventLoggerTest() override = default;
};
class AndroidFormEventLoggerFunnelTest : public testing::TestWithParam<int> {
public:
~AndroidFormEventLoggerFunnelTest() override = default;
};
INSTANTIATE_TEST_SUITE_P(AndroidFormEventLoggerTest,
AndroidFormEventLoggerFunnelTest,
testing::Values(0, 1, 2, 3, 4));
TEST_P(AndroidFormEventLoggerFunnelTest, LogFunnelAndKeyMetrics) {
// Phase 1: Simulate events according to GetParam().
const bool parsed_form = GetParam() >= 1;
const bool user_interacted_with_form = GetParam() >= 2;
const bool user_accepted_suggestion = GetParam() >= 3;
const bool user_submitted_form = GetParam() >= 4;
base::HistogramTester histogram_tester;
{
AndroidFormEventLogger logger("FormType");
if (parsed_form) {
logger.OnDidParseForm();
}
if (user_interacted_with_form) {
logger.OnDidInteractWithAutofillableForm();
}
if (user_accepted_suggestion) {
logger.OnDidFillSuggestion();
}
if (user_submitted_form) {
logger.OnWillSubmitForm();
}
// `logger` records metrics in destructor.
}
// Phase 2: Check which metrics where recorded.
EXPECT_THAT(histogram_tester.GetAllSamples(
"Autofill.WebView.Funnel.ParsedAsType.FormType"),
BucketsAre(base::Bucket(parsed_form, 1)));
if (parsed_form) {
EXPECT_THAT(
histogram_tester.GetAllSamples(
"Autofill.WebView.Funnel.InteractionAfterParsedAsType.FormType"),
BucketsAre(base::Bucket(user_interacted_with_form, 1)));
} else {
histogram_tester.ExpectTotalCount(
"Autofill.WebView.Funnel.InteractionAfterParsedAsType.FormType", 0u);
}
if (user_interacted_with_form) {
EXPECT_THAT(histogram_tester.GetAllSamples(
"Autofill.WebView.Funnel.FillAfterInteraction.FormType"),
BucketsAre(base::Bucket(user_accepted_suggestion, 1)));
} else {
histogram_tester.ExpectTotalCount(
"Autofill.Funnel.FillAfterInteraction.FormType", 0u);
}
if (user_submitted_form) {
// `user_submitted_form` == true && `user_accepted_suggestion` == false
// is tested in a different test.
EXPECT_THAT(histogram_tester.GetAllSamples(
"Autofill.WebView.KeyMetrics.FillingAssistance.FormType"),
BucketsAre(base::Bucket(user_accepted_suggestion, 1)));
// A different test tests the user editing an autofilled field.
EXPECT_THAT(histogram_tester.GetAllSamples(
"Autofill.WebView.KeyMetrics.FillingCorrectness.FormType"),
BucketsAre(base::Bucket(true, 1)));
EXPECT_THAT(
histogram_tester.GetAllSamples(
"Autofill.WebView.KeyMetrics.FormSubmission.Autofilled.FormType"),
BucketsAre(base::Bucket(true, 1)));
} else {
histogram_tester.ExpectTotalCount(
"Autofill.WebView.KeyMetrics.FillingAssistance.FormType", 0u);
histogram_tester.ExpectTotalCount(
"Autofill.WebView.KeyMetrics.FillingCorrectness.FormType", 0u);
if (user_accepted_suggestion) {
EXPECT_THAT(
histogram_tester.GetAllSamples(
"Autofill.WebView.KeyMetrics.FormSubmission.Autofilled.FormType"),
BucketsAre(base::Bucket(false, 1)));
} else {
histogram_tester.ExpectTotalCount(
"Autofill.WebView.KeyMetrics.FormSubmission.Autofilled.FormType", 0u);
}
}
}
// Test that Autofill.WebView.KeyMetrics.FillingCorrectness is correctly
// recorded in the scenario that the user edits an autofilled field.
TEST_F(AndroidFormEventLoggerTest, FillingCorrectnessEditedAutofilledField) {
base::HistogramTester histogram_tester;
{
AndroidFormEventLogger logger("FormType");
logger.OnDidParseForm();
logger.OnDidInteractWithAutofillableForm();
logger.OnDidFillSuggestion();
logger.OnEditedAutofilledField();
logger.OnWillSubmitForm();
// `logger` records metrics in destructor.
}
EXPECT_THAT(histogram_tester.GetAllSamples(
"Autofill.WebView.KeyMetrics.FillingCorrectness.FormType"),
BucketsAre(base::Bucket(false, 1)));
}
// Test that Autofill.WebView.FillingAssistance metric is correctly recorded in
// the scenario that the user interacts with the form and submits it but does
// not use autofill.
TEST_F(AndroidFormEventLoggerTest,
FillingAssistanceFormSubmissionInteractedNoAutofill) {
base::HistogramTester histogram_tester;
{
AndroidFormEventLogger logger("FormType");
logger.OnDidParseForm();
logger.OnDidInteractWithAutofillableForm();
logger.OnWillSubmitForm();
// `logger` records metrics in destructor.
}
EXPECT_THAT(histogram_tester.GetAllSamples(
"Autofill.WebView.KeyMetrics.FillingAssistance.FormType"),
BucketsAre(base::Bucket(false, 1)));
}
// Test that Autofill.WebView.KeyMetrics.FormSubmission metric is correctly
// recorded in the scenario that the user manually fills the form (without the
// help of autofill) and submits it.
TEST_F(AndroidFormEventLoggerTest, FormSubmissionManualFill) {
base::HistogramTester histogram_tester;
{
AndroidFormEventLogger logger("FormType");
logger.OnDidParseForm();
logger.OnDidInteractWithAutofillableForm();
logger.OnTypedIntoNonFilledField();
logger.OnWillSubmitForm();
// `logger` records metrics in destructor.
}
EXPECT_THAT(
histogram_tester.GetAllSamples(
"Autofill.WebView.KeyMetrics.FormSubmission.NotAutofilled.FormType"),
BucketsAre(base::Bucket(true, 1)));
}
// Test that Autofill.WebView.KeyMetrics.FormSubmission metric is correctly
// recorded in the scenario that the user manually fills the form and navigates
// away from the page without submitting the form.
TEST_F(AndroidFormEventLoggerTest, FilledFormNavigatedAway) {
base::HistogramTester histogram_tester;
{
AndroidFormEventLogger logger("FormType");
logger.OnDidParseForm();
logger.OnDidInteractWithAutofillableForm();
logger.OnTypedIntoNonFilledField();
// `logger` records metrics in destructor.
}
EXPECT_THAT(
histogram_tester.GetAllSamples(
"Autofill.WebView.KeyMetrics.FormSubmission.NotAutofilled.FormType"),
BucketsAre(base::Bucket(false, 1)));
}
} // namespace autofill
|