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

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

Issue 12476031: Refactor notifications of chrome/browser/webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 5 #include <vector>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 270
271 protected: 271 protected:
272 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( 272 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
273 MockAutofillMetrics* metric_logger); 273 MockAutofillMetrics* metric_logger);
274 274
275 content::TestBrowserThread ui_thread_; 275 content::TestBrowserThread ui_thread_;
276 content::TestBrowserThread file_thread_; 276 content::TestBrowserThread file_thread_;
277 content::TestBrowserThread io_thread_; 277 content::TestBrowserThread io_thread_;
278 278
279 scoped_ptr<TestAutofillManager> autofill_manager_; 279 scoped_ptr<TestAutofillManager> autofill_manager_;
280 TestPersonalDataManager personal_data_; 280 scoped_ptr<TestPersonalDataManager> personal_data_;
281 281
282 private: 282 private:
283 std::string default_gmock_verbosity_level_; 283 std::string default_gmock_verbosity_level_;
284 284
285 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); 285 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest);
286 }; 286 };
287 287
288 AutofillMetricsTest::AutofillMetricsTest() 288 AutofillMetricsTest::AutofillMetricsTest()
289 : ChromeRenderViewHostTestHarness(), 289 : ChromeRenderViewHostTestHarness(),
290 ui_thread_(BrowserThread::UI, &message_loop_), 290 ui_thread_(BrowserThread::UI, &message_loop_),
291 file_thread_(BrowserThread::FILE), 291 file_thread_(BrowserThread::FILE),
292 io_thread_(BrowserThread::IO) { 292 io_thread_(BrowserThread::IO) {
293 } 293 }
294 294
295 AutofillMetricsTest::~AutofillMetricsTest() { 295 AutofillMetricsTest::~AutofillMetricsTest() {
296 // Order of destruction is important as AutofillManager relies on 296 // Order of destruction is important as AutofillManager relies on
297 // PersonalDataManager to be around when it gets destroyed. 297 // PersonalDataManager to be around when it gets destroyed.
298 autofill_manager_.reset(); 298 autofill_manager_.reset();
299 } 299 }
300 300
301 void AutofillMetricsTest::SetUp() { 301 void AutofillMetricsTest::SetUp() {
302 TestingProfile* profile = new TestingProfile(); 302 TestingProfile* profile = new TestingProfile();
303 profile->CreateRequestContext(); 303 profile->CreateRequestContext();
304 browser_context_.reset(profile); 304 browser_context_.reset(profile);
305 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL); 305 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL);
306 306
307 ChromeRenderViewHostTestHarness::SetUp(); 307 ChromeRenderViewHostTestHarness::SetUp();
308 io_thread_.StartIOThread(); 308 io_thread_.StartIOThread();
309 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); 309 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents());
310 personal_data_.SetBrowserContext(profile); 310
311 personal_data_.reset(new TestPersonalDataManager());
312 personal_data_->SetBrowserContext(profile);
311 autofill_manager_.reset(new TestAutofillManager( 313 autofill_manager_.reset(new TestAutofillManager(
312 web_contents(), 314 web_contents(),
313 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), 315 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()),
314 &personal_data_)); 316 personal_data_.get()));
315 317
316 file_thread_.Start(); 318 file_thread_.Start();
317 319
318 // Ignore any metrics that we haven't explicitly set expectations for. 320 // Ignore any metrics that we haven't explicitly set expectations for.
319 // If we don't override the verbosity level, we'll get lots of log spew from 321 // If we don't override the verbosity level, we'll get lots of log spew from
320 // mocked functions that aren't relevant to a test but happen to be called 322 // mocked functions that aren't relevant to a test but happen to be called
321 // during the test's execution. 323 // during the test's execution.
322 // CAUTION: This is a global variable. So as to not affect other tests, this 324 // CAUTION: This is a global variable. So as to not affect other tests, this
323 // _must_ be restored to its original value at the end of the test. 325 // _must_ be restored to its original value at the end of the test.
324 default_gmock_verbosity_level_ = ::testing::FLAGS_gmock_verbose; 326 default_gmock_verbosity_level_ = ::testing::FLAGS_gmock_verbose;
325 ::testing::FLAGS_gmock_verbose = "error"; 327 ::testing::FLAGS_gmock_verbose = "error";
326 } 328 }
327 329
328 void AutofillMetricsTest::TearDown() { 330 void AutofillMetricsTest::TearDown() {
329 // Restore the global Gmock verbosity level to its default value. 331 // Restore the global Gmock verbosity level to its default value.
330 ::testing::FLAGS_gmock_verbose = default_gmock_verbosity_level_; 332 ::testing::FLAGS_gmock_verbose = default_gmock_verbosity_level_;
331 333
332 // Order of destruction is important as AutofillManager relies on 334 // Order of destruction is important as AutofillManager relies on
333 // PersonalDataManager to be around when it gets destroyed. Also, a real 335 // PersonalDataManager to be around when it gets destroyed. Also, a real
334 // AutofillManager is tied to the lifetime of the WebContents, so it must 336 // AutofillManager is tied to the lifetime of the WebContents, so it must
335 // be destroyed at the destruction of the WebContents. 337 // be destroyed at the destruction of the WebContents.
336 autofill_manager_.reset(); 338 autofill_manager_.reset();
339 personal_data_.reset();
337 profile()->ResetRequestContext(); 340 profile()->ResetRequestContext();
338 file_thread_.Stop(); 341 file_thread_.Stop();
339 ChromeRenderViewHostTestHarness::TearDown(); 342 ChromeRenderViewHostTestHarness::TearDown();
340 io_thread_.Stop(); 343 io_thread_.Stop();
341 } 344 }
342 345
343 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( 346 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate(
344 MockAutofillMetrics* metric_logger) { 347 MockAutofillMetrics* metric_logger) {
345 EXPECT_CALL(*metric_logger, 348 EXPECT_CALL(*metric_logger,
346 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 349 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
347 350
348 CreditCard credit_card; 351 CreditCard credit_card;
349 return AutofillCCInfoBarDelegate::CreateForTesting( 352 return AutofillCCInfoBarDelegate::CreateForTesting(
350 metric_logger, 353 metric_logger,
351 base::Bind(&TestPersonalDataManager::SaveImportedCreditCard, 354 base::Bind(&TestPersonalDataManager::SaveImportedCreditCard,
352 base::Unretained(&personal_data_), credit_card)); 355 base::Unretained(personal_data_.get()), credit_card));
353 } 356 }
354 357
355 // Test that we log quality metrics appropriately. 358 // Test that we log quality metrics appropriately.
356 TEST_F(AutofillMetricsTest, QualityMetrics) { 359 TEST_F(AutofillMetricsTest, QualityMetrics) {
357 // Set up our form data. 360 // Set up our form data.
358 FormData form; 361 FormData form;
359 form.name = ASCIIToUTF16("TestForm"); 362 form.name = ASCIIToUTF16("TestForm");
360 form.method = ASCIIToUTF16("POST"); 363 form.method = ASCIIToUTF16("POST");
361 form.origin = GURL("http://example.com/form.html"); 364 form.origin = GURL("http://example.com/form.html");
362 form.action = GURL("http://example.com/submit.html"); 365 form.action = GURL("http://example.com/submit.html");
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 ADDRESS_HOME_COUNTRY, experiment_id)); 1019 ADDRESS_HOME_COUNTRY, experiment_id));
1017 1020
1018 // Simulate form submission. 1021 // Simulate form submission.
1019 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form, 1022 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
1020 TimeTicks::Now())); 1023 TimeTicks::Now()));
1021 } 1024 }
1022 1025
1023 // Test that the profile count is logged correctly. 1026 // Test that the profile count is logged correctly.
1024 TEST_F(AutofillMetricsTest, StoredProfileCount) { 1027 TEST_F(AutofillMetricsTest, StoredProfileCount) {
1025 // The metric should be logged when the profiles are first loaded. 1028 // The metric should be logged when the profiles are first loaded.
1026 EXPECT_CALL(*personal_data_.metric_logger(), 1029 EXPECT_CALL(*personal_data_->metric_logger(),
1027 LogStoredProfileCount(2)).Times(1); 1030 LogStoredProfileCount(2)).Times(1);
1028 personal_data_.LoadProfiles(); 1031 personal_data_->LoadProfiles();
1029 1032
1030 // The metric should only be logged once. 1033 // The metric should only be logged once.
1031 EXPECT_CALL(*personal_data_.metric_logger(), 1034 EXPECT_CALL(*personal_data_->metric_logger(),
1032 LogStoredProfileCount(::testing::_)).Times(0); 1035 LogStoredProfileCount(::testing::_)).Times(0);
1033 personal_data_.LoadProfiles(); 1036 personal_data_->LoadProfiles();
1034 } 1037 }
1035 1038
1036 // Test that we correctly log when Autofill is enabled. 1039 // Test that we correctly log when Autofill is enabled.
1037 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { 1040 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) {
1038 personal_data_.set_autofill_enabled(true); 1041 personal_data_->set_autofill_enabled(true);
1039 EXPECT_CALL(*personal_data_.metric_logger(), 1042 EXPECT_CALL(*personal_data_->metric_logger(),
1040 LogIsAutofillEnabledAtStartup(true)).Times(1); 1043 LogIsAutofillEnabledAtStartup(true)).Times(1);
1041 personal_data_.Init(profile()); 1044 personal_data_->Init(profile());
1042 } 1045 }
1043 1046
1044 // Test that we correctly log when Autofill is disabled. 1047 // Test that we correctly log when Autofill is disabled.
1045 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { 1048 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) {
1046 personal_data_.set_autofill_enabled(false); 1049 personal_data_->set_autofill_enabled(false);
1047 EXPECT_CALL(*personal_data_.metric_logger(), 1050 EXPECT_CALL(*personal_data_->metric_logger(),
1048 LogIsAutofillEnabledAtStartup(false)).Times(1); 1051 LogIsAutofillEnabledAtStartup(false)).Times(1);
1049 personal_data_.Init(profile()); 1052 personal_data_->Init(profile());
1050 } 1053 }
1051 1054
1052 // Test that we log the number of Autofill suggestions when filling a form. 1055 // Test that we log the number of Autofill suggestions when filling a form.
1053 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { 1056 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) {
1054 // Set up our form data. 1057 // Set up our form data.
1055 FormData form; 1058 FormData form;
1056 form.name = ASCIIToUTF16("TestForm"); 1059 form.name = ASCIIToUTF16("TestForm");
1057 form.method = ASCIIToUTF16("POST"); 1060 form.method = ASCIIToUTF16("POST");
1058 form.origin = GURL("http://example.com/form.html"); 1061 form.origin = GURL("http://example.com/form.html");
1059 form.action = GURL("http://example.com/submit.html"); 1062 form.action = GURL("http://example.com/submit.html");
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 1145
1143 // Test that credit card infobar metrics are logged correctly. 1146 // Test that credit card infobar metrics are logged correctly.
1144 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { 1147 TEST_F(AutofillMetricsTest, CreditCardInfoBar) {
1145 MockAutofillMetrics metric_logger; 1148 MockAutofillMetrics metric_logger;
1146 ::testing::InSequence dummy; 1149 ::testing::InSequence dummy;
1147 1150
1148 // Accept the infobar. 1151 // Accept the infobar.
1149 { 1152 {
1150 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); 1153 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
1151 ASSERT_TRUE(infobar); 1154 ASSERT_TRUE(infobar);
1152 EXPECT_CALL(personal_data_, SaveImportedCreditCard(_)); 1155 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
1153 EXPECT_CALL(metric_logger, 1156 EXPECT_CALL(metric_logger,
1154 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); 1157 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1);
1155 EXPECT_CALL(metric_logger, 1158 EXPECT_CALL(metric_logger,
1156 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); 1159 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1157 EXPECT_TRUE(infobar->Accept()); 1160 EXPECT_TRUE(infobar->Accept());
1158 } 1161 }
1159 1162
1160 // Cancel the infobar. 1163 // Cancel the infobar.
1161 { 1164 {
1162 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); 1165 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1572 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1570 autofill_manager_->OnDidFillAutofillFormData( 1573 autofill_manager_->OnDidFillAutofillFormData(
1571 TimeTicks::FromInternalValue(5)); 1574 TimeTicks::FromInternalValue(5));
1572 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1575 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1573 TimeTicks::FromInternalValue(3)); 1576 TimeTicks::FromInternalValue(3));
1574 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1577 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1575 autofill_manager_->Reset(); 1578 autofill_manager_->Reset();
1576 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1579 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1577 } 1580 }
1578 } 1581 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698