Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / autofill / core / browser / autofill_metrics_unittest.cc
blob3c2f8b21b78ecb01a988892bed29ad80e8ec33ab
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"
7 #include <vector>
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/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h"
34 #include "ui/gfx/geometry/rect.h"
35 #include "url/gurl.h"
37 using base::ASCIIToUTF16;
38 using base::Bucket;
39 using base::TimeTicks;
40 using rappor::TestRapporService;
41 using ::testing::ElementsAre;
43 namespace autofill {
44 namespace {
46 class TestPersonalDataManager : public PersonalDataManager {
47 public:
48 TestPersonalDataManager()
49 : PersonalDataManager("en-US"),
50 autofill_enabled_(true) {
51 CreateTestAutofillProfiles(&web_profiles_);
54 using PersonalDataManager::set_account_tracker;
55 using PersonalDataManager::set_database;
56 using PersonalDataManager::SetPrefService;
58 // Overridden to avoid a trip to the database. This should be a no-op except
59 // for the side-effect of logging the profile count.
60 void LoadProfiles() override {
62 std::vector<AutofillProfile*> profiles;
63 web_profiles_.release(&profiles);
64 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT,
65 profiles);
66 pending_profiles_query_ = 123;
67 OnWebDataServiceRequestDone(pending_profiles_query_, &result);
70 std::vector<AutofillProfile*> profiles;
71 server_profiles_.release(&profiles);
72 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT,
73 profiles);
74 pending_server_profiles_query_ = 124;
75 OnWebDataServiceRequestDone(pending_server_profiles_query_, &result);
79 // Overridden to avoid a trip to the database.
80 void LoadCreditCards() override {
82 std::vector<CreditCard*> credit_cards;
83 local_credit_cards_.release(&credit_cards);
84 WDResult<std::vector<CreditCard*> > result(
85 AUTOFILL_CREDITCARDS_RESULT, credit_cards);
86 pending_creditcards_query_ = 125;
87 OnWebDataServiceRequestDone(pending_creditcards_query_, &result);
90 std::vector<CreditCard*> credit_cards;
91 server_credit_cards_.release(&credit_cards);
92 WDResult<std::vector<CreditCard*> > result(
93 AUTOFILL_CREDITCARDS_RESULT, credit_cards);
94 pending_server_creditcards_query_ = 126;
95 OnWebDataServiceRequestDone(pending_server_creditcards_query_, &result);
99 void set_autofill_enabled(bool autofill_enabled) {
100 autofill_enabled_ = autofill_enabled;
103 // Removes all existing profiles and creates 0 or 1 local profiles and 0 or 1
104 // server profile according to the paramters.
105 void RecreateProfiles(bool include_local_profile,
106 bool include_server_profile) {
107 web_profiles_.clear();
108 server_profiles_.clear();
109 if (include_local_profile) {
110 AutofillProfile* profile = new AutofillProfile;
111 test::SetProfileInfo(profile, "Elvis", "Aaron",
112 "Presley", "theking@gmail.com", "RCA",
113 "3734 Elvis Presley Blvd.", "Apt. 10",
114 "Memphis", "Tennessee", "38116", "US",
115 "12345678901");
116 profile->set_guid("00000000-0000-0000-0000-000000000001");
117 web_profiles_.push_back(profile);
119 if (include_server_profile) {
120 AutofillProfile* profile = new AutofillProfile(
121 AutofillProfile::SERVER_PROFILE, "server_id");
122 test::SetProfileInfo(profile, "Charles", "Hardin",
123 "Holley", "buddy@gmail.com", "Decca",
124 "123 Apple St.", "unit 6", "Lubbock",
125 "Texas", "79401", "US", "2345678901");
126 profile->set_guid("00000000-0000-0000-0000-000000000002");
127 server_profiles_.push_back(profile);
129 Refresh();
132 // Removes all existing credit cards and creates 0 or 1 local profiles and
133 // 0 or 1 server profile according to the paramters.
134 void RecreateCreditCards(bool include_local_credit_card,
135 bool include_masked_server_credit_card,
136 bool include_full_server_credit_card) {
137 local_credit_cards_.clear();
138 server_credit_cards_.clear();
139 if (include_local_credit_card) {
140 CreditCard* credit_card = new CreditCard;
141 credit_card->set_guid("10000000-0000-0000-0000-000000000001");
142 local_credit_cards_.push_back(credit_card);
144 if (include_masked_server_credit_card) {
145 CreditCard* credit_card = new CreditCard(
146 CreditCard::MASKED_SERVER_CARD, "server_id");
147 credit_card->set_guid("10000000-0000-0000-0000-000000000002");
148 credit_card->SetTypeForMaskedCard(kDiscoverCard);
149 server_credit_cards_.push_back(credit_card);
151 if (include_full_server_credit_card) {
152 CreditCard* credit_card = new CreditCard(
153 CreditCard::FULL_SERVER_CARD, "server_id");
154 credit_card->set_guid("10000000-0000-0000-0000-000000000003");
155 server_credit_cards_.push_back(credit_card);
157 Refresh();
160 bool IsAutofillEnabled() const override { return autofill_enabled_; }
162 private:
163 void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) {
164 AutofillProfile* profile = new AutofillProfile;
165 test::SetProfileInfo(profile, "Elvis", "Aaron",
166 "Presley", "theking@gmail.com", "RCA",
167 "3734 Elvis Presley Blvd.", "Apt. 10",
168 "Memphis", "Tennessee", "38116", "US",
169 "12345678901");
170 profile->set_guid("00000000-0000-0000-0000-000000000001");
171 profiles->push_back(profile);
172 profile = new AutofillProfile;
173 test::SetProfileInfo(profile, "Charles", "Hardin",
174 "Holley", "buddy@gmail.com", "Decca",
175 "123 Apple St.", "unit 6", "Lubbock",
176 "Texas", "79401", "US", "2345678901");
177 profile->set_guid("00000000-0000-0000-0000-000000000002");
178 profiles->push_back(profile);
181 bool autofill_enabled_;
183 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
186 class TestFormStructure : public FormStructure {
187 public:
188 explicit TestFormStructure(const FormData& form) : FormStructure(form) {}
189 ~TestFormStructure() override {}
191 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types,
192 const std::vector<ServerFieldType>& server_types) {
193 ASSERT_EQ(field_count(), heuristic_types.size());
194 ASSERT_EQ(field_count(), server_types.size());
196 for (size_t i = 0; i < field_count(); ++i) {
197 AutofillField* form_field = field(i);
198 ASSERT_TRUE(form_field);
199 form_field->set_heuristic_type(heuristic_types[i]);
200 form_field->set_server_type(server_types[i]);
203 UpdateAutofillCount();
206 private:
207 DISALLOW_COPY_AND_ASSIGN(TestFormStructure);
210 class TestAutofillManager : public AutofillManager {
211 public:
212 TestAutofillManager(AutofillDriver* driver,
213 AutofillClient* autofill_client,
214 TestPersonalDataManager* personal_manager)
215 : AutofillManager(driver, autofill_client, personal_manager),
216 autofill_enabled_(true) {}
217 ~TestAutofillManager() override {}
219 bool IsAutofillEnabled() const override { return autofill_enabled_; }
221 void set_autofill_enabled(bool autofill_enabled) {
222 autofill_enabled_ = autofill_enabled;
225 void AddSeenForm(const FormData& form,
226 const std::vector<ServerFieldType>& heuristic_types,
227 const std::vector<ServerFieldType>& server_types) {
228 FormData empty_form = form;
229 for (size_t i = 0; i < empty_form.fields.size(); ++i) {
230 empty_form.fields[i].value = base::string16();
233 // |form_structure| will be owned by |form_structures()|.
234 TestFormStructure* form_structure = new TestFormStructure(empty_form);
235 form_structure->SetFieldTypes(heuristic_types, server_types);
236 form_structures()->push_back(form_structure);
239 // Calls AutofillManager::OnWillSubmitForm and waits for it to complete.
240 void WillSubmitForm(const FormData& form, const TimeTicks& timestamp) {
241 run_loop_.reset(new base::RunLoop());
242 if (!OnWillSubmitForm(form, timestamp))
243 return;
245 // Wait for the asynchronous OnWillSubmitForm() call to complete.
246 run_loop_->Run();
249 // Calls both AutofillManager::OnWillSubmitForm and
250 // AutofillManager::OnFormSubmitted.
251 void SubmitForm(const FormData& form, const TimeTicks& timestamp) {
252 WillSubmitForm(form, timestamp);
253 OnFormSubmitted(form);
256 void UploadFormDataAsyncCallback(
257 const FormStructure* submitted_form,
258 const base::TimeTicks& load_time,
259 const base::TimeTicks& interaction_time,
260 const base::TimeTicks& submission_time) override {
261 run_loop_->Quit();
263 AutofillManager::UploadFormDataAsyncCallback(submitted_form,
264 load_time,
265 interaction_time,
266 submission_time);
269 private:
270 bool autofill_enabled_;
271 scoped_ptr<base::RunLoop> run_loop_;
273 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
276 } // namespace
278 // This is defined in the autofill_metrics.cc implementation file.
279 int GetFieldTypeGroupMetric(ServerFieldType field_type,
280 AutofillMetrics::FieldTypeQualityMetric metric);
282 class AutofillMetricsTest : public testing::Test {
283 public:
284 ~AutofillMetricsTest() override;
286 void SetUp() override;
287 void TearDown() override;
289 protected:
290 void EnableWalletSync();
292 base::MessageLoop message_loop_;
293 TestAutofillClient autofill_client_;
294 scoped_ptr<AccountTrackerService> account_tracker_;
295 scoped_ptr<TestSigninClient> signin_client_;
296 scoped_ptr<TestAutofillDriver> autofill_driver_;
297 scoped_ptr<TestAutofillManager> autofill_manager_;
298 scoped_ptr<TestPersonalDataManager> personal_data_;
299 scoped_ptr<AutofillExternalDelegate> external_delegate_;
302 AutofillMetricsTest::~AutofillMetricsTest() {
303 // Order of destruction is important as AutofillManager relies on
304 // PersonalDataManager to be around when it gets destroyed.
305 autofill_manager_.reset();
308 void AutofillMetricsTest::SetUp() {
309 autofill_client_.SetPrefs(test::PrefServiceForTesting());
311 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
312 test::DisableSystemServices(autofill_client_.GetPrefs());
314 // Setup account tracker.
315 signin_client_.reset(new TestSigninClient(autofill_client_.GetPrefs()));
316 account_tracker_.reset(new AccountTrackerService());
317 account_tracker_->Initialize(signin_client_.get());
319 personal_data_.reset(new TestPersonalDataManager());
320 personal_data_->set_database(autofill_client_.GetDatabase());
321 personal_data_->SetPrefService(autofill_client_.GetPrefs());
322 personal_data_->set_account_tracker(account_tracker_.get());
323 autofill_driver_.reset(new TestAutofillDriver());
324 autofill_manager_.reset(new TestAutofillManager(
325 autofill_driver_.get(), &autofill_client_, personal_data_.get()));
327 external_delegate_.reset(new AutofillExternalDelegate(
328 autofill_manager_.get(),
329 autofill_driver_.get()));
330 autofill_manager_->SetExternalDelegate(external_delegate_.get());
333 void AutofillMetricsTest::TearDown() {
334 // Order of destruction is important as AutofillManager relies on
335 // PersonalDataManager to be around when it gets destroyed.
336 autofill_manager_.reset();
337 autofill_driver_.reset();
338 personal_data_.reset();
339 account_tracker_->Shutdown();
340 account_tracker_.reset();
341 signin_client_.reset();
344 void AutofillMetricsTest::EnableWalletSync() {
345 autofill_client_.GetPrefs()->SetBoolean(
346 prefs::kAutofillWalletSyncExperimentEnabled, true);
347 std::string account_id =
348 account_tracker_->SeedAccountInfo("12345", "syncuser@example.com");
349 autofill_client_.GetPrefs()->SetString(
350 ::prefs::kGoogleServicesAccountId, account_id);
353 // Test that we log quality metrics appropriately.
354 TEST_F(AutofillMetricsTest, QualityMetrics) {
355 // Set up our form data.
356 FormData form;
357 form.name = ASCIIToUTF16("TestForm");
358 form.origin = GURL("http://example.com/form.html");
359 form.action = GURL("http://example.com/submit.html");
361 std::vector<ServerFieldType> heuristic_types, server_types;
362 FormFieldData field;
364 test::CreateTestFormField(
365 "Autofilled", "autofilled", "Elvis Aaron Presley", "text", &field);
366 field.is_autofilled = true;
367 form.fields.push_back(field);
368 heuristic_types.push_back(NAME_FULL);
369 server_types.push_back(NAME_FIRST);
371 test::CreateTestFormField(
372 "Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field);
373 field.is_autofilled = false;
374 form.fields.push_back(field);
375 heuristic_types.push_back(PHONE_HOME_NUMBER);
376 server_types.push_back(EMAIL_ADDRESS);
378 test::CreateTestFormField("Empty", "empty", "", "text", &field);
379 field.is_autofilled = false;
380 form.fields.push_back(field);
381 heuristic_types.push_back(NAME_FULL);
382 server_types.push_back(NAME_FIRST);
384 test::CreateTestFormField("Unknown", "unknown", "garbage", "text", &field);
385 field.is_autofilled = false;
386 form.fields.push_back(field);
387 heuristic_types.push_back(PHONE_HOME_NUMBER);
388 server_types.push_back(EMAIL_ADDRESS);
390 test::CreateTestFormField("Select", "select", "USA", "select-one", &field);
391 field.is_autofilled = false;
392 form.fields.push_back(field);
393 heuristic_types.push_back(UNKNOWN_TYPE);
394 server_types.push_back(NO_SERVER_DATA);
396 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
397 field.is_autofilled = true;
398 form.fields.push_back(field);
399 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
400 server_types.push_back(PHONE_HOME_WHOLE_NUMBER);
402 // Simulate having seen this form on page load.
403 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
405 // Simulate form submission.
406 base::HistogramTester histogram_tester;
407 autofill_manager_->SubmitForm(form, TimeTicks::Now());
409 // Heuristic predictions.
410 // Unknown:
411 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
412 AutofillMetrics::TYPE_UNKNOWN, 1);
413 histogram_tester.ExpectBucketCount(
414 "Autofill.Quality.HeuristicType.ByFieldType",
415 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
416 AutofillMetrics::TYPE_UNKNOWN),
418 // Match:
419 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
420 AutofillMetrics::TYPE_MATCH, 2);
421 histogram_tester.ExpectBucketCount(
422 "Autofill.Quality.HeuristicType.ByFieldType",
423 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1);
424 histogram_tester.ExpectBucketCount(
425 "Autofill.Quality.HeuristicType.ByFieldType",
426 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER,
427 AutofillMetrics::TYPE_MATCH),
429 // Mismatch:
430 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
431 AutofillMetrics::TYPE_MISMATCH, 1);
432 histogram_tester.ExpectBucketCount(
433 "Autofill.Quality.HeuristicType.ByFieldType",
434 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH),
437 // Server predictions:
438 // Unknown:
439 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
440 AutofillMetrics::TYPE_UNKNOWN, 1);
441 histogram_tester.ExpectBucketCount(
442 "Autofill.Quality.ServerType.ByFieldType",
443 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
444 AutofillMetrics::TYPE_UNKNOWN),
446 // Match:
447 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
448 AutofillMetrics::TYPE_MATCH, 2);
449 histogram_tester.ExpectBucketCount(
450 "Autofill.Quality.ServerType.ByFieldType",
451 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MATCH), 1);
452 histogram_tester.ExpectBucketCount(
453 "Autofill.Quality.ServerType.ByFieldType",
454 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER,
455 AutofillMetrics::TYPE_MATCH),
457 // Mismatch:
458 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
459 AutofillMetrics::TYPE_MISMATCH, 1);
460 histogram_tester.ExpectBucketCount(
461 "Autofill.Quality.ServerType.ByFieldType",
462 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1);
464 // Overall predictions:
465 // Unknown:
466 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
467 AutofillMetrics::TYPE_UNKNOWN, 1);
468 histogram_tester.ExpectBucketCount(
469 "Autofill.Quality.PredictedType.ByFieldType",
470 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
471 AutofillMetrics::TYPE_UNKNOWN),
473 // Match:
474 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
475 AutofillMetrics::TYPE_MATCH, 2);
476 histogram_tester.ExpectBucketCount(
477 "Autofill.Quality.PredictedType.ByFieldType",
478 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MATCH), 1);
479 histogram_tester.ExpectBucketCount(
480 "Autofill.Quality.PredictedType.ByFieldType",
481 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER,
482 AutofillMetrics::TYPE_MATCH),
484 // Mismatch:
485 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
486 AutofillMetrics::TYPE_MISMATCH, 1);
487 histogram_tester.ExpectBucketCount(
488 "Autofill.Quality.PredictedType.ByFieldType",
489 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1);
492 // Test that we do not log RAPPOR metrics when the number of mismatches is not
493 // high enough.
494 TEST_F(AutofillMetricsTest, Rappor_LowMismatchRate_NoMetricsReported) {
495 // Set up our form data.
496 FormData form;
497 form.name = ASCIIToUTF16("TestForm");
498 form.origin = GURL("http://example.com/form.html");
499 form.action = GURL("http://example.com/submit.html");
501 std::vector<ServerFieldType> heuristic_types, server_types;
502 FormFieldData field;
504 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley",
505 "text", &field);
506 field.is_autofilled = true;
507 form.fields.push_back(field);
508 heuristic_types.push_back(NAME_FULL);
509 server_types.push_back(NAME_FULL);
511 test::CreateTestFormField("Autofill Failed", "autofillfailed",
512 "buddy@gmail.com", "text", &field);
513 field.is_autofilled = false;
514 form.fields.push_back(field);
515 heuristic_types.push_back(EMAIL_ADDRESS);
516 server_types.push_back(NAME_LAST);
518 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
519 field.is_autofilled = true;
520 form.fields.push_back(field);
521 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
522 server_types.push_back(EMAIL_ADDRESS);
524 // Simulate having seen this form on page load.
525 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
527 // Simulate form submission.
528 autofill_manager_->SubmitForm(form, TimeTicks::Now());
530 // The number of mismatches did not trigger the RAPPOR metric logging.
531 EXPECT_EQ(0, autofill_client_.test_rappor_service()->GetReportsCount());
534 // Test that we don't log RAPPOR metrics in the case heuristics and/or server
535 // have no data.
536 TEST_F(AutofillMetricsTest, Rappor_NoDataServerAndHeuristic_NoMetricsReported) {
537 // Set up our form data.
538 FormData form;
539 form.name = ASCIIToUTF16("TestForm");
540 form.origin = GURL("http://example.com/form.html");
541 form.action = GURL("http://example.com/submit.html");
543 std::vector<ServerFieldType> heuristic_types, server_types;
544 FormFieldData field;
546 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley",
547 "text", &field);
548 field.is_autofilled = true;
549 form.fields.push_back(field);
550 heuristic_types.push_back(UNKNOWN_TYPE);
551 server_types.push_back(NO_SERVER_DATA);
553 test::CreateTestFormField("Autofill Failed", "autofillfailed",
554 "buddy@gmail.com", "text", &field);
555 field.is_autofilled = false;
556 form.fields.push_back(field);
557 heuristic_types.push_back(UNKNOWN_TYPE);
558 server_types.push_back(NO_SERVER_DATA);
560 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
561 field.is_autofilled = true;
562 form.fields.push_back(field);
563 heuristic_types.push_back(UNKNOWN_TYPE);
564 server_types.push_back(NO_SERVER_DATA);
566 // Simulate having seen this form on page load.
567 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
569 // Simulate form submission.
570 autofill_manager_->SubmitForm(form, TimeTicks::Now());
572 // No RAPPOR metrics are logged in the case of multiple UNKNOWN_TYPE and
573 // NO_SERVER_DATA for heuristics and server predictions, respectively.
574 EXPECT_EQ(0, autofill_client_.test_rappor_service()->GetReportsCount());
577 // Test that we log high number of mismatches for the server prediction.
578 TEST_F(AutofillMetricsTest, Rappor_HighServerMismatchRate_MetricsReported) {
579 // Set up our form data.
580 FormData form;
581 form.name = ASCIIToUTF16("TestForm");
582 form.origin = GURL("http://example.com/form.html");
583 form.action = GURL("http://example.com/submit.html");
585 std::vector<ServerFieldType> heuristic_types, server_types;
586 FormFieldData field;
588 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley",
589 "text", &field);
590 field.is_autofilled = true;
591 form.fields.push_back(field);
592 heuristic_types.push_back(NAME_FULL);
593 server_types.push_back(NAME_FIRST);
595 test::CreateTestFormField("Autofill Failed", "autofillfailed",
596 "buddy@gmail.com", "text", &field);
597 field.is_autofilled = false;
598 form.fields.push_back(field);
599 heuristic_types.push_back(PHONE_HOME_NUMBER);
600 server_types.push_back(NAME_LAST);
602 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
603 field.is_autofilled = true;
604 form.fields.push_back(field);
605 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
606 server_types.push_back(EMAIL_ADDRESS);
608 // Simulate having seen this form on page load.
609 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
611 // Simulate form submission.
612 autofill_manager_->SubmitForm(form, TimeTicks::Now());
614 // The number of mismatches did trigger the RAPPOR metric logging for server
615 // predictions.
616 EXPECT_EQ(1, autofill_client_.test_rappor_service()->GetReportsCount());
617 std::string sample;
618 rappor::RapporType type;
619 EXPECT_FALSE(
620 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric(
621 "Autofill.HighNumberOfHeuristicMismatches", &sample, &type));
622 EXPECT_TRUE(
623 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric(
624 "Autofill.HighNumberOfServerMismatches", &sample, &type));
625 EXPECT_EQ("example.com", sample);
626 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
629 // Test that we log high number of mismatches for the heuristic predictions.
630 TEST_F(AutofillMetricsTest, Rappor_HighHeuristicMismatchRate_MetricsReported) {
631 // Set up our form data.
632 FormData form;
633 form.name = ASCIIToUTF16("TestForm");
634 form.origin = GURL("http://example.com/form.html");
635 form.action = GURL("http://example.com/submit.html");
637 std::vector<ServerFieldType> heuristic_types, server_types;
638 FormFieldData field;
640 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley",
641 "text", &field);
642 field.is_autofilled = true;
643 form.fields.push_back(field);
644 heuristic_types.push_back(NAME_FIRST);
645 server_types.push_back(NAME_FULL);
647 test::CreateTestFormField("Autofill Failed", "autofillfailed",
648 "buddy@gmail.com", "text", &field);
649 field.is_autofilled = false;
650 form.fields.push_back(field);
651 heuristic_types.push_back(PHONE_HOME_NUMBER);
652 server_types.push_back(NAME_LAST);
654 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
655 field.is_autofilled = true;
656 form.fields.push_back(field);
657 heuristic_types.push_back(EMAIL_ADDRESS);
658 server_types.push_back(PHONE_HOME_WHOLE_NUMBER);
660 // Simulate having seen this form on page load.
661 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
663 // Simulate form submission.
664 autofill_manager_->SubmitForm(form, TimeTicks::Now());
666 // The number of mismatches did trigger the RAPPOR metric logging for
667 // heuristic predictions.
668 EXPECT_EQ(1, autofill_client_.test_rappor_service()->GetReportsCount());
669 std::string sample;
670 rappor::RapporType type;
671 EXPECT_FALSE(
672 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric(
673 "Autofill.HighNumberOfServerMismatches", &sample, &type));
674 EXPECT_TRUE(
675 autofill_client_.test_rappor_service()->GetRecordedSampleForMetric(
676 "Autofill.HighNumberOfHeuristicMismatches", &sample, &type));
677 EXPECT_EQ("example.com", sample);
678 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
681 // Verify that when a field is annotated with the autocomplete attribute, its
682 // predicted type is remembered when quality metrics are logged.
683 TEST_F(AutofillMetricsTest, PredictedMetricsWithAutocomplete) {
684 // Set up our form data.
685 FormData form;
686 form.name = ASCIIToUTF16("TestForm");
687 form.origin = GURL("http://example.com/form.html");
688 form.action = GURL("http://example.com/submit.html");
690 FormFieldData field1;
691 test::CreateTestFormField("Select", "select", "USA", "select-one", &field1);
692 field1.autocomplete_attribute = "country";
693 form.fields.push_back(field1);
695 // Two other fields to have the minimum of 3 to be parsed by autofill. Note
696 // that they have default values not found in the user profiles. They will be
697 // changed between the time the form is seen/parsed, and the time it is
698 // submitted.
699 FormFieldData field2;
700 test::CreateTestFormField("Unknown", "Unknown", "", "text", &field2);
701 form.fields.push_back(field2);
702 FormFieldData field3;
703 test::CreateTestFormField("Phone", "phone", "", "tel", &field3);
704 form.fields.push_back(field3);
706 std::vector<FormData> forms(1, form);
709 base::HistogramTester histogram_tester;
710 autofill_manager_->OnFormsSeen(forms, TimeTicks());
711 // We change the value of the text fields to change the default/seen values
712 // (hence the values are not cleared in UpdateFromCache). The new values
713 // match what is in the test profile.
714 form.fields[1].value = base::ASCIIToUTF16("79401");
715 form.fields[2].value = base::ASCIIToUTF16("2345678901");
716 autofill_manager_->SubmitForm(form, TimeTicks::Now());
718 // First verify that country was not predicted by client or server.
719 histogram_tester.ExpectBucketCount(
720 "Autofill.Quality.ServerType.ByFieldType",
721 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
722 AutofillMetrics::TYPE_UNKNOWN),
724 histogram_tester.ExpectBucketCount(
725 "Autofill.Quality.HeuristicType.ByFieldType",
726 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
727 AutofillMetrics::TYPE_UNKNOWN),
729 // We expect a match for country because it had |autocomplete_attribute|.
730 histogram_tester.ExpectBucketCount(
731 "Autofill.Quality.PredictedType.ByFieldType",
732 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
733 AutofillMetrics::TYPE_MATCH),
736 // We did not predict zip code or phone number, because they did not have
737 // |autocomplete_attribute|, nor client or server predictions.
738 histogram_tester.ExpectBucketCount(
739 "Autofill.Quality.ServerType.ByFieldType",
740 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP,
741 AutofillMetrics::TYPE_UNKNOWN),
743 histogram_tester.ExpectBucketCount(
744 "Autofill.Quality.HeuristicType.ByFieldType",
745 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP,
746 AutofillMetrics::TYPE_UNKNOWN),
748 histogram_tester.ExpectBucketCount(
749 "Autofill.Quality.PredictedType.ByFieldType",
750 GetFieldTypeGroupMetric(ADDRESS_HOME_ZIP,
751 AutofillMetrics::TYPE_UNKNOWN),
753 histogram_tester.ExpectBucketCount(
754 "Autofill.Quality.ServerType.ByFieldType",
755 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER,
756 AutofillMetrics::TYPE_UNKNOWN),
758 histogram_tester.ExpectBucketCount(
759 "Autofill.Quality.HeuristicType.ByFieldType",
760 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER,
761 AutofillMetrics::TYPE_UNKNOWN),
763 histogram_tester.ExpectBucketCount(
764 "Autofill.Quality.PredictedType.ByFieldType",
765 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER,
766 AutofillMetrics::TYPE_UNKNOWN),
769 // Sanity check.
770 histogram_tester.ExpectTotalCount("Autofill.Quality.PredictedType", 3);
774 // Test that we behave sanely when the cached form differs from the submitted
775 // one.
776 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) {
777 // Set up our form data.
778 FormData form;
779 form.name = ASCIIToUTF16("TestForm");
780 form.origin = GURL("http://example.com/form.html");
781 form.action = GURL("http://example.com/submit.html");
783 std::vector<ServerFieldType> heuristic_types, server_types;
785 FormFieldData field;
786 test::CreateTestFormField(
787 "Both match", "match", "Elvis Aaron Presley", "text", &field);
788 field.is_autofilled = true;
789 form.fields.push_back(field);
790 heuristic_types.push_back(NAME_FULL);
791 server_types.push_back(NAME_FULL);
792 test::CreateTestFormField(
793 "Both mismatch", "mismatch", "buddy@gmail.com", "text", &field);
794 field.is_autofilled = false;
795 form.fields.push_back(field);
796 heuristic_types.push_back(PHONE_HOME_NUMBER);
797 server_types.push_back(PHONE_HOME_NUMBER);
798 test::CreateTestFormField(
799 "Only heuristics match", "mixed", "Memphis", "text", &field);
800 field.is_autofilled = false;
801 form.fields.push_back(field);
802 heuristic_types.push_back(ADDRESS_HOME_CITY);
803 server_types.push_back(PHONE_HOME_NUMBER);
804 test::CreateTestFormField("Unknown", "unknown", "garbage", "text", &field);
805 field.is_autofilled = false;
806 form.fields.push_back(field);
807 heuristic_types.push_back(UNKNOWN_TYPE);
808 server_types.push_back(UNKNOWN_TYPE);
810 // Simulate having seen this form with the desired heuristic and server types.
811 // |form_structure| will be owned by |autofill_manager_|.
812 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
815 // Add a field and re-arrange the remaining form fields before submitting.
816 std::vector<FormFieldData> cached_fields = form.fields;
817 form.fields.clear();
818 test::CreateTestFormField(
819 "New field", "new field", "Tennessee", "text", &field);
820 form.fields.push_back(field);
821 form.fields.push_back(cached_fields[2]);
822 form.fields.push_back(cached_fields[1]);
823 form.fields.push_back(cached_fields[3]);
824 form.fields.push_back(cached_fields[0]);
826 // Simulate form submission.
827 base::HistogramTester histogram_tester;
828 autofill_manager_->SubmitForm(form, TimeTicks::Now());
830 // Heuristic predictions.
831 // Unknown:
832 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
833 AutofillMetrics::TYPE_UNKNOWN, 1);
834 histogram_tester.ExpectBucketCount(
835 "Autofill.Quality.HeuristicType.ByFieldType",
836 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE,
837 AutofillMetrics::TYPE_UNKNOWN),
839 // Match:
840 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
841 AutofillMetrics::TYPE_MATCH, 2);
842 histogram_tester.ExpectBucketCount(
843 "Autofill.Quality.HeuristicType.ByFieldType",
844 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY, AutofillMetrics::TYPE_MATCH),
846 histogram_tester.ExpectBucketCount(
847 "Autofill.Quality.HeuristicType.ByFieldType",
848 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1);
849 // Mismatch:
850 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
851 AutofillMetrics::TYPE_MISMATCH, 1);
852 histogram_tester.ExpectBucketCount(
853 "Autofill.Quality.HeuristicType.ByFieldType",
854 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH),
857 // Server predictions:
858 // Unknown:
859 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
860 AutofillMetrics::TYPE_UNKNOWN, 1);
861 histogram_tester.ExpectBucketCount(
862 "Autofill.Quality.ServerType.ByFieldType",
863 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE,
864 AutofillMetrics::TYPE_UNKNOWN),
866 // Match:
867 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
868 AutofillMetrics::TYPE_MATCH, 1);
869 histogram_tester.ExpectBucketCount(
870 "Autofill.Quality.ServerType.ByFieldType",
871 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1);
872 // Mismatch:
873 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
874 AutofillMetrics::TYPE_MISMATCH, 2);
875 histogram_tester.ExpectBucketCount(
876 "Autofill.Quality.ServerType.ByFieldType",
877 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY,
878 AutofillMetrics::TYPE_MISMATCH),
880 histogram_tester.ExpectBucketCount(
881 "Autofill.Quality.ServerType.ByFieldType",
882 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH),
885 // Overall predictions:
886 // Unknown:
887 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
888 AutofillMetrics::TYPE_UNKNOWN, 1);
889 histogram_tester.ExpectBucketCount(
890 "Autofill.Quality.PredictedType.ByFieldType",
891 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE,
892 AutofillMetrics::TYPE_UNKNOWN),
894 // Match:
895 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
896 AutofillMetrics::TYPE_MATCH, 1);
897 histogram_tester.ExpectBucketCount(
898 "Autofill.Quality.PredictedType.ByFieldType",
899 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1);
900 // Mismatch:
901 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
902 AutofillMetrics::TYPE_MISMATCH, 2);
903 histogram_tester.ExpectBucketCount(
904 "Autofill.Quality.PredictedType.ByFieldType",
905 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY,
906 AutofillMetrics::TYPE_MISMATCH),
908 histogram_tester.ExpectBucketCount(
909 "Autofill.Quality.PredictedType.ByFieldType",
910 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH),
914 // Verify that when submitting an autofillable form, the stored profile metric
915 // is logged.
916 TEST_F(AutofillMetricsTest, StoredProfileCountAutofillableFormSubmission) {
917 // Construct a fillable form.
918 FormData form;
919 form.name = ASCIIToUTF16("TestForm");
920 form.origin = GURL("http://example.com/form.html");
921 form.action = GURL("http://example.com/submit.html");
923 // Three fields is enough to make it an autofillable form.
924 FormFieldData field;
925 test::CreateTestFormField("Name", "name", "", "text", &field);
926 form.fields.push_back(field);
927 test::CreateTestFormField("Email", "email", "", "text", &field);
928 form.fields.push_back(field);
929 test::CreateTestFormField("Phone", "phone", "", "text", &field);
930 form.fields.push_back(field);
932 std::vector<FormData> forms(1, form);
934 // Simulate form submission.
935 base::HistogramTester histogram_tester;
936 autofill_manager_->OnFormsSeen(forms, TimeTicks());
937 autofill_manager_->SubmitForm(form, TimeTicks::Now());
939 // An autofillable form was submitted, and the number of stored profiles is
940 // logged.
941 histogram_tester.ExpectUniqueSample(
942 "Autofill.StoredProfileCountAtAutofillableFormSubmission", 2, 1);
945 // Verify that when submitting a non-autofillable form, the stored profile
946 // metric is not logged.
947 TEST_F(AutofillMetricsTest, StoredProfileCountNonAutofillableFormSubmission) {
948 // Construct a non-fillable form.
949 FormData form;
950 form.name = ASCIIToUTF16("TestForm");
951 form.origin = GURL("http://example.com/form.html");
952 form.action = GURL("http://example.com/submit.html");
954 // Two fields is not enough to make it an autofillable form.
955 FormFieldData field;
956 test::CreateTestFormField("Name", "name", "", "text", &field);
957 form.fields.push_back(field);
958 test::CreateTestFormField("Email", "email", "", "text", &field);
959 form.fields.push_back(field);
961 std::vector<FormData> forms(1, form);
963 // Simulate form submission.
964 base::HistogramTester histogram_tester;
965 autofill_manager_->OnFormsSeen(forms, TimeTicks());
966 autofill_manager_->SubmitForm(form, TimeTicks::Now());
968 // A non-autofillable form was submitted, and number of stored profiles is NOT
969 // logged.
970 histogram_tester.ExpectTotalCount(
971 "Autofill.StoredProfileCountAtAutofillableFormSubmission", 0);
974 // Verify that when submitting an autofillable form, the proper number of edited
975 // fields is logged.
976 TEST_F(AutofillMetricsTest, NumberOfEditedAutofilledFields) {
977 // Construct a fillable form.
978 FormData form;
979 form.name = ASCIIToUTF16("TestForm");
980 form.origin = GURL("http://example.com/form.html");
981 form.action = GURL("http://example.com/submit.html");
983 std::vector<ServerFieldType> heuristic_types, server_types;
985 // Three fields is enough to make it an autofillable form.
986 FormFieldData field;
987 test::CreateTestFormField("Autofilled", "autofilled", "Elvis Aaron Presley",
988 "text", &field);
989 field.is_autofilled = true;
990 form.fields.push_back(field);
991 heuristic_types.push_back(NAME_FULL);
992 server_types.push_back(NAME_FULL);
994 test::CreateTestFormField("Autofill Failed", "autofillfailed",
995 "buddy@gmail.com", "text", &field);
996 field.is_autofilled = true;
997 form.fields.push_back(field);
998 heuristic_types.push_back(EMAIL_ADDRESS);
999 server_types.push_back(EMAIL_ADDRESS);
1001 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
1002 field.is_autofilled = true;
1003 form.fields.push_back(field);
1004 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
1005 server_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
1007 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
1009 base::HistogramTester histogram_tester;
1010 // Simulate text input in the first and second fields.
1011 autofill_manager_->OnTextFieldDidChange(form, form.fields[0], TimeTicks());
1012 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks());
1014 // Simulate form submission.
1015 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1017 // An autofillable form was submitted, and the number of edited autofilled
1018 // fields is logged.
1019 histogram_tester.ExpectUniqueSample(
1020 "Autofill.NumberOfEditedAutofilledFieldsAtSubmission", 2, 1);
1023 // Verify that we correctly log metrics regarding developer engagement.
1024 TEST_F(AutofillMetricsTest, DeveloperEngagement) {
1025 // Start with a non-fillable form.
1026 FormData form;
1027 form.name = ASCIIToUTF16("TestForm");
1028 form.origin = GURL("http://example.com/form.html");
1029 form.action = GURL("http://example.com/submit.html");
1031 FormFieldData field;
1032 test::CreateTestFormField("Name", "name", "", "text", &field);
1033 form.fields.push_back(field);
1034 test::CreateTestFormField("Email", "email", "", "text", &field);
1035 form.fields.push_back(field);
1037 std::vector<FormData> forms(1, form);
1039 // Ensure no metrics are logged when loading a non-fillable form.
1041 base::HistogramTester histogram_tester;
1042 autofill_manager_->OnFormsSeen(forms, TimeTicks());
1043 autofill_manager_->Reset();
1044 histogram_tester.ExpectTotalCount("Autofill.DeveloperEngagement", 0);
1047 // Add another field to the form, so that it becomes fillable.
1048 test::CreateTestFormField("Phone", "phone", "", "text", &field);
1049 forms.back().fields.push_back(field);
1051 // Expect only the "form parsed" metric to be logged; no metrics about
1052 // author-specified field type hints.
1054 base::HistogramTester histogram_tester;
1055 autofill_manager_->OnFormsSeen(forms, TimeTicks());
1056 autofill_manager_->Reset();
1057 histogram_tester.ExpectUniqueSample("Autofill.DeveloperEngagement",
1058 AutofillMetrics::FILLABLE_FORM_PARSED,
1062 // Add some fields with an author-specified field type to the form.
1063 // We need to add at least three fields, because a form must have at least
1064 // three fillable fields to be considered to be autofillable; and if at least
1065 // one field specifies an explicit type hint, we don't apply any of our usual
1066 // local heuristics to detect field types in the rest of the form.
1067 test::CreateTestFormField("", "", "", "text", &field);
1068 field.autocomplete_attribute = "given-name";
1069 forms.back().fields.push_back(field);
1070 test::CreateTestFormField("", "", "", "text", &field);
1071 field.autocomplete_attribute = "email";
1072 forms.back().fields.push_back(field);
1073 test::CreateTestFormField("", "", "", "text", &field);
1074 field.autocomplete_attribute = "address-line1";
1075 forms.back().fields.push_back(field);
1077 // Expect both the "form parsed" metric and the author-specified field type
1078 // hints metric to be logged.
1080 base::HistogramTester histogram_tester;
1081 autofill_manager_->OnFormsSeen(forms, TimeTicks());
1082 autofill_manager_->Reset();
1083 histogram_tester.ExpectBucketCount("Autofill.DeveloperEngagement",
1084 AutofillMetrics::FILLABLE_FORM_PARSED,
1086 histogram_tester.ExpectBucketCount(
1087 "Autofill.DeveloperEngagement",
1088 AutofillMetrics::FILLABLE_FORM_CONTAINS_TYPE_HINTS, 1);
1092 // Test that the profile count is logged correctly.
1093 TEST_F(AutofillMetricsTest, StoredProfileCount) {
1094 // The metric should be logged when the profiles are first loaded.
1096 base::HistogramTester histogram_tester;
1097 personal_data_->LoadProfiles();
1098 histogram_tester.ExpectUniqueSample("Autofill.StoredProfileCount", 2, 1);
1101 // The metric should only be logged once.
1103 base::HistogramTester histogram_tester;
1104 personal_data_->LoadProfiles();
1105 histogram_tester.ExpectTotalCount("Autofill.StoredProfileCount", 0);
1109 // Test that we correctly log when Autofill is enabled.
1110 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) {
1111 base::HistogramTester histogram_tester;
1112 personal_data_->set_autofill_enabled(true);
1113 personal_data_->Init(
1114 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(),
1115 account_tracker_.get(), false);
1116 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.Startup", true, 1);
1119 // Test that we correctly log when Autofill is disabled.
1120 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) {
1121 base::HistogramTester histogram_tester;
1122 personal_data_->set_autofill_enabled(false);
1123 personal_data_->Init(
1124 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(),
1125 account_tracker_.get(), false);
1126 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.Startup", false, 1);
1129 // Test that we log the number of Autofill suggestions when filling a form.
1130 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) {
1131 // Set up our form data.
1132 FormData form;
1133 form.name = ASCIIToUTF16("TestForm");
1134 form.origin = GURL("http://example.com/form.html");
1135 form.action = GURL("http://example.com/submit.html");
1137 FormFieldData field;
1138 std::vector<ServerFieldType> field_types;
1139 test::CreateTestFormField("Name", "name", "", "text", &field);
1140 form.fields.push_back(field);
1141 field_types.push_back(NAME_FULL);
1142 test::CreateTestFormField("Email", "email", "", "email", &field);
1143 form.fields.push_back(field);
1144 field_types.push_back(EMAIL_ADDRESS);
1145 test::CreateTestFormField("Phone", "phone", "", "tel", &field);
1146 form.fields.push_back(field);
1147 field_types.push_back(PHONE_HOME_NUMBER);
1149 // Simulate having seen this form on page load.
1150 // |form_structure| will be owned by |autofill_manager_|.
1151 autofill_manager_->AddSeenForm(form, field_types, field_types);
1154 // Simulate activating the autofill popup for the phone field.
1155 base::HistogramTester histogram_tester;
1156 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1157 histogram_tester.ExpectUniqueSample("Autofill.AddressSuggestionsCount", 2,
1162 // Simulate activating the autofill popup for the email field after typing.
1163 // No new metric should be logged, since we're still on the same page.
1164 test::CreateTestFormField("Email", "email", "b", "email", &field);
1165 base::HistogramTester histogram_tester;
1166 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1167 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0);
1170 // Reset the autofill manager state.
1171 autofill_manager_->Reset();
1172 autofill_manager_->AddSeenForm(form, field_types, field_types);
1175 // Simulate activating the autofill popup for the email field after typing.
1176 base::HistogramTester histogram_tester;
1177 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1178 histogram_tester.ExpectUniqueSample("Autofill.AddressSuggestionsCount", 1,
1182 // Reset the autofill manager state again.
1183 autofill_manager_->Reset();
1184 autofill_manager_->AddSeenForm(form, field_types, field_types);
1187 // Simulate activating the autofill popup for the email field after typing.
1188 form.fields[0].is_autofilled = true;
1189 base::HistogramTester histogram_tester;
1190 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1191 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0);
1195 // Test that we log interacted form event for credit cards related.
1196 TEST_F(AutofillMetricsTest, CreditCardInteractedFormEvents) {
1197 // Set up our form data.
1198 FormData form;
1199 form.name = ASCIIToUTF16("TestForm");
1200 form.origin = GURL("http://example.com/form.html");
1201 form.action = GURL("http://example.com/submit.html");
1203 FormFieldData field;
1204 std::vector<ServerFieldType> field_types;
1205 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1206 form.fields.push_back(field);
1207 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1208 test::CreateTestFormField("Year", "card_year", "", "text", &field);
1209 form.fields.push_back(field);
1210 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1211 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1212 form.fields.push_back(field);
1213 field_types.push_back(CREDIT_CARD_NUMBER);
1215 // Simulate having seen this form on page load.
1216 // |form_structure| will be owned by |autofill_manager_|.
1217 autofill_manager_->AddSeenForm(form, field_types, field_types);
1220 // Simulate activating the autofill popup for the credit card field.
1221 base::HistogramTester histogram_tester;
1222 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1223 histogram_tester.ExpectUniqueSample(
1224 "Autofill.FormEvents.CreditCard",
1225 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
1228 // Reset the autofill manager state.
1229 autofill_manager_->Reset();
1230 autofill_manager_->AddSeenForm(form, field_types, field_types);
1233 // Simulate activating the autofill popup for the credit card field twice.
1234 base::HistogramTester histogram_tester;
1235 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1236 autofill_manager_->OnQueryFormFieldAutofill(1, form, field, gfx::RectF());
1237 histogram_tester.ExpectUniqueSample(
1238 "Autofill.FormEvents.CreditCard",
1239 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
1243 // Test that we log suggestion shown form events for credit cards.
1244 TEST_F(AutofillMetricsTest, CreditCardShownFormEvents) {
1245 // Set up our form data.
1246 FormData form;
1247 form.name = ASCIIToUTF16("TestForm");
1248 form.origin = GURL("http://example.com/form.html");
1249 form.action = GURL("http://example.com/submit.html");
1251 FormFieldData field;
1252 std::vector<ServerFieldType> field_types;
1253 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1254 form.fields.push_back(field);
1255 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1256 test::CreateTestFormField("Year", "card_year", "", "text", &field);
1257 form.fields.push_back(field);
1258 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1259 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1260 form.fields.push_back(field);
1261 field_types.push_back(CREDIT_CARD_NUMBER);
1263 // Simulate having seen this form on page load.
1264 // |form_structure| will be owned by |autofill_manager_|.
1265 autofill_manager_->AddSeenForm(form, field_types, field_types);
1268 // Simulating new popup being shown.
1269 base::HistogramTester histogram_tester;
1270 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
1271 histogram_tester.ExpectBucketCount(
1272 "Autofill.FormEvents.CreditCard",
1273 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 1);
1274 histogram_tester.ExpectBucketCount(
1275 "Autofill.FormEvents.CreditCard",
1276 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 1);
1279 // Reset the autofill manager state.
1280 autofill_manager_->Reset();
1281 autofill_manager_->AddSeenForm(form, field_types, field_types);
1284 // Simulating two popups in the same page load.
1285 base::HistogramTester histogram_tester;
1286 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
1287 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
1288 histogram_tester.ExpectBucketCount(
1289 "Autofill.FormEvents.CreditCard",
1290 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 2);
1291 histogram_tester.ExpectBucketCount(
1292 "Autofill.FormEvents.CreditCard",
1293 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 1);
1296 // Reset the autofill manager state.
1297 autofill_manager_->Reset();
1298 autofill_manager_->AddSeenForm(form, field_types, field_types);
1301 // Simulating same popup being refreshed.
1302 base::HistogramTester histogram_tester;
1303 autofill_manager_->DidShowSuggestions(false /* is_new_popup */, form,
1304 field);
1305 histogram_tester.ExpectBucketCount(
1306 "Autofill.FormEvents.CreditCard",
1307 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0);
1308 histogram_tester.ExpectBucketCount(
1309 "Autofill.FormEvents.CreditCard",
1310 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0);
1314 // Test that we log selected form event for credit cards.
1315 TEST_F(AutofillMetricsTest, CreditCardSelectedFormEvents) {
1316 EnableWalletSync();
1317 // Creating all kinds of cards.
1318 personal_data_->RecreateCreditCards(
1319 true /* include_local_credit_card */,
1320 true /* include_masked_server_credit_card */,
1321 true /* include_full_server_credit_card */);
1322 // Set up our form data.
1323 FormData form;
1324 form.name = ASCIIToUTF16("TestForm");
1325 form.origin = GURL("http://example.com/form.html");
1326 form.action = GURL("http://example.com/submit.html");
1328 FormFieldData field;
1329 std::vector<ServerFieldType> field_types;
1330 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1331 form.fields.push_back(field);
1332 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1333 test::CreateTestFormField("Year", "card_year", "", "text", &field);
1334 form.fields.push_back(field);
1335 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1336 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1337 form.fields.push_back(field);
1338 field_types.push_back(CREDIT_CARD_NUMBER);
1340 // Simulate having seen this form on page load.
1341 // |form_structure| will be owned by |autofill_manager_|.
1342 autofill_manager_->AddSeenForm(form, field_types, field_types);
1345 // Simulating selecting a masked card server suggestion.
1346 base::HistogramTester histogram_tester;
1347 std::string guid(
1348 "10000000-0000-0000-0000-000000000002"); // masked server card
1349 autofill_manager_->FillOrPreviewForm(
1350 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields[2],
1351 autofill_manager_->MakeFrontendID(guid, std::string()));
1352 histogram_tester.ExpectBucketCount(
1353 "Autofill.FormEvents.CreditCard",
1354 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED, 1);
1355 histogram_tester.ExpectBucketCount(
1356 "Autofill.FormEvents.CreditCard",
1357 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED_ONCE,
1361 // Reset the autofill manager state.
1362 autofill_manager_->Reset();
1363 autofill_manager_->AddSeenForm(form, field_types, field_types);
1366 // Simulating selecting multiple times a masked card server.
1367 base::HistogramTester histogram_tester;
1368 std::string guid(
1369 "10000000-0000-0000-0000-000000000002"); // masked server card
1370 autofill_manager_->FillOrPreviewForm(
1371 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields[2],
1372 autofill_manager_->MakeFrontendID(guid, std::string()));
1373 autofill_manager_->FillOrPreviewForm(
1374 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields[2],
1375 autofill_manager_->MakeFrontendID(guid, std::string()));
1376 histogram_tester.ExpectBucketCount(
1377 "Autofill.FormEvents.CreditCard",
1378 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED, 2);
1379 histogram_tester.ExpectBucketCount(
1380 "Autofill.FormEvents.CreditCard",
1381 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED_ONCE,
1386 // Test that we log filled form events for credit cards.
1387 TEST_F(AutofillMetricsTest, CreditCardFilledFormEvents) {
1388 autofill_client_.GetPrefs()->SetBoolean(
1389 prefs::kAutofillWalletSyncExperimentEnabled, true);
1390 // Creating all kinds of cards.
1391 personal_data_->RecreateCreditCards(
1392 true /* include_local_credit_card */,
1393 true /* include_masked_server_credit_card */,
1394 true /* include_full_server_credit_card */);
1395 // Set up our form data.
1396 FormData form;
1397 form.name = ASCIIToUTF16("TestForm");
1398 form.origin = GURL("http://example.com/form.html");
1399 form.action = GURL("http://example.com/submit.html");
1401 FormFieldData field;
1402 std::vector<ServerFieldType> field_types;
1403 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1404 form.fields.push_back(field);
1405 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1406 test::CreateTestFormField("Year", "card_year", "", "text", &field);
1407 form.fields.push_back(field);
1408 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1409 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1410 form.fields.push_back(field);
1411 field_types.push_back(CREDIT_CARD_NUMBER);
1413 // Simulate having seen this form on page load.
1414 // |form_structure| will be owned by |autofill_manager_|.
1415 autofill_manager_->AddSeenForm(form, field_types, field_types);
1418 // Simulating filling a local card suggestion.
1419 base::HistogramTester histogram_tester;
1420 std::string guid("10000000-0000-0000-0000-000000000001"); // local card
1421 autofill_manager_->FillOrPreviewForm(
1422 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1423 autofill_manager_->MakeFrontendID(guid, std::string()));
1424 histogram_tester.ExpectBucketCount(
1425 "Autofill.FormEvents.CreditCard",
1426 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 1);
1427 histogram_tester.ExpectBucketCount(
1428 "Autofill.FormEvents.CreditCard",
1429 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1);
1432 // Reset the autofill manager state.
1433 autofill_manager_->Reset();
1434 autofill_manager_->AddSeenForm(form, field_types, field_types);
1437 // Simulating filling a masked card server suggestion.
1438 base::HistogramTester histogram_tester;
1439 std::string guid(
1440 "10000000-0000-0000-0000-000000000002"); // masked server card
1441 autofill_manager_->FillOrPreviewForm(
1442 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1443 autofill_manager_->MakeFrontendID(guid, std::string()));
1444 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
1445 "6011000990139424");
1446 histogram_tester.ExpectBucketCount(
1447 "Autofill.FormEvents.CreditCard",
1448 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1);
1449 histogram_tester.ExpectBucketCount(
1450 "Autofill.FormEvents.CreditCard",
1451 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE,
1455 // Recreating cards as the previous test should have upgraded the masked
1456 // card to a full card.
1457 personal_data_->RecreateCreditCards(
1458 true /* include_local_credit_card */,
1459 true /* include_masked_server_credit_card */,
1460 true /* include_full_server_credit_card */);
1462 // Reset the autofill manager state.
1463 autofill_manager_->Reset();
1464 autofill_manager_->AddSeenForm(form, field_types, field_types);
1467 // Simulating filling a full card server suggestion.
1468 base::HistogramTester histogram_tester;
1469 std::string guid(
1470 "10000000-0000-0000-0000-000000000003"); // full server card
1471 autofill_manager_->FillOrPreviewForm(
1472 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1473 autofill_manager_->MakeFrontendID(guid, std::string()));
1474 histogram_tester.ExpectBucketCount(
1475 "Autofill.FormEvents.CreditCard",
1476 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED, 1);
1477 histogram_tester.ExpectBucketCount(
1478 "Autofill.FormEvents.CreditCard",
1479 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE, 1);
1482 // Reset the autofill manager state.
1483 autofill_manager_->Reset();
1484 autofill_manager_->AddSeenForm(form, field_types, field_types);
1487 // Simulating filling multiple times.
1488 base::HistogramTester histogram_tester;
1489 std::string guid("10000000-0000-0000-0000-000000000001"); // local card
1490 autofill_manager_->FillOrPreviewForm(
1491 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1492 autofill_manager_->MakeFrontendID(guid, std::string()));
1493 autofill_manager_->FillOrPreviewForm(
1494 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1495 autofill_manager_->MakeFrontendID(guid, std::string()));
1496 histogram_tester.ExpectBucketCount(
1497 "Autofill.FormEvents.CreditCard",
1498 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2);
1499 histogram_tester.ExpectBucketCount(
1500 "Autofill.FormEvents.CreditCard",
1501 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1);
1505 // Test that we log submitted form events for credit cards.
1506 TEST_F(AutofillMetricsTest, CreditCardGetRealPanDuration) {
1507 EnableWalletSync();
1508 // Creating masked card
1509 personal_data_->RecreateCreditCards(
1510 false /* include_local_credit_card */,
1511 true /* include_masked_server_credit_card */,
1512 false /* include_full_server_credit_card */);
1513 // Set up our form data.
1514 FormData form;
1515 form.name = ASCIIToUTF16("TestForm");
1516 form.origin = GURL("http://example.com/form.html");
1517 form.action = GURL("http://example.com/submit.html");
1519 FormFieldData field;
1520 std::vector<ServerFieldType> field_types;
1521 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1522 form.fields.push_back(field);
1523 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1524 test::CreateTestFormField("Year", "card_year", "", "text", &field);
1525 form.fields.push_back(field);
1526 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1527 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1528 form.fields.push_back(field);
1529 field_types.push_back(CREDIT_CARD_NUMBER);
1531 // Simulate having seen this form on page load.
1532 // |form_structure| will be owned by |autofill_manager_|.
1533 autofill_manager_->AddSeenForm(form, field_types, field_types);
1536 // Simulating filling a masked card server suggestion.
1537 base::HistogramTester histogram_tester;
1538 // Masked server card.
1539 std::string guid("10000000-0000-0000-0000-000000000002");
1540 autofill_manager_->FillOrPreviewForm(
1541 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1542 autofill_manager_->MakeFrontendID(guid, std::string()));
1543 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
1544 "6011000990139424");
1545 histogram_tester.ExpectTotalCount(
1546 "Autofill.UnmaskPrompt.GetRealPanDuration", 1);
1547 histogram_tester.ExpectTotalCount(
1548 "Autofill.UnmaskPrompt.GetRealPanDuration.Success", 1);
1551 // Reset the autofill manager state.
1552 autofill_manager_->Reset();
1553 autofill_manager_->AddSeenForm(form, field_types, field_types);
1554 // Creating masked card
1555 personal_data_->RecreateCreditCards(
1556 false /* include_local_credit_card */,
1557 true /* include_masked_server_credit_card */,
1558 false /* include_full_server_credit_card */);
1561 // Simulating filling a masked card server suggestion.
1562 base::HistogramTester histogram_tester;
1563 // Masked server card.
1564 std::string guid("10000000-0000-0000-0000-000000000002");
1565 autofill_manager_->FillOrPreviewForm(
1566 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1567 autofill_manager_->MakeFrontendID(guid, std::string()));
1568 autofill_manager_->OnDidGetRealPan(AutofillClient::PERMANENT_FAILURE,
1569 std::string());
1570 histogram_tester.ExpectTotalCount(
1571 "Autofill.UnmaskPrompt.GetRealPanDuration", 1);
1572 histogram_tester.ExpectTotalCount(
1573 "Autofill.UnmaskPrompt.GetRealPanDuration.Failure", 1);
1577 // Test that we log submitted form events for credit cards.
1578 TEST_F(AutofillMetricsTest, CreditCardSubmittedFormEvents) {
1579 EnableWalletSync();
1580 // Creating all kinds of cards.
1581 personal_data_->RecreateCreditCards(
1582 true /* include_local_credit_card */,
1583 true /* include_masked_server_credit_card */,
1584 true /* include_full_server_credit_card */);
1585 // Set up our form data.
1586 FormData form;
1587 form.name = ASCIIToUTF16("TestForm");
1588 form.origin = GURL("http://example.com/form.html");
1589 form.action = GURL("http://example.com/submit.html");
1591 FormFieldData field;
1592 std::vector<ServerFieldType> field_types;
1593 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1594 form.fields.push_back(field);
1595 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1596 test::CreateTestFormField("Year", "card_year", "", "text", &field);
1597 form.fields.push_back(field);
1598 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1599 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1600 form.fields.push_back(field);
1601 field_types.push_back(CREDIT_CARD_NUMBER);
1603 // Simulate having seen this form on page load.
1604 // |form_structure| will be owned by |autofill_manager_|.
1605 autofill_manager_->AddSeenForm(form, field_types, field_types);
1608 // Simulating submission with no filled data.
1609 base::HistogramTester histogram_tester;
1610 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1611 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1612 histogram_tester.ExpectBucketCount(
1613 "Autofill.FormEvents.CreditCard",
1614 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1615 histogram_tester.ExpectBucketCount(
1616 "Autofill.FormEvents.CreditCard",
1617 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
1620 // Reset the autofill manager state.
1621 autofill_manager_->Reset();
1622 autofill_manager_->AddSeenForm(form, field_types, field_types);
1625 // Simulating submission with filled local data.
1626 base::HistogramTester histogram_tester;
1627 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1628 std::string guid("10000000-0000-0000-0000-000000000001"); // local card
1629 autofill_manager_->FillOrPreviewForm(
1630 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1631 autofill_manager_->MakeFrontendID(guid, std::string()));
1632 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1633 histogram_tester.ExpectBucketCount(
1634 "Autofill.FormEvents.CreditCard",
1635 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1636 histogram_tester.ExpectBucketCount(
1637 "Autofill.FormEvents.CreditCard",
1638 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1);
1641 // Reset the autofill manager state.
1642 autofill_manager_->Reset();
1643 autofill_manager_->AddSeenForm(form, field_types, field_types);
1646 // Simulating submission with filled server data.
1647 base::HistogramTester histogram_tester;
1648 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1649 std::string guid(
1650 "10000000-0000-0000-0000-000000000003"); // full server card
1651 autofill_manager_->FillOrPreviewForm(
1652 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1653 autofill_manager_->MakeFrontendID(guid, std::string()));
1654 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1655 histogram_tester.ExpectBucketCount(
1656 "Autofill.FormEvents.CreditCard",
1657 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1658 histogram_tester.ExpectBucketCount(
1659 "Autofill.FormEvents.CreditCard",
1660 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1);
1663 // Reset the autofill manager state.
1664 autofill_manager_->Reset();
1665 autofill_manager_->AddSeenForm(form, field_types, field_types);
1668 // Simulating submission with a masked card server suggestion.
1669 base::HistogramTester histogram_tester;
1670 std::string guid(
1671 "10000000-0000-0000-0000-000000000002"); // masked server card
1672 autofill_manager_->FillOrPreviewForm(
1673 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1674 autofill_manager_->MakeFrontendID(guid, std::string()));
1675 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
1676 "6011000990139424");
1677 histogram_tester.ExpectBucketCount(
1678 "Autofill.FormEvents.CreditCard",
1679 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1);
1680 histogram_tester.ExpectBucketCount(
1681 "Autofill.FormEvents.CreditCard",
1682 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE,
1686 // Recreating cards as the previous test should have upgraded the masked
1687 // card to a full card.
1688 personal_data_->RecreateCreditCards(
1689 true /* include_local_credit_card */,
1690 true /* include_masked_server_credit_card */,
1691 true /* include_full_server_credit_card */);
1693 // Reset the autofill manager state.
1694 autofill_manager_->Reset();
1695 autofill_manager_->AddSeenForm(form, field_types, field_types);
1698 // Simulating multiple submissions.
1699 base::HistogramTester histogram_tester;
1700 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1701 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1702 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1703 histogram_tester.ExpectBucketCount(
1704 "Autofill.FormEvents.CreditCard",
1705 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1706 histogram_tester.ExpectBucketCount(
1707 "Autofill.FormEvents.CreditCard",
1708 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1709 histogram_tester.ExpectBucketCount(
1710 "Autofill.FormEvents.CreditCard",
1711 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1712 histogram_tester.ExpectBucketCount(
1713 "Autofill.FormEvents.CreditCard",
1714 AutofillMetrics::
1715 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE,
1717 histogram_tester.ExpectBucketCount(
1718 "Autofill.FormEvents.CreditCard",
1719 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
1720 histogram_tester.ExpectBucketCount(
1721 "Autofill.FormEvents.CreditCard",
1722 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
1723 histogram_tester.ExpectBucketCount(
1724 "Autofill.FormEvents.CreditCard",
1725 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1726 histogram_tester.ExpectBucketCount(
1727 "Autofill.FormEvents.CreditCard",
1728 AutofillMetrics::
1729 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE,
1733 // Reset the autofill manager state.
1734 autofill_manager_->Reset();
1735 autofill_manager_->AddSeenForm(form, field_types, field_types);
1738 // Simulating submission without previous interaction.
1739 base::HistogramTester histogram_tester;
1740 autofill_manager_->SubmitForm(form, TimeTicks::Now());
1741 histogram_tester.ExpectBucketCount(
1742 "Autofill.FormEvents.CreditCard",
1743 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1744 histogram_tester.ExpectBucketCount(
1745 "Autofill.FormEvents.CreditCard",
1746 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1747 histogram_tester.ExpectBucketCount(
1748 "Autofill.FormEvents.CreditCard",
1749 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1750 histogram_tester.ExpectBucketCount(
1751 "Autofill.FormEvents.CreditCard",
1752 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
1753 histogram_tester.ExpectBucketCount(
1754 "Autofill.FormEvents.CreditCard",
1755 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1756 histogram_tester.ExpectBucketCount(
1757 "Autofill.FormEvents.CreditCard",
1758 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1762 // Test that we log "will submit" (but not submitted) form events for credit
1763 // cards. Mirrors CreditCardSubmittedFormEvents test but does not expect any
1764 // "submitted" metrics.
1765 TEST_F(AutofillMetricsTest, CreditCardWillSubmitFormEvents) {
1766 EnableWalletSync();
1767 // Creating all kinds of cards.
1768 personal_data_->RecreateCreditCards(
1769 true /* include_local_credit_card */,
1770 true /* include_masked_server_credit_card */,
1771 true /* include_full_server_credit_card */);
1772 // Set up our form data.
1773 FormData form;
1774 form.name = ASCIIToUTF16("TestForm");
1775 form.origin = GURL("http://example.com/form.html");
1776 form.action = GURL("http://example.com/submit.html");
1778 FormFieldData field;
1779 std::vector<ServerFieldType> field_types;
1780 test::CreateTestFormField("Month", "card_month", "", "text", &field);
1781 form.fields.push_back(field);
1782 field_types.push_back(CREDIT_CARD_EXP_MONTH);
1783 test::CreateTestFormField("Year", "card_year", "", "text", &field);
1784 form.fields.push_back(field);
1785 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
1786 test::CreateTestFormField("Credit card", "card", "", "text", &field);
1787 form.fields.push_back(field);
1788 field_types.push_back(CREDIT_CARD_NUMBER);
1790 // Simulate having seen this form on page load.
1791 // |form_structure| will be owned by |autofill_manager_|.
1792 autofill_manager_->AddSeenForm(form, field_types, field_types);
1795 // Simulating submission with no filled data.
1796 base::HistogramTester histogram_tester;
1797 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1798 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1799 histogram_tester.ExpectBucketCount(
1800 "Autofill.FormEvents.CreditCard",
1801 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1802 histogram_tester.ExpectBucketCount(
1803 "Autofill.FormEvents.CreditCard",
1804 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
1807 // Reset the autofill manager state.
1808 autofill_manager_->Reset();
1809 autofill_manager_->AddSeenForm(form, field_types, field_types);
1812 // Simulating submission with filled local data.
1813 base::HistogramTester histogram_tester;
1814 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1815 std::string guid("10000000-0000-0000-0000-000000000001"); // local card
1816 autofill_manager_->FillOrPreviewForm(
1817 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1818 autofill_manager_->MakeFrontendID(guid, std::string()));
1819 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1820 histogram_tester.ExpectBucketCount(
1821 "Autofill.FormEvents.CreditCard",
1822 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1823 histogram_tester.ExpectBucketCount(
1824 "Autofill.FormEvents.CreditCard",
1825 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
1828 // Reset the autofill manager state.
1829 autofill_manager_->Reset();
1830 autofill_manager_->AddSeenForm(form, field_types, field_types);
1833 // Simulating submission with filled server data.
1834 base::HistogramTester histogram_tester;
1835 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1836 // Full server card.
1837 std::string guid("10000000-0000-0000-0000-000000000003");
1838 autofill_manager_->FillOrPreviewForm(
1839 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1840 autofill_manager_->MakeFrontendID(guid, std::string()));
1841 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1842 histogram_tester.ExpectBucketCount(
1843 "Autofill.FormEvents.CreditCard",
1844 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1845 histogram_tester.ExpectBucketCount(
1846 "Autofill.FormEvents.CreditCard",
1847 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1850 // Reset the autofill manager state.
1851 autofill_manager_->Reset();
1852 autofill_manager_->AddSeenForm(form, field_types, field_types);
1855 // Simulating submission with a masked card server suggestion.
1856 base::HistogramTester histogram_tester;
1857 // Masked server card.
1858 std::string guid("10000000-0000-0000-0000-000000000002");
1859 autofill_manager_->FillOrPreviewForm(
1860 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
1861 autofill_manager_->MakeFrontendID(guid, std::string()));
1862 autofill_manager_->OnDidGetRealPan(AutofillClient::SUCCESS,
1863 "6011000990139424");
1864 histogram_tester.ExpectBucketCount(
1865 "Autofill.FormEvents.CreditCard",
1866 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, 1);
1867 histogram_tester.ExpectBucketCount(
1868 "Autofill.FormEvents.CreditCard",
1869 AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE,
1873 // Recreating cards as the previous test should have upgraded the masked
1874 // card to a full card.
1875 personal_data_->RecreateCreditCards(
1876 true /* include_local_credit_card */,
1877 true /* include_masked_server_credit_card */,
1878 true /* include_full_server_credit_card */);
1880 // Reset the autofill manager state.
1881 autofill_manager_->Reset();
1882 autofill_manager_->AddSeenForm(form, field_types, field_types);
1885 // Simulating multiple submissions.
1886 base::HistogramTester histogram_tester;
1887 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1888 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1889 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1890 histogram_tester.ExpectBucketCount(
1891 "Autofill.FormEvents.CreditCard",
1892 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
1893 histogram_tester.ExpectBucketCount(
1894 "Autofill.FormEvents.CreditCard",
1895 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1896 histogram_tester.ExpectBucketCount(
1897 "Autofill.FormEvents.CreditCard",
1898 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1899 histogram_tester.ExpectBucketCount(
1900 "Autofill.FormEvents.CreditCard",
1901 AutofillMetrics::
1902 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE,
1904 histogram_tester.ExpectBucketCount(
1905 "Autofill.FormEvents.CreditCard",
1906 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
1907 histogram_tester.ExpectBucketCount(
1908 "Autofill.FormEvents.CreditCard",
1909 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
1910 histogram_tester.ExpectBucketCount(
1911 "Autofill.FormEvents.CreditCard",
1912 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1913 histogram_tester.ExpectBucketCount(
1914 "Autofill.FormEvents.CreditCard",
1915 AutofillMetrics
1916 ::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE,
1920 // Reset the autofill manager state.
1921 autofill_manager_->Reset();
1922 autofill_manager_->AddSeenForm(form, field_types, field_types);
1925 // Simulating submission without previous interaction.
1926 base::HistogramTester histogram_tester;
1927 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
1928 histogram_tester.ExpectBucketCount(
1929 "Autofill.FormEvents.CreditCard",
1930 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1931 histogram_tester.ExpectBucketCount(
1932 "Autofill.FormEvents.CreditCard",
1933 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1934 histogram_tester.ExpectBucketCount(
1935 "Autofill.FormEvents.CreditCard",
1936 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
1937 histogram_tester.ExpectBucketCount(
1938 "Autofill.FormEvents.CreditCard",
1939 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
1940 histogram_tester.ExpectBucketCount(
1941 "Autofill.FormEvents.CreditCard",
1942 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1943 histogram_tester.ExpectBucketCount(
1944 "Autofill.FormEvents.CreditCard",
1945 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
1949 // Test that we log interacted form events for address.
1950 TEST_F(AutofillMetricsTest, AddressInteractedFormEvents) {
1951 // Set up our form data.
1952 FormData form;
1953 form.name = ASCIIToUTF16("TestForm");
1954 form.origin = GURL("http://example.com/form.html");
1955 form.action = GURL("http://example.com/submit.html");
1957 FormFieldData field;
1958 std::vector<ServerFieldType> field_types;
1959 test::CreateTestFormField("State", "state", "", "text", &field);
1960 form.fields.push_back(field);
1961 field_types.push_back(ADDRESS_HOME_STATE);
1962 test::CreateTestFormField("City", "city", "", "text", &field);
1963 form.fields.push_back(field);
1964 field_types.push_back(ADDRESS_HOME_CITY);
1965 test::CreateTestFormField("Street", "street", "", "text", &field);
1966 form.fields.push_back(field);
1967 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS);
1969 // Simulate having seen this form on page load.
1970 // |form_structure| will be owned by |autofill_manager_|.
1971 autofill_manager_->AddSeenForm(form, field_types, field_types);
1974 // Simulate activating the autofill popup for the street field.
1975 base::HistogramTester histogram_tester;
1976 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1977 histogram_tester.ExpectUniqueSample(
1978 "Autofill.FormEvents.Address",
1979 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
1982 // Reset the autofill manager state.
1983 autofill_manager_->Reset();
1984 autofill_manager_->AddSeenForm(form, field_types, field_types);
1987 // Simulate activating the autofill popup for the street field twice.
1988 base::HistogramTester histogram_tester;
1989 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
1990 autofill_manager_->OnQueryFormFieldAutofill(1, form, field, gfx::RectF());
1991 histogram_tester.ExpectUniqueSample(
1992 "Autofill.FormEvents.Address",
1993 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
1997 // Test that we log suggestion shown form events for address.
1998 TEST_F(AutofillMetricsTest, AddressShownFormEvents) {
1999 EnableWalletSync();
2000 // Creating all kinds of profiles.
2001 personal_data_->RecreateProfiles(true /* include_local_profile */,
2002 true /* include_server_profile */);
2003 // Set up our form data.
2004 FormData form;
2005 form.name = ASCIIToUTF16("TestForm");
2006 form.origin = GURL("http://example.com/form.html");
2007 form.action = GURL("http://example.com/submit.html");
2009 FormFieldData field;
2010 std::vector<ServerFieldType> field_types;
2011 test::CreateTestFormField("State", "state", "", "text", &field);
2012 form.fields.push_back(field);
2013 field_types.push_back(ADDRESS_HOME_STATE);
2014 test::CreateTestFormField("City", "city", "", "text", &field);
2015 form.fields.push_back(field);
2016 field_types.push_back(ADDRESS_HOME_CITY);
2017 test::CreateTestFormField("Street", "street", "", "text", &field);
2018 form.fields.push_back(field);
2019 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS);
2021 // Simulate having seen this form on page load.
2022 // |form_structure| will be owned by |autofill_manager_|.
2023 autofill_manager_->AddSeenForm(form, field_types, field_types);
2026 // Simulating new popup being shown.
2027 base::HistogramTester histogram_tester;
2028 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
2029 histogram_tester.ExpectBucketCount(
2030 "Autofill.FormEvents.Address",
2031 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 1);
2032 histogram_tester.ExpectBucketCount(
2033 "Autofill.FormEvents.Address",
2034 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 1);
2037 // Reset the autofill manager state.
2038 autofill_manager_->Reset();
2039 autofill_manager_->AddSeenForm(form, field_types, field_types);
2042 // Simulating two popups in the same page load.
2043 base::HistogramTester histogram_tester;
2044 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
2045 autofill_manager_->DidShowSuggestions(true /* is_new_popup */, form, field);
2046 histogram_tester.ExpectBucketCount(
2047 "Autofill.FormEvents.Address",
2048 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 2);
2049 histogram_tester.ExpectBucketCount(
2050 "Autofill.FormEvents.Address",
2051 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 1);
2054 // Reset the autofill manager state.
2055 autofill_manager_->Reset();
2056 autofill_manager_->AddSeenForm(form, field_types, field_types);
2059 // Simulating same popup being refreshed.
2060 base::HistogramTester histogram_tester;
2061 autofill_manager_->DidShowSuggestions(false /* is_new_popup */, form,
2062 field);
2063 histogram_tester.ExpectBucketCount(
2064 "Autofill.FormEvents.Address",
2065 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, 0);
2066 histogram_tester.ExpectBucketCount(
2067 "Autofill.FormEvents.Address",
2068 AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, 0);
2072 // Test that we log filled form events for address.
2073 TEST_F(AutofillMetricsTest, AddressFilledFormEvents) {
2074 EnableWalletSync();
2075 // Creating all kinds of profiles.
2076 personal_data_->RecreateProfiles(true /* include_local_profile */,
2077 true /* include_server_profile */);
2078 // Set up our form data.
2079 FormData form;
2080 form.name = ASCIIToUTF16("TestForm");
2081 form.origin = GURL("http://example.com/form.html");
2082 form.action = GURL("http://example.com/submit.html");
2084 FormFieldData field;
2085 std::vector<ServerFieldType> field_types;
2086 test::CreateTestFormField("State", "state", "", "text", &field);
2087 form.fields.push_back(field);
2088 field_types.push_back(ADDRESS_HOME_STATE);
2089 test::CreateTestFormField("City", "city", "", "text", &field);
2090 form.fields.push_back(field);
2091 field_types.push_back(ADDRESS_HOME_CITY);
2092 test::CreateTestFormField("Street", "street", "", "text", &field);
2093 form.fields.push_back(field);
2094 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS);
2096 // Simulate having seen this form on page load.
2097 // |form_structure| will be owned by |autofill_manager_|.
2098 autofill_manager_->AddSeenForm(form, field_types, field_types);
2101 // Simulating selecting/filling a local profile suggestion.
2102 base::HistogramTester histogram_tester;
2103 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile
2104 autofill_manager_->FillOrPreviewForm(
2105 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2106 autofill_manager_->MakeFrontendID(std::string(), guid));
2107 histogram_tester.ExpectBucketCount(
2108 "Autofill.FormEvents.Address",
2109 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 1);
2110 histogram_tester.ExpectBucketCount(
2111 "Autofill.FormEvents.Address",
2112 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1);
2115 // Reset the autofill manager state.
2116 autofill_manager_->Reset();
2117 autofill_manager_->AddSeenForm(form, field_types, field_types);
2120 // Simulating selecting/filling a server profile suggestion.
2121 base::HistogramTester histogram_tester;
2122 std::string guid("00000000-0000-0000-0000-000000000002"); // server profile
2123 autofill_manager_->FillOrPreviewForm(
2124 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2125 autofill_manager_->MakeFrontendID(std::string(), guid));
2126 histogram_tester.ExpectBucketCount(
2127 "Autofill.FormEvents.Address",
2128 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED, 1);
2129 histogram_tester.ExpectBucketCount(
2130 "Autofill.FormEvents.Address",
2131 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE, 1);
2134 // Reset the autofill manager state.
2135 autofill_manager_->Reset();
2136 autofill_manager_->AddSeenForm(form, field_types, field_types);
2139 // Simulating selecting/filling a local profile suggestion.
2140 base::HistogramTester histogram_tester;
2141 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile
2142 autofill_manager_->FillOrPreviewForm(
2143 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2144 autofill_manager_->MakeFrontendID(std::string(), guid));
2145 autofill_manager_->FillOrPreviewForm(
2146 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2147 autofill_manager_->MakeFrontendID(std::string(), guid));
2148 histogram_tester.ExpectBucketCount(
2149 "Autofill.FormEvents.Address",
2150 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, 2);
2151 histogram_tester.ExpectBucketCount(
2152 "Autofill.FormEvents.Address",
2153 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, 1);
2157 // Test that we log submitted form events for address.
2158 TEST_F(AutofillMetricsTest, AddressSubmittedFormEvents) {
2159 EnableWalletSync();
2160 // Creating all kinds of profiles.
2161 personal_data_->RecreateProfiles(true /* include_local_profile */,
2162 true /* include_server_profile */);
2163 // Set up our form data.
2164 FormData form;
2165 form.name = ASCIIToUTF16("TestForm");
2166 form.origin = GURL("http://example.com/form.html");
2167 form.action = GURL("http://example.com/submit.html");
2169 FormFieldData field;
2170 std::vector<ServerFieldType> field_types;
2171 test::CreateTestFormField("State", "state", "", "text", &field);
2172 form.fields.push_back(field);
2173 field_types.push_back(ADDRESS_HOME_STATE);
2174 test::CreateTestFormField("City", "city", "", "text", &field);
2175 form.fields.push_back(field);
2176 field_types.push_back(ADDRESS_HOME_CITY);
2177 test::CreateTestFormField("Street", "street", "", "text", &field);
2178 form.fields.push_back(field);
2179 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS);
2181 // Simulate having seen this form on page load.
2182 // |form_structure| will be owned by |autofill_manager_|.
2183 autofill_manager_->AddSeenForm(form, field_types, field_types);
2186 // Simulating submission with no filled data.
2187 base::HistogramTester histogram_tester;
2188 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2189 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2190 histogram_tester.ExpectBucketCount(
2191 "Autofill.FormEvents.Address",
2192 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2193 histogram_tester.ExpectBucketCount(
2194 "Autofill.FormEvents.Address",
2195 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
2198 // Reset the autofill manager state.
2199 autofill_manager_->Reset();
2200 autofill_manager_->AddSeenForm(form, field_types, field_types);
2203 // Simulating submission with filled local data.
2204 base::HistogramTester histogram_tester;
2205 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2206 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile
2207 autofill_manager_->FillOrPreviewForm(
2208 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2209 autofill_manager_->MakeFrontendID(std::string(), guid));
2210 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2211 histogram_tester.ExpectBucketCount(
2212 "Autofill.FormEvents.Address",
2213 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2214 histogram_tester.ExpectBucketCount(
2215 "Autofill.FormEvents.Address",
2216 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 1);
2219 // Reset the autofill manager state.
2220 autofill_manager_->Reset();
2221 autofill_manager_->AddSeenForm(form, field_types, field_types);
2224 // Simulating submission with filled server data.
2225 base::HistogramTester histogram_tester;
2226 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2227 std::string guid("00000000-0000-0000-0000-000000000002"); // server profile
2228 autofill_manager_->FillOrPreviewForm(
2229 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2230 autofill_manager_->MakeFrontendID(std::string(), guid));
2231 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2232 histogram_tester.ExpectBucketCount(
2233 "Autofill.FormEvents.Address",
2234 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2235 histogram_tester.ExpectBucketCount(
2236 "Autofill.FormEvents.Address",
2237 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 1);
2240 // Reset the autofill manager state.
2241 autofill_manager_->Reset();
2242 autofill_manager_->AddSeenForm(form, field_types, field_types);
2245 // Simulating multiple submissions.
2246 base::HistogramTester histogram_tester;
2247 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2248 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2249 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2250 histogram_tester.ExpectBucketCount(
2251 "Autofill.FormEvents.Address",
2252 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2253 histogram_tester.ExpectBucketCount(
2254 "Autofill.FormEvents.Address",
2255 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2256 histogram_tester.ExpectBucketCount(
2257 "Autofill.FormEvents.Address",
2258 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2259 histogram_tester.ExpectBucketCount(
2260 "Autofill.FormEvents.Address",
2261 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 1);
2262 histogram_tester.ExpectBucketCount(
2263 "Autofill.FormEvents.Address",
2264 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
2265 histogram_tester.ExpectBucketCount(
2266 "Autofill.FormEvents.Address",
2267 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
2270 // Reset the autofill manager state.
2271 autofill_manager_->Reset();
2272 autofill_manager_->AddSeenForm(form, field_types, field_types);
2275 // Simulating submission without previous interaction.
2276 base::HistogramTester histogram_tester;
2277 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2278 histogram_tester.ExpectBucketCount(
2279 "Autofill.FormEvents.Address",
2280 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2281 histogram_tester.ExpectBucketCount(
2282 "Autofill.FormEvents.Address",
2283 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2284 histogram_tester.ExpectBucketCount(
2285 "Autofill.FormEvents.Address",
2286 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2287 histogram_tester.ExpectBucketCount(
2288 "Autofill.FormEvents.Address",
2289 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
2290 histogram_tester.ExpectBucketCount(
2291 "Autofill.FormEvents.Address",
2292 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
2293 histogram_tester.ExpectBucketCount(
2294 "Autofill.FormEvents.Address",
2295 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
2299 // Test that we log "will submit" (but not submitted) form events for address.
2300 // Mirrors AddressSubmittedFormEvents test but does not expect any "submitted"
2301 // metrics.
2302 TEST_F(AutofillMetricsTest, AddressWillSubmitFormEvents) {
2303 EnableWalletSync();
2304 // Creating all kinds of profiles.
2305 personal_data_->RecreateProfiles(true /* include_local_profile */,
2306 true /* include_server_profile */);
2307 // Set up our form data.
2308 FormData form;
2309 form.name = ASCIIToUTF16("TestForm");
2310 form.origin = GURL("http://example.com/form.html");
2311 form.action = GURL("http://example.com/submit.html");
2313 FormFieldData field;
2314 std::vector<ServerFieldType> field_types;
2315 test::CreateTestFormField("State", "state", "", "text", &field);
2316 form.fields.push_back(field);
2317 field_types.push_back(ADDRESS_HOME_STATE);
2318 test::CreateTestFormField("City", "city", "", "text", &field);
2319 form.fields.push_back(field);
2320 field_types.push_back(ADDRESS_HOME_CITY);
2321 test::CreateTestFormField("Street", "street", "", "text", &field);
2322 form.fields.push_back(field);
2323 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS);
2325 // Simulate having seen this form on page load.
2326 // |form_structure| will be owned by |autofill_manager_|.
2327 autofill_manager_->AddSeenForm(form, field_types, field_types);
2330 // Simulating submission with no filled data.
2331 base::HistogramTester histogram_tester;
2332 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2333 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
2334 histogram_tester.ExpectBucketCount(
2335 "Autofill.FormEvents.Address",
2336 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2337 histogram_tester.ExpectBucketCount(
2338 "Autofill.FormEvents.Address",
2339 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
2342 // Reset the autofill manager state.
2343 autofill_manager_->Reset();
2344 autofill_manager_->AddSeenForm(form, field_types, field_types);
2347 // Simulating submission with filled local data.
2348 base::HistogramTester histogram_tester;
2349 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2350 std::string guid("00000000-0000-0000-0000-000000000001"); // local profile
2351 autofill_manager_->FillOrPreviewForm(
2352 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2353 autofill_manager_->MakeFrontendID(std::string(), guid));
2354 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
2355 histogram_tester.ExpectBucketCount(
2356 "Autofill.FormEvents.Address",
2357 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2358 histogram_tester.ExpectBucketCount(
2359 "Autofill.FormEvents.Address",
2360 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
2363 // Reset the autofill manager state.
2364 autofill_manager_->Reset();
2365 autofill_manager_->AddSeenForm(form, field_types, field_types);
2368 // Simulating submission with filled server data.
2369 base::HistogramTester histogram_tester;
2370 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2371 std::string guid("00000000-0000-0000-0000-000000000002"); // server profile
2372 autofill_manager_->FillOrPreviewForm(
2373 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2374 autofill_manager_->MakeFrontendID(std::string(), guid));
2375 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
2376 histogram_tester.ExpectBucketCount(
2377 "Autofill.FormEvents.Address",
2378 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2379 histogram_tester.ExpectBucketCount(
2380 "Autofill.FormEvents.Address",
2381 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
2384 // Reset the autofill manager state.
2385 autofill_manager_->Reset();
2386 autofill_manager_->AddSeenForm(form, field_types, field_types);
2389 // Simulating multiple submissions.
2390 base::HistogramTester histogram_tester;
2391 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2392 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
2393 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
2394 histogram_tester.ExpectBucketCount(
2395 "Autofill.FormEvents.Address",
2396 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 1);
2397 histogram_tester.ExpectBucketCount(
2398 "Autofill.FormEvents.Address",
2399 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
2400 histogram_tester.ExpectBucketCount(
2401 "Autofill.FormEvents.Address",
2402 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
2403 histogram_tester.ExpectBucketCount(
2404 "Autofill.FormEvents.Address",
2405 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
2408 // Reset the autofill manager state.
2409 autofill_manager_->Reset();
2410 autofill_manager_->AddSeenForm(form, field_types, field_types);
2413 // Simulating submission without previous interaction.
2414 base::HistogramTester histogram_tester;
2415 autofill_manager_->WillSubmitForm(form, TimeTicks::Now());
2416 histogram_tester.ExpectBucketCount(
2417 "Autofill.FormEvents.Address",
2418 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2419 histogram_tester.ExpectBucketCount(
2420 "Autofill.FormEvents.Address",
2421 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2422 histogram_tester.ExpectBucketCount(
2423 "Autofill.FormEvents.Address",
2424 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, 0);
2425 histogram_tester.ExpectBucketCount(
2426 "Autofill.FormEvents.Address",
2427 AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, 0);
2428 histogram_tester.ExpectBucketCount(
2429 "Autofill.FormEvents.Address",
2430 AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, 0);
2431 histogram_tester.ExpectBucketCount(
2432 "Autofill.FormEvents.Address",
2433 AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, 0);
2437 // Test that we log interacted form event for credit cards only once.
2438 TEST_F(AutofillMetricsTest, CreditCardFormEventsAreSegmented) {
2439 EnableWalletSync();
2441 // Set up our form data.
2442 FormData form;
2443 form.name = ASCIIToUTF16("TestForm");
2444 form.origin = GURL("http://example.com/form.html");
2445 form.action = GURL("http://example.com/submit.html");
2447 FormFieldData field;
2448 std::vector<ServerFieldType> field_types;
2449 test::CreateTestFormField("Month", "card_month", "", "text", &field);
2450 form.fields.push_back(field);
2451 field_types.push_back(CREDIT_CARD_EXP_MONTH);
2452 test::CreateTestFormField("Year", "card_year", "", "text", &field);
2453 form.fields.push_back(field);
2454 field_types.push_back(CREDIT_CARD_EXP_2_DIGIT_YEAR);
2455 test::CreateTestFormField("Credit card", "card", "", "text", &field);
2456 form.fields.push_back(field);
2457 field_types.push_back(CREDIT_CARD_NUMBER);
2459 // Simulate having seen this form on page load.
2460 // |form_structure| will be owned by |autofill_manager_|.
2461 autofill_manager_->AddSeenForm(form, field_types, field_types);
2462 personal_data_->RecreateCreditCards(
2463 false /* include_local_credit_card */,
2464 false /* include_masked_server_credit_card */,
2465 false /* include_full_server_credit_card */);
2468 // Simulate activating the autofill popup for the credit card field.
2469 base::HistogramTester histogram_tester;
2470 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2471 histogram_tester.ExpectUniqueSample(
2472 "Autofill.FormEvents.CreditCard.WithNoData",
2473 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
2476 // Reset the autofill manager state.
2477 autofill_manager_->Reset();
2478 autofill_manager_->AddSeenForm(form, field_types, field_types);
2479 personal_data_->RecreateCreditCards(
2480 true /* include_local_credit_card */,
2481 false /* include_masked_server_credit_card */,
2482 false /* include_full_server_credit_card */);
2485 // Simulate activating the autofill popup for the credit card field.
2486 base::HistogramTester histogram_tester;
2487 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2488 histogram_tester.ExpectUniqueSample(
2489 "Autofill.FormEvents.CreditCard.WithOnlyLocalData",
2490 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
2493 // Reset the autofill manager state.
2494 autofill_manager_->Reset();
2495 autofill_manager_->AddSeenForm(form, field_types, field_types);
2496 personal_data_->RecreateCreditCards(
2497 false /* include_local_credit_card */,
2498 true /* include_masked_server_credit_card */,
2499 false /* include_full_server_credit_card */);
2502 // Simulate activating the autofill popup for the credit card field.
2503 base::HistogramTester histogram_tester;
2504 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2505 histogram_tester.ExpectUniqueSample(
2506 "Autofill.FormEvents.CreditCard.WithOnlyServerData",
2507 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
2510 // Reset the autofill manager state.
2511 autofill_manager_->Reset();
2512 autofill_manager_->AddSeenForm(form, field_types, field_types);
2513 personal_data_->RecreateCreditCards(
2514 false /* include_local_credit_card */,
2515 false /* include_masked_server_credit_card */,
2516 true /* include_full_server_credit_card */);
2519 // Simulate activating the autofill popup for the credit card field.
2520 base::HistogramTester histogram_tester;
2521 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2522 histogram_tester.ExpectUniqueSample(
2523 "Autofill.FormEvents.CreditCard.WithOnlyServerData",
2524 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
2527 // Reset the autofill manager state.
2528 autofill_manager_->Reset();
2529 autofill_manager_->AddSeenForm(form, field_types, field_types);
2530 personal_data_->RecreateCreditCards(
2531 true /* include_local_credit_card */,
2532 false /* include_masked_server_credit_card */,
2533 true /* include_full_server_credit_card */);
2536 // Simulate activating the autofill popup for the credit card field.
2537 base::HistogramTester histogram_tester;
2538 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2539 histogram_tester.ExpectUniqueSample(
2540 "Autofill.FormEvents.CreditCard.WithBothServerAndLocalData",
2541 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
2545 // Test that we log interacted form event for address only once.
2546 TEST_F(AutofillMetricsTest, AddressFormEventsAreSegmented) {
2547 EnableWalletSync();
2549 // Set up our form data.
2550 FormData form;
2551 form.name = ASCIIToUTF16("TestForm");
2552 form.origin = GURL("http://example.com/form.html");
2553 form.action = GURL("http://example.com/submit.html");
2555 FormFieldData field;
2556 std::vector<ServerFieldType> field_types;
2557 test::CreateTestFormField("State", "state", "", "text", &field);
2558 form.fields.push_back(field);
2559 field_types.push_back(ADDRESS_HOME_STATE);
2560 test::CreateTestFormField("City", "city", "", "text", &field);
2561 form.fields.push_back(field);
2562 field_types.push_back(ADDRESS_HOME_CITY);
2563 test::CreateTestFormField("Street", "street", "", "text", &field);
2564 form.fields.push_back(field);
2565 field_types.push_back(ADDRESS_HOME_STREET_ADDRESS);
2567 // Simulate having seen this form on page load.
2568 // |form_structure| will be owned by |autofill_manager_|.
2569 autofill_manager_->AddSeenForm(form, field_types, field_types);
2570 personal_data_->RecreateProfiles(false /* include_local_profile */,
2571 false /* include_server_profile */);
2574 // Simulate activating the autofill popup for the street field.
2575 base::HistogramTester histogram_tester;
2576 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2577 histogram_tester.ExpectUniqueSample(
2578 "Autofill.FormEvents.Address.WithNoData",
2579 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
2582 // Reset the autofill manager state.
2583 autofill_manager_->Reset();
2584 autofill_manager_->AddSeenForm(form, field_types, field_types);
2585 personal_data_->RecreateProfiles(true /* include_local_profile */,
2586 false /* include_server_profile */);
2589 // Simulate activating the autofill popup for the street field.
2590 base::HistogramTester histogram_tester;
2591 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2592 histogram_tester.ExpectUniqueSample(
2593 "Autofill.FormEvents.Address.WithOnlyLocalData",
2594 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
2597 // Reset the autofill manager state.
2598 autofill_manager_->Reset();
2599 autofill_manager_->AddSeenForm(form, field_types, field_types);
2600 personal_data_->RecreateProfiles(false /* include_local_profile */,
2601 true /* include_server_profile */);
2604 // Simulate activating the autofill popup for the street field.
2605 base::HistogramTester histogram_tester;
2606 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2607 histogram_tester.ExpectUniqueSample(
2608 "Autofill.FormEvents.Address.WithOnlyServerData",
2609 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
2612 // Reset the autofill manager state.
2613 autofill_manager_->Reset();
2614 autofill_manager_->AddSeenForm(form, field_types, field_types);
2615 personal_data_->RecreateProfiles(true /* include_local_profile */,
2616 true /* include_server_profile */);
2619 // Simulate activating the autofill popup for the street field.
2620 base::HistogramTester histogram_tester;
2621 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::RectF());
2622 histogram_tester.ExpectUniqueSample(
2623 "Autofill.FormEvents.Address.WithBothServerAndLocalData",
2624 AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, 1);
2629 // Test that we log that Autofill is enabled when filling a form.
2630 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) {
2631 base::HistogramTester histogram_tester;
2632 autofill_manager_->set_autofill_enabled(true);
2633 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks());
2634 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", true, 1);
2637 // Test that we log that Autofill is disabled when filling a form.
2638 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtPageLoad) {
2639 base::HistogramTester histogram_tester;
2640 autofill_manager_->set_autofill_enabled(false);
2641 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks());
2642 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", false, 1);
2645 // Verify that we correctly log user happiness metrics dealing with form loading
2646 // and form submission.
2647 TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
2648 // Start with a form with insufficiently many fields.
2649 FormData form;
2650 form.name = ASCIIToUTF16("TestForm");
2651 form.origin = GURL("http://example.com/form.html");
2652 form.action = GURL("http://example.com/submit.html");
2654 FormFieldData field;
2655 test::CreateTestFormField("Name", "name", "", "text", &field);
2656 form.fields.push_back(field);
2657 test::CreateTestFormField("Email", "email", "", "text", &field);
2658 form.fields.push_back(field);
2660 std::vector<FormData> forms(1, form);
2662 // Expect no notifications when the form is first seen.
2664 base::HistogramTester histogram_tester;
2665 autofill_manager_->OnFormsSeen(forms, TimeTicks());
2666 histogram_tester.ExpectTotalCount("Autofill.UserHappiness", 0);
2670 // Expect no notifications when the form is submitted.
2672 base::HistogramTester histogram_tester;
2673 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2674 histogram_tester.ExpectTotalCount("Autofill.UserHappiness", 0);
2677 // Add more fields to the form.
2678 test::CreateTestFormField("Phone", "phone", "", "text", &field);
2679 form.fields.push_back(field);
2680 test::CreateTestFormField("Unknown", "unknown", "", "text", &field);
2681 form.fields.push_back(field);
2682 forms.front() = form;
2684 // Expect a notification when the form is first seen.
2686 base::HistogramTester histogram_tester;
2687 autofill_manager_->OnFormsSeen(forms, TimeTicks());
2688 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness",
2689 AutofillMetrics::FORMS_LOADED, 1);
2692 // Expect a notification when the form is submitted.
2694 base::HistogramTester histogram_tester;
2695 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2696 histogram_tester.ExpectUniqueSample(
2697 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM,
2701 // Fill in two of the fields.
2702 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
2703 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
2704 forms.front() = form;
2706 // Expect a notification when the form is submitted.
2708 base::HistogramTester histogram_tester;
2709 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2710 histogram_tester.ExpectUniqueSample(
2711 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM,
2715 // Fill in the third field.
2716 form.fields[2].value = ASCIIToUTF16("12345678901");
2717 forms.front() = form;
2719 // Expect notifications when the form is submitted.
2721 base::HistogramTester histogram_tester;
2722 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2723 histogram_tester.ExpectUniqueSample(
2724 "Autofill.UserHappiness",
2725 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE, 1);
2729 // Mark one of the fields as autofilled.
2730 form.fields[1].is_autofilled = true;
2731 forms.front() = form;
2733 // Expect notifications when the form is submitted.
2735 base::HistogramTester histogram_tester;
2736 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2737 histogram_tester.ExpectUniqueSample(
2738 "Autofill.UserHappiness",
2739 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME, 1);
2742 // Mark all of the fillable fields as autofilled.
2743 form.fields[0].is_autofilled = true;
2744 form.fields[2].is_autofilled = true;
2745 forms.front() = form;
2747 // Expect notifications when the form is submitted.
2749 base::HistogramTester histogram_tester;
2750 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2751 histogram_tester.ExpectUniqueSample(
2752 "Autofill.UserHappiness",
2753 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL, 1);
2756 // Clear out the third field's value.
2757 form.fields[2].value = base::string16();
2758 forms.front() = form;
2760 // Expect notifications when the form is submitted.
2762 base::HistogramTester histogram_tester;
2763 autofill_manager_->SubmitForm(form, TimeTicks::Now());
2764 histogram_tester.ExpectUniqueSample(
2765 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM,
2770 // Verify that we correctly log user happiness metrics dealing with form
2771 // interaction.
2772 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
2773 // Load a fillable form.
2774 FormData form;
2775 form.name = ASCIIToUTF16("TestForm");
2776 form.origin = GURL("http://example.com/form.html");
2777 form.action = GURL("http://example.com/submit.html");
2779 FormFieldData field;
2780 test::CreateTestFormField("Name", "name", "", "text", &field);
2781 form.fields.push_back(field);
2782 test::CreateTestFormField("Email", "email", "", "text", &field);
2783 form.fields.push_back(field);
2784 test::CreateTestFormField("Phone", "phone", "", "text", &field);
2785 form.fields.push_back(field);
2787 std::vector<FormData> forms(1, form);
2789 // Expect a notification when the form is first seen.
2791 base::HistogramTester histogram_tester;
2792 autofill_manager_->OnFormsSeen(forms, TimeTicks());
2793 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness",
2794 AutofillMetrics::FORMS_LOADED, 1);
2797 // Simulate typing.
2799 base::HistogramTester histogram_tester;
2800 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
2801 TimeTicks());
2802 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness",
2803 AutofillMetrics::USER_DID_TYPE, 1);
2806 // Simulate suggestions shown twice for a single edit (i.e. multiple
2807 // keystrokes in a single field).
2809 base::HistogramTester histogram_tester;
2810 autofill_manager_->DidShowSuggestions(true, form, field);
2811 autofill_manager_->DidShowSuggestions(false, form, field);
2812 histogram_tester.ExpectBucketCount("Autofill.UserHappiness",
2813 AutofillMetrics::SUGGESTIONS_SHOWN, 1);
2814 histogram_tester.ExpectBucketCount(
2815 "Autofill.UserHappiness", AutofillMetrics::SUGGESTIONS_SHOWN_ONCE, 1);
2818 // Simulate suggestions shown for a different field.
2820 base::HistogramTester histogram_tester;
2821 autofill_manager_->DidShowSuggestions(true, form, form.fields[1]);
2822 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness",
2823 AutofillMetrics::SUGGESTIONS_SHOWN, 1);
2826 // Simulate invoking autofill.
2828 base::HistogramTester histogram_tester;
2829 autofill_manager_->OnDidFillAutofillFormData(TimeTicks());
2830 histogram_tester.ExpectBucketCount("Autofill.UserHappiness",
2831 AutofillMetrics::USER_DID_AUTOFILL, 1);
2832 histogram_tester.ExpectBucketCount(
2833 "Autofill.UserHappiness", AutofillMetrics::USER_DID_AUTOFILL_ONCE, 1);
2836 // Simulate editing an autofilled field.
2838 base::HistogramTester histogram_tester;
2839 std::string guid("00000000-0000-0000-0000-000000000001");
2840 autofill_manager_->FillOrPreviewForm(
2841 AutofillDriver::FORM_DATA_ACTION_FILL, 0, form, form.fields.front(),
2842 autofill_manager_->MakeFrontendID(std::string(), guid));
2843 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
2844 TimeTicks());
2845 // Simulate a second keystroke; make sure we don't log the metric twice.
2846 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
2847 TimeTicks());
2848 histogram_tester.ExpectBucketCount(
2849 "Autofill.UserHappiness",
2850 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1);
2851 histogram_tester.ExpectBucketCount(
2852 "Autofill.UserHappiness",
2853 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE, 1);
2856 // Simulate invoking autofill again.
2858 base::HistogramTester histogram_tester;
2859 autofill_manager_->OnDidFillAutofillFormData(TimeTicks());
2860 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness",
2861 AutofillMetrics::USER_DID_AUTOFILL, 1);
2864 // Simulate editing another autofilled field.
2866 base::HistogramTester histogram_tester;
2867 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks());
2868 histogram_tester.ExpectUniqueSample(
2869 "Autofill.UserHappiness",
2870 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1);
2874 // Verify that we correctly log metrics tracking the duration of form fill.
2875 TEST_F(AutofillMetricsTest, FormFillDuration) {
2876 // Load a fillable form.
2877 FormData form;
2878 form.name = ASCIIToUTF16("TestForm");
2879 form.origin = GURL("http://example.com/form.html");
2880 form.action = GURL("http://example.com/submit.html");
2882 FormFieldData field;
2883 test::CreateTestFormField("Name", "name", "", "text", &field);
2884 form.fields.push_back(field);
2885 test::CreateTestFormField("Email", "email", "", "text", &field);
2886 form.fields.push_back(field);
2887 test::CreateTestFormField("Phone", "phone", "", "text", &field);
2888 form.fields.push_back(field);
2890 std::vector<FormData> forms(1, form);
2892 // Fill additional form.
2893 FormData second_form = form;
2894 test::CreateTestFormField("Second Phone", "second_phone", "", "text", &field);
2895 second_form.fields.push_back(field);
2897 std::vector<FormData> second_forms(1, second_form);
2899 // Fill the field values for form submission.
2900 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
2901 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
2902 form.fields[2].value = ASCIIToUTF16("12345678901");
2904 // Fill the field values for form submission.
2905 second_form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
2906 second_form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
2907 second_form.fields[2].value = ASCIIToUTF16("12345678901");
2908 second_form.fields[3].value = ASCIIToUTF16("51512345678");
2910 // Expect only form load metrics to be logged if the form is submitted without
2911 // user interaction.
2913 base::HistogramTester histogram_tester;
2914 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
2915 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17));
2917 histogram_tester.ExpectTotalCount(
2918 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
2919 histogram_tester.ExpectUniqueSample(
2920 "Autofill.FillDuration.FromLoad.WithoutAutofill", 16, 1);
2921 histogram_tester.ExpectTotalCount(
2922 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
2923 histogram_tester.ExpectTotalCount(
2924 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
2926 autofill_manager_->Reset();
2929 // Expect metric to be logged if the user manually edited a form field.
2931 base::HistogramTester histogram_tester;
2932 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
2933 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
2934 TimeTicks::FromInternalValue(3));
2935 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17));
2937 histogram_tester.ExpectTotalCount(
2938 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
2939 histogram_tester.ExpectUniqueSample(
2940 "Autofill.FillDuration.FromLoad.WithoutAutofill", 16, 1);
2941 histogram_tester.ExpectTotalCount(
2942 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
2943 histogram_tester.ExpectUniqueSample(
2944 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 14, 1);
2946 autofill_manager_->Reset();
2949 // Expect metric to be logged if the user autofilled the form.
2950 form.fields[0].is_autofilled = true;
2952 base::HistogramTester histogram_tester;
2953 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
2954 autofill_manager_->OnDidFillAutofillFormData(
2955 TimeTicks::FromInternalValue(5));
2956 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17));
2958 histogram_tester.ExpectUniqueSample(
2959 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
2960 histogram_tester.ExpectTotalCount(
2961 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
2962 histogram_tester.ExpectUniqueSample(
2963 "Autofill.FillDuration.FromInteraction.WithAutofill", 12, 1);
2964 histogram_tester.ExpectTotalCount(
2965 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
2967 autofill_manager_->Reset();
2970 // Expect metric to be logged if the user both manually filled some fields
2971 // and autofilled others. Messages can arrive out of order, so make sure they
2972 // take precedence appropriately.
2974 base::HistogramTester histogram_tester;
2976 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
2977 autofill_manager_->OnDidFillAutofillFormData(
2978 TimeTicks::FromInternalValue(5));
2979 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
2980 TimeTicks::FromInternalValue(3));
2981 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17));
2983 histogram_tester.ExpectUniqueSample(
2984 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
2985 histogram_tester.ExpectTotalCount(
2986 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
2987 histogram_tester.ExpectUniqueSample(
2988 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1);
2989 histogram_tester.ExpectTotalCount(
2990 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
2992 autofill_manager_->Reset();
2995 // Make sure that loading another form doesn't affect metrics from the first
2996 // form.
2998 base::HistogramTester histogram_tester;
2999 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
3000 autofill_manager_->OnFormsSeen(second_forms,
3001 TimeTicks::FromInternalValue(3));
3002 autofill_manager_->OnDidFillAutofillFormData(
3003 TimeTicks::FromInternalValue(5));
3004 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
3005 TimeTicks::FromInternalValue(3));
3006 autofill_manager_->SubmitForm(form, TimeTicks::FromInternalValue(17));
3008 histogram_tester.ExpectUniqueSample(
3009 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
3010 histogram_tester.ExpectTotalCount(
3011 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
3012 histogram_tester.ExpectUniqueSample(
3013 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1);
3014 histogram_tester.ExpectTotalCount(
3015 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
3017 autofill_manager_->Reset();
3020 // Make sure that submitting a form that was loaded later will report the
3021 // later loading time.
3023 base::HistogramTester histogram_tester;
3024 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
3025 autofill_manager_->OnFormsSeen(second_forms,
3026 TimeTicks::FromInternalValue(5));
3027 autofill_manager_->SubmitForm(second_form,
3028 TimeTicks::FromInternalValue(17));
3030 histogram_tester.ExpectTotalCount(
3031 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
3032 histogram_tester.ExpectUniqueSample(
3033 "Autofill.FillDuration.FromLoad.WithoutAutofill", 12, 1);
3034 histogram_tester.ExpectTotalCount(
3035 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
3036 histogram_tester.ExpectTotalCount(
3037 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
3039 autofill_manager_->Reset();
3043 // Test class that shares setup code for testing ParseQueryResponse.
3044 class AutofillMetricsParseQueryResponseTest : public testing::Test {
3045 public:
3046 void SetUp() override {
3047 FormData form;
3048 form.origin = GURL("http://foo.com");
3049 FormFieldData field;
3050 field.form_control_type = "text";
3052 field.label = ASCIIToUTF16("fullname");
3053 field.name = ASCIIToUTF16("fullname");
3054 form.fields.push_back(field);
3056 field.label = ASCIIToUTF16("address");
3057 field.name = ASCIIToUTF16("address");
3058 form.fields.push_back(field);
3060 // Checkable fields should be ignored in parsing
3061 FormFieldData checkable_field;
3062 checkable_field.label = ASCIIToUTF16("radio_button");
3063 checkable_field.form_control_type = "radio";
3064 checkable_field.is_checkable = true;
3065 form.fields.push_back(checkable_field);
3067 forms_.push_back(new FormStructure(form));
3069 field.label = ASCIIToUTF16("email");
3070 field.name = ASCIIToUTF16("email");
3071 form.fields.push_back(field);
3073 field.label = ASCIIToUTF16("password");
3074 field.name = ASCIIToUTF16("password");
3075 field.form_control_type = "password";
3076 form.fields.push_back(field);
3078 forms_.push_back(new FormStructure(form));
3081 protected:
3082 TestRapporService rappor_service_;
3083 ScopedVector<FormStructure> forms_;
3086 TEST_F(AutofillMetricsParseQueryResponseTest, ServerHasData) {
3087 std::string response =
3088 "<autofillqueryresponse>"
3089 "<field autofilltype=\"7\" />"
3090 "<field autofilltype=\"30\" />"
3091 "<field autofilltype=\"9\" />"
3092 "<field autofilltype=\"0\" />"
3093 "</autofillqueryresponse>";
3095 base::HistogramTester histogram_tester;
3096 FormStructure::ParseQueryResponse(response, forms_.get(), &rappor_service_);
3097 EXPECT_THAT(
3098 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"),
3099 ElementsAre(Bucket(true, 2)));
3101 // No RAPPOR metrics are logged in the case there is server data available for
3102 // all forms.
3103 EXPECT_EQ(0, rappor_service_.GetReportsCount());
3106 // If the server returns NO_SERVER_DATA for one of the forms, expect RAPPOR
3107 // logging.
3108 TEST_F(AutofillMetricsParseQueryResponseTest, OneFormNoServerData) {
3109 std::string response =
3110 "<autofillqueryresponse>"
3111 "<field autofilltype=\"0\" />"
3112 "<field autofilltype=\"0\" />"
3113 "<field autofilltype=\"9\" />"
3114 "<field autofilltype=\"0\" />"
3115 "</autofillqueryresponse>";
3117 base::HistogramTester histogram_tester;
3118 FormStructure::ParseQueryResponse(response, forms_.get(), &rappor_service_);
3119 EXPECT_THAT(
3120 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"),
3121 ElementsAre(Bucket(false, 1), Bucket(true, 1)));
3123 EXPECT_EQ(1, rappor_service_.GetReportsCount());
3124 std::string sample;
3125 rappor::RapporType type;
3126 EXPECT_TRUE(rappor_service_.GetRecordedSampleForMetric(
3127 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type));
3128 EXPECT_EQ("foo.com", sample);
3129 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
3132 // If the server returns NO_SERVER_DATA for both of the forms, expect RAPPOR
3133 // logging.
3134 TEST_F(AutofillMetricsParseQueryResponseTest, AllFormsNoServerData) {
3135 std::string response =
3136 "<autofillqueryresponse>"
3137 "<field autofilltype=\"0\" />"
3138 "<field autofilltype=\"0\" />"
3139 "<field autofilltype=\"0\" />"
3140 "<field autofilltype=\"0\" />"
3141 "</autofillqueryresponse>";
3143 base::HistogramTester histogram_tester;
3144 FormStructure::ParseQueryResponse(response, forms_.get(), &rappor_service_);
3145 EXPECT_THAT(
3146 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"),
3147 ElementsAre(Bucket(false, 2)));
3149 // Even though both forms are logging to RAPPOR, there is only one sample for
3150 // a given eTLD+1.
3151 EXPECT_EQ(1, rappor_service_.GetReportsCount());
3152 std::string sample;
3153 rappor::RapporType type;
3154 EXPECT_TRUE(rappor_service_.GetRecordedSampleForMetric(
3155 "Autofill.QueryResponseHasNoServerDataForForm", &sample, &type));
3156 EXPECT_EQ("foo.com", sample);
3157 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
3160 // If the server returns NO_SERVER_DATA for only some of the fields, expect no
3161 // RAPPOR logging, and expect the UMA metric to say there is data.
3162 TEST_F(AutofillMetricsParseQueryResponseTest, PartialNoServerData) {
3163 std::string response =
3164 "<autofillqueryresponse>"
3165 "<field autofilltype=\"0\" />"
3166 "<field autofilltype=\"10\" />"
3167 "<field autofilltype=\"0\" />"
3168 "<field autofilltype=\"11\" />"
3169 "</autofillqueryresponse>";
3171 base::HistogramTester histogram_tester;
3172 FormStructure::ParseQueryResponse(response, forms_.get(), &rappor_service_);
3173 EXPECT_THAT(
3174 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"),
3175 ElementsAre(Bucket(true, 2)));
3177 // No RAPPOR metrics are logged in the case there is at least some server data
3178 // available for all forms.
3179 EXPECT_EQ(0, rappor_service_.GetReportsCount());
3182 } // namespace autofill