Chromium Code Reviews| 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" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/histogram_tester.h" | 14 #include "base/test/histogram_tester.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "components/autofill/core/browser/autofill_external_delegate.h" | 16 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 17 #include "components/autofill/core/browser/autofill_manager.h" | 17 #include "components/autofill/core/browser/autofill_manager.h" |
| 18 #include "components/autofill/core/browser/autofill_test_utils.h" | 18 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 19 #include "components/autofill/core/browser/payments/payments_client.h" | 19 #include "components/autofill/core/browser/payments/payments_client.h" |
| 20 #include "components/autofill/core/browser/personal_data_manager.h" | 20 #include "components/autofill/core/browser/personal_data_manager.h" |
| 21 #include "components/autofill/core/browser/test_autofill_client.h" | 21 #include "components/autofill/core/browser/test_autofill_client.h" |
| 22 #include "components/autofill/core/browser/test_autofill_driver.h" | 22 #include "components/autofill/core/browser/test_autofill_driver.h" |
| 23 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 23 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| 24 #include "components/autofill/core/common/autofill_l10n_util.h" | |
| 24 #include "components/autofill/core/common/autofill_pref_names.h" | 25 #include "components/autofill/core/common/autofill_pref_names.h" |
| 25 #include "components/autofill/core/common/form_data.h" | 26 #include "components/autofill/core/common/form_data.h" |
| 26 #include "components/autofill/core/common/form_field_data.h" | 27 #include "components/autofill/core/common/form_field_data.h" |
| 27 #include "components/rappor/test_rappor_service.h" | 28 #include "components/rappor/test_rappor_service.h" |
| 28 #include "components/signin/core/browser/account_tracker_service.h" | 29 #include "components/signin/core/browser/account_tracker_service.h" |
| 29 #include "components/signin/core/browser/fake_signin_manager.h" | 30 #include "components/signin/core/browser/fake_signin_manager.h" |
| 30 #include "components/signin/core/browser/test_signin_client.h" | 31 #include "components/signin/core/browser/test_signin_client.h" |
| 31 #include "components/signin/core/common/signin_pref_names.h" | 32 #include "components/signin/core/common/signin_pref_names.h" |
| 32 #include "components/webdata/common/web_data_results.h" | 33 #include "components/webdata/common/web_data_results.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "third_party/icu/source/common/unicode/locid.h" | |
| 35 #include "ui/gfx/geometry/rect.h" | 37 #include "ui/gfx/geometry/rect.h" |
| 36 #include "url/gurl.h" | 38 #include "url/gurl.h" |
| 37 | 39 |
| 38 using base::ASCIIToUTF16; | 40 using base::ASCIIToUTF16; |
| 39 using base::Bucket; | 41 using base::Bucket; |
| 40 using base::TimeTicks; | 42 using base::TimeTicks; |
| 41 using rappor::TestRapporService; | 43 using rappor::TestRapporService; |
| 42 using ::testing::ElementsAre; | 44 using ::testing::ElementsAre; |
| 45 using icu::Locale; | |
| 43 | 46 |
| 44 namespace autofill { | 47 namespace autofill { |
| 45 namespace { | 48 namespace { |
| 46 | 49 |
| 47 class TestPersonalDataManager : public PersonalDataManager { | 50 class TestPersonalDataManager : public PersonalDataManager { |
| 48 public: | 51 public: |
| 49 TestPersonalDataManager() | 52 TestPersonalDataManager() |
| 50 : PersonalDataManager("en-US"), | 53 : PersonalDataManager("en-US"), |
| 51 autofill_enabled_(true) { | 54 autofill_enabled_(true) { |
| 52 CreateTestAutofillProfiles(&web_profiles_); | 55 CreateTestAutofillProfiles(&web_profiles_); |
| (...skipping 3130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3183 autofill_manager_->SubmitForm(fourth_form, TimeTicks::FromInternalValue(17)); | 3186 autofill_manager_->SubmitForm(fourth_form, TimeTicks::FromInternalValue(17)); |
| 3184 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", | 3187 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3185 AutofillMetrics::NEW_PROFILE_CREATED, 2); | 3188 AutofillMetrics::NEW_PROFILE_CREATED, 2); |
| 3186 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", | 3189 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3187 AutofillMetrics::EXISTING_PROFILE_USED, 1); | 3190 AutofillMetrics::EXISTING_PROFILE_USED, 1); |
| 3188 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", | 3191 histogram_tester.ExpectBucketCount("Autofill.ProfileActionOnFormSubmitted", |
| 3189 AutofillMetrics::EXISTING_PROFILE_UPDATED, | 3192 AutofillMetrics::EXISTING_PROFILE_UPDATED, |
| 3190 1); | 3193 1); |
| 3191 } | 3194 } |
| 3192 | 3195 |
| 3196 // Test the success in the creation of the ICU Collator. | |
| 3197 TEST_F(AutofillMetricsTest, IcuCollatorCreationSuccess) { | |
| 3198 base::HistogramTester histogram_tester; | |
| 3199 l10n::CaseInsensitiveCompare compare; | |
| 3200 histogram_tester.ExpectUniqueSample("Autofill.IcuCollatorCreationSuccess", | |
| 3201 true, 1); | |
| 3202 } | |
| 3203 | |
| 3204 // Test the failure in creating the ICU Collator. | |
| 3205 TEST_F(AutofillMetricsTest, IcuCollatorCreationSuccess_BadLocale) { | |
| 3206 // Setting the locale to a bogus value. | |
| 3207 Locale bogusLocale = Locale::createFromName("garbage"); | |
| 3208 bogusLocale.setToBogus(); | |
| 3209 | |
| 3210 base::HistogramTester histogram_tester; | |
| 3211 l10n::CaseInsensitiveCompare compare(bogusLocale); | |
|
Ilya Sherman
2015/11/19 22:31:20
Rather than creating a test-only constructor, coul
Mathieu
2015/11/20 16:19:38
It was my first thought as well. I tried to call s
| |
| 3212 histogram_tester.ExpectUniqueSample("Autofill.IcuCollatorCreationSuccess", | |
| 3213 false, 1); | |
| 3214 } | |
| 3215 | |
| 3193 // Test class that shares setup code for testing ParseQueryResponse. | 3216 // Test class that shares setup code for testing ParseQueryResponse. |
| 3194 class AutofillMetricsParseQueryResponseTest : public testing::Test { | 3217 class AutofillMetricsParseQueryResponseTest : public testing::Test { |
| 3195 public: | 3218 public: |
| 3196 void SetUp() override { | 3219 void SetUp() override { |
| 3197 FormData form; | 3220 FormData form; |
| 3198 form.origin = GURL("http://foo.com"); | 3221 form.origin = GURL("http://foo.com"); |
| 3199 FormFieldData field; | 3222 FormFieldData field; |
| 3200 field.form_control_type = "text"; | 3223 field.form_control_type = "text"; |
| 3201 | 3224 |
| 3202 field.label = ASCIIToUTF16("fullname"); | 3225 field.label = ASCIIToUTF16("fullname"); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3323 EXPECT_THAT( | 3346 EXPECT_THAT( |
| 3324 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 3347 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
| 3325 ElementsAre(Bucket(true, 2))); | 3348 ElementsAre(Bucket(true, 2))); |
| 3326 | 3349 |
| 3327 // No RAPPOR metrics are logged in the case there is at least some server data | 3350 // No RAPPOR metrics are logged in the case there is at least some server data |
| 3328 // available for all forms. | 3351 // available for all forms. |
| 3329 EXPECT_EQ(0, rappor_service_.GetReportsCount()); | 3352 EXPECT_EQ(0, rappor_service_.GetReportsCount()); |
| 3330 } | 3353 } |
| 3331 | 3354 |
| 3332 } // namespace autofill | 3355 } // namespace autofill |
| OLD | NEW |