Commit 133fdd79 authored by sebsg's avatar sebsg Committed by Commit Bot

[AF] Add metrics for the DynamicForm feature.

Bug: 845615
Change-Id: Ia8da247d2c7bc5a836b1ad1c3912c686be2c0190
Reviewed-on: https://chromium-review.googlesource.com/1069532Reviewed-by: default avatarRoger McFarlane <rogerm@chromium.org>
Commit-Queue: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561471}
parent 0e4ef275
......@@ -2062,21 +2062,33 @@ bool AutofillManager::ShouldTriggerRefill(const FormStructure& form_structure) {
if (!base::FeatureList::IsEnabled(features::kAutofillDynamicForms))
return false;
address_form_event_logger_->OnDidSeeDynamicForm();
// Should not refill if a form with the same name has not been filled before.
auto itr =
filling_contexts_map_.find(form_structure.GetIdentifierForRefill());
if (itr == filling_contexts_map_.end())
return false;
address_form_event_logger_->OnDidSeeFillableDynamicForm();
FillingContext* filling_context = itr->second.get();
base::TimeTicks now = base::TimeTicks::Now();
base::TimeDelta delta = now - filling_context->original_fill_time;
if (filling_context->attempted_refill &&
delta.InMilliseconds() < kLimitBeforeRefillMs) {
address_form_event_logger_->OnSubsequentRefillAttempt();
}
return !filling_context->attempted_refill &&
delta.InMilliseconds() < kLimitBeforeRefillMs;
}
void AutofillManager::TriggerRefill(const FormData& form,
FormStructure* form_structure) {
address_form_event_logger_->OnDidRefill();
auto itr =
filling_contexts_map_.find(form_structure->GetIdentifierForRefill());
DCHECK(itr != filling_contexts_map_.end());
......
......@@ -667,6 +667,7 @@ class AutofillManager : public AutofillHandler,
QualityMetrics_LoggedCorrecltyForRationalizationBad);
FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, SaneMetricsWithCacheMismatch);
FRIEND_TEST_ALL_PREFIXES(AutofillMetricsTest, DynamicFormMetrics);
FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest, TestExternalDelegate);
FRIEND_TEST_ALL_PREFIXES(AutofillManagerTest,
TestTabContentsWithExternalDelegate);
......
......@@ -1579,6 +1579,22 @@ void AutofillMetrics::FormEventLogger::SetBankNameAvailable() {
has_logged_bank_name_available_ = true;
}
void AutofillMetrics::FormEventLogger::OnDidSeeDynamicForm() {
Log(AutofillMetrics::FORM_EVENT_DID_SEE_DYNAMIC_FORM);
}
void AutofillMetrics::FormEventLogger::OnDidSeeFillableDynamicForm() {
Log(AutofillMetrics::FORM_EVENT_DID_SEE_FILLABLE_DYNAMIC_FORM);
}
void AutofillMetrics::FormEventLogger::OnDidRefill() {
Log(AutofillMetrics::FORM_EVENT_DID_DYNAMIC_REFILL);
}
void AutofillMetrics::FormEventLogger::OnSubsequentRefillAttempt() {
Log(AutofillMetrics::FORM_EVENT_DYNAMIC_CHANGE_AFTER_REFILL);
}
void AutofillMetrics::FormEventLogger::Log(FormEvent event) const {
DCHECK_LT(event, NUM_FORM_EVENTS);
std::string name("Autofill.FormEvents.");
......
......@@ -496,6 +496,16 @@ class AutofillMetrics {
FORM_EVENT_SUBMIT_WITHOUT_SELECTING_SUGGESTIONS_WRONG_SIZE_CARD,
FORM_EVENT_SUBMIT_WITHOUT_SELECTING_SUGGESTIONS_FAIL_LUHN_CHECK_CARD,
// The form was changed dynamically.
FORM_EVENT_DID_SEE_DYNAMIC_FORM,
// The form was changed dynamically and was fillable.
FORM_EVENT_DID_SEE_FILLABLE_DYNAMIC_FORM,
// There was a dynamic change of the form and it got re-filled
// automatically.
FORM_EVENT_DID_DYNAMIC_REFILL,
// The form dynamically changed another time after the refill.
FORM_EVENT_DYNAMIC_CHANGE_AFTER_REFILL,
NUM_FORM_EVENTS,
};
......@@ -1038,6 +1048,14 @@ class AutofillMetrics {
void SetBankNameAvailable();
void OnDidSeeDynamicForm();
void OnDidSeeFillableDynamicForm();
void OnDidRefill();
void OnSubsequentRefillAttempt();
private:
void Log(FormEvent event) const;
void Log(BankNameDisplayedFormEvent event) const;
......
......@@ -7076,4 +7076,101 @@ TEST_F(AutofillMetricsTest, AutofillSuggestionShownTest) {
Collapse(CalculateFormSignature(form))}}});
}
TEST_F(AutofillMetricsTest, DynamicFormMetrics) {
scoped_feature_list_.InitWithFeatures(
{features::kAutofillDynamicForms},
{features::kAutofillRequireSecureCreditCardContext,
features::kAutofillRestrictUnownedFieldsToFormlessCheckout});
// Set up our form data.
FormData form;
form.name = ASCIIToUTF16("TestForm");
form.origin = GURL("http://example.com/form.html");
form.action = GURL("http://example.com/submit.html");
FormFieldData field;
std::vector<ServerFieldType> field_types;
test::CreateTestFormField("State", "state", "", "text", &field);
form.fields.push_back(field);
field_types.push_back(ADDRESS_HOME_STATE);
test::CreateTestFormField("City", "city", "", "text", &field);
form.fields.push_back(field);
field_types.push_back(ADDRESS_HOME_CITY);
test::CreateTestFormField("Street", "street", "", "text", &field);
form.fields.push_back(field);
field_types.push_back(ADDRESS_HOME_STREET_ADDRESS);
// Simulate seeing.
base::HistogramTester histogram_tester;
autofill_manager_->AddSeenForm(form, field_types, field_types);
std::string guid("00000000-0000-0000-0000-000000000001");
// Simulate checking whether to fill a dynamic form before the form was filled
// initially.
FormStructure form_structure(form);
autofill_manager_->ShouldTriggerRefill(form_structure);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_SEE_DYNAMIC_FORM, 1);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_SEE_FILLABLE_DYNAMIC_FORM, 0);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_DYNAMIC_REFILL, 0);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DYNAMIC_CHANGE_AFTER_REFILL, 0);
// Simulate filling the form.
autofill_manager_->FillOrPreviewForm(
AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
autofill_manager_->MakeFrontendID(std::string(), guid));
// Simulate checking whether to fill a dynamic form after the form was filled
// initially.
autofill_manager_->ShouldTriggerRefill(form_structure);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_SEE_DYNAMIC_FORM, 2);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_SEE_FILLABLE_DYNAMIC_FORM, 1);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_DYNAMIC_REFILL, 0);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DYNAMIC_CHANGE_AFTER_REFILL, 0);
// Trigger a refill, the refill metric should be updated.
autofill_manager_->TriggerRefill(form, &form_structure);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_SEE_DYNAMIC_FORM, 2);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_SEE_FILLABLE_DYNAMIC_FORM, 1);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_DYNAMIC_REFILL, 1);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DYNAMIC_CHANGE_AFTER_REFILL, 0);
// Trigger a check to see whether a refill should happen. The
autofill_manager_->ShouldTriggerRefill(form_structure);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_SEE_DYNAMIC_FORM, 3);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_SEE_FILLABLE_DYNAMIC_FORM, 2);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DID_DYNAMIC_REFILL, 1);
histogram_tester.ExpectBucketCount(
"Autofill.FormEvents.Address",
AutofillMetrics::FORM_EVENT_DYNAMIC_CHANGE_AFTER_REFILL, 1);
}
} // namespace autofill
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment