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" |
| 11 #include "chrome/browser/autofill/autocheckout_infobar_delegate.h" |
11 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
12 #include "chrome/browser/autofill/autofill_common_test.h" | 13 #include "chrome/browser/autofill/autofill_common_test.h" |
13 #include "chrome/browser/autofill/autofill_manager.h" | 14 #include "chrome/browser/autofill/autofill_manager.h" |
14 #include "chrome/browser/autofill/autofill_manager_delegate.h" | 15 #include "chrome/browser/autofill/autofill_manager_delegate.h" |
15 #include "chrome/browser/autofill/autofill_metrics.h" | 16 #include "chrome/browser/autofill/autofill_metrics.h" |
16 #include "chrome/browser/autofill/personal_data_manager.h" | 17 #include "chrome/browser/autofill/personal_data_manager.h" |
17 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 18 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
18 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" | 19 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" |
19 #include "chrome/browser/webdata/web_data_service.h" | 20 #include "chrome/browser/webdata/web_data_service.h" |
20 #include "chrome/common/form_data.h" | 21 #include "chrome/common/form_data.h" |
21 #include "chrome/common/form_field_data.h" | 22 #include "chrome/common/form_field_data.h" |
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
23 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
24 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
| 26 #include "googleurl/src/gurl.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
27 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
28 | 30 |
29 using content::BrowserThread; | 31 using content::BrowserThread; |
30 using ::testing::_; | 32 using ::testing::_; |
31 using ::testing::AnyNumber; | 33 using ::testing::AnyNumber; |
32 using ::testing::Mock; | 34 using ::testing::Mock; |
33 using base::TimeTicks; | 35 using base::TimeTicks; |
34 using base::TimeDelta; | 36 using base::TimeDelta; |
35 | 37 |
36 namespace { | 38 namespace { |
37 | 39 |
38 class MockAutofillMetrics : public AutofillMetrics { | 40 class MockAutofillMetrics : public AutofillMetrics { |
39 public: | 41 public: |
40 MockAutofillMetrics() {} | 42 MockAutofillMetrics() {} |
41 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); | 43 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); |
| 44 MOCK_CONST_METHOD1(LogAutocheckoutInfoBarMetric, void(InfoBarMetric metric)); |
42 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, | 45 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, |
43 void(DeveloperEngagementMetric metric)); | 46 void(DeveloperEngagementMetric metric)); |
44 MOCK_CONST_METHOD3(LogHeuristicTypePrediction, | 47 MOCK_CONST_METHOD3(LogHeuristicTypePrediction, |
45 void(FieldTypeQualityMetric metric, | 48 void(FieldTypeQualityMetric metric, |
46 AutofillFieldType field_type, | 49 AutofillFieldType field_type, |
47 const std::string& experiment_id)); | 50 const std::string& experiment_id)); |
48 MOCK_CONST_METHOD3(LogOverallTypePrediction, | 51 MOCK_CONST_METHOD3(LogOverallTypePrediction, |
49 void(FieldTypeQualityMetric metric, | 52 void(FieldTypeQualityMetric metric, |
50 AutofillFieldType field_type, | 53 AutofillFieldType field_type, |
51 const std::string& experiment_id)); | 54 const std::string& experiment_id)); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 if (!did_finish_async_form_submit_) { | 224 if (!did_finish_async_form_submit_) { |
222 // TODO(isherman): It seems silly to need this variable. Is there some | 225 // TODO(isherman): It seems silly to need this variable. Is there some |
223 // way I can just query the message loop's state? | 226 // way I can just query the message loop's state? |
224 message_loop_is_running_ = true; | 227 message_loop_is_running_ = true; |
225 MessageLoop::current()->Run(); | 228 MessageLoop::current()->Run(); |
226 } else { | 229 } else { |
227 did_finish_async_form_submit_ = false; | 230 did_finish_async_form_submit_ = false; |
228 } | 231 } |
229 } | 232 } |
230 | 233 |
| 234 virtual void ShowAutocheckoutDialog( |
| 235 const FormData& form, |
| 236 const GURL& frame_url, |
| 237 const content::SSLStatus& ssl_status) OVERRIDE { |
| 238 // no-op. Just used as callback from autocheckout_infobar_delegate. |
| 239 } |
| 240 |
231 virtual void UploadFormDataAsyncCallback( | 241 virtual void UploadFormDataAsyncCallback( |
232 const FormStructure* submitted_form, | 242 const FormStructure* submitted_form, |
233 const base::TimeTicks& load_time, | 243 const base::TimeTicks& load_time, |
234 const base::TimeTicks& interaction_time, | 244 const base::TimeTicks& interaction_time, |
235 const base::TimeTicks& submission_time) OVERRIDE { | 245 const base::TimeTicks& submission_time) OVERRIDE { |
236 if (message_loop_is_running_) { | 246 if (message_loop_is_running_) { |
237 MessageLoop::current()->Quit(); | 247 MessageLoop::current()->Quit(); |
238 message_loop_is_running_ = false; | 248 message_loop_is_running_ = false; |
239 } else { | 249 } else { |
240 did_finish_async_form_submit_ = true; | 250 did_finish_async_form_submit_ = true; |
(...skipping 24 matching lines...) Expand all Loading... |
265 virtual ~AutofillMetricsTest(); | 275 virtual ~AutofillMetricsTest(); |
266 | 276 |
267 virtual void SetUp() OVERRIDE; | 277 virtual void SetUp() OVERRIDE; |
268 virtual void TearDown() OVERRIDE; | 278 virtual void TearDown() OVERRIDE; |
269 | 279 |
270 protected: | 280 protected: |
271 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( | 281 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( |
272 MockAutofillMetrics* metric_logger, | 282 MockAutofillMetrics* metric_logger, |
273 CreditCard** created_card); | 283 CreditCard** created_card); |
274 | 284 |
| 285 scoped_ptr<ConfirmInfoBarDelegate> CreateAutocheckoutDelegate( |
| 286 MockAutofillMetrics* metric_logger); |
| 287 |
275 content::TestBrowserThread ui_thread_; | 288 content::TestBrowserThread ui_thread_; |
276 content::TestBrowserThread file_thread_; | 289 content::TestBrowserThread file_thread_; |
277 | 290 |
278 scoped_refptr<TestAutofillManager> autofill_manager_; | 291 scoped_refptr<TestAutofillManager> autofill_manager_; |
279 TestPersonalDataManager personal_data_; | 292 TestPersonalDataManager personal_data_; |
280 | 293 |
281 private: | 294 private: |
282 std::string default_gmock_verbosity_level_; | 295 std::string default_gmock_verbosity_level_; |
283 | 296 |
284 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); | 297 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 EXPECT_CALL(*metric_logger, | 353 EXPECT_CALL(*metric_logger, |
341 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 354 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
342 // The delegate created below will take ownership of this object. | 355 // The delegate created below will take ownership of this object. |
343 CreditCard* credit_card = new CreditCard(); | 356 CreditCard* credit_card = new CreditCard(); |
344 if (created_card) | 357 if (created_card) |
345 *created_card = credit_card; | 358 *created_card = credit_card; |
346 return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_, | 359 return AutofillCCInfoBarDelegate::Create(credit_card, &personal_data_, |
347 metric_logger); | 360 metric_logger); |
348 } | 361 } |
349 | 362 |
| 363 scoped_ptr<ConfirmInfoBarDelegate> |
| 364 AutofillMetricsTest::CreateAutocheckoutDelegate( |
| 365 MockAutofillMetrics* metric_logger) { |
| 366 EXPECT_CALL(*metric_logger, |
| 367 LogAutocheckoutInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
| 368 GURL url("www.google.com"); |
| 369 content::SSLStatus ssl_status; |
| 370 return AutocheckoutInfoBarDelegate::Create(metric_logger, |
| 371 url, |
| 372 ssl_status, |
| 373 autofill_manager_.get()); |
| 374 } |
| 375 |
350 // Test that we log quality metrics appropriately. | 376 // Test that we log quality metrics appropriately. |
351 TEST_F(AutofillMetricsTest, QualityMetrics) { | 377 TEST_F(AutofillMetricsTest, QualityMetrics) { |
352 // Set up our form data. | 378 // Set up our form data. |
353 FormData form; | 379 FormData form; |
354 form.name = ASCIIToUTF16("TestForm"); | 380 form.name = ASCIIToUTF16("TestForm"); |
355 form.method = ASCIIToUTF16("POST"); | 381 form.method = ASCIIToUTF16("POST"); |
356 form.origin = GURL("http://example.com/form.html"); | 382 form.origin = GURL("http://example.com/form.html"); |
357 form.action = GURL("http://example.com/submit.html"); | 383 form.action = GURL("http://example.com/submit.html"); |
358 form.user_submitted = true; | 384 form.user_submitted = true; |
359 | 385 |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 // Ignore the infobar. | 1205 // Ignore the infobar. |
1180 { | 1206 { |
1181 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, | 1207 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger, |
1182 NULL)); | 1208 NULL)); |
1183 ASSERT_TRUE(infobar); | 1209 ASSERT_TRUE(infobar); |
1184 EXPECT_CALL(metric_logger, | 1210 EXPECT_CALL(metric_logger, |
1185 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1); | 1211 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1); |
1186 } | 1212 } |
1187 } | 1213 } |
1188 | 1214 |
| 1215 // Test that autofill flow infobar metrics are logged correctly. |
| 1216 TEST_F(AutofillMetricsTest, AutocheckoutInfoBar) { |
| 1217 MockAutofillMetrics metric_logger; |
| 1218 ::testing::InSequence dummy; |
| 1219 |
| 1220 // Accept the infobar. |
| 1221 { |
| 1222 scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| 1223 CreateAutocheckoutDelegate(&metric_logger)); |
| 1224 ASSERT_TRUE(infobar); |
| 1225 EXPECT_CALL(metric_logger, |
| 1226 LogAutocheckoutInfoBarMetric( |
| 1227 AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); |
| 1228 EXPECT_CALL(metric_logger, |
| 1229 LogAutocheckoutInfoBarMetric( |
| 1230 AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 1231 EXPECT_TRUE(infobar->Accept()); |
| 1232 } |
| 1233 |
| 1234 // Cancel the infobar. |
| 1235 { |
| 1236 scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| 1237 CreateAutocheckoutDelegate(&metric_logger)); |
| 1238 ASSERT_TRUE(infobar); |
| 1239 EXPECT_CALL(metric_logger, |
| 1240 LogAutocheckoutInfoBarMetric( |
| 1241 AutofillMetrics::INFOBAR_DENIED)).Times(1); |
| 1242 EXPECT_CALL(metric_logger, |
| 1243 LogAutocheckoutInfoBarMetric( |
| 1244 AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 1245 EXPECT_TRUE(infobar->Cancel()); |
| 1246 } |
| 1247 |
| 1248 // Dismiss the infobar. |
| 1249 { |
| 1250 scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| 1251 CreateAutocheckoutDelegate(&metric_logger)); |
| 1252 ASSERT_TRUE(infobar); |
| 1253 EXPECT_CALL(metric_logger, |
| 1254 LogAutocheckoutInfoBarMetric( |
| 1255 AutofillMetrics::INFOBAR_DENIED)).Times(1); |
| 1256 EXPECT_CALL(metric_logger, |
| 1257 LogAutocheckoutInfoBarMetric( |
| 1258 AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 1259 infobar->InfoBarDismissed(); |
| 1260 } |
| 1261 |
| 1262 // Ignore the infobar. |
| 1263 { |
| 1264 scoped_ptr<ConfirmInfoBarDelegate> infobar( |
| 1265 CreateAutocheckoutDelegate(&metric_logger)); |
| 1266 ASSERT_TRUE(infobar); |
| 1267 EXPECT_CALL(metric_logger, |
| 1268 LogAutocheckoutInfoBarMetric( |
| 1269 AutofillMetrics::INFOBAR_IGNORED)).Times(1); |
| 1270 } |
| 1271 } |
| 1272 |
| 1273 |
1189 // Test that server query response experiment id metrics are logged correctly. | 1274 // Test that server query response experiment id metrics are logged correctly. |
1190 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { | 1275 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) { |
1191 MockAutofillMetrics metric_logger; | 1276 MockAutofillMetrics metric_logger; |
1192 ::testing::InSequence dummy; | 1277 ::testing::InSequence dummy; |
1193 | 1278 |
1194 // No experiment specified. | 1279 // No experiment specified. |
1195 EXPECT_CALL(metric_logger, | 1280 EXPECT_CALL(metric_logger, |
1196 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); | 1281 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); |
1197 EXPECT_CALL(metric_logger, | 1282 EXPECT_CALL(metric_logger, |
1198 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED)); | 1283 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED)); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); | 1647 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); |
1563 autofill_manager_->OnDidFillAutofillFormData( | 1648 autofill_manager_->OnDidFillAutofillFormData( |
1564 TimeTicks::FromInternalValue(5)); | 1649 TimeTicks::FromInternalValue(5)); |
1565 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1650 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
1566 TimeTicks::FromInternalValue(3)); | 1651 TimeTicks::FromInternalValue(3)); |
1567 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1652 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
1568 autofill_manager_->Reset(); | 1653 autofill_manager_->Reset(); |
1569 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1654 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
1570 } | 1655 } |
1571 } | 1656 } |
OLD | NEW |