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

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

Issue 714273003: [Autofill, Clean-up] Clean up the Autofill metrics tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: anonymouse -> anonymous Created 6 years, 1 month 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
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_metrics.h" 5 #include "components/autofill/core/browser/autofill_metrics.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
12 #include "base/run_loop.h" 11 #include "base/run_loop.h"
13 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/test/histogram_tester.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "components/autofill/core/browser/autofill_external_delegate.h" 16 #include "components/autofill/core/browser/autofill_external_delegate.h"
17 #include "components/autofill/core/browser/autofill_manager.h" 17 #include "components/autofill/core/browser/autofill_manager.h"
18 #include "components/autofill/core/browser/autofill_test_utils.h" 18 #include "components/autofill/core/browser/autofill_test_utils.h"
19 #include "components/autofill/core/browser/personal_data_manager.h" 19 #include "components/autofill/core/browser/personal_data_manager.h"
20 #include "components/autofill/core/browser/test_autofill_client.h" 20 #include "components/autofill/core/browser/test_autofill_client.h"
21 #include "components/autofill/core/browser/test_autofill_driver.h" 21 #include "components/autofill/core/browser/test_autofill_driver.h"
22 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 22 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
23 #include "components/autofill/core/common/form_data.h" 23 #include "components/autofill/core/common/form_data.h"
24 #include "components/autofill/core/common/form_field_data.h" 24 #include "components/autofill/core/common/form_field_data.h"
25 #include "components/webdata/common/web_data_results.h" 25 #include "components/webdata/common/web_data_results.h"
26 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gfx/rect.h" 27 #include "ui/gfx/rect.h"
29 #include "url/gurl.h" 28 #include "url/gurl.h"
30 29
31 using base::ASCIIToUTF16; 30 using base::ASCIIToUTF16;
32 using base::TimeDelta;
33 using base::TimeTicks; 31 using base::TimeTicks;
34 using testing::_;
35 using testing::AnyNumber;
36 using testing::Mock;
37 32
38 namespace autofill { 33 namespace autofill {
39
40 namespace { 34 namespace {
41 35
42 class MockAutofillMetrics : public AutofillMetrics {
43 public:
44 MockAutofillMetrics() {}
45 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric));
46 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric,
47 void(DeveloperEngagementMetric metric));
48 MOCK_CONST_METHOD2(LogHeuristicTypePrediction,
49 void(FieldTypeQualityMetric metric,
50 ServerFieldType field_type));
51 MOCK_CONST_METHOD2(LogOverallTypePrediction,
52 void(FieldTypeQualityMetric metric,
53 ServerFieldType field_type));
54 MOCK_CONST_METHOD2(LogServerTypePrediction,
55 void(FieldTypeQualityMetric metric,
56 ServerFieldType field_type));
57 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric));
58 MOCK_CONST_METHOD1(LogUserHappinessMetric, void(UserHappinessMetric metric));
59 MOCK_CONST_METHOD1(LogFormFillDurationFromLoadWithAutofill,
60 void(const TimeDelta& duration));
61 MOCK_CONST_METHOD1(LogFormFillDurationFromLoadWithoutAutofill,
62 void(const TimeDelta& duration));
63 MOCK_CONST_METHOD1(LogFormFillDurationFromInteractionWithAutofill,
64 void(const TimeDelta& duration));
65 MOCK_CONST_METHOD1(LogFormFillDurationFromInteractionWithoutAutofill,
66 void(const TimeDelta& duration));
67 MOCK_CONST_METHOD1(LogIsAutofillEnabledAtPageLoad, void(bool enabled));
68 MOCK_CONST_METHOD1(LogIsAutofillEnabledAtStartup, void(bool enabled));
69 MOCK_CONST_METHOD1(LogStoredProfileCount, void(size_t num_profiles));
70 MOCK_CONST_METHOD1(LogAddressSuggestionsCount, void(size_t num_suggestions));
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics);
74 };
75
76 class TestPersonalDataManager : public PersonalDataManager { 36 class TestPersonalDataManager : public PersonalDataManager {
77 public: 37 public:
78 TestPersonalDataManager() 38 TestPersonalDataManager()
79 : PersonalDataManager("en-US"), 39 : PersonalDataManager("en-US"), autofill_enabled_(true) {
80 autofill_enabled_(true) {
81 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>());
82 CreateTestAutofillProfiles(&web_profiles_); 40 CreateTestAutofillProfiles(&web_profiles_);
83 } 41 }
84 42
85 using PersonalDataManager::set_database; 43 using PersonalDataManager::set_database;
86 using PersonalDataManager::SetPrefService; 44 using PersonalDataManager::SetPrefService;
87 45
88 // Overridden to avoid a trip to the database. This should be a no-op except 46 // Overridden to avoid a trip to the database. This should be a no-op except
89 // for the side-effect of logging the profile count. 47 // for the side-effect of logging the profile count.
90 virtual void LoadProfiles() override { 48 virtual void LoadProfiles() override {
91 std::vector<AutofillProfile*> profiles; 49 std::vector<AutofillProfile*> profiles;
92 web_profiles_.release(&profiles); 50 web_profiles_.release(&profiles);
93 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, 51 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT,
94 profiles); 52 profiles);
95 ReceiveLoadedProfiles(0, &result); 53 ReceiveLoadedProfiles(0, &result);
96 } 54 }
97 55
98 // Overridden to avoid a trip to the database. 56 // Overridden to avoid a trip to the database.
99 virtual void LoadCreditCards() override {} 57 virtual void LoadCreditCards() override {}
100 58
101 const MockAutofillMetrics* metric_logger() const {
102 return static_cast<const MockAutofillMetrics*>(
103 PersonalDataManager::metric_logger());
104 }
105
106 void set_autofill_enabled(bool autofill_enabled) { 59 void set_autofill_enabled(bool autofill_enabled) {
107 autofill_enabled_ = autofill_enabled; 60 autofill_enabled_ = autofill_enabled;
108 } 61 }
109 62
110 virtual bool IsAutofillEnabled() const override { 63 virtual bool IsAutofillEnabled() const override {
111 return autofill_enabled_; 64 return autofill_enabled_;
112 } 65 }
113 66
114 MOCK_METHOD1(SaveImportedCreditCard,
115 std::string(const CreditCard& imported_credit_card));
116
117 private: 67 private:
118 void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) { 68 void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) {
119 AutofillProfile* profile = new AutofillProfile; 69 AutofillProfile* profile = new AutofillProfile;
120 test::SetProfileInfo(profile, "Elvis", "Aaron", 70 test::SetProfileInfo(profile, "Elvis", "Aaron",
121 "Presley", "theking@gmail.com", "RCA", 71 "Presley", "theking@gmail.com", "RCA",
122 "3734 Elvis Presley Blvd.", "Apt. 10", 72 "3734 Elvis Presley Blvd.", "Apt. 10",
123 "Memphis", "Tennessee", "38116", "US", 73 "Memphis", "Tennessee", "38116", "US",
124 "12345678901"); 74 "12345678901");
125 profile->set_guid("00000000-0000-0000-0000-000000000001"); 75 profile->set_guid("00000000-0000-0000-0000-000000000001");
126 profiles->push_back(profile); 76 profiles->push_back(profile);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 private: 111 private:
162 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); 112 DISALLOW_COPY_AND_ASSIGN(TestFormStructure);
163 }; 113 };
164 114
165 class TestAutofillManager : public AutofillManager { 115 class TestAutofillManager : public AutofillManager {
166 public: 116 public:
167 TestAutofillManager(AutofillDriver* driver, 117 TestAutofillManager(AutofillDriver* driver,
168 AutofillClient* autofill_client, 118 AutofillClient* autofill_client,
169 TestPersonalDataManager* personal_manager) 119 TestPersonalDataManager* personal_manager)
170 : AutofillManager(driver, autofill_client, personal_manager), 120 : AutofillManager(driver, autofill_client, personal_manager),
171 autofill_enabled_(true) { 121 autofill_enabled_(true) {}
172 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>);
173 }
174 ~TestAutofillManager() override {} 122 ~TestAutofillManager() override {}
175 123
176 bool IsAutofillEnabled() const override { return autofill_enabled_; } 124 bool IsAutofillEnabled() const override { return autofill_enabled_; }
177 125
178 void set_autofill_enabled(bool autofill_enabled) { 126 void set_autofill_enabled(bool autofill_enabled) {
179 autofill_enabled_ = autofill_enabled; 127 autofill_enabled_ = autofill_enabled;
180 } 128 }
181 129
182 MockAutofillMetrics* metric_logger() {
183 return static_cast<MockAutofillMetrics*>(const_cast<AutofillMetrics*>(
184 AutofillManager::metric_logger()));
185 }
186
187 void AddSeenForm(const FormData& form, 130 void AddSeenForm(const FormData& form,
188 const std::vector<ServerFieldType>& heuristic_types, 131 const std::vector<ServerFieldType>& heuristic_types,
189 const std::vector<ServerFieldType>& server_types) { 132 const std::vector<ServerFieldType>& server_types) {
190 FormData empty_form = form; 133 FormData empty_form = form;
191 for (size_t i = 0; i < empty_form.fields.size(); ++i) { 134 for (size_t i = 0; i < empty_form.fields.size(); ++i) {
192 empty_form.fields[i].value = base::string16(); 135 empty_form.fields[i].value = base::string16();
193 } 136 }
194 137
195 // |form_structure| will be owned by |form_structures()|. 138 // |form_structure| will be owned by |form_structures()|.
196 TestFormStructure* form_structure = new TestFormStructure(empty_form); 139 TestFormStructure* form_structure = new TestFormStructure(empty_form);
(...skipping 25 matching lines...) Expand all
222 165
223 private: 166 private:
224 bool autofill_enabled_; 167 bool autofill_enabled_;
225 scoped_ptr<base::RunLoop> run_loop_; 168 scoped_ptr<base::RunLoop> run_loop_;
226 169
227 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); 170 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
228 }; 171 };
229 172
230 } // namespace 173 } // namespace
231 174
175 // This is defined in the autofill_metrics.cc implementation file.
176 int GetFieldTypeGroupMetric(ServerFieldType field_type,
177 AutofillMetrics::FieldTypeQualityMetric metric);
178
232 class AutofillMetricsTest : public testing::Test { 179 class AutofillMetricsTest : public testing::Test {
233 public: 180 public:
234 ~AutofillMetricsTest() override; 181 ~AutofillMetricsTest() override;
235 182
236 void SetUp() override; 183 void SetUp() override;
237 void TearDown() override; 184 void TearDown() override;
238 185
239 protected: 186 protected:
240 base::MessageLoop message_loop_; 187 base::MessageLoop message_loop_;
241 TestAutofillClient autofill_client_; 188 TestAutofillClient autofill_client_;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 271
325 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field); 272 test::CreateTestFormField("Phone", "phone", "2345678901", "tel", &field);
326 field.is_autofilled = true; 273 field.is_autofilled = true;
327 form.fields.push_back(field); 274 form.fields.push_back(field);
328 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER); 275 heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
329 server_types.push_back(PHONE_HOME_WHOLE_NUMBER); 276 server_types.push_back(PHONE_HOME_WHOLE_NUMBER);
330 277
331 // Simulate having seen this form on page load. 278 // Simulate having seen this form on page load.
332 autofill_manager_->AddSeenForm(form, heuristic_types, server_types); 279 autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
333 280
334 // Establish our expectations. 281 // Simulate form submission.
335 ::testing::InSequence dummy; 282 base::HistogramTester histogram_tester;
336 // Autofilled field 283 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
337 EXPECT_CALL(*autofill_manager_->metric_logger(),
338 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MATCH,
339 NAME_FULL));
340 EXPECT_CALL(*autofill_manager_->metric_logger(),
341 LogServerTypePrediction(AutofillMetrics::TYPE_MISMATCH,
342 NAME_FULL));
343 EXPECT_CALL(*autofill_manager_->metric_logger(),
344 LogOverallTypePrediction(AutofillMetrics::TYPE_MISMATCH,
345 NAME_FULL));
346 // Non-autofilled field for which we had data
347 EXPECT_CALL(*autofill_manager_->metric_logger(),
348 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MISMATCH,
349 EMAIL_ADDRESS));
350 EXPECT_CALL(*autofill_manager_->metric_logger(),
351 LogServerTypePrediction(AutofillMetrics::TYPE_MATCH,
352 EMAIL_ADDRESS));
353 EXPECT_CALL(*autofill_manager_->metric_logger(),
354 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH,
355 EMAIL_ADDRESS));
356 // Empty field
357 // Unknown field
358 // <select> field
359 EXPECT_CALL(*autofill_manager_->metric_logger(),
360 LogHeuristicTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
361 ADDRESS_HOME_COUNTRY));
362 EXPECT_CALL(*autofill_manager_->metric_logger(),
363 LogServerTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
364 ADDRESS_HOME_COUNTRY));
365 EXPECT_CALL(*autofill_manager_->metric_logger(),
366 LogOverallTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
367 ADDRESS_HOME_COUNTRY));
368 // Phone field
369 EXPECT_CALL(*autofill_manager_->metric_logger(),
370 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MATCH,
371 PHONE_HOME_WHOLE_NUMBER));
372 EXPECT_CALL(*autofill_manager_->metric_logger(),
373 LogServerTypePrediction(AutofillMetrics::TYPE_MATCH,
374 PHONE_HOME_WHOLE_NUMBER));
375 EXPECT_CALL(*autofill_manager_->metric_logger(),
376 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH,
377 PHONE_HOME_WHOLE_NUMBER));
378 EXPECT_CALL(*autofill_manager_->metric_logger(),
379 LogUserHappinessMetric(
380 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME));
381 284
382 // Simulate form submission. 285 // Heuristic predictions.
383 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form, 286 // Unknown:
384 TimeTicks::Now())); 287 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
288 AutofillMetrics::TYPE_UNKNOWN, 1);
289 histogram_tester.ExpectBucketCount(
290 "Autofill.Quality.HeuristicType.ByFieldType",
291 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
292 AutofillMetrics::TYPE_UNKNOWN),
293 1);
294 // Match:
295 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
296 AutofillMetrics::TYPE_MATCH, 2);
297 histogram_tester.ExpectBucketCount(
298 "Autofill.Quality.HeuristicType.ByFieldType",
299 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1);
300 histogram_tester.ExpectBucketCount(
301 "Autofill.Quality.HeuristicType.ByFieldType",
302 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER,
303 AutofillMetrics::TYPE_MATCH),
304 1);
305 // Mismatch:
306 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
307 AutofillMetrics::TYPE_MISMATCH, 1);
308 histogram_tester.ExpectBucketCount(
309 "Autofill.Quality.HeuristicType.ByFieldType",
310 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH),
311 1);
312
313 // Server predictions:
314 // Unknown:
315 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
316 AutofillMetrics::TYPE_UNKNOWN, 1);
317 histogram_tester.ExpectBucketCount(
318 "Autofill.Quality.ServerType.ByFieldType",
319 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
320 AutofillMetrics::TYPE_UNKNOWN),
321 1);
322 // Match:
323 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
324 AutofillMetrics::TYPE_MATCH, 2);
325 histogram_tester.ExpectBucketCount(
326 "Autofill.Quality.ServerType.ByFieldType",
327 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MATCH), 1);
328 histogram_tester.ExpectBucketCount(
329 "Autofill.Quality.ServerType.ByFieldType",
330 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER,
331 AutofillMetrics::TYPE_MATCH),
332 1);
333 // Mismatch:
334 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
335 AutofillMetrics::TYPE_MISMATCH, 1);
336 histogram_tester.ExpectBucketCount(
337 "Autofill.Quality.ServerType.ByFieldType",
338 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1);
339
340 // Overall predictions:
341 // Unknown:
342 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
343 AutofillMetrics::TYPE_UNKNOWN, 1);
344 histogram_tester.ExpectBucketCount(
345 "Autofill.Quality.PredictedType.ByFieldType",
346 GetFieldTypeGroupMetric(ADDRESS_HOME_COUNTRY,
347 AutofillMetrics::TYPE_UNKNOWN),
348 1);
349 // Match:
350 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
351 AutofillMetrics::TYPE_MATCH, 2);
352 histogram_tester.ExpectBucketCount(
353 "Autofill.Quality.PredictedType.ByFieldType",
354 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MATCH), 1);
355 histogram_tester.ExpectBucketCount(
356 "Autofill.Quality.PredictedType.ByFieldType",
357 GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER,
358 AutofillMetrics::TYPE_MATCH),
359 1);
360 // Mismatch:
361 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
362 AutofillMetrics::TYPE_MISMATCH, 1);
363 histogram_tester.ExpectBucketCount(
364 "Autofill.Quality.PredictedType.ByFieldType",
365 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MISMATCH), 1);
385 } 366 }
386 367
387 // Test that we behave sanely when the cached form differs from the submitted 368 // Test that we behave sanely when the cached form differs from the submitted
388 // one. 369 // one.
389 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) { 370 TEST_F(AutofillMetricsTest, SaneMetricsWithCacheMismatch) {
390 // Set up our form data. 371 // Set up our form data.
391 FormData form; 372 FormData form;
392 form.name = ASCIIToUTF16("TestForm"); 373 form.name = ASCIIToUTF16("TestForm");
393 form.origin = GURL("http://example.com/form.html"); 374 form.origin = GURL("http://example.com/form.html");
394 form.action = GURL("http://example.com/submit.html"); 375 form.action = GURL("http://example.com/submit.html");
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 std::vector<FormFieldData> cached_fields = form.fields; 411 std::vector<FormFieldData> cached_fields = form.fields;
431 form.fields.clear(); 412 form.fields.clear();
432 test::CreateTestFormField( 413 test::CreateTestFormField(
433 "New field", "new field", "Tennessee", "text", &field); 414 "New field", "new field", "Tennessee", "text", &field);
434 form.fields.push_back(field); 415 form.fields.push_back(field);
435 form.fields.push_back(cached_fields[2]); 416 form.fields.push_back(cached_fields[2]);
436 form.fields.push_back(cached_fields[1]); 417 form.fields.push_back(cached_fields[1]);
437 form.fields.push_back(cached_fields[3]); 418 form.fields.push_back(cached_fields[3]);
438 form.fields.push_back(cached_fields[0]); 419 form.fields.push_back(cached_fields[0]);
439 420
440 // Establish our expectations. 421 // Simulate form submission.
441 ::testing::InSequence dummy; 422 base::HistogramTester histogram_tester;
442 // New field 423 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
443 EXPECT_CALL(*autofill_manager_->metric_logger(),
444 LogHeuristicTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
445 ADDRESS_HOME_STATE));
446 EXPECT_CALL(*autofill_manager_->metric_logger(),
447 LogServerTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
448 ADDRESS_HOME_STATE));
449 EXPECT_CALL(*autofill_manager_->metric_logger(),
450 LogOverallTypePrediction(AutofillMetrics::TYPE_UNKNOWN,
451 ADDRESS_HOME_STATE));
452 // Only heuristics match
453 EXPECT_CALL(*autofill_manager_->metric_logger(),
454 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MATCH,
455 ADDRESS_HOME_CITY));
456 EXPECT_CALL(*autofill_manager_->metric_logger(),
457 LogServerTypePrediction(AutofillMetrics::TYPE_MISMATCH,
458 ADDRESS_HOME_CITY));
459 EXPECT_CALL(*autofill_manager_->metric_logger(),
460 LogOverallTypePrediction(AutofillMetrics::TYPE_MISMATCH,
461 ADDRESS_HOME_CITY));
462 // Both mismatch
463 EXPECT_CALL(*autofill_manager_->metric_logger(),
464 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MISMATCH,
465 EMAIL_ADDRESS));
466 EXPECT_CALL(*autofill_manager_->metric_logger(),
467 LogServerTypePrediction(AutofillMetrics::TYPE_MISMATCH,
468 EMAIL_ADDRESS));
469 EXPECT_CALL(*autofill_manager_->metric_logger(),
470 LogOverallTypePrediction(AutofillMetrics::TYPE_MISMATCH,
471 EMAIL_ADDRESS));
472 // Unknown
473 // Both match
474 EXPECT_CALL(*autofill_manager_->metric_logger(),
475 LogHeuristicTypePrediction(AutofillMetrics::TYPE_MATCH,
476 NAME_FULL));
477 EXPECT_CALL(*autofill_manager_->metric_logger(),
478 LogServerTypePrediction(AutofillMetrics::TYPE_MATCH,
479 NAME_FULL));
480 EXPECT_CALL(*autofill_manager_->metric_logger(),
481 LogOverallTypePrediction(AutofillMetrics::TYPE_MATCH,
482 NAME_FULL));
483 424
484 // Simulate form submission. 425 // Heuristic predictions.
485 EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form, 426 // Unknown:
486 TimeTicks::Now())); 427 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
428 AutofillMetrics::TYPE_UNKNOWN, 1);
429 histogram_tester.ExpectBucketCount(
430 "Autofill.Quality.HeuristicType.ByFieldType",
431 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE,
432 AutofillMetrics::TYPE_UNKNOWN),
433 1);
434 // Match:
435 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
436 AutofillMetrics::TYPE_MATCH, 2);
437 histogram_tester.ExpectBucketCount(
438 "Autofill.Quality.HeuristicType.ByFieldType",
439 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY, AutofillMetrics::TYPE_MATCH),
440 1);
441 histogram_tester.ExpectBucketCount(
442 "Autofill.Quality.HeuristicType.ByFieldType",
443 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1);
444 // Mismatch:
445 histogram_tester.ExpectBucketCount("Autofill.Quality.HeuristicType",
446 AutofillMetrics::TYPE_MISMATCH, 1);
447 histogram_tester.ExpectBucketCount(
448 "Autofill.Quality.HeuristicType.ByFieldType",
449 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH),
450 1);
451
452 // Server predictions:
453 // Unknown:
454 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
455 AutofillMetrics::TYPE_UNKNOWN, 1);
456 histogram_tester.ExpectBucketCount(
457 "Autofill.Quality.ServerType.ByFieldType",
458 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE,
459 AutofillMetrics::TYPE_UNKNOWN),
460 1);
461 // Match:
462 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
463 AutofillMetrics::TYPE_MATCH, 1);
464 histogram_tester.ExpectBucketCount(
465 "Autofill.Quality.ServerType.ByFieldType",
466 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1);
467 // Mismatch:
468 histogram_tester.ExpectBucketCount("Autofill.Quality.ServerType",
469 AutofillMetrics::TYPE_MISMATCH, 2);
470 histogram_tester.ExpectBucketCount(
471 "Autofill.Quality.ServerType.ByFieldType",
472 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY,
473 AutofillMetrics::TYPE_MISMATCH),
474 1);
475 histogram_tester.ExpectBucketCount(
476 "Autofill.Quality.ServerType.ByFieldType",
477 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH),
478 1);
479
480 // Overall predictions:
481 // Unknown:
482 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
483 AutofillMetrics::TYPE_UNKNOWN, 1);
484 histogram_tester.ExpectBucketCount(
485 "Autofill.Quality.PredictedType.ByFieldType",
486 GetFieldTypeGroupMetric(ADDRESS_HOME_STATE,
487 AutofillMetrics::TYPE_UNKNOWN),
488 1);
489 // Match:
490 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
491 AutofillMetrics::TYPE_MATCH, 1);
492 histogram_tester.ExpectBucketCount(
493 "Autofill.Quality.PredictedType.ByFieldType",
494 GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1);
495 // Mismatch:
496 histogram_tester.ExpectBucketCount("Autofill.Quality.PredictedType",
497 AutofillMetrics::TYPE_MISMATCH, 2);
498 histogram_tester.ExpectBucketCount(
499 "Autofill.Quality.PredictedType.ByFieldType",
500 GetFieldTypeGroupMetric(ADDRESS_HOME_CITY,
501 AutofillMetrics::TYPE_MISMATCH),
502 1);
503 histogram_tester.ExpectBucketCount(
504 "Autofill.Quality.PredictedType.ByFieldType",
505 GetFieldTypeGroupMetric(EMAIL_ADDRESS, AutofillMetrics::TYPE_MISMATCH),
506 1);
487 } 507 }
488 508
489 // Verify that we correctly log metrics regarding developer engagement. 509 // Verify that we correctly log metrics regarding developer engagement.
490 TEST_F(AutofillMetricsTest, DeveloperEngagement) { 510 TEST_F(AutofillMetricsTest, DeveloperEngagement) {
491 // Start with a non-fillable form. 511 // Start with a non-fillable form.
492 FormData form; 512 FormData form;
493 form.name = ASCIIToUTF16("TestForm"); 513 form.name = ASCIIToUTF16("TestForm");
494 form.origin = GURL("http://example.com/form.html"); 514 form.origin = GURL("http://example.com/form.html");
495 form.action = GURL("http://example.com/submit.html"); 515 form.action = GURL("http://example.com/submit.html");
496 516
497 FormFieldData field; 517 FormFieldData field;
498 test::CreateTestFormField("Name", "name", "", "text", &field); 518 test::CreateTestFormField("Name", "name", "", "text", &field);
499 form.fields.push_back(field); 519 form.fields.push_back(field);
500 test::CreateTestFormField("Email", "email", "", "text", &field); 520 test::CreateTestFormField("Email", "email", "", "text", &field);
501 form.fields.push_back(field); 521 form.fields.push_back(field);
502 522
503 std::vector<FormData> forms(1, form); 523 std::vector<FormData> forms(1, form);
504 524
505 // Ensure no metrics are logged when loading a non-fillable form. 525 // Ensure no metrics are logged when loading a non-fillable form.
506 { 526 {
507 EXPECT_CALL(*autofill_manager_->metric_logger(), 527 base::HistogramTester histogram_tester;
508 LogDeveloperEngagementMetric(_)).Times(0);
509 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 528 autofill_manager_->OnFormsSeen(forms, TimeTicks());
510 autofill_manager_->Reset(); 529 autofill_manager_->Reset();
511 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 530 histogram_tester.ExpectTotalCount("Autofill.DeveloperEngagement", 0);
512 } 531 }
513 532
514 // Add another field to the form, so that it becomes fillable. 533 // Add another field to the form, so that it becomes fillable.
515 test::CreateTestFormField("Phone", "phone", "", "text", &field); 534 test::CreateTestFormField("Phone", "phone", "", "text", &field);
516 forms.back().fields.push_back(field); 535 forms.back().fields.push_back(field);
517 536
518 // Expect only the "form parsed" metric to be logged; no metrics about 537 // Expect only the "form parsed" metric to be logged; no metrics about
519 // author-specified field type hints. 538 // author-specified field type hints.
520 { 539 {
521 EXPECT_CALL( 540 base::HistogramTester histogram_tester;
522 *autofill_manager_->metric_logger(),
523 LogDeveloperEngagementMetric(
524 AutofillMetrics::FILLABLE_FORM_PARSED)).Times(1);
525 EXPECT_CALL(
526 *autofill_manager_->metric_logger(),
527 LogDeveloperEngagementMetric(
528 AutofillMetrics::FILLABLE_FORM_CONTAINS_TYPE_HINTS)).Times(0);
529 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 541 autofill_manager_->OnFormsSeen(forms, TimeTicks());
530 autofill_manager_->Reset(); 542 autofill_manager_->Reset();
531 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 543 histogram_tester.ExpectUniqueSample("Autofill.DeveloperEngagement",
544 AutofillMetrics::FILLABLE_FORM_PARSED,
545 1);
532 } 546 }
533 547
534 // Add some fields with an author-specified field type to the form. 548 // Add some fields with an author-specified field type to the form.
535 // We need to add at least three fields, because a form must have at least 549 // We need to add at least three fields, because a form must have at least
536 // three fillable fields to be considered to be autofillable; and if at least 550 // three fillable fields to be considered to be autofillable; and if at least
537 // one field specifies an explicit type hint, we don't apply any of our usual 551 // one field specifies an explicit type hint, we don't apply any of our usual
538 // local heuristics to detect field types in the rest of the form. 552 // local heuristics to detect field types in the rest of the form.
539 test::CreateTestFormField("", "", "", "text", &field); 553 test::CreateTestFormField("", "", "", "text", &field);
540 field.autocomplete_attribute = "given-name"; 554 field.autocomplete_attribute = "given-name";
541 forms.back().fields.push_back(field); 555 forms.back().fields.push_back(field);
542 test::CreateTestFormField("", "", "", "text", &field); 556 test::CreateTestFormField("", "", "", "text", &field);
543 field.autocomplete_attribute = "email"; 557 field.autocomplete_attribute = "email";
544 forms.back().fields.push_back(field); 558 forms.back().fields.push_back(field);
545 test::CreateTestFormField("", "", "", "text", &field); 559 test::CreateTestFormField("", "", "", "text", &field);
546 field.autocomplete_attribute = "address-line1"; 560 field.autocomplete_attribute = "address-line1";
547 forms.back().fields.push_back(field); 561 forms.back().fields.push_back(field);
548 562
549 // Expect both the "form parsed" metric and the author-specified field type 563 // Expect both the "form parsed" metric and the author-specified field type
550 // hints metric to be logged. 564 // hints metric to be logged.
551 { 565 {
552 EXPECT_CALL( 566 base::HistogramTester histogram_tester;
553 *autofill_manager_->metric_logger(),
554 LogDeveloperEngagementMetric(
555 AutofillMetrics::FILLABLE_FORM_PARSED)).Times(1);
556 EXPECT_CALL(
557 *autofill_manager_->metric_logger(),
558 LogDeveloperEngagementMetric(
559 AutofillMetrics::FILLABLE_FORM_CONTAINS_TYPE_HINTS)).Times(1);
560 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 567 autofill_manager_->OnFormsSeen(forms, TimeTicks());
561 autofill_manager_->Reset(); 568 autofill_manager_->Reset();
562 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 569 histogram_tester.ExpectBucketCount("Autofill.DeveloperEngagement",
570 AutofillMetrics::FILLABLE_FORM_PARSED,
571 1);
572 histogram_tester.ExpectBucketCount(
573 "Autofill.DeveloperEngagement",
574 AutofillMetrics::FILLABLE_FORM_CONTAINS_TYPE_HINTS, 1);
563 } 575 }
564 } 576 }
565 577
566 // Test that the profile count is logged correctly. 578 // Test that the profile count is logged correctly.
567 TEST_F(AutofillMetricsTest, StoredProfileCount) { 579 TEST_F(AutofillMetricsTest, StoredProfileCount) {
568 // The metric should be logged when the profiles are first loaded. 580 // The metric should be logged when the profiles are first loaded.
569 EXPECT_CALL(*personal_data_->metric_logger(), 581 {
570 LogStoredProfileCount(2)).Times(1); 582 base::HistogramTester histogram_tester;
571 personal_data_->LoadProfiles(); 583 personal_data_->LoadProfiles();
584 histogram_tester.ExpectUniqueSample("Autofill.StoredProfileCount", 2, 1);
585 }
572 586
573 // The metric should only be logged once. 587 // The metric should only be logged once.
574 EXPECT_CALL(*personal_data_->metric_logger(), 588 {
575 LogStoredProfileCount(::testing::_)).Times(0); 589 base::HistogramTester histogram_tester;
576 personal_data_->LoadProfiles(); 590 personal_data_->LoadProfiles();
591 histogram_tester.ExpectTotalCount("Autofill.StoredProfileCount", 0);
592 }
577 } 593 }
578 594
579 // Test that we correctly log when Autofill is enabled. 595 // Test that we correctly log when Autofill is enabled.
580 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) { 596 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtStartup) {
597 base::HistogramTester histogram_tester;
581 personal_data_->set_autofill_enabled(true); 598 personal_data_->set_autofill_enabled(true);
582 EXPECT_CALL(*personal_data_->metric_logger(),
583 LogIsAutofillEnabledAtStartup(true)).Times(1);
584 personal_data_->Init( 599 personal_data_->Init(
585 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), false); 600 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), false);
601 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.Startup", true, 1);
586 } 602 }
587 603
588 // Test that we correctly log when Autofill is disabled. 604 // Test that we correctly log when Autofill is disabled.
589 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) { 605 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtStartup) {
606 base::HistogramTester histogram_tester;
590 personal_data_->set_autofill_enabled(false); 607 personal_data_->set_autofill_enabled(false);
591 EXPECT_CALL(*personal_data_->metric_logger(),
592 LogIsAutofillEnabledAtStartup(false)).Times(1);
593 personal_data_->Init( 608 personal_data_->Init(
594 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), false); 609 autofill_client_.GetDatabase(), autofill_client_.GetPrefs(), false);
610 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.Startup", false, 1);
595 } 611 }
596 612
597 // Test that we log the number of Autofill suggestions when filling a form. 613 // Test that we log the number of Autofill suggestions when filling a form.
598 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) { 614 TEST_F(AutofillMetricsTest, AddressSuggestionsCount) {
599 // Set up our form data. 615 // Set up our form data.
600 FormData form; 616 FormData form;
601 form.name = ASCIIToUTF16("TestForm"); 617 form.name = ASCIIToUTF16("TestForm");
602 form.origin = GURL("http://example.com/form.html"); 618 form.origin = GURL("http://example.com/form.html");
603 form.action = GURL("http://example.com/submit.html"); 619 form.action = GURL("http://example.com/submit.html");
604 form.user_submitted = true; 620 form.user_submitted = true;
605 621
606 FormFieldData field; 622 FormFieldData field;
607 std::vector<ServerFieldType> field_types; 623 std::vector<ServerFieldType> field_types;
608 test::CreateTestFormField("Name", "name", "", "text", &field); 624 test::CreateTestFormField("Name", "name", "", "text", &field);
609 form.fields.push_back(field); 625 form.fields.push_back(field);
610 field_types.push_back(NAME_FULL); 626 field_types.push_back(NAME_FULL);
611 test::CreateTestFormField("Email", "email", "", "email", &field); 627 test::CreateTestFormField("Email", "email", "", "email", &field);
612 form.fields.push_back(field); 628 form.fields.push_back(field);
613 field_types.push_back(EMAIL_ADDRESS); 629 field_types.push_back(EMAIL_ADDRESS);
614 test::CreateTestFormField("Phone", "phone", "", "tel", &field); 630 test::CreateTestFormField("Phone", "phone", "", "tel", &field);
615 form.fields.push_back(field); 631 form.fields.push_back(field);
616 field_types.push_back(PHONE_HOME_NUMBER); 632 field_types.push_back(PHONE_HOME_NUMBER);
617 633
618 // Simulate having seen this form on page load. 634 // Simulate having seen this form on page load.
619 // |form_structure| will be owned by |autofill_manager_|. 635 // |form_structure| will be owned by |autofill_manager_|.
620 autofill_manager_->AddSeenForm(form, field_types, field_types); 636 autofill_manager_->AddSeenForm(form, field_types, field_types);
621 637
622 // Establish our expectations. 638 {
623 ::testing::InSequence dummy; 639 // Simulate activating the autofill popup for the phone field.
624 EXPECT_CALL(*autofill_manager_->metric_logger(), 640 base::HistogramTester histogram_tester;
625 LogAddressSuggestionsCount(2)).Times(1); 641 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
642 false);
643 histogram_tester.ExpectUniqueSample("Autofill.AddressSuggestionsCount", 2,
644 1);
645 }
626 646
627 // Simulate activating the autofill popup for the phone field. 647 {
628 autofill_manager_->OnQueryFormFieldAutofill( 648 // Simulate activating the autofill popup for the email field after typing.
629 0, form, field, gfx::Rect(), false); 649 // No new metric should be logged, since we're still on the same page.
630 650 test::CreateTestFormField("Email", "email", "b", "email", &field);
631 // Simulate activating the autofill popup for the email field after typing. 651 base::HistogramTester histogram_tester;
632 // No new metric should be logged, since we're still on the same page. 652 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
633 test::CreateTestFormField("Email", "email", "b", "email", &field); 653 false);
634 autofill_manager_->OnQueryFormFieldAutofill( 654 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0);
635 0, form, field, gfx::Rect(), false); 655 }
636 656
637 // Reset the autofill manager state. 657 // Reset the autofill manager state.
638 autofill_manager_->Reset(); 658 autofill_manager_->Reset();
639 autofill_manager_->AddSeenForm(form, field_types, field_types); 659 autofill_manager_->AddSeenForm(form, field_types, field_types);
640 660
641 // Establish our expectations. 661 {
642 EXPECT_CALL(*autofill_manager_->metric_logger(), 662 // Simulate activating the autofill popup for the email field after typing.
643 LogAddressSuggestionsCount(1)).Times(1); 663 base::HistogramTester histogram_tester;
644 664 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
645 // Simulate activating the autofill popup for the email field after typing. 665 false);
646 autofill_manager_->OnQueryFormFieldAutofill( 666 histogram_tester.ExpectUniqueSample("Autofill.AddressSuggestionsCount", 1,
647 0, form, field, gfx::Rect(), false); 667 1);
668 }
648 669
649 // Reset the autofill manager state again. 670 // Reset the autofill manager state again.
650 autofill_manager_->Reset(); 671 autofill_manager_->Reset();
651 autofill_manager_->AddSeenForm(form, field_types, field_types); 672 autofill_manager_->AddSeenForm(form, field_types, field_types);
652 673
653 // Establish our expectations. 674 {
654 EXPECT_CALL(*autofill_manager_->metric_logger(), 675 // Simulate activating the autofill popup for the email field after typing.
655 LogAddressSuggestionsCount(::testing::_)).Times(0); 676 form.fields[0].is_autofilled = true;
656 677 base::HistogramTester histogram_tester;
657 // Simulate activating the autofill popup for the email field after typing. 678 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect(),
658 form.fields[0].is_autofilled = true; 679 false);
659 autofill_manager_->OnQueryFormFieldAutofill( 680 histogram_tester.ExpectTotalCount("Autofill.AddressSuggestionsCount", 0);
660 0, form, field, gfx::Rect(), false); 681 }
661 } 682 }
662 683
663 // Test that we log whether Autofill is enabled when filling a form. 684 // Test that we log that Autofill is enabled when filling a form.
664 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) { 685 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) {
665 // Establish our expectations. 686 base::HistogramTester histogram_tester;
666 ::testing::InSequence dummy;
667 EXPECT_CALL(*autofill_manager_->metric_logger(),
668 LogIsAutofillEnabledAtPageLoad(true)).Times(1);
669
670 autofill_manager_->set_autofill_enabled(true); 687 autofill_manager_->set_autofill_enabled(true);
671 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); 688 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks());
689 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", true, 1);
690 }
672 691
673 // Reset the autofill manager state. 692 // Test that we log that Autofill is disabled when filling a form.
674 autofill_manager_->Reset(); 693 TEST_F(AutofillMetricsTest, AutofillIsDisabledAtPageLoad) {
675 694 base::HistogramTester histogram_tester;
676 // Establish our expectations.
677 EXPECT_CALL(*autofill_manager_->metric_logger(),
678 LogIsAutofillEnabledAtPageLoad(false)).Times(1);
679
680 autofill_manager_->set_autofill_enabled(false); 695 autofill_manager_->set_autofill_enabled(false);
681 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); 696 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks());
697 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", false, 1);
682 } 698 }
683 699
684 // Verify that we correctly log user happiness metrics dealing with form loading 700 // Verify that we correctly log user happiness metrics dealing with form loading
685 // and form submission. 701 // and form submission.
686 TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) { 702 TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
687 // Start with a form with insufficiently many fields. 703 // Start with a form with insufficiently many fields.
688 FormData form; 704 FormData form;
689 form.name = ASCIIToUTF16("TestForm"); 705 form.name = ASCIIToUTF16("TestForm");
690 form.origin = GURL("http://example.com/form.html"); 706 form.origin = GURL("http://example.com/form.html");
691 form.action = GURL("http://example.com/submit.html"); 707 form.action = GURL("http://example.com/submit.html");
692 form.user_submitted = true; 708 form.user_submitted = true;
693 709
694 FormFieldData field; 710 FormFieldData field;
695 test::CreateTestFormField("Name", "name", "", "text", &field); 711 test::CreateTestFormField("Name", "name", "", "text", &field);
696 form.fields.push_back(field); 712 form.fields.push_back(field);
697 test::CreateTestFormField("Email", "email", "", "text", &field); 713 test::CreateTestFormField("Email", "email", "", "text", &field);
698 form.fields.push_back(field); 714 form.fields.push_back(field);
699 715
700 std::vector<FormData> forms(1, form); 716 std::vector<FormData> forms(1, form);
701 717
702 // Expect no notifications when the form is first seen. 718 // Expect no notifications when the form is first seen.
703 { 719 {
704 EXPECT_CALL(*autofill_manager_->metric_logger(), 720 base::HistogramTester histogram_tester;
705 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED)).Times(0);
706 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 721 autofill_manager_->OnFormsSeen(forms, TimeTicks());
722 histogram_tester.ExpectTotalCount("Autofill.UserHappiness", 0);
707 } 723 }
708 724
709 725
710 // Expect no notifications when the form is submitted. 726 // Expect no notifications when the form is submitted.
711 { 727 {
712 EXPECT_CALL( 728 base::HistogramTester histogram_tester;
713 *autofill_manager_->metric_logger(),
714 LogUserHappinessMetric(
715 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL)).Times(0);
716 EXPECT_CALL(
717 *autofill_manager_->metric_logger(),
718 LogUserHappinessMetric(
719 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)).Times(0);
720 EXPECT_CALL(
721 *autofill_manager_->metric_logger(),
722 LogUserHappinessMetric(
723 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE)).Times(0);
724 EXPECT_CALL(
725 *autofill_manager_->metric_logger(),
726 LogUserHappinessMetric(
727 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)).Times(0);
728 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 729 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
730 histogram_tester.ExpectTotalCount("Autofill.UserHappiness", 0);
729 } 731 }
730 732
731 // Add more fields to the form. 733 // Add more fields to the form.
732 test::CreateTestFormField("Phone", "phone", "", "text", &field); 734 test::CreateTestFormField("Phone", "phone", "", "text", &field);
733 form.fields.push_back(field); 735 form.fields.push_back(field);
734 test::CreateTestFormField("Unknown", "unknown", "", "text", &field); 736 test::CreateTestFormField("Unknown", "unknown", "", "text", &field);
735 form.fields.push_back(field); 737 form.fields.push_back(field);
736 forms.front() = form; 738 forms.front() = form;
737 739
738 // Expect a notification when the form is first seen. 740 // Expect a notification when the form is first seen.
739 { 741 {
740 EXPECT_CALL(*autofill_manager_->metric_logger(), 742 base::HistogramTester histogram_tester;
741 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED));
742 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 743 autofill_manager_->OnFormsSeen(forms, TimeTicks());
744 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness",
745 AutofillMetrics::FORMS_LOADED, 1);
743 } 746 }
744 747
745 // Expect a notification when the form is submitted. 748 // Expect a notification when the form is submitted.
746 { 749 {
747 EXPECT_CALL(*autofill_manager_->metric_logger(), 750 base::HistogramTester histogram_tester;
748 LogUserHappinessMetric(
749 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
750 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 751 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
752 histogram_tester.ExpectUniqueSample(
753 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM,
754 1);
751 } 755 }
752 756
753 // Fill in two of the fields. 757 // Fill in two of the fields.
754 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); 758 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
755 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); 759 form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
756 forms.front() = form; 760 forms.front() = form;
757 761
758 // Expect a notification when the form is submitted. 762 // Expect a notification when the form is submitted.
759 { 763 {
760 EXPECT_CALL(*autofill_manager_->metric_logger(), 764 base::HistogramTester histogram_tester;
761 LogUserHappinessMetric(
762 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
763 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 765 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
766 histogram_tester.ExpectUniqueSample(
767 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM,
768 1);
764 } 769 }
765 770
766 // Fill in the third field. 771 // Fill in the third field.
767 form.fields[2].value = ASCIIToUTF16("12345678901"); 772 form.fields[2].value = ASCIIToUTF16("12345678901");
768 forms.front() = form; 773 forms.front() = form;
769 774
770 // Expect notifications when the form is submitted. 775 // Expect notifications when the form is submitted.
771 { 776 {
772 EXPECT_CALL(*autofill_manager_->metric_logger(), 777 base::HistogramTester histogram_tester;
773 LogUserHappinessMetric(
774 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE));
775 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 778 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
779 histogram_tester.ExpectUniqueSample(
780 "Autofill.UserHappiness",
781 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE, 1);
776 } 782 }
777 783
778 784
779 // Mark one of the fields as autofilled. 785 // Mark one of the fields as autofilled.
780 form.fields[1].is_autofilled = true; 786 form.fields[1].is_autofilled = true;
781 forms.front() = form; 787 forms.front() = form;
782 788
783 // Expect notifications when the form is submitted. 789 // Expect notifications when the form is submitted.
784 { 790 {
785 EXPECT_CALL(*autofill_manager_->metric_logger(), 791 base::HistogramTester histogram_tester;
786 LogUserHappinessMetric(
787 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME));
788 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 792 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
793 histogram_tester.ExpectUniqueSample(
794 "Autofill.UserHappiness",
795 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME, 1);
789 } 796 }
790 797
791 // Mark all of the fillable fields as autofilled. 798 // Mark all of the fillable fields as autofilled.
792 form.fields[0].is_autofilled = true; 799 form.fields[0].is_autofilled = true;
793 form.fields[2].is_autofilled = true; 800 form.fields[2].is_autofilled = true;
794 forms.front() = form; 801 forms.front() = form;
795 802
796 // Expect notifications when the form is submitted. 803 // Expect notifications when the form is submitted.
797 { 804 {
798 EXPECT_CALL(*autofill_manager_->metric_logger(), 805 base::HistogramTester histogram_tester;
799 LogUserHappinessMetric(
800 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL));
801 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 806 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
807 histogram_tester.ExpectUniqueSample(
808 "Autofill.UserHappiness",
809 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL, 1);
802 } 810 }
803 811
804 // Clear out the third field's value. 812 // Clear out the third field's value.
805 form.fields[2].value = base::string16(); 813 form.fields[2].value = base::string16();
806 forms.front() = form; 814 forms.front() = form;
807 815
808 // Expect notifications when the form is submitted. 816 // Expect notifications when the form is submitted.
809 { 817 {
810 EXPECT_CALL(*autofill_manager_->metric_logger(), 818 base::HistogramTester histogram_tester;
811 LogUserHappinessMetric(
812 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM));
813 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 819 autofill_manager_->FormSubmitted(form, TimeTicks::Now());
820 histogram_tester.ExpectUniqueSample(
821 "Autofill.UserHappiness", AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM,
822 1);
814 } 823 }
815 } 824 }
816 825
817 // Verify that we correctly log user happiness metrics dealing with form 826 // Verify that we correctly log user happiness metrics dealing with form
818 // interaction. 827 // interaction.
819 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { 828 TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) {
820 // Load a fillable form. 829 // Load a fillable form.
821 FormData form; 830 FormData form;
822 form.name = ASCIIToUTF16("TestForm"); 831 form.name = ASCIIToUTF16("TestForm");
823 form.origin = GURL("http://example.com/form.html"); 832 form.origin = GURL("http://example.com/form.html");
824 form.action = GURL("http://example.com/submit.html"); 833 form.action = GURL("http://example.com/submit.html");
825 form.user_submitted = true; 834 form.user_submitted = true;
826 835
827 FormFieldData field; 836 FormFieldData field;
828 test::CreateTestFormField("Name", "name", "", "text", &field); 837 test::CreateTestFormField("Name", "name", "", "text", &field);
829 form.fields.push_back(field); 838 form.fields.push_back(field);
830 test::CreateTestFormField("Email", "email", "", "text", &field); 839 test::CreateTestFormField("Email", "email", "", "text", &field);
831 form.fields.push_back(field); 840 form.fields.push_back(field);
832 test::CreateTestFormField("Phone", "phone", "", "text", &field); 841 test::CreateTestFormField("Phone", "phone", "", "text", &field);
833 form.fields.push_back(field); 842 form.fields.push_back(field);
834 843
835 std::vector<FormData> forms(1, form); 844 std::vector<FormData> forms(1, form);
836 845
837 // Expect a notification when the form is first seen. 846 // Expect a notification when the form is first seen.
838 { 847 {
839 EXPECT_CALL(*autofill_manager_->metric_logger(), 848 base::HistogramTester histogram_tester;
840 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED));
841 autofill_manager_->OnFormsSeen(forms, TimeTicks()); 849 autofill_manager_->OnFormsSeen(forms, TimeTicks());
850 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness",
851 AutofillMetrics::FORMS_LOADED, 1);
842 } 852 }
843 853
844 // Simulate typing. 854 // Simulate typing.
845 { 855 {
846 EXPECT_CALL(*autofill_manager_->metric_logger(), 856 base::HistogramTester histogram_tester;
847 LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE));
848 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 857 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
849 TimeTicks()); 858 TimeTicks());
859 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness",
860 AutofillMetrics::USER_DID_TYPE, 1);
850 } 861 }
851 862
852 // Simulate suggestions shown twice for a single edit (i.e. multiple 863 // Simulate suggestions shown twice for a single edit (i.e. multiple
853 // keystrokes in a single field). 864 // keystrokes in a single field).
854 { 865 {
855 EXPECT_CALL(*autofill_manager_->metric_logger(), 866 base::HistogramTester histogram_tester;
856 LogUserHappinessMetric(
857 AutofillMetrics::SUGGESTIONS_SHOWN)).Times(1);
858 EXPECT_CALL(*autofill_manager_->metric_logger(),
859 LogUserHappinessMetric(
860 AutofillMetrics::SUGGESTIONS_SHOWN_ONCE)).Times(1);
861 autofill_manager_->DidShowSuggestions(true); 867 autofill_manager_->DidShowSuggestions(true);
862 autofill_manager_->DidShowSuggestions(false); 868 autofill_manager_->DidShowSuggestions(false);
869 histogram_tester.ExpectBucketCount("Autofill.UserHappiness",
870 AutofillMetrics::SUGGESTIONS_SHOWN, 1);
871 histogram_tester.ExpectBucketCount(
872 "Autofill.UserHappiness", AutofillMetrics::SUGGESTIONS_SHOWN_ONCE, 1);
863 } 873 }
864 874
865 // Simulate suggestions shown for a different field. 875 // Simulate suggestions shown for a different field.
866 { 876 {
867 EXPECT_CALL(*autofill_manager_->metric_logger(), 877 base::HistogramTester histogram_tester;
868 LogUserHappinessMetric(AutofillMetrics::SUGGESTIONS_SHOWN));
869 EXPECT_CALL(*autofill_manager_->metric_logger(),
870 LogUserHappinessMetric(
871 AutofillMetrics::SUGGESTIONS_SHOWN_ONCE)).Times(0);
872 autofill_manager_->DidShowSuggestions(true); 878 autofill_manager_->DidShowSuggestions(true);
879 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness",
880 AutofillMetrics::SUGGESTIONS_SHOWN, 1);
873 } 881 }
874 882
875 // Simulate invoking autofill. 883 // Simulate invoking autofill.
876 { 884 {
877 EXPECT_CALL(*autofill_manager_->metric_logger(), 885 base::HistogramTester histogram_tester;
878 LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL));
879 EXPECT_CALL(*autofill_manager_->metric_logger(),
880 LogUserHappinessMetric(
881 AutofillMetrics::USER_DID_AUTOFILL_ONCE));
882 autofill_manager_->OnDidFillAutofillFormData(TimeTicks()); 886 autofill_manager_->OnDidFillAutofillFormData(TimeTicks());
887 histogram_tester.ExpectBucketCount("Autofill.UserHappiness",
888 AutofillMetrics::USER_DID_AUTOFILL, 1);
889 histogram_tester.ExpectBucketCount(
890 "Autofill.UserHappiness", AutofillMetrics::USER_DID_AUTOFILL_ONCE, 1);
883 } 891 }
884 892
885 // Simulate editing an autofilled field. 893 // Simulate editing an autofilled field.
886 { 894 {
887 EXPECT_CALL(*autofill_manager_->metric_logger(), 895 base::HistogramTester histogram_tester;
888 LogUserHappinessMetric(
889 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD));
890 EXPECT_CALL(*autofill_manager_->metric_logger(),
891 LogUserHappinessMetric(
892 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE));
893 PersonalDataManager::GUIDPair guid( 896 PersonalDataManager::GUIDPair guid(
894 "00000000-0000-0000-0000-000000000001", 0); 897 "00000000-0000-0000-0000-000000000001", 0);
895 PersonalDataManager::GUIDPair empty(std::string(), 0); 898 PersonalDataManager::GUIDPair empty(std::string(), 0);
896 autofill_manager_->FillOrPreviewForm( 899 autofill_manager_->FillOrPreviewForm(
897 AutofillDriver::FORM_DATA_ACTION_FILL, 900 AutofillDriver::FORM_DATA_ACTION_FILL,
898 0, form, form.fields.front(), 901 0, form, form.fields.front(),
899 autofill_manager_->PackGUIDs(empty, guid)); 902 autofill_manager_->PackGUIDs(empty, guid));
900 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 903 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
901 TimeTicks()); 904 TimeTicks());
902 // Simulate a second keystroke; make sure we don't log the metric twice. 905 // Simulate a second keystroke; make sure we don't log the metric twice.
903 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 906 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
904 TimeTicks()); 907 TimeTicks());
908 histogram_tester.ExpectBucketCount(
909 "Autofill.UserHappiness",
910 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1);
911 histogram_tester.ExpectBucketCount(
912 "Autofill.UserHappiness",
913 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE, 1);
905 } 914 }
906 915
907 // Simulate invoking autofill again. 916 // Simulate invoking autofill again.
908 EXPECT_CALL(*autofill_manager_->metric_logger(), 917 {
909 LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL)); 918 base::HistogramTester histogram_tester;
910 EXPECT_CALL(*autofill_manager_->metric_logger(), 919 autofill_manager_->OnDidFillAutofillFormData(TimeTicks());
911 LogUserHappinessMetric( 920 histogram_tester.ExpectUniqueSample("Autofill.UserHappiness",
912 AutofillMetrics::USER_DID_AUTOFILL_ONCE)).Times(0); 921 AutofillMetrics::USER_DID_AUTOFILL, 1);
913 autofill_manager_->OnDidFillAutofillFormData(TimeTicks()); 922 }
914 923
915 // Simulate editing another autofilled field. 924 // Simulate editing another autofilled field.
916 { 925 {
917 EXPECT_CALL(*autofill_manager_->metric_logger(), 926 base::HistogramTester histogram_tester;
918 LogUserHappinessMetric(
919 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD));
920 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); 927 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks());
928 histogram_tester.ExpectUniqueSample(
929 "Autofill.UserHappiness",
930 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD, 1);
921 } 931 }
922 } 932 }
923 933
924 // Verify that we correctly log metrics tracking the duration of form fill. 934 // Verify that we correctly log metrics tracking the duration of form fill.
925 TEST_F(AutofillMetricsTest, FormFillDuration) { 935 TEST_F(AutofillMetricsTest, FormFillDuration) {
926 // Load a fillable form. 936 // Load a fillable form.
927 FormData form; 937 FormData form;
928 form.name = ASCIIToUTF16("TestForm"); 938 form.name = ASCIIToUTF16("TestForm");
929 form.origin = GURL("http://example.com/form.html"); 939 form.origin = GURL("http://example.com/form.html");
930 form.action = GURL("http://example.com/submit.html"); 940 form.action = GURL("http://example.com/submit.html");
(...skipping 23 matching lines...) Expand all
954 964
955 // Fill the field values for form submission. 965 // Fill the field values for form submission.
956 second_form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); 966 second_form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley");
957 second_form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); 967 second_form.fields[1].value = ASCIIToUTF16("theking@gmail.com");
958 second_form.fields[2].value = ASCIIToUTF16("12345678901"); 968 second_form.fields[2].value = ASCIIToUTF16("12345678901");
959 second_form.fields[3].value = ASCIIToUTF16("51512345678"); 969 second_form.fields[3].value = ASCIIToUTF16("51512345678");
960 970
961 // Expect only form load metrics to be logged if the form is submitted without 971 // Expect only form load metrics to be logged if the form is submitted without
962 // user interaction. 972 // user interaction.
963 { 973 {
964 EXPECT_CALL(*autofill_manager_->metric_logger(), 974 base::HistogramTester histogram_tester;
965 LogFormFillDurationFromLoadWithAutofill(_)).Times(0);
966 EXPECT_CALL(*autofill_manager_->metric_logger(),
967 LogFormFillDurationFromLoadWithoutAutofill(
968 TimeDelta::FromInternalValue(16)));
969 EXPECT_CALL(*autofill_manager_->metric_logger(),
970 LogFormFillDurationFromInteractionWithAutofill(_)).Times(0);
971 EXPECT_CALL(*autofill_manager_->metric_logger(),
972 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0);
973 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 975 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
974 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 976 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
977
978 histogram_tester.ExpectTotalCount(
979 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
980 histogram_tester.ExpectUniqueSample(
981 "Autofill.FillDuration.FromLoad.WithoutAutofill", 16, 1);
982 histogram_tester.ExpectTotalCount(
983 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
984 histogram_tester.ExpectTotalCount(
985 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
986
975 autofill_manager_->Reset(); 987 autofill_manager_->Reset();
976 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
977 } 988 }
978 989
979 // Expect metric to be logged if the user manually edited a form field. 990 // Expect metric to be logged if the user manually edited a form field.
980 { 991 {
981 EXPECT_CALL(*autofill_manager_->metric_logger(), 992 base::HistogramTester histogram_tester;
982 LogFormFillDurationFromLoadWithAutofill(_)).Times(0);
983 EXPECT_CALL(*autofill_manager_->metric_logger(),
984 LogFormFillDurationFromLoadWithoutAutofill(
985 TimeDelta::FromInternalValue(16)));
986 EXPECT_CALL(*autofill_manager_->metric_logger(),
987 LogFormFillDurationFromInteractionWithAutofill(_)).Times(0);
988 EXPECT_CALL(*autofill_manager_->metric_logger(),
989 LogFormFillDurationFromInteractionWithoutAutofill(
990 TimeDelta::FromInternalValue(14)));
991 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 993 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
992 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 994 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
993 TimeTicks::FromInternalValue(3)); 995 TimeTicks::FromInternalValue(3));
994 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 996 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
997
998 histogram_tester.ExpectTotalCount(
999 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
1000 histogram_tester.ExpectUniqueSample(
1001 "Autofill.FillDuration.FromLoad.WithoutAutofill", 16, 1);
1002 histogram_tester.ExpectTotalCount(
1003 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
1004 histogram_tester.ExpectUniqueSample(
1005 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 14, 1);
1006
995 autofill_manager_->Reset(); 1007 autofill_manager_->Reset();
996 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
997 } 1008 }
998 1009
999 // Expect metric to be logged if the user autofilled the form. 1010 // Expect metric to be logged if the user autofilled the form.
1000 form.fields[0].is_autofilled = true; 1011 form.fields[0].is_autofilled = true;
1001 { 1012 {
1002 EXPECT_CALL(*autofill_manager_->metric_logger(), 1013 base::HistogramTester histogram_tester;
1003 LogFormFillDurationFromLoadWithAutofill(
1004 TimeDelta::FromInternalValue(16)));
1005 EXPECT_CALL(*autofill_manager_->metric_logger(),
1006 LogFormFillDurationFromLoadWithoutAutofill(_)).Times(0);
1007 EXPECT_CALL(*autofill_manager_->metric_logger(),
1008 LogFormFillDurationFromInteractionWithAutofill(
1009 TimeDelta::FromInternalValue(12)));
1010 EXPECT_CALL(*autofill_manager_->metric_logger(),
1011 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0);
1012 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1014 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1013 autofill_manager_->OnDidFillAutofillFormData( 1015 autofill_manager_->OnDidFillAutofillFormData(
1014 TimeTicks::FromInternalValue(5)); 1016 TimeTicks::FromInternalValue(5));
1015 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1017 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1018
1019 histogram_tester.ExpectUniqueSample(
1020 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
1021 histogram_tester.ExpectTotalCount(
1022 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
1023 histogram_tester.ExpectUniqueSample(
1024 "Autofill.FillDuration.FromInteraction.WithAutofill", 12, 1);
1025 histogram_tester.ExpectTotalCount(
1026 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
1027
1016 autofill_manager_->Reset(); 1028 autofill_manager_->Reset();
1017 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1018 } 1029 }
1019 1030
1020 // Expect metric to be logged if the user both manually filled some fields 1031 // Expect metric to be logged if the user both manually filled some fields
1021 // and autofilled others. Messages can arrive out of order, so make sure they 1032 // and autofilled others. Messages can arrive out of order, so make sure they
1022 // take precedence appropriately. 1033 // take precedence appropriately.
1023 { 1034 {
1024 EXPECT_CALL(*autofill_manager_->metric_logger(), 1035 base::HistogramTester histogram_tester;
1025 LogFormFillDurationFromLoadWithAutofill( 1036
1026 TimeDelta::FromInternalValue(16)));
1027 EXPECT_CALL(*autofill_manager_->metric_logger(),
1028 LogFormFillDurationFromLoadWithoutAutofill(_)).Times(0);
1029 EXPECT_CALL(*autofill_manager_->metric_logger(),
1030 LogFormFillDurationFromInteractionWithAutofill(
1031 TimeDelta::FromInternalValue(14)));
1032 EXPECT_CALL(*autofill_manager_->metric_logger(),
1033 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0);
1034 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1037 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1035 autofill_manager_->OnDidFillAutofillFormData( 1038 autofill_manager_->OnDidFillAutofillFormData(
1036 TimeTicks::FromInternalValue(5)); 1039 TimeTicks::FromInternalValue(5));
1037 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1040 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1038 TimeTicks::FromInternalValue(3)); 1041 TimeTicks::FromInternalValue(3));
1039 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1042 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1043
1044 histogram_tester.ExpectUniqueSample(
1045 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
1046 histogram_tester.ExpectTotalCount(
1047 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
1048 histogram_tester.ExpectUniqueSample(
1049 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1);
1050 histogram_tester.ExpectTotalCount(
1051 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
1052
1040 autofill_manager_->Reset(); 1053 autofill_manager_->Reset();
1041 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1042 } 1054 }
1043 1055
1044 // Make sure that loading another form doesn't affect metrics from the first 1056 // Make sure that loading another form doesn't affect metrics from the first
1045 // form. 1057 // form.
1046 { 1058 {
1047 EXPECT_CALL(*autofill_manager_->metric_logger(), 1059 base::HistogramTester histogram_tester;
1048 LogFormFillDurationFromLoadWithAutofill(
1049 TimeDelta::FromInternalValue(16)));
1050 EXPECT_CALL(*autofill_manager_->metric_logger(),
1051 LogFormFillDurationFromLoadWithoutAutofill(_)).Times(0);
1052 EXPECT_CALL(*autofill_manager_->metric_logger(),
1053 LogFormFillDurationFromInteractionWithAutofill(
1054 TimeDelta::FromInternalValue(14)));
1055 EXPECT_CALL(*autofill_manager_->metric_logger(),
1056 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0);
1057 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1060 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1058 autofill_manager_->OnFormsSeen(second_forms, 1061 autofill_manager_->OnFormsSeen(second_forms,
1059 TimeTicks::FromInternalValue(3)); 1062 TimeTicks::FromInternalValue(3));
1060 autofill_manager_->OnDidFillAutofillFormData( 1063 autofill_manager_->OnDidFillAutofillFormData(
1061 TimeTicks::FromInternalValue(5)); 1064 TimeTicks::FromInternalValue(5));
1062 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1065 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1063 TimeTicks::FromInternalValue(3)); 1066 TimeTicks::FromInternalValue(3));
1064 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1067 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1068
1069 histogram_tester.ExpectUniqueSample(
1070 "Autofill.FillDuration.FromLoad.WithAutofill", 16, 1);
1071 histogram_tester.ExpectTotalCount(
1072 "Autofill.FillDuration.FromLoad.WithoutAutofill", 0);
1073 histogram_tester.ExpectUniqueSample(
1074 "Autofill.FillDuration.FromInteraction.WithAutofill", 14, 1);
1075 histogram_tester.ExpectTotalCount(
1076 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
1077
1065 autofill_manager_->Reset(); 1078 autofill_manager_->Reset();
1066 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1067 } 1079 }
1068 1080
1069 // Make sure that submitting a form that was loaded later will report the 1081 // Make sure that submitting a form that was loaded later will report the
1070 // later loading time. 1082 // later loading time.
1071 { 1083 {
1072 EXPECT_CALL(*autofill_manager_->metric_logger(), 1084 base::HistogramTester histogram_tester;
1073 LogFormFillDurationFromLoadWithoutAutofill(
1074 TimeDelta::FromInternalValue(12)));
1075 EXPECT_CALL(*autofill_manager_->metric_logger(),
1076 LogFormFillDurationFromLoadWithAutofill(_)).Times(0);
1077 EXPECT_CALL(*autofill_manager_->metric_logger(),
1078 LogFormFillDurationFromInteractionWithAutofill(_)).Times(0);
1079 EXPECT_CALL(*autofill_manager_->metric_logger(),
1080 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0);
1081 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1)); 1085 autofill_manager_->OnFormsSeen(forms, TimeTicks::FromInternalValue(1));
1082 autofill_manager_->OnFormsSeen(second_forms, 1086 autofill_manager_->OnFormsSeen(second_forms,
1083 TimeTicks::FromInternalValue(5)); 1087 TimeTicks::FromInternalValue(5));
1084 autofill_manager_->FormSubmitted(second_form, 1088 autofill_manager_->FormSubmitted(second_form,
1085 TimeTicks::FromInternalValue(17)); 1089 TimeTicks::FromInternalValue(17));
1090
1091 histogram_tester.ExpectTotalCount(
1092 "Autofill.FillDuration.FromLoad.WithAutofill", 0);
1093 histogram_tester.ExpectUniqueSample(
1094 "Autofill.FillDuration.FromLoad.WithoutAutofill", 12, 1);
1095 histogram_tester.ExpectTotalCount(
1096 "Autofill.FillDuration.FromInteraction.WithAutofill", 0);
1097 histogram_tester.ExpectTotalCount(
1098 "Autofill.FillDuration.FromInteraction.WithoutAutofill", 0);
1099
1086 autofill_manager_->Reset(); 1100 autofill_manager_->Reset();
1087 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1088 } 1101 }
1089 } 1102 }
1090 1103
1091 } // namespace autofill 1104 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_metrics.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698