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, user_action_tester.GetActionCount("Autofill_FormSubmitted")); | |
1558 } | |
1559 } | |
1560 | |
1561 // Test that the profile checkout flow user actions are correctly logged. | |
1562 TEST_F(AutofillMetricsTest, ProfileCheckoutFlowUserActions) { | |
1563 // Create profiles. | |
1564 personal_data_->RecreateProfiles(true /* include_local_profile */, | |
1565 false /* include_server_profile */); | |
1566 | |
1567 // Set up our form data. | |
1568 FormData form; | |
1569 form.name = ASCIIToUTF16("TestForm"); | |
1570 form.origin = GURL("http://example.com/form.html"); | |
1571 form.action = GURL("http://example.com/submit.html"); | |
1572 | |
1573 FormFieldData field; | |
1574 std::vector<ServerFieldType> field_types; | |
1575 test::CreateTestFormField("State", "state", "", "text", &field); | |
1576 form.fields.push_back(field); | |
1577 field_types.push_back(ADDRESS_HOME_STATE); | |
1578 test::CreateTestFormField("City", "city", "", "text", &field); | |
1579 form.fields.push_back(field); | |
1580 field_types.push_back(ADDRESS_HOME_CITY); | |
1581 test::CreateTestFormField("Street", "street", "", "text", &field); | |
1582 form.fields.push_back(field); | |
1583 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS); | |
1584 | |
1585 // Simulate having seen this form on page load. | |
1586 // |form_structure| will be owned by |autofill_manager_|. | |
1587 autofill_manager_->AddSeenForm(form, field_types, field_types); | |
1588 | |
1589 // Simulate an Autofill query on a profile field. | |
1590 { | |
1591 base::UserActionTester user_action_tester; | |
1592 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | |
1593 EXPECT_EQ(1, user_action_tester.GetActionCount( | |
1594 "Autofill_PolledProfileSuggestions")); | |
1595 } | |
1596 | |
1597 // Simulate showing a profile suggestion. | |
1598 { | |
1599 base::UserActionTester user_action_tester; | |
1600 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field); | |
1601 EXPECT_EQ(1, user_action_tester.GetActionCount( | |
1602 "Autofill_ShowedProfileSuggestions")); | |
1603 } | |
1604 | |
1605 // Simulate selecting a profile suggestions. | |
1606 { | |
1607 base::UserActionTester user_action_tester; | |
1608 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. | |
1609 external_delegate_->DidAcceptSuggestion( | |
1610 ASCIIToUTF16("Test"), | |
1611 autofill_manager_->MakeFrontendID(guid, std::string()), 0); | |
1612 EXPECT_EQ(1, | |
1613 user_action_tester.GetActionCount("Autofill_SelectedSuggestion")); | |
1614 } | |
1615 | |
1616 // Simulate filling a profile suggestion. | |
1617 { | |
1618 base::UserActionTester user_action_tester; | |
1619 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile. | |
1620 autofill_manager_->FillOrPreviewForm( | |
1621 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(), | |
1622 autofill_manager_->MakeFrontendID(std::string(), guid)); | |
1623 EXPECT_EQ(1, user_action_tester.GetActionCount( | |
1624 "Autofill_FilledProfileSuggestion")); | |
1625 } | |
1626 | |
1627 // Simulate submitting the profile form. | |
1628 { | |
1629 base::UserActionTester user_action_tester; | |
1630 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF()); | |
1631 autofill_manager_->SubmitForm(form, TimeTicks::Now()); | |
1632 EXPECT_EQ(1, user_action_tester.GetActionCount("Autofill_FormSubmitted")); | |
Mathieu
2016/04/11 16:45:46
if you also log OnWillSubmitForm it's ok to check
sebsg
2016/04/12 14:40:59
Done.
| |
1633 } | |
1634 } | |
1635 | |
1484 // Test that we log interacted form event for credit cards related. | 1636 // Test that we log interacted form event for credit cards related. |
1485 TEST_F(AutofillMetricsTest, CreditCardInteractedFormEvents) { | 1637 TEST_F(AutofillMetricsTest, CreditCardInteractedFormEvents) { |
1486 // Set up our form data. | 1638 // Set up our form data. |
1487 FormData form; | 1639 FormData form; |
1488 form.name = ASCIIToUTF16("TestForm"); | 1640 form.name = ASCIIToUTF16("TestForm"); |
1489 form.origin = GURL("http://example.com/form.html"); | 1641 form.origin = GURL("http://example.com/form.html"); |
1490 form.action = GURL("http://example.com/submit.html"); | 1642 form.action = GURL("http://example.com/submit.html"); |
1491 | 1643 |
1492 FormFieldData field; | 1644 FormFieldData field; |
1493 std::vector<ServerFieldType> field_types; | 1645 std::vector<ServerFieldType> field_types; |
(...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3609 EXPECT_THAT( | 3761 EXPECT_THAT( |
3610 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), | 3762 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), |
3611 ElementsAre(Bucket(true, 2))); | 3763 ElementsAre(Bucket(true, 2))); |
3612 | 3764 |
3613 // No RAPPOR metrics are logged in the case there is at least some server data | 3765 // No RAPPOR metrics are logged in the case there is at least some server data |
3614 // available for all forms. | 3766 // available for all forms. |
3615 EXPECT_EQ(0, rappor_service_.GetReportsCount()); | 3767 EXPECT_EQ(0, rappor_service_.GetReportsCount()); |
3616 } | 3768 } |
3617 | 3769 |
3618 } // namespace autofill | 3770 } // namespace autofill |
OLD | NEW |