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/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 14 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
| 15 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 15 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 16 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 16 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
| 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "components/autofill/core/browser/autofill_external_delegate.h" | 19 #include "components/autofill/core/browser/autofill_external_delegate.h" |
| 20 #include "components/autofill/core/browser/autofill_manager.h" | 20 #include "components/autofill/core/browser/autofill_manager.h" |
| 21 #include "components/autofill/core/browser/autofill_manager_delegate.h" | 21 #include "components/autofill/core/browser/autofill_manager_delegate.h" |
| 22 #include "components/autofill/core/browser/autofill_test_utils.h" | 22 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 23 #include "components/autofill/core/browser/personal_data_manager.h" | 23 #include "components/autofill/core/browser/personal_data_manager.h" |
| 24 #include "components/autofill/core/browser/test_autofill_driver.h" | 24 #include "components/autofill/core/browser/test_autofill_driver.h" |
| 25 #include "components/autofill/core/browser/webdata/autofill_webdata_service.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/autofill/core/common/forms_seen_state.h" | 28 #include "components/autofill/core/common/forms_seen_state.h" |
| 28 #include "components/webdata/common/web_data_results.h" | 29 #include "components/webdata/common/web_data_results.h" |
| 29 #include "content/public/test/test_utils.h" | 30 #include "content/public/test/test_utils.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 32 #include "ui/gfx/rect.h" | 33 #include "ui/gfx/rect.h" |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 | 35 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 | 88 |
| 88 class TestPersonalDataManager : public PersonalDataManager { | 89 class TestPersonalDataManager : public PersonalDataManager { |
| 89 public: | 90 public: |
| 90 TestPersonalDataManager() | 91 TestPersonalDataManager() |
| 91 : PersonalDataManager("en-US"), | 92 : PersonalDataManager("en-US"), |
| 92 autofill_enabled_(true) { | 93 autofill_enabled_(true) { |
| 93 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>()); | 94 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>()); |
| 94 CreateTestAutofillProfiles(&web_profiles_); | 95 CreateTestAutofillProfiles(&web_profiles_); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void SetBrowserContext(content::BrowserContext* context) { | 98 void SetAutofillWebDataService( |
| 98 set_browser_context(context); | 99 scoped_refptr<AutofillWebDataService> webdata) { |
| 100 set_autofill_webdata_service(webdata); | |
|
Ilya Sherman
2013/11/14 02:22:02
Ditto here.
blundell
2013/11/14 16:46:30
Done.
| |
| 99 } | 101 } |
| 100 | 102 |
| 101 void SetPrefService(PrefService* pref_service) { | 103 void SetPrefService(PrefService* pref_service) { |
| 102 set_pref_service(pref_service); | 104 set_pref_service(pref_service); |
| 103 } | 105 } |
| 104 | 106 |
| 105 // Overridden to avoid a trip to the database. This should be a no-op except | 107 // Overridden to avoid a trip to the database. This should be a no-op except |
| 106 // for the side-effect of logging the profile count. | 108 // for the side-effect of logging the profile count. |
| 107 virtual void LoadProfiles() OVERRIDE { | 109 virtual void LoadProfiles() OVERRIDE { |
| 108 std::vector<AutofillProfile*> profiles; | 110 std::vector<AutofillProfile*> profiles; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 | 283 |
| 282 void AutofillMetricsTest::SetUp() { | 284 void AutofillMetricsTest::SetUp() { |
| 283 ChromeRenderViewHostTestHarness::SetUp(); | 285 ChromeRenderViewHostTestHarness::SetUp(); |
| 284 | 286 |
| 285 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. | 287 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. |
| 286 autofill::test::DisableSystemServices(profile()); | 288 autofill::test::DisableSystemServices(profile()); |
| 287 | 289 |
| 288 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); | 290 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); |
| 289 | 291 |
| 290 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 292 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
| 293 autofill::TabAutofillManagerDelegate* manager_delegate = | |
| 294 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()); | |
| 291 | 295 |
| 292 personal_data_.reset(new TestPersonalDataManager()); | 296 personal_data_.reset(new TestPersonalDataManager()); |
| 293 personal_data_->SetBrowserContext(profile()); | 297 personal_data_->SetAutofillWebDataService( |
| 298 manager_delegate->GetAutofillWebDataService()); | |
| 294 personal_data_->SetPrefService(profile()->GetPrefs()); | 299 personal_data_->SetPrefService(profile()->GetPrefs()); |
| 295 autofill_driver_.reset(new TestAutofillDriver(web_contents())); | 300 autofill_driver_.reset(new TestAutofillDriver(web_contents())); |
| 296 autofill_manager_.reset(new TestAutofillManager( | 301 autofill_manager_.reset(new TestAutofillManager( |
| 297 autofill_driver_.get(), | 302 autofill_driver_.get(), manager_delegate, personal_data_.get())); |
| 298 TabAutofillManagerDelegate::FromWebContents(web_contents()), | |
| 299 personal_data_.get())); | |
| 300 | 303 |
| 301 external_delegate_.reset(new AutofillExternalDelegate( | 304 external_delegate_.reset(new AutofillExternalDelegate( |
| 302 web_contents(), | 305 web_contents(), |
| 303 autofill_manager_.get(), | 306 autofill_manager_.get(), |
| 304 autofill_driver_.get())); | 307 autofill_driver_.get())); |
| 305 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 308 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
| 306 } | 309 } |
| 307 | 310 |
| 308 void AutofillMetricsTest::TearDown() { | 311 void AutofillMetricsTest::TearDown() { |
| 309 // Order of destruction is important as AutofillManager relies on | 312 // Order of destruction is important as AutofillManager relies on |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1002 EXPECT_CALL(*personal_data_->metric_logger(), | 1005 EXPECT_CALL(*personal_data_->metric_logger(), |
| 1003 LogStoredProfileCount(::testing::_)).Times(0); | 1006 LogStoredProfileCount(::testing::_)).Times(0); |
| 1004 personal_data_->LoadProfiles(); | 1007 personal_data_->LoadProfiles(); |
| 1005 } | 1008 } |
| 1006 | 1009 |
| 1007 // Test that we correctly log when Autofill is enabled. | 1010 // Test that we correctly log when Autofill is enabled. |
| 1008 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { | 1011 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { |
| 1009 personal_data_->set_autofill_enabled(true); | 1012 personal_data_->set_autofill_enabled(true); |
| 1010 EXPECT_CALL(*personal_data_->metric_logger(), | 1013 EXPECT_CALL(*personal_data_->metric_logger(), |
| 1011 LogIsAutofillEnabledAtStartup(true)).Times(1); | 1014 LogIsAutofillEnabledAtStartup(true)).Times(1); |
| 1012 personal_data_->Init(profile(), | 1015 autofill::TabAutofillManagerDelegate* manager_delegate = |
| 1016 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()); | |
| 1017 personal_data_->Init(manager_delegate->GetAutofillWebDataService(), | |
| 1013 profile()->GetPrefs(), | 1018 profile()->GetPrefs(), |
| 1014 profile()->IsOffTheRecord()); | 1019 profile()->IsOffTheRecord()); |
| 1015 } | 1020 } |
| 1016 | 1021 |
| 1017 // Test that we correctly log when Autofill is disabled. | 1022 // Test that we correctly log when Autofill is disabled. |
| 1018 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { | 1023 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { |
| 1019 personal_data_->set_autofill_enabled(false); | 1024 personal_data_->set_autofill_enabled(false); |
| 1020 EXPECT_CALL(*personal_data_->metric_logger(), | 1025 EXPECT_CALL(*personal_data_->metric_logger(), |
| 1021 LogIsAutofillEnabledAtStartup(false)).Times(1); | 1026 LogIsAutofillEnabledAtStartup(false)).Times(1); |
| 1022 personal_data_->Init(profile(), | 1027 autofill::TabAutofillManagerDelegate* manager_delegate = |
| 1028 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()); | |
| 1029 personal_data_->Init(manager_delegate->GetAutofillWebDataService(), | |
| 1023 profile()->GetPrefs(), | 1030 profile()->GetPrefs(), |
| 1024 profile()->IsOffTheRecord()); | 1031 profile()->IsOffTheRecord()); |
| 1025 } | 1032 } |
| 1026 | 1033 |
| 1027 // Test that we log the number of Autofill suggestions when filling a form. | 1034 // Test that we log the number of Autofill suggestions when filling a form. |
| 1028 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { | 1035 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { |
| 1029 // Set up our form data. | 1036 // Set up our form data. |
| 1030 FormData form; | 1037 FormData form; |
| 1031 form.name = ASCIIToUTF16("TestForm"); | 1038 form.name = ASCIIToUTF16("TestForm"); |
| 1032 form.method = ASCIIToUTF16("POST"); | 1039 form.method = ASCIIToUTF16("POST"); |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1556 TimeTicks::FromInternalValue(5)); | 1563 TimeTicks::FromInternalValue(5)); |
| 1557 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1564 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 1558 TimeTicks::FromInternalValue(3)); | 1565 TimeTicks::FromInternalValue(3)); |
| 1559 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1566 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
| 1560 autofill_manager_->Reset(); | 1567 autofill_manager_->Reset(); |
| 1561 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1568 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
| 1562 } | 1569 } |
| 1563 } | 1570 } |
| 1564 | 1571 |
| 1565 } // namespace autofill | 1572 } // namespace autofill |
| OLD | NEW |