Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: components/autofill/browser/autofill_metrics_unittest.cc

Issue 17392006: In components/autofill, move browser/ to core/browser/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to fix conflicts Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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.
4
5 #include <vector>
6
7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/time.h"
12 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
13 #include "chrome/browser/autofill/personal_data_manager_factory.h"
14 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "chrome/test/base/testing_profile.h"
17 #include "components/autofill/browser/autofill_common_test.h"
18 #include "components/autofill/browser/autofill_manager.h"
19 #include "components/autofill/browser/autofill_manager_delegate.h"
20 #include "components/autofill/browser/autofill_metrics.h"
21 #include "components/autofill/browser/personal_data_manager.h"
22 #include "components/autofill/browser/test_autofill_driver.h"
23 #include "components/autofill/content/browser/autocheckout_page_meta_data.h"
24 #include "components/autofill/core/common/form_data.h"
25 #include "components/autofill/core/common/form_field_data.h"
26 #include "components/autofill/core/common/forms_seen_state.h"
27 #include "components/webdata/common/web_data_results.h"
28 #include "content/public/test/test_utils.h"
29 #include "googleurl/src/gurl.h"
30 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h"
32 #include "ui/gfx/rect.h"
33
34 using base::TimeDelta;
35 using base::TimeTicks;
36 using testing::_;
37 using testing::AnyNumber;
38 using testing::Mock;
39
40 namespace autofill {
41
42 namespace {
43
44 class MockAutofillMetrics : public AutofillMetrics {
45 public:
46 MockAutofillMetrics() {}
47 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric));
48 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric,
49 void(DeveloperEngagementMetric metric));
50 MOCK_CONST_METHOD3(LogHeuristicTypePrediction,
51 void(FieldTypeQualityMetric metric,
52 AutofillFieldType field_type,
53 const std::string& experiment_id));
54 MOCK_CONST_METHOD3(LogOverallTypePrediction,
55 void(FieldTypeQualityMetric metric,
56 AutofillFieldType field_type,
57 const std::string& experiment_id));
58 MOCK_CONST_METHOD3(LogServerTypePrediction,
59 void(FieldTypeQualityMetric metric,
60 AutofillFieldType field_type,
61 const std::string& experiment_id));
62 MOCK_CONST_METHOD2(LogQualityMetric, void(QualityMetric metric,
63 const std::string& experiment_id));
64 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric));
65 MOCK_CONST_METHOD1(LogUserHappinessMetric, void(UserHappinessMetric metric));
66 MOCK_CONST_METHOD1(LogFormFillDurationFromLoadWithAutofill,
67 void(const TimeDelta& duration));
68 MOCK_CONST_METHOD1(LogFormFillDurationFromLoadWithoutAutofill,
69 void(const TimeDelta& duration));
70 MOCK_CONST_METHOD1(LogFormFillDurationFromInteractionWithAutofill,
71 void(const TimeDelta& duration));
72 MOCK_CONST_METHOD1(LogFormFillDurationFromInteractionWithoutAutofill,
73 void(const TimeDelta& duration));
74 MOCK_CONST_METHOD1(LogIsAutofillEnabledAtPageLoad, void(bool enabled));
75 MOCK_CONST_METHOD1(LogIsAutofillEnabledAtStartup, void(bool enabled));
76 MOCK_CONST_METHOD1(LogStoredProfileCount, void(size_t num_profiles));
77 MOCK_CONST_METHOD1(LogAddressSuggestionsCount, void(size_t num_suggestions));
78 MOCK_CONST_METHOD1(LogServerExperimentIdForQuery,
79 void(const std::string& experiment_id));
80 MOCK_CONST_METHOD1(LogServerExperimentIdForUpload,
81 void(const std::string& experiment_id));
82
83 private:
84 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics);
85 };
86
87 class TestPersonalDataManager : public PersonalDataManager {
88 public:
89 TestPersonalDataManager()
90 : PersonalDataManager("en-US"),
91 autofill_enabled_(true) {
92 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>());
93 CreateTestAutofillProfiles(&web_profiles_);
94 }
95
96 void SetBrowserContext(content::BrowserContext* context) {
97 set_browser_context(context);
98 }
99
100 // Overridden to avoid a trip to the database. This should be a no-op except
101 // for the side-effect of logging the profile count.
102 virtual void LoadProfiles() OVERRIDE {
103 std::vector<AutofillProfile*> profiles;
104 web_profiles_.release(&profiles);
105 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT,
106 profiles);
107 ReceiveLoadedProfiles(0, &result);
108 }
109
110 // Overridden to avoid a trip to the database.
111 virtual void LoadCreditCards() OVERRIDE {}
112
113 const MockAutofillMetrics* metric_logger() const {
114 return static_cast<const MockAutofillMetrics*>(
115 PersonalDataManager::metric_logger());
116 }
117
118 void set_autofill_enabled(bool autofill_enabled) {
119 autofill_enabled_ = autofill_enabled;
120 }
121
122 virtual bool IsAutofillEnabled() const OVERRIDE {
123 return autofill_enabled_;
124 }
125
126 MOCK_METHOD1(SaveImportedCreditCard,
127 void(const CreditCard& imported_credit_card));
128
129 private:
130 void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) {
131 AutofillProfile* profile = new AutofillProfile;
132 test::SetProfileInfo(profile, "Elvis", "Aaron",
133 "Presley", "theking@gmail.com", "RCA",
134 "3734 Elvis Presley Blvd.", "Apt. 10",
135 "Memphis", "Tennessee", "38116", "US",
136 "12345678901");
137 profile->set_guid("00000000-0000-0000-0000-000000000001");
138 profiles->push_back(profile);
139 profile = new AutofillProfile;
140 test::SetProfileInfo(profile, "Charles", "Hardin",
141 "Holley", "buddy@gmail.com", "Decca",
142 "123 Apple St.", "unit 6", "Lubbock",
143 "Texas", "79401", "US", "2345678901");
144 profile->set_guid("00000000-0000-0000-0000-000000000002");
145 profiles->push_back(profile);
146 }
147
148 bool autofill_enabled_;
149
150 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager);
151 };
152
153 class TestFormStructure : public FormStructure {
154 public:
155 explicit TestFormStructure(const FormData& form)
156 : FormStructure(form, std::string()) {}
157 virtual ~TestFormStructure() {}
158
159 void SetFieldTypes(const std::vector<AutofillFieldType>& heuristic_types,
160 const std::vector<AutofillFieldType>& server_types) {
161 ASSERT_EQ(field_count(), heuristic_types.size());
162 ASSERT_EQ(field_count(), server_types.size());
163
164 for (size_t i = 0; i < field_count(); ++i) {
165 AutofillField* form_field = field(i);
166 ASSERT_TRUE(form_field);
167 form_field->set_heuristic_type(heuristic_types[i]);
168 form_field->set_server_type(server_types[i]);
169 }
170
171 UpdateAutofillCount();
172 }
173
174 virtual std::string server_experiment_id() const OVERRIDE {
175 return server_experiment_id_;
176 }
177 void set_server_experiment_id(const std::string& server_experiment_id) {
178 server_experiment_id_ = server_experiment_id;
179 }
180
181 private:
182 std::string server_experiment_id_;
183 DISALLOW_COPY_AND_ASSIGN(TestFormStructure);
184 };
185
186 class TestAutofillManager : public AutofillManager {
187 public:
188 TestAutofillManager(AutofillDriver* driver,
189 AutofillManagerDelegate* manager_delegate,
190 TestPersonalDataManager* personal_manager)
191 : AutofillManager(driver, manager_delegate, personal_manager),
192 autofill_enabled_(true) {
193 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>);
194 }
195 virtual ~TestAutofillManager() {}
196
197 virtual std::string GetAutocheckoutURLPrefix() const OVERRIDE {
198 return std::string();
199 }
200
201 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; }
202
203 void set_autofill_enabled(bool autofill_enabled) {
204 autofill_enabled_ = autofill_enabled;
205 }
206
207 MockAutofillMetrics* metric_logger() {
208 return static_cast<MockAutofillMetrics*>(const_cast<AutofillMetrics*>(
209 AutofillManager::metric_logger()));
210 }
211
212 void AddSeenForm(const FormData& form,
213 const std::vector<AutofillFieldType>& heuristic_types,
214 const std::vector<AutofillFieldType>& server_types,
215 const std::string& experiment_id) {
216 FormData empty_form = form;
217 for (size_t i = 0; i < empty_form.fields.size(); ++i) {
218 empty_form.fields[i].value = base::string16();
219 }
220
221 // |form_structure| will be owned by |form_structures()|.
222 TestFormStructure* form_structure = new TestFormStructure(empty_form);
223 form_structure->SetFieldTypes(heuristic_types, server_types);
224 form_structure->set_server_experiment_id(experiment_id);
225 form_structures()->push_back(form_structure);
226 }
227
228 void FormSubmitted(const FormData& form, const TimeTicks& timestamp) {
229 message_loop_runner_ = new content::MessageLoopRunner();
230 if (!OnFormSubmitted(form, timestamp))
231 return;
232
233 // Wait for the asynchronous FormSubmitted() call to complete.
234 message_loop_runner_->Run();
235 }
236
237 virtual void UploadFormDataAsyncCallback(
238 const FormStructure* submitted_form,
239 const base::TimeTicks& load_time,
240 const base::TimeTicks& interaction_time,
241 const base::TimeTicks& submission_time) OVERRIDE {
242 message_loop_runner_->Quit();
243
244 AutofillManager::UploadFormDataAsyncCallback(submitted_form,
245 load_time,
246 interaction_time,
247 submission_time);
248 }
249
250 private:
251 bool autofill_enabled_;
252 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
253
254 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
255 };
256
257 } // namespace
258
259 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness {
260 public:
261 virtual ~AutofillMetricsTest();
262
263 virtual void SetUp() OVERRIDE;
264 virtual void TearDown() OVERRIDE;
265
266 protected:
267 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
268 MockAutofillMetrics* metric_logger);
269
270 scoped_ptr<TestAutofillDriver> autofill_driver_;
271 scoped_ptr<TestAutofillManager> autofill_manager_;
272 scoped_ptr<TestPersonalDataManager> personal_data_;
273 };
274
275 AutofillMetricsTest::~AutofillMetricsTest() {
276 // Order of destruction is important as AutofillManager relies on
277 // PersonalDataManager to be around when it gets destroyed.
278 autofill_manager_.reset();
279 }
280
281 void AutofillMetricsTest::SetUp() {
282 TestingProfile* profile = new TestingProfile();
283
284 // Ensure Mac OS X does not pop up a modal dialog for the Address Book.
285 autofill::test::DisableSystemServices(profile);
286
287 profile->CreateRequestContext();
288 browser_context_.reset(profile);
289 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile, NULL);
290
291 ChromeRenderViewHostTestHarness::SetUp();
292 TabAutofillManagerDelegate::CreateForWebContents(web_contents());
293
294 personal_data_.reset(new TestPersonalDataManager());
295 personal_data_->SetBrowserContext(profile);
296 autofill_driver_.reset(new TestAutofillDriver(web_contents()));
297 autofill_manager_.reset(new TestAutofillManager(
298 autofill_driver_.get(),
299 TabAutofillManagerDelegate::FromWebContents(web_contents()),
300 personal_data_.get()));
301 }
302
303 void AutofillMetricsTest::TearDown() {
304 // Order of destruction is important as AutofillManager relies on
305 // PersonalDataManager to be around when it gets destroyed. Also, a real
306 // AutofillManager is tied to the lifetime of the WebContents, so it must
307 // be destroyed at the destruction of the WebContents.
308 autofill_manager_.reset();
309 autofill_driver_.reset();
310 personal_data_.reset();
311 profile()->ResetRequestContext();
312 ChromeRenderViewHostTestHarness::TearDown();
313 }
314
315 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate(
316 MockAutofillMetrics* metric_logger) {
317 EXPECT_CALL(*metric_logger,
318 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
319
320 CreditCard credit_card;
321 return AutofillCCInfoBarDelegate::CreateForTesting(
322 metric_logger,
323 base::Bind(&TestPersonalDataManager::SaveImportedCreditCard,
324 base::Unretained(personal_data_.get()), credit_card));
325 }
326
327 // Test that we log quality metrics appropriately.
328 TEST_F(AutofillMetricsTest, QualityMetrics) {
329 // Set up our form data.
330 FormData form;
331 form.name = ASCIIToUTF16("TestForm");
332 form.method = ASCIIToUTF16("POST");
333 form.origin = GURL("http://example.com/form.html");
334 form.action = GURL("http://example.com/submit.html");
335 form.user_submitted = true;
336
337 std::vector<AutofillFieldType> heuristic_types, server_types;
338 FormFieldData field;
339
340 test::CreateTestFormField(
341 "Autofilled", "autofilled", "Elvis Aaron Presley", "text", &field);
342 field.is_autofilled = true;
343 form.fields.push_back(field);
344 heuristic_types.push_back(NAME_FULL);
345 server_types.push_back(NAME_FIRST);
346
347 test::CreateTestFormField(
348 "Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field);
349 field.is_autofilled = false;
350 form.fields.push_back(field);
351 heuristic_types.push_back(PHONE_HOME_NUMBER);
352 server_types.push_back(EMAIL_ADDRESS);
353
354 test::CreateTestFormField("Empty", "empty", "", "text", &field);
355 field.is_autofilled = false;
356 form.fields.push_back(field);
357 heuristic_types.push_back(NAME_FULL);
358 server_types.push_back(NAME_FIRST);
359
360 test::CreateTestFormField("Unknown", "unknown", "garbage", "text", &field);
361 field.is_autofilled = false;
362 form.fields.push_back(field);
363 heuristic_types.push_back(PHONE_HOME_NUMBER);
364 server_types.push_back(EMAIL_ADDRESS);
365
366 test::CreateTestFormField("Select", "select", "USA", "select-one", &field);
367 field.is_autofilled = false;
368 form.fields.push_back(field);
369 heuristic_types.push_back(UNKNOWN_TYPE);
370 server_types.push_back(NO_SERVER_DATA);
371
372 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
373 field.is_autofilled = true;
374 form.fields.push_back(field);
375 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
376 server_types.push_back(PHONE_HOME_WHOLE_NUMBER);
377
378 // Simulate having seen this form on page load.
379 autofill_manager_->AddSeenForm(form, heuristic_types, server_types,
380 std::string());
381
382 // Establish our expectations.
383 ::testing::InSequence dummy;
384 EXPECT_CALL(*autofill_manager_->metric_logger(),
385 LogServerExperimentIdForUpload(std::string()));
386 // Autofilled field
387 EXPECT_CALL(*autofill_manager_->metric_logger(),
388 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
389 std::string()));
390 EXPECT_CALL(*autofill_manager_->metric_logger(),
391 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MATCH,
392 NAME_FULL, std::string()));
393 EXPECT_CALL(*autofill_manager_->metric_logger(),
394 LogServerTypePrediction(AutofillMetrics::TYPE_MISMATCH,
395 NAME_FULL, std::string()));
396 EXPECT_CALL(*autofill_manager_->metric_logger(),
397 LogOverallTypePrediction(AutofillMetrics::TYPE_MISMATCH,
398 NAME_FULL, std::string()));
399 EXPECT_CALL(*autofill_manager_->metric_logger(),
400 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED,
401 std::string()));
402 // Non-autofilled field for which we had data
403 EXPECT_CALL(*autofill_manager_->metric_logger(),
404 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
405 std::string()));
406 EXPECT_CALL(*autofill_manager_->metric_logger(),
407 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MISMATCH,
408 EMAIL_ADDRESS, std::string()));
409 EXPECT_CALL(*autofill_manager_->metric_logger(),
410 LogServerTypePrediction(AutofillMetrics::TYPE_MATCH,
411 EMAIL_ADDRESS, std::string()));
412 EXPECT_CALL(*autofill_manager_->metric_logger(),
413 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH,
414 EMAIL_ADDRESS, std::string()));
415 EXPECT_CALL(*autofill_manager_->metric_logger(),
416 LogQualityMetric(AutofillMetrics::FIELD_NOT_AUTOFILLED,
417 std::string()));
418 EXPECT_CALL(*autofill_manager_->metric_logger(),
419 LogQualityMetric(
420 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH,
421 std::string()));
422 EXPECT_CALL(*autofill_manager_->metric_logger(),
423 LogQualityMetric(
424 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MATCH,
425 std::string()));
426 // Empty field
427 EXPECT_CALL(*autofill_manager_->metric_logger(),
428 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
429 std::string()));
430 // Unknown field
431 EXPECT_CALL(*autofill_manager_->metric_logger(),
432 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
433 std::string()));
434 // <select> field
435 EXPECT_CALL(*autofill_manager_->metric_logger(),
436 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
437 std::string()));
438 EXPECT_CALL(*autofill_manager_->metric_logger(),
439 LogHeuristicTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
440 ADDRESS_HOME_COUNTRY, std::string()));
441 EXPECT_CALL(*autofill_manager_->metric_logger(),
442 LogServerTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
443 ADDRESS_HOME_COUNTRY, std::string()));
444 EXPECT_CALL(*autofill_manager_->metric_logger(),
445 LogOverallTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
446 ADDRESS_HOME_COUNTRY, std::string()));
447 // Phone field
448 EXPECT_CALL(*autofill_manager_->metric_logger(),
449 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
450 std::string()));
451 EXPECT_CALL(*autofill_manager_->metric_logger(),
452 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MATCH,
453 PHONE_HOME_WHOLE_NUMBER, std::string()));
454 EXPECT_CALL(*autofill_manager_->metric_logger(),
455 LogServerTypePrediction(AutofillMetrics::TYPE_MATCH,
456 PHONE_HOME_WHOLE_NUMBER, std::string()));
457 EXPECT_CALL(*autofill_manager_->metric_logger(),
458 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH,
459 PHONE_HOME_WHOLE_NUMBER, std::string()));
460 EXPECT_CALL(*autofill_manager_->metric_logger(),
461 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED,
462 std::string()));
463 EXPECT_CALL(*autofill_manager_->metric_logger(),
464 LogUserHappinessMetric(
465 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME));
466
467 // Simulate form submission.
468 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
469 TimeTicks::Now()));
470 }
471
472 // Test that we log the appropriate additional metrics when Autofill failed.
473 TEST_F(AutofillMetricsTest, QualityMetricsForFailure) {
474 // Set up our form data.
475 FormData form;
476 form.name = ASCIIToUTF16("TestForm");
477 form.method = ASCIIToUTF16("POST");
478 form.origin = GURL("http://example.com/form.html");
479 form.action = GURL("http://example.com/submit.html");
480 form.user_submitted = true;
481
482 struct {
483 const char* label;
484 const char* name;
485 const char* value;
486 AutofillFieldType heuristic_type;
487 AutofillFieldType server_type;
488 AutofillMetrics::QualityMetric heuristic_metric;
489 AutofillMetrics::QualityMetric server_metric;
490 } failure_cases[] = {
491 {
492 "Heuristics unknown, server unknown", "0,0", "Elvis",
493 UNKNOWN_TYPE, NO_SERVER_DATA,
494 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_UNKNOWN,
495 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_UNKNOWN
496 },
497 {
498 "Heuristics match, server unknown", "1,0", "Aaron",
499 NAME_MIDDLE, NO_SERVER_DATA,
500 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MATCH,
501 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_UNKNOWN
502 },
503 {
504 "Heuristics mismatch, server unknown", "2,0", "Presley",
505 PHONE_HOME_NUMBER, NO_SERVER_DATA,
506 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH,
507 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_UNKNOWN
508 },
509 {
510 "Heuristics unknown, server match", "0,1", "theking@gmail.com",
511 UNKNOWN_TYPE, EMAIL_ADDRESS,
512 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_UNKNOWN,
513 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MATCH
514 },
515 {
516 "Heuristics match, server match", "1,1", "3734 Elvis Presley Blvd.",
517 ADDRESS_HOME_LINE1, ADDRESS_HOME_LINE1,
518 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MATCH,
519 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MATCH
520 },
521 {
522 "Heuristics mismatch, server match", "2,1", "Apt. 10",
523 PHONE_HOME_NUMBER, ADDRESS_HOME_LINE2,
524 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH,
525 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MATCH
526 },
527 {
528 "Heuristics unknown, server mismatch", "0,2", "Memphis",
529 UNKNOWN_TYPE, PHONE_HOME_NUMBER,
530 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_UNKNOWN,
531 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MISMATCH
532 },
533 {
534 "Heuristics match, server mismatch", "1,2", "Tennessee",
535 ADDRESS_HOME_STATE, PHONE_HOME_NUMBER,
536 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MATCH,
537 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MISMATCH
538 },
539 {
540 "Heuristics mismatch, server mismatch", "2,2", "38116",
541 PHONE_HOME_NUMBER, PHONE_HOME_NUMBER,
542 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH,
543 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MISMATCH
544 }
545 };
546
547 std::vector<AutofillFieldType> heuristic_types, server_types;
548 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(failure_cases); ++i) {
549 FormFieldData field;
550 test::CreateTestFormField(failure_cases[i].label,
551 failure_cases[i].name,
552 failure_cases[i].value, "text", &field);
553 form.fields.push_back(field);
554 heuristic_types.push_back(failure_cases[i].heuristic_type);
555 server_types.push_back(failure_cases[i].server_type);
556
557 }
558
559 // Simulate having seen this form with the desired heuristic and server types.
560 // |form_structure| will be owned by |autofill_manager_|.
561 autofill_manager_->AddSeenForm(form, heuristic_types, server_types,
562 std::string());
563
564
565 // Establish our expectations.
566 ::testing::InSequence dummy;
567 EXPECT_CALL(*autofill_manager_->metric_logger(),
568 LogServerExperimentIdForUpload(std::string()));
569 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(failure_cases); ++i) {
570 EXPECT_CALL(*autofill_manager_->metric_logger(),
571 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
572 std::string()));
573 EXPECT_CALL(*autofill_manager_->metric_logger(),
574 LogQualityMetric(AutofillMetrics::FIELD_NOT_AUTOFILLED,
575 std::string()));
576 EXPECT_CALL(*autofill_manager_->metric_logger(),
577 LogQualityMetric(failure_cases[i].heuristic_metric,
578 std::string()));
579 EXPECT_CALL(*autofill_manager_->metric_logger(),
580 LogQualityMetric(failure_cases[i].server_metric,
581 std::string()));
582 }
583
584 // Simulate form submission.
585 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
586 TimeTicks::Now()));
587 }
588
589 // Test that we behave sanely when the cached form differs from the submitted
590 // one.
591 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) {
592 // Set up our form data.
593 FormData form;
594 form.name = ASCIIToUTF16("TestForm");
595 form.method = ASCIIToUTF16("POST");
596 form.origin = GURL("http://example.com/form.html");
597 form.action = GURL("http://example.com/submit.html");
598 form.user_submitted = true;
599
600 std::vector<AutofillFieldType> heuristic_types, server_types;
601
602 FormFieldData field;
603 test::CreateTestFormField(
604 "Both match", "match", "Elvis Aaron Presley", "text", &field);
605 field.is_autofilled = true;
606 form.fields.push_back(field);
607 heuristic_types.push_back(NAME_FULL);
608 server_types.push_back(NAME_FULL);
609 test::CreateTestFormField(
610 "Both mismatch", "mismatch", "buddy@gmail.com", "text", &field);
611 field.is_autofilled = false;
612 form.fields.push_back(field);
613 heuristic_types.push_back(PHONE_HOME_NUMBER);
614 server_types.push_back(PHONE_HOME_NUMBER);
615 test::CreateTestFormField(
616 "Only heuristics match", "mixed", "Memphis", "text", &field);
617 field.is_autofilled = false;
618 form.fields.push_back(field);
619 heuristic_types.push_back(ADDRESS_HOME_CITY);
620 server_types.push_back(PHONE_HOME_NUMBER);
621 test::CreateTestFormField("Unknown", "unknown", "garbage", "text", &field);
622 field.is_autofilled = false;
623 form.fields.push_back(field);
624 heuristic_types.push_back(UNKNOWN_TYPE);
625 server_types.push_back(UNKNOWN_TYPE);
626
627 // Simulate having seen this form with the desired heuristic and server types.
628 // |form_structure| will be owned by |autofill_manager_|.
629 autofill_manager_->AddSeenForm(form, heuristic_types, server_types,
630 std::string());
631
632
633 // Add a field and re-arrange the remaining form fields before submitting.
634 std::vector<FormFieldData> cached_fields = form.fields;
635 form.fields.clear();
636 test::CreateTestFormField(
637 "New field", "new field", "Tennessee", "text", &field);
638 form.fields.push_back(field);
639 form.fields.push_back(cached_fields[2]);
640 form.fields.push_back(cached_fields[1]);
641 form.fields.push_back(cached_fields[3]);
642 form.fields.push_back(cached_fields[0]);
643
644 // Establish our expectations.
645 ::testing::InSequence dummy;
646 // New field
647 EXPECT_CALL(*autofill_manager_->metric_logger(),
648 LogServerExperimentIdForUpload(std::string()));
649 EXPECT_CALL(*autofill_manager_->metric_logger(),
650 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
651 std::string()));
652 EXPECT_CALL(*autofill_manager_->metric_logger(),
653 LogHeuristicTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
654 ADDRESS_HOME_STATE, std::string()));
655 EXPECT_CALL(*autofill_manager_->metric_logger(),
656 LogServerTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
657 ADDRESS_HOME_STATE, std::string()));
658 EXPECT_CALL(*autofill_manager_->metric_logger(),
659 LogOverallTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
660 ADDRESS_HOME_STATE, std::string()));
661 EXPECT_CALL(*autofill_manager_->metric_logger(),
662 LogQualityMetric(AutofillMetrics::FIELD_NOT_AUTOFILLED,
663 std::string()));
664 EXPECT_CALL(*autofill_manager_->metric_logger(),
665 LogQualityMetric(
666 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_UNKNOWN,
667 std::string()));
668 EXPECT_CALL(*autofill_manager_->metric_logger(),
669 LogQualityMetric(
670 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_UNKNOWN,
671 std::string()));
672 // Only heuristics match
673 EXPECT_CALL(*autofill_manager_->metric_logger(),
674 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
675 std::string()));
676 EXPECT_CALL(*autofill_manager_->metric_logger(),
677 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MATCH,
678 ADDRESS_HOME_CITY, std::string()));
679 EXPECT_CALL(*autofill_manager_->metric_logger(),
680 LogServerTypePrediction(AutofillMetrics::TYPE_MISMATCH,
681 ADDRESS_HOME_CITY, std::string()));
682 EXPECT_CALL(*autofill_manager_->metric_logger(),
683 LogOverallTypePrediction(AutofillMetrics::TYPE_MISMATCH,
684 ADDRESS_HOME_CITY, std::string()));
685 EXPECT_CALL(*autofill_manager_->metric_logger(),
686 LogQualityMetric(AutofillMetrics::FIELD_NOT_AUTOFILLED,
687 std::string()));
688 EXPECT_CALL(*autofill_manager_->metric_logger(),
689 LogQualityMetric(
690 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MATCH,
691 std::string()));
692 EXPECT_CALL(*autofill_manager_->metric_logger(),
693 LogQualityMetric(
694 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MISMATCH,
695 std::string()));
696 // Both mismatch
697 EXPECT_CALL(*autofill_manager_->metric_logger(),
698 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
699 std::string()));
700 EXPECT_CALL(*autofill_manager_->metric_logger(),
701 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MISMATCH,
702 EMAIL_ADDRESS, std::string()));
703 EXPECT_CALL(*autofill_manager_->metric_logger(),
704 LogServerTypePrediction(AutofillMetrics::TYPE_MISMATCH,
705 EMAIL_ADDRESS, std::string()));
706 EXPECT_CALL(*autofill_manager_->metric_logger(),
707 LogOverallTypePrediction(AutofillMetrics::TYPE_MISMATCH,
708 EMAIL_ADDRESS, std::string()));
709 EXPECT_CALL(*autofill_manager_->metric_logger(),
710 LogQualityMetric(AutofillMetrics::FIELD_NOT_AUTOFILLED,
711 std::string()));
712 EXPECT_CALL(*autofill_manager_->metric_logger(),
713 LogQualityMetric(
714 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH,
715 std::string()));
716 EXPECT_CALL(*autofill_manager_->metric_logger(),
717 LogQualityMetric(
718 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MISMATCH,
719 std::string()));
720 // Unknown
721 EXPECT_CALL(*autofill_manager_->metric_logger(),
722 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
723 std::string()));
724 // Both match
725 EXPECT_CALL(*autofill_manager_->metric_logger(),
726 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
727 std::string()));
728 EXPECT_CALL(*autofill_manager_->metric_logger(),
729 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MATCH,
730 NAME_FULL, std::string()));
731 EXPECT_CALL(*autofill_manager_->metric_logger(),
732 LogServerTypePrediction(AutofillMetrics::TYPE_MATCH,
733 NAME_FULL, std::string()));
734 EXPECT_CALL(*autofill_manager_->metric_logger(),
735 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH,
736 NAME_FULL, std::string()));
737 EXPECT_CALL(*autofill_manager_->metric_logger(),
738 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED,
739 std::string()));
740
741 // Simulate form submission.
742 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
743 TimeTicks::Now()));
744 }
745
746 // Verify that we correctly log metrics regarding developer engagement.
747 TEST_F(AutofillMetricsTest, DeveloperEngagement) {
748 // Start with a non-fillable form.
749 FormData form;
750 form.name = ASCIIToUTF16("TestForm");
751 form.method = ASCIIToUTF16("POST");
752 form.origin = GURL("http://example.com/form.html");
753 form.action = GURL("http://example.com/submit.html");
754
755 FormFieldData field;
756 test::CreateTestFormField("Name", "name", "", "text", &field);
757 form.fields.push_back(field);
758 test::CreateTestFormField("Email", "email", "", "text", &field);
759 form.fields.push_back(field);
760
761 std::vector<FormData> forms(1, form);
762
763 // Ensure no metrics are logged when loading a non-fillable form.
764 {
765 EXPECT_CALL(*autofill_manager_->metric_logger(),
766 LogDeveloperEngagementMetric(_)).Times(0);
767 autofill_manager_->OnFormsSeen(forms, TimeTicks(),
768 autofill::NO_SPECIAL_FORMS_SEEN);
769 autofill_manager_->Reset();
770 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
771 }
772
773 // Add another field to the form, so that it becomes fillable.
774 test::CreateTestFormField("Phone", "phone", "", "text", &field);
775 forms.back().fields.push_back(field);
776
777 // Expect only the "form parsed" metric to be logged; no metrics about
778 // author-specified field type hints.
779 {
780 EXPECT_CALL(
781 *autofill_manager_->metric_logger(),
782 LogDeveloperEngagementMetric(
783 AutofillMetrics::FILLABLE_FORM_PARSED)).Times(1);
784 EXPECT_CALL(
785 *autofill_manager_->metric_logger(),
786 LogDeveloperEngagementMetric(
787 AutofillMetrics::FILLABLE_FORM_CONTAINS_TYPE_HINTS)).Times(0);
788 autofill_manager_->OnFormsSeen(forms, TimeTicks(),
789 autofill::NO_SPECIAL_FORMS_SEEN);
790 autofill_manager_->Reset();
791 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
792 }
793
794 // Add some fields with an author-specified field type to the form.
795 // We need to add at least three fields, because a form must have at least
796 // three fillable fields to be considered to be autofillable; and if at least
797 // one field specifies an explicit type hint, we don't apply any of our usual
798 // local heuristics to detect field types in the rest of the form.
799 test::CreateTestFormField("", "", "", "text", &field);
800 field.autocomplete_attribute = "given-name";
801 forms.back().fields.push_back(field);
802 test::CreateTestFormField("", "", "", "text", &field);
803 field.autocomplete_attribute = "email";
804 forms.back().fields.push_back(field);
805 test::CreateTestFormField("", "", "", "text", &field);
806 field.autocomplete_attribute = "street-address";
807 forms.back().fields.push_back(field);
808
809 // Expect both the "form parsed" metric and the author-specified field type
810 // hints metric to be logged.
811 {
812 EXPECT_CALL(
813 *autofill_manager_->metric_logger(),
814 LogDeveloperEngagementMetric(
815 AutofillMetrics::FILLABLE_FORM_PARSED)).Times(1);
816 EXPECT_CALL(
817 *autofill_manager_->metric_logger(),
818 LogDeveloperEngagementMetric(
819 AutofillMetrics::FILLABLE_FORM_CONTAINS_TYPE_HINTS)).Times(1);
820 autofill_manager_->OnFormsSeen(forms, TimeTicks(),
821 autofill::NO_SPECIAL_FORMS_SEEN);
822 autofill_manager_->Reset();
823 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
824 }
825 }
826
827 // Test that we don't log quality metrics for non-autofillable forms.
828 TEST_F(AutofillMetricsTest, NoQualityMetricsForNonAutofillableForms) {
829 // Forms must include at least three fields to be auto-fillable.
830 FormData form;
831 form.name = ASCIIToUTF16("TestForm");
832 form.method = ASCIIToUTF16("POST");
833 form.origin = GURL("http://example.com/form.html");
834 form.action = GURL("http://example.com/submit.html");
835 form.user_submitted = true;
836
837 FormFieldData field;
838 test::CreateTestFormField(
839 "Autofilled", "autofilled", "Elvis Presley", "text", &field);
840 field.is_autofilled = true;
841 form.fields.push_back(field);
842 test::CreateTestFormField(
843 "Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field);
844 form.fields.push_back(field);
845
846 // Simulate form submission.
847 EXPECT_CALL(*autofill_manager_->metric_logger(),
848 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
849 std::string())).Times(0);
850 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
851 TimeTicks::Now()));
852
853 // Search forms are not auto-fillable.
854 form.action = GURL("http://example.com/search?q=Elvis%20Presley");
855 test::CreateTestFormField("Empty", "empty", "", "text", &field);
856 form.fields.push_back(field);
857
858 // Simulate form submission.
859 EXPECT_CALL(*autofill_manager_->metric_logger(),
860 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
861 std::string())).Times(0);
862 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
863 TimeTicks::Now()));
864 }
865
866 // Test that we recored the experiment id appropriately.
867 TEST_F(AutofillMetricsTest, QualityMetricsWithExperimentId) {
868 // Set up our form data.
869 FormData form;
870 form.name = ASCIIToUTF16("TestForm");
871 form.method = ASCIIToUTF16("POST");
872 form.origin = GURL("http://example.com/form.html");
873 form.action = GURL("http://example.com/submit.html");
874 form.user_submitted = true;
875
876 std::vector<AutofillFieldType> heuristic_types, server_types;
877 FormFieldData field;
878
879 test::CreateTestFormField(
880 "Autofilled", "autofilled", "Elvis Aaron Presley", "text", &field);
881 field.is_autofilled = true;
882 form.fields.push_back(field);
883 heuristic_types.push_back(NAME_FULL);
884 server_types.push_back(NAME_FIRST);
885
886 test::CreateTestFormField(
887 "Autofill Failed", "autofillfailed", "buddy@gmail.com", "text", &field);
888 field.is_autofilled = false;
889 form.fields.push_back(field);
890 heuristic_types.push_back(PHONE_HOME_NUMBER);
891 server_types.push_back(EMAIL_ADDRESS);
892
893 test::CreateTestFormField("Empty", "empty", "", "text", &field);
894 field.is_autofilled = false;
895 form.fields.push_back(field);
896 heuristic_types.push_back(NAME_FULL);
897 server_types.push_back(NAME_FIRST);
898
899 test::CreateTestFormField("Unknown", "unknown", "garbage", "text", &field);
900 field.is_autofilled = false;
901 form.fields.push_back(field);
902 heuristic_types.push_back(PHONE_HOME_NUMBER);
903 server_types.push_back(EMAIL_ADDRESS);
904
905 test::CreateTestFormField("Select", "select", "USA", "select-one", &field);
906 field.is_autofilled = false;
907 form.fields.push_back(field);
908 heuristic_types.push_back(UNKNOWN_TYPE);
909 server_types.push_back(NO_SERVER_DATA);
910
911 const std::string experiment_id = "ThatOughtaDoIt";
912
913 // Simulate having seen this form on page load.
914 // |form_structure| will be owned by |autofill_manager_|.
915 autofill_manager_->AddSeenForm(form, heuristic_types, server_types,
916 experiment_id);
917
918 // Establish our expectations.
919 ::testing::InSequence dummy;
920 EXPECT_CALL(*autofill_manager_->metric_logger(),
921 LogServerExperimentIdForUpload(experiment_id));
922 // Autofilled field
923 EXPECT_CALL(*autofill_manager_->metric_logger(),
924 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
925 experiment_id));
926 EXPECT_CALL(*autofill_manager_->metric_logger(),
927 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MATCH,
928 NAME_FULL, experiment_id));
929 EXPECT_CALL(*autofill_manager_->metric_logger(),
930 LogServerTypePrediction(AutofillMetrics::TYPE_MISMATCH,
931 NAME_FULL, experiment_id));
932 EXPECT_CALL(*autofill_manager_->metric_logger(),
933 LogOverallTypePrediction(AutofillMetrics::TYPE_MISMATCH,
934 NAME_FULL, experiment_id));
935 EXPECT_CALL(*autofill_manager_->metric_logger(),
936 LogQualityMetric(AutofillMetrics::FIELD_AUTOFILLED,
937 experiment_id));
938 // Non-autofilled field for which we had data
939 EXPECT_CALL(*autofill_manager_->metric_logger(),
940 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
941 experiment_id));
942 EXPECT_CALL(*autofill_manager_->metric_logger(),
943 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MISMATCH,
944 EMAIL_ADDRESS, experiment_id));
945 EXPECT_CALL(*autofill_manager_->metric_logger(),
946 LogServerTypePrediction(AutofillMetrics::TYPE_MATCH,
947 EMAIL_ADDRESS, experiment_id));
948 EXPECT_CALL(*autofill_manager_->metric_logger(),
949 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH,
950 EMAIL_ADDRESS, experiment_id));
951 EXPECT_CALL(*autofill_manager_->metric_logger(),
952 LogQualityMetric(AutofillMetrics::FIELD_NOT_AUTOFILLED,
953 experiment_id));
954 EXPECT_CALL(*autofill_manager_->metric_logger(),
955 LogQualityMetric(
956 AutofillMetrics::NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH,
957 experiment_id));
958 EXPECT_CALL(*autofill_manager_->metric_logger(),
959 LogQualityMetric(
960 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MATCH,
961 experiment_id));
962 // Empty field
963 EXPECT_CALL(*autofill_manager_->metric_logger(),
964 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
965 experiment_id));
966 // Unknown field
967 EXPECT_CALL(*autofill_manager_->metric_logger(),
968 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
969 experiment_id));
970 // <select> field
971 EXPECT_CALL(*autofill_manager_->metric_logger(),
972 LogQualityMetric(AutofillMetrics::FIELD_SUBMITTED,
973 experiment_id));
974 EXPECT_CALL(*autofill_manager_->metric_logger(),
975 LogHeuristicTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
976 ADDRESS_HOME_COUNTRY, experiment_id));
977 EXPECT_CALL(*autofill_manager_->metric_logger(),
978 LogServerTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
979 ADDRESS_HOME_COUNTRY, experiment_id));
980 EXPECT_CALL(*autofill_manager_->metric_logger(),
981 LogOverallTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
982 ADDRESS_HOME_COUNTRY, experiment_id));
983
984 // Simulate form submission.
985 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form,
986 TimeTicks::Now()));
987 }
988
989 // Test that the profile count is logged correctly.
990 TEST_F(AutofillMetricsTest, StoredProfileCount) {
991 // The metric should be logged when the profiles are first loaded.
992 EXPECT_CALL(*personal_data_->metric_logger(),
993 LogStoredProfileCount(2)).Times(1);
994 personal_data_->LoadProfiles();
995
996 // The metric should only be logged once.
997 EXPECT_CALL(*personal_data_->metric_logger(),
998 LogStoredProfileCount(::testing::_)).Times(0);
999 personal_data_->LoadProfiles();
1000 }
1001
1002 // Test that we correctly log when Autofill is enabled.
1003 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) {
1004 personal_data_->set_autofill_enabled(true);
1005 EXPECT_CALL(*personal_data_->metric_logger(),
1006 LogIsAutofillEnabledAtStartup(true)).Times(1);
1007 personal_data_->Init(profile());
1008 }
1009
1010 // Test that we correctly log when Autofill is disabled.
1011 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) {
1012 personal_data_->set_autofill_enabled(false);
1013 EXPECT_CALL(*personal_data_->metric_logger(),
1014 LogIsAutofillEnabledAtStartup(false)).Times(1);
1015 personal_data_->Init(profile());
1016 }
1017
1018 // Test that we log the number of Autofill suggestions when filling a form.
1019 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) {
1020 // Set up our form data.
1021 FormData form;
1022 form.name = ASCIIToUTF16("TestForm");
1023 form.method = ASCIIToUTF16("POST");
1024 form.origin = GURL("http://example.com/form.html");
1025 form.action = GURL("http://example.com/submit.html");
1026 form.user_submitted = true;
1027
1028 FormFieldData field;
1029 std::vector<AutofillFieldType> field_types;
1030 test::CreateTestFormField("Name", "name", "", "text", &field);
1031 form.fields.push_back(field);
1032 field_types.push_back(NAME_FULL);
1033 test::CreateTestFormField("Email", "email", "", "email", &field);
1034 form.fields.push_back(field);
1035 field_types.push_back(EMAIL_ADDRESS);
1036 test::CreateTestFormField("Phone", "phone", "", "tel", &field);
1037 form.fields.push_back(field);
1038 field_types.push_back(PHONE_HOME_NUMBER);
1039
1040 // Simulate having seen this form on page load.
1041 // |form_structure| will be owned by |autofill_manager_|.
1042 autofill_manager_->AddSeenForm(form, field_types, field_types,
1043 std::string());
1044
1045 // Establish our expectations.
1046 ::testing::InSequence dummy;
1047 EXPECT_CALL(*autofill_manager_->metric_logger(),
1048 LogAddressSuggestionsCount(2)).Times(1);
1049
1050 // Simulate activating the autofill popup for the phone field.
1051 autofill_manager_->OnQueryFormFieldAutofill(
1052 0, form, field, gfx::Rect(), false);
1053
1054 // Simulate activating the autofill popup for the email field after typing.
1055 // No new metric should be logged, since we're still on the same page.
1056 test::CreateTestFormField("Email", "email", "b", "email", &field);
1057 autofill_manager_->OnQueryFormFieldAutofill(
1058 0, form, field, gfx::Rect(), false);
1059
1060 // Reset the autofill manager state.
1061 autofill_manager_->Reset();
1062 autofill_manager_->AddSeenForm(form, field_types, field_types,
1063 std::string());
1064
1065 // Establish our expectations.
1066 EXPECT_CALL(*autofill_manager_->metric_logger(),
1067 LogAddressSuggestionsCount(1)).Times(1);
1068
1069 // Simulate activating the autofill popup for the email field after typing.
1070 autofill_manager_->OnQueryFormFieldAutofill(
1071 0, form, field, gfx::Rect(), false);
1072
1073 // Reset the autofill manager state again.
1074 autofill_manager_->Reset();
1075 autofill_manager_->AddSeenForm(form, field_types, field_types,
1076 std::string());
1077
1078 // Establish our expectations.
1079 EXPECT_CALL(*autofill_manager_->metric_logger(),
1080 LogAddressSuggestionsCount(::testing::_)).Times(0);
1081
1082 // Simulate activating the autofill popup for the email field after typing.
1083 form.fields[0].is_autofilled = true;
1084 autofill_manager_->OnQueryFormFieldAutofill(
1085 0, form, field, gfx::Rect(), false);
1086 }
1087
1088 // Test that we log whether Autofill is enabled when filling a form.
1089 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) {
1090 // Establish our expectations.
1091 ::testing::InSequence dummy;
1092 EXPECT_CALL(*autofill_manager_->metric_logger(),
1093 LogIsAutofillEnabledAtPageLoad(true)).Times(1);
1094
1095 autofill_manager_->set_autofill_enabled(true);
1096 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks(),
1097 autofill::NO_SPECIAL_FORMS_SEEN);
1098
1099 // Reset the autofill manager state.
1100 autofill_manager_->Reset();
1101
1102 // Establish our expectations.
1103 EXPECT_CALL(*autofill_manager_->metric_logger(),
1104 LogIsAutofillEnabledAtPageLoad(false)).Times(1);
1105
1106 autofill_manager_->set_autofill_enabled(false);
1107 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks(),
1108 autofill::NO_SPECIAL_FORMS_SEEN);
1109 }
1110
1111 // Test that credit card infobar metrics are logged correctly.
1112 TEST_F(AutofillMetricsTest, CreditCardInfoBar) {
1113 testing::NiceMock<MockAutofillMetrics> metric_logger;
1114 ::testing::InSequence dummy;
1115
1116 // Accept the infobar.
1117 {
1118 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
1119 ASSERT_TRUE(infobar);
1120 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
1121 EXPECT_CALL(metric_logger,
1122 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1);
1123 EXPECT_CALL(metric_logger,
1124 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1125 EXPECT_TRUE(infobar->Accept());
1126 }
1127
1128 // Cancel the infobar.
1129 {
1130 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
1131 ASSERT_TRUE(infobar);
1132 EXPECT_CALL(metric_logger,
1133 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
1134 EXPECT_CALL(metric_logger,
1135 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1136 EXPECT_TRUE(infobar->Cancel());
1137 }
1138
1139 // Dismiss the infobar.
1140 {
1141 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
1142 ASSERT_TRUE(infobar);
1143 EXPECT_CALL(metric_logger,
1144 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
1145 EXPECT_CALL(metric_logger,
1146 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
1147 infobar->InfoBarDismissed();
1148 }
1149
1150 // Ignore the infobar.
1151 {
1152 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
1153 ASSERT_TRUE(infobar);
1154 EXPECT_CALL(metric_logger,
1155 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1);
1156 }
1157 }
1158
1159 // Test that server query response experiment id metrics are logged correctly.
1160 TEST_F(AutofillMetricsTest, ServerQueryExperimentIdForQuery) {
1161 testing::NiceMock<MockAutofillMetrics> metric_logger;
1162 ::testing::InSequence dummy;
1163
1164 // No experiment specified.
1165 EXPECT_CALL(metric_logger,
1166 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED));
1167 EXPECT_CALL(metric_logger,
1168 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED));
1169 EXPECT_CALL(metric_logger,
1170 LogServerExperimentIdForQuery(std::string()));
1171 EXPECT_CALL(metric_logger,
1172 LogServerQueryMetric(
1173 AutofillMetrics::QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS));
1174 AutocheckoutPageMetaData page_meta_data;
1175 FormStructure::ParseQueryResponse(
1176 "<autofillqueryresponse></autofillqueryresponse>",
1177 std::vector<FormStructure*>(),
1178 &page_meta_data,
1179 metric_logger);
1180
1181 // Experiment "ar1" specified.
1182 EXPECT_CALL(metric_logger,
1183 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED));
1184 EXPECT_CALL(metric_logger,
1185 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED));
1186 EXPECT_CALL(metric_logger,
1187 LogServerExperimentIdForQuery("ar1"));
1188 EXPECT_CALL(metric_logger,
1189 LogServerQueryMetric(
1190 AutofillMetrics::QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS));
1191 FormStructure::ParseQueryResponse(
1192 "<autofillqueryresponse experimentid=\"ar1\"></autofillqueryresponse>",
1193 std::vector<FormStructure*>(),
1194 &page_meta_data,
1195 metric_logger);
1196 }
1197
1198 // Verify that we correctly log user happiness metrics dealing with form loading
1199 // and form submission.
1200 TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
1201 // Start with a form with insufficiently many fields.
1202 FormData form;
1203 form.name = ASCIIToUTF16("TestForm");
1204 form.method = ASCIIToUTF16("POST");
1205 form.origin = GURL("http://example.com/form.html");
1206 form.action = GURL("http://example.com/submit.html");
1207 form.user_submitted = true;
1208
1209 FormFieldData field;
1210 test::CreateTestFormField("Name", "name", "", "text", &field);
1211 form.fields.push_back(field);
1212 test::CreateTestFormField("Email", "email", "", "text", &field);
1213 form.fields.push_back(field);
1214
1215 std::vector<FormData> forms(1, form);
1216
1217 // Expect no notifications when the form is first seen.
1218 {
1219 EXPECT_CALL(*autofill_manager_->metric_logger(),
1220 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED)).Times(0);
1221 autofill_manager_->OnFormsSeen(forms, TimeTicks(),
1222 autofill::NO_SPECIAL_FORMS_SEEN);
1223 }
1224
1225
1226 // Expect no notifications when the form is submitted.
1227 {
1228 EXPECT_CALL(
1229 *autofill_manager_->metric_logger(),
1230 LogUserHappinessMetric(
1231 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL)).Times(0);
1232 EXPECT_CALL(
1233 *autofill_manager_->metric_logger(),
1234 LogUserHappinessMetric(
1235 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)).Times(0);
1236 EXPECT_CALL(
1237 *autofill_manager_->metric_logger(),
1238 LogUserHappinessMetric(
1239 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE)).Times(0);
1240 EXPECT_CALL(
1241 *autofill_manager_->metric_logger(),
1242 LogUserHappinessMetric(
1243 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)).Times(0);
1244 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1245 }
1246
1247 // Add more fields to the form.
1248 test::CreateTestFormField("Phone", "phone", "", "text", &field);
1249 form.fields.push_back(field);
1250 test::CreateTestFormField("Unknown", "unknown", "", "text", &field);
1251 form.fields.push_back(field);
1252 forms.front() = form;
1253
1254 // Expect a notification when the form is first seen.
1255 {
1256 EXPECT_CALL(*autofill_manager_->metric_logger(),
1257 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED));
1258 autofill_manager_->OnFormsSeen(forms, TimeTicks(),
1259 autofill::NO_SPECIAL_FORMS_SEEN);
1260 }
1261
1262 // Expect a notification when the form is submitted.
1263 {
1264 EXPECT_CALL(*autofill_manager_->metric_logger(),
1265 LogUserHappinessMetric(
1266 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
1267 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1268 }
1269
1270 // Fill in two of the fields.
1271 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
1272 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
1273 forms.front() = form;
1274
1275 // Expect a notification when the form is submitted.
1276 {
1277 EXPECT_CALL(*autofill_manager_->metric_logger(),
1278 LogUserHappinessMetric(
1279 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
1280 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1281 }
1282
1283 // Fill in the third field.
1284 form.fields[2].value = ASCIIToUTF16("12345678901");
1285 forms.front() = form;
1286
1287 // Expect notifications when the form is submitted.
1288 {
1289 EXPECT_CALL(*autofill_manager_->metric_logger(),
1290 LogUserHappinessMetric(
1291 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE));
1292 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1293 }
1294
1295
1296 // Mark one of the fields as autofilled.
1297 form.fields[1].is_autofilled = true;
1298 forms.front() = form;
1299
1300 // Expect notifications when the form is submitted.
1301 {
1302 EXPECT_CALL(*autofill_manager_->metric_logger(),
1303 LogUserHappinessMetric(
1304 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME));
1305 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1306 }
1307
1308 // Mark all of the fillable fields as autofilled.
1309 form.fields[0].is_autofilled = true;
1310 form.fields[2].is_autofilled = true;
1311 forms.front() = form;
1312
1313 // Expect notifications when the form is submitted.
1314 {
1315 EXPECT_CALL(*autofill_manager_->metric_logger(),
1316 LogUserHappinessMetric(
1317 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL));
1318 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1319 }
1320
1321 // Clear out the third field's value.
1322 form.fields[2].value = base::string16();
1323 forms.front() = form;
1324
1325 // Expect notifications when the form is submitted.
1326 {
1327 EXPECT_CALL(*autofill_manager_->metric_logger(),
1328 LogUserHappinessMetric(
1329 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
1330 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
1331 }
1332 }
1333
1334 // Verify that we correctly log user happiness metrics dealing with form
1335 // interaction.
1336 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
1337 // Load a fillable form.
1338 FormData form;
1339 form.name = ASCIIToUTF16("TestForm");
1340 form.method = ASCIIToUTF16("POST");
1341 form.origin = GURL("http://example.com/form.html");
1342 form.action = GURL("http://example.com/submit.html");
1343 form.user_submitted = true;
1344
1345 FormFieldData field;
1346 test::CreateTestFormField("Name", "name", "", "text", &field);
1347 form.fields.push_back(field);
1348 test::CreateTestFormField("Email", "email", "", "text", &field);
1349 form.fields.push_back(field);
1350 test::CreateTestFormField("Phone", "phone", "", "text", &field);
1351 form.fields.push_back(field);
1352
1353 std::vector<FormData> forms(1, form);
1354
1355 // Expect a notification when the form is first seen.
1356 {
1357 EXPECT_CALL(*autofill_manager_->metric_logger(),
1358 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED));
1359 autofill_manager_->OnFormsSeen(forms, TimeTicks(),
1360 autofill::NO_SPECIAL_FORMS_SEEN);
1361 }
1362
1363 // Simulate typing.
1364 {
1365 EXPECT_CALL(*autofill_manager_->metric_logger(),
1366 LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE));
1367 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1368 TimeTicks());
1369 }
1370
1371 // Simulate suggestions shown twice for a single edit (i.e. multiple
1372 // keystrokes in a single field).
1373 {
1374 EXPECT_CALL(*autofill_manager_->metric_logger(),
1375 LogUserHappinessMetric(
1376 AutofillMetrics::SUGGESTIONS_SHOWN)).Times(1);
1377 EXPECT_CALL(*autofill_manager_->metric_logger(),
1378 LogUserHappinessMetric(
1379 AutofillMetrics::SUGGESTIONS_SHOWN_ONCE)).Times(1);
1380 autofill_manager_->OnDidShowAutofillSuggestions(true);
1381 autofill_manager_->OnDidShowAutofillSuggestions(false);
1382 }
1383
1384 // Simulate suggestions shown for a different field.
1385 {
1386 EXPECT_CALL(*autofill_manager_->metric_logger(),
1387 LogUserHappinessMetric(AutofillMetrics::SUGGESTIONS_SHOWN));
1388 EXPECT_CALL(*autofill_manager_->metric_logger(),
1389 LogUserHappinessMetric(
1390 AutofillMetrics::SUGGESTIONS_SHOWN_ONCE)).Times(0);
1391 autofill_manager_->OnDidShowAutofillSuggestions(true);
1392 }
1393
1394 // Simulate invoking autofill.
1395 {
1396 EXPECT_CALL(*autofill_manager_->metric_logger(),
1397 LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL));
1398 EXPECT_CALL(*autofill_manager_->metric_logger(),
1399 LogUserHappinessMetric(
1400 AutofillMetrics::USER_DID_AUTOFILL_ONCE));
1401 autofill_manager_->OnDidFillAutofillFormData(TimeTicks());
1402 }
1403
1404 // Simulate editing an autofilled field.
1405 {
1406 EXPECT_CALL(*autofill_manager_->metric_logger(),
1407 LogUserHappinessMetric(
1408 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD));
1409 EXPECT_CALL(*autofill_manager_->metric_logger(),
1410 LogUserHappinessMetric(
1411 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE));
1412 PersonalDataManager::GUIDPair guid(
1413 "00000000-0000-0000-0000-000000000001", 0);
1414 PersonalDataManager::GUIDPair empty(std::string(), 0);
1415 autofill_manager_->OnFillAutofillFormData(
1416 0, form, form.fields.front(),
1417 autofill_manager_->PackGUIDs(empty, guid));
1418 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1419 TimeTicks());
1420 // Simulate a second keystroke; make sure we don't log the metric twice.
1421 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1422 TimeTicks());
1423 }
1424
1425 // Simulate invoking autofill again.
1426 EXPECT_CALL(*autofill_manager_->metric_logger(),
1427 LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL));
1428 EXPECT_CALL(*autofill_manager_->metric_logger(),
1429 LogUserHappinessMetric(
1430 AutofillMetrics::USER_DID_AUTOFILL_ONCE)).Times(0);
1431 autofill_manager_->OnDidFillAutofillFormData(TimeTicks());
1432
1433 // Simulate editing another autofilled field.
1434 {
1435 EXPECT_CALL(*autofill_manager_->metric_logger(),
1436 LogUserHappinessMetric(
1437 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD));
1438 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks());
1439 }
1440 }
1441
1442 // Verify that we correctly log metrics tracking the duration of form fill.
1443 TEST_F(AutofillMetricsTest, FormFillDuration) {
1444 // Load a fillable form.
1445 FormData form;
1446 form.name = ASCIIToUTF16("TestForm");
1447 form.method = ASCIIToUTF16("POST");
1448 form.origin = GURL("http://example.com/form.html");
1449 form.action = GURL("http://example.com/submit.html");
1450 form.user_submitted = true;
1451
1452 FormFieldData field;
1453 test::CreateTestFormField("Name", "name", "", "text", &field);
1454 form.fields.push_back(field);
1455 test::CreateTestFormField("Email", "email", "", "text", &field);
1456 form.fields.push_back(field);
1457 test::CreateTestFormField("Phone", "phone", "", "text", &field);
1458 form.fields.push_back(field);
1459
1460 std::vector<FormData> forms(1, form);
1461
1462 // Fill the field values for form submission.
1463 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
1464 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
1465 form.fields[2].value = ASCIIToUTF16("12345678901");
1466
1467 // Expect only form load metrics to be logged if the form is submitted without
1468 // user interaction.
1469 {
1470 EXPECT_CALL(*autofill_manager_->metric_logger(),
1471 LogFormFillDurationFromLoadWithAutofill(_)).Times(0);
1472 EXPECT_CALL(*autofill_manager_->metric_logger(),
1473 LogFormFillDurationFromLoadWithoutAutofill(
1474 TimeDelta::FromInternalValue(16)));
1475 EXPECT_CALL(*autofill_manager_->metric_logger(),
1476 LogFormFillDurationFromInteractionWithAutofill(_)).Times(0);
1477 EXPECT_CALL(*autofill_manager_->metric_logger(),
1478 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0);
1479 autofill_manager_->OnFormsSeen(
1480 forms, TimeTicks::FromInternalValue(1),
1481 autofill::NO_SPECIAL_FORMS_SEEN);
1482 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1483 autofill_manager_->Reset();
1484 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1485 }
1486
1487 // Expect metric to be logged if the user manually edited a form field.
1488 {
1489 EXPECT_CALL(*autofill_manager_->metric_logger(),
1490 LogFormFillDurationFromLoadWithAutofill(_)).Times(0);
1491 EXPECT_CALL(*autofill_manager_->metric_logger(),
1492 LogFormFillDurationFromLoadWithoutAutofill(
1493 TimeDelta::FromInternalValue(16)));
1494 EXPECT_CALL(*autofill_manager_->metric_logger(),
1495 LogFormFillDurationFromInteractionWithAutofill(_)).Times(0);
1496 EXPECT_CALL(*autofill_manager_->metric_logger(),
1497 LogFormFillDurationFromInteractionWithoutAutofill(
1498 TimeDelta::FromInternalValue(14)));
1499 autofill_manager_->OnFormsSeen(
1500 forms, TimeTicks::FromInternalValue(1),
1501 autofill::NO_SPECIAL_FORMS_SEEN);
1502 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1503 TimeTicks::FromInternalValue(3));
1504 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1505 autofill_manager_->Reset();
1506 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1507 }
1508
1509 // Expect metric to be logged if the user autofilled the form.
1510 form.fields[0].is_autofilled = true;
1511 {
1512 EXPECT_CALL(*autofill_manager_->metric_logger(),
1513 LogFormFillDurationFromLoadWithAutofill(
1514 TimeDelta::FromInternalValue(16)));
1515 EXPECT_CALL(*autofill_manager_->metric_logger(),
1516 LogFormFillDurationFromLoadWithoutAutofill(_)).Times(0);
1517 EXPECT_CALL(*autofill_manager_->metric_logger(),
1518 LogFormFillDurationFromInteractionWithAutofill(
1519 TimeDelta::FromInternalValue(12)));
1520 EXPECT_CALL(*autofill_manager_->metric_logger(),
1521 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0);
1522 autofill_manager_->OnFormsSeen(
1523 forms, TimeTicks::FromInternalValue(1),
1524 autofill::NO_SPECIAL_FORMS_SEEN);
1525 autofill_manager_->OnDidFillAutofillFormData(
1526 TimeTicks::FromInternalValue(5));
1527 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1528 autofill_manager_->Reset();
1529 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1530 }
1531
1532 // Expect metric to be logged if the user both manually filled some fields
1533 // and autofilled others. Messages can arrive out of order, so make sure they
1534 // take precedence appropriately.
1535 {
1536 EXPECT_CALL(*autofill_manager_->metric_logger(),
1537 LogFormFillDurationFromLoadWithAutofill(
1538 TimeDelta::FromInternalValue(16)));
1539 EXPECT_CALL(*autofill_manager_->metric_logger(),
1540 LogFormFillDurationFromLoadWithoutAutofill(_)).Times(0);
1541 EXPECT_CALL(*autofill_manager_->metric_logger(),
1542 LogFormFillDurationFromInteractionWithAutofill(
1543 TimeDelta::FromInternalValue(14)));
1544 EXPECT_CALL(*autofill_manager_->metric_logger(),
1545 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0);
1546 autofill_manager_->OnFormsSeen(
1547 forms, TimeTicks::FromInternalValue(1),
1548 autofill::NO_SPECIAL_FORMS_SEEN);
1549 autofill_manager_->OnDidFillAutofillFormData(
1550 TimeTicks::FromInternalValue(5));
1551 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1552 TimeTicks::FromInternalValue(3));
1553 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1554 autofill_manager_->Reset();
1555 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1556 }
1557 }
1558
1559 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/autofill_metrics.cc ('k') | components/autofill/browser/autofill_popup_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698