| OLD | NEW | 
|     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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   274  |   274  | 
|   275  protected: |   275  protected: | 
|   276   scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( |   276   scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( | 
|   277       MockAutofillMetrics* metric_logger); |   277       MockAutofillMetrics* metric_logger); | 
|   278  |   278  | 
|   279   content::TestBrowserThread ui_thread_; |   279   content::TestBrowserThread ui_thread_; | 
|   280   content::TestBrowserThread file_thread_; |   280   content::TestBrowserThread file_thread_; | 
|   281   content::TestBrowserThread io_thread_; |   281   content::TestBrowserThread io_thread_; | 
|   282  |   282  | 
|   283   scoped_ptr<TestAutofillManager> autofill_manager_; |   283   scoped_ptr<TestAutofillManager> autofill_manager_; | 
|   284   TestPersonalDataManager personal_data_; |   284   scoped_ptr<TestPersonalDataManager> personal_data_; | 
|   285  |   285  | 
|   286  private: |   286  private: | 
|   287   DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); |   287   DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); | 
|   288 }; |   288 }; | 
|   289  |   289  | 
|   290 AutofillMetricsTest::AutofillMetricsTest() |   290 AutofillMetricsTest::AutofillMetricsTest() | 
|   291   : ChromeRenderViewHostTestHarness(), |   291   : ChromeRenderViewHostTestHarness(), | 
|   292     ui_thread_(BrowserThread::UI, &message_loop_), |   292     ui_thread_(BrowserThread::UI, &message_loop_), | 
|   293     file_thread_(BrowserThread::FILE), |   293     file_thread_(BrowserThread::FILE), | 
|   294     io_thread_(BrowserThread::IO) { |   294     io_thread_(BrowserThread::IO) { | 
|   295 } |   295 } | 
|   296  |   296  | 
|   297 AutofillMetricsTest::~AutofillMetricsTest() { |   297 AutofillMetricsTest::~AutofillMetricsTest() { | 
|   298   // Order of destruction is important as AutofillManager relies on |   298   // Order of destruction is important as AutofillManager relies on | 
|   299   // PersonalDataManager to be around when it gets destroyed. |   299   // PersonalDataManager to be around when it gets destroyed. | 
|   300   autofill_manager_.reset(); |   300   autofill_manager_.reset(); | 
|   301 } |   301 } | 
|   302  |   302  | 
|   303 void AutofillMetricsTest::SetUp() { |   303 void AutofillMetricsTest::SetUp() { | 
|   304   TestingProfile* profile = new TestingProfile(); |   304   TestingProfile* profile = new TestingProfile(); | 
|   305   profile->CreateRequestContext(); |   305   profile->CreateRequestContext(); | 
|   306   browser_context_.reset(profile); |   306   browser_context_.reset(profile); | 
|   307   PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL); |   307   PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL); | 
|   308  |   308  | 
|   309   ChromeRenderViewHostTestHarness::SetUp(); |   309   ChromeRenderViewHostTestHarness::SetUp(); | 
|   310   io_thread_.StartIOThread(); |   310   io_thread_.StartIOThread(); | 
|   311   autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |   311   autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 
|   312   personal_data_.SetBrowserContext(profile); |   312  | 
 |   313   personal_data_.reset(new TestPersonalDataManager()); | 
 |   314   personal_data_->SetBrowserContext(profile); | 
|   313   autofill_manager_.reset(new TestAutofillManager( |   315   autofill_manager_.reset(new TestAutofillManager( | 
|   314       web_contents(), |   316       web_contents(), | 
|   315       autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), |   317       autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), | 
|   316       &personal_data_)); |   318       personal_data_.get())); | 
|   317  |   319  | 
|   318   file_thread_.Start(); |   320   file_thread_.Start(); | 
|   319 } |   321 } | 
|   320  |   322  | 
|   321 void AutofillMetricsTest::TearDown() { |   323 void AutofillMetricsTest::TearDown() { | 
|   322   // Order of destruction is important as AutofillManager relies on |   324   // Order of destruction is important as AutofillManager relies on | 
|   323   // PersonalDataManager to be around when it gets destroyed. Also, a real |   325   // PersonalDataManager to be around when it gets destroyed. Also, a real | 
|   324   // AutofillManager is tied to the lifetime of the WebContents, so it must |   326   // AutofillManager is tied to the lifetime of the WebContents, so it must | 
|   325   // be destroyed at the destruction of the WebContents. |   327   // be destroyed at the destruction of the WebContents. | 
|   326   autofill_manager_.reset(); |   328   autofill_manager_.reset(); | 
 |   329   personal_data_.reset(); | 
|   327   profile()->ResetRequestContext(); |   330   profile()->ResetRequestContext(); | 
|   328   file_thread_.Stop(); |   331   file_thread_.Stop(); | 
|   329   ChromeRenderViewHostTestHarness::TearDown(); |   332   ChromeRenderViewHostTestHarness::TearDown(); | 
|   330   io_thread_.Stop(); |   333   io_thread_.Stop(); | 
|   331 } |   334 } | 
|   332  |   335  | 
|   333 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( |   336 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( | 
|   334     MockAutofillMetrics* metric_logger) { |   337     MockAutofillMetrics* metric_logger) { | 
|   335   EXPECT_CALL(*metric_logger, |   338   EXPECT_CALL(*metric_logger, | 
|   336               LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |   339               LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 
|   337  |   340  | 
|   338   CreditCard credit_card; |   341   CreditCard credit_card; | 
|   339   return AutofillCCInfoBarDelegate::CreateForTesting( |   342   return AutofillCCInfoBarDelegate::CreateForTesting( | 
|   340       metric_logger, |   343       metric_logger, | 
|   341       base::Bind(&TestPersonalDataManager::SaveImportedCreditCard, |   344       base::Bind(&TestPersonalDataManager::SaveImportedCreditCard, | 
|   342                  base::Unretained(&personal_data_), credit_card)); |   345                  base::Unretained(personal_data_.get()), credit_card)); | 
|   343 } |   346 } | 
|   344  |   347  | 
|   345 // Test that we log quality metrics appropriately. |   348 // Test that we log quality metrics appropriately. | 
|   346 TEST_F(AutofillMetricsTest, QualityMetrics) { |   349 TEST_F(AutofillMetricsTest, QualityMetrics) { | 
|   347   // Set up our form data. |   350   // Set up our form data. | 
|   348   FormData form; |   351   FormData form; | 
|   349   form.name = ASCIIToUTF16("TestForm"); |   352   form.name = ASCIIToUTF16("TestForm"); | 
|   350   form.method = ASCIIToUTF16("POST"); |   353   form.method = ASCIIToUTF16("POST"); | 
|   351   form.origin = GURL("http://example.com/form.html"); |   354   form.origin = GURL("http://example.com/form.html"); | 
|   352   form.action = GURL("http://example.com/submit.html"); |   355   form.action = GURL("http://example.com/submit.html"); | 
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1006                                        ADDRESS_HOME_COUNTRY, experiment_id)); |  1009                                        ADDRESS_HOME_COUNTRY, experiment_id)); | 
|  1007  |  1010  | 
|  1008   // Simulate form submission. |  1011   // Simulate form submission. | 
|  1009   EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form, |  1012   EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form, | 
|  1010                                                            TimeTicks::Now())); |  1013                                                            TimeTicks::Now())); | 
|  1011 } |  1014 } | 
|  1012  |  1015  | 
|  1013 // Test that the profile count is logged correctly. |  1016 // Test that the profile count is logged correctly. | 
|  1014 TEST_F(AutofillMetricsTest, StoredProfileCount) { |  1017 TEST_F(AutofillMetricsTest, StoredProfileCount) { | 
|  1015   // The metric should be logged when the profiles are first loaded. |  1018   // The metric should be logged when the profiles are first loaded. | 
|  1016   EXPECT_CALL(*personal_data_.metric_logger(), |  1019   EXPECT_CALL(*personal_data_->metric_logger(), | 
|  1017               LogStoredProfileCount(2)).Times(1); |  1020               LogStoredProfileCount(2)).Times(1); | 
|  1018   personal_data_.LoadProfiles(); |  1021   personal_data_->LoadProfiles(); | 
|  1019  |  1022  | 
|  1020   // The metric should only be logged once. |  1023   // The metric should only be logged once. | 
|  1021   EXPECT_CALL(*personal_data_.metric_logger(), |  1024   EXPECT_CALL(*personal_data_->metric_logger(), | 
|  1022               LogStoredProfileCount(::testing::_)).Times(0); |  1025               LogStoredProfileCount(::testing::_)).Times(0); | 
|  1023   personal_data_.LoadProfiles(); |  1026   personal_data_->LoadProfiles(); | 
|  1024 } |  1027 } | 
|  1025  |  1028  | 
|  1026 // Test that we correctly log when Autofill is enabled. |  1029 // Test that we correctly log when Autofill is enabled. | 
|  1027 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { |  1030 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { | 
|  1028   personal_data_.set_autofill_enabled(true); |  1031   personal_data_->set_autofill_enabled(true); | 
|  1029   EXPECT_CALL(*personal_data_.metric_logger(), |  1032   EXPECT_CALL(*personal_data_->metric_logger(), | 
|  1030               LogIsAutofillEnabledAtStartup(true)).Times(1); |  1033               LogIsAutofillEnabledAtStartup(true)).Times(1); | 
|  1031   personal_data_.Init(profile()); |  1034   personal_data_->Init(profile()); | 
|  1032 } |  1035 } | 
|  1033  |  1036  | 
|  1034 // Test that we correctly log when Autofill is disabled. |  1037 // Test that we correctly log when Autofill is disabled. | 
|  1035 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { |  1038 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { | 
|  1036   personal_data_.set_autofill_enabled(false); |  1039   personal_data_->set_autofill_enabled(false); | 
|  1037   EXPECT_CALL(*personal_data_.metric_logger(), |  1040   EXPECT_CALL(*personal_data_->metric_logger(), | 
|  1038               LogIsAutofillEnabledAtStartup(false)).Times(1); |  1041               LogIsAutofillEnabledAtStartup(false)).Times(1); | 
|  1039   personal_data_.Init(profile()); |  1042   personal_data_->Init(profile()); | 
|  1040 } |  1043 } | 
|  1041  |  1044  | 
|  1042 // Test that we log the number of Autofill suggestions when filling a form. |  1045 // Test that we log the number of Autofill suggestions when filling a form. | 
|  1043 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { |  1046 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { | 
|  1044   // Set up our form data. |  1047   // Set up our form data. | 
|  1045   FormData form; |  1048   FormData form; | 
|  1046   form.name = ASCIIToUTF16("TestForm"); |  1049   form.name = ASCIIToUTF16("TestForm"); | 
|  1047   form.method = ASCIIToUTF16("POST"); |  1050   form.method = ASCIIToUTF16("POST"); | 
|  1048   form.origin = GURL("http://example.com/form.html"); |  1051   form.origin = GURL("http://example.com/form.html"); | 
|  1049   form.action = GURL("http://example.com/submit.html"); |  1052   form.action = GURL("http://example.com/submit.html"); | 
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1132  |  1135  | 
|  1133 // Test that credit card infobar metrics are logged correctly. |  1136 // Test that credit card infobar metrics are logged correctly. | 
|  1134 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { |  1137 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { | 
|  1135   testing::NiceMock<MockAutofillMetrics> metric_logger; |  1138   testing::NiceMock<MockAutofillMetrics> metric_logger; | 
|  1136   ::testing::InSequence dummy; |  1139   ::testing::InSequence dummy; | 
|  1137  |  1140  | 
|  1138   // Accept the infobar. |  1141   // Accept the infobar. | 
|  1139   { |  1142   { | 
|  1140     scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); |  1143     scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); | 
|  1141     ASSERT_TRUE(infobar); |  1144     ASSERT_TRUE(infobar); | 
|  1142     EXPECT_CALL(personal_data_, SaveImportedCreditCard(_)); |  1145     EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); | 
|  1143     EXPECT_CALL(metric_logger, |  1146     EXPECT_CALL(metric_logger, | 
|  1144         LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); |  1147         LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); | 
|  1145     EXPECT_CALL(metric_logger, |  1148     EXPECT_CALL(metric_logger, | 
|  1146         LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); |  1149         LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); | 
|  1147     EXPECT_TRUE(infobar->Accept()); |  1150     EXPECT_TRUE(infobar->Accept()); | 
|  1148   } |  1151   } | 
|  1149  |  1152  | 
|  1150   // Cancel the infobar. |  1153   // Cancel the infobar. | 
|  1151   { |  1154   { | 
|  1152     scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); |  1155     scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); | 
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1563         forms, TimeTicks::FromInternalValue(1), false); |  1566         forms, TimeTicks::FromInternalValue(1), false); | 
|  1564     autofill_manager_->OnDidFillAutofillFormData( |  1567     autofill_manager_->OnDidFillAutofillFormData( | 
|  1565         TimeTicks::FromInternalValue(5)); |  1568         TimeTicks::FromInternalValue(5)); | 
|  1566     autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |  1569     autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 
|  1567                                             TimeTicks::FromInternalValue(3)); |  1570                                             TimeTicks::FromInternalValue(3)); | 
|  1568     autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |  1571     autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 
|  1569     autofill_manager_->Reset(); |  1572     autofill_manager_->Reset(); | 
|  1570     Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |  1573     Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 
|  1571   } |  1574   } | 
|  1572 } |  1575 } | 
| OLD | NEW |