Index: chrome/browser/autofill/autofill_metrics_unittest.cc |
diff --git a/chrome/browser/autofill/autofill_metrics_unittest.cc b/chrome/browser/autofill/autofill_metrics_unittest.cc |
index 0141830e4ce215f3dddf3b1239e6605b77629995..5dc3ab9f384cd922b1df7cc0fd889b9c3c0cda0a 100644 |
--- a/chrome/browser/autofill/autofill_metrics_unittest.cc |
+++ b/chrome/browser/autofill/autofill_metrics_unittest.cc |
@@ -4,6 +4,7 @@ |
#include <vector> |
+#include "base/bind.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/string16.h" |
#include "base/time.h" |
@@ -17,6 +18,7 @@ |
#include "chrome/browser/autofill/autofill_metrics.h" |
#include "chrome/browser/autofill/personal_data_manager.h" |
#include "chrome/browser/autofill/personal_data_manager_factory.h" |
+#include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
#include "chrome/browser/webdata/web_data_service.h" |
#include "chrome/common/form_data.h" |
@@ -43,6 +45,10 @@ class MockAutofillMetrics : public AutofillMetrics { |
MockAutofillMetrics() {} |
MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); |
MOCK_CONST_METHOD1(LogAutocheckoutInfoBarMetric, void(InfoBarMetric metric)); |
+ MOCK_CONST_METHOD3(LogRequestAutocompleteUiDuration, |
+ void(const TimeDelta& duration, |
+ autofill::DialogRequester requester, |
+ DialogDismissalAction dismissal_action)); |
MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, |
void(DeveloperEngagementMetric metric)); |
MOCK_CONST_METHOD3(LogHeuristicTypePrediction, |
@@ -89,6 +95,10 @@ class TestPersonalDataManager : public PersonalDataManager { |
CreateTestAutofillProfiles(&web_profiles_); |
} |
+ static ProfileKeyedService* Build(Profile* profile) { |
+ return new TestPersonalDataManager(); |
+ } |
+ |
void SetBrowserContext(content::BrowserContext* context) { |
set_browser_context(context); |
} |
@@ -261,7 +271,7 @@ class TestAutofillManager : public AutofillManager { |
DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
}; |
-class TestAutocheckoutManager : public AutocheckoutManager { |
+class TestAutocheckoutManager : public autofill::AutocheckoutManager { |
public: |
explicit TestAutocheckoutManager(AutofillManager* autofill_manager) |
: AutocheckoutManager(autofill_manager) { |
@@ -280,6 +290,9 @@ class TestAutocheckoutManager : public AutocheckoutManager { |
DISALLOW_COPY_AND_ASSIGN(TestAutocheckoutManager); |
}; |
+void MockRequestAutocompleteDialogCallback(const FormStructure*) { |
+} |
+ |
} // namespace |
class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { |
@@ -300,10 +313,11 @@ class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { |
content::TestBrowserThread ui_thread_; |
content::TestBrowserThread file_thread_; |
+ content::TestBrowserThread io_thread_; |
scoped_refptr<TestAutofillManager> autofill_manager_; |
TestAutocheckoutManager autocheckout_manager_; |
- TestPersonalDataManager personal_data_; |
+ TestPersonalDataManager* personal_data_; |
private: |
std::string default_gmock_verbosity_level_; |
@@ -315,6 +329,7 @@ AutofillMetricsTest::AutofillMetricsTest() |
: ChromeRenderViewHostTestHarness(), |
ui_thread_(BrowserThread::UI, &message_loop_), |
file_thread_(BrowserThread::FILE), |
+ io_thread_(BrowserThread::IO), |
autocheckout_manager_(NULL) { |
} |
@@ -325,17 +340,23 @@ AutofillMetricsTest::~AutofillMetricsTest() { |
} |
void AutofillMetricsTest::SetUp() { |
- Profile* profile = new TestingProfile(); |
+ TestingProfile* profile = new TestingProfile(); |
+ profile->CreateRequestContext(); |
browser_context_.reset(profile); |
- PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL); |
+ personal_data_ = |
+ static_cast<TestPersonalDataManager*>( |
+ PersonalDataManagerFactory::GetInstance()->SetTestingFactoryAndUse( |
+ profile, TestPersonalDataManager::Build)); |
ChromeRenderViewHostTestHarness::SetUp(); |
- TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
- personal_data_.SetBrowserContext(profile); |
+ io_thread_.StartIOThread(); |
+ |
+ autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
+ personal_data_->SetBrowserContext(profile); |
autofill_manager_ = new TestAutofillManager( |
web_contents(), |
- TabAutofillManagerDelegate::FromWebContents(web_contents()), |
- &personal_data_); |
+ autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), |
+ personal_data_); |
file_thread_.Start(); |
@@ -359,7 +380,10 @@ void AutofillMetricsTest::TearDown() { |
// be destroyed at the destruction of the WebContents. |
autofill_manager_ = NULL; |
file_thread_.Stop(); |
+ |
+ profile()->ResetRequestContext(); |
ChromeRenderViewHostTestHarness::TearDown(); |
+ io_thread_.Stop(); |
} |
scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( |
@@ -371,7 +395,7 @@ scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( |
CreditCard* credit_card = new CreditCard(); |
if (created_card) |
*created_card = credit_card; |
- return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_, |
+ return AutofillCCInfoBarDelegate::Create(credit_card, personal_data_, |
metric_logger); |
} |
@@ -382,7 +406,7 @@ AutofillMetricsTest::CreateAutocheckoutDelegate( |
LogAutocheckoutInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
GURL url("www.google.com"); |
content::SSLStatus ssl_status; |
- return AutocheckoutInfoBarDelegate::Create( |
+ return autofill::AutocheckoutInfoBarDelegate::Create( |
*metric_logger, |
url, |
ssl_status, |
@@ -1060,28 +1084,28 @@ TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) { |
// Test that the profile count is logged correctly. |
TEST_F(AutofillMetricsTest, StoredProfileCount) { |
// The metric should be logged when the profiles are first loaded. |
- EXPECT_CALL(*personal_data_.metric_logger(), |
+ EXPECT_CALL(*personal_data_->metric_logger(), |
LogStoredProfileCount(2)).Times(1); |
- personal_data_.LoadProfiles(); |
+ personal_data_->LoadProfiles(); |
// The metric should only be logged once. |
- EXPECT_CALL(*personal_data_.metric_logger(), |
+ EXPECT_CALL(*personal_data_->metric_logger(), |
LogStoredProfileCount(::testing::_)).Times(0); |
- personal_data_.LoadProfiles(); |
+ personal_data_->LoadProfiles(); |
} |
// Test that we correctly log whether Autofill is enabled. |
TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { |
- personal_data_.set_autofill_enabled(true); |
- EXPECT_CALL(*personal_data_.metric_logger(), |
+ personal_data_->set_autofill_enabled(true); |
+ EXPECT_CALL(*personal_data_->metric_logger(), |
LogIsAutofillEnabledAtStartup(true)).Times(1); |
- personal_data_.Init(profile()); |
- personal_data_.Shutdown(); |
+ personal_data_->Init(profile()); |
+ personal_data_->Shutdown(); |
- personal_data_.set_autofill_enabled(false); |
- EXPECT_CALL(*personal_data_.metric_logger(), |
+ personal_data_->set_autofill_enabled(false); |
+ EXPECT_CALL(*personal_data_->metric_logger(), |
LogIsAutofillEnabledAtStartup(false)).Times(1); |
- personal_data_.Init(profile()); |
+ personal_data_->Init(profile()); |
} |
// Test that we log the number of Autofill suggestions when filling a form. |
@@ -1186,7 +1210,7 @@ TEST_F(AutofillMetricsTest, CreditCardInfoBar) { |
scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, |
&credit_card)); |
ASSERT_TRUE(infobar); |
- EXPECT_CALL(personal_data_, SaveImportedCreditCard(*credit_card)); |
+ EXPECT_CALL(*personal_data_, SaveImportedCreditCard(*credit_card)); |
EXPECT_CALL(metric_logger, |
LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); |
EXPECT_CALL(metric_logger, |
@@ -1286,6 +1310,76 @@ TEST_F(AutofillMetricsTest, AutocheckoutInfoBar) { |
} |
} |
+// TODO(isherman): Enable this test on other platforms once the UI is |
+// implemented on those platforms. |
+#if defined(TOOLKIT_VIEWS) |
+TEST_F(AutofillMetricsTest, RequestAutocompleteUiDuration) { |
+ MockAutofillMetrics metric_logger; |
+ ::testing::InSequence dummy; |
+ |
+ FormData form; |
+ form.name = ASCIIToUTF16("TestForm"); |
+ form.method = ASCIIToUTF16("POST"); |
+ form.origin = GURL("http://example.com/form.html"); |
+ form.action = GURL("http://example.com/submit.html"); |
+ form.user_submitted = true; |
+ |
+ FormFieldData field; |
+ field.autocomplete_attribute = "email"; |
+ form.fields.push_back(field); |
+ |
+ // Submit the form data. |
+ { |
+ EXPECT_CALL(metric_logger, |
+ LogRequestAutocompleteUiDuration( |
+ _, |
+ autofill::DIALOG_REQUESTER_REQUEST_AUTOCOMPLETE, |
+ AutofillMetrics::DIALOG_ACCEPTED)).Times(1); |
+ |
+ autofill::AutofillDialogControllerImpl* dialog_controller = |
+ new autofill::AutofillDialogControllerImpl( |
+ web_contents(), form, GURL(), content::SSLStatus(), |
+ metric_logger, |
+ autofill::DIALOG_REQUESTER_REQUEST_AUTOCOMPLETE, |
+ base::Bind(&MockRequestAutocompleteDialogCallback)); |
+ dialog_controller->Show(); |
+ dialog_controller->ViewClosed(autofill::ACTION_SUBMIT); |
+ } |
+ |
+ // Cancel out of the dialog. |
+ { |
+ EXPECT_CALL(metric_logger, |
+ LogRequestAutocompleteUiDuration( |
+ _, autofill::DIALOG_REQUESTER_AUTOCHECKOUT, |
+ AutofillMetrics::DIALOG_CANCELED)).Times(1); |
+ |
+ autofill::AutofillDialogControllerImpl* dialog_controller = |
+ new autofill::AutofillDialogControllerImpl( |
+ web_contents(), form, GURL(), content::SSLStatus(), |
+ metric_logger, autofill::DIALOG_REQUESTER_AUTOCHECKOUT, |
+ base::Bind(&MockRequestAutocompleteDialogCallback)); |
+ dialog_controller->Show(); |
+ dialog_controller->ViewClosed(autofill::ACTION_ABORT); |
+ } |
+ |
+ // Take some other action that dismisses the dialog. |
+ { |
+ EXPECT_CALL(metric_logger, |
+ LogRequestAutocompleteUiDuration( |
+ _, |
+ autofill::DIALOG_REQUESTER_AUTOCHECKOUT, |
+ AutofillMetrics::DIALOG_CANCELED)).Times(1); |
+ |
+ autofill::AutofillDialogControllerImpl* dialog_controller = |
+ new autofill::AutofillDialogControllerImpl( |
+ web_contents(), form, GURL(), content::SSLStatus(), |
+ metric_logger, autofill::DIALOG_REQUESTER_AUTOCHECKOUT, |
+ base::Bind(&MockRequestAutocompleteDialogCallback)); |
+ dialog_controller->Show(); |
+ dialog_controller->Hide(); |
+ } |
+} |
+#endif // defined(TOOLKIT_VIEWS) |
// Test that server query response experiment id metrics are logged correctly. |
TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { |