OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_metrics.h" | 5 #include "components/autofill/core/browser/autofill_metrics.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/test/histogram_tester.h" | 16 #include "base/test/histogram_tester.h" |
| 17 #include "base/test/user_action_tester.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "components/autofill/core/browser/autofill_external_delegate.h" | 19 #include "components/autofill/core/browser/autofill_external_delegate.h" |
19 #include "components/autofill/core/browser/autofill_manager.h" | 20 #include "components/autofill/core/browser/autofill_manager.h" |
20 #include "components/autofill/core/browser/autofill_test_utils.h" | 21 #include "components/autofill/core/browser/autofill_test_utils.h" |
21 #include "components/autofill/core/browser/payments/payments_client.h" | 22 #include "components/autofill/core/browser/payments/payments_client.h" |
22 #include "components/autofill/core/browser/personal_data_manager.h" | 23 #include "components/autofill/core/browser/personal_data_manager.h" |
23 #include "components/autofill/core/browser/test_autofill_client.h" | 24 #include "components/autofill/core/browser/test_autofill_client.h" |
24 #include "components/autofill/core/browser/test_autofill_driver.h" | 25 #include "components/autofill/core/browser/test_autofill_driver.h" |
25 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 26 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
26 #include "components/autofill/core/common/form_data.h" | 27 #include "components/autofill/core/common/form_data.h" |
(...skipping 1447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 | 1475 |
1475 { | 1476 { |
1476 // Simulate activating the autofill popup for the email field after typing. | 1477 // Simulate activating the autofill popup for the email field after typing. |
1477 form.fields[0].is_autofilled = true; | 1478 form.fields[0].is_autofilled = true; |
1478 base::HistogramTester histogram_tester; | 1479 base::HistogramTester histogram_tester; |
1479 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | 1480 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
1480 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); | 1481 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0); |
1481 } | 1482 } |
1482 } | 1483 } |
1483 | 1484 |
| 1485 // Test that the credit card checkout flow user actions are correctly logged. |
| 1486 TEST_F(AutofillMetricsTest, CreditCardCheckoutFlowUserActions) { |
| 1487 personal_data_->RecreateCreditCards( |
| 1488 true /* include_local_credit_card */, |
| 1489 false /* include_masked_server_credit_card */, |
| 1490 false /* include_full_server_credit_card */); |
| 1491 |
| 1492 // Set up our form data. |
| 1493 FormData form; |
| 1494 form.name = ASCIIToUTF16("TestForm"); |
| 1495 form.origin = GURL("http://example.com/form.html"); |
| 1496 form.action = GURL("http://example.com/submit.html"); |
| 1497 |
| 1498 FormFieldData field; |
| 1499 std::vector<ServerFieldType> field_types; |
| 1500 test::CreateTestFormField("Name on card", "cc-name", "", "text", &field); |
| 1501 form.fields.push_back(field); |
| 1502 field_types.push_back(CREDIT_CARD_NAME_FULL); |
| 1503 test::CreateTestFormField("Credit card", "card", "", "text", &field); |
| 1504 form.fields.push_back(field); |
| 1505 field_types.push_back(CREDIT_CARD_NUMBER); |
| 1506 test::CreateTestFormField("Month", "card_month", "", "text", &field); |
| 1507 form.fields.push_back(field); |
| 1508 field_types.push_back(CREDIT_CARD_EXP_MONTH); |
| 1509 |
| 1510 // Simulate having seen this form on page load. |
| 1511 // |form_structure| will be owned by |autofill_manager_|. |
| 1512 autofill_manager_->AddSeenForm(form, field_types, field_types); |
| 1513 |
| 1514 // Simulate an Autofill query on a credit card field. |
| 1515 { |
| 1516 base::UserActionTester user_action_tester; |
| 1517 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| 1518 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 1519 "Autofill_PolledCreditCardSuggestions")); |
| 1520 } |
| 1521 |
| 1522 // Simulate showing a credit card suggestion. |
| 1523 { |
| 1524 base::UserActionTester user_action_tester; |
| 1525 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
| 1526 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 1527 "Autofill_ShowedCreditCardSuggestions")); |
| 1528 } |
| 1529 |
| 1530 // Simulate selecting a credit card suggestions. |
| 1531 { |
| 1532 base::UserActionTester user_action_tester; |
| 1533 std::string guid("10000000-0000-0000-0000-000000000001"); // local card |
| 1534 external_delegate_->DidAcceptSuggestion( |
| 1535 ASCIIToUTF16("Test"), |
| 1536 autofill_manager_->MakeFrontendID(guid, std::string()), 0); |
| 1537 EXPECT_EQ(1, |
| 1538 user_action_tester.GetActionCount("Autofill_SelectedSuggestion")); |
| 1539 } |
| 1540 |
| 1541 // Simulate filling a credit card suggestion. |
| 1542 { |
| 1543 base::UserActionTester user_action_tester; |
| 1544 std::string guid("10000000-0000-0000-0000-000000000001"); // local card |
| 1545 autofill_manager_->FillOrPreviewForm( |
| 1546 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), |
| 1547 autofill_manager_->MakeFrontendID(guid, std::string())); |
| 1548 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 1549 "Autofill_FilledCreditCardSuggestion")); |
| 1550 } |
| 1551 |
| 1552 // Simulate submitting the credit card form. |
| 1553 { |
| 1554 base::UserActionTester user_action_tester; |
| 1555 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| 1556 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 1557 EXPECT_EQ(1, |
| 1558 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); |
| 1559 EXPECT_EQ(1, user_action_tester.GetActionCount("Autofill_FormSubmitted")); |
| 1560 } |
| 1561 } |
| 1562 |
| 1563 // Test that the profile checkout flow user actions are correctly logged. |
| 1564 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { |
| 1565 // Create profiles. |
| 1566 personal_data_->RecreateProfiles(true /* include_local_profile */, |
| 1567 false /* include_server_profile */); |
| 1568 |
| 1569 // Set up our form data. |
| 1570 FormData form; |
| 1571 form.name = ASCIIToUTF16("TestForm"); |
| 1572 form.origin = GURL("http://example.com/form.html"); |
| 1573 form.action = GURL("http://example.com/submit.html"); |
| 1574 |
| 1575 FormFieldData field; |
| 1576 std::vector<ServerFieldType> field_types; |
| 1577 test::CreateTestFormField("State", "state", "", "text", &field); |
| 1578 form.fields.push_back(field); |
| 1579 field_types.push_back(ADDRESS_HOME_STATE); |
| 1580 test::CreateTestFormField("City", "city", "", "text", &field); |
| 1581 form.fields.push_back(field); |
| 1582 field_types.push_back(ADDRESS_HOME_CITY); |
| 1583 test::CreateTestFormField("Street", "street", "", "text", &field); |
| 1584 form.fields.push_back(field); |
| 1585 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS); |
| 1586 |
| 1587 // Simulate having seen this form on page load. |
| 1588 // |form_structure| will be owned by |autofill_manager_|. |
| 1589 autofill_manager_->AddSeenForm(form, field_types, field_types); |
| 1590 |
| 1591 // Simulate an Autofill query on a profile field. |
| 1592 { |
| 1593 base::UserActionTester user_action_tester; |
| 1594 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| 1595 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 1596 "Autofill_PolledProfileSuggestions")); |
| 1597 } |
| 1598 |
| 1599 // Simulate showing a profile suggestion. |
| 1600 { |
| 1601 base::UserActionTester user_action_tester; |
| 1602 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); |
| 1603 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 1604 "Autofill_ShowedProfileSuggestions")); |
| 1605 } |
| 1606 |
| 1607 // Simulate selecting a profile suggestions. |
| 1608 { |
| 1609 base::UserActionTester user_action_tester; |
| 1610 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. |
| 1611 external_delegate_->DidAcceptSuggestion( |
| 1612 ASCIIToUTF16("Test"), |
| 1613 autofill_manager_->MakeFrontendID(guid, std::string()), 0); |
| 1614 EXPECT_EQ(1, |
| 1615 user_action_tester.GetActionCount("Autofill_SelectedSuggestion")); |
| 1616 } |
| 1617 |
| 1618 // Simulate filling a profile suggestion. |
| 1619 { |
| 1620 base::UserActionTester user_action_tester; |
| 1621 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. |
| 1622 autofill_manager_->FillOrPreviewForm( |
| 1623 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), |
| 1624 autofill_manager_->MakeFrontendID(std::string(), guid)); |
| 1625 EXPECT_EQ(1, user_action_tester.GetActionCount( |
| 1626 "Autofill_FilledProfileSuggestion")); |
| 1627 } |
| 1628 |
| 1629 // Simulate submitting the profile form. |
| 1630 { |
| 1631 base::UserActionTester user_action_tester; |
| 1632 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); |
| 1633 autofill_manager_->SubmitForm(form, TimeTicks::Now()); |
| 1634 EXPECT_EQ(1, |
| 1635 user_action_tester.GetActionCount("Autofill_OnWillSubmitForm")); |
| 1636 EXPECT_EQ(1, user_action_tester.GetActionCount("Autofill_FormSubmitted")); |
| 1637 } |
| 1638 } |
| 1639 |
1484 // Test that we log interacted form event for credit cards related. | 1640 // Test that we log interacted form event for credit cards related. |
1485 TEST_F(AutofillMetricsTest, CreditCardInteractedFormEvents) { | 1641 TEST_F(AutofillMetricsTest, CreditCardInteractedFormEvents) { |
1486 // Set up our form data. | 1642 // Set up our form data. |
1487 FormData form; | 1643 FormData form; |
1488 form.name = ASCIIToUTF16("TestForm"); | 1644 form.name = ASCIIToUTF16("TestForm"); |
1489 form.origin = GURL("http://example.com/form.html"); | 1645 form.origin = GURL("http://example.com/form.html"); |
1490 form.action = GURL("http://example.com/submit.html"); | 1646 form.action = GURL("http://example.com/submit.html"); |
1491 | 1647 |
1492 FormFieldData field; | 1648 FormFieldData field; |
1493 std::vector<ServerFieldType> field_types; | 1649 std::vector<ServerFieldType> field_types; |
(...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3609 EXPECT_THAT( | 3765 EXPECT_THAT( |
3610 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 3766 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
3611 ElementsAre(Bucket(true, 2))); | 3767 ElementsAre(Bucket(true, 2))); |
3612 | 3768 |
3613 // No RAPPOR metrics are logged in the case there is at least some server data | 3769 // No RAPPOR metrics are logged in the case there is at least some server data |
3614 // available for all forms. | 3770 // available for all forms. |
3615 EXPECT_EQ(0, rappor_service_.GetReportsCount()); | 3771 EXPECT_EQ(0, rappor_service_.GetReportsCount()); |
3616 } | 3772 } |
3617 | 3773 |
3618 } // namespace autofill | 3774 } // namespace autofill |
OLD | NEW |