1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autofill/autofill_common_test.h"
#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/autofill/autofill_metrics.h"
#include "chrome/browser/autofill/personal_data_manager.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "content/browser/renderer_host/test_render_view_host.h"
#include "content/browser/tab_contents/test_tab_contents.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/glue/form_data.h"
#include "webkit/glue/form_field.h"
using webkit_glue::FormData;
using webkit_glue::FormField;
namespace {
class MockAutofillMetrics : public AutofillMetrics {
public:
MockAutofillMetrics() {}
MOCK_CONST_METHOD1(Log, void(ServerQueryMetric metric));
MOCK_CONST_METHOD2(Log, void(QualityMetric metric,
const std::string& experiment_id));
MOCK_CONST_METHOD1(LogProfileCount, void(size_t num_profiles));
private:
DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics);
};
// TODO(isherman): Move this into autofill_common_test.h?
class TestPersonalDataManager : public PersonalDataManager {
public:
TestPersonalDataManager() {
set_metric_logger(new MockAutofillMetrics);
CreateTestAutoFillProfiles(&web_profiles_);
CreateTestCreditCards(&credit_cards_);
}
virtual void InitializeIfNeeded() {}
virtual void SaveImportedFormData() {}
virtual bool IsDataLoaded() const { return true; }
// Overridden to avoid a trip to the database. This should be a no-op except
// for the side-effect of logging the profile count.
virtual void LoadProfiles() {
std::vector<AutoFillProfile*> profiles;
web_profiles_.release(&profiles);
WDResult<std::vector<AutoFillProfile*> > result(AUTOFILL_PROFILES_RESULT,
profiles);
ReceiveLoadedProfiles(0, &result);
}
// Adds |profile| to |web_profiles_| and takes ownership of the profile's
// memory.
virtual void AddProfile(AutoFillProfile* profile) {
web_profiles_.push_back(profile);
}
const MockAutofillMetrics* metric_logger() const {
return static_cast<const MockAutofillMetrics*>(
PersonalDataManager::metric_logger());
}
static void ResetHasLoggedProfileCount() {
PersonalDataManager::set_has_logged_profile_count(false);
}
private:
void CreateTestAutoFillProfiles(ScopedVector<AutoFillProfile>* profiles) {
AutoFillProfile* profile = new AutoFillProfile;
autofill_test::SetProfileInfo(profile, "Elvis", "Aaron",
"Presley", "theking@gmail.com", "RCA",
"3734 Elvis Presley Blvd.", "Apt. 10",
"Memphis", "Tennessee", "38116", "USA",
"12345678901", "");
profile->set_guid("00000000-0000-0000-0000-000000000001");
profiles->push_back(profile);
profile = new AutoFillProfile;
autofill_test::SetProfileInfo(profile, "Charles", "Hardin",
"Holley", "buddy@gmail.com", "Decca",
"123 Apple St.", "unit 6", "Lubbock",
"Texas", "79401", "USA", "23456789012",
"");
profile->set_guid("00000000-0000-0000-0000-000000000002");
profiles->push_back(profile);
profile = new AutoFillProfile;
autofill_test::SetProfileInfo(profile, "", "", "", "", "", "", "",
"", "", "", "", "", "");
profile->set_guid("00000000-0000-0000-0000-000000000003");
profiles->push_back(profile);
}
void CreateTestCreditCards(ScopedVector<CreditCard>* credit_cards) {
CreditCard* credit_card = new CreditCard;
autofill_test::SetCreditCardInfo(credit_card, "Elvis Presley",
"4234567890123456", // Visa
"04", "2012");
credit_card->set_guid("00000000-0000-0000-0000-000000000004");
credit_cards->push_back(credit_card);
credit_card = new CreditCard;
autofill_test::SetCreditCardInfo(credit_card, "Buddy Holly",
"5187654321098765", // Mastercard
"10", "2014");
credit_card->set_guid("00000000-0000-0000-0000-000000000005");
credit_cards->push_back(credit_card);
credit_card = new CreditCard;
autofill_test::SetCreditCardInfo(credit_card, "", "", "", "");
credit_card->set_guid("00000000-0000-0000-0000-000000000006");
credit_cards->push_back(credit_card);
}
DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
};
class TestAutofillManager : public AutofillManager {
public:
TestAutofillManager(TabContents* tab_contents,
TestPersonalDataManager* personal_manager)
: AutofillManager(tab_contents, personal_manager),
autofill_enabled_(true) {
set_metric_logger(new MockAutofillMetrics);
}
virtual ~TestAutofillManager() {}
virtual bool IsAutoFillEnabled() const { return autofill_enabled_; }
void set_autofill_enabled(bool autofill_enabled) {
autofill_enabled_ = autofill_enabled;
}
const MockAutofillMetrics* metric_logger() const {
return static_cast<const MockAutofillMetrics*>(
AutofillManager::metric_logger());
}
void AddSeenForm(FormStructure* form) {
form_structures()->push_back(form);
}
private:
bool autofill_enabled_;
DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
};
class TestFormStructure : public FormStructure {
public:
explicit TestFormStructure(const FormData& form) : FormStructure(form) {}
virtual ~TestFormStructure() {}
void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types,
const std::vector<AutofillFieldType>& server_types) {
ASSERT_EQ(field_count(), heuristic_types.size());
ASSERT_EQ(field_count(), server_types.size());
for (size_t i = 0; i < field_count(); ++i) {
AutofillField* field = (*fields())[i];
ASSERT_TRUE(field);
field->set_heuristic_type(heuristic_types[i]);
field->set_server_type(server_types[i]);
}
UpdateAutoFillCount();
}
virtual std::string server_experiment_id() const OVERRIDE {
return server_experiment_id_;
}
void set_server_experiment_id(const std::string& server_experiment_id) {
server_experiment_id_ = server_experiment_id;
}
private:
std::string server_experiment_id_;
DISALLOW_COPY_AND_ASSIGN(TestFormStructure);
};
} // namespace
class AutofillMetricsTest : public RenderViewHostTestHarness {
public:
AutofillMetricsTest() {}
virtual ~AutofillMetricsTest() {
// Order of destruction is important as AutofillManager relies on
// PersonalDataManager to be around when it gets destroyed.
autofill_manager_.reset(NULL);
test_personal_data_ = NULL;
}
virtual void SetUp() {
RenderViewHostTestHarness::SetUp();
test_personal_data_ = new TestPersonalDataManager();
autofill_manager_.reset(new TestAutofillManager(contents(),
test_personal_data_.get()));
}
protected:
scoped_ptr<TestAutofillManager> autofill_manager_;
scoped_refptr<TestPersonalDataManager> test_personal_data_;
private:
DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest);
};
// Test that we log quality metrics appropriately.
TEST_F(AutofillMetricsTest, QualityMetrics) {
// Set up our form data.
FormData form;
form.name = ASCIIToUTF16("TestForm");
form.method = ASCIIToUTF16("POST");
form.origin = GURL("http://example.com/form.html");
form.action = GURL("http://example.com/submit.html");
form.user_submitted = true;
FormField field;
autofill_test::CreateTestFormField(
"Autofilled", "autofilled", "Elvis Presley", "text", &field);
field.is_autofilled = true;
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field);
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"Empty", "empty", "", "text", &field);
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"Unknown", "unknown", "garbage", "text", &field);
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"Select", "select", "USA", "select-one", &field);
form.fields.push_back(field);
// Simulate having seen this form on page load.
// |form_structure| will be owned by |autofill_manager_|.
TestFormStructure* form_structure = new TestFormStructure(form);
autofill_manager_->AddSeenForm(form_structure);
// Establish our expectations.
::testing::InSequence dummy;
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_AUTOFILLED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_AUTOFILL_FAILED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN,
std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SERVER_TYPE_UNKNOWN, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string()));
// Simulate form submission.
EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
}
// Test that we log the appropriate additional metrics when AutoFill failed.
TEST_F(AutofillMetricsTest, QualityMetricsForFailure) {
// Set up our form data.
FormData form;
form.name = ASCIIToUTF16("TestForm");
form.method = ASCIIToUTF16("POST");
form.origin = GURL("http://example.com/form.html");
form.action = GURL("http://example.com/submit.html");
form.user_submitted = true;
struct {
const char* label;
const char* name;
const char* value;
AutofillFieldType heuristic_type;
AutofillFieldType server_type;
AutofillMetrics::QualityMetric heuristic_metric;
AutofillMetrics::QualityMetric server_metric;
} failure_cases[] = {
{
"Heuristics unknown, server unknown", "0,0", "Elvis",
UNKNOWN_TYPE, NO_SERVER_DATA,
AutofillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN,
AutofillMetrics::FIELD_SERVER_TYPE_UNKNOWN
},
{
"Heuristics match, server unknown", "1,0", "Aaron",
NAME_MIDDLE, NO_SERVER_DATA,
AutofillMetrics::FIELD_HEURISTIC_TYPE_MATCH,
AutofillMetrics::FIELD_SERVER_TYPE_UNKNOWN
},
{
"Heuristics mismatch, server unknown", "2,0", "Presley",
PHONE_HOME_NUMBER, NO_SERVER_DATA,
AutofillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH,
AutofillMetrics::FIELD_SERVER_TYPE_UNKNOWN
},
{
"Heuristics unknown, server match", "0,1", "theking@gmail.com",
UNKNOWN_TYPE, EMAIL_ADDRESS,
AutofillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN,
AutofillMetrics::FIELD_SERVER_TYPE_MATCH
},
{
"Heuristics match, server match", "1,1", "3734 Elvis Presley Blvd.",
ADDRESS_HOME_LINE1, ADDRESS_HOME_LINE1,
AutofillMetrics::FIELD_HEURISTIC_TYPE_MATCH,
AutofillMetrics::FIELD_SERVER_TYPE_MATCH
},
{
"Heuristics mismatch, server match", "2,1", "Apt. 10",
PHONE_HOME_NUMBER, ADDRESS_HOME_LINE2,
AutofillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH,
AutofillMetrics::FIELD_SERVER_TYPE_MATCH
},
{
"Heuristics unknown, server mismatch", "0,2", "Memphis",
UNKNOWN_TYPE, PHONE_HOME_NUMBER,
AutofillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN,
AutofillMetrics::FIELD_SERVER_TYPE_MISMATCH
},
{
"Heuristics match, server mismatch", "1,2", "Tennessee",
ADDRESS_HOME_STATE, PHONE_HOME_NUMBER,
AutofillMetrics::FIELD_HEURISTIC_TYPE_MATCH,
AutofillMetrics::FIELD_SERVER_TYPE_MISMATCH
},
{
"Heuristics mismatch, server mismatch", "2,2", "38116",
PHONE_HOME_NUMBER, PHONE_HOME_NUMBER,
AutofillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH,
AutofillMetrics::FIELD_SERVER_TYPE_MISMATCH
}
};
std::vector<AutofillFieldType> heuristic_types, server_types;
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(failure_cases); ++i) {
FormField field;
autofill_test::CreateTestFormField(failure_cases[i].label,
failure_cases[i].name,
failure_cases[i].value, "text", &field);
form.fields.push_back(field);
heuristic_types.push_back(failure_cases[i].heuristic_type);
server_types.push_back(failure_cases[i].server_type);
}
// Simulate having seen this form with the desired heuristic and server types.
// |form_structure| will be owned by |autofill_manager_|.
TestFormStructure* form_structure = new TestFormStructure(form);
form_structure->SetFieldTypes(heuristic_types, server_types);
autofill_manager_->AddSeenForm(form_structure);
// Establish our expectations.
::testing::InSequence dummy;
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(failure_cases); ++i) {
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_AUTOFILL_FAILED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(failure_cases[i].heuristic_metric, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(failure_cases[i].server_metric, std::string()));
}
// Simulate form submission.
EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
}
// Test that we behave sanely when the cached form differs from the submitted
// one.
TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) {
// Set up our form data.
FormData form;
form.name = ASCIIToUTF16("TestForm");
form.method = ASCIIToUTF16("POST");
form.origin = GURL("http://example.com/form.html");
form.action = GURL("http://example.com/submit.html");
form.user_submitted = true;
std::vector<AutofillFieldType> heuristic_types, server_types;
FormField field;
autofill_test::CreateTestFormField(
"Both match", "match", "Elvis Presley", "text", &field);
field.is_autofilled = true;
form.fields.push_back(field);
heuristic_types.push_back(NAME_FULL);
server_types.push_back(NAME_FULL);
autofill_test::CreateTestFormField(
"Both mismatch", "mismatch", "buddy@gmail.com", "text", &field);
form.fields.push_back(field);
heuristic_types.push_back(PHONE_HOME_NUMBER);
server_types.push_back(PHONE_HOME_NUMBER);
autofill_test::CreateTestFormField(
"Only heuristics match", "mixed", "Memphis", "text", &field);
form.fields.push_back(field);
heuristic_types.push_back(ADDRESS_HOME_CITY);
server_types.push_back(PHONE_HOME_NUMBER);
autofill_test::CreateTestFormField(
"Unknown", "unknown", "garbage", "text", &field);
form.fields.push_back(field);
heuristic_types.push_back(UNKNOWN_TYPE);
server_types.push_back(UNKNOWN_TYPE);
// Simulate having seen this form with the desired heuristic and server types.
// |form_structure| will be owned by |autofill_manager_|.
TestFormStructure* form_structure = new TestFormStructure(form);
form_structure->SetFieldTypes(heuristic_types, server_types);
autofill_manager_->AddSeenForm(form_structure);
// Add a field and re-arrange the remaining form fields before submitting.
std::vector<FormField> cached_fields = form.fields;
form.fields.clear();
autofill_test::CreateTestFormField(
"New field", "new field", "Tennessee", "text", &field);
form.fields.push_back(field);
form.fields.push_back(cached_fields[2]);
form.fields.push_back(cached_fields[1]);
form.fields.push_back(cached_fields[3]);
form.fields.push_back(cached_fields[0]);
// Establish our expectations.
::testing::InSequence dummy;
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_AUTOFILL_FAILED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN,
std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SERVER_TYPE_UNKNOWN, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_AUTOFILL_FAILED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_HEURISTIC_TYPE_MATCH, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SERVER_TYPE_MISMATCH, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_AUTOFILL_FAILED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH,
std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SERVER_TYPE_MISMATCH, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string()));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_AUTOFILLED, std::string()));
// Simulate form submission.
EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
}
// Test that we don't log quality metrics for non-autofillable forms.
TEST_F(AutofillMetricsTest, NoQualityMetricsForNonAutofillableForms) {
// Forms must include at least three fields to be auto-fillable.
FormData form;
form.name = ASCIIToUTF16("TestForm");
form.method = ASCIIToUTF16("POST");
form.origin = GURL("http://example.com/form.html");
form.action = GURL("http://example.com/submit.html");
form.user_submitted = true;
FormField field;
autofill_test::CreateTestFormField(
"Autofilled", "autofilled", "Elvis Presley", "text", &field);
field.is_autofilled = true;
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field);
form.fields.push_back(field);
// Simulate form submission.
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string())).Times(0);
EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
// Search forms are not auto-fillable.
form.action = GURL("http://example.com/search?q=Elvis%20Presley");
autofill_test::CreateTestFormField(
"Empty", "empty", "", "text", &field);
form.fields.push_back(field);
// Simulate form submission.
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, std::string())).Times(0);
EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
}
// Test that we recored the experiment id appropriately.
TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) {
// Set up our form data.
FormData form;
form.name = ASCIIToUTF16("TestForm");
form.method = ASCIIToUTF16("POST");
form.origin = GURL("http://example.com/form.html");
form.action = GURL("http://example.com/submit.html");
form.user_submitted = true;
FormField field;
autofill_test::CreateTestFormField(
"Autofilled", "autofilled", "Elvis Presley", "text", &field);
field.is_autofilled = true;
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field);
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"Empty", "empty", "", "text", &field);
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"Unknown", "unknown", "garbage", "text", &field);
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"Select", "select", "USA", "select-one", &field);
form.fields.push_back(field);
const std::string experiment_id = "ThatOughtaDoIt";
// Simulate having seen this form on page load.
// |form_structure| will be owned by |autofill_manager_|.
TestFormStructure* form_structure = new TestFormStructure(form);
form_structure->set_server_experiment_id(experiment_id);
autofill_manager_->AddSeenForm(form_structure);
// Establish our expectations.
::testing::InSequence dummy;
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, experiment_id));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_AUTOFILLED, experiment_id));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, experiment_id));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_AUTOFILL_FAILED, experiment_id));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN,
experiment_id));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SERVER_TYPE_UNKNOWN, experiment_id));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, experiment_id));
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutofillMetrics::FIELD_SUBMITTED, experiment_id));
// Simulate form submission.
EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
}
// Test that the profile count is logged correctly.
TEST_F(AutofillMetricsTest, ProfileCount) {
TestPersonalDataManager::ResetHasLoggedProfileCount();
// The metric should be logged when the profiles are first loaded.
EXPECT_CALL(*test_personal_data_->metric_logger(),
LogProfileCount(3)).Times(1);
test_personal_data_->LoadProfiles();
// The metric should only be logged once.
EXPECT_CALL(*test_personal_data_->metric_logger(),
LogProfileCount(::testing::_)).Times(0);
test_personal_data_->LoadProfiles();
}
|