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

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

Issue 306053008: Rename AutofillManagerDelegate to AutofillClient. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 6 months 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 | Annotate | Revision Log
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/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.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_driver.h" 21 #include "components/autofill/core/browser/test_autofill_driver.h"
21 #include "components/autofill/core/browser/test_autofill_manager_delegate.h"
22 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 22 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
23 #include "components/autofill/core/common/form_data.h" 23 #include "components/autofill/core/common/form_data.h"
24 #include "components/autofill/core/common/form_field_data.h" 24 #include "components/autofill/core/common/form_field_data.h"
25 #include "components/webdata/common/web_data_results.h" 25 #include "components/webdata/common/web_data_results.h"
26 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gfx/rect.h" 28 #include "ui/gfx/rect.h"
29 #include "url/gurl.h" 29 #include "url/gurl.h"
30 30
31 using base::ASCIIToUTF16; 31 using base::ASCIIToUTF16;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 UpdateAutofillCount(); 158 UpdateAutofillCount();
159 } 159 }
160 160
161 private: 161 private:
162 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); 162 DISALLOW_COPY_AND_ASSIGN(TestFormStructure);
163 }; 163 };
164 164
165 class TestAutofillManager : public AutofillManager { 165 class TestAutofillManager : public AutofillManager {
166 public: 166 public:
167 TestAutofillManager(AutofillDriver* driver, 167 TestAutofillManager(AutofillDriver* driver,
168 AutofillManagerDelegate* manager_delegate, 168 AutofillClient* autofill_client,
169 TestPersonalDataManager* personal_manager) 169 TestPersonalDataManager* personal_manager)
170 : AutofillManager(driver, manager_delegate, personal_manager), 170 : AutofillManager(driver, autofill_client, personal_manager),
171 autofill_enabled_(true) { 171 autofill_enabled_(true) {
172 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>); 172 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>);
173 } 173 }
174 virtual ~TestAutofillManager() {} 174 virtual ~TestAutofillManager() {}
175 175
176 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } 176 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; }
177 177
178 void set_autofill_enabled(bool autofill_enabled) { 178 void set_autofill_enabled(bool autofill_enabled) {
179 autofill_enabled_ = autofill_enabled; 179 autofill_enabled_ = autofill_enabled;
180 } 180 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 231
232 class AutofillMetricsTest : public testing::Test { 232 class AutofillMetricsTest : public testing::Test {
233 public: 233 public:
234 virtual ~AutofillMetricsTest(); 234 virtual ~AutofillMetricsTest();
235 235
236 virtual void SetUp() OVERRIDE; 236 virtual void SetUp() OVERRIDE;
237 virtual void TearDown() OVERRIDE; 237 virtual void TearDown() OVERRIDE;
238 238
239 protected: 239 protected:
240 base::MessageLoop message_loop_; 240 base::MessageLoop message_loop_;
241 TestAutofillManagerDelegate manager_delegate_; 241 TestAutofillClient autofill_client_;
242 scoped_ptr<TestAutofillDriver> autofill_driver_; 242 scoped_ptr<TestAutofillDriver> autofill_driver_;
243 scoped_ptr<TestAutofillManager> autofill_manager_; 243 scoped_ptr<TestAutofillManager> autofill_manager_;
244 scoped_ptr<TestPersonalDataManager> personal_data_; 244 scoped_ptr<TestPersonalDataManager> personal_data_;
245 scoped_ptr<AutofillExternalDelegate> external_delegate_; 245 scoped_ptr<AutofillExternalDelegate> external_delegate_;
246 }; 246 };
247 247
248 AutofillMetricsTest::~AutofillMetricsTest() { 248 AutofillMetricsTest::~AutofillMetricsTest() {
249 // Order of destruction is important as AutofillManager relies on 249 // Order of destruction is important as AutofillManager relies on
250 // PersonalDataManager to be around when it gets destroyed. 250 // PersonalDataManager to be around when it gets destroyed.
251 autofill_manager_.reset(); 251 autofill_manager_.reset();
252 } 252 }
253 253
254 void AutofillMetricsTest::SetUp() { 254 void AutofillMetricsTest::SetUp() {
255 manager_delegate_.SetPrefs(test::PrefServiceForTesting()); 255 autofill_client_.SetPrefs(test::PrefServiceForTesting());
256 256
257 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. 257 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
258 test::DisableSystemServices(manager_delegate_.GetPrefs()); 258 test::DisableSystemServices(autofill_client_.GetPrefs());
259 259
260 personal_data_.reset(new TestPersonalDataManager()); 260 personal_data_.reset(new TestPersonalDataManager());
261 personal_data_->set_database(manager_delegate_.GetDatabase()); 261 personal_data_->set_database(autofill_client_.GetDatabase());
262 personal_data_->SetPrefService(manager_delegate_.GetPrefs()); 262 personal_data_->SetPrefService(autofill_client_.GetPrefs());
263 autofill_driver_.reset(new TestAutofillDriver()); 263 autofill_driver_.reset(new TestAutofillDriver());
264 autofill_manager_.reset(new TestAutofillManager( 264 autofill_manager_.reset(new TestAutofillManager(
265 autofill_driver_.get(), &manager_delegate_, personal_data_.get())); 265 autofill_driver_.get(), &autofill_client_, personal_data_.get()));
266 266
267 external_delegate_.reset(new AutofillExternalDelegate( 267 external_delegate_.reset(new AutofillExternalDelegate(
268 autofill_manager_.get(), 268 autofill_manager_.get(),
269 autofill_driver_.get())); 269 autofill_driver_.get()));
270 autofill_manager_->SetExternalDelegate(external_delegate_.get()); 270 autofill_manager_->SetExternalDelegate(external_delegate_.get());
271 } 271 }
272 272
273 void AutofillMetricsTest::TearDown() { 273 void AutofillMetricsTest::TearDown() {
274 // Order of destruction is important as AutofillManager relies on 274 // Order of destruction is important as AutofillManager relies on
275 // PersonalDataManager to be around when it gets destroyed. 275 // PersonalDataManager to be around when it gets destroyed.
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 LogStoredProfileCount(::testing::_)).Times(0); 578 LogStoredProfileCount(::testing::_)).Times(0);
579 personal_data_->LoadProfiles(); 579 personal_data_->LoadProfiles();
580 } 580 }
581 581
582 // Test that we correctly log when Autofill is enabled. 582 // Test that we correctly log when Autofill is enabled.
583 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { 583 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) {
584 personal_data_->set_autofill_enabled(true); 584 personal_data_->set_autofill_enabled(true);
585 EXPECT_CALL(*personal_data_->metric_logger(), 585 EXPECT_CALL(*personal_data_->metric_logger(),
586 LogIsAutofillEnabledAtStartup(true)).Times(1); 586 LogIsAutofillEnabledAtStartup(true)).Times(1);
587 personal_data_->Init( 587 personal_data_->Init(
588 manager_delegate_.GetDatabase(), manager_delegate_.GetPrefs(), false); 588 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), false);
589 } 589 }
590 590
591 // Test that we correctly log when Autofill is disabled. 591 // Test that we correctly log when Autofill is disabled.
592 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { 592 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) {
593 personal_data_->set_autofill_enabled(false); 593 personal_data_->set_autofill_enabled(false);
594 EXPECT_CALL(*personal_data_->metric_logger(), 594 EXPECT_CALL(*personal_data_->metric_logger(),
595 LogIsAutofillEnabledAtStartup(false)).Times(1); 595 LogIsAutofillEnabledAtStartup(false)).Times(1);
596 personal_data_->Init( 596 personal_data_->Init(
597 manager_delegate_.GetDatabase(), manager_delegate_.GetPrefs(), false); 597 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), false);
598 } 598 }
599 599
600 // Test that we log the number of Autofill suggestions when filling a form. 600 // Test that we log the number of Autofill suggestions when filling a form.
601 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { 601 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) {
602 // Set up our form data. 602 // Set up our form data.
603 FormData form; 603 FormData form;
604 form.name = ASCIIToUTF16("TestForm"); 604 form.name = ASCIIToUTF16("TestForm");
605 form.method = ASCIIToUTF16("POST"); 605 form.method = ASCIIToUTF16("POST");
606 form.origin = GURL("http://example.com/form.html"); 606 form.origin = GURL("http://example.com/form.html");
607 form.action = GURL("http://example.com/submit.html"); 607 form.action = GURL("http://example.com/submit.html");
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 autofill_manager_->OnFormsSeen(second_forms, 1089 autofill_manager_->OnFormsSeen(second_forms,
1090 TimeTicks::FromInternalValue(5)); 1090 TimeTicks::FromInternalValue(5));
1091 autofill_manager_->FormSubmitted(second_form, 1091 autofill_manager_->FormSubmitted(second_form,
1092 TimeTicks::FromInternalValue(17)); 1092 TimeTicks::FromInternalValue(17));
1093 autofill_manager_->Reset(); 1093 autofill_manager_->Reset();
1094 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1094 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1095 } 1095 }
1096 } 1096 }
1097 1097
1098 } // namespace autofill 1098 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.h ('k') | components/autofill/core/browser/test_autofill_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698