| 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { | 263 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { |
| 264 public: | 264 public: |
| 265 AutofillMetricsTest(); | 265 AutofillMetricsTest(); |
| 266 virtual ~AutofillMetricsTest(); | 266 virtual ~AutofillMetricsTest(); |
| 267 | 267 |
| 268 virtual void SetUp() OVERRIDE; | 268 virtual void SetUp() OVERRIDE; |
| 269 virtual void TearDown() OVERRIDE; | 269 virtual void TearDown() OVERRIDE; |
| 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 CreditCard** created_card); | |
| 275 | 274 |
| 276 content::TestBrowserThread ui_thread_; | 275 content::TestBrowserThread ui_thread_; |
| 277 content::TestBrowserThread file_thread_; | 276 content::TestBrowserThread file_thread_; |
| 278 content::TestBrowserThread io_thread_; | 277 content::TestBrowserThread io_thread_; |
| 279 | 278 |
| 280 scoped_ptr<TestAutofillManager> autofill_manager_; | 279 scoped_ptr<TestAutofillManager> autofill_manager_; |
| 281 TestPersonalDataManager personal_data_; | 280 TestPersonalDataManager personal_data_; |
| 282 | 281 |
| 283 private: | 282 private: |
| 284 std::string default_gmock_verbosity_level_; | 283 std::string default_gmock_verbosity_level_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 // AutofillManager is tied to the lifetime of the WebContents, so it must | 334 // AutofillManager is tied to the lifetime of the WebContents, so it must |
| 336 // be destroyed at the destruction of the WebContents. | 335 // be destroyed at the destruction of the WebContents. |
| 337 autofill_manager_.reset(); | 336 autofill_manager_.reset(); |
| 338 profile()->ResetRequestContext(); | 337 profile()->ResetRequestContext(); |
| 339 file_thread_.Stop(); | 338 file_thread_.Stop(); |
| 340 ChromeRenderViewHostTestHarness::TearDown(); | 339 ChromeRenderViewHostTestHarness::TearDown(); |
| 341 io_thread_.Stop(); | 340 io_thread_.Stop(); |
| 342 } | 341 } |
| 343 | 342 |
| 344 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( | 343 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( |
| 345 MockAutofillMetrics* metric_logger, | 344 MockAutofillMetrics* metric_logger) { |
| 346 CreditCard** created_card) { | |
| 347 EXPECT_CALL(*metric_logger, | 345 EXPECT_CALL(*metric_logger, |
| 348 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 346 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
| 349 // The delegate created below will take ownership of this object. | 347 |
| 350 CreditCard* credit_card = new CreditCard(); | 348 CreditCard credit_card; |
| 351 if (created_card) | 349 return AutofillCCInfoBarDelegate::CreateForTesting( |
| 352 *created_card = credit_card; | 350 metric_logger, |
| 353 return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_, | 351 base::Bind(&TestPersonalDataManager::SaveImportedCreditCard, |
| 354 metric_logger); | 352 base::Unretained(&personal_data_), credit_card)); |
| 355 } | 353 } |
| 356 | 354 |
| 357 // Test that we log quality metrics appropriately. | 355 // Test that we log quality metrics appropriately. |
| 358 TEST_F(AutofillMetricsTest, QualityMetrics) { | 356 TEST_F(AutofillMetricsTest, QualityMetrics) { |
| 359 // Set up our form data. | 357 // Set up our form data. |
| 360 FormData form; | 358 FormData form; |
| 361 form.name = ASCIIToUTF16("TestForm"); | 359 form.name = ASCIIToUTF16("TestForm"); |
| 362 form.method = ASCIIToUTF16("POST"); | 360 form.method = ASCIIToUTF16("POST"); |
| 363 form.origin = GURL("http://example.com/form.html"); | 361 form.origin = GURL("http://example.com/form.html"); |
| 364 form.action = GURL("http://example.com/submit.html"); | 362 form.action = GURL("http://example.com/submit.html"); |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); | 1140 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); |
| 1143 } | 1141 } |
| 1144 | 1142 |
| 1145 // Test that credit card infobar metrics are logged correctly. | 1143 // Test that credit card infobar metrics are logged correctly. |
| 1146 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { | 1144 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { |
| 1147 MockAutofillMetrics metric_logger; | 1145 MockAutofillMetrics metric_logger; |
| 1148 ::testing::InSequence dummy; | 1146 ::testing::InSequence dummy; |
| 1149 | 1147 |
| 1150 // Accept the infobar. | 1148 // Accept the infobar. |
| 1151 { | 1149 { |
| 1152 CreditCard* credit_card; | 1150 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); |
| 1153 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, | |
| 1154 &credit_card)); | |
| 1155 ASSERT_TRUE(infobar); | 1151 ASSERT_TRUE(infobar); |
| 1156 EXPECT_CALL(personal_data_, SaveImportedCreditCard(*credit_card)); | 1152 EXPECT_CALL(personal_data_, SaveImportedCreditCard(_)); |
| 1157 EXPECT_CALL(metric_logger, | 1153 EXPECT_CALL(metric_logger, |
| 1158 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); | 1154 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); |
| 1159 EXPECT_CALL(metric_logger, | 1155 EXPECT_CALL(metric_logger, |
| 1160 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); | 1156 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 1161 EXPECT_TRUE(infobar->Accept()); | 1157 EXPECT_TRUE(infobar->Accept()); |
| 1162 } | 1158 } |
| 1163 | 1159 |
| 1164 // Cancel the infobar. | 1160 // Cancel the infobar. |
| 1165 { | 1161 { |
| 1166 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, | 1162 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); |
| 1167 NULL)); | |
| 1168 ASSERT_TRUE(infobar); | 1163 ASSERT_TRUE(infobar); |
| 1169 EXPECT_CALL(metric_logger, | 1164 EXPECT_CALL(metric_logger, |
| 1170 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1); | 1165 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1); |
| 1171 EXPECT_CALL(metric_logger, | 1166 EXPECT_CALL(metric_logger, |
| 1172 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); | 1167 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 1173 EXPECT_TRUE(infobar->Cancel()); | 1168 EXPECT_TRUE(infobar->Cancel()); |
| 1174 } | 1169 } |
| 1175 | 1170 |
| 1176 // Dismiss the infobar. | 1171 // Dismiss the infobar. |
| 1177 { | 1172 { |
| 1178 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, | 1173 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); |
| 1179 NULL)); | |
| 1180 ASSERT_TRUE(infobar); | 1174 ASSERT_TRUE(infobar); |
| 1181 EXPECT_CALL(metric_logger, | 1175 EXPECT_CALL(metric_logger, |
| 1182 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1); | 1176 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1); |
| 1183 EXPECT_CALL(metric_logger, | 1177 EXPECT_CALL(metric_logger, |
| 1184 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); | 1178 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 1185 infobar->InfoBarDismissed(); | 1179 infobar->InfoBarDismissed(); |
| 1186 } | 1180 } |
| 1187 | 1181 |
| 1188 // Ignore the infobar. | 1182 // Ignore the infobar. |
| 1189 { | 1183 { |
| 1190 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, | 1184 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger)); |
| 1191 NULL)); | |
| 1192 ASSERT_TRUE(infobar); | 1185 ASSERT_TRUE(infobar); |
| 1193 EXPECT_CALL(metric_logger, | 1186 EXPECT_CALL(metric_logger, |
| 1194 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1); | 1187 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1); |
| 1195 } | 1188 } |
| 1196 } | 1189 } |
| 1197 | 1190 |
| 1198 // Test that server query response experiment id metrics are logged correctly. | 1191 // Test that server query response experiment id metrics are logged correctly. |
| 1199 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { | 1192 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { |
| 1200 MockAutofillMetrics metric_logger; | 1193 MockAutofillMetrics metric_logger; |
| 1201 ::testing::InSequence dummy; | 1194 ::testing::InSequence dummy; |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1576 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); | 1569 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); |
| 1577 autofill_manager_->OnDidFillAutofillFormData( | 1570 autofill_manager_->OnDidFillAutofillFormData( |
| 1578 TimeTicks::FromInternalValue(5)); | 1571 TimeTicks::FromInternalValue(5)); |
| 1579 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1572 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 1580 TimeTicks::FromInternalValue(3)); | 1573 TimeTicks::FromInternalValue(3)); |
| 1581 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1574 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
| 1582 autofill_manager_->Reset(); | 1575 autofill_manager_->Reset(); |
| 1583 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1576 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
| 1584 } | 1577 } |
| 1585 } | 1578 } |
| OLD | NEW |