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
3 // found in the LICENSE file.
5 #include "components/autofill/core/browser/autofill_metrics.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/run_loop.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "base/test/histogram_tester.h"
15 #include "base/time/time.h"
16 #include "components/autofill/core/browser/autofill_external_delegate.h"
17 #include "components/autofill/core/browser/autofill_manager.h"
18 #include "components/autofill/core/browser/autofill_test_utils.h"
19 #include "components/autofill/core/browser/personal_data_manager.h"
20 #include "components/autofill/core/browser/test_autofill_client.h"
21 #include "components/autofill/core/browser/test_autofill_driver.h"
22 #include "components/autofill/core/browser/wallet/real_pan_wallet_client.h"
23 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
24 #include "components/autofill/core/common/autofill_pref_names.h"
25 #include "components/autofill/core/common/form_data.h"
26 #include "components/autofill/core/common/form_field_data.h"
27 #include "components/rappor/test_rappor_service.h"
28 #include "components/signin/core/browser/account_tracker_service.h"
29 #include "components/signin/core/browser/test_signin_client.h"
30 #include "components/signin/core/common/signin_pref_names.h"
31 #include "components/webdata/common/web_data_results.h"
32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "ui/gfx/geometry/rect.h"
36 using base::ASCIIToUTF16
;
37 using base::TimeTicks
;
42 class TestPersonalDataManager
: public PersonalDataManager
{
44 TestPersonalDataManager()
45 : PersonalDataManager("en-US"),
46 autofill_enabled_(true) {
47 CreateTestAutofillProfiles(&web_profiles_
);
50 using PersonalDataManager::set_account_tracker
;
51 using PersonalDataManager::set_database
;
52 using PersonalDataManager::SetPrefService
;
54 // Overridden to avoid a trip to the database. This should be a no-op except
55 // for the side-effect of logging the profile count.
56 void LoadProfiles() override
{
58 std::vector
<AutofillProfile
*> profiles
;
59 web_profiles_
.release(&profiles
);
60 WDResult
<std::vector
<AutofillProfile
*> > result(AUTOFILL_PROFILES_RESULT
,
62 pending_profiles_query_
= 123;
63 OnWebDataServiceRequestDone(pending_profiles_query_
, &result
);
66 std::vector
<AutofillProfile
*> profiles
;
67 server_profiles_
.release(&profiles
);
68 WDResult
<std::vector
<AutofillProfile
*> > result(AUTOFILL_PROFILES_RESULT
,
70 pending_server_profiles_query_
= 124;
71 OnWebDataServiceRequestDone(pending_server_profiles_query_
, &result
);
75 // Overridden to avoid a trip to the database.
76 void LoadCreditCards() override
{
78 std::vector
<CreditCard
*> credit_cards
;
79 local_credit_cards_
.release(&credit_cards
);
80 WDResult
<std::vector
<CreditCard
*> > result(
81 AUTOFILL_CREDITCARDS_RESULT
, credit_cards
);
82 pending_creditcards_query_
= 125;
83 OnWebDataServiceRequestDone(pending_creditcards_query_
, &result
);
86 std::vector
<CreditCard
*> credit_cards
;
87 server_credit_cards_
.release(&credit_cards
);
88 WDResult
<std::vector
<CreditCard
*> > result(
89 AUTOFILL_CREDITCARDS_RESULT
, credit_cards
);
90 pending_server_creditcards_query_
= 126;
91 OnWebDataServiceRequestDone(pending_server_creditcards_query_
, &result
);
95 void set_autofill_enabled(bool autofill_enabled
) {
96 autofill_enabled_
= autofill_enabled
;
99 // Removes all existing profiles and creates 0 or 1 local profiles and 0 or 1
100 // server profile according to the paramters.
101 void RecreateProfiles(bool include_local_profile
,
102 bool include_server_profile
) {
103 web_profiles_
.clear();
104 server_profiles_
.clear();
105 if (include_local_profile
) {
106 AutofillProfile
* profile
= new AutofillProfile
;
107 test::SetProfileInfo(profile
, "Elvis", "Aaron",
108 "Presley", "theking@gmail.com", "RCA",
109 "3734 Elvis Presley Blvd.", "Apt. 10",
110 "Memphis", "Tennessee", "38116", "US",
112 profile
->set_guid("00000000-0000-0000-0000-000000000001");
113 web_profiles_
.push_back(profile
);
115 if (include_server_profile
) {
116 AutofillProfile
* profile
= new AutofillProfile(
117 AutofillProfile::SERVER_PROFILE
, "server_id");
118 test::SetProfileInfo(profile
, "Charles", "Hardin",
119 "Holley", "buddy@gmail.com", "Decca",
120 "123 Apple St.", "unit 6", "Lubbock",
121 "Texas", "79401", "US", "2345678901");
122 profile
->set_guid("00000000-0000-0000-0000-000000000002");
123 server_profiles_
.push_back(profile
);
128 // Removes all existing credit cards and creates 0 or 1 local profiles and
129 // 0 or 1 server profile according to the paramters.
130 void RecreateCreditCards(bool include_local_credit_card
,
131 bool include_masked_server_credit_card
,
132 bool include_full_server_credit_card
) {
133 local_credit_cards_
.clear();
134 server_credit_cards_
.clear();
135 if (include_local_credit_card
) {
136 CreditCard
* credit_card
= new CreditCard
;
137 credit_card
->set_guid("10000000-0000-0000-0000-000000000001");
138 local_credit_cards_
.push_back(credit_card
);
140 if (include_masked_server_credit_card
) {
141 CreditCard
* credit_card
= new CreditCard(
142 CreditCard::MASKED_SERVER_CARD
, "server_id");
143 credit_card
->set_guid("10000000-0000-0000-0000-000000000002");
144 credit_card
->SetTypeForMaskedCard(kDiscoverCard
);
145 server_credit_cards_
.push_back(credit_card
);
147 if (include_full_server_credit_card
) {
148 CreditCard
* credit_card
= new CreditCard(
149 CreditCard::FULL_SERVER_CARD
, "server_id");
150 credit_card
->set_guid("10000000-0000-0000-0000-000000000003");
151 server_credit_cards_
.push_back(credit_card
);
156 bool IsAutofillEnabled() const override
{ return autofill_enabled_
; }
159 void CreateTestAutofillProfiles(ScopedVector
<AutofillProfile
>* profiles
) {
160 AutofillProfile
* profile
= new AutofillProfile
;
161 test::SetProfileInfo(profile
, "Elvis", "Aaron",
162 "Presley", "theking@gmail.com", "RCA",
163 "3734 Elvis Presley Blvd.", "Apt. 10",
164 "Memphis", "Tennessee", "38116", "US",
166 profile
->set_guid("00000000-0000-0000-0000-000000000001");
167 profiles
->push_back(profile
);
168 profile
= new AutofillProfile
;
169 test::SetProfileInfo(profile
, "Charles", "Hardin",
170 "Holley", "buddy@gmail.com", "Decca",
171 "123 Apple St.", "unit 6", "Lubbock",
172 "Texas", "79401", "US", "2345678901");
173 profile
->set_guid("00000000-0000-0000-0000-000000000002");
174 profiles
->push_back(profile
);
177 bool autofill_enabled_
;
179 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager
);
182 class TestFormStructure
: public FormStructure
{
184 explicit TestFormStructure(const FormData
& form
) : FormStructure(form
) {}
185 ~TestFormStructure() override
{}
187 void SetFieldTypes(const std::vector
<ServerFieldType
>& heuristic_types
,
188 const std::vector
<ServerFieldType
>& server_types
) {
189 ASSERT_EQ(field_count(), heuristic_types
.size());
190 ASSERT_EQ(field_count(), server_types
.size());
192 for (size_t i
= 0; i
< field_count(); ++i
) {
193 AutofillField
* form_field
= field(i
);
194 ASSERT_TRUE(form_field
);
195 form_field
->set_heuristic_type(heuristic_types
[i
]);
196 form_field
->set_server_type(server_types
[i
]);
199 UpdateAutofillCount();
203 DISALLOW_COPY_AND_ASSIGN(TestFormStructure
);
206 class TestAutofillManager
: public AutofillManager
{
208 TestAutofillManager(AutofillDriver
* driver
,
209 AutofillClient
* autofill_client
,
210 TestPersonalDataManager
* personal_manager
)
211 : AutofillManager(driver
, autofill_client
, personal_manager
),
212 autofill_enabled_(true) {}
213 ~TestAutofillManager() override
{}
215 bool IsAutofillEnabled() const override
{ return autofill_enabled_
; }
217 void set_autofill_enabled(bool autofill_enabled
) {
218 autofill_enabled_
= autofill_enabled
;
221 void AddSeenForm(const FormData
& form
,
222 const std::vector
<ServerFieldType
>& heuristic_types
,
223 const std::vector
<ServerFieldType
>& server_types
) {
224 FormData empty_form
= form
;
225 for (size_t i
= 0; i
< empty_form
.fields
.size(); ++i
) {
226 empty_form
.fields
[i
].value
= base::string16();
229 // |form_structure| will be owned by |form_structures()|.
230 TestFormStructure
* form_structure
= new TestFormStructure(empty_form
);
231 form_structure
->SetFieldTypes(heuristic_types
, server_types
);
232 form_structures()->push_back(form_structure
);
235 // Calls AutofillManager::OnWillSubmitForm and waits for it to complete.
236 void WillSubmitForm(const FormData
& form
, const TimeTicks
& timestamp
) {
237 run_loop_
.reset(new base::RunLoop());
238 if (!OnWillSubmitForm(form
, timestamp
))
241 // Wait for the asynchronous OnWillSubmitForm() call to complete.
245 // Calls both AutofillManager::OnWillSubmitForm and
246 // AutofillManager::OnFormSubmitted.
247 void SubmitForm(const FormData
& form
, const TimeTicks
& timestamp
) {
248 WillSubmitForm(form
, timestamp
);
249 OnFormSubmitted(form
);
252 void UploadFormDataAsyncCallback(
253 const FormStructure
* submitted_form
,
254 const base::TimeTicks
& load_time
,
255 const base::TimeTicks
& interaction_time
,
256 const base::TimeTicks
& submission_time
) override
{
259 AutofillManager::UploadFormDataAsyncCallback(submitted_form
,
266 bool autofill_enabled_
;
267 scoped_ptr
<base::RunLoop
> run_loop_
;
269 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager
);
274 // This is defined in the autofill_metrics.cc implementation file.
275 int GetFieldTypeGroupMetric(ServerFieldType field_type
,
276 AutofillMetrics::FieldTypeQualityMetric metric
);
278 class AutofillMetricsTest
: public testing::Test
{
280 ~AutofillMetricsTest() override
;
282 void SetUp() override
;
283 void TearDown() override
;
286 void EnableWalletSync();
288 base::MessageLoop message_loop_
;
289 TestAutofillClient autofill_client_
;
290 scoped_ptr
<AccountTrackerService
> account_tracker_
;
291 scoped_ptr
<TestSigninClient
> signin_client_
;
292 scoped_ptr
<TestAutofillDriver
> autofill_driver_
;
293 scoped_ptr
<TestAutofillManager
> autofill_manager_
;
294 scoped_ptr
<TestPersonalDataManager
> personal_data_
;
295 scoped_ptr
<AutofillExternalDelegate
> external_delegate_
;
298 AutofillMetricsTest::~AutofillMetricsTest() {
299 // Order of destruction is important as AutofillManager relies on
300 // PersonalDataManager to be around when it gets destroyed.
301 autofill_manager_
.reset();
304 void AutofillMetricsTest::SetUp() {
305 autofill_client_
.SetPrefs(test::PrefServiceForTesting());
307 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
308 test::DisableSystemServices(autofill_client_
.GetPrefs());
310 // Setup account tracker.
311 signin_client_
.reset(new TestSigninClient(autofill_client_
.GetPrefs()));
312 account_tracker_
.reset(new AccountTrackerService());
313 account_tracker_
->Initialize(signin_client_
.get());
315 personal_data_
.reset(new TestPersonalDataManager());
316 personal_data_
->set_database(autofill_client_
.GetDatabase());
317 personal_data_
->SetPrefService(autofill_client_
.GetPrefs());
318 personal_data_
->set_account_tracker(account_tracker_
.get());
319 autofill_driver_
.reset(new TestAutofillDriver());
320 autofill_manager_
.reset(new TestAutofillManager(
321 autofill_driver_
.get(), &autofill_client_
, personal_data_
.get()));
323 external_delegate_
.reset(new AutofillExternalDelegate(
324 autofill_manager_
.get(),
325 autofill_driver_
.get()));
326 autofill_manager_
->SetExternalDelegate(external_delegate_
.get());
329 void AutofillMetricsTest::TearDown() {
330 // Order of destruction is important as AutofillManager relies on
331 // PersonalDataManager to be around when it gets destroyed.
332 autofill_manager_
.reset();
333 autofill_driver_
.reset();
334 personal_data_
.reset();
335 account_tracker_
->Shutdown();
336 account_tracker_
.reset();
337 signin_client_
.reset();
340 void AutofillMetricsTest::EnableWalletSync() {
341 autofill_client_
.GetPrefs()->SetBoolean(
342 prefs::kAutofillWalletSyncExperimentEnabled
, true);
343 std::string account_id
=
344 account_tracker_
->SeedAccountInfo("12345", "syncuser@example.com");
345 autofill_client_
.GetPrefs()->SetString(
346 ::prefs::kGoogleServicesAccountId
, account_id
);
349 // Test that we log quality metrics appropriately.
350 TEST_F(AutofillMetricsTest
, QualityMetrics
) {
351 // Set up our form data.
353 form
.name
= ASCIIToUTF16("TestForm");
354 form
.origin
= GURL("http://example.com/form.html");
355 form
.action
= GURL("http://example.com/submit.html");
357 std::vector
<ServerFieldType
> heuristic_types
, server_types
;
360 test::CreateTestFormField(
361 "Autofilled", "autofilled", "Elvis Aaron Presley", "text", &field
);
362 field
.is_autofilled
= true;
363 form
.fields
.push_back(field
);
364 heuristic_types
.push_back(NAME_FULL
);
365 server_types
.push_back(NAME_FIRST
);
367 test::CreateTestFormField(
368 "Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field
);
369 field
.is_autofilled
= false;
370 form
.fields
.push_back(field
);
371 heuristic_types
.push_back(PHONE_HOME_NUMBER
);
372 server_types
.push_back(EMAIL_ADDRESS
);
374 test::CreateTestFormField("Empty", "empty", "", "text", &field
);
375 field
.is_autofilled
= false;
376 form
.fields
.push_back(field
);
377 heuristic_types
.push_back(NAME_FULL
);
378 server_types
.push_back(NAME_FIRST
);
380 test::CreateTestFormField("Unknown", "unknown", "garbage", "text", &field
);
381 field
.is_autofilled
= false;
382 form
.fields
.push_back(field
);
383 heuristic_types
.push_back(PHONE_HOME_NUMBER
);
384 server_types
.push_back(EMAIL_ADDRESS
);
386 test::CreateTestFormField("Select", "select", "USA", "select-one", &field
);
387 field
.is_autofilled
= false;
388 form
.fields
.push_back(field
);
389 heuristic_types
.push_back(UNKNOWN_TYPE
);
390 server_types
.push_back(NO_SERVER_DATA
);
392 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field
);
393 field
.is_autofilled
= true;
394 form
.fields
.push_back(field
);
395 heuristic_types
.push_back(PHONE_HOME_CITY_AND_NUMBER
);
396 server_types
.push_back(PHONE_HOME_WHOLE_NUMBER
);
398 // Simulate having seen this form on page load.
399 autofill_manager_
->AddSeenForm(form
, heuristic_types
, server_types
);
401 // Simulate form submission.
402 base::HistogramTester histogram_tester
;
403 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
405 // Heuristic predictions.
407 histogram_tester
.ExpectBucketCount("Autofill.Quality.HeuristicType",
408 AutofillMetrics::TYPE_UNKNOWN
, 1);
409 histogram_tester
.ExpectBucketCount(
410 "Autofill.Quality.HeuristicType.ByFieldType",
411 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY
,
412 AutofillMetrics::TYPE_UNKNOWN
),
415 histogram_tester
.ExpectBucketCount("Autofill.Quality.HeuristicType",
416 AutofillMetrics::TYPE_MATCH
, 2);
417 histogram_tester
.ExpectBucketCount(
418 "Autofill.Quality.HeuristicType.ByFieldType",
419 GetFieldTypeGroupMetric(NAME_FULL
, AutofillMetrics::TYPE_MATCH
), 1);
420 histogram_tester
.ExpectBucketCount(
421 "Autofill.Quality.HeuristicType.ByFieldType",
422 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER
,
423 AutofillMetrics::TYPE_MATCH
),
426 histogram_tester
.ExpectBucketCount("Autofill.Quality.HeuristicType",
427 AutofillMetrics::TYPE_MISMATCH
, 1);
428 histogram_tester
.ExpectBucketCount(
429 "Autofill.Quality.HeuristicType.ByFieldType",
430 GetFieldTypeGroupMetric(EMAIL_ADDRESS
, AutofillMetrics::TYPE_MISMATCH
),
433 // Server predictions:
435 histogram_tester
.ExpectBucketCount("Autofill.Quality.ServerType",
436 AutofillMetrics::TYPE_UNKNOWN
, 1);
437 histogram_tester
.ExpectBucketCount(
438 "Autofill.Quality.ServerType.ByFieldType",
439 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY
,
440 AutofillMetrics::TYPE_UNKNOWN
),
443 histogram_tester
.ExpectBucketCount("Autofill.Quality.ServerType",
444 AutofillMetrics::TYPE_MATCH
, 2);
445 histogram_tester
.ExpectBucketCount(
446 "Autofill.Quality.ServerType.ByFieldType",
447 GetFieldTypeGroupMetric(EMAIL_ADDRESS
, AutofillMetrics::TYPE_MATCH
), 1);
448 histogram_tester
.ExpectBucketCount(
449 "Autofill.Quality.ServerType.ByFieldType",
450 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER
,
451 AutofillMetrics::TYPE_MATCH
),
454 histogram_tester
.ExpectBucketCount("Autofill.Quality.ServerType",
455 AutofillMetrics::TYPE_MISMATCH
, 1);
456 histogram_tester
.ExpectBucketCount(
457 "Autofill.Quality.ServerType.ByFieldType",
458 GetFieldTypeGroupMetric(NAME_FULL
, AutofillMetrics::TYPE_MISMATCH
), 1);
460 // Overall predictions:
462 histogram_tester
.ExpectBucketCount("Autofill.Quality.PredictedType",
463 AutofillMetrics::TYPE_UNKNOWN
, 1);
464 histogram_tester
.ExpectBucketCount(
465 "Autofill.Quality.PredictedType.ByFieldType",
466 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY
,
467 AutofillMetrics::TYPE_UNKNOWN
),
470 histogram_tester
.ExpectBucketCount("Autofill.Quality.PredictedType",
471 AutofillMetrics::TYPE_MATCH
, 2);
472 histogram_tester
.ExpectBucketCount(
473 "Autofill.Quality.PredictedType.ByFieldType",
474 GetFieldTypeGroupMetric(EMAIL_ADDRESS
, AutofillMetrics::TYPE_MATCH
), 1);
475 histogram_tester
.ExpectBucketCount(
476 "Autofill.Quality.PredictedType.ByFieldType",
477 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER
,
478 AutofillMetrics::TYPE_MATCH
),
481 histogram_tester
.ExpectBucketCount("Autofill.Quality.PredictedType",
482 AutofillMetrics::TYPE_MISMATCH
, 1);
483 histogram_tester
.ExpectBucketCount(
484 "Autofill.Quality.PredictedType.ByFieldType",
485 GetFieldTypeGroupMetric(NAME_FULL
, AutofillMetrics::TYPE_MISMATCH
), 1);
488 // Test that we do not log RAPPOR metrics when the number of mismatches is not
490 TEST_F(AutofillMetricsTest
, Rappor_LowMismatchRate_NoMetricsReported
) {
491 // Set up our form data.
493 form
.name
= ASCIIToUTF16("TestForm");
494 form
.origin
= GURL("http://example.com/form.html");
495 form
.action
= GURL("http://example.com/submit.html");
497 std::vector
<ServerFieldType
> heuristic_types
, server_types
;
500 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley",
502 field
.is_autofilled
= true;
503 form
.fields
.push_back(field
);
504 heuristic_types
.push_back(NAME_FULL
);
505 server_types
.push_back(NAME_FULL
);
507 test::CreateTestFormField("Autofill Failed", "autofillfailed",
508 "buddy@gmail.com", "text", &field
);
509 field
.is_autofilled
= false;
510 form
.fields
.push_back(field
);
511 heuristic_types
.push_back(EMAIL_ADDRESS
);
512 server_types
.push_back(NAME_LAST
);
514 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field
);
515 field
.is_autofilled
= true;
516 form
.fields
.push_back(field
);
517 heuristic_types
.push_back(PHONE_HOME_CITY_AND_NUMBER
);
518 server_types
.push_back(EMAIL_ADDRESS
);
520 // Simulate having seen this form on page load.
521 autofill_manager_
->AddSeenForm(form
, heuristic_types
, server_types
);
523 // Simulate form submission.
524 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
526 // The number of mismatches did not trigger the RAPPOR metric logging.
527 EXPECT_EQ(0, autofill_client_
.test_rappor_service()->GetReportsCount());
530 // Test that we don't log RAPPOR metrics in the case heuristics and/or server
532 TEST_F(AutofillMetricsTest
, Rappor_NoDataServerAndHeuristic_NoMetricsReported
) {
533 // Set up our form data.
535 form
.name
= ASCIIToUTF16("TestForm");
536 form
.origin
= GURL("http://example.com/form.html");
537 form
.action
= GURL("http://example.com/submit.html");
539 std::vector
<ServerFieldType
> heuristic_types
, server_types
;
542 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley",
544 field
.is_autofilled
= true;
545 form
.fields
.push_back(field
);
546 heuristic_types
.push_back(UNKNOWN_TYPE
);
547 server_types
.push_back(NO_SERVER_DATA
);
549 test::CreateTestFormField("Autofill Failed", "autofillfailed",
550 "buddy@gmail.com", "text", &field
);
551 field
.is_autofilled
= false;
552 form
.fields
.push_back(field
);
553 heuristic_types
.push_back(UNKNOWN_TYPE
);
554 server_types
.push_back(NO_SERVER_DATA
);
556 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field
);
557 field
.is_autofilled
= true;
558 form
.fields
.push_back(field
);
559 heuristic_types
.push_back(UNKNOWN_TYPE
);
560 server_types
.push_back(NO_SERVER_DATA
);
562 // Simulate having seen this form on page load.
563 autofill_manager_
->AddSeenForm(form
, heuristic_types
, server_types
);
565 // Simulate form submission.
566 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
568 // No RAPPOR metrics are logged in the case of multiple UNKNOWN_TYPE and
569 // NO_SERVER_DATA for heuristics and server predictions, respectively.
570 EXPECT_EQ(0, autofill_client_
.test_rappor_service()->GetReportsCount());
573 // Test that we log high number of mismatches for the server prediction.
574 TEST_F(AutofillMetricsTest
, Rappor_HighServerMismatchRate_MetricsReported
) {
575 // Set up our form data.
577 form
.name
= ASCIIToUTF16("TestForm");
578 form
.origin
= GURL("http://example.com/form.html");
579 form
.action
= GURL("http://example.com/submit.html");
581 std::vector
<ServerFieldType
> heuristic_types
, server_types
;
584 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley",
586 field
.is_autofilled
= true;
587 form
.fields
.push_back(field
);
588 heuristic_types
.push_back(NAME_FULL
);
589 server_types
.push_back(NAME_FIRST
);
591 test::CreateTestFormField("Autofill Failed", "autofillfailed",
592 "buddy@gmail.com", "text", &field
);
593 field
.is_autofilled
= false;
594 form
.fields
.push_back(field
);
595 heuristic_types
.push_back(PHONE_HOME_NUMBER
);
596 server_types
.push_back(NAME_LAST
);
598 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field
);
599 field
.is_autofilled
= true;
600 form
.fields
.push_back(field
);
601 heuristic_types
.push_back(PHONE_HOME_CITY_AND_NUMBER
);
602 server_types
.push_back(EMAIL_ADDRESS
);
604 // Simulate having seen this form on page load.
605 autofill_manager_
->AddSeenForm(form
, heuristic_types
, server_types
);
607 // Simulate form submission.
608 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
610 // The number of mismatches did trigger the RAPPOR metric logging for server
612 EXPECT_EQ(1, autofill_client_
.test_rappor_service()->GetReportsCount());
614 rappor::RapporType type
;
616 autofill_client_
.test_rappor_service()->GetRecordedSampleForMetric(
617 "Autofill.HighNumberOfHeuristicMismatches", &sample
, &type
));
619 autofill_client_
.test_rappor_service()->GetRecordedSampleForMetric(
620 "Autofill.HighNumberOfServerMismatches", &sample
, &type
));
621 EXPECT_EQ("example.com", sample
);
622 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE
, type
);
625 // Test that we log high number of mismatches for the heuristic predictions.
626 TEST_F(AutofillMetricsTest
, Rappor_HighHeuristicMismatchRate_MetricsReported
) {
627 // Set up our form data.
629 form
.name
= ASCIIToUTF16("TestForm");
630 form
.origin
= GURL("http://example.com/form.html");
631 form
.action
= GURL("http://example.com/submit.html");
633 std::vector
<ServerFieldType
> heuristic_types
, server_types
;
636 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley",
638 field
.is_autofilled
= true;
639 form
.fields
.push_back(field
);
640 heuristic_types
.push_back(NAME_FIRST
);
641 server_types
.push_back(NAME_FULL
);
643 test::CreateTestFormField("Autofill Failed", "autofillfailed",
644 "buddy@gmail.com", "text", &field
);
645 field
.is_autofilled
= false;
646 form
.fields
.push_back(field
);
647 heuristic_types
.push_back(PHONE_HOME_NUMBER
);
648 server_types
.push_back(NAME_LAST
);
650 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field
);
651 field
.is_autofilled
= true;
652 form
.fields
.push_back(field
);
653 heuristic_types
.push_back(EMAIL_ADDRESS
);
654 server_types
.push_back(PHONE_HOME_WHOLE_NUMBER
);
656 // Simulate having seen this form on page load.
657 autofill_manager_
->AddSeenForm(form
, heuristic_types
, server_types
);
659 // Simulate form submission.
660 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
662 // The number of mismatches did trigger the RAPPOR metric logging for
663 // heuristic predictions.
664 EXPECT_EQ(1, autofill_client_
.test_rappor_service()->GetReportsCount());
666 rappor::RapporType type
;
668 autofill_client_
.test_rappor_service()->GetRecordedSampleForMetric(
669 "Autofill.HighNumberOfServerMismatches", &sample
, &type
));
671 autofill_client_
.test_rappor_service()->GetRecordedSampleForMetric(
672 "Autofill.HighNumberOfHeuristicMismatches", &sample
, &type
));
673 EXPECT_EQ("example.com", sample
);
674 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE
, type
);
677 // Verify that when a field is annotated with the autocomplete attribute, its
678 // predicted type is remembered when quality metrics are logged.
679 TEST_F(AutofillMetricsTest
, PredictedMetricsWithAutocomplete
) {
680 // Set up our form data.
682 form
.name
= ASCIIToUTF16("TestForm");
683 form
.origin
= GURL("http://example.com/form.html");
684 form
.action
= GURL("http://example.com/submit.html");
686 FormFieldData field1
;
687 test::CreateTestFormField("Select", "select", "USA", "select-one", &field1
);
688 field1
.autocomplete_attribute
= "country";
689 form
.fields
.push_back(field1
);
691 // Two other fields to have the minimum of 3 to be parsed by autofill. Note
692 // that they have default values not found in the user profiles. They will be
693 // changed between the time the form is seen/parsed, and the time it is
695 FormFieldData field2
;
696 test::CreateTestFormField("Unknown", "Unknown", "", "text", &field2
);
697 form
.fields
.push_back(field2
);
698 FormFieldData field3
;
699 test::CreateTestFormField("Phone", "phone", "", "tel", &field3
);
700 form
.fields
.push_back(field3
);
702 std::vector
<FormData
> forms(1, form
);
705 base::HistogramTester histogram_tester
;
706 autofill_manager_
->OnFormsSeen(forms
, TimeTicks());
707 // We change the value of the text fields to change the default/seen values
708 // (hence the values are not cleared in UpdateFromCache). The new values
709 // match what is in the test profile.
710 form
.fields
[1].value
= base::ASCIIToUTF16("79401");
711 form
.fields
[2].value
= base::ASCIIToUTF16("2345678901");
712 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
714 // First verify that country was not predicted by client or server.
715 histogram_tester
.ExpectBucketCount(
716 "Autofill.Quality.ServerType.ByFieldType",
717 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY
,
718 AutofillMetrics::TYPE_UNKNOWN
),
720 histogram_tester
.ExpectBucketCount(
721 "Autofill.Quality.HeuristicType.ByFieldType",
722 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY
,
723 AutofillMetrics::TYPE_UNKNOWN
),
725 // We expect a match for country because it had |autocomplete_attribute|.
726 histogram_tester
.ExpectBucketCount(
727 "Autofill.Quality.PredictedType.ByFieldType",
728 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY
,
729 AutofillMetrics::TYPE_MATCH
),
732 // We did not predict zip code or phone number, because they did not have
733 // |autocomplete_attribute|, nor client or server predictions.
734 histogram_tester
.ExpectBucketCount(
735 "Autofill.Quality.ServerType.ByFieldType",
736 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP
,
737 AutofillMetrics::TYPE_UNKNOWN
),
739 histogram_tester
.ExpectBucketCount(
740 "Autofill.Quality.HeuristicType.ByFieldType",
741 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP
,
742 AutofillMetrics::TYPE_UNKNOWN
),
744 histogram_tester
.ExpectBucketCount(
745 "Autofill.Quality.PredictedType.ByFieldType",
746 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP
,
747 AutofillMetrics::TYPE_UNKNOWN
),
749 histogram_tester
.ExpectBucketCount(
750 "Autofill.Quality.ServerType.ByFieldType",
751 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER
,
752 AutofillMetrics::TYPE_UNKNOWN
),
754 histogram_tester
.ExpectBucketCount(
755 "Autofill.Quality.HeuristicType.ByFieldType",
756 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER
,
757 AutofillMetrics::TYPE_UNKNOWN
),
759 histogram_tester
.ExpectBucketCount(
760 "Autofill.Quality.PredictedType.ByFieldType",
761 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER
,
762 AutofillMetrics::TYPE_UNKNOWN
),
766 histogram_tester
.ExpectTotalCount("Autofill.Quality.PredictedType", 3);
770 // Test that we behave sanely when the cached form differs from the submitted
772 TEST_F(AutofillMetricsTest
, SaneMetricsWithCacheMismatch
) {
773 // Set up our form data.
775 form
.name
= ASCIIToUTF16("TestForm");
776 form
.origin
= GURL("http://example.com/form.html");
777 form
.action
= GURL("http://example.com/submit.html");
779 std::vector
<ServerFieldType
> heuristic_types
, server_types
;
782 test::CreateTestFormField(
783 "Both match", "match", "Elvis Aaron Presley", "text", &field
);
784 field
.is_autofilled
= true;
785 form
.fields
.push_back(field
);
786 heuristic_types
.push_back(NAME_FULL
);
787 server_types
.push_back(NAME_FULL
);
788 test::CreateTestFormField(
789 "Both mismatch", "mismatch", "buddy@gmail.com", "text", &field
);
790 field
.is_autofilled
= false;
791 form
.fields
.push_back(field
);
792 heuristic_types
.push_back(PHONE_HOME_NUMBER
);
793 server_types
.push_back(PHONE_HOME_NUMBER
);
794 test::CreateTestFormField(
795 "Only heuristics match", "mixed", "Memphis", "text", &field
);
796 field
.is_autofilled
= false;
797 form
.fields
.push_back(field
);
798 heuristic_types
.push_back(ADDRESS_HOME_CITY
);
799 server_types
.push_back(PHONE_HOME_NUMBER
);
800 test::CreateTestFormField("Unknown", "unknown", "garbage", "text", &field
);
801 field
.is_autofilled
= false;
802 form
.fields
.push_back(field
);
803 heuristic_types
.push_back(UNKNOWN_TYPE
);
804 server_types
.push_back(UNKNOWN_TYPE
);
806 // Simulate having seen this form with the desired heuristic and server types.
807 // |form_structure| will be owned by |autofill_manager_|.
808 autofill_manager_
->AddSeenForm(form
, heuristic_types
, server_types
);
811 // Add a field and re-arrange the remaining form fields before submitting.
812 std::vector
<FormFieldData
> cached_fields
= form
.fields
;
814 test::CreateTestFormField(
815 "New field", "new field", "Tennessee", "text", &field
);
816 form
.fields
.push_back(field
);
817 form
.fields
.push_back(cached_fields
[2]);
818 form
.fields
.push_back(cached_fields
[1]);
819 form
.fields
.push_back(cached_fields
[3]);
820 form
.fields
.push_back(cached_fields
[0]);
822 // Simulate form submission.
823 base::HistogramTester histogram_tester
;
824 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
826 // Heuristic predictions.
828 histogram_tester
.ExpectBucketCount("Autofill.Quality.HeuristicType",
829 AutofillMetrics::TYPE_UNKNOWN
, 1);
830 histogram_tester
.ExpectBucketCount(
831 "Autofill.Quality.HeuristicType.ByFieldType",
832 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE
,
833 AutofillMetrics::TYPE_UNKNOWN
),
836 histogram_tester
.ExpectBucketCount("Autofill.Quality.HeuristicType",
837 AutofillMetrics::TYPE_MATCH
, 2);
838 histogram_tester
.ExpectBucketCount(
839 "Autofill.Quality.HeuristicType.ByFieldType",
840 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY
, AutofillMetrics::TYPE_MATCH
),
842 histogram_tester
.ExpectBucketCount(
843 "Autofill.Quality.HeuristicType.ByFieldType",
844 GetFieldTypeGroupMetric(NAME_FULL
, AutofillMetrics::TYPE_MATCH
), 1);
846 histogram_tester
.ExpectBucketCount("Autofill.Quality.HeuristicType",
847 AutofillMetrics::TYPE_MISMATCH
, 1);
848 histogram_tester
.ExpectBucketCount(
849 "Autofill.Quality.HeuristicType.ByFieldType",
850 GetFieldTypeGroupMetric(EMAIL_ADDRESS
, AutofillMetrics::TYPE_MISMATCH
),
853 // Server predictions:
855 histogram_tester
.ExpectBucketCount("Autofill.Quality.ServerType",
856 AutofillMetrics::TYPE_UNKNOWN
, 1);
857 histogram_tester
.ExpectBucketCount(
858 "Autofill.Quality.ServerType.ByFieldType",
859 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE
,
860 AutofillMetrics::TYPE_UNKNOWN
),
863 histogram_tester
.ExpectBucketCount("Autofill.Quality.ServerType",
864 AutofillMetrics::TYPE_MATCH
, 1);
865 histogram_tester
.ExpectBucketCount(
866 "Autofill.Quality.ServerType.ByFieldType",
867 GetFieldTypeGroupMetric(NAME_FULL
, AutofillMetrics::TYPE_MATCH
), 1);
869 histogram_tester
.ExpectBucketCount("Autofill.Quality.ServerType",
870 AutofillMetrics::TYPE_MISMATCH
, 2);
871 histogram_tester
.ExpectBucketCount(
872 "Autofill.Quality.ServerType.ByFieldType",
873 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY
,
874 AutofillMetrics::TYPE_MISMATCH
),
876 histogram_tester
.ExpectBucketCount(
877 "Autofill.Quality.ServerType.ByFieldType",
878 GetFieldTypeGroupMetric(EMAIL_ADDRESS
, AutofillMetrics::TYPE_MISMATCH
),
881 // Overall predictions:
883 histogram_tester
.ExpectBucketCount("Autofill.Quality.PredictedType",
884 AutofillMetrics::TYPE_UNKNOWN
, 1);
885 histogram_tester
.ExpectBucketCount(
886 "Autofill.Quality.PredictedType.ByFieldType",
887 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE
,
888 AutofillMetrics::TYPE_UNKNOWN
),
891 histogram_tester
.ExpectBucketCount("Autofill.Quality.PredictedType",
892 AutofillMetrics::TYPE_MATCH
, 1);
893 histogram_tester
.ExpectBucketCount(
894 "Autofill.Quality.PredictedType.ByFieldType",
895 GetFieldTypeGroupMetric(NAME_FULL
, AutofillMetrics::TYPE_MATCH
), 1);
897 histogram_tester
.ExpectBucketCount("Autofill.Quality.PredictedType",
898 AutofillMetrics::TYPE_MISMATCH
, 2);
899 histogram_tester
.ExpectBucketCount(
900 "Autofill.Quality.PredictedType.ByFieldType",
901 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY
,
902 AutofillMetrics::TYPE_MISMATCH
),
904 histogram_tester
.ExpectBucketCount(
905 "Autofill.Quality.PredictedType.ByFieldType",
906 GetFieldTypeGroupMetric(EMAIL_ADDRESS
, AutofillMetrics::TYPE_MISMATCH
),
910 // Verify that when submitting an autofillable form, the stored profile metric
912 TEST_F(AutofillMetricsTest
, StoredProfileCountAutofillableFormSubmission
) {
913 // Construct a fillable form.
915 form
.name
= ASCIIToUTF16("TestForm");
916 form
.origin
= GURL("http://example.com/form.html");
917 form
.action
= GURL("http://example.com/submit.html");
919 // Three fields is enough to make it an autofillable form.
921 test::CreateTestFormField("Name", "name", "", "text", &field
);
922 form
.fields
.push_back(field
);
923 test::CreateTestFormField("Email", "email", "", "text", &field
);
924 form
.fields
.push_back(field
);
925 test::CreateTestFormField("Phone", "phone", "", "text", &field
);
926 form
.fields
.push_back(field
);
928 std::vector
<FormData
> forms(1, form
);
930 // Simulate form submission.
931 base::HistogramTester histogram_tester
;
932 autofill_manager_
->OnFormsSeen(forms
, TimeTicks());
933 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
935 // An autofillable form was submitted, and the number of stored profiles is
937 histogram_tester
.ExpectUniqueSample(
938 "Autofill.StoredProfileCountAtAutofillableFormSubmission", 2, 1);
941 // Verify that when submitting a non-autofillable form, the stored profile
942 // metric is not logged.
943 TEST_F(AutofillMetricsTest
, StoredProfileCountNonAutofillableFormSubmission
) {
944 // Construct a non-fillable form.
946 form
.name
= ASCIIToUTF16("TestForm");
947 form
.origin
= GURL("http://example.com/form.html");
948 form
.action
= GURL("http://example.com/submit.html");
950 // Two fields is not enough to make it an autofillable form.
952 test::CreateTestFormField("Name", "name", "", "text", &field
);
953 form
.fields
.push_back(field
);
954 test::CreateTestFormField("Email", "email", "", "text", &field
);
955 form
.fields
.push_back(field
);
957 std::vector
<FormData
> forms(1, form
);
959 // Simulate form submission.
960 base::HistogramTester histogram_tester
;
961 autofill_manager_
->OnFormsSeen(forms
, TimeTicks());
962 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
964 // A non-autofillable form was submitted, and number of stored profiles is NOT
966 histogram_tester
.ExpectTotalCount(
967 "Autofill.StoredProfileCountAtAutofillableFormSubmission", 0);
970 // Verify that when submitting an autofillable form, the proper number of edited
972 TEST_F(AutofillMetricsTest
, NumberOfEditedAutofilledFields
) {
973 // Construct a fillable form.
975 form
.name
= ASCIIToUTF16("TestForm");
976 form
.origin
= GURL("http://example.com/form.html");
977 form
.action
= GURL("http://example.com/submit.html");
979 std::vector
<ServerFieldType
> heuristic_types
, server_types
;
981 // Three fields is enough to make it an autofillable form.
983 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley",
985 field
.is_autofilled
= true;
986 form
.fields
.push_back(field
);
987 heuristic_types
.push_back(NAME_FULL
);
988 server_types
.push_back(NAME_FULL
);
990 test::CreateTestFormField("Autofill Failed", "autofillfailed",
991 "buddy@gmail.com", "text", &field
);
992 field
.is_autofilled
= true;
993 form
.fields
.push_back(field
);
994 heuristic_types
.push_back(EMAIL_ADDRESS
);
995 server_types
.push_back(EMAIL_ADDRESS
);
997 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field
);
998 field
.is_autofilled
= true;
999 form
.fields
.push_back(field
);
1000 heuristic_types
.push_back(PHONE_HOME_CITY_AND_NUMBER
);
1001 server_types
.push_back(PHONE_HOME_CITY_AND_NUMBER
);
1003 autofill_manager_
->AddSeenForm(form
, heuristic_types
, server_types
);
1005 base::HistogramTester histogram_tester
;
1006 // Simulate text input in the first and second fields.
1007 autofill_manager_
->OnTextFieldDidChange(form
, form
.fields
[0], TimeTicks());
1008 autofill_manager_
->OnTextFieldDidChange(form
, form
.fields
[1], TimeTicks());
1010 // Simulate form submission.
1011 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
1013 // An autofillable form was submitted, and the number of edited autofilled
1014 // fields is logged.
1015 histogram_tester
.ExpectUniqueSample(
1016 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1);
1019 // Verify that we correctly log metrics regarding developer engagement.
1020 TEST_F(AutofillMetricsTest
, DeveloperEngagement
) {
1021 // Start with a non-fillable form.
1023 form
.name
= ASCIIToUTF16("TestForm");
1024 form
.origin
= GURL("http://example.com/form.html");
1025 form
.action
= GURL("http://example.com/submit.html");
1027 FormFieldData field
;
1028 test::CreateTestFormField("Name", "name", "", "text", &field
);
1029 form
.fields
.push_back(field
);
1030 test::CreateTestFormField("Email", "email", "", "text", &field
);
1031 form
.fields
.push_back(field
);
1033 std::vector
<FormData
> forms(1, form
);
1035 // Ensure no metrics are logged when loading a non-fillable form.
1037 base::HistogramTester histogram_tester
;
1038 autofill_manager_
->OnFormsSeen(forms
, TimeTicks());
1039 autofill_manager_
->Reset();
1040 histogram_tester
.ExpectTotalCount("Autofill.DeveloperEngagement", 0);
1043 // Add another field to the form, so that it becomes fillable.
1044 test::CreateTestFormField("Phone", "phone", "", "text", &field
);
1045 forms
.back().fields
.push_back(field
);
1047 // Expect only the "form parsed" metric to be logged; no metrics about
1048 // author-specified field type hints.
1050 base::HistogramTester histogram_tester
;
1051 autofill_manager_
->OnFormsSeen(forms
, TimeTicks());
1052 autofill_manager_
->Reset();
1053 histogram_tester
.ExpectUniqueSample("Autofill.DeveloperEngagement",
1054 AutofillMetrics::FILLABLE_FORM_PARSED
,
1058 // Add some fields with an author-specified field type to the form.
1059 // We need to add at least three fields, because a form must have at least
1060 // three fillable fields to be considered to be autofillable; and if at least
1061 // one field specifies an explicit type hint, we don't apply any of our usual
1062 // local heuristics to detect field types in the rest of the form.
1063 test::CreateTestFormField("", "", "", "text", &field
);
1064 field
.autocomplete_attribute
= "given-name";
1065 forms
.back().fields
.push_back(field
);
1066 test::CreateTestFormField("", "", "", "text", &field
);
1067 field
.autocomplete_attribute
= "email";
1068 forms
.back().fields
.push_back(field
);
1069 test::CreateTestFormField("", "", "", "text", &field
);
1070 field
.autocomplete_attribute
= "address-line1";
1071 forms
.back().fields
.push_back(field
);
1073 // Expect both the "form parsed" metric and the author-specified field type
1074 // hints metric to be logged.
1076 base::HistogramTester histogram_tester
;
1077 autofill_manager_
->OnFormsSeen(forms
, TimeTicks());
1078 autofill_manager_
->Reset();
1079 histogram_tester
.ExpectBucketCount("Autofill.DeveloperEngagement",
1080 AutofillMetrics::FILLABLE_FORM_PARSED
,
1082 histogram_tester
.ExpectBucketCount(
1083 "Autofill.DeveloperEngagement",
1084 AutofillMetrics::FILLABLE_FORM_CONTAINS_TYPE_HINTS
, 1);
1088 // Test that the profile count is logged correctly.
1089 TEST_F(AutofillMetricsTest
, StoredProfileCount
) {
1090 // The metric should be logged when the profiles are first loaded.
1092 base::HistogramTester histogram_tester
;
1093 personal_data_
->LoadProfiles();
1094 histogram_tester
.ExpectUniqueSample("Autofill.StoredProfileCount", 2, 1);
1097 // The metric should only be logged once.
1099 base::HistogramTester histogram_tester
;
1100 personal_data_
->LoadProfiles();
1101 histogram_tester
.ExpectTotalCount("Autofill.StoredProfileCount", 0);
1105 // Test that we correctly log when Autofill is enabled.
1106 TEST_F(AutofillMetricsTest
, AutofillIsEnabledAtStartup
) {
1107 base::HistogramTester histogram_tester
;
1108 personal_data_
->set_autofill_enabled(true);
1109 personal_data_
->Init(
1110 autofill_client_
.GetDatabase(), autofill_client_
.GetPrefs(),
1111 account_tracker_
.get(), false);
1112 histogram_tester
.ExpectUniqueSample("Autofill.IsEnabled.Startup", true, 1);
1115 // Test that we correctly log when Autofill is disabled.
1116 TEST_F(AutofillMetricsTest
, AutofillIsDisabledAtStartup
) {
1117 base::HistogramTester histogram_tester
;
1118 personal_data_
->set_autofill_enabled(false);
1119 personal_data_
->Init(
1120 autofill_client_
.GetDatabase(), autofill_client_
.GetPrefs(),
1121 account_tracker_
.get(), false);
1122 histogram_tester
.ExpectUniqueSample("Autofill.IsEnabled.Startup", false, 1);
1125 // Test that we log the number of Autofill suggestions when filling a form.
1126 TEST_F(AutofillMetricsTest
, AddressSuggestionsCount
) {
1127 // Set up our form data.
1129 form
.name
= ASCIIToUTF16("TestForm");
1130 form
.origin
= GURL("http://example.com/form.html");
1131 form
.action
= GURL("http://example.com/submit.html");
1133 FormFieldData field
;
1134 std::vector
<ServerFieldType
> field_types
;
1135 test::CreateTestFormField("Name", "name", "", "text", &field
);
1136 form
.fields
.push_back(field
);
1137 field_types
.push_back(NAME_FULL
);
1138 test::CreateTestFormField("Email", "email", "", "email", &field
);
1139 form
.fields
.push_back(field
);
1140 field_types
.push_back(EMAIL_ADDRESS
);
1141 test::CreateTestFormField("Phone", "phone", "", "tel", &field
);
1142 form
.fields
.push_back(field
);
1143 field_types
.push_back(PHONE_HOME_NUMBER
);
1145 // Simulate having seen this form on page load.
1146 // |form_structure| will be owned by |autofill_manager_|.
1147 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1150 // Simulate activating the autofill popup for the phone field.
1151 base::HistogramTester histogram_tester
;
1152 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1153 histogram_tester
.ExpectUniqueSample("Autofill.AddressSuggestionsCount", 2,
1158 // Simulate activating the autofill popup for the email field after typing.
1159 // No new metric should be logged, since we're still on the same page.
1160 test::CreateTestFormField("Email", "email", "b", "email", &field
);
1161 base::HistogramTester histogram_tester
;
1162 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1163 histogram_tester
.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0);
1166 // Reset the autofill manager state.
1167 autofill_manager_
->Reset();
1168 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1171 // Simulate activating the autofill popup for the email field after typing.
1172 base::HistogramTester histogram_tester
;
1173 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1174 histogram_tester
.ExpectUniqueSample("Autofill.AddressSuggestionsCount", 1,
1178 // Reset the autofill manager state again.
1179 autofill_manager_
->Reset();
1180 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1183 // Simulate activating the autofill popup for the email field after typing.
1184 form
.fields
[0].is_autofilled
= true;
1185 base::HistogramTester histogram_tester
;
1186 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1187 histogram_tester
.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0);
1191 // Test that we log interacted form event for credit cards related.
1192 TEST_F(AutofillMetricsTest
, CreditCardInteractedFormEvents
) {
1193 // Set up our form data.
1195 form
.name
= ASCIIToUTF16("TestForm");
1196 form
.origin
= GURL("http://example.com/form.html");
1197 form
.action
= GURL("http://example.com/submit.html");
1199 FormFieldData field
;
1200 std::vector
<ServerFieldType
> field_types
;
1201 test::CreateTestFormField("Month", "card_month", "", "text", &field
);
1202 form
.fields
.push_back(field
);
1203 field_types
.push_back(CREDIT_CARD_EXP_MONTH
);
1204 test::CreateTestFormField("Year", "card_year", "", "text", &field
);
1205 form
.fields
.push_back(field
);
1206 field_types
.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR
);
1207 test::CreateTestFormField("Credit card", "card", "", "text", &field
);
1208 form
.fields
.push_back(field
);
1209 field_types
.push_back(CREDIT_CARD_NUMBER
);
1211 // Simulate having seen this form on page load.
1212 // |form_structure| will be owned by |autofill_manager_|.
1213 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1216 // Simulate activating the autofill popup for the credit card field.
1217 base::HistogramTester histogram_tester
;
1218 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1219 histogram_tester
.ExpectUniqueSample(
1220 "Autofill.FormEvents.CreditCard",
1221 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
1224 // Reset the autofill manager state.
1225 autofill_manager_
->Reset();
1226 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1229 // Simulate activating the autofill popup for the credit card field twice.
1230 base::HistogramTester histogram_tester
;
1231 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1232 autofill_manager_
->OnQueryFormFieldAutofill(1, form
, field
, gfx::Rect());
1233 histogram_tester
.ExpectUniqueSample(
1234 "Autofill.FormEvents.CreditCard",
1235 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
1239 // Test that we log suggestion shown form events for credit cards.
1240 TEST_F(AutofillMetricsTest
, CreditCardShownFormEvents
) {
1241 // Set up our form data.
1243 form
.name
= ASCIIToUTF16("TestForm");
1244 form
.origin
= GURL("http://example.com/form.html");
1245 form
.action
= GURL("http://example.com/submit.html");
1247 FormFieldData field
;
1248 std::vector
<ServerFieldType
> field_types
;
1249 test::CreateTestFormField("Month", "card_month", "", "text", &field
);
1250 form
.fields
.push_back(field
);
1251 field_types
.push_back(CREDIT_CARD_EXP_MONTH
);
1252 test::CreateTestFormField("Year", "card_year", "", "text", &field
);
1253 form
.fields
.push_back(field
);
1254 field_types
.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR
);
1255 test::CreateTestFormField("Credit card", "card", "", "text", &field
);
1256 form
.fields
.push_back(field
);
1257 field_types
.push_back(CREDIT_CARD_NUMBER
);
1259 // Simulate having seen this form on page load.
1260 // |form_structure| will be owned by |autofill_manager_|.
1261 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1264 // Simulating new popup being shown.
1265 base::HistogramTester histogram_tester
;
1266 autofill_manager_
->DidShowSuggestions(true /* is_new_popup */, form
, field
);
1267 histogram_tester
.ExpectBucketCount(
1268 "Autofill.FormEvents.CreditCard",
1269 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN
, 1);
1270 histogram_tester
.ExpectBucketCount(
1271 "Autofill.FormEvents.CreditCard",
1272 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE
, 1);
1275 // Reset the autofill manager state.
1276 autofill_manager_
->Reset();
1277 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1280 // Simulating two popups in the same page load.
1281 base::HistogramTester histogram_tester
;
1282 autofill_manager_
->DidShowSuggestions(true /* is_new_popup */, form
, field
);
1283 autofill_manager_
->DidShowSuggestions(true /* is_new_popup */, form
, field
);
1284 histogram_tester
.ExpectBucketCount(
1285 "Autofill.FormEvents.CreditCard",
1286 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN
, 2);
1287 histogram_tester
.ExpectBucketCount(
1288 "Autofill.FormEvents.CreditCard",
1289 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE
, 1);
1292 // Reset the autofill manager state.
1293 autofill_manager_
->Reset();
1294 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1297 // Simulating same popup being refreshed.
1298 base::HistogramTester histogram_tester
;
1299 autofill_manager_
->DidShowSuggestions(false /* is_new_popup */, form
,
1301 histogram_tester
.ExpectBucketCount(
1302 "Autofill.FormEvents.CreditCard",
1303 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN
, 0);
1304 histogram_tester
.ExpectBucketCount(
1305 "Autofill.FormEvents.CreditCard",
1306 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE
, 0);
1310 // Test that we log selected form event for credit cards.
1311 TEST_F(AutofillMetricsTest
, CreditCardSelectedFormEvents
) {
1313 // Creating all kinds of cards.
1314 personal_data_
->RecreateCreditCards(
1315 true /* include_local_credit_card */,
1316 true /* include_masked_server_credit_card */,
1317 true /* include_full_server_credit_card */);
1318 // Set up our form data.
1320 form
.name
= ASCIIToUTF16("TestForm");
1321 form
.origin
= GURL("http://example.com/form.html");
1322 form
.action
= GURL("http://example.com/submit.html");
1324 FormFieldData field
;
1325 std::vector
<ServerFieldType
> field_types
;
1326 test::CreateTestFormField("Month", "card_month", "", "text", &field
);
1327 form
.fields
.push_back(field
);
1328 field_types
.push_back(CREDIT_CARD_EXP_MONTH
);
1329 test::CreateTestFormField("Year", "card_year", "", "text", &field
);
1330 form
.fields
.push_back(field
);
1331 field_types
.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR
);
1332 test::CreateTestFormField("Credit card", "card", "", "text", &field
);
1333 form
.fields
.push_back(field
);
1334 field_types
.push_back(CREDIT_CARD_NUMBER
);
1336 // Simulate having seen this form on page load.
1337 // |form_structure| will be owned by |autofill_manager_|.
1338 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1341 // Simulating selecting a masked card server suggestion.
1342 base::HistogramTester histogram_tester
;
1344 "10000000-0000-0000-0000-000000000002"); // masked server card
1345 autofill_manager_
->FillOrPreviewForm(
1346 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
[2],
1347 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1348 histogram_tester
.ExpectBucketCount(
1349 "Autofill.FormEvents.CreditCard",
1350 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED
, 1);
1351 histogram_tester
.ExpectBucketCount(
1352 "Autofill.FormEvents.CreditCard",
1353 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED_ONCE
,
1357 // Reset the autofill manager state.
1358 autofill_manager_
->Reset();
1359 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1362 // Simulating selecting multiple times a masked card server.
1363 base::HistogramTester histogram_tester
;
1365 "10000000-0000-0000-0000-000000000002"); // masked server card
1366 autofill_manager_
->FillOrPreviewForm(
1367 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
[2],
1368 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1369 autofill_manager_
->FillOrPreviewForm(
1370 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
[2],
1371 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1372 histogram_tester
.ExpectBucketCount(
1373 "Autofill.FormEvents.CreditCard",
1374 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED
, 2);
1375 histogram_tester
.ExpectBucketCount(
1376 "Autofill.FormEvents.CreditCard",
1377 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED_ONCE
,
1382 // Test that we log filled form events for credit cards.
1383 TEST_F(AutofillMetricsTest
, CreditCardFilledFormEvents
) {
1384 autofill_client_
.GetPrefs()->SetBoolean(
1385 prefs::kAutofillWalletSyncExperimentEnabled
, true);
1386 // Creating all kinds of cards.
1387 personal_data_
->RecreateCreditCards(
1388 true /* include_local_credit_card */,
1389 true /* include_masked_server_credit_card */,
1390 true /* include_full_server_credit_card */);
1391 // Set up our form data.
1393 form
.name
= ASCIIToUTF16("TestForm");
1394 form
.origin
= GURL("http://example.com/form.html");
1395 form
.action
= GURL("http://example.com/submit.html");
1397 FormFieldData field
;
1398 std::vector
<ServerFieldType
> field_types
;
1399 test::CreateTestFormField("Month", "card_month", "", "text", &field
);
1400 form
.fields
.push_back(field
);
1401 field_types
.push_back(CREDIT_CARD_EXP_MONTH
);
1402 test::CreateTestFormField("Year", "card_year", "", "text", &field
);
1403 form
.fields
.push_back(field
);
1404 field_types
.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR
);
1405 test::CreateTestFormField("Credit card", "card", "", "text", &field
);
1406 form
.fields
.push_back(field
);
1407 field_types
.push_back(CREDIT_CARD_NUMBER
);
1409 // Simulate having seen this form on page load.
1410 // |form_structure| will be owned by |autofill_manager_|.
1411 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1414 // Simulating filling a local card suggestion.
1415 base::HistogramTester histogram_tester
;
1416 std::string
guid("10000000-0000-0000-0000-000000000001"); // local card
1417 autofill_manager_
->FillOrPreviewForm(
1418 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1419 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1420 histogram_tester
.ExpectBucketCount(
1421 "Autofill.FormEvents.CreditCard",
1422 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED
, 1);
1423 histogram_tester
.ExpectBucketCount(
1424 "Autofill.FormEvents.CreditCard",
1425 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE
, 1);
1428 // Reset the autofill manager state.
1429 autofill_manager_
->Reset();
1430 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1433 // Simulating filling a masked card server suggestion.
1434 base::HistogramTester histogram_tester
;
1436 "10000000-0000-0000-0000-000000000002"); // masked server card
1437 autofill_manager_
->FillOrPreviewForm(
1438 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1439 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1440 autofill_manager_
->OnDidGetRealPan(AutofillClient::SUCCESS
,
1441 "6011000990139424");
1442 histogram_tester
.ExpectBucketCount(
1443 "Autofill.FormEvents.CreditCard",
1444 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED
, 1);
1445 histogram_tester
.ExpectBucketCount(
1446 "Autofill.FormEvents.CreditCard",
1447 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE
,
1451 // Recreating cards as the previous test should have upgraded the masked
1452 // card to a full card.
1453 personal_data_
->RecreateCreditCards(
1454 true /* include_local_credit_card */,
1455 true /* include_masked_server_credit_card */,
1456 true /* include_full_server_credit_card */);
1458 // Reset the autofill manager state.
1459 autofill_manager_
->Reset();
1460 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1463 // Simulating filling a full card server suggestion.
1464 base::HistogramTester histogram_tester
;
1466 "10000000-0000-0000-0000-000000000003"); // full server card
1467 autofill_manager_
->FillOrPreviewForm(
1468 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1469 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1470 histogram_tester
.ExpectBucketCount(
1471 "Autofill.FormEvents.CreditCard",
1472 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED
, 1);
1473 histogram_tester
.ExpectBucketCount(
1474 "Autofill.FormEvents.CreditCard",
1475 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE
, 1);
1478 // Reset the autofill manager state.
1479 autofill_manager_
->Reset();
1480 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1483 // Simulating filling multiple times.
1484 base::HistogramTester histogram_tester
;
1485 std::string
guid("10000000-0000-0000-0000-000000000001"); // local card
1486 autofill_manager_
->FillOrPreviewForm(
1487 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1488 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1489 autofill_manager_
->FillOrPreviewForm(
1490 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1491 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1492 histogram_tester
.ExpectBucketCount(
1493 "Autofill.FormEvents.CreditCard",
1494 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED
, 2);
1495 histogram_tester
.ExpectBucketCount(
1496 "Autofill.FormEvents.CreditCard",
1497 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE
, 1);
1501 // Test that we log submitted form events for credit cards.
1502 TEST_F(AutofillMetricsTest
, CreditCardGetRealPanDuration
) {
1504 // Creating masked card
1505 personal_data_
->RecreateCreditCards(
1506 false /* include_local_credit_card */,
1507 true /* include_masked_server_credit_card */,
1508 false /* include_full_server_credit_card */);
1509 // Set up our form data.
1511 form
.name
= ASCIIToUTF16("TestForm");
1512 form
.origin
= GURL("http://example.com/form.html");
1513 form
.action
= GURL("http://example.com/submit.html");
1515 FormFieldData field
;
1516 std::vector
<ServerFieldType
> field_types
;
1517 test::CreateTestFormField("Month", "card_month", "", "text", &field
);
1518 form
.fields
.push_back(field
);
1519 field_types
.push_back(CREDIT_CARD_EXP_MONTH
);
1520 test::CreateTestFormField("Year", "card_year", "", "text", &field
);
1521 form
.fields
.push_back(field
);
1522 field_types
.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR
);
1523 test::CreateTestFormField("Credit card", "card", "", "text", &field
);
1524 form
.fields
.push_back(field
);
1525 field_types
.push_back(CREDIT_CARD_NUMBER
);
1527 // Simulate having seen this form on page load.
1528 // |form_structure| will be owned by |autofill_manager_|.
1529 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1532 // Simulating filling a masked card server suggestion.
1533 base::HistogramTester histogram_tester
;
1534 // Masked server card.
1535 std::string
guid("10000000-0000-0000-0000-000000000002");
1536 autofill_manager_
->FillOrPreviewForm(
1537 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1538 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1539 autofill_manager_
->OnDidGetRealPan(AutofillClient::SUCCESS
,
1540 "6011000990139424");
1541 histogram_tester
.ExpectTotalCount(
1542 "Autofill.UnmaskPrompt.GetRealPanDuration", 1);
1543 histogram_tester
.ExpectTotalCount(
1544 "Autofill.UnmaskPrompt.GetRealPanDuration.Success", 1);
1547 // Reset the autofill manager state.
1548 autofill_manager_
->Reset();
1549 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1550 // Creating masked card
1551 personal_data_
->RecreateCreditCards(
1552 false /* include_local_credit_card */,
1553 true /* include_masked_server_credit_card */,
1554 false /* include_full_server_credit_card */);
1557 // Simulating filling a masked card server suggestion.
1558 base::HistogramTester histogram_tester
;
1559 // Masked server card.
1560 std::string
guid("10000000-0000-0000-0000-000000000002");
1561 autofill_manager_
->FillOrPreviewForm(
1562 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1563 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1564 autofill_manager_
->OnDidGetRealPan(AutofillClient::PERMANENT_FAILURE
,
1566 histogram_tester
.ExpectTotalCount(
1567 "Autofill.UnmaskPrompt.GetRealPanDuration", 1);
1568 histogram_tester
.ExpectTotalCount(
1569 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1);
1573 // Test that we log submitted form events for credit cards.
1574 TEST_F(AutofillMetricsTest
, CreditCardSubmittedFormEvents
) {
1576 // Creating all kinds of cards.
1577 personal_data_
->RecreateCreditCards(
1578 true /* include_local_credit_card */,
1579 true /* include_masked_server_credit_card */,
1580 true /* include_full_server_credit_card */);
1581 // Set up our form data.
1583 form
.name
= ASCIIToUTF16("TestForm");
1584 form
.origin
= GURL("http://example.com/form.html");
1585 form
.action
= GURL("http://example.com/submit.html");
1587 FormFieldData field
;
1588 std::vector
<ServerFieldType
> field_types
;
1589 test::CreateTestFormField("Month", "card_month", "", "text", &field
);
1590 form
.fields
.push_back(field
);
1591 field_types
.push_back(CREDIT_CARD_EXP_MONTH
);
1592 test::CreateTestFormField("Year", "card_year", "", "text", &field
);
1593 form
.fields
.push_back(field
);
1594 field_types
.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR
);
1595 test::CreateTestFormField("Credit card", "card", "", "text", &field
);
1596 form
.fields
.push_back(field
);
1597 field_types
.push_back(CREDIT_CARD_NUMBER
);
1599 // Simulate having seen this form on page load.
1600 // |form_structure| will be owned by |autofill_manager_|.
1601 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1604 // Simulating submission with no filled data.
1605 base::HistogramTester histogram_tester
;
1606 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1607 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
1608 histogram_tester
.ExpectBucketCount(
1609 "Autofill.FormEvents.CreditCard",
1610 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
1611 histogram_tester
.ExpectBucketCount(
1612 "Autofill.FormEvents.CreditCard",
1613 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 1);
1616 // Reset the autofill manager state.
1617 autofill_manager_
->Reset();
1618 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1621 // Simulating submission with filled local data.
1622 base::HistogramTester histogram_tester
;
1623 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1624 std::string
guid("10000000-0000-0000-0000-000000000001"); // local card
1625 autofill_manager_
->FillOrPreviewForm(
1626 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1627 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1628 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
1629 histogram_tester
.ExpectBucketCount(
1630 "Autofill.FormEvents.CreditCard",
1631 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
1632 histogram_tester
.ExpectBucketCount(
1633 "Autofill.FormEvents.CreditCard",
1634 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE
, 1);
1637 // Reset the autofill manager state.
1638 autofill_manager_
->Reset();
1639 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1642 // Simulating submission with filled server data.
1643 base::HistogramTester histogram_tester
;
1644 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1646 "10000000-0000-0000-0000-000000000003"); // full server card
1647 autofill_manager_
->FillOrPreviewForm(
1648 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1649 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1650 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
1651 histogram_tester
.ExpectBucketCount(
1652 "Autofill.FormEvents.CreditCard",
1653 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
1654 histogram_tester
.ExpectBucketCount(
1655 "Autofill.FormEvents.CreditCard",
1656 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 1);
1659 // Reset the autofill manager state.
1660 autofill_manager_
->Reset();
1661 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1664 // Simulating submission with a masked card server suggestion.
1665 base::HistogramTester histogram_tester
;
1667 "10000000-0000-0000-0000-000000000002"); // masked server card
1668 autofill_manager_
->FillOrPreviewForm(
1669 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1670 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1671 autofill_manager_
->OnDidGetRealPan(AutofillClient::SUCCESS
,
1672 "6011000990139424");
1673 histogram_tester
.ExpectBucketCount(
1674 "Autofill.FormEvents.CreditCard",
1675 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED
, 1);
1676 histogram_tester
.ExpectBucketCount(
1677 "Autofill.FormEvents.CreditCard",
1678 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE
,
1682 // Recreating cards as the previous test should have upgraded the masked
1683 // card to a full card.
1684 personal_data_
->RecreateCreditCards(
1685 true /* include_local_credit_card */,
1686 true /* include_masked_server_credit_card */,
1687 true /* include_full_server_credit_card */);
1689 // Reset the autofill manager state.
1690 autofill_manager_
->Reset();
1691 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1694 // Simulating multiple submissions.
1695 base::HistogramTester histogram_tester
;
1696 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1697 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
1698 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
1699 histogram_tester
.ExpectBucketCount(
1700 "Autofill.FormEvents.CreditCard",
1701 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
1702 histogram_tester
.ExpectBucketCount(
1703 "Autofill.FormEvents.CreditCard",
1704 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
1705 histogram_tester
.ExpectBucketCount(
1706 "Autofill.FormEvents.CreditCard",
1707 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
1708 histogram_tester
.ExpectBucketCount(
1709 "Autofill.FormEvents.CreditCard",
1711 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE
,
1713 histogram_tester
.ExpectBucketCount(
1714 "Autofill.FormEvents.CreditCard",
1715 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 1);
1716 histogram_tester
.ExpectBucketCount(
1717 "Autofill.FormEvents.CreditCard",
1718 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE
, 0);
1719 histogram_tester
.ExpectBucketCount(
1720 "Autofill.FormEvents.CreditCard",
1721 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
1722 histogram_tester
.ExpectBucketCount(
1723 "Autofill.FormEvents.CreditCard",
1725 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE
,
1729 // Reset the autofill manager state.
1730 autofill_manager_
->Reset();
1731 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1734 // Simulating submission without previous interaction.
1735 base::HistogramTester histogram_tester
;
1736 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
1737 histogram_tester
.ExpectBucketCount(
1738 "Autofill.FormEvents.CreditCard",
1739 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
1740 histogram_tester
.ExpectBucketCount(
1741 "Autofill.FormEvents.CreditCard",
1742 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
1743 histogram_tester
.ExpectBucketCount(
1744 "Autofill.FormEvents.CreditCard",
1745 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
1746 histogram_tester
.ExpectBucketCount(
1747 "Autofill.FormEvents.CreditCard",
1748 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 0);
1749 histogram_tester
.ExpectBucketCount(
1750 "Autofill.FormEvents.CreditCard",
1751 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
1752 histogram_tester
.ExpectBucketCount(
1753 "Autofill.FormEvents.CreditCard",
1754 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
1758 // Test that we log "will submit" (but not submitted) form events for credit
1759 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any
1760 // "submitted" metrics.
1761 TEST_F(AutofillMetricsTest
, CreditCardWillSubmitFormEvents
) {
1763 // Creating all kinds of cards.
1764 personal_data_
->RecreateCreditCards(
1765 true /* include_local_credit_card */,
1766 true /* include_masked_server_credit_card */,
1767 true /* include_full_server_credit_card */);
1768 // Set up our form data.
1770 form
.name
= ASCIIToUTF16("TestForm");
1771 form
.origin
= GURL("http://example.com/form.html");
1772 form
.action
= GURL("http://example.com/submit.html");
1774 FormFieldData field
;
1775 std::vector
<ServerFieldType
> field_types
;
1776 test::CreateTestFormField("Month", "card_month", "", "text", &field
);
1777 form
.fields
.push_back(field
);
1778 field_types
.push_back(CREDIT_CARD_EXP_MONTH
);
1779 test::CreateTestFormField("Year", "card_year", "", "text", &field
);
1780 form
.fields
.push_back(field
);
1781 field_types
.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR
);
1782 test::CreateTestFormField("Credit card", "card", "", "text", &field
);
1783 form
.fields
.push_back(field
);
1784 field_types
.push_back(CREDIT_CARD_NUMBER
);
1786 // Simulate having seen this form on page load.
1787 // |form_structure| will be owned by |autofill_manager_|.
1788 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1791 // Simulating submission with no filled data.
1792 base::HistogramTester histogram_tester
;
1793 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1794 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
1795 histogram_tester
.ExpectBucketCount(
1796 "Autofill.FormEvents.CreditCard",
1797 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
1798 histogram_tester
.ExpectBucketCount(
1799 "Autofill.FormEvents.CreditCard",
1800 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 0);
1803 // Reset the autofill manager state.
1804 autofill_manager_
->Reset();
1805 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1808 // Simulating submission with filled local data.
1809 base::HistogramTester histogram_tester
;
1810 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1811 std::string
guid("10000000-0000-0000-0000-000000000001"); // local card
1812 autofill_manager_
->FillOrPreviewForm(
1813 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1814 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1815 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
1816 histogram_tester
.ExpectBucketCount(
1817 "Autofill.FormEvents.CreditCard",
1818 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
1819 histogram_tester
.ExpectBucketCount(
1820 "Autofill.FormEvents.CreditCard",
1821 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE
, 0);
1824 // Reset the autofill manager state.
1825 autofill_manager_
->Reset();
1826 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1829 // Simulating submission with filled server data.
1830 base::HistogramTester histogram_tester
;
1831 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1832 // Full server card.
1833 std::string
guid("10000000-0000-0000-0000-000000000003");
1834 autofill_manager_
->FillOrPreviewForm(
1835 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1836 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1837 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
1838 histogram_tester
.ExpectBucketCount(
1839 "Autofill.FormEvents.CreditCard",
1840 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
1841 histogram_tester
.ExpectBucketCount(
1842 "Autofill.FormEvents.CreditCard",
1843 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
1846 // Reset the autofill manager state.
1847 autofill_manager_
->Reset();
1848 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1851 // Simulating submission with a masked card server suggestion.
1852 base::HistogramTester histogram_tester
;
1853 // Masked server card.
1854 std::string
guid("10000000-0000-0000-0000-000000000002");
1855 autofill_manager_
->FillOrPreviewForm(
1856 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
1857 autofill_manager_
->MakeFrontendID(guid
, std::string()));
1858 autofill_manager_
->OnDidGetRealPan(AutofillClient::SUCCESS
,
1859 "6011000990139424");
1860 histogram_tester
.ExpectBucketCount(
1861 "Autofill.FormEvents.CreditCard",
1862 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED
, 1);
1863 histogram_tester
.ExpectBucketCount(
1864 "Autofill.FormEvents.CreditCard",
1865 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE
,
1869 // Recreating cards as the previous test should have upgraded the masked
1870 // card to a full card.
1871 personal_data_
->RecreateCreditCards(
1872 true /* include_local_credit_card */,
1873 true /* include_masked_server_credit_card */,
1874 true /* include_full_server_credit_card */);
1876 // Reset the autofill manager state.
1877 autofill_manager_
->Reset();
1878 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1881 // Simulating multiple submissions.
1882 base::HistogramTester histogram_tester
;
1883 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1884 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
1885 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
1886 histogram_tester
.ExpectBucketCount(
1887 "Autofill.FormEvents.CreditCard",
1888 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
1889 histogram_tester
.ExpectBucketCount(
1890 "Autofill.FormEvents.CreditCard",
1891 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
1892 histogram_tester
.ExpectBucketCount(
1893 "Autofill.FormEvents.CreditCard",
1894 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
1895 histogram_tester
.ExpectBucketCount(
1896 "Autofill.FormEvents.CreditCard",
1898 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE
,
1900 histogram_tester
.ExpectBucketCount(
1901 "Autofill.FormEvents.CreditCard",
1902 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 0);
1903 histogram_tester
.ExpectBucketCount(
1904 "Autofill.FormEvents.CreditCard",
1905 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE
, 0);
1906 histogram_tester
.ExpectBucketCount(
1907 "Autofill.FormEvents.CreditCard",
1908 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
1909 histogram_tester
.ExpectBucketCount(
1910 "Autofill.FormEvents.CreditCard",
1912 ::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE
,
1916 // Reset the autofill manager state.
1917 autofill_manager_
->Reset();
1918 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1921 // Simulating submission without previous interaction.
1922 base::HistogramTester histogram_tester
;
1923 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
1924 histogram_tester
.ExpectBucketCount(
1925 "Autofill.FormEvents.CreditCard",
1926 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
1927 histogram_tester
.ExpectBucketCount(
1928 "Autofill.FormEvents.CreditCard",
1929 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
1930 histogram_tester
.ExpectBucketCount(
1931 "Autofill.FormEvents.CreditCard",
1932 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
1933 histogram_tester
.ExpectBucketCount(
1934 "Autofill.FormEvents.CreditCard",
1935 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 0);
1936 histogram_tester
.ExpectBucketCount(
1937 "Autofill.FormEvents.CreditCard",
1938 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
1939 histogram_tester
.ExpectBucketCount(
1940 "Autofill.FormEvents.CreditCard",
1941 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
1945 // Test that we log interacted form events for address.
1946 TEST_F(AutofillMetricsTest
, AddressInteractedFormEvents
) {
1947 // Set up our form data.
1949 form
.name
= ASCIIToUTF16("TestForm");
1950 form
.origin
= GURL("http://example.com/form.html");
1951 form
.action
= GURL("http://example.com/submit.html");
1953 FormFieldData field
;
1954 std::vector
<ServerFieldType
> field_types
;
1955 test::CreateTestFormField("State", "state", "", "text", &field
);
1956 form
.fields
.push_back(field
);
1957 field_types
.push_back(ADDRESS_HOME_STATE
);
1958 test::CreateTestFormField("City", "city", "", "text", &field
);
1959 form
.fields
.push_back(field
);
1960 field_types
.push_back(ADDRESS_HOME_CITY
);
1961 test::CreateTestFormField("Street", "street", "", "text", &field
);
1962 form
.fields
.push_back(field
);
1963 field_types
.push_back(ADDRESS_HOME_STREET_ADDRESS
);
1965 // Simulate having seen this form on page load.
1966 // |form_structure| will be owned by |autofill_manager_|.
1967 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1970 // Simulate activating the autofill popup for the street field.
1971 base::HistogramTester histogram_tester
;
1972 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1973 histogram_tester
.ExpectUniqueSample(
1974 "Autofill.FormEvents.Address",
1975 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
1978 // Reset the autofill manager state.
1979 autofill_manager_
->Reset();
1980 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
1983 // Simulate activating the autofill popup for the street field twice.
1984 base::HistogramTester histogram_tester
;
1985 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
1986 autofill_manager_
->OnQueryFormFieldAutofill(1, form
, field
, gfx::Rect());
1987 histogram_tester
.ExpectUniqueSample(
1988 "Autofill.FormEvents.Address",
1989 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
1993 // Test that we log suggestion shown form events for address.
1994 TEST_F(AutofillMetricsTest
, AddressShownFormEvents
) {
1996 // Creating all kinds of profiles.
1997 personal_data_
->RecreateProfiles(true /* include_local_profile */,
1998 true /* include_server_profile */);
1999 // Set up our form data.
2001 form
.name
= ASCIIToUTF16("TestForm");
2002 form
.origin
= GURL("http://example.com/form.html");
2003 form
.action
= GURL("http://example.com/submit.html");
2005 FormFieldData field
;
2006 std::vector
<ServerFieldType
> field_types
;
2007 test::CreateTestFormField("State", "state", "", "text", &field
);
2008 form
.fields
.push_back(field
);
2009 field_types
.push_back(ADDRESS_HOME_STATE
);
2010 test::CreateTestFormField("City", "city", "", "text", &field
);
2011 form
.fields
.push_back(field
);
2012 field_types
.push_back(ADDRESS_HOME_CITY
);
2013 test::CreateTestFormField("Street", "street", "", "text", &field
);
2014 form
.fields
.push_back(field
);
2015 field_types
.push_back(ADDRESS_HOME_STREET_ADDRESS
);
2017 // Simulate having seen this form on page load.
2018 // |form_structure| will be owned by |autofill_manager_|.
2019 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2022 // Simulating new popup being shown.
2023 base::HistogramTester histogram_tester
;
2024 autofill_manager_
->DidShowSuggestions(true /* is_new_popup */, form
, field
);
2025 histogram_tester
.ExpectBucketCount(
2026 "Autofill.FormEvents.Address",
2027 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN
, 1);
2028 histogram_tester
.ExpectBucketCount(
2029 "Autofill.FormEvents.Address",
2030 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE
, 1);
2033 // Reset the autofill manager state.
2034 autofill_manager_
->Reset();
2035 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2038 // Simulating two popups in the same page load.
2039 base::HistogramTester histogram_tester
;
2040 autofill_manager_
->DidShowSuggestions(true /* is_new_popup */, form
, field
);
2041 autofill_manager_
->DidShowSuggestions(true /* is_new_popup */, form
, field
);
2042 histogram_tester
.ExpectBucketCount(
2043 "Autofill.FormEvents.Address",
2044 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN
, 2);
2045 histogram_tester
.ExpectBucketCount(
2046 "Autofill.FormEvents.Address",
2047 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE
, 1);
2050 // Reset the autofill manager state.
2051 autofill_manager_
->Reset();
2052 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2055 // Simulating same popup being refreshed.
2056 base::HistogramTester histogram_tester
;
2057 autofill_manager_
->DidShowSuggestions(false /* is_new_popup */, form
,
2059 histogram_tester
.ExpectBucketCount(
2060 "Autofill.FormEvents.Address",
2061 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN
, 0);
2062 histogram_tester
.ExpectBucketCount(
2063 "Autofill.FormEvents.Address",
2064 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE
, 0);
2068 // Test that we log filled form events for address.
2069 TEST_F(AutofillMetricsTest
, AddressFilledFormEvents
) {
2071 // Creating all kinds of profiles.
2072 personal_data_
->RecreateProfiles(true /* include_local_profile */,
2073 true /* include_server_profile */);
2074 // Set up our form data.
2076 form
.name
= ASCIIToUTF16("TestForm");
2077 form
.origin
= GURL("http://example.com/form.html");
2078 form
.action
= GURL("http://example.com/submit.html");
2080 FormFieldData field
;
2081 std::vector
<ServerFieldType
> field_types
;
2082 test::CreateTestFormField("State", "state", "", "text", &field
);
2083 form
.fields
.push_back(field
);
2084 field_types
.push_back(ADDRESS_HOME_STATE
);
2085 test::CreateTestFormField("City", "city", "", "text", &field
);
2086 form
.fields
.push_back(field
);
2087 field_types
.push_back(ADDRESS_HOME_CITY
);
2088 test::CreateTestFormField("Street", "street", "", "text", &field
);
2089 form
.fields
.push_back(field
);
2090 field_types
.push_back(ADDRESS_HOME_STREET_ADDRESS
);
2092 // Simulate having seen this form on page load.
2093 // |form_structure| will be owned by |autofill_manager_|.
2094 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2097 // Simulating selecting/filling a local profile suggestion.
2098 base::HistogramTester histogram_tester
;
2099 std::string
guid("00000000-0000-0000-0000-000000000001"); // local profile
2100 autofill_manager_
->FillOrPreviewForm(
2101 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
2102 autofill_manager_
->MakeFrontendID(std::string(), guid
));
2103 histogram_tester
.ExpectBucketCount(
2104 "Autofill.FormEvents.Address",
2105 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED
, 1);
2106 histogram_tester
.ExpectBucketCount(
2107 "Autofill.FormEvents.Address",
2108 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE
, 1);
2111 // Reset the autofill manager state.
2112 autofill_manager_
->Reset();
2113 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2116 // Simulating selecting/filling a server profile suggestion.
2117 base::HistogramTester histogram_tester
;
2118 std::string
guid("00000000-0000-0000-0000-000000000002"); // server profile
2119 autofill_manager_
->FillOrPreviewForm(
2120 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
2121 autofill_manager_
->MakeFrontendID(std::string(), guid
));
2122 histogram_tester
.ExpectBucketCount(
2123 "Autofill.FormEvents.Address",
2124 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED
, 1);
2125 histogram_tester
.ExpectBucketCount(
2126 "Autofill.FormEvents.Address",
2127 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE
, 1);
2130 // Reset the autofill manager state.
2131 autofill_manager_
->Reset();
2132 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2135 // Simulating selecting/filling a local profile suggestion.
2136 base::HistogramTester histogram_tester
;
2137 std::string
guid("00000000-0000-0000-0000-000000000001"); // local profile
2138 autofill_manager_
->FillOrPreviewForm(
2139 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
2140 autofill_manager_
->MakeFrontendID(std::string(), guid
));
2141 autofill_manager_
->FillOrPreviewForm(
2142 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
2143 autofill_manager_
->MakeFrontendID(std::string(), guid
));
2144 histogram_tester
.ExpectBucketCount(
2145 "Autofill.FormEvents.Address",
2146 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED
, 2);
2147 histogram_tester
.ExpectBucketCount(
2148 "Autofill.FormEvents.Address",
2149 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE
, 1);
2153 // Test that we log submitted form events for address.
2154 TEST_F(AutofillMetricsTest
, AddressSubmittedFormEvents
) {
2156 // Creating all kinds of profiles.
2157 personal_data_
->RecreateProfiles(true /* include_local_profile */,
2158 true /* include_server_profile */);
2159 // Set up our form data.
2161 form
.name
= ASCIIToUTF16("TestForm");
2162 form
.origin
= GURL("http://example.com/form.html");
2163 form
.action
= GURL("http://example.com/submit.html");
2165 FormFieldData field
;
2166 std::vector
<ServerFieldType
> field_types
;
2167 test::CreateTestFormField("State", "state", "", "text", &field
);
2168 form
.fields
.push_back(field
);
2169 field_types
.push_back(ADDRESS_HOME_STATE
);
2170 test::CreateTestFormField("City", "city", "", "text", &field
);
2171 form
.fields
.push_back(field
);
2172 field_types
.push_back(ADDRESS_HOME_CITY
);
2173 test::CreateTestFormField("Street", "street", "", "text", &field
);
2174 form
.fields
.push_back(field
);
2175 field_types
.push_back(ADDRESS_HOME_STREET_ADDRESS
);
2177 // Simulate having seen this form on page load.
2178 // |form_structure| will be owned by |autofill_manager_|.
2179 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2182 // Simulating submission with no filled data.
2183 base::HistogramTester histogram_tester
;
2184 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2185 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2186 histogram_tester
.ExpectBucketCount(
2187 "Autofill.FormEvents.Address",
2188 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
2189 histogram_tester
.ExpectBucketCount(
2190 "Autofill.FormEvents.Address",
2191 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 1);
2194 // Reset the autofill manager state.
2195 autofill_manager_
->Reset();
2196 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2199 // Simulating submission with filled local data.
2200 base::HistogramTester histogram_tester
;
2201 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2202 std::string
guid("00000000-0000-0000-0000-000000000001"); // local profile
2203 autofill_manager_
->FillOrPreviewForm(
2204 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
2205 autofill_manager_
->MakeFrontendID(std::string(), guid
));
2206 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2207 histogram_tester
.ExpectBucketCount(
2208 "Autofill.FormEvents.Address",
2209 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
2210 histogram_tester
.ExpectBucketCount(
2211 "Autofill.FormEvents.Address",
2212 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE
, 1);
2215 // Reset the autofill manager state.
2216 autofill_manager_
->Reset();
2217 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2220 // Simulating submission with filled server data.
2221 base::HistogramTester histogram_tester
;
2222 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2223 std::string
guid("00000000-0000-0000-0000-000000000002"); // server profile
2224 autofill_manager_
->FillOrPreviewForm(
2225 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
2226 autofill_manager_
->MakeFrontendID(std::string(), guid
));
2227 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2228 histogram_tester
.ExpectBucketCount(
2229 "Autofill.FormEvents.Address",
2230 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
2231 histogram_tester
.ExpectBucketCount(
2232 "Autofill.FormEvents.Address",
2233 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 1);
2236 // Reset the autofill manager state.
2237 autofill_manager_
->Reset();
2238 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2241 // Simulating multiple submissions.
2242 base::HistogramTester histogram_tester
;
2243 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2244 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2245 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2246 histogram_tester
.ExpectBucketCount(
2247 "Autofill.FormEvents.Address",
2248 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
2249 histogram_tester
.ExpectBucketCount(
2250 "Autofill.FormEvents.Address",
2251 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
2252 histogram_tester
.ExpectBucketCount(
2253 "Autofill.FormEvents.Address",
2254 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
2255 histogram_tester
.ExpectBucketCount(
2256 "Autofill.FormEvents.Address",
2257 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 1);
2258 histogram_tester
.ExpectBucketCount(
2259 "Autofill.FormEvents.Address",
2260 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE
, 0);
2261 histogram_tester
.ExpectBucketCount(
2262 "Autofill.FormEvents.Address",
2263 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
2266 // Reset the autofill manager state.
2267 autofill_manager_
->Reset();
2268 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2271 // Simulating submission without previous interaction.
2272 base::HistogramTester histogram_tester
;
2273 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2274 histogram_tester
.ExpectBucketCount(
2275 "Autofill.FormEvents.Address",
2276 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
2277 histogram_tester
.ExpectBucketCount(
2278 "Autofill.FormEvents.Address",
2279 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
2280 histogram_tester
.ExpectBucketCount(
2281 "Autofill.FormEvents.Address",
2282 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
2283 histogram_tester
.ExpectBucketCount(
2284 "Autofill.FormEvents.Address",
2285 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 0);
2286 histogram_tester
.ExpectBucketCount(
2287 "Autofill.FormEvents.Address",
2288 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE
, 0);
2289 histogram_tester
.ExpectBucketCount(
2290 "Autofill.FormEvents.Address",
2291 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
2295 // Test that we log "will submit" (but not submitted) form events for address.
2296 // Mirrors AddressSubmittedFormEvents test but does not expect any "submitted"
2298 TEST_F(AutofillMetricsTest
, AddressWillSubmitFormEvents
) {
2300 // Creating all kinds of profiles.
2301 personal_data_
->RecreateProfiles(true /* include_local_profile */,
2302 true /* include_server_profile */);
2303 // Set up our form data.
2305 form
.name
= ASCIIToUTF16("TestForm");
2306 form
.origin
= GURL("http://example.com/form.html");
2307 form
.action
= GURL("http://example.com/submit.html");
2309 FormFieldData field
;
2310 std::vector
<ServerFieldType
> field_types
;
2311 test::CreateTestFormField("State", "state", "", "text", &field
);
2312 form
.fields
.push_back(field
);
2313 field_types
.push_back(ADDRESS_HOME_STATE
);
2314 test::CreateTestFormField("City", "city", "", "text", &field
);
2315 form
.fields
.push_back(field
);
2316 field_types
.push_back(ADDRESS_HOME_CITY
);
2317 test::CreateTestFormField("Street", "street", "", "text", &field
);
2318 form
.fields
.push_back(field
);
2319 field_types
.push_back(ADDRESS_HOME_STREET_ADDRESS
);
2321 // Simulate having seen this form on page load.
2322 // |form_structure| will be owned by |autofill_manager_|.
2323 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2326 // Simulating submission with no filled data.
2327 base::HistogramTester histogram_tester
;
2328 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2329 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
2330 histogram_tester
.ExpectBucketCount(
2331 "Autofill.FormEvents.Address",
2332 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
2333 histogram_tester
.ExpectBucketCount(
2334 "Autofill.FormEvents.Address",
2335 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 0);
2338 // Reset the autofill manager state.
2339 autofill_manager_
->Reset();
2340 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2343 // Simulating submission with filled local data.
2344 base::HistogramTester histogram_tester
;
2345 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2346 std::string
guid("00000000-0000-0000-0000-000000000001"); // local profile
2347 autofill_manager_
->FillOrPreviewForm(
2348 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
2349 autofill_manager_
->MakeFrontendID(std::string(), guid
));
2350 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
2351 histogram_tester
.ExpectBucketCount(
2352 "Autofill.FormEvents.Address",
2353 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
2354 histogram_tester
.ExpectBucketCount(
2355 "Autofill.FormEvents.Address",
2356 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE
, 0);
2359 // Reset the autofill manager state.
2360 autofill_manager_
->Reset();
2361 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2364 // Simulating submission with filled server data.
2365 base::HistogramTester histogram_tester
;
2366 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2367 std::string
guid("00000000-0000-0000-0000-000000000002"); // server profile
2368 autofill_manager_
->FillOrPreviewForm(
2369 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
2370 autofill_manager_
->MakeFrontendID(std::string(), guid
));
2371 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
2372 histogram_tester
.ExpectBucketCount(
2373 "Autofill.FormEvents.Address",
2374 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
2375 histogram_tester
.ExpectBucketCount(
2376 "Autofill.FormEvents.Address",
2377 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
2380 // Reset the autofill manager state.
2381 autofill_manager_
->Reset();
2382 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2385 // Simulating multiple submissions.
2386 base::HistogramTester histogram_tester
;
2387 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2388 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
2389 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
2390 histogram_tester
.ExpectBucketCount(
2391 "Autofill.FormEvents.Address",
2392 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 1);
2393 histogram_tester
.ExpectBucketCount(
2394 "Autofill.FormEvents.Address",
2395 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 0);
2396 histogram_tester
.ExpectBucketCount(
2397 "Autofill.FormEvents.Address",
2398 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE
, 0);
2399 histogram_tester
.ExpectBucketCount(
2400 "Autofill.FormEvents.Address",
2401 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
2404 // Reset the autofill manager state.
2405 autofill_manager_
->Reset();
2406 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2409 // Simulating submission without previous interaction.
2410 base::HistogramTester histogram_tester
;
2411 autofill_manager_
->WillSubmitForm(form
, TimeTicks::Now());
2412 histogram_tester
.ExpectBucketCount(
2413 "Autofill.FormEvents.Address",
2414 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
2415 histogram_tester
.ExpectBucketCount(
2416 "Autofill.FormEvents.Address",
2417 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
2418 histogram_tester
.ExpectBucketCount(
2419 "Autofill.FormEvents.Address",
2420 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE
, 0);
2421 histogram_tester
.ExpectBucketCount(
2422 "Autofill.FormEvents.Address",
2423 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE
, 0);
2424 histogram_tester
.ExpectBucketCount(
2425 "Autofill.FormEvents.Address",
2426 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE
, 0);
2427 histogram_tester
.ExpectBucketCount(
2428 "Autofill.FormEvents.Address",
2429 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE
, 0);
2433 // Test that we log interacted form event for credit cards only once.
2434 TEST_F(AutofillMetricsTest
, CreditCardFormEventsAreSegmented
) {
2437 // Set up our form data.
2439 form
.name
= ASCIIToUTF16("TestForm");
2440 form
.origin
= GURL("http://example.com/form.html");
2441 form
.action
= GURL("http://example.com/submit.html");
2443 FormFieldData field
;
2444 std::vector
<ServerFieldType
> field_types
;
2445 test::CreateTestFormField("Month", "card_month", "", "text", &field
);
2446 form
.fields
.push_back(field
);
2447 field_types
.push_back(CREDIT_CARD_EXP_MONTH
);
2448 test::CreateTestFormField("Year", "card_year", "", "text", &field
);
2449 form
.fields
.push_back(field
);
2450 field_types
.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR
);
2451 test::CreateTestFormField("Credit card", "card", "", "text", &field
);
2452 form
.fields
.push_back(field
);
2453 field_types
.push_back(CREDIT_CARD_NUMBER
);
2455 // Simulate having seen this form on page load.
2456 // |form_structure| will be owned by |autofill_manager_|.
2457 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2458 personal_data_
->RecreateCreditCards(
2459 false /* include_local_credit_card */,
2460 false /* include_masked_server_credit_card */,
2461 false /* include_full_server_credit_card */);
2464 // Simulate activating the autofill popup for the credit card field.
2465 base::HistogramTester histogram_tester
;
2466 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2467 histogram_tester
.ExpectUniqueSample(
2468 "Autofill.FormEvents.CreditCard.WithNoData",
2469 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
2472 // Reset the autofill manager state.
2473 autofill_manager_
->Reset();
2474 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2475 personal_data_
->RecreateCreditCards(
2476 true /* include_local_credit_card */,
2477 false /* include_masked_server_credit_card */,
2478 false /* include_full_server_credit_card */);
2481 // Simulate activating the autofill popup for the credit card field.
2482 base::HistogramTester histogram_tester
;
2483 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2484 histogram_tester
.ExpectUniqueSample(
2485 "Autofill.FormEvents.CreditCard.WithOnlyLocalData",
2486 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
2489 // Reset the autofill manager state.
2490 autofill_manager_
->Reset();
2491 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2492 personal_data_
->RecreateCreditCards(
2493 false /* include_local_credit_card */,
2494 true /* include_masked_server_credit_card */,
2495 false /* include_full_server_credit_card */);
2498 // Simulate activating the autofill popup for the credit card field.
2499 base::HistogramTester histogram_tester
;
2500 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2501 histogram_tester
.ExpectUniqueSample(
2502 "Autofill.FormEvents.CreditCard.WithOnlyServerData",
2503 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
2506 // Reset the autofill manager state.
2507 autofill_manager_
->Reset();
2508 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2509 personal_data_
->RecreateCreditCards(
2510 false /* include_local_credit_card */,
2511 false /* include_masked_server_credit_card */,
2512 true /* include_full_server_credit_card */);
2515 // Simulate activating the autofill popup for the credit card field.
2516 base::HistogramTester histogram_tester
;
2517 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2518 histogram_tester
.ExpectUniqueSample(
2519 "Autofill.FormEvents.CreditCard.WithOnlyServerData",
2520 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
2523 // Reset the autofill manager state.
2524 autofill_manager_
->Reset();
2525 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2526 personal_data_
->RecreateCreditCards(
2527 true /* include_local_credit_card */,
2528 false /* include_masked_server_credit_card */,
2529 true /* include_full_server_credit_card */);
2532 // Simulate activating the autofill popup for the credit card field.
2533 base::HistogramTester histogram_tester
;
2534 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2535 histogram_tester
.ExpectUniqueSample(
2536 "Autofill.FormEvents.CreditCard.WithBothServerAndLocalData",
2537 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
2541 // Test that we log interacted form event for address only once.
2542 TEST_F(AutofillMetricsTest
, AddressFormEventsAreSegmented
) {
2545 // Set up our form data.
2547 form
.name
= ASCIIToUTF16("TestForm");
2548 form
.origin
= GURL("http://example.com/form.html");
2549 form
.action
= GURL("http://example.com/submit.html");
2551 FormFieldData field
;
2552 std::vector
<ServerFieldType
> field_types
;
2553 test::CreateTestFormField("State", "state", "", "text", &field
);
2554 form
.fields
.push_back(field
);
2555 field_types
.push_back(ADDRESS_HOME_STATE
);
2556 test::CreateTestFormField("City", "city", "", "text", &field
);
2557 form
.fields
.push_back(field
);
2558 field_types
.push_back(ADDRESS_HOME_CITY
);
2559 test::CreateTestFormField("Street", "street", "", "text", &field
);
2560 form
.fields
.push_back(field
);
2561 field_types
.push_back(ADDRESS_HOME_STREET_ADDRESS
);
2563 // Simulate having seen this form on page load.
2564 // |form_structure| will be owned by |autofill_manager_|.
2565 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2566 personal_data_
->RecreateProfiles(false /* include_local_profile */,
2567 false /* include_server_profile */);
2570 // Simulate activating the autofill popup for the street field.
2571 base::HistogramTester histogram_tester
;
2572 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2573 histogram_tester
.ExpectUniqueSample(
2574 "Autofill.FormEvents.Address.WithNoData",
2575 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
2578 // Reset the autofill manager state.
2579 autofill_manager_
->Reset();
2580 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2581 personal_data_
->RecreateProfiles(true /* include_local_profile */,
2582 false /* include_server_profile */);
2585 // Simulate activating the autofill popup for the street field.
2586 base::HistogramTester histogram_tester
;
2587 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2588 histogram_tester
.ExpectUniqueSample(
2589 "Autofill.FormEvents.Address.WithOnlyLocalData",
2590 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
2593 // Reset the autofill manager state.
2594 autofill_manager_
->Reset();
2595 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2596 personal_data_
->RecreateProfiles(false /* include_local_profile */,
2597 true /* include_server_profile */);
2600 // Simulate activating the autofill popup for the street field.
2601 base::HistogramTester histogram_tester
;
2602 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2603 histogram_tester
.ExpectUniqueSample(
2604 "Autofill.FormEvents.Address.WithOnlyServerData",
2605 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
2608 // Reset the autofill manager state.
2609 autofill_manager_
->Reset();
2610 autofill_manager_
->AddSeenForm(form
, field_types
, field_types
);
2611 personal_data_
->RecreateProfiles(true /* include_local_profile */,
2612 true /* include_server_profile */);
2615 // Simulate activating the autofill popup for the street field.
2616 base::HistogramTester histogram_tester
;
2617 autofill_manager_
->OnQueryFormFieldAutofill(0, form
, field
, gfx::Rect());
2618 histogram_tester
.ExpectUniqueSample(
2619 "Autofill.FormEvents.Address.WithBothServerAndLocalData",
2620 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE
, 1);
2625 // Test that we log that Autofill is enabled when filling a form.
2626 TEST_F(AutofillMetricsTest
, AutofillIsEnabledAtPageLoad
) {
2627 base::HistogramTester histogram_tester
;
2628 autofill_manager_
->set_autofill_enabled(true);
2629 autofill_manager_
->OnFormsSeen(std::vector
<FormData
>(), TimeTicks());
2630 histogram_tester
.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", true, 1);
2633 // Test that we log that Autofill is disabled when filling a form.
2634 TEST_F(AutofillMetricsTest
, AutofillIsDisabledAtPageLoad
) {
2635 base::HistogramTester histogram_tester
;
2636 autofill_manager_
->set_autofill_enabled(false);
2637 autofill_manager_
->OnFormsSeen(std::vector
<FormData
>(), TimeTicks());
2638 histogram_tester
.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", false, 1);
2641 // Verify that we correctly log user happiness metrics dealing with form loading
2642 // and form submission.
2643 TEST_F(AutofillMetricsTest
, UserHappinessFormLoadAndSubmission
) {
2644 // Start with a form with insufficiently many fields.
2646 form
.name
= ASCIIToUTF16("TestForm");
2647 form
.origin
= GURL("http://example.com/form.html");
2648 form
.action
= GURL("http://example.com/submit.html");
2650 FormFieldData field
;
2651 test::CreateTestFormField("Name", "name", "", "text", &field
);
2652 form
.fields
.push_back(field
);
2653 test::CreateTestFormField("Email", "email", "", "text", &field
);
2654 form
.fields
.push_back(field
);
2656 std::vector
<FormData
> forms(1, form
);
2658 // Expect no notifications when the form is first seen.
2660 base::HistogramTester histogram_tester
;
2661 autofill_manager_
->OnFormsSeen(forms
, TimeTicks());
2662 histogram_tester
.ExpectTotalCount("Autofill.UserHappiness", 0);
2666 // Expect no notifications when the form is submitted.
2668 base::HistogramTester histogram_tester
;
2669 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2670 histogram_tester
.ExpectTotalCount("Autofill.UserHappiness", 0);
2673 // Add more fields to the form.
2674 test::CreateTestFormField("Phone", "phone", "", "text", &field
);
2675 form
.fields
.push_back(field
);
2676 test::CreateTestFormField("Unknown", "unknown", "", "text", &field
);
2677 form
.fields
.push_back(field
);
2678 forms
.front() = form
;
2680 // Expect a notification when the form is first seen.
2682 base::HistogramTester histogram_tester
;
2683 autofill_manager_
->OnFormsSeen(forms
, TimeTicks());
2684 histogram_tester
.ExpectUniqueSample("Autofill.UserHappiness",
2685 AutofillMetrics::FORMS_LOADED
, 1);
2688 // Expect a notification when the form is submitted.
2690 base::HistogramTester histogram_tester
;
2691 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2692 histogram_tester
.ExpectUniqueSample(
2693 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM
,
2697 // Fill in two of the fields.
2698 form
.fields
[0].value
= ASCIIToUTF16("Elvis Aaron Presley");
2699 form
.fields
[1].value
= ASCIIToUTF16("theking@gmail.com");
2700 forms
.front() = form
;
2702 // Expect a notification when the form is submitted.
2704 base::HistogramTester histogram_tester
;
2705 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2706 histogram_tester
.ExpectUniqueSample(
2707 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM
,
2711 // Fill in the third field.
2712 form
.fields
[2].value
= ASCIIToUTF16("12345678901");
2713 forms
.front() = form
;
2715 // Expect notifications when the form is submitted.
2717 base::HistogramTester histogram_tester
;
2718 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2719 histogram_tester
.ExpectUniqueSample(
2720 "Autofill.UserHappiness",
2721 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE
, 1);
2725 // Mark one of the fields as autofilled.
2726 form
.fields
[1].is_autofilled
= true;
2727 forms
.front() = form
;
2729 // Expect notifications when the form is submitted.
2731 base::HistogramTester histogram_tester
;
2732 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2733 histogram_tester
.ExpectUniqueSample(
2734 "Autofill.UserHappiness",
2735 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME
, 1);
2738 // Mark all of the fillable fields as autofilled.
2739 form
.fields
[0].is_autofilled
= true;
2740 form
.fields
[2].is_autofilled
= true;
2741 forms
.front() = form
;
2743 // Expect notifications when the form is submitted.
2745 base::HistogramTester histogram_tester
;
2746 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2747 histogram_tester
.ExpectUniqueSample(
2748 "Autofill.UserHappiness",
2749 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL
, 1);
2752 // Clear out the third field's value.
2753 form
.fields
[2].value
= base::string16();
2754 forms
.front() = form
;
2756 // Expect notifications when the form is submitted.
2758 base::HistogramTester histogram_tester
;
2759 autofill_manager_
->SubmitForm(form
, TimeTicks::Now());
2760 histogram_tester
.ExpectUniqueSample(
2761 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM
,
2766 // Verify that we correctly log user happiness metrics dealing with form
2768 TEST_F(AutofillMetricsTest
, UserHappinessFormInteraction
) {
2769 // Load a fillable form.
2771 form
.name
= ASCIIToUTF16("TestForm");
2772 form
.origin
= GURL("http://example.com/form.html");
2773 form
.action
= GURL("http://example.com/submit.html");
2775 FormFieldData field
;
2776 test::CreateTestFormField("Name", "name", "", "text", &field
);
2777 form
.fields
.push_back(field
);
2778 test::CreateTestFormField("Email", "email", "", "text", &field
);
2779 form
.fields
.push_back(field
);
2780 test::CreateTestFormField("Phone", "phone", "", "text", &field
);
2781 form
.fields
.push_back(field
);
2783 std::vector
<FormData
> forms(1, form
);
2785 // Expect a notification when the form is first seen.
2787 base::HistogramTester histogram_tester
;
2788 autofill_manager_
->OnFormsSeen(forms
, TimeTicks());
2789 histogram_tester
.ExpectUniqueSample("Autofill.UserHappiness",
2790 AutofillMetrics::FORMS_LOADED
, 1);
2795 base::HistogramTester histogram_tester
;
2796 autofill_manager_
->OnTextFieldDidChange(form
, form
.fields
.front(),
2798 histogram_tester
.ExpectUniqueSample("Autofill.UserHappiness",
2799 AutofillMetrics::USER_DID_TYPE
, 1);
2802 // Simulate suggestions shown twice for a single edit (i.e. multiple
2803 // keystrokes in a single field).
2805 base::HistogramTester histogram_tester
;
2806 autofill_manager_
->DidShowSuggestions(true, form
, field
);
2807 autofill_manager_
->DidShowSuggestions(false, form
, field
);
2808 histogram_tester
.ExpectBucketCount("Autofill.UserHappiness",
2809 AutofillMetrics::SUGGESTIONS_SHOWN
, 1);
2810 histogram_tester
.ExpectBucketCount(
2811 "Autofill.UserHappiness", AutofillMetrics::SUGGESTIONS_SHOWN_ONCE
, 1);
2814 // Simulate suggestions shown for a different field.
2816 base::HistogramTester histogram_tester
;
2817 autofill_manager_
->DidShowSuggestions(true, form
, form
.fields
[1]);
2818 histogram_tester
.ExpectUniqueSample("Autofill.UserHappiness",
2819 AutofillMetrics::SUGGESTIONS_SHOWN
, 1);
2822 // Simulate invoking autofill.
2824 base::HistogramTester histogram_tester
;
2825 autofill_manager_
->OnDidFillAutofillFormData(TimeTicks());
2826 histogram_tester
.ExpectBucketCount("Autofill.UserHappiness",
2827 AutofillMetrics::USER_DID_AUTOFILL
, 1);
2828 histogram_tester
.ExpectBucketCount(
2829 "Autofill.UserHappiness", AutofillMetrics::USER_DID_AUTOFILL_ONCE
, 1);
2832 // Simulate editing an autofilled field.
2834 base::HistogramTester histogram_tester
;
2835 std::string
guid("00000000-0000-0000-0000-000000000001");
2836 autofill_manager_
->FillOrPreviewForm(
2837 AutofillDriver::FORM_DATA_ACTION_FILL
, 0, form
, form
.fields
.front(),
2838 autofill_manager_
->MakeFrontendID(std::string(), guid
));
2839 autofill_manager_
->OnTextFieldDidChange(form
, form
.fields
.front(),
2841 // Simulate a second keystroke; make sure we don't log the metric twice.
2842 autofill_manager_
->OnTextFieldDidChange(form
, form
.fields
.front(),
2844 histogram_tester
.ExpectBucketCount(
2845 "Autofill.UserHappiness",
2846 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD
, 1);
2847 histogram_tester
.ExpectBucketCount(
2848 "Autofill.UserHappiness",
2849 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE
, 1);
2852 // Simulate invoking autofill again.
2854 base::HistogramTester histogram_tester
;
2855 autofill_manager_
->OnDidFillAutofillFormData(TimeTicks());
2856 histogram_tester
.ExpectUniqueSample("Autofill.UserHappiness",
2857 AutofillMetrics::USER_DID_AUTOFILL
, 1);
2860 // Simulate editing another autofilled field.
2862 base::HistogramTester histogram_tester
;
2863 autofill_manager_
->OnTextFieldDidChange(form
, form
.fields
[1], TimeTicks());
2864 histogram_tester
.ExpectUniqueSample(
2865 "Autofill.UserHappiness",
2866 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD
, 1);
2870 // Verify that we correctly log metrics tracking the duration of form fill.
2871 TEST_F(AutofillMetricsTest
, FormFillDuration
) {
2872 // Load a fillable form.
2874 form
.name
= ASCIIToUTF16("TestForm");
2875 form
.origin
= GURL("http://example.com/form.html");
2876 form
.action
= GURL("http://example.com/submit.html");
2878 FormFieldData field
;
2879 test::CreateTestFormField("Name", "name", "", "text", &field
);
2880 form
.fields
.push_back(field
);
2881 test::CreateTestFormField("Email", "email", "", "text", &field
);
2882 form
.fields
.push_back(field
);
2883 test::CreateTestFormField("Phone", "phone", "", "text", &field
);
2884 form
.fields
.push_back(field
);
2886 std::vector
<FormData
> forms(1, form
);
2888 // Fill additional form.
2889 FormData second_form
= form
;
2890 test::CreateTestFormField("Second Phone", "second_phone", "", "text", &field
);
2891 second_form
.fields
.push_back(field
);
2893 std::vector
<FormData
> second_forms(1, second_form
);
2895 // Fill the field values for form submission.
2896 form
.fields
[0].value
= ASCIIToUTF16("Elvis Aaron Presley");
2897 form
.fields
[1].value
= ASCIIToUTF16("theking@gmail.com");
2898 form
.fields
[2].value
= ASCIIToUTF16("12345678901");
2900 // Fill the field values for form submission.
2901 second_form
.fields
[0].value
= ASCIIToUTF16("Elvis Aaron Presley");
2902 second_form
.fields
[1].value
= ASCIIToUTF16("theking@gmail.com");
2903 second_form
.fields
[2].value
= ASCIIToUTF16("12345678901");
2904 second_form
.fields
[3].value
= ASCIIToUTF16("51512345678");
2906 // Expect only form load metrics to be logged if the form is submitted without
2907 // user interaction.
2909 base::HistogramTester histogram_tester
;
2910 autofill_manager_
->OnFormsSeen(forms
, TimeTicks::FromInternalValue(1));
2911 autofill_manager_
->SubmitForm(form
, TimeTicks::FromInternalValue(17));
2913 histogram_tester
.ExpectTotalCount(
2914 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
2915 histogram_tester
.ExpectUniqueSample(
2916 "Autofill.FillDuration.FromLoad.WithoutAutofill", 16, 1);
2917 histogram_tester
.ExpectTotalCount(
2918 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
2919 histogram_tester
.ExpectTotalCount(
2920 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
2922 autofill_manager_
->Reset();
2925 // Expect metric to be logged if the user manually edited a form field.
2927 base::HistogramTester histogram_tester
;
2928 autofill_manager_
->OnFormsSeen(forms
, TimeTicks::FromInternalValue(1));
2929 autofill_manager_
->OnTextFieldDidChange(form
, form
.fields
.front(),
2930 TimeTicks::FromInternalValue(3));
2931 autofill_manager_
->SubmitForm(form
, TimeTicks::FromInternalValue(17));
2933 histogram_tester
.ExpectTotalCount(
2934 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
2935 histogram_tester
.ExpectUniqueSample(
2936 "Autofill.FillDuration.FromLoad.WithoutAutofill", 16, 1);
2937 histogram_tester
.ExpectTotalCount(
2938 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
2939 histogram_tester
.ExpectUniqueSample(
2940 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 14, 1);
2942 autofill_manager_
->Reset();
2945 // Expect metric to be logged if the user autofilled the form.
2946 form
.fields
[0].is_autofilled
= true;
2948 base::HistogramTester histogram_tester
;
2949 autofill_manager_
->OnFormsSeen(forms
, TimeTicks::FromInternalValue(1));
2950 autofill_manager_
->OnDidFillAutofillFormData(
2951 TimeTicks::FromInternalValue(5));
2952 autofill_manager_
->SubmitForm(form
, TimeTicks::FromInternalValue(17));
2954 histogram_tester
.ExpectUniqueSample(
2955 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
2956 histogram_tester
.ExpectTotalCount(
2957 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
2958 histogram_tester
.ExpectUniqueSample(
2959 "Autofill.FillDuration.FromInteraction.WithAutofill", 12, 1);
2960 histogram_tester
.ExpectTotalCount(
2961 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
2963 autofill_manager_
->Reset();
2966 // Expect metric to be logged if the user both manually filled some fields
2967 // and autofilled others. Messages can arrive out of order, so make sure they
2968 // take precedence appropriately.
2970 base::HistogramTester histogram_tester
;
2972 autofill_manager_
->OnFormsSeen(forms
, TimeTicks::FromInternalValue(1));
2973 autofill_manager_
->OnDidFillAutofillFormData(
2974 TimeTicks::FromInternalValue(5));
2975 autofill_manager_
->OnTextFieldDidChange(form
, form
.fields
.front(),
2976 TimeTicks::FromInternalValue(3));
2977 autofill_manager_
->SubmitForm(form
, TimeTicks::FromInternalValue(17));
2979 histogram_tester
.ExpectUniqueSample(
2980 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
2981 histogram_tester
.ExpectTotalCount(
2982 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
2983 histogram_tester
.ExpectUniqueSample(
2984 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1);
2985 histogram_tester
.ExpectTotalCount(
2986 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
2988 autofill_manager_
->Reset();
2991 // Make sure that loading another form doesn't affect metrics from the first
2994 base::HistogramTester histogram_tester
;
2995 autofill_manager_
->OnFormsSeen(forms
, TimeTicks::FromInternalValue(1));
2996 autofill_manager_
->OnFormsSeen(second_forms
,
2997 TimeTicks::FromInternalValue(3));
2998 autofill_manager_
->OnDidFillAutofillFormData(
2999 TimeTicks::FromInternalValue(5));
3000 autofill_manager_
->OnTextFieldDidChange(form
, form
.fields
.front(),
3001 TimeTicks::FromInternalValue(3));
3002 autofill_manager_
->SubmitForm(form
, TimeTicks::FromInternalValue(17));
3004 histogram_tester
.ExpectUniqueSample(
3005 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
3006 histogram_tester
.ExpectTotalCount(
3007 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
3008 histogram_tester
.ExpectUniqueSample(
3009 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1);
3010 histogram_tester
.ExpectTotalCount(
3011 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
3013 autofill_manager_
->Reset();
3016 // Make sure that submitting a form that was loaded later will report the
3017 // later loading time.
3019 base::HistogramTester histogram_tester
;
3020 autofill_manager_
->OnFormsSeen(forms
, TimeTicks::FromInternalValue(1));
3021 autofill_manager_
->OnFormsSeen(second_forms
,
3022 TimeTicks::FromInternalValue(5));
3023 autofill_manager_
->SubmitForm(second_form
,
3024 TimeTicks::FromInternalValue(17));
3026 histogram_tester
.ExpectTotalCount(
3027 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
3028 histogram_tester
.ExpectUniqueSample(
3029 "Autofill.FillDuration.FromLoad.WithoutAutofill", 12, 1);
3030 histogram_tester
.ExpectTotalCount(
3031 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
3032 histogram_tester
.ExpectTotalCount(
3033 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
3035 autofill_manager_
->Reset();
3039 } // namespace autofill