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/personal_data_manager.h" | 19 #include "components/autofill/core/browser/personal_data_manager.h" |
20 #include "components/autofill/core/browser/test_autofill_client.h" | 20 #include "components/autofill/core/browser/test_autofill_client.h" |
21 #include "components/autofill/core/browser/test_autofill_driver.h" | 21 #include "components/autofill/core/browser/test_autofill_driver.h" |
22 #include "components/autofill/core/browser/wallet/real_pan_wallet_client.h" | 22 #include "components/autofill/core/browser/wallet/real_pan_wallet_client.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_pref_names.h" | 24 #include "components/autofill/core/common/autofill_pref_names.h" |
25 #include "components/autofill/core/common/form_data.h" | 25 #include "components/autofill/core/common/form_data.h" |
26 #include "components/autofill/core/common/form_field_data.h" | 26 #include "components/autofill/core/common/form_field_data.h" |
27 #include "components/rappor/test_rappor_service.h" | 27 #include "components/rappor/test_rappor_service.h" |
| 28 #include "components/signin/core/browser/account_tracker_service.h" |
| 29 #include "components/signin/core/browser/test_signin_client.h" |
28 #include "components/signin/core/common/signin_pref_names.h" | 30 #include "components/signin/core/common/signin_pref_names.h" |
29 #include "components/webdata/common/web_data_results.h" | 31 #include "components/webdata/common/web_data_results.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "ui/gfx/geometry/rect.h" | 33 #include "ui/gfx/geometry/rect.h" |
32 #include "url/gurl.h" | 34 #include "url/gurl.h" |
33 | 35 |
34 using base::ASCIIToUTF16; | 36 using base::ASCIIToUTF16; |
35 using base::TimeTicks; | 37 using base::TimeTicks; |
36 | 38 |
37 namespace autofill { | 39 namespace autofill { |
38 namespace { | 40 namespace { |
39 | 41 |
40 class TestPersonalDataManager : public PersonalDataManager { | 42 class TestPersonalDataManager : public PersonalDataManager { |
41 public: | 43 public: |
42 TestPersonalDataManager() | 44 TestPersonalDataManager() |
43 : PersonalDataManager("en-US"), | 45 : PersonalDataManager("en-US"), |
44 autofill_enabled_(true) { | 46 autofill_enabled_(true) { |
45 CreateTestAutofillProfiles(&web_profiles_); | 47 CreateTestAutofillProfiles(&web_profiles_); |
46 } | 48 } |
47 | 49 |
| 50 using PersonalDataManager::set_account_tracker; |
48 using PersonalDataManager::set_database; | 51 using PersonalDataManager::set_database; |
49 using PersonalDataManager::SetPrefService; | 52 using PersonalDataManager::SetPrefService; |
50 | 53 |
51 // Overridden to avoid a trip to the database. This should be a no-op except | 54 // Overridden to avoid a trip to the database. This should be a no-op except |
52 // for the side-effect of logging the profile count. | 55 // for the side-effect of logging the profile count. |
53 void LoadProfiles() override { | 56 void LoadProfiles() override { |
54 { | 57 { |
55 std::vector<AutofillProfile*> profiles; | 58 std::vector<AutofillProfile*> profiles; |
56 web_profiles_.release(&profiles); | 59 web_profiles_.release(&profiles); |
57 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, | 60 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 ~AutofillMetricsTest() override; | 280 ~AutofillMetricsTest() override; |
278 | 281 |
279 void SetUp() override; | 282 void SetUp() override; |
280 void TearDown() override; | 283 void TearDown() override; |
281 | 284 |
282 protected: | 285 protected: |
283 void EnableWalletSync(); | 286 void EnableWalletSync(); |
284 | 287 |
285 base::MessageLoop message_loop_; | 288 base::MessageLoop message_loop_; |
286 TestAutofillClient autofill_client_; | 289 TestAutofillClient autofill_client_; |
| 290 scoped_ptr<AccountTrackerService> account_tracker_; |
| 291 scoped_ptr<TestSigninClient> signin_client_; |
287 scoped_ptr<TestAutofillDriver> autofill_driver_; | 292 scoped_ptr<TestAutofillDriver> autofill_driver_; |
288 scoped_ptr<TestAutofillManager> autofill_manager_; | 293 scoped_ptr<TestAutofillManager> autofill_manager_; |
289 scoped_ptr<TestPersonalDataManager> personal_data_; | 294 scoped_ptr<TestPersonalDataManager> personal_data_; |
290 scoped_ptr<AutofillExternalDelegate> external_delegate_; | 295 scoped_ptr<AutofillExternalDelegate> external_delegate_; |
291 }; | 296 }; |
292 | 297 |
293 AutofillMetricsTest::~AutofillMetricsTest() { | 298 AutofillMetricsTest::~AutofillMetricsTest() { |
294 // Order of destruction is important as AutofillManager relies on | 299 // Order of destruction is important as AutofillManager relies on |
295 // PersonalDataManager to be around when it gets destroyed. | 300 // PersonalDataManager to be around when it gets destroyed. |
296 autofill_manager_.reset(); | 301 autofill_manager_.reset(); |
297 } | 302 } |
298 | 303 |
299 void AutofillMetricsTest::SetUp() { | 304 void AutofillMetricsTest::SetUp() { |
300 autofill_client_.SetPrefs(test::PrefServiceForTesting()); | 305 autofill_client_.SetPrefs(test::PrefServiceForTesting()); |
301 | 306 |
302 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. | 307 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. |
303 test::DisableSystemServices(autofill_client_.GetPrefs()); | 308 test::DisableSystemServices(autofill_client_.GetPrefs()); |
304 | 309 |
| 310 // Setup account tracker. |
| 311 signin_client_.reset(new TestSigninClient(autofill_client_.GetPrefs())); |
| 312 account_tracker_.reset(new AccountTrackerService()); |
| 313 account_tracker_->Initialize( |
| 314 autofill_client_.GetIdentityProvider()->GetTokenService(), |
| 315 signin_client_.get()); |
| 316 |
305 personal_data_.reset(new TestPersonalDataManager()); | 317 personal_data_.reset(new TestPersonalDataManager()); |
306 personal_data_->set_database(autofill_client_.GetDatabase()); | 318 personal_data_->set_database(autofill_client_.GetDatabase()); |
307 personal_data_->SetPrefService(autofill_client_.GetPrefs()); | 319 personal_data_->SetPrefService(autofill_client_.GetPrefs()); |
| 320 personal_data_->set_account_tracker(account_tracker_.get()); |
308 autofill_driver_.reset(new TestAutofillDriver()); | 321 autofill_driver_.reset(new TestAutofillDriver()); |
309 autofill_manager_.reset(new TestAutofillManager( | 322 autofill_manager_.reset(new TestAutofillManager( |
310 autofill_driver_.get(), &autofill_client_, personal_data_.get())); | 323 autofill_driver_.get(), &autofill_client_, personal_data_.get())); |
311 | 324 |
312 external_delegate_.reset(new AutofillExternalDelegate( | 325 external_delegate_.reset(new AutofillExternalDelegate( |
313 autofill_manager_.get(), | 326 autofill_manager_.get(), |
314 autofill_driver_.get())); | 327 autofill_driver_.get())); |
315 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 328 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
316 } | 329 } |
317 | 330 |
318 void AutofillMetricsTest::TearDown() { | 331 void AutofillMetricsTest::TearDown() { |
319 // Order of destruction is important as AutofillManager relies on | 332 // Order of destruction is important as AutofillManager relies on |
320 // PersonalDataManager to be around when it gets destroyed. | 333 // PersonalDataManager to be around when it gets destroyed. |
321 autofill_manager_.reset(); | 334 autofill_manager_.reset(); |
322 autofill_driver_.reset(); | 335 autofill_driver_.reset(); |
323 personal_data_.reset(); | 336 personal_data_.reset(); |
| 337 account_tracker_->Shutdown(); |
| 338 account_tracker_.reset(); |
| 339 signin_client_.reset(); |
324 } | 340 } |
325 | 341 |
326 void AutofillMetricsTest::EnableWalletSync() { | 342 void AutofillMetricsTest::EnableWalletSync() { |
327 autofill_client_.GetPrefs()->SetBoolean( | 343 autofill_client_.GetPrefs()->SetBoolean( |
328 prefs::kAutofillWalletSyncExperimentEnabled, true); | 344 prefs::kAutofillWalletSyncExperimentEnabled, true); |
| 345 std::string account_id = |
| 346 account_tracker_->SeedAccountInfo("12345", "syncuser@example.com"); |
329 autofill_client_.GetPrefs()->SetString( | 347 autofill_client_.GetPrefs()->SetString( |
330 ::prefs::kGoogleServicesUsername, "syncuser@example.com"); | 348 ::prefs::kGoogleServicesAccountId, account_id); |
331 } | 349 } |
332 | 350 |
333 // Test that we log quality metrics appropriately. | 351 // Test that we log quality metrics appropriately. |
334 TEST_F(AutofillMetricsTest, QualityMetrics) { | 352 TEST_F(AutofillMetricsTest, QualityMetrics) { |
335 // Set up our form data. | 353 // Set up our form data. |
336 FormData form; | 354 FormData form; |
337 form.name = ASCIIToUTF16("TestForm"); | 355 form.name = ASCIIToUTF16("TestForm"); |
338 form.origin = GURL("http://example.com/form.html"); | 356 form.origin = GURL("http://example.com/form.html"); |
339 form.action = GURL("http://example.com/submit.html"); | 357 form.action = GURL("http://example.com/submit.html"); |
340 form.user_submitted = true; | 358 form.user_submitted = true; |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 personal_data_->LoadProfiles(); | 1062 personal_data_->LoadProfiles(); |
1045 histogram_tester.ExpectTotalCount("Autofill.StoredProfileCount", 0); | 1063 histogram_tester.ExpectTotalCount("Autofill.StoredProfileCount", 0); |
1046 } | 1064 } |
1047 } | 1065 } |
1048 | 1066 |
1049 // Test that we correctly log when Autofill is enabled. | 1067 // Test that we correctly log when Autofill is enabled. |
1050 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { | 1068 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { |
1051 base::HistogramTester histogram_tester; | 1069 base::HistogramTester histogram_tester; |
1052 personal_data_->set_autofill_enabled(true); | 1070 personal_data_->set_autofill_enabled(true); |
1053 personal_data_->Init( | 1071 personal_data_->Init( |
1054 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), false); | 1072 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), |
| 1073 account_tracker_.get(), false); |
1055 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.Startup", true, 1); | 1074 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.Startup", true, 1); |
1056 } | 1075 } |
1057 | 1076 |
1058 // Test that we correctly log when Autofill is disabled. | 1077 // Test that we correctly log when Autofill is disabled. |
1059 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { | 1078 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { |
1060 base::HistogramTester histogram_tester; | 1079 base::HistogramTester histogram_tester; |
1061 personal_data_->set_autofill_enabled(false); | 1080 personal_data_->set_autofill_enabled(false); |
1062 personal_data_->Init( | 1081 personal_data_->Init( |
1063 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), false); | 1082 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), |
| 1083 account_tracker_.get(), false); |
1064 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.Startup", false, 1); | 1084 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.Startup", false, 1); |
1065 } | 1085 } |
1066 | 1086 |
1067 // Test that we log the number of Autofill suggestions when filling a form. | 1087 // Test that we log the number of Autofill suggestions when filling a form. |
1068 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { | 1088 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { |
1069 // Set up our form data. | 1089 // Set up our form data. |
1070 FormData form; | 1090 FormData form; |
1071 form.name = ASCIIToUTF16("TestForm"); | 1091 form.name = ASCIIToUTF16("TestForm"); |
1072 form.origin = GURL("http://example.com/form.html"); | 1092 form.origin = GURL("http://example.com/form.html"); |
1073 form.action = GURL("http://example.com/submit.html"); | 1093 form.action = GURL("http://example.com/submit.html"); |
(...skipping 1946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3020 histogram_tester.ExpectTotalCount( | 3040 histogram_tester.ExpectTotalCount( |
3021 "Autofill.FillDuration.FromInteraction.WithAutofill", 0); | 3041 "Autofill.FillDuration.FromInteraction.WithAutofill", 0); |
3022 histogram_tester.ExpectTotalCount( | 3042 histogram_tester.ExpectTotalCount( |
3023 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); | 3043 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0); |
3024 | 3044 |
3025 autofill_manager_->Reset(); | 3045 autofill_manager_->Reset(); |
3026 } | 3046 } |
3027 } | 3047 } |
3028 | 3048 |
3029 } // namespace autofill | 3049 } // namespace autofill |
OLD | NEW |