Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4543)

Unified Diff: chrome/browser/autofill/autofill_metrics_unittest.cc

Issue 7740070: Add metrics to measure time elapsed between form load and form submission with or without Autofill. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/autofill_metrics_unittest.cc
diff --git a/chrome/browser/autofill/autofill_metrics_unittest.cc b/chrome/browser/autofill/autofill_metrics_unittest.cc
index 76a953d18ad80d5e5ce4af8a007ac0d9fd00c8a2..f93148a0d5f5d3b9c27ac56859b46e117a27529d 100644
--- a/chrome/browser/autofill/autofill_metrics_unittest.cc
+++ b/chrome/browser/autofill/autofill_metrics_unittest.cc
@@ -7,6 +7,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
+#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
#include "chrome/browser/autofill/autofill_common_test.h"
@@ -22,6 +23,9 @@
#include "webkit/glue/form_data.h"
#include "webkit/glue/form_field.h"
+using ::testing::_;
+using ::testing::AnyNumber;
+using ::testing::Mock;
using webkit_glue::FormData;
using webkit_glue::FormField;
@@ -47,6 +51,10 @@ class MockAutofillMetrics : public AutofillMetrics {
const std::string& experiment_id));
MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric));
MOCK_CONST_METHOD1(LogUserHappinessMetric, void(UserHappinessMetric metric));
+ MOCK_CONST_METHOD1(LogAutofilledFormSubmittedAfterDuration,
+ void(const base::TimeDelta& duration));
+ MOCK_CONST_METHOD1(LogNonAutofilledFormSubmittedAfterDuration,
+ void(const base::TimeDelta& duration));
MOCK_CONST_METHOD1(LogIsAutofillEnabledAtPageLoad, void(bool enabled));
MOCK_CONST_METHOD1(LogIsAutofillEnabledAtStartup, void(bool enabled));
MOCK_CONST_METHOD1(LogStoredProfileCount, void(size_t num_profiles));
@@ -169,9 +177,9 @@ class TestAutofillManager : public AutofillManager {
autofill_enabled_ = autofill_enabled;
}
- const MockAutofillMetrics* metric_logger() const {
- return static_cast<const MockAutofillMetrics*>(
- AutofillManager::metric_logger());
+ MockAutofillMetrics* metric_logger() {
+ return static_cast<MockAutofillMetrics*>(const_cast<AutofillMetrics*>(
+ AutofillManager::metric_logger()));
}
void AddSeenForm(const FormData& form,
@@ -395,7 +403,7 @@ TEST_F(AutofillMetricsTest, QualityMetrics) {
AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME));
// Simulate form submission.
- EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
+ EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 0));
jar (doing other things) 2011/08/31 17:02:21 I don't think you should be passing in a zero. Th
Ilya Sherman 2011/08/31 21:56:23 Done.
}
// Test that we log the appropriate additional metrics when Autofill failed.
@@ -512,7 +520,7 @@ TEST_F(AutofillMetricsTest, QualityMetricsForFailure) {
}
// Simulate form submission.
- EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
+ EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 0));
}
// Test that we behave sanely when the cached form differs from the submitted
@@ -669,7 +677,7 @@ TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) {
std::string()));
// Simulate form submission.
- EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
+ EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 0));
}
// Test that we don't log quality metrics for non-autofillable forms.
@@ -695,7 +703,7 @@ TEST_F(AutofillMetricsTest, NoQualityMetricsForNonAutofillableForms) {
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
std::string())).Times(0);
- EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
+ EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 0));
// Search forms are not auto-fillable.
form.action = GURL("http://example.com/search?q=Elvis%20Presley");
@@ -707,7 +715,7 @@ TEST_F(AutofillMetricsTest, NoQualityMetricsForNonAutofillableForms) {
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
std::string())).Times(0);
- EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
+ EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 0));
}
// Test that we recored the experiment id appropriately.
@@ -832,7 +840,7 @@ TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) {
ADDRESS_HOME_COUNTRY, experiment_id));
// Simulate form submission.
- EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
+ EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form, 0));
}
// Test that the profile count is logged correctly.
@@ -1076,7 +1084,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
*autofill_manager_->metric_logger(),
LogUserHappinessMetric(
AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)).Times(0);
- autofill_manager_->OnFormSubmitted(form);
+ autofill_manager_->OnFormSubmitted(form, 0);
}
// Add more fields to the form.
@@ -1098,7 +1106,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogUserHappinessMetric(
AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
- autofill_manager_->OnFormSubmitted(form);
+ autofill_manager_->OnFormSubmitted(form, 0);
}
// Fill in two of the fields.
@@ -1111,7 +1119,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogUserHappinessMetric(
AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
- autofill_manager_->OnFormSubmitted(form);
+ autofill_manager_->OnFormSubmitted(form, 0);
}
// Fill in the third field.
@@ -1123,7 +1131,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogUserHappinessMetric(
AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE));
- autofill_manager_->OnFormSubmitted(form);
+ autofill_manager_->OnFormSubmitted(form, 0);
}
@@ -1136,7 +1144,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogUserHappinessMetric(
AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME));
- autofill_manager_->OnFormSubmitted(form);
+ autofill_manager_->OnFormSubmitted(form, 0);
}
// Mark all of the fillable fields as autofilled.
@@ -1149,7 +1157,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogUserHappinessMetric(
AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL));
- autofill_manager_->OnFormSubmitted(form);
+ autofill_manager_->OnFormSubmitted(form, 0);
}
// Clear out the third field's value.
@@ -1161,7 +1169,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogUserHappinessMetric(
AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
- autofill_manager_->OnFormSubmitted(form);
+ autofill_manager_->OnFormSubmitted(form, 0);
}
}
@@ -1197,7 +1205,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
{
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE));
- autofill_manager_->OnTextFieldDidChange(form, form.fields.front());
+ autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 0);
}
// Simulate suggestions shown twice for a single edit (i.e. multiple
@@ -1230,7 +1238,7 @@ TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogUserHappinessMetric(
AutofillMetrics::USER_DID_AUTOFILL_ONCE));
- autofill_manager_->OnDidFillAutofillFormData();
+ autofill_manager_->OnDidFillAutofillFormData(0);
}
// Simulate editing an autofilled field.
@@ -1246,9 +1254,9 @@ TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
autofill_manager_->OnFillAutofillFormData(
0, form, form.fields.front(),
autofill_manager_->PackGUIDs(empty, guid));
- autofill_manager_->OnTextFieldDidChange(form, form.fields.front());
+ autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 0);
// Simulate a second keystroke; make sure we don't log the metric twice.
- autofill_manager_->OnTextFieldDidChange(form, form.fields.front());
+ autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 0);
}
// Simulate invoking autofill again.
@@ -1257,13 +1265,120 @@ TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogUserHappinessMetric(
AutofillMetrics::USER_DID_AUTOFILL_ONCE)).Times(0);
- autofill_manager_->OnDidFillAutofillFormData();
+ autofill_manager_->OnDidFillAutofillFormData(0);
// Simulate editing another autofilled field.
{
EXPECT_CALL(*autofill_manager_->metric_logger(),
LogUserHappinessMetric(
AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD));
- autofill_manager_->OnTextFieldDidChange(form, form.fields[1]);
+ autofill_manager_->OnTextFieldDidChange(form, form.fields[1], 0);
}
}
+
+// Verify that we correctly log metrics tracking the duration of form fill.
+TEST_F(AutofillMetricsTest, FormFillDuration) {
+ // Load a fillable form.
+ FormData form;
+ form.name = ASCIIToUTF16("TestForm");
+ form.method = ASCIIToUTF16("POST");
+ form.origin = GURL("http://example.com/form.html");
+ form.action = GURL("http://example.com/submit.html");
+ form.user_submitted = true;
+
+ FormField field;
+ autofill_test::CreateTestFormField("Name", "name", "", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField("Email", "email", "", "text", &field);
+ form.fields.push_back(field);
+ autofill_test::CreateTestFormField("Phone", "phone", "", "text", &field);
+ form.fields.push_back(field);
+
+ std::vector<FormData> forms(1, form);
+
+ // Fill the field values for form submission.
+ form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
+ form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
+ form.fields[2].value = ASCIIToUTF16("12345678901");
+
+ // Ignore any non-timing metrics.
+ // CAUTION: This is a global variable. So as to not affect other tests, this
+ // _must_ be restored to "warning" at the end of the test.
+ ::testing::FLAGS_gmock_verbose = "error";
+
+ // Expect no metric to be logged if the form is submitted without user
+ // interaction.
+ {
+ EXPECT_CALL(*autofill_manager_->metric_logger(),
+ LogAutofilledFormSubmittedAfterDuration(_)).Times(0);
+ EXPECT_CALL(*autofill_manager_->metric_logger(),
+ LogNonAutofilledFormSubmittedAfterDuration(_)).Times(0);
+ autofill_manager_->OnFormsSeen(forms);
+ autofill_manager_->OnFormSubmitted(form, 17);
+ autofill_manager_->Reset();
+ Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
+ }
+
+ // Expect metric to be logged if the user manually edited a form field.
+ {
+ EXPECT_CALL(*autofill_manager_->metric_logger(),
+ LogAutofilledFormSubmittedAfterDuration(_)).Times(0);
+ EXPECT_CALL(*autofill_manager_->metric_logger(),
+ LogNonAutofilledFormSubmittedAfterDuration(
+ base::TimeDelta::FromInternalValue(14)));
+ autofill_manager_->OnFormsSeen(forms);
+ autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 3);
+ autofill_manager_->OnFormSubmitted(form, 17);
+ autofill_manager_->Reset();
+ Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
+ }
+
+ // Expect metric to be logged if the user autofilled the form.
+ form.fields[0].is_autofilled = true;
+ {
+ EXPECT_CALL(*autofill_manager_->metric_logger(),
+ LogAutofilledFormSubmittedAfterDuration(
+ base::TimeDelta::FromInternalValue(12)));
+ EXPECT_CALL(*autofill_manager_->metric_logger(),
+ LogNonAutofilledFormSubmittedAfterDuration(_)).Times(0);
+ autofill_manager_->OnFormsSeen(forms);
+ autofill_manager_->OnDidFillAutofillFormData(5);
+ autofill_manager_->OnFormSubmitted(form, 17);
+ autofill_manager_->Reset();
+ Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
+ }
+
+ // Expect metric to be logged if the user both manually filled some fields
+ // and autofilled others. Messages can arrive out of order, so make sure they
+ // take precedence appropriately.
+ {
+ EXPECT_CALL(*autofill_manager_->metric_logger(),
+ LogAutofilledFormSubmittedAfterDuration(
+ base::TimeDelta::FromInternalValue(14)));
+ EXPECT_CALL(*autofill_manager_->metric_logger(),
+ LogNonAutofilledFormSubmittedAfterDuration(_)).Times(0);
+ autofill_manager_->OnFormsSeen(forms);
+ autofill_manager_->OnDidFillAutofillFormData(5);
+ autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 3);
+ autofill_manager_->OnFormSubmitted(form, 17);
+ autofill_manager_->Reset();
+ Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
+ }
+
+ // Expect no metric to be logged if the form submission time appears to be
+ // prior to the first form interaction.
+ {
+ EXPECT_CALL(*autofill_manager_->metric_logger(),
+ LogAutofilledFormSubmittedAfterDuration(_)).Times(0);
+ EXPECT_CALL(*autofill_manager_->metric_logger(),
+ LogNonAutofilledFormSubmittedAfterDuration(_)).Times(0);
+ autofill_manager_->OnFormsSeen(forms);
+ autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 23);
+ autofill_manager_->OnFormSubmitted(form, 17);
+ autofill_manager_->Reset();
+ Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
+ }
+
+ // Restore the global Gmock verbosity level to its default value.
+ ::testing::FLAGS_gmock_verbose = "warning";
+}

Powered by Google App Engine
This is Rietveld 408576698