| 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 run_loop_->Run(); | 261 run_loop_->Run(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 // Calls both AutofillManager::OnWillSubmitForm and | 264 // Calls both AutofillManager::OnWillSubmitForm and |
| 265 // AutofillManager::OnFormSubmitted. | 265 // AutofillManager::OnFormSubmitted. |
| 266 void SubmitForm(const FormData& form, const TimeTicks& timestamp) { | 266 void SubmitForm(const FormData& form, const TimeTicks& timestamp) { |
| 267 WillSubmitForm(form, timestamp); | 267 WillSubmitForm(form, timestamp); |
| 268 OnFormSubmitted(form); | 268 OnFormSubmitted(form); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void UploadFormDataAsyncCallback( | 271 void UploadFormDataAsyncCallback(const FormStructure* submitted_form, |
| 272 const FormStructure* submitted_form, | 272 const base::TimeTicks& load_time, |
| 273 const base::TimeTicks& load_time, | 273 const base::TimeTicks& interaction_time, |
| 274 const base::TimeTicks& interaction_time, | 274 const base::TimeTicks& submission_time, |
| 275 const base::TimeTicks& submission_time) override { | 275 bool observed_submission) override { |
| 276 run_loop_->Quit(); | 276 run_loop_->Quit(); |
| 277 | 277 |
| 278 AutofillManager::UploadFormDataAsyncCallback(submitted_form, | 278 AutofillManager::UploadFormDataAsyncCallback( |
| 279 load_time, | 279 submitted_form, load_time, interaction_time, submission_time, |
| 280 interaction_time, | 280 observed_submission); |
| 281 submission_time); | |
| 282 } | 281 } |
| 283 | 282 |
| 284 private: | 283 private: |
| 285 bool autofill_enabled_; | 284 bool autofill_enabled_; |
| 286 scoped_ptr<base::RunLoop> run_loop_; | 285 scoped_ptr<base::RunLoop> run_loop_; |
| 287 | 286 |
| 288 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 287 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
| 289 }; | 288 }; |
| 290 | 289 |
| 291 } // namespace | 290 } // namespace |
| (...skipping 2555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2847 { | 2846 { |
| 2848 base::HistogramTester histogram_tester; | 2847 base::HistogramTester histogram_tester; |
| 2849 autofill_manager_->DidShowSuggestions(true, form, form.fields[1]); | 2848 autofill_manager_->DidShowSuggestions(true, form, form.fields[1]); |
| 2850 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness", | 2849 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness", |
| 2851 AutofillMetrics::SUGGESTIONS_SHOWN, 1); | 2850 AutofillMetrics::SUGGESTIONS_SHOWN, 1); |
| 2852 } | 2851 } |
| 2853 | 2852 |
| 2854 // Simulate invoking autofill. | 2853 // Simulate invoking autofill. |
| 2855 { | 2854 { |
| 2856 base::HistogramTester histogram_tester; | 2855 base::HistogramTester histogram_tester; |
| 2857 autofill_manager_->OnDidFillAutofillFormData(TimeTicks()); | 2856 autofill_manager_->OnDidFillAutofillFormData(form, TimeTicks()); |
| 2858 histogram_tester.ExpectBucketCount("Autofill.UserHappiness", | 2857 histogram_tester.ExpectBucketCount("Autofill.UserHappiness", |
| 2859 AutofillMetrics::USER_DID_AUTOFILL, 1); | 2858 AutofillMetrics::USER_DID_AUTOFILL, 1); |
| 2860 histogram_tester.ExpectBucketCount( | 2859 histogram_tester.ExpectBucketCount( |
| 2861 "Autofill.UserHappiness", AutofillMetrics::USER_DID_AUTOFILL_ONCE, 1); | 2860 "Autofill.UserHappiness", AutofillMetrics::USER_DID_AUTOFILL_ONCE, 1); |
| 2862 } | 2861 } |
| 2863 | 2862 |
| 2864 // Simulate editing an autofilled field. | 2863 // Simulate editing an autofilled field. |
| 2865 { | 2864 { |
| 2866 base::HistogramTester histogram_tester; | 2865 base::HistogramTester histogram_tester; |
| 2867 std::string guid("00000000-0000-0000-0000-000000000001"); | 2866 std::string guid("00000000-0000-0000-0000-000000000001"); |
| 2868 autofill_manager_->FillOrPreviewForm( | 2867 autofill_manager_->FillOrPreviewForm( |
| 2869 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), | 2868 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), |
| 2870 autofill_manager_->MakeFrontendID(std::string(), guid)); | 2869 autofill_manager_->MakeFrontendID(std::string(), guid)); |
| 2871 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 2870 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 2872 TimeTicks()); | 2871 TimeTicks()); |
| 2873 // Simulate a second keystroke; make sure we don't log the metric twice. | 2872 // Simulate a second keystroke; make sure we don't log the metric twice. |
| 2874 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 2873 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 2875 TimeTicks()); | 2874 TimeTicks()); |
| 2876 histogram_tester.ExpectBucketCount( | 2875 histogram_tester.ExpectBucketCount( |
| 2877 "Autofill.UserHappiness", | 2876 "Autofill.UserHappiness", |
| 2878 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1); | 2877 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1); |
| 2879 histogram_tester.ExpectBucketCount( | 2878 histogram_tester.ExpectBucketCount( |
| 2880 "Autofill.UserHappiness", | 2879 "Autofill.UserHappiness", |
| 2881 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE, 1); | 2880 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE, 1); |
| 2882 } | 2881 } |
| 2883 | 2882 |
| 2884 // Simulate invoking autofill again. | 2883 // Simulate invoking autofill again. |
| 2885 { | 2884 { |
| 2886 base::HistogramTester histogram_tester; | 2885 base::HistogramTester histogram_tester; |
| 2887 autofill_manager_->OnDidFillAutofillFormData(TimeTicks()); | 2886 autofill_manager_->OnDidFillAutofillFormData(form, TimeTicks()); |
| 2888 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness", | 2887 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness", |
| 2889 AutofillMetrics::USER_DID_AUTOFILL, 1); | 2888 AutofillMetrics::USER_DID_AUTOFILL, 1); |
| 2890 } | 2889 } |
| 2891 | 2890 |
| 2892 // Simulate editing another autofilled field. | 2891 // Simulate editing another autofilled field. |
| 2893 { | 2892 { |
| 2894 base::HistogramTester histogram_tester; | 2893 base::HistogramTester histogram_tester; |
| 2895 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); | 2894 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); |
| 2896 histogram_tester.ExpectUniqueSample( | 2895 histogram_tester.ExpectUniqueSample( |
| 2897 "Autofill.UserHappiness", | 2896 "Autofill.UserHappiness", |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2973 | 2972 |
| 2974 autofill_manager_->Reset(); | 2973 autofill_manager_->Reset(); |
| 2975 } | 2974 } |
| 2976 | 2975 |
| 2977 // Expect metric to be logged if the user autofilled the form. | 2976 // Expect metric to be logged if the user autofilled the form. |
| 2978 form.fields[0].is_autofilled = true; | 2977 form.fields[0].is_autofilled = true; |
| 2979 { | 2978 { |
| 2980 base::HistogramTester histogram_tester; | 2979 base::HistogramTester histogram_tester; |
| 2981 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); | 2980 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); |
| 2982 autofill_manager_->OnDidFillAutofillFormData( | 2981 autofill_manager_->OnDidFillAutofillFormData( |
| 2983 TimeTicks::FromInternalValue(5)); | 2982 form, TimeTicks::FromInternalValue(5)); |
| 2984 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17)); | 2983 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17)); |
| 2985 | 2984 |
| 2986 histogram_tester.ExpectUniqueSample( | 2985 histogram_tester.ExpectUniqueSample( |
| 2987 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1); | 2986 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1); |
| 2988 histogram_tester.ExpectTotalCount( | 2987 histogram_tester.ExpectTotalCount( |
| 2989 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0); | 2988 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0); |
| 2990 histogram_tester.ExpectUniqueSample( | 2989 histogram_tester.ExpectUniqueSample( |
| 2991 "Autofill.FillDuration.FromInteraction.WithAutofill", 12, 1); | 2990 "Autofill.FillDuration.FromInteraction.WithAutofill", 12, 1); |
| 2992 histogram_tester.ExpectTotalCount( | 2991 histogram_tester.ExpectTotalCount( |
| 2993 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); | 2992 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); |
| 2994 | 2993 |
| 2995 autofill_manager_->Reset(); | 2994 autofill_manager_->Reset(); |
| 2996 } | 2995 } |
| 2997 | 2996 |
| 2998 // Expect metric to be logged if the user both manually filled some fields | 2997 // Expect metric to be logged if the user both manually filled some fields |
| 2999 // and autofilled others. Messages can arrive out of order, so make sure they | 2998 // and autofilled others. Messages can arrive out of order, so make sure they |
| 3000 // take precedence appropriately. | 2999 // take precedence appropriately. |
| 3001 { | 3000 { |
| 3002 base::HistogramTester histogram_tester; | 3001 base::HistogramTester histogram_tester; |
| 3003 | 3002 |
| 3004 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); | 3003 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); |
| 3005 autofill_manager_->OnDidFillAutofillFormData( | 3004 autofill_manager_->OnDidFillAutofillFormData( |
| 3006 TimeTicks::FromInternalValue(5)); | 3005 form, TimeTicks::FromInternalValue(5)); |
| 3007 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 3006 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 3008 TimeTicks::FromInternalValue(3)); | 3007 TimeTicks::FromInternalValue(3)); |
| 3009 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17)); | 3008 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17)); |
| 3010 | 3009 |
| 3011 histogram_tester.ExpectUniqueSample( | 3010 histogram_tester.ExpectUniqueSample( |
| 3012 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1); | 3011 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1); |
| 3013 histogram_tester.ExpectTotalCount( | 3012 histogram_tester.ExpectTotalCount( |
| 3014 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0); | 3013 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0); |
| 3015 histogram_tester.ExpectUniqueSample( | 3014 histogram_tester.ExpectUniqueSample( |
| 3016 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1); | 3015 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1); |
| 3017 histogram_tester.ExpectTotalCount( | 3016 histogram_tester.ExpectTotalCount( |
| 3018 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); | 3017 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); |
| 3019 | 3018 |
| 3020 autofill_manager_->Reset(); | 3019 autofill_manager_->Reset(); |
| 3021 } | 3020 } |
| 3022 | 3021 |
| 3023 // Make sure that loading another form doesn't affect metrics from the first | 3022 // Make sure that loading another form doesn't affect metrics from the first |
| 3024 // form. | 3023 // form. |
| 3025 { | 3024 { |
| 3026 base::HistogramTester histogram_tester; | 3025 base::HistogramTester histogram_tester; |
| 3027 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); | 3026 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); |
| 3028 autofill_manager_->OnFormsSeen(second_forms, | 3027 autofill_manager_->OnFormsSeen(second_forms, |
| 3029 TimeTicks::FromInternalValue(3)); | 3028 TimeTicks::FromInternalValue(3)); |
| 3030 autofill_manager_->OnDidFillAutofillFormData( | 3029 autofill_manager_->OnDidFillAutofillFormData( |
| 3031 TimeTicks::FromInternalValue(5)); | 3030 form, TimeTicks::FromInternalValue(5)); |
| 3032 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 3031 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 3033 TimeTicks::FromInternalValue(3)); | 3032 TimeTicks::FromInternalValue(3)); |
| 3034 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17)); | 3033 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17)); |
| 3035 | 3034 |
| 3036 histogram_tester.ExpectUniqueSample( | 3035 histogram_tester.ExpectUniqueSample( |
| 3037 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1); | 3036 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1); |
| 3038 histogram_tester.ExpectTotalCount( | 3037 histogram_tester.ExpectTotalCount( |
| 3039 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0); | 3038 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0); |
| 3040 histogram_tester.ExpectUniqueSample( | 3039 histogram_tester.ExpectUniqueSample( |
| 3041 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1); | 3040 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3323 EXPECT_THAT( | 3322 EXPECT_THAT( |
| 3324 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 3323 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
| 3325 ElementsAre(Bucket(true, 2))); | 3324 ElementsAre(Bucket(true, 2))); |
| 3326 | 3325 |
| 3327 // No RAPPOR metrics are logged in the case there is at least some server data | 3326 // No RAPPOR metrics are logged in the case there is at least some server data |
| 3328 // available for all forms. | 3327 // available for all forms. |
| 3329 EXPECT_EQ(0, rappor_service_.GetReportsCount()); | 3328 EXPECT_EQ(0, rappor_service_.GetReportsCount()); |
| 3330 } | 3329 } |
| 3331 | 3330 |
| 3332 } // namespace autofill | 3331 } // namespace autofill |
| OLD | NEW |