autofill_metrics_unittest.cc revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "components/autofill/core/browser/autofill_metrics.h" 6 7#include <vector> 8 9#include "base/memory/ref_counted.h" 10#include "base/memory/scoped_ptr.h" 11#include "base/strings/string16.h" 12#include "base/strings/utf_string_conversions.h" 13#include "base/time/time.h" 14#include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" 15#include "chrome/browser/autofill/personal_data_manager_factory.h" 16#include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" 17#include "chrome/test/base/chrome_render_view_host_test_harness.h" 18#include "chrome/test/base/testing_profile.h" 19#include "components/autofill/core/browser/autofill_common_test.h" 20#include "components/autofill/core/browser/autofill_external_delegate.h" 21#include "components/autofill/core/browser/autofill_manager.h" 22#include "components/autofill/core/browser/autofill_manager_delegate.h" 23#include "components/autofill/core/browser/personal_data_manager.h" 24#include "components/autofill/core/browser/test_autofill_driver.h" 25#include "components/autofill/core/common/form_data.h" 26#include "components/autofill/core/common/form_field_data.h" 27#include "components/autofill/core/common/forms_seen_state.h" 28#include "components/webdata/common/web_data_results.h" 29#include "content/public/test/test_utils.h" 30#include "testing/gmock/include/gmock/gmock.h" 31#include "testing/gtest/include/gtest/gtest.h" 32#include "ui/gfx/rect.h" 33#include "url/gurl.h" 34 35using base::TimeDelta; 36using base::TimeTicks; 37using testing::_; 38using testing::AnyNumber; 39using testing::Mock; 40 41namespace autofill { 42 43namespace { 44 45class MockAutofillMetrics : public AutofillMetrics { 46 public: 47 MockAutofillMetrics() {} 48 MOCK_CONST_METHOD1(LogCreditCardInfoBarMetric, void(InfoBarMetric metric)); 49 MOCK_CONST_METHOD1(LogDeveloperEngagementMetric, 50 void(DeveloperEngagementMetric metric)); 51 MOCK_CONST_METHOD3(LogHeuristicTypePrediction, 52 void(FieldTypeQualityMetric metric, 53 ServerFieldType field_type, 54 const std::string& experiment_id)); 55 MOCK_CONST_METHOD3(LogOverallTypePrediction, 56 void(FieldTypeQualityMetric metric, 57 ServerFieldType field_type, 58 const std::string& experiment_id)); 59 MOCK_CONST_METHOD3(LogServerTypePrediction, 60 void(FieldTypeQualityMetric metric, 61 ServerFieldType field_type, 62 const std::string& experiment_id)); 63 MOCK_CONST_METHOD2(LogQualityMetric, void(QualityMetric metric, 64 const std::string& experiment_id)); 65 MOCK_CONST_METHOD1(LogServerQueryMetric, void(ServerQueryMetric metric)); 66 MOCK_CONST_METHOD1(LogUserHappinessMetric, void(UserHappinessMetric metric)); 67 MOCK_CONST_METHOD1(LogFormFillDurationFromLoadWithAutofill, 68 void(const TimeDelta& duration)); 69 MOCK_CONST_METHOD1(LogFormFillDurationFromLoadWithoutAutofill, 70 void(const TimeDelta& duration)); 71 MOCK_CONST_METHOD1(LogFormFillDurationFromInteractionWithAutofill, 72 void(const TimeDelta& duration)); 73 MOCK_CONST_METHOD1(LogFormFillDurationFromInteractionWithoutAutofill, 74 void(const TimeDelta& duration)); 75 MOCK_CONST_METHOD1(LogIsAutofillEnabledAtPageLoad, void(bool enabled)); 76 MOCK_CONST_METHOD1(LogIsAutofillEnabledAtStartup, void(bool enabled)); 77 MOCK_CONST_METHOD1(LogStoredProfileCount, void(size_t num_profiles)); 78 MOCK_CONST_METHOD1(LogAddressSuggestionsCount, void(size_t num_suggestions)); 79 MOCK_CONST_METHOD1(LogServerExperimentIdForQuery, 80 void(const std::string& experiment_id)); 81 MOCK_CONST_METHOD1(LogServerExperimentIdForUpload, 82 void(const std::string& experiment_id)); 83 84 private: 85 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); 86}; 87 88class TestPersonalDataManager : public PersonalDataManager { 89 public: 90 TestPersonalDataManager() 91 : PersonalDataManager("en-US"), 92 autofill_enabled_(true) { 93 set_metric_logger(new testing::NiceMock<MockAutofillMetrics>()); 94 CreateTestAutofillProfiles(&web_profiles_); 95 } 96 97 void SetBrowserContext(content::BrowserContext* context) { 98 set_browser_context(context); 99 } 100 101 // Overridden to avoid a trip to the database. This should be a no-op except 102 // for the side-effect of logging the profile count. 103 virtual void LoadProfiles() OVERRIDE { 104 std::vector<AutofillProfile*> profiles; 105 web_profiles_.release(&profiles); 106 WDResult<std::vector<AutofillProfile*> > result(AUTOFILL_PROFILES_RESULT, 107 profiles); 108 ReceiveLoadedProfiles(0, &result); 109 } 110 111 // Overridden to avoid a trip to the database. 112 virtual void LoadCreditCards() OVERRIDE {} 113 114 const MockAutofillMetrics* metric_logger() const { 115 return static_cast<const MockAutofillMetrics*>( 116 PersonalDataManager::metric_logger()); 117 } 118 119 void set_autofill_enabled(bool autofill_enabled) { 120 autofill_enabled_ = autofill_enabled; 121 } 122 123 virtual bool IsAutofillEnabled() const OVERRIDE { 124 return autofill_enabled_; 125 } 126 127 MOCK_METHOD1(SaveImportedCreditCard, 128 std::string(const CreditCard& imported_credit_card)); 129 130 private: 131 void CreateTestAutofillProfiles(ScopedVector<AutofillProfile>* profiles) { 132 AutofillProfile* profile = new AutofillProfile; 133 test::SetProfileInfo(profile, "Elvis", "Aaron", 134 "Presley", "theking@gmail.com", "RCA", 135 "3734 Elvis Presley Blvd.", "Apt. 10", 136 "Memphis", "Tennessee", "38116", "US", 137 "12345678901"); 138 profile->set_guid("00000000-0000-0000-0000-000000000001"); 139 profiles->push_back(profile); 140 profile = new AutofillProfile; 141 test::SetProfileInfo(profile, "Charles", "Hardin", 142 "Holley", "buddy@gmail.com", "Decca", 143 "123 Apple St.", "unit 6", "Lubbock", 144 "Texas", "79401", "US", "2345678901"); 145 profile->set_guid("00000000-0000-0000-0000-000000000002"); 146 profiles->push_back(profile); 147 } 148 149 bool autofill_enabled_; 150 151 DISALLOW_COPY_AND_ASSIGN(TestPersonalDataManager); 152}; 153 154class TestFormStructure : public FormStructure { 155 public: 156 explicit TestFormStructure(const FormData& form) : FormStructure(form) {} 157 virtual ~TestFormStructure() {} 158 159 void SetFieldTypes(const std::vector<ServerFieldType>& heuristic_types, 160 const std::vector<ServerFieldType>& 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 186class 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 bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } 198 199 void set_autofill_enabled(bool autofill_enabled) { 200 autofill_enabled_ = autofill_enabled; 201 } 202 203 MockAutofillMetrics* metric_logger() { 204 return static_cast<MockAutofillMetrics*>(const_cast<AutofillMetrics*>( 205 AutofillManager::metric_logger())); 206 } 207 208 void AddSeenForm(const FormData& form, 209 const std::vector<ServerFieldType>& heuristic_types, 210 const std::vector<ServerFieldType>& server_types, 211 const std::string& experiment_id) { 212 FormData empty_form = form; 213 for (size_t i = 0; i < empty_form.fields.size(); ++i) { 214 empty_form.fields[i].value = base::string16(); 215 } 216 217 // |form_structure| will be owned by |form_structures()|. 218 TestFormStructure* form_structure = new TestFormStructure(empty_form); 219 form_structure->SetFieldTypes(heuristic_types, server_types); 220 form_structure->set_server_experiment_id(experiment_id); 221 form_structures()->push_back(form_structure); 222 } 223 224 void FormSubmitted(const FormData& form, const TimeTicks& timestamp) { 225 message_loop_runner_ = new content::MessageLoopRunner(); 226 if (!OnFormSubmitted(form, timestamp)) 227 return; 228 229 // Wait for the asynchronous FormSubmitted() call to complete. 230 message_loop_runner_->Run(); 231 } 232 233 virtual void UploadFormDataAsyncCallback( 234 const FormStructure* submitted_form, 235 const base::TimeTicks& load_time, 236 const base::TimeTicks& interaction_time, 237 const base::TimeTicks& submission_time) OVERRIDE { 238 message_loop_runner_->Quit(); 239 240 AutofillManager::UploadFormDataAsyncCallback(submitted_form, 241 load_time, 242 interaction_time, 243 submission_time); 244 } 245 246 private: 247 bool autofill_enabled_; 248 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 249 250 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); 251}; 252 253} // namespace 254 255class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { 256 public: 257 virtual ~AutofillMetricsTest(); 258 259 virtual void SetUp() OVERRIDE; 260 virtual void TearDown() OVERRIDE; 261 262 protected: 263 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate( 264 MockAutofillMetrics* metric_logger); 265 266 scoped_ptr<TestAutofillDriver> autofill_driver_; 267 scoped_ptr<TestAutofillManager> autofill_manager_; 268 scoped_ptr<TestPersonalDataManager> personal_data_; 269 scoped_ptr<AutofillExternalDelegate> external_delegate_; 270}; 271 272AutofillMetricsTest::~AutofillMetricsTest() { 273 // Order of destruction is important as AutofillManager relies on 274 // PersonalDataManager to be around when it gets destroyed. 275 autofill_manager_.reset(); 276} 277 278void AutofillMetricsTest::SetUp() { 279 ChromeRenderViewHostTestHarness::SetUp(); 280 281 // Ensure Mac OS X does not pop up a modal dialog for the Address Book. 282 autofill::test::DisableSystemServices(profile()); 283 284 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); 285 286 TabAutofillManagerDelegate::CreateForWebContents(web_contents()); 287 288 personal_data_.reset(new TestPersonalDataManager()); 289 personal_data_->SetBrowserContext(profile()); 290 autofill_driver_.reset(new TestAutofillDriver(web_contents())); 291 autofill_manager_.reset(new TestAutofillManager( 292 autofill_driver_.get(), 293 TabAutofillManagerDelegate::FromWebContents(web_contents()), 294 personal_data_.get())); 295 296 external_delegate_.reset(new AutofillExternalDelegate( 297 web_contents(), 298 autofill_manager_.get(), 299 autofill_driver_.get())); 300 autofill_manager_->SetExternalDelegate(external_delegate_.get()); 301} 302 303void 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 ChromeRenderViewHostTestHarness::TearDown(); 312} 313 314scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate( 315 MockAutofillMetrics* metric_logger) { 316 EXPECT_CALL(*metric_logger, 317 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 318 319 CreditCard credit_card; 320 return AutofillCCInfoBarDelegate::Create( 321 metric_logger, 322 base::Bind( 323 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard), 324 base::Unretained(personal_data_.get()), credit_card)); 325} 326 327// Test that we log quality metrics appropriately. 328TEST_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<ServerFieldType> 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. 473TEST_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 ServerFieldType heuristic_type; 487 ServerFieldType 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<ServerFieldType> 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. 591TEST_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<ServerFieldType> 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. 747TEST_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 = "address-line1"; 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. 828TEST_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. 867TEST_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<ServerFieldType> 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. 990TEST_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. 1003TEST_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. 1011TEST_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. 1019TEST_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<ServerFieldType> 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. 1089TEST_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. 1112TEST_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. 1160TEST_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 FormStructure::ParseQueryResponse( 1175 "<autofillqueryresponse></autofillqueryresponse>", 1176 std::vector<FormStructure*>(), 1177 metric_logger); 1178 1179 // Experiment "ar1" specified. 1180 EXPECT_CALL(metric_logger, 1181 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED)); 1182 EXPECT_CALL(metric_logger, 1183 LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED)); 1184 EXPECT_CALL(metric_logger, 1185 LogServerExperimentIdForQuery("ar1")); 1186 EXPECT_CALL(metric_logger, 1187 LogServerQueryMetric( 1188 AutofillMetrics::QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS)); 1189 FormStructure::ParseQueryResponse( 1190 "<autofillqueryresponse experimentid=\"ar1\"></autofillqueryresponse>", 1191 std::vector<FormStructure*>(), 1192 metric_logger); 1193} 1194 1195// Verify that we correctly log user happiness metrics dealing with form loading 1196// and form submission. 1197TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) { 1198 // Start with a form with insufficiently many fields. 1199 FormData form; 1200 form.name = ASCIIToUTF16("TestForm"); 1201 form.method = ASCIIToUTF16("POST"); 1202 form.origin = GURL("http://example.com/form.html"); 1203 form.action = GURL("http://example.com/submit.html"); 1204 form.user_submitted = true; 1205 1206 FormFieldData field; 1207 test::CreateTestFormField("Name", "name", "", "text", &field); 1208 form.fields.push_back(field); 1209 test::CreateTestFormField("Email", "email", "", "text", &field); 1210 form.fields.push_back(field); 1211 1212 std::vector<FormData> forms(1, form); 1213 1214 // Expect no notifications when the form is first seen. 1215 { 1216 EXPECT_CALL(*autofill_manager_->metric_logger(), 1217 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED)).Times(0); 1218 autofill_manager_->OnFormsSeen(forms, TimeTicks(), 1219 autofill::NO_SPECIAL_FORMS_SEEN); 1220 } 1221 1222 1223 // Expect no notifications when the form is submitted. 1224 { 1225 EXPECT_CALL( 1226 *autofill_manager_->metric_logger(), 1227 LogUserHappinessMetric( 1228 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL)).Times(0); 1229 EXPECT_CALL( 1230 *autofill_manager_->metric_logger(), 1231 LogUserHappinessMetric( 1232 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)).Times(0); 1233 EXPECT_CALL( 1234 *autofill_manager_->metric_logger(), 1235 LogUserHappinessMetric( 1236 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE)).Times(0); 1237 EXPECT_CALL( 1238 *autofill_manager_->metric_logger(), 1239 LogUserHappinessMetric( 1240 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)).Times(0); 1241 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 1242 } 1243 1244 // Add more fields to the form. 1245 test::CreateTestFormField("Phone", "phone", "", "text", &field); 1246 form.fields.push_back(field); 1247 test::CreateTestFormField("Unknown", "unknown", "", "text", &field); 1248 form.fields.push_back(field); 1249 forms.front() = form; 1250 1251 // Expect a notification when the form is first seen. 1252 { 1253 EXPECT_CALL(*autofill_manager_->metric_logger(), 1254 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED)); 1255 autofill_manager_->OnFormsSeen(forms, TimeTicks(), 1256 autofill::NO_SPECIAL_FORMS_SEEN); 1257 } 1258 1259 // Expect a notification when the form is submitted. 1260 { 1261 EXPECT_CALL(*autofill_manager_->metric_logger(), 1262 LogUserHappinessMetric( 1263 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)); 1264 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 1265 } 1266 1267 // Fill in two of the fields. 1268 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); 1269 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); 1270 forms.front() = form; 1271 1272 // Expect a notification when the form is submitted. 1273 { 1274 EXPECT_CALL(*autofill_manager_->metric_logger(), 1275 LogUserHappinessMetric( 1276 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)); 1277 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 1278 } 1279 1280 // Fill in the third field. 1281 form.fields[2].value = ASCIIToUTF16("12345678901"); 1282 forms.front() = form; 1283 1284 // Expect notifications when the form is submitted. 1285 { 1286 EXPECT_CALL(*autofill_manager_->metric_logger(), 1287 LogUserHappinessMetric( 1288 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_NONE)); 1289 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 1290 } 1291 1292 1293 // Mark one of the fields as autofilled. 1294 form.fields[1].is_autofilled = true; 1295 forms.front() = form; 1296 1297 // Expect notifications when the form is submitted. 1298 { 1299 EXPECT_CALL(*autofill_manager_->metric_logger(), 1300 LogUserHappinessMetric( 1301 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME)); 1302 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 1303 } 1304 1305 // Mark all of the fillable fields as autofilled. 1306 form.fields[0].is_autofilled = true; 1307 form.fields[2].is_autofilled = true; 1308 forms.front() = form; 1309 1310 // Expect notifications when the form is submitted. 1311 { 1312 EXPECT_CALL(*autofill_manager_->metric_logger(), 1313 LogUserHappinessMetric( 1314 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL)); 1315 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 1316 } 1317 1318 // Clear out the third field's value. 1319 form.fields[2].value = base::string16(); 1320 forms.front() = form; 1321 1322 // Expect notifications when the form is submitted. 1323 { 1324 EXPECT_CALL(*autofill_manager_->metric_logger(), 1325 LogUserHappinessMetric( 1326 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM)); 1327 autofill_manager_->FormSubmitted(form, TimeTicks::Now()); 1328 } 1329} 1330 1331// Verify that we correctly log user happiness metrics dealing with form 1332// interaction. 1333TEST_F(AutofillMetricsTest, UserHappinessFormInteraction) { 1334 // Load a fillable form. 1335 FormData form; 1336 form.name = ASCIIToUTF16("TestForm"); 1337 form.method = ASCIIToUTF16("POST"); 1338 form.origin = GURL("http://example.com/form.html"); 1339 form.action = GURL("http://example.com/submit.html"); 1340 form.user_submitted = true; 1341 1342 FormFieldData field; 1343 test::CreateTestFormField("Name", "name", "", "text", &field); 1344 form.fields.push_back(field); 1345 test::CreateTestFormField("Email", "email", "", "text", &field); 1346 form.fields.push_back(field); 1347 test::CreateTestFormField("Phone", "phone", "", "text", &field); 1348 form.fields.push_back(field); 1349 1350 std::vector<FormData> forms(1, form); 1351 1352 // Expect a notification when the form is first seen. 1353 { 1354 EXPECT_CALL(*autofill_manager_->metric_logger(), 1355 LogUserHappinessMetric(AutofillMetrics::FORMS_LOADED)); 1356 autofill_manager_->OnFormsSeen(forms, TimeTicks(), 1357 autofill::NO_SPECIAL_FORMS_SEEN); 1358 } 1359 1360 // Simulate typing. 1361 { 1362 EXPECT_CALL(*autofill_manager_->metric_logger(), 1363 LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE)); 1364 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1365 TimeTicks()); 1366 } 1367 1368 // Simulate suggestions shown twice for a single edit (i.e. multiple 1369 // keystrokes in a single field). 1370 { 1371 EXPECT_CALL(*autofill_manager_->metric_logger(), 1372 LogUserHappinessMetric( 1373 AutofillMetrics::SUGGESTIONS_SHOWN)).Times(1); 1374 EXPECT_CALL(*autofill_manager_->metric_logger(), 1375 LogUserHappinessMetric( 1376 AutofillMetrics::SUGGESTIONS_SHOWN_ONCE)).Times(1); 1377 autofill_manager_->OnDidShowAutofillSuggestions(true); 1378 autofill_manager_->OnDidShowAutofillSuggestions(false); 1379 } 1380 1381 // Simulate suggestions shown for a different field. 1382 { 1383 EXPECT_CALL(*autofill_manager_->metric_logger(), 1384 LogUserHappinessMetric(AutofillMetrics::SUGGESTIONS_SHOWN)); 1385 EXPECT_CALL(*autofill_manager_->metric_logger(), 1386 LogUserHappinessMetric( 1387 AutofillMetrics::SUGGESTIONS_SHOWN_ONCE)).Times(0); 1388 autofill_manager_->OnDidShowAutofillSuggestions(true); 1389 } 1390 1391 // Simulate invoking autofill. 1392 { 1393 EXPECT_CALL(*autofill_manager_->metric_logger(), 1394 LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL)); 1395 EXPECT_CALL(*autofill_manager_->metric_logger(), 1396 LogUserHappinessMetric( 1397 AutofillMetrics::USER_DID_AUTOFILL_ONCE)); 1398 autofill_manager_->OnDidFillAutofillFormData(TimeTicks()); 1399 } 1400 1401 // Simulate editing an autofilled field. 1402 { 1403 EXPECT_CALL(*autofill_manager_->metric_logger(), 1404 LogUserHappinessMetric( 1405 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD)); 1406 EXPECT_CALL(*autofill_manager_->metric_logger(), 1407 LogUserHappinessMetric( 1408 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD_ONCE)); 1409 PersonalDataManager::GUIDPair guid( 1410 "00000000-0000-0000-0000-000000000001", 0); 1411 PersonalDataManager::GUIDPair empty(std::string(), 0); 1412 autofill_manager_->OnFillAutofillFormData( 1413 0, form, form.fields.front(), 1414 autofill_manager_->PackGUIDs(empty, guid)); 1415 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1416 TimeTicks()); 1417 // Simulate a second keystroke; make sure we don't log the metric twice. 1418 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1419 TimeTicks()); 1420 } 1421 1422 // Simulate invoking autofill again. 1423 EXPECT_CALL(*autofill_manager_->metric_logger(), 1424 LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL)); 1425 EXPECT_CALL(*autofill_manager_->metric_logger(), 1426 LogUserHappinessMetric( 1427 AutofillMetrics::USER_DID_AUTOFILL_ONCE)).Times(0); 1428 autofill_manager_->OnDidFillAutofillFormData(TimeTicks()); 1429 1430 // Simulate editing another autofilled field. 1431 { 1432 EXPECT_CALL(*autofill_manager_->metric_logger(), 1433 LogUserHappinessMetric( 1434 AutofillMetrics::USER_DID_EDIT_AUTOFILLED_FIELD)); 1435 autofill_manager_->OnTextFieldDidChange(form, form.fields[1], TimeTicks()); 1436 } 1437} 1438 1439// Verify that we correctly log metrics tracking the duration of form fill. 1440TEST_F(AutofillMetricsTest, FormFillDuration) { 1441 // Load a fillable form. 1442 FormData form; 1443 form.name = ASCIIToUTF16("TestForm"); 1444 form.method = ASCIIToUTF16("POST"); 1445 form.origin = GURL("http://example.com/form.html"); 1446 form.action = GURL("http://example.com/submit.html"); 1447 form.user_submitted = true; 1448 1449 FormFieldData field; 1450 test::CreateTestFormField("Name", "name", "", "text", &field); 1451 form.fields.push_back(field); 1452 test::CreateTestFormField("Email", "email", "", "text", &field); 1453 form.fields.push_back(field); 1454 test::CreateTestFormField("Phone", "phone", "", "text", &field); 1455 form.fields.push_back(field); 1456 1457 std::vector<FormData> forms(1, form); 1458 1459 // Fill the field values for form submission. 1460 form.fields[0].value = ASCIIToUTF16("Elvis Aaron Presley"); 1461 form.fields[1].value = ASCIIToUTF16("theking@gmail.com"); 1462 form.fields[2].value = ASCIIToUTF16("12345678901"); 1463 1464 // Expect only form load metrics to be logged if the form is submitted without 1465 // user interaction. 1466 { 1467 EXPECT_CALL(*autofill_manager_->metric_logger(), 1468 LogFormFillDurationFromLoadWithAutofill(_)).Times(0); 1469 EXPECT_CALL(*autofill_manager_->metric_logger(), 1470 LogFormFillDurationFromLoadWithoutAutofill( 1471 TimeDelta::FromInternalValue(16))); 1472 EXPECT_CALL(*autofill_manager_->metric_logger(), 1473 LogFormFillDurationFromInteractionWithAutofill(_)).Times(0); 1474 EXPECT_CALL(*autofill_manager_->metric_logger(), 1475 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0); 1476 autofill_manager_->OnFormsSeen( 1477 forms, TimeTicks::FromInternalValue(1), 1478 autofill::NO_SPECIAL_FORMS_SEEN); 1479 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1480 autofill_manager_->Reset(); 1481 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1482 } 1483 1484 // Expect metric to be logged if the user manually edited a form field. 1485 { 1486 EXPECT_CALL(*autofill_manager_->metric_logger(), 1487 LogFormFillDurationFromLoadWithAutofill(_)).Times(0); 1488 EXPECT_CALL(*autofill_manager_->metric_logger(), 1489 LogFormFillDurationFromLoadWithoutAutofill( 1490 TimeDelta::FromInternalValue(16))); 1491 EXPECT_CALL(*autofill_manager_->metric_logger(), 1492 LogFormFillDurationFromInteractionWithAutofill(_)).Times(0); 1493 EXPECT_CALL(*autofill_manager_->metric_logger(), 1494 LogFormFillDurationFromInteractionWithoutAutofill( 1495 TimeDelta::FromInternalValue(14))); 1496 autofill_manager_->OnFormsSeen( 1497 forms, TimeTicks::FromInternalValue(1), 1498 autofill::NO_SPECIAL_FORMS_SEEN); 1499 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1500 TimeTicks::FromInternalValue(3)); 1501 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1502 autofill_manager_->Reset(); 1503 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1504 } 1505 1506 // Expect metric to be logged if the user autofilled the form. 1507 form.fields[0].is_autofilled = true; 1508 { 1509 EXPECT_CALL(*autofill_manager_->metric_logger(), 1510 LogFormFillDurationFromLoadWithAutofill( 1511 TimeDelta::FromInternalValue(16))); 1512 EXPECT_CALL(*autofill_manager_->metric_logger(), 1513 LogFormFillDurationFromLoadWithoutAutofill(_)).Times(0); 1514 EXPECT_CALL(*autofill_manager_->metric_logger(), 1515 LogFormFillDurationFromInteractionWithAutofill( 1516 TimeDelta::FromInternalValue(12))); 1517 EXPECT_CALL(*autofill_manager_->metric_logger(), 1518 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0); 1519 autofill_manager_->OnFormsSeen( 1520 forms, TimeTicks::FromInternalValue(1), 1521 autofill::NO_SPECIAL_FORMS_SEEN); 1522 autofill_manager_->OnDidFillAutofillFormData( 1523 TimeTicks::FromInternalValue(5)); 1524 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1525 autofill_manager_->Reset(); 1526 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1527 } 1528 1529 // Expect metric to be logged if the user both manually filled some fields 1530 // and autofilled others. Messages can arrive out of order, so make sure they 1531 // take precedence appropriately. 1532 { 1533 EXPECT_CALL(*autofill_manager_->metric_logger(), 1534 LogFormFillDurationFromLoadWithAutofill( 1535 TimeDelta::FromInternalValue(16))); 1536 EXPECT_CALL(*autofill_manager_->metric_logger(), 1537 LogFormFillDurationFromLoadWithoutAutofill(_)).Times(0); 1538 EXPECT_CALL(*autofill_manager_->metric_logger(), 1539 LogFormFillDurationFromInteractionWithAutofill( 1540 TimeDelta::FromInternalValue(14))); 1541 EXPECT_CALL(*autofill_manager_->metric_logger(), 1542 LogFormFillDurationFromInteractionWithoutAutofill(_)).Times(0); 1543 autofill_manager_->OnFormsSeen( 1544 forms, TimeTicks::FromInternalValue(1), 1545 autofill::NO_SPECIAL_FORMS_SEEN); 1546 autofill_manager_->OnDidFillAutofillFormData( 1547 TimeTicks::FromInternalValue(5)); 1548 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1549 TimeTicks::FromInternalValue(3)); 1550 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1551 autofill_manager_->Reset(); 1552 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1553 } 1554} 1555 1556} // namespace autofill 1557