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/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 : PersonalDataManager("en-US"), | 91 : PersonalDataManager("en-US"), |
92 autofill_enabled_(true) { | 92 autofill_enabled_(true) { |
93 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>()); | 93 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>()); |
94 CreateTestAutofillProfiles(&web_profiles_); | 94 CreateTestAutofillProfiles(&web_profiles_); |
95 } | 95 } |
96 | 96 |
97 void SetBrowserContext(content::BrowserContext* context) { | 97 void SetBrowserContext(content::BrowserContext* context) { |
98 set_browser_context(context); | 98 set_browser_context(context); |
99 } | 99 } |
100 | 100 |
| 101 void SetPrefService(PrefService* pref_service) { |
| 102 set_pref_service(pref_service); |
| 103 } |
| 104 |
101 // Overridden to avoid a trip to the database. This should be a no-op except | 105 // Overridden to avoid a trip to the database. This should be a no-op except |
102 // for the side-effect of logging the profile count. | 106 // for the side-effect of logging the profile count. |
103 virtual void LoadProfiles() OVERRIDE { | 107 virtual void LoadProfiles() OVERRIDE { |
104 std::vector<AutofillProfile*> profiles; | 108 std::vector<AutofillProfile*> profiles; |
105 web_profiles_.release(&profiles); | 109 web_profiles_.release(&profiles); |
106 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, | 110 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, |
107 profiles); | 111 profiles); |
108 ReceiveLoadedProfiles(0, &result); | 112 ReceiveLoadedProfiles(0, &result); |
109 } | 113 } |
110 | 114 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 | 284 |
281 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. | 285 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. |
282 autofill::test::DisableSystemServices(profile()); | 286 autofill::test::DisableSystemServices(profile()); |
283 | 287 |
284 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); | 288 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); |
285 | 289 |
286 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 290 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
287 | 291 |
288 personal_data_.reset(new TestPersonalDataManager()); | 292 personal_data_.reset(new TestPersonalDataManager()); |
289 personal_data_->SetBrowserContext(profile()); | 293 personal_data_->SetBrowserContext(profile()); |
| 294 personal_data_->SetPrefService(profile()->GetPrefs()); |
290 autofill_driver_.reset(new TestAutofillDriver(web_contents())); | 295 autofill_driver_.reset(new TestAutofillDriver(web_contents())); |
291 autofill_manager_.reset(new TestAutofillManager( | 296 autofill_manager_.reset(new TestAutofillManager( |
292 autofill_driver_.get(), | 297 autofill_driver_.get(), |
293 TabAutofillManagerDelegate::FromWebContents(web_contents()), | 298 TabAutofillManagerDelegate::FromWebContents(web_contents()), |
294 personal_data_.get())); | 299 personal_data_.get())); |
295 | 300 |
296 external_delegate_.reset(new AutofillExternalDelegate( | 301 external_delegate_.reset(new AutofillExternalDelegate( |
297 web_contents(), | 302 web_contents(), |
298 autofill_manager_.get(), | 303 autofill_manager_.get(), |
299 autofill_driver_.get())); | 304 autofill_driver_.get())); |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 EXPECT_CALL(*personal_data_->metric_logger(), | 1002 EXPECT_CALL(*personal_data_->metric_logger(), |
998 LogStoredProfileCount(::testing::_)).Times(0); | 1003 LogStoredProfileCount(::testing::_)).Times(0); |
999 personal_data_->LoadProfiles(); | 1004 personal_data_->LoadProfiles(); |
1000 } | 1005 } |
1001 | 1006 |
1002 // Test that we correctly log when Autofill is enabled. | 1007 // Test that we correctly log when Autofill is enabled. |
1003 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { | 1008 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { |
1004 personal_data_->set_autofill_enabled(true); | 1009 personal_data_->set_autofill_enabled(true); |
1005 EXPECT_CALL(*personal_data_->metric_logger(), | 1010 EXPECT_CALL(*personal_data_->metric_logger(), |
1006 LogIsAutofillEnabledAtStartup(true)).Times(1); | 1011 LogIsAutofillEnabledAtStartup(true)).Times(1); |
1007 personal_data_->Init(profile()); | 1012 personal_data_->Init(profile(), profile()->GetPrefs()); |
1008 } | 1013 } |
1009 | 1014 |
1010 // Test that we correctly log when Autofill is disabled. | 1015 // Test that we correctly log when Autofill is disabled. |
1011 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { | 1016 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { |
1012 personal_data_->set_autofill_enabled(false); | 1017 personal_data_->set_autofill_enabled(false); |
1013 EXPECT_CALL(*personal_data_->metric_logger(), | 1018 EXPECT_CALL(*personal_data_->metric_logger(), |
1014 LogIsAutofillEnabledAtStartup(false)).Times(1); | 1019 LogIsAutofillEnabledAtStartup(false)).Times(1); |
1015 personal_data_->Init(profile()); | 1020 personal_data_->Init(profile(), profile()->GetPrefs()); |
1016 } | 1021 } |
1017 | 1022 |
1018 // Test that we log the number of Autofill suggestions when filling a form. | 1023 // Test that we log the number of Autofill suggestions when filling a form. |
1019 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { | 1024 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { |
1020 // Set up our form data. | 1025 // Set up our form data. |
1021 FormData form; | 1026 FormData form; |
1022 form.name = ASCIIToUTF16("TestForm"); | 1027 form.name = ASCIIToUTF16("TestForm"); |
1023 form.method = ASCIIToUTF16("POST"); | 1028 form.method = ASCIIToUTF16("POST"); |
1024 form.origin = GURL("http://example.com/form.html"); | 1029 form.origin = GURL("http://example.com/form.html"); |
1025 form.action = GURL("http://example.com/submit.html"); | 1030 form.action = GURL("http://example.com/submit.html"); |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 TimeTicks::FromInternalValue(5)); | 1552 TimeTicks::FromInternalValue(5)); |
1548 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1553 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
1549 TimeTicks::FromInternalValue(3)); | 1554 TimeTicks::FromInternalValue(3)); |
1550 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1555 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
1551 autofill_manager_->Reset(); | 1556 autofill_manager_->Reset(); |
1552 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1557 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
1553 } | 1558 } |
1554 } | 1559 } |
1555 | 1560 |
1556 } // namespace autofill | 1561 } // namespace autofill |
OLD | NEW |