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

Side by Side Diff: components/autofill/core/browser/autofill_metrics_unittest.cc

Issue 1392623002: [Autofill] Add metric for profile action on form submitted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_metrics.h" 5 #include "components/autofill/core/browser/autofill_metrics.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 3055 matching lines...) Expand 10 before | Expand all | Expand 10 after
3066 "Autofill.FillDuration.FromLoad.WithoutAutofill", 12, 1); 3066 "Autofill.FillDuration.FromLoad.WithoutAutofill", 12, 1);
3067 histogram_tester.ExpectTotalCount( 3067 histogram_tester.ExpectTotalCount(
3068 "Autofill.FillDuration.FromInteraction.WithAutofill", 0); 3068 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
3069 histogram_tester.ExpectTotalCount( 3069 histogram_tester.ExpectTotalCount(
3070 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); 3070 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
3071 3071
3072 autofill_manager_->Reset(); 3072 autofill_manager_->Reset();
3073 } 3073 }
3074 } 3074 }
3075 3075
3076 // Verify that we correctly log metrics for profile creation on form submission. 3076 // Verify that we correctly log metrics for profile action on form submission.
3077 TEST_F(AutofillMetricsTest, AutomaticProfileCreation) { 3077 TEST_F(AutofillMetricsTest, ProfileActionOnFormSubmitted) {
3078 base::HistogramTester histogram_tester; 3078 base::HistogramTester histogram_tester;
3079 3079
3080 // Load a fillable form. 3080 // Load a fillable form.
3081 FormData form; 3081 FormData form;
3082 form.name = ASCIIToUTF16("TestForm"); 3082 form.name = ASCIIToUTF16("TestForm");
3083 form.origin = GURL("http://example.com/form.html"); 3083 form.origin = GURL("http://example.com/form.html");
3084 form.action = GURL("http://example.com/submit.html"); 3084 form.action = GURL("http://example.com/submit.html");
3085 3085
3086 // Create the form's fields. 3086 // Create the form's fields.
3087 FormFieldData field; 3087 FormFieldData field;
3088 test::CreateTestFormField("Name", "name", "", "text", &field); 3088 test::CreateTestFormField("Name", "name", "", "text", &field);
3089 form.fields.push_back(field); 3089 form.fields.push_back(field);
3090 test::CreateTestFormField("Email", "email", "", "text", &field); 3090 test::CreateTestFormField("Email", "email", "", "text", &field);
3091 form.fields.push_back(field); 3091 form.fields.push_back(field);
3092 test::CreateTestFormField("Phone", "phone", "", "text", &field); 3092 test::CreateTestFormField("Phone", "phone", "", "text", &field);
3093 form.fields.push_back(field); 3093 form.fields.push_back(field);
3094 test::CreateTestFormField("Address", "address", "", "text", &field); 3094 test::CreateTestFormField("Address", "address", "", "text", &field);
3095 form.fields.push_back(field); 3095 form.fields.push_back(field);
3096 test::CreateTestFormField("City", "city", "", "text", &field); 3096 test::CreateTestFormField("City", "city", "", "text", &field);
3097 form.fields.push_back(field); 3097 form.fields.push_back(field);
3098 test::CreateTestFormField("Country", "country", "", "text", &field); 3098 test::CreateTestFormField("Country", "country", "", "text", &field);
3099 form.fields.push_back(field); 3099 form.fields.push_back(field);
3100 test::CreateTestFormField("State", "state", "", "text", &field); 3100 test::CreateTestFormField("State", "state", "", "text", &field);
3101 form.fields.push_back(field); 3101 form.fields.push_back(field);
3102 test::CreateTestFormField("Zip", "zip", "", "text", &field); 3102 test::CreateTestFormField("Zip", "zip", "", "text", &field);
3103 form.fields.push_back(field); 3103 form.fields.push_back(field);
3104 test::CreateTestFormField("Organization", "organization", "", "text", &field);
3105 form.fields.push_back(field);
3104 3106
3105 std::vector<FormData> forms(1, form); 3107 std::vector<FormData> forms(1, form);
3106 3108
3107 // Fill second form. 3109 // Fill second form.
3108 FormData second_form = form; 3110 FormData second_form = form;
3109 std::vector<FormData> second_forms(1, second_form); 3111 std::vector<FormData> second_forms(1, second_form);
3110 3112
3111 // Fill a third form. 3113 // Fill a third form.
3112 FormData third_form = form; 3114 FormData third_form = form;
3113 std::vector<FormData> third_forms(1, third_form); 3115 std::vector<FormData> third_forms(1, third_form);
3114 3116
3117 // Fill a fourth form.
3118 FormData fourth_form = form;
3119 std::vector<FormData> fourth_forms(1, fourth_form);
3120
3115 // Fill the field values for the first form submission. 3121 // Fill the field values for the first form submission.
3116 form.fields[0].value = ASCIIToUTF16("Albert Canuck"); 3122 form.fields[0].value = ASCIIToUTF16("Albert Canuck");
3117 form.fields[1].value = ASCIIToUTF16("can@gmail.com"); 3123 form.fields[1].value = ASCIIToUTF16("can@gmail.com");
3118 form.fields[2].value = ASCIIToUTF16("12345678901"); 3124 form.fields[2].value = ASCIIToUTF16("12345678901");
3119 form.fields[3].value = ASCIIToUTF16("1234 McGill street."); 3125 form.fields[3].value = ASCIIToUTF16("1234 McGill street.");
3120 form.fields[4].value = ASCIIToUTF16("Montreal"); 3126 form.fields[4].value = ASCIIToUTF16("Montreal");
3121 form.fields[5].value = ASCIIToUTF16("Canada"); 3127 form.fields[5].value = ASCIIToUTF16("Canada");
3122 form.fields[6].value = ASCIIToUTF16("Quebec"); 3128 form.fields[6].value = ASCIIToUTF16("Quebec");
3123 form.fields[7].value = ASCIIToUTF16("A1A 1A1"); 3129 form.fields[7].value = ASCIIToUTF16("A1A 1A1");
3124 3130
3125 // Fill the field values for the second form submission (same as first form). 3131 // Fill the field values for the second form submission (same as first form).
3126 second_form.fields = form.fields; 3132 second_form.fields = form.fields;
3127 3133
3128 // Fill the field values for the third form submission. 3134 // Fill the field values for the third form submission.
3129 third_form.fields[0].value = ASCIIToUTF16("Jean-Paul Canuck"); 3135 third_form.fields[0].value = ASCIIToUTF16("Jean-Paul Canuck");
3130 third_form.fields[1].value = ASCIIToUTF16("can2@gmail.com"); 3136 third_form.fields[1].value = ASCIIToUTF16("can2@gmail.com");
3131 third_form.fields[2].value = ASCIIToUTF16("12345678901"); 3137 third_form.fields[2].value = ASCIIToUTF16("");
3132 third_form.fields[3].value = ASCIIToUTF16("1234 McGill street."); 3138 third_form.fields[3].value = ASCIIToUTF16("1234 McGill street.");
3133 third_form.fields[4].value = ASCIIToUTF16("Montreal"); 3139 third_form.fields[4].value = ASCIIToUTF16("Montreal");
3134 third_form.fields[5].value = ASCIIToUTF16("Canada"); 3140 third_form.fields[5].value = ASCIIToUTF16("Canada");
3135 third_form.fields[6].value = ASCIIToUTF16("Quebec"); 3141 third_form.fields[6].value = ASCIIToUTF16("Quebec");
3136 third_form.fields[7].value = ASCIIToUTF16("A1A 1A1"); 3142 third_form.fields[7].value = ASCIIToUTF16("A1A 1A1");
3137 3143
3138 // Expect to log true for the metric since a new profile is submitted. 3144 // Fill the field values for the fourth form submission (same as third form
3145 // plus phone info).
3146 fourth_form.fields = third_form.fields;
3147 fourth_form.fields[2].value = ASCIIToUTF16("12345678901");
3148
3149 // Expect to log NEW_PROFILE_CREATED for the metric since a new profile is
3150 // submitted.
3139 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 3151 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
3140 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17)); 3152 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17));
3141 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", 3153 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3142 true, 1); 3154 AutofillMetrics::NEW_PROFILE_CREATED, 1);
3143 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", 3155 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3144 false, 0); 3156 AutofillMetrics::EXISTING_PROFILE_USED, 0);
3157 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3158 AutofillMetrics::EXISTING_PROFILE_UPDATED,
3159 0);
3145 3160
3146 // Expect to log false for the metric since the same profile is submitted. 3161 // Expect to log EXISTING_PROFILE_USED for the metric since the same profile
3162 // is submitted.
3147 autofill_manager_->OnFormsSeen(second_forms, TimeTicks::FromInternalValue(1)); 3163 autofill_manager_->OnFormsSeen(second_forms, TimeTicks::FromInternalValue(1));
3148 autofill_manager_->SubmitForm(second_form, TimeTicks::FromInternalValue(17)); 3164 autofill_manager_->SubmitForm(second_form, TimeTicks::FromInternalValue(17));
3149 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", 3165 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3150 true, 1); 3166 AutofillMetrics::NEW_PROFILE_CREATED, 1);
3151 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", 3167 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3152 false, 1); 3168 AutofillMetrics::EXISTING_PROFILE_USED, 1);
3169 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3170 AutofillMetrics::EXISTING_PROFILE_UPDATED,
3171 0);
3153 3172
3154 // Expect to log true for the metric since a new profile is submitted. 3173 // Expect to log NEW_PROFILE_CREATED for the metric since a new profile is
3174 // submitted.
3155 autofill_manager_->OnFormsSeen(third_forms, TimeTicks::FromInternalValue(1)); 3175 autofill_manager_->OnFormsSeen(third_forms, TimeTicks::FromInternalValue(1));
3156 autofill_manager_->SubmitForm(third_form, TimeTicks::FromInternalValue(17)); 3176 autofill_manager_->SubmitForm(third_form, TimeTicks::FromInternalValue(17));
3157 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", 3177 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3158 true, 2); 3178 AutofillMetrics::NEW_PROFILE_CREATED, 2);
3159 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", 3179 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3160 false, 1); 3180 AutofillMetrics::EXISTING_PROFILE_USED, 1);
3181 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3182 AutofillMetrics::EXISTING_PROFILE_UPDATED,
3183 0);
3184
3185 // Expect to log EXISTING_PROFILE_UPDATED for the metric since the profile was
3186 // updated.
3187 autofill_manager_->OnFormsSeen(fourth_forms, TimeTicks::FromInternalValue(1));
3188 autofill_manager_->SubmitForm(fourth_form, TimeTicks::FromInternalValue(17));
3189 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3190 AutofillMetrics::NEW_PROFILE_CREATED, 2);
3191 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3192 AutofillMetrics::EXISTING_PROFILE_USED, 1);
3193 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted",
3194 AutofillMetrics::EXISTING_PROFILE_UPDATED,
3195 1);
3161 } 3196 }
3162 3197
3163 // Test class that shares setup code for testing ParseQueryResponse. 3198 // Test class that shares setup code for testing ParseQueryResponse.
3164 class AutofillMetricsParseQueryResponseTest : public testing::Test { 3199 class AutofillMetricsParseQueryResponseTest : public testing::Test {
3165 public: 3200 public:
3166 void SetUp() override { 3201 void SetUp() override {
3167 FormData form; 3202 FormData form;
3168 form.origin = GURL("http://foo.com"); 3203 form.origin = GURL("http://foo.com");
3169 FormFieldData field; 3204 FormFieldData field;
3170 field.form_control_type = "text"; 3205 field.form_control_type = "text";
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
3293 EXPECT_THAT( 3328 EXPECT_THAT(
3294 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), 3329 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"),
3295 ElementsAre(Bucket(true, 2))); 3330 ElementsAre(Bucket(true, 2)));
3296 3331
3297 // No RAPPOR metrics are logged in the case there is at least some server data 3332 // No RAPPOR metrics are logged in the case there is at least some server data
3298 // available for all forms. 3333 // available for all forms.
3299 EXPECT_EQ(0, rappor_service_.GetReportsCount()); 3334 EXPECT_EQ(0, rappor_service_.GetReportsCount());
3300 } 3335 }
3301 3336
3302 } // namespace autofill 3337 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.cc ('k') | components/autofill/core/browser/autofill_profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698