Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: components/autofill/core/browser/autofill_metrics_unittest.cc

Issue 71683003: Have AutofillManagerDelegate supply the AutofillWebDataService to core code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittests, respond to reviews Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 using PersonalDataManager::set_database;
98 set_browser_context(context); 99 using PersonalDataManager::set_pref_service;
99 }
100
101 void SetPrefService(PrefService* pref_service) {
102 set_pref_service(pref_service);
103 }
104 100
105 // Overridden to avoid a trip to the database. This should be a no-op except 101 // 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. 102 // for the side-effect of logging the profile count.
107 virtual void LoadProfiles() OVERRIDE { 103 virtual void LoadProfiles() OVERRIDE {
108 std::vector<AutofillProfile*> profiles; 104 std::vector<AutofillProfile*> profiles;
109 web_profiles_.release(&profiles); 105 web_profiles_.release(&profiles);
110 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, 106 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT,
111 profiles); 107 profiles);
112 ReceiveLoadedProfiles(0, &result); 108 ReceiveLoadedProfiles(0, &result);
113 } 109 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 277
282 void AutofillMetricsTest::SetUp() { 278 void AutofillMetricsTest::SetUp() {
283 ChromeRenderViewHostTestHarness::SetUp(); 279 ChromeRenderViewHostTestHarness::SetUp();
284 280
285 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. 281 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
286 autofill::test::DisableSystemServices(profile()); 282 autofill::test::DisableSystemServices(profile());
287 283
288 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); 284 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL);
289 285
290 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); 286 TabAutofillManagerDelegate::CreateForWebContents(web_contents());
287 autofill::TabAutofillManagerDelegate* manager_delegate =
288 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents());
291 289
292 personal_data_.reset(new TestPersonalDataManager()); 290 personal_data_.reset(new TestPersonalDataManager());
293 personal_data_->SetBrowserContext(profile()); 291 personal_data_->set_database(manager_delegate->GetDatabase());
294 personal_data_->SetPrefService(profile()->GetPrefs()); 292 personal_data_->set_pref_service(profile()->GetPrefs());
295 autofill_driver_.reset(new TestAutofillDriver(web_contents())); 293 autofill_driver_.reset(new TestAutofillDriver(web_contents()));
296 autofill_manager_.reset(new TestAutofillManager( 294 autofill_manager_.reset(new TestAutofillManager(
297 autofill_driver_.get(), 295 autofill_driver_.get(), manager_delegate, personal_data_.get()));
298 TabAutofillManagerDelegate::FromWebContents(web_contents()),
299 personal_data_.get()));
300 296
301 external_delegate_.reset(new AutofillExternalDelegate( 297 external_delegate_.reset(new AutofillExternalDelegate(
302 web_contents(), 298 web_contents(),
303 autofill_manager_.get(), 299 autofill_manager_.get(),
304 autofill_driver_.get())); 300 autofill_driver_.get()));
305 autofill_manager_->SetExternalDelegate(external_delegate_.get()); 301 autofill_manager_->SetExternalDelegate(external_delegate_.get());
306 } 302 }
307 303
308 void AutofillMetricsTest::TearDown() { 304 void AutofillMetricsTest::TearDown() {
309 // Order of destruction is important as AutofillManager relies on 305 // Order of destruction is important as AutofillManager relies on
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 EXPECT_CALL(*personal_data_->metric_logger(), 998 EXPECT_CALL(*personal_data_->metric_logger(),
1003 LogStoredProfileCount(::testing::_)).Times(0); 999 LogStoredProfileCount(::testing::_)).Times(0);
1004 personal_data_->LoadProfiles(); 1000 personal_data_->LoadProfiles();
1005 } 1001 }
1006 1002
1007 // Test that we correctly log when Autofill is enabled. 1003 // Test that we correctly log when Autofill is enabled.
1008 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { 1004 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) {
1009 personal_data_->set_autofill_enabled(true); 1005 personal_data_->set_autofill_enabled(true);
1010 EXPECT_CALL(*personal_data_->metric_logger(), 1006 EXPECT_CALL(*personal_data_->metric_logger(),
1011 LogIsAutofillEnabledAtStartup(true)).Times(1); 1007 LogIsAutofillEnabledAtStartup(true)).Times(1);
1012 personal_data_->Init(profile(), 1008 autofill::TabAutofillManagerDelegate* manager_delegate =
1009 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents());
1010 personal_data_->Init(manager_delegate->GetDatabase(),
1013 profile()->GetPrefs(), 1011 profile()->GetPrefs(),
1014 profile()->IsOffTheRecord()); 1012 profile()->IsOffTheRecord());
1015 } 1013 }
1016 1014
1017 // Test that we correctly log when Autofill is disabled. 1015 // Test that we correctly log when Autofill is disabled.
1018 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { 1016 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) {
1019 personal_data_->set_autofill_enabled(false); 1017 personal_data_->set_autofill_enabled(false);
1020 EXPECT_CALL(*personal_data_->metric_logger(), 1018 EXPECT_CALL(*personal_data_->metric_logger(),
1021 LogIsAutofillEnabledAtStartup(false)).Times(1); 1019 LogIsAutofillEnabledAtStartup(false)).Times(1);
1022 personal_data_->Init(profile(), 1020 autofill::TabAutofillManagerDelegate* manager_delegate =
1021 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents());
1022 personal_data_->Init(manager_delegate->GetDatabase(),
1023 profile()->GetPrefs(), 1023 profile()->GetPrefs(),
1024 profile()->IsOffTheRecord()); 1024 profile()->IsOffTheRecord());
1025 } 1025 }
1026 1026
1027 // Test that we log the number of Autofill suggestions when filling a form. 1027 // Test that we log the number of Autofill suggestions when filling a form.
1028 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { 1028 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) {
1029 // Set up our form data. 1029 // Set up our form data.
1030 FormData form; 1030 FormData form;
1031 form.name = ASCIIToUTF16("TestForm"); 1031 form.name = ASCIIToUTF16("TestForm");
1032 form.method = ASCIIToUTF16("POST"); 1032 form.method = ASCIIToUTF16("POST");
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1556 TimeTicks::FromInternalValue(5)); 1556 TimeTicks::FromInternalValue(5));
1557 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1557 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1558 TimeTicks::FromInternalValue(3)); 1558 TimeTicks::FromInternalValue(3));
1559 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1559 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1560 autofill_manager_->Reset(); 1560 autofill_manager_->Reset();
1561 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1561 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1562 } 1562 }
1563 } 1563 }
1564 1564
1565 } // namespace autofill 1565 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698