| OLD | NEW |
| 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 3035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3046 "Autofill.FillDuration.FromLoad.WithoutAutofill", 12, 1); | 3046 "Autofill.FillDuration.FromLoad.WithoutAutofill", 12, 1); |
| 3047 histogram_tester.ExpectTotalCount( | 3047 histogram_tester.ExpectTotalCount( |
| 3048 "Autofill.FillDuration.FromInteraction.WithAutofill", 0); | 3048 "Autofill.FillDuration.FromInteraction.WithAutofill", 0); |
| 3049 histogram_tester.ExpectTotalCount( | 3049 histogram_tester.ExpectTotalCount( |
| 3050 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); | 3050 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); |
| 3051 | 3051 |
| 3052 autofill_manager_->Reset(); | 3052 autofill_manager_->Reset(); |
| 3053 } | 3053 } |
| 3054 } | 3054 } |
| 3055 | 3055 |
| 3056 // Verify that we correctly log metrics for profile creation on form submission. | 3056 // Verify that we correctly log metrics for profile action on form submission. |
| 3057 TEST_F(AutofillMetricsTest, AutomaticProfileCreation) { | 3057 TEST_F(AutofillMetricsTest, ProfileActionOnFormSubmitted) { |
| 3058 base::HistogramTester histogram_tester; | 3058 base::HistogramTester histogram_tester; |
| 3059 | 3059 |
| 3060 // Load a fillable form. | 3060 // Load a fillable form. |
| 3061 FormData form; | 3061 FormData form; |
| 3062 form.name = ASCIIToUTF16("TestForm"); | 3062 form.name = ASCIIToUTF16("TestForm"); |
| 3063 form.origin = GURL("http://example.com/form.html"); | 3063 form.origin = GURL("http://example.com/form.html"); |
| 3064 form.action = GURL("http://example.com/submit.html"); | 3064 form.action = GURL("http://example.com/submit.html"); |
| 3065 | 3065 |
| 3066 // Create the form's fields. | 3066 // Create the form's fields. |
| 3067 FormFieldData field; | 3067 FormFieldData field; |
| 3068 test::CreateTestFormField("Name", "name", "", "text", &field); | 3068 test::CreateTestFormField("Name", "name", "", "text", &field); |
| 3069 form.fields.push_back(field); | 3069 form.fields.push_back(field); |
| 3070 test::CreateTestFormField("Email", "email", "", "text", &field); | 3070 test::CreateTestFormField("Email", "email", "", "text", &field); |
| 3071 form.fields.push_back(field); | 3071 form.fields.push_back(field); |
| 3072 test::CreateTestFormField("Phone", "phone", "", "text", &field); | 3072 test::CreateTestFormField("Phone", "phone", "", "text", &field); |
| 3073 form.fields.push_back(field); | 3073 form.fields.push_back(field); |
| 3074 test::CreateTestFormField("Address", "address", "", "text", &field); | 3074 test::CreateTestFormField("Address", "address", "", "text", &field); |
| 3075 form.fields.push_back(field); | 3075 form.fields.push_back(field); |
| 3076 test::CreateTestFormField("City", "city", "", "text", &field); | 3076 test::CreateTestFormField("City", "city", "", "text", &field); |
| 3077 form.fields.push_back(field); | 3077 form.fields.push_back(field); |
| 3078 test::CreateTestFormField("Country", "country", "", "text", &field); | 3078 test::CreateTestFormField("Country", "country", "", "text", &field); |
| 3079 form.fields.push_back(field); | 3079 form.fields.push_back(field); |
| 3080 test::CreateTestFormField("State", "state", "", "text", &field); | 3080 test::CreateTestFormField("State", "state", "", "text", &field); |
| 3081 form.fields.push_back(field); | 3081 form.fields.push_back(field); |
| 3082 test::CreateTestFormField("Zip", "zip", "", "text", &field); | 3082 test::CreateTestFormField("Zip", "zip", "", "text", &field); |
| 3083 form.fields.push_back(field); | 3083 form.fields.push_back(field); |
| 3084 test::CreateTestFormField("Organization", "organization", "", "text", &field); |
| 3085 form.fields.push_back(field); |
| 3084 | 3086 |
| 3085 std::vector<FormData> forms(1, form); | 3087 std::vector<FormData> forms(1, form); |
| 3086 | 3088 |
| 3087 // Fill second form. | 3089 // Fill second form. |
| 3088 FormData second_form = form; | 3090 FormData second_form = form; |
| 3089 std::vector<FormData> second_forms(1, second_form); | 3091 std::vector<FormData> second_forms(1, second_form); |
| 3090 | 3092 |
| 3091 // Fill a third form. | 3093 // Fill a third form. |
| 3092 FormData third_form = form; | 3094 FormData third_form = form; |
| 3093 std::vector<FormData> third_forms(1, third_form); | 3095 std::vector<FormData> third_forms(1, third_form); |
| 3094 | 3096 |
| 3097 // Fill a fourth form. |
| 3098 FormData fourth_form = form; |
| 3099 std::vector<FormData> fourth_forms(1, fourth_form); |
| 3100 |
| 3095 // Fill the field values for the first form submission. | 3101 // Fill the field values for the first form submission. |
| 3096 form.fields[0].value = ASCIIToUTF16("Albert Canuck"); | 3102 form.fields[0].value = ASCIIToUTF16("Albert Canuck"); |
| 3097 form.fields[1].value = ASCIIToUTF16("can@gmail.com"); | 3103 form.fields[1].value = ASCIIToUTF16("can@gmail.com"); |
| 3098 form.fields[2].value = ASCIIToUTF16("12345678901"); | 3104 form.fields[2].value = ASCIIToUTF16("12345678901"); |
| 3099 form.fields[3].value = ASCIIToUTF16("1234 McGill street."); | 3105 form.fields[3].value = ASCIIToUTF16("1234 McGill street."); |
| 3100 form.fields[4].value = ASCIIToUTF16("Montreal"); | 3106 form.fields[4].value = ASCIIToUTF16("Montreal"); |
| 3101 form.fields[5].value = ASCIIToUTF16("Canada"); | 3107 form.fields[5].value = ASCIIToUTF16("Canada"); |
| 3102 form.fields[6].value = ASCIIToUTF16("Quebec"); | 3108 form.fields[6].value = ASCIIToUTF16("Quebec"); |
| 3103 form.fields[7].value = ASCIIToUTF16("A1A 1A1"); | 3109 form.fields[7].value = ASCIIToUTF16("A1A 1A1"); |
| 3104 | 3110 |
| 3105 // Fill the field values for the second form submission (same as first form). | 3111 // Fill the field values for the second form submission (same as first form). |
| 3106 second_form.fields = form.fields; | 3112 second_form.fields = form.fields; |
| 3107 | 3113 |
| 3108 // Fill the field values for the third form submission. | 3114 // Fill the field values for the third form submission. |
| 3109 third_form.fields[0].value = ASCIIToUTF16("Jean-Paul Canuck"); | 3115 third_form.fields[0].value = ASCIIToUTF16("Jean-Paul Canuck"); |
| 3110 third_form.fields[1].value = ASCIIToUTF16("can2@gmail.com"); | 3116 third_form.fields[1].value = ASCIIToUTF16("can2@gmail.com"); |
| 3111 third_form.fields[2].value = ASCIIToUTF16("12345678901"); | 3117 third_form.fields[2].value = ASCIIToUTF16(""); |
| 3112 third_form.fields[3].value = ASCIIToUTF16("1234 McGill street."); | 3118 third_form.fields[3].value = ASCIIToUTF16("1234 McGill street."); |
| 3113 third_form.fields[4].value = ASCIIToUTF16("Montreal"); | 3119 third_form.fields[4].value = ASCIIToUTF16("Montreal"); |
| 3114 third_form.fields[5].value = ASCIIToUTF16("Canada"); | 3120 third_form.fields[5].value = ASCIIToUTF16("Canada"); |
| 3115 third_form.fields[6].value = ASCIIToUTF16("Quebec"); | 3121 third_form.fields[6].value = ASCIIToUTF16("Quebec"); |
| 3116 third_form.fields[7].value = ASCIIToUTF16("A1A 1A1"); | 3122 third_form.fields[7].value = ASCIIToUTF16("A1A 1A1"); |
| 3117 | 3123 |
| 3118 // Expect to log true for the metric since a new profile is submitted. | 3124 // Fill the field values for the fourth form submission (same as third form |
| 3125 // plus phone info). |
| 3126 fourth_form.fields = third_form.fields; |
| 3127 fourth_form.fields[2].value = ASCIIToUTF16("12345678901"); |
| 3128 |
| 3129 // Expect to log NEW_PROFILE_CREATED for the metric since a new profile is |
| 3130 // submitted. |
| 3119 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); | 3131 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); |
| 3120 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17)); | 3132 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17)); |
| 3121 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", | 3133 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3122 true, 1); | 3134 AutofillMetrics::NEW_PROFILE_CREATED, 1); |
| 3123 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", | 3135 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3124 false, 0); | 3136 AutofillMetrics::EXISTING_PROFILE_USED, 0); |
| 3137 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3138 AutofillMetrics::EXISTING_PROFILE_UPDATED, |
| 3139 0); |
| 3125 | 3140 |
| 3126 // Expect to log false for the metric since the same profile is submitted. | 3141 // Expect to log EXISTING_PROFILE_USED for the metric since the same profile |
| 3142 // is submitted. |
| 3127 autofill_manager_->OnFormsSeen(second_forms, TimeTicks::FromInternalValue(1)); | 3143 autofill_manager_->OnFormsSeen(second_forms, TimeTicks::FromInternalValue(1)); |
| 3128 autofill_manager_->SubmitForm(second_form, TimeTicks::FromInternalValue(17)); | 3144 autofill_manager_->SubmitForm(second_form, TimeTicks::FromInternalValue(17)); |
| 3129 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", | 3145 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3130 true, 1); | 3146 AutofillMetrics::NEW_PROFILE_CREATED, 1); |
| 3131 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", | 3147 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3132 false, 1); | 3148 AutofillMetrics::EXISTING_PROFILE_USED, 1); |
| 3149 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3150 AutofillMetrics::EXISTING_PROFILE_UPDATED, |
| 3151 0); |
| 3133 | 3152 |
| 3134 // Expect to log true for the metric since a new profile is submitted. | 3153 // Expect to log NEW_PROFILE_CREATED for the metric since a new profile is |
| 3154 // submitted. |
| 3135 autofill_manager_->OnFormsSeen(third_forms, TimeTicks::FromInternalValue(1)); | 3155 autofill_manager_->OnFormsSeen(third_forms, TimeTicks::FromInternalValue(1)); |
| 3136 autofill_manager_->SubmitForm(third_form, TimeTicks::FromInternalValue(17)); | 3156 autofill_manager_->SubmitForm(third_form, TimeTicks::FromInternalValue(17)); |
| 3137 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", | 3157 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3138 true, 2); | 3158 AutofillMetrics::NEW_PROFILE_CREATED, 2); |
| 3139 histogram_tester.ExpectBucketCount("Autofill.AutomaticProfileCreation", | 3159 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3140 false, 1); | 3160 AutofillMetrics::EXISTING_PROFILE_USED, 1); |
| 3161 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3162 AutofillMetrics::EXISTING_PROFILE_UPDATED, |
| 3163 0); |
| 3164 |
| 3165 // Expect to log EXISTING_PROFILE_UPDATED for the metric since the profile was |
| 3166 // updated. |
| 3167 autofill_manager_->OnFormsSeen(fourth_forms, TimeTicks::FromInternalValue(1)); |
| 3168 autofill_manager_->SubmitForm(fourth_form, TimeTicks::FromInternalValue(17)); |
| 3169 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3170 AutofillMetrics::NEW_PROFILE_CREATED, 2); |
| 3171 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3172 AutofillMetrics::EXISTING_PROFILE_USED, 1); |
| 3173 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3174 AutofillMetrics::EXISTING_PROFILE_UPDATED, |
| 3175 1); |
| 3141 } | 3176 } |
| 3142 | 3177 |
| 3143 // Test class that shares setup code for testing ParseQueryResponse. | 3178 // Test class that shares setup code for testing ParseQueryResponse. |
| 3144 class AutofillMetricsParseQueryResponseTest : public testing::Test { | 3179 class AutofillMetricsParseQueryResponseTest : public testing::Test { |
| 3145 public: | 3180 public: |
| 3146 void SetUp() override { | 3181 void SetUp() override { |
| 3147 FormData form; | 3182 FormData form; |
| 3148 form.origin = GURL("http://foo.com"); | 3183 form.origin = GURL("http://foo.com"); |
| 3149 FormFieldData field; | 3184 FormFieldData field; |
| 3150 field.form_control_type = "text"; | 3185 field.form_control_type = "text"; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3273 EXPECT_THAT( | 3308 EXPECT_THAT( |
| 3274 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 3309 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
| 3275 ElementsAre(Bucket(true, 2))); | 3310 ElementsAre(Bucket(true, 2))); |
| 3276 | 3311 |
| 3277 // No RAPPOR metrics are logged in the case there is at least some server data | 3312 // No RAPPOR metrics are logged in the case there is at least some server data |
| 3278 // available for all forms. | 3313 // available for all forms. |
| 3279 EXPECT_EQ(0, rappor_service_.GetReportsCount()); | 3314 EXPECT_EQ(0, rappor_service_.GetReportsCount()); |
| 3280 } | 3315 } |
| 3281 | 3316 |
| 3282 } // namespace autofill | 3317 } // namespace autofill |
| OLD | NEW |