| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 registry->RegisterBooleanPref(autofill::prefs::kAutofillEnabled, true); | 95 registry->RegisterBooleanPref(autofill::prefs::kAutofillEnabled, true); |
| 96 registry->RegisterBooleanPref(autofill::prefs::kAutofillWalletImportEnabled, | 96 registry->RegisterBooleanPref(autofill::prefs::kAutofillWalletImportEnabled, |
| 97 true); | 97 true); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void RunAndSignal(const base::Closure& cb, WaitableEvent* event) { | 100 void RunAndSignal(const base::Closure& cb, WaitableEvent* event) { |
| 101 cb.Run(); | 101 cb.Run(); |
| 102 event->Signal(); | 102 event->Signal(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 AutofillEntry MakeAutofillEntry(const char* name, |
| 106 const char* value, |
| 107 int time_shift0, |
| 108 int time_shift1) { |
| 109 // Time deep in the past would cause Autocomplete sync to discard the |
| 110 // entries. |
| 111 static Time base_time = Time::Now().LocalMidnight(); |
| 112 |
| 113 Time date_created = base_time + TimeDelta::FromSeconds(time_shift0); |
| 114 Time date_last_used = date_created; |
| 115 if (time_shift1 >= 0) |
| 116 date_last_used = base_time + TimeDelta::FromSeconds(time_shift1); |
| 117 return AutofillEntry( |
| 118 AutofillKey(base::ASCIIToUTF16(name), base::ASCIIToUTF16(value)), |
| 119 date_created, date_last_used); |
| 120 } |
| 121 |
| 122 AutofillEntry MakeAutofillEntry(const char* name, |
| 123 const char* value, |
| 124 int time_shift) { |
| 125 return MakeAutofillEntry(name, value, time_shift, -1); |
| 126 } |
| 127 |
| 105 } // namespace | 128 } // namespace |
| 106 | 129 |
| 107 class AutofillTableMock : public AutofillTable { | 130 class AutofillTableMock : public AutofillTable { |
| 108 public: | 131 public: |
| 109 AutofillTableMock() {} | 132 AutofillTableMock() {} |
| 110 MOCK_METHOD2(RemoveFormElement, | 133 MOCK_METHOD2(RemoveFormElement, |
| 111 bool(const base::string16& name, | 134 bool(const base::string16& name, |
| 112 const base::string16& value)); // NOLINT | 135 const base::string16& value)); // NOLINT |
| 113 MOCK_METHOD1(GetAllAutofillEntries, | 136 MOCK_METHOD1(GetAllAutofillEntries, |
| 114 bool(std::vector<AutofillEntry>* entries)); // NOLINT | 137 bool(std::vector<AutofillEntry>* entries)); // NOLINT |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 void OnDataTypeConfigureComplete(const std::vector< | 371 void OnDataTypeConfigureComplete(const std::vector< |
| 349 syncer::DataTypeConfigurationStats>& configuration_stats) override { | 372 syncer::DataTypeConfigurationStats>& configuration_stats) override { |
| 350 ASSERT_EQ(1u, configuration_stats.size()); | 373 ASSERT_EQ(1u, configuration_stats.size()); |
| 351 association_stats_ = configuration_stats[0].association_stats; | 374 association_stats_ = configuration_stats[0].association_stats; |
| 352 } | 375 } |
| 353 | 376 |
| 354 protected: | 377 protected: |
| 355 ProfileSyncServiceAutofillTest() : debug_ptr_factory_(this) { | 378 ProfileSyncServiceAutofillTest() : debug_ptr_factory_(this) { |
| 356 autofill::CountryNames::SetLocaleString("en-US"); | 379 autofill::CountryNames::SetLocaleString("en-US"); |
| 357 RegisterAutofillPrefs( | 380 RegisterAutofillPrefs( |
| 358 profile_sync_service_bundle_.pref_service()->registry()); | 381 profile_sync_service_bundle()->pref_service()->registry()); |
| 359 | 382 |
| 360 data_type_thread_.Start(); | 383 data_type_thread()->Start(); |
| 361 profile_sync_service_bundle_.set_db_thread(data_type_thread_.task_runner()); | 384 profile_sync_service_bundle()->set_db_thread( |
| 385 data_type_thread()->task_runner()); |
| 362 | 386 |
| 363 web_database_.reset(new WebDatabaseFake(&autofill_table_)); | 387 web_database_.reset(new WebDatabaseFake(&autofill_table_)); |
| 364 web_data_wrapper_ = make_scoped_ptr(new MockWebDataServiceWrapper( | 388 web_data_wrapper_ = make_scoped_ptr(new MockWebDataServiceWrapper( |
| 365 new WebDataServiceFake(base::ThreadTaskRunnerHandle::Get(), | 389 new WebDataServiceFake(base::ThreadTaskRunnerHandle::Get(), |
| 366 data_type_thread_.task_runner()), | 390 data_type_thread()->task_runner()), |
| 367 new TokenWebDataServiceFake(base::ThreadTaskRunnerHandle::Get(), | 391 new TokenWebDataServiceFake(base::ThreadTaskRunnerHandle::Get(), |
| 368 data_type_thread_.task_runner()))); | 392 data_type_thread()->task_runner()))); |
| 369 web_data_service_ = static_cast<WebDataServiceFake*>( | 393 web_data_service_ = static_cast<WebDataServiceFake*>( |
| 370 web_data_wrapper_->GetAutofillWebData().get()); | 394 web_data_wrapper_->GetAutofillWebData().get()); |
| 371 web_data_service_->SetDatabase(web_database_.get()); | 395 web_data_service_->SetDatabase(web_database_.get()); |
| 372 | 396 |
| 373 personal_data_manager_ = make_scoped_ptr(new MockPersonalDataManager()); | 397 personal_data_manager_ = make_scoped_ptr(new MockPersonalDataManager()); |
| 374 | 398 |
| 375 EXPECT_CALL(*personal_data_manager_, LoadProfiles()); | 399 EXPECT_CALL(personal_data_manager(), LoadProfiles()); |
| 376 EXPECT_CALL(*personal_data_manager_, LoadCreditCards()); | 400 EXPECT_CALL(personal_data_manager(), LoadCreditCards()); |
| 377 | 401 |
| 378 personal_data_manager_->Init( | 402 personal_data_manager_->Init( |
| 379 web_data_service_, profile_sync_service_bundle_.pref_service(), | 403 web_data_service_, profile_sync_service_bundle()->pref_service(), |
| 380 profile_sync_service_bundle_.account_tracker(), | 404 profile_sync_service_bundle()->account_tracker(), |
| 381 profile_sync_service_bundle_.signin_manager(), false); | 405 profile_sync_service_bundle()->signin_manager(), false); |
| 382 | 406 |
| 383 web_data_service_->StartSyncableService(); | 407 web_data_service_->StartSyncableService(); |
| 384 | 408 |
| 385 browser_sync::ProfileSyncServiceBundle::SyncClientBuilder builder( | 409 browser_sync::ProfileSyncServiceBundle::SyncClientBuilder builder( |
| 386 &profile_sync_service_bundle_); | 410 profile_sync_service_bundle()); |
| 387 builder.SetPersonalDataManager(personal_data_manager_.get()); | 411 builder.SetPersonalDataManager(personal_data_manager_.get()); |
| 388 builder.SetSyncServiceCallback( | 412 builder.SetSyncServiceCallback(GetSyncServiceCallback()); |
| 389 base::Bind(&ProfileSyncServiceAutofillTest::GetSyncService, | |
| 390 base::Unretained(this))); | |
| 391 builder.SetSyncableServiceCallback( | 413 builder.SetSyncableServiceCallback( |
| 392 base::Bind(&ProfileSyncServiceAutofillTest::GetSyncableServiceForType, | 414 base::Bind(&ProfileSyncServiceAutofillTest::GetSyncableServiceForType, |
| 393 base::Unretained(this))); | 415 base::Unretained(this))); |
| 394 builder.set_activate_model_creation(); | 416 builder.set_activate_model_creation(); |
| 395 sync_client_owned_ = builder.Build(); | 417 sync_client_owned_ = builder.Build(); |
| 396 sync_client_ = sync_client_owned_.get(); | 418 sync_client_ = sync_client_owned_.get(); |
| 397 | 419 |
| 398 // When UpdateAutofillEntries() is called with an empty list, the return | 420 // When UpdateAutofillEntries() is called with an empty list, the return |
| 399 // value should be |true|, rather than the default of |false|. | 421 // value should be |true|, rather than the default of |false|. |
| 400 std::vector<AutofillEntry> empty; | 422 std::vector<AutofillEntry> empty; |
| 401 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(empty)) | 423 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(empty)) |
| 402 .WillRepeatedly(Return(true)); | 424 .WillRepeatedly(Return(true)); |
| 403 } | 425 } |
| 404 | 426 |
| 405 ~ProfileSyncServiceAutofillTest() override { | 427 ~ProfileSyncServiceAutofillTest() override { |
| 406 web_data_service_->ShutdownOnUIThread(); | 428 web_data_service_->ShutdownOnUIThread(); |
| 407 web_data_service_->ShutdownSyncableService(); | 429 web_data_service_->ShutdownSyncableService(); |
| 408 web_data_wrapper_->Shutdown(); | 430 web_data_wrapper_->Shutdown(); |
| 409 web_data_service_ = nullptr; | 431 web_data_service_ = nullptr; |
| 410 web_data_wrapper_.reset(); | 432 web_data_wrapper_.reset(); |
| 411 web_database_.reset(); | 433 web_database_.reset(); |
| 412 // Shut down the service explicitly before some data members from this | 434 // Shut down the service explicitly before some data members from this |
| 413 // test it needs will be deleted. | 435 // test it needs will be deleted. |
| 414 sync_service_->Shutdown(); | 436 sync_service()->Shutdown(); |
| 415 } | 437 } |
| 416 | 438 |
| 417 int GetSyncCount(syncer::ModelType type) { | 439 int GetSyncCount(syncer::ModelType type) { |
| 418 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 440 syncer::ReadTransaction trans(FROM_HERE, sync_service()->GetUserShare()); |
| 419 syncer::ReadNode node(&trans); | 441 syncer::ReadNode node(&trans); |
| 420 if (node.InitTypeRoot(type) != BaseNode::INIT_OK) | 442 if (node.InitTypeRoot(type) != BaseNode::INIT_OK) |
| 421 return 0; | 443 return 0; |
| 422 return node.GetTotalNodeCount() - 1; | 444 return node.GetTotalNodeCount() - 1; |
| 423 } | 445 } |
| 424 | 446 |
| 425 void StartSyncService(const base::Closure& callback, | 447 void StartSyncService(const base::Closure& callback, |
| 426 bool will_fail_association, | 448 bool will_fail_association, |
| 427 syncer::ModelType type) { | 449 syncer::ModelType type) { |
| 428 SigninManagerBase* signin = profile_sync_service_bundle_.signin_manager(); | 450 SigninManagerBase* signin = profile_sync_service_bundle()->signin_manager(); |
| 429 signin->SetAuthenticatedAccountInfo("12345", "test_user@gmail.com"); | 451 signin->SetAuthenticatedAccountInfo("12345", "test_user@gmail.com"); |
| 430 sync_service_ = CreateSyncService(std::move(sync_client_owned_), callback); | 452 CreateSyncService(std::move(sync_client_owned_), callback); |
| 431 | 453 |
| 432 EXPECT_CALL(*profile_sync_service_bundle_.component_factory(), | 454 EXPECT_CALL(*profile_sync_service_bundle()->component_factory(), |
| 433 CreateDataTypeManager(_, _, _, _, _)) | 455 CreateDataTypeManager(_, _, _, _, _)) |
| 434 .WillOnce(ReturnNewDataTypeManagerWithDebugListener( | 456 .WillOnce(ReturnNewDataTypeManagerWithDebugListener( |
| 435 syncer::MakeWeakHandle(debug_ptr_factory_.GetWeakPtr()))); | 457 syncer::MakeWeakHandle(debug_ptr_factory_.GetWeakPtr()))); |
| 436 | 458 |
| 437 EXPECT_CALL(*personal_data_manager_, IsDataLoaded()). | 459 EXPECT_CALL(personal_data_manager(), IsDataLoaded()) |
| 438 WillRepeatedly(Return(true)); | 460 .WillRepeatedly(Return(true)); |
| 439 | 461 |
| 440 // We need tokens to get the tests going | 462 // We need tokens to get the tests going |
| 441 profile_sync_service_bundle_.auth_service()->UpdateCredentials( | 463 profile_sync_service_bundle()->auth_service()->UpdateCredentials( |
| 442 signin->GetAuthenticatedAccountId(), "oauth2_login_token"); | 464 signin->GetAuthenticatedAccountId(), "oauth2_login_token"); |
| 443 | 465 |
| 444 sync_service_->RegisterDataTypeController(CreateDataTypeController(type)); | 466 sync_service()->RegisterDataTypeController(CreateDataTypeController(type)); |
| 445 sync_service_->Initialize(); | 467 sync_service()->Initialize(); |
| 446 base::RunLoop().Run(); | 468 base::RunLoop().Run(); |
| 447 | 469 |
| 448 // It's possible this test triggered an unrecoverable error, in which case | 470 // It's possible this test triggered an unrecoverable error, in which case |
| 449 // we can't get the sync count. | 471 // we can't get the sync count. |
| 450 if (sync_service_->IsSyncActive()) { | 472 if (sync_service()->IsSyncActive()) { |
| 451 EXPECT_EQ(GetSyncCount(type), | 473 EXPECT_EQ(GetSyncCount(type), |
| 452 association_stats_.num_sync_items_after_association); | 474 association_stats_.num_sync_items_after_association); |
| 453 } | 475 } |
| 454 EXPECT_EQ(association_stats_.num_sync_items_after_association, | 476 EXPECT_EQ(association_stats_.num_sync_items_after_association, |
| 455 association_stats_.num_sync_items_before_association + | 477 association_stats_.num_sync_items_before_association + |
| 456 association_stats_.num_sync_items_added - | 478 association_stats_.num_sync_items_added - |
| 457 association_stats_.num_sync_items_deleted); | 479 association_stats_.num_sync_items_deleted); |
| 458 } | 480 } |
| 459 | 481 |
| 460 bool AddAutofillSyncNode(const AutofillEntry& entry) { | 482 bool AddAutofillSyncNode(const AutofillEntry& entry) { |
| 461 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 483 syncer::WriteTransaction trans(FROM_HERE, sync_service()->GetUserShare()); |
| 462 syncer::WriteNode node(&trans); | 484 syncer::WriteNode node(&trans); |
| 463 std::string tag = AutocompleteSyncableService::KeyToTag( | 485 std::string tag = AutocompleteSyncableService::KeyToTag( |
| 464 base::UTF16ToUTF8(entry.key().name()), | 486 base::UTF16ToUTF8(entry.key().name()), |
| 465 base::UTF16ToUTF8(entry.key().value())); | 487 base::UTF16ToUTF8(entry.key().value())); |
| 466 syncer::WriteNode::InitUniqueByCreationResult result = | 488 syncer::WriteNode::InitUniqueByCreationResult result = |
| 467 node.InitUniqueByCreation(AUTOFILL, tag); | 489 node.InitUniqueByCreation(AUTOFILL, tag); |
| 468 if (result != syncer::WriteNode::INIT_SUCCESS) | 490 if (result != syncer::WriteNode::INIT_SUCCESS) |
| 469 return false; | 491 return false; |
| 470 | 492 |
| 471 sync_pb::EntitySpecifics specifics; | 493 sync_pb::EntitySpecifics specifics; |
| 472 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); | 494 AutocompleteSyncableService::WriteAutofillEntry(entry, &specifics); |
| 473 node.SetEntitySpecifics(specifics); | 495 node.SetEntitySpecifics(specifics); |
| 474 return true; | 496 return true; |
| 475 } | 497 } |
| 476 | 498 |
| 477 bool AddAutofillSyncNode(const AutofillProfile& profile) { | 499 bool AddAutofillSyncNode(const AutofillProfile& profile) { |
| 478 syncer::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 500 syncer::WriteTransaction trans(FROM_HERE, sync_service()->GetUserShare()); |
| 479 syncer::WriteNode node(&trans); | 501 syncer::WriteNode node(&trans); |
| 480 std::string tag = profile.guid(); | 502 std::string tag = profile.guid(); |
| 481 syncer::WriteNode::InitUniqueByCreationResult result = | 503 syncer::WriteNode::InitUniqueByCreationResult result = |
| 482 node.InitUniqueByCreation(AUTOFILL_PROFILE, tag); | 504 node.InitUniqueByCreation(AUTOFILL_PROFILE, tag); |
| 483 if (result != syncer::WriteNode::INIT_SUCCESS) | 505 if (result != syncer::WriteNode::INIT_SUCCESS) |
| 484 return false; | 506 return false; |
| 485 | 507 |
| 486 sync_pb::EntitySpecifics specifics; | 508 sync_pb::EntitySpecifics specifics; |
| 487 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); | 509 AutofillProfileSyncableService::WriteAutofillProfile(profile, &specifics); |
| 488 node.SetEntitySpecifics(specifics); | 510 node.SetEntitySpecifics(specifics); |
| 489 return true; | 511 return true; |
| 490 } | 512 } |
| 491 | 513 |
| 492 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, | 514 bool GetAutofillEntriesFromSyncDB(std::vector<AutofillEntry>* entries, |
| 493 std::vector<AutofillProfile>* profiles) { | 515 std::vector<AutofillProfile>* profiles) { |
| 494 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 516 syncer::ReadTransaction trans(FROM_HERE, sync_service()->GetUserShare()); |
| 495 syncer::ReadNode autofill_root(&trans); | 517 syncer::ReadNode autofill_root(&trans); |
| 496 if (autofill_root.InitTypeRoot(AUTOFILL) != BaseNode::INIT_OK) { | 518 if (autofill_root.InitTypeRoot(AUTOFILL) != BaseNode::INIT_OK) { |
| 497 return false; | 519 return false; |
| 498 } | 520 } |
| 499 | 521 |
| 500 int64_t child_id = autofill_root.GetFirstChildId(); | 522 int64_t child_id = autofill_root.GetFirstChildId(); |
| 501 while (child_id != syncer::kInvalidId) { | 523 while (child_id != syncer::kInvalidId) { |
| 502 syncer::ReadNode child_node(&trans); | 524 syncer::ReadNode child_node(&trans); |
| 503 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) | 525 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) |
| 504 return false; | 526 return false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 523 autofill.profile(), &p); | 545 autofill.profile(), &p); |
| 524 profiles->push_back(p); | 546 profiles->push_back(p); |
| 525 } | 547 } |
| 526 child_id = child_node.GetSuccessorId(); | 548 child_id = child_node.GetSuccessorId(); |
| 527 } | 549 } |
| 528 return true; | 550 return true; |
| 529 } | 551 } |
| 530 | 552 |
| 531 bool GetAutofillProfilesFromSyncDBUnderProfileNode( | 553 bool GetAutofillProfilesFromSyncDBUnderProfileNode( |
| 532 std::vector<AutofillProfile>* profiles) { | 554 std::vector<AutofillProfile>* profiles) { |
| 533 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 555 syncer::ReadTransaction trans(FROM_HERE, sync_service()->GetUserShare()); |
| 534 syncer::ReadNode autofill_root(&trans); | 556 syncer::ReadNode autofill_root(&trans); |
| 535 if (autofill_root.InitTypeRoot(AUTOFILL_PROFILE) != BaseNode::INIT_OK) { | 557 if (autofill_root.InitTypeRoot(AUTOFILL_PROFILE) != BaseNode::INIT_OK) { |
| 536 return false; | 558 return false; |
| 537 } | 559 } |
| 538 | 560 |
| 539 int64_t child_id = autofill_root.GetFirstChildId(); | 561 int64_t child_id = autofill_root.GetFirstChildId(); |
| 540 while (child_id != syncer::kInvalidId) { | 562 while (child_id != syncer::kInvalidId) { |
| 541 syncer::ReadNode child_node(&trans); | 563 syncer::ReadNode child_node(&trans); |
| 542 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) | 564 if (child_node.InitByIdLookup(child_id) != BaseNode::INIT_OK) |
| 543 return false; | 565 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 556 | 578 |
| 557 void SetIdleChangeProcessorExpectations() { | 579 void SetIdleChangeProcessorExpectations() { |
| 558 EXPECT_CALL(autofill_table_, RemoveFormElement(_, _)).Times(0); | 580 EXPECT_CALL(autofill_table_, RemoveFormElement(_, _)).Times(0); |
| 559 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _, _)).Times(0); | 581 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _, _)).Times(0); |
| 560 | 582 |
| 561 // Only permit UpdateAutofillEntries() to be called with an empty list. | 583 // Only permit UpdateAutofillEntries() to be called with an empty list. |
| 562 std::vector<AutofillEntry> empty; | 584 std::vector<AutofillEntry> empty; |
| 563 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(Not(empty))).Times(0); | 585 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(Not(empty))).Times(0); |
| 564 } | 586 } |
| 565 | 587 |
| 566 static AutofillEntry MakeAutofillEntry(const char* name, | |
| 567 const char* value, | |
| 568 int time_shift0, | |
| 569 int time_shift1) { | |
| 570 // Time deep in the past would cause Autocomplete sync to discard the | |
| 571 // entries. | |
| 572 static Time base_time = Time::Now().LocalMidnight(); | |
| 573 | |
| 574 Time date_created = base_time + TimeDelta::FromSeconds(time_shift0); | |
| 575 Time date_last_used = date_created; | |
| 576 if (time_shift1 >= 0) | |
| 577 date_last_used = base_time + TimeDelta::FromSeconds(time_shift1); | |
| 578 return AutofillEntry( | |
| 579 AutofillKey(base::ASCIIToUTF16(name), base::ASCIIToUTF16(value)), | |
| 580 date_created, date_last_used); | |
| 581 } | |
| 582 | |
| 583 static AutofillEntry MakeAutofillEntry(const char* name, | |
| 584 const char* value, | |
| 585 int time_shift) { | |
| 586 return MakeAutofillEntry(name, value, time_shift, -1); | |
| 587 } | |
| 588 | |
| 589 sync_driver::DataTypeController* CreateDataTypeController( | 588 sync_driver::DataTypeController* CreateDataTypeController( |
| 590 syncer::ModelType type) { | 589 syncer::ModelType type) { |
| 591 DCHECK(type == AUTOFILL || type == AUTOFILL_PROFILE); | 590 DCHECK(type == AUTOFILL || type == AUTOFILL_PROFILE); |
| 592 if (type == AUTOFILL) { | 591 if (type == AUTOFILL) { |
| 593 return new AutofillDataTypeController( | 592 return new AutofillDataTypeController(base::ThreadTaskRunnerHandle::Get(), |
| 594 base::ThreadTaskRunnerHandle::Get(), data_type_thread_.task_runner(), | 593 data_type_thread()->task_runner(), |
| 595 base::Bind(&base::DoNothing), sync_client_, web_data_service_); | 594 base::Bind(&base::DoNothing), |
| 595 sync_client_, web_data_service_); |
| 596 } else { | 596 } else { |
| 597 return new AutofillProfileDataTypeController( | 597 return new AutofillProfileDataTypeController( |
| 598 base::ThreadTaskRunnerHandle::Get(), data_type_thread_.task_runner(), | 598 base::ThreadTaskRunnerHandle::Get(), |
| 599 base::Bind(&base::DoNothing), sync_client_, web_data_service_); | 599 data_type_thread()->task_runner(), base::Bind(&base::DoNothing), |
| 600 sync_client_, web_data_service_); |
| 600 } | 601 } |
| 601 } | 602 } |
| 602 | 603 |
| 604 AutofillTableMock& autofill_table() { return autofill_table_; } |
| 605 |
| 606 MockPersonalDataManager& personal_data_manager() { |
| 607 return *personal_data_manager_; |
| 608 } |
| 609 |
| 610 WebDataServiceFake* web_data_service() { return web_data_service_.get(); } |
| 611 |
| 612 private: |
| 603 friend class AddAutofillHelper<AutofillEntry>; | 613 friend class AddAutofillHelper<AutofillEntry>; |
| 604 friend class AddAutofillHelper<AutofillProfile>; | 614 friend class AddAutofillHelper<AutofillProfile>; |
| 605 friend class FakeServerUpdater; | |
| 606 | |
| 607 AutofillTableMock autofill_table_; | |
| 608 scoped_ptr<WebDatabaseFake> web_database_; | |
| 609 scoped_ptr<MockWebDataServiceWrapper> web_data_wrapper_; | |
| 610 scoped_refptr<WebDataServiceFake> web_data_service_; | |
| 611 scoped_ptr<MockPersonalDataManager> personal_data_manager_; | |
| 612 syncer::DataTypeAssociationStats association_stats_; | |
| 613 base::WeakPtrFactory<DataTypeDebugInfoListener> debug_ptr_factory_; | |
| 614 // |sync_client_owned_| keeps the created client until it is passed to the | |
| 615 // created ProfileSyncService. |sync_client_| just keeps a weak reference to | |
| 616 // the client the whole time. | |
| 617 scoped_ptr<sync_driver::FakeSyncClient> sync_client_owned_; | |
| 618 sync_driver::FakeSyncClient* sync_client_; | |
| 619 | |
| 620 private: | |
| 621 sync_driver::SyncService* GetSyncService() { return sync_service_.get(); } | |
| 622 | 615 |
| 623 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( | 616 base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( |
| 624 syncer::ModelType type) { | 617 syncer::ModelType type) { |
| 625 DCHECK(type == AUTOFILL || type == AUTOFILL_PROFILE); | 618 DCHECK(type == AUTOFILL || type == AUTOFILL_PROFILE); |
| 626 if (type == AUTOFILL) { | 619 if (type == AUTOFILL) { |
| 627 return AutocompleteSyncableService::FromWebDataService( | 620 return AutocompleteSyncableService::FromWebDataService( |
| 628 web_data_service_.get()) | 621 web_data_service_.get()) |
| 629 ->AsWeakPtr(); | 622 ->AsWeakPtr(); |
| 630 } else { | 623 } else { |
| 631 return AutofillProfileSyncableService::FromWebDataService( | 624 return AutofillProfileSyncableService::FromWebDataService( |
| 632 web_data_service_.get()) | 625 web_data_service_.get()) |
| 633 ->AsWeakPtr(); | 626 ->AsWeakPtr(); |
| 634 } | 627 } |
| 635 } | 628 } |
| 636 | 629 |
| 630 AutofillTableMock autofill_table_; |
| 631 scoped_ptr<WebDatabaseFake> web_database_; |
| 632 scoped_ptr<MockWebDataServiceWrapper> web_data_wrapper_; |
| 633 scoped_refptr<WebDataServiceFake> web_data_service_; |
| 634 scoped_ptr<MockPersonalDataManager> personal_data_manager_; |
| 635 syncer::DataTypeAssociationStats association_stats_; |
| 636 base::WeakPtrFactory<DataTypeDebugInfoListener> debug_ptr_factory_; |
| 637 // |sync_client_owned_| keeps the created client until it is passed to the |
| 638 // created ProfileSyncService. |sync_client_| just keeps a weak reference to |
| 639 // the client the whole time. |
| 640 scoped_ptr<sync_driver::FakeSyncClient> sync_client_owned_; |
| 641 sync_driver::FakeSyncClient* sync_client_; |
| 642 |
| 637 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAutofillTest); | 643 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceAutofillTest); |
| 638 }; | 644 }; |
| 639 | 645 |
| 640 template <class T> | 646 template <class T> |
| 641 class AddAutofillHelper { | 647 class AddAutofillHelper { |
| 642 public: | 648 public: |
| 643 AddAutofillHelper(ProfileSyncServiceAutofillTest* test, | 649 AddAutofillHelper(ProfileSyncServiceAutofillTest* test, |
| 644 const std::vector<T>& entries) | 650 const std::vector<T>& entries) |
| 645 : callback_(base::Bind(&AddAutofillHelper::AddAutofillCallback, | 651 : callback_(base::Bind(&AddAutofillHelper::AddAutofillCallback, |
| 646 base::Unretained(this), test, entries)), | 652 base::Unretained(this), test, entries)), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 }; | 696 }; |
| 691 | 697 |
| 692 // Our fake server updater. Needs the RefCountedThreadSafe inheritance so we can | 698 // Our fake server updater. Needs the RefCountedThreadSafe inheritance so we can |
| 693 // post tasks with it. | 699 // post tasks with it. |
| 694 class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> { | 700 class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> { |
| 695 public: | 701 public: |
| 696 FakeServerUpdater(TestProfileSyncService* service, | 702 FakeServerUpdater(TestProfileSyncService* service, |
| 697 WaitableEvent* wait_for_start, | 703 WaitableEvent* wait_for_start, |
| 698 WaitableEvent* wait_for_syncapi, | 704 WaitableEvent* wait_for_syncapi, |
| 699 scoped_refptr<base::SequencedTaskRunner> db_thread) | 705 scoped_refptr<base::SequencedTaskRunner> db_thread) |
| 700 : entry_(ProfileSyncServiceAutofillTest::MakeAutofillEntry("0", "0", 0)), | 706 : entry_(MakeAutofillEntry("0", "0", 0)), |
| 701 service_(service), | 707 service_(service), |
| 702 wait_for_start_(wait_for_start), | 708 wait_for_start_(wait_for_start), |
| 703 wait_for_syncapi_(wait_for_syncapi), | 709 wait_for_syncapi_(wait_for_syncapi), |
| 704 is_finished_(false, false), | 710 is_finished_(false, false), |
| 705 db_thread_(db_thread) {} | 711 db_thread_(db_thread) {} |
| 706 | 712 |
| 707 void Update() { | 713 void Update() { |
| 708 // This gets called in a modelsafeworker thread. | 714 // This gets called in a modelsafeworker thread. |
| 709 ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread()); | 715 ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread()); |
| 710 | 716 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 DISALLOW_COPY_AND_ASSIGN(FakeServerUpdater); | 788 DISALLOW_COPY_AND_ASSIGN(FakeServerUpdater); |
| 783 }; | 789 }; |
| 784 | 790 |
| 785 // TODO(skrul): Test abort startup. | 791 // TODO(skrul): Test abort startup. |
| 786 // TODO(skrul): Test processing of cloud changes. | 792 // TODO(skrul): Test processing of cloud changes. |
| 787 // TODO(tim): Add autofill data type controller test, and a case to cover | 793 // TODO(tim): Add autofill data type controller test, and a case to cover |
| 788 // waiting for the PersonalDataManager. | 794 // waiting for the PersonalDataManager. |
| 789 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) { | 795 TEST_F(ProfileSyncServiceAutofillTest, FailModelAssociation) { |
| 790 // Don't create the root autofill node so startup fails. | 796 // Don't create the root autofill node so startup fails. |
| 791 StartSyncService(base::Closure(), true, AUTOFILL); | 797 StartSyncService(base::Closure(), true, AUTOFILL); |
| 792 EXPECT_TRUE(sync_service_->HasUnrecoverableError()); | 798 EXPECT_TRUE(sync_service()->HasUnrecoverableError()); |
| 793 } | 799 } |
| 794 | 800 |
| 795 TEST_F(ProfileSyncServiceAutofillTest, EmptyNativeEmptySync) { | 801 TEST_F(ProfileSyncServiceAutofillTest, EmptyNativeEmptySync) { |
| 796 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true)); | 802 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
| 803 .WillOnce(Return(true)); |
| 797 SetIdleChangeProcessorExpectations(); | 804 SetIdleChangeProcessorExpectations(); |
| 798 CreateRootHelper create_root(this, AUTOFILL); | 805 CreateRootHelper create_root(this, AUTOFILL); |
| 799 EXPECT_CALL(*personal_data_manager_, Refresh()); | 806 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 800 StartSyncService(create_root.callback(), false, AUTOFILL); | 807 StartSyncService(create_root.callback(), false, AUTOFILL); |
| 801 EXPECT_TRUE(create_root.success()); | 808 EXPECT_TRUE(create_root.success()); |
| 802 std::vector<AutofillEntry> sync_entries; | 809 std::vector<AutofillEntry> sync_entries; |
| 803 std::vector<AutofillProfile> sync_profiles; | 810 std::vector<AutofillProfile> sync_profiles; |
| 804 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 811 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 805 EXPECT_EQ(0U, sync_entries.size()); | 812 EXPECT_EQ(0U, sync_entries.size()); |
| 806 EXPECT_EQ(0U, sync_profiles.size()); | 813 EXPECT_EQ(0U, sync_profiles.size()); |
| 807 } | 814 } |
| 808 | 815 |
| 809 TEST_F(ProfileSyncServiceAutofillTest, HasNativeEntriesEmptySync) { | 816 TEST_F(ProfileSyncServiceAutofillTest, HasNativeEntriesEmptySync) { |
| 810 std::vector<AutofillEntry> entries; | 817 std::vector<AutofillEntry> entries; |
| 811 entries.push_back(MakeAutofillEntry("foo", "bar", 1)); | 818 entries.push_back(MakeAutofillEntry("foo", "bar", 1)); |
| 812 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). | 819 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
| 813 WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); | 820 .WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); |
| 814 SetIdleChangeProcessorExpectations(); | 821 SetIdleChangeProcessorExpectations(); |
| 815 CreateRootHelper create_root(this, AUTOFILL); | 822 CreateRootHelper create_root(this, AUTOFILL); |
| 816 EXPECT_CALL(*personal_data_manager_, Refresh()); | 823 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 817 StartSyncService(create_root.callback(), false, AUTOFILL); | 824 StartSyncService(create_root.callback(), false, AUTOFILL); |
| 818 ASSERT_TRUE(create_root.success()); | 825 ASSERT_TRUE(create_root.success()); |
| 819 std::vector<AutofillEntry> sync_entries; | 826 std::vector<AutofillEntry> sync_entries; |
| 820 std::vector<AutofillProfile> sync_profiles; | 827 std::vector<AutofillProfile> sync_profiles; |
| 821 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 828 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 822 ASSERT_EQ(1U, entries.size()); | 829 ASSERT_EQ(1U, entries.size()); |
| 823 EXPECT_TRUE(entries[0] == sync_entries[0]); | 830 EXPECT_TRUE(entries[0] == sync_entries[0]); |
| 824 EXPECT_EQ(0U, sync_profiles.size()); | 831 EXPECT_EQ(0U, sync_profiles.size()); |
| 825 } | 832 } |
| 826 | 833 |
| 827 TEST_F(ProfileSyncServiceAutofillTest, HasProfileEmptySync) { | 834 TEST_F(ProfileSyncServiceAutofillTest, HasProfileEmptySync) { |
| 828 std::vector<AutofillProfile*> profiles; | 835 std::vector<AutofillProfile*> profiles; |
| 829 std::vector<AutofillProfile> expected_profiles; | 836 std::vector<AutofillProfile> expected_profiles; |
| 830 // Owned by GetAutofillProfiles caller. | 837 // Owned by GetAutofillProfiles caller. |
| 831 AutofillProfile* profile0 = new AutofillProfile; | 838 AutofillProfile* profile0 = new AutofillProfile; |
| 832 autofill::test::SetProfileInfoWithGuid(profile0, | 839 autofill::test::SetProfileInfoWithGuid(profile0, |
| 833 "54B3F9AA-335E-4F71-A27D-719C41564230", "Billing", | 840 "54B3F9AA-335E-4F71-A27D-719C41564230", "Billing", |
| 834 "Mitchell", "Morrison", | 841 "Mitchell", "Morrison", |
| 835 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 842 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 836 "91601", "US", "12345678910"); | 843 "91601", "US", "12345678910"); |
| 837 profiles.push_back(profile0); | 844 profiles.push_back(profile0); |
| 838 expected_profiles.push_back(*profile0); | 845 expected_profiles.push_back(*profile0); |
| 839 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)). | 846 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| 840 WillOnce(DoAll(SetArgumentPointee<0>(profiles), Return(true))); | 847 .WillOnce(DoAll(SetArgumentPointee<0>(profiles), Return(true))); |
| 841 EXPECT_CALL(*personal_data_manager_, Refresh()); | 848 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 842 SetIdleChangeProcessorExpectations(); | 849 SetIdleChangeProcessorExpectations(); |
| 843 CreateRootHelper create_root(this, AUTOFILL_PROFILE); | 850 CreateRootHelper create_root(this, AUTOFILL_PROFILE); |
| 844 StartSyncService(create_root.callback(), false, AUTOFILL_PROFILE); | 851 StartSyncService(create_root.callback(), false, AUTOFILL_PROFILE); |
| 845 ASSERT_TRUE(create_root.success()); | 852 ASSERT_TRUE(create_root.success()); |
| 846 std::vector<AutofillProfile> sync_profiles; | 853 std::vector<AutofillProfile> sync_profiles; |
| 847 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(&sync_profiles)); | 854 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode(&sync_profiles)); |
| 848 EXPECT_EQ(1U, sync_profiles.size()); | 855 EXPECT_EQ(1U, sync_profiles.size()); |
| 849 EXPECT_EQ(0, expected_profiles[0].Compare(sync_profiles[0])); | 856 EXPECT_EQ(0, expected_profiles[0].Compare(sync_profiles[0])); |
| 850 } | 857 } |
| 851 | 858 |
| 852 TEST_F(ProfileSyncServiceAutofillTest, HasNativeWithDuplicatesEmptySync) { | 859 TEST_F(ProfileSyncServiceAutofillTest, HasNativeWithDuplicatesEmptySync) { |
| 853 // There is buggy autofill code that allows duplicate name/value | 860 // There is buggy autofill code that allows duplicate name/value |
| 854 // pairs to exist in the database with separate pair_ids. | 861 // pairs to exist in the database with separate pair_ids. |
| 855 std::vector<AutofillEntry> entries; | 862 std::vector<AutofillEntry> entries; |
| 856 entries.push_back(MakeAutofillEntry("foo", "bar", 1)); | 863 entries.push_back(MakeAutofillEntry("foo", "bar", 1)); |
| 857 entries.push_back(MakeAutofillEntry("dup", "", 2)); | 864 entries.push_back(MakeAutofillEntry("dup", "", 2)); |
| 858 entries.push_back(MakeAutofillEntry("dup", "", 3)); | 865 entries.push_back(MakeAutofillEntry("dup", "", 3)); |
| 859 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). | 866 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
| 860 WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); | 867 .WillOnce(DoAll(SetArgumentPointee<0>(entries), Return(true))); |
| 861 SetIdleChangeProcessorExpectations(); | 868 SetIdleChangeProcessorExpectations(); |
| 862 CreateRootHelper create_root(this, AUTOFILL); | 869 CreateRootHelper create_root(this, AUTOFILL); |
| 863 EXPECT_CALL(*personal_data_manager_, Refresh()); | 870 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 864 StartSyncService(create_root.callback(), false, AUTOFILL); | 871 StartSyncService(create_root.callback(), false, AUTOFILL); |
| 865 ASSERT_TRUE(create_root.success()); | 872 ASSERT_TRUE(create_root.success()); |
| 866 std::vector<AutofillEntry> sync_entries; | 873 std::vector<AutofillEntry> sync_entries; |
| 867 std::vector<AutofillProfile> sync_profiles; | 874 std::vector<AutofillProfile> sync_profiles; |
| 868 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 875 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 869 EXPECT_EQ(2U, sync_entries.size()); | 876 EXPECT_EQ(2U, sync_entries.size()); |
| 870 } | 877 } |
| 871 | 878 |
| 872 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncNoMerge) { | 879 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncNoMerge) { |
| 873 AutofillEntry native_entry(MakeAutofillEntry("native", "entry", 1)); | 880 AutofillEntry native_entry(MakeAutofillEntry("native", "entry", 1)); |
| 874 AutofillEntry sync_entry(MakeAutofillEntry("sync", "entry", 2)); | 881 AutofillEntry sync_entry(MakeAutofillEntry("sync", "entry", 2)); |
| 875 | 882 |
| 876 std::vector<AutofillEntry> native_entries; | 883 std::vector<AutofillEntry> native_entries; |
| 877 native_entries.push_back(native_entry); | 884 native_entries.push_back(native_entry); |
| 878 | 885 |
| 879 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). | 886 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
| 880 WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); | 887 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); |
| 881 | 888 |
| 882 std::vector<AutofillEntry> sync_entries; | 889 std::vector<AutofillEntry> sync_entries; |
| 883 sync_entries.push_back(sync_entry); | 890 sync_entries.push_back(sync_entry); |
| 884 | 891 |
| 885 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); | 892 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); |
| 886 | 893 |
| 887 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(ElementsAre(sync_entry))). | 894 EXPECT_CALL(autofill_table(), UpdateAutofillEntries(ElementsAre(sync_entry))) |
| 888 WillOnce(Return(true)); | 895 .WillOnce(Return(true)); |
| 889 | 896 |
| 890 EXPECT_CALL(*personal_data_manager_, Refresh()); | 897 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 891 StartSyncService(add_autofill.callback(), false, AUTOFILL); | 898 StartSyncService(add_autofill.callback(), false, AUTOFILL); |
| 892 ASSERT_TRUE(add_autofill.success()); | 899 ASSERT_TRUE(add_autofill.success()); |
| 893 | 900 |
| 894 std::set<AutofillEntry> expected_entries; | 901 std::set<AutofillEntry> expected_entries; |
| 895 expected_entries.insert(native_entry); | 902 expected_entries.insert(native_entry); |
| 896 expected_entries.insert(sync_entry); | 903 expected_entries.insert(sync_entry); |
| 897 | 904 |
| 898 std::vector<AutofillEntry> new_sync_entries; | 905 std::vector<AutofillEntry> new_sync_entries; |
| 899 std::vector<AutofillProfile> new_sync_profiles; | 906 std::vector<AutofillProfile> new_sync_profiles; |
| 900 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, | 907 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, |
| 901 &new_sync_profiles)); | 908 &new_sync_profiles)); |
| 902 std::set<AutofillEntry> new_sync_entries_set(new_sync_entries.begin(), | 909 std::set<AutofillEntry> new_sync_entries_set(new_sync_entries.begin(), |
| 903 new_sync_entries.end()); | 910 new_sync_entries.end()); |
| 904 | 911 |
| 905 EXPECT_TRUE(expected_entries == new_sync_entries_set); | 912 EXPECT_TRUE(expected_entries == new_sync_entries_set); |
| 906 } | 913 } |
| 907 | 914 |
| 908 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeEntry) { | 915 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeEntry) { |
| 909 AutofillEntry native_entry(MakeAutofillEntry("merge", "entry", 1)); | 916 AutofillEntry native_entry(MakeAutofillEntry("merge", "entry", 1)); |
| 910 AutofillEntry sync_entry(MakeAutofillEntry("merge", "entry", 2)); | 917 AutofillEntry sync_entry(MakeAutofillEntry("merge", "entry", 2)); |
| 911 AutofillEntry merged_entry(MakeAutofillEntry("merge", "entry", 1, 2)); | 918 AutofillEntry merged_entry(MakeAutofillEntry("merge", "entry", 1, 2)); |
| 912 | 919 |
| 913 std::vector<AutofillEntry> native_entries; | 920 std::vector<AutofillEntry> native_entries; |
| 914 native_entries.push_back(native_entry); | 921 native_entries.push_back(native_entry); |
| 915 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). | 922 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
| 916 WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); | 923 .WillOnce(DoAll(SetArgumentPointee<0>(native_entries), Return(true))); |
| 917 | 924 |
| 918 std::vector<AutofillEntry> sync_entries; | 925 std::vector<AutofillEntry> sync_entries; |
| 919 sync_entries.push_back(sync_entry); | 926 sync_entries.push_back(sync_entry); |
| 920 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); | 927 AddAutofillHelper<AutofillEntry> add_autofill(this, sync_entries); |
| 921 | 928 |
| 922 EXPECT_CALL(autofill_table_, | 929 EXPECT_CALL(autofill_table(), |
| 923 UpdateAutofillEntries(ElementsAre(merged_entry))).WillOnce(Return(true)); | 930 UpdateAutofillEntries(ElementsAre(merged_entry))) |
| 924 EXPECT_CALL(*personal_data_manager_, Refresh()); | 931 .WillOnce(Return(true)); |
| 932 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 925 StartSyncService(add_autofill.callback(), false, AUTOFILL); | 933 StartSyncService(add_autofill.callback(), false, AUTOFILL); |
| 926 ASSERT_TRUE(add_autofill.success()); | 934 ASSERT_TRUE(add_autofill.success()); |
| 927 | 935 |
| 928 std::vector<AutofillEntry> new_sync_entries; | 936 std::vector<AutofillEntry> new_sync_entries; |
| 929 std::vector<AutofillProfile> new_sync_profiles; | 937 std::vector<AutofillProfile> new_sync_profiles; |
| 930 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, | 938 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, |
| 931 &new_sync_profiles)); | 939 &new_sync_profiles)); |
| 932 ASSERT_EQ(1U, new_sync_entries.size()); | 940 ASSERT_EQ(1U, new_sync_entries.size()); |
| 933 EXPECT_TRUE(merged_entry == new_sync_entries[0]); | 941 EXPECT_TRUE(merged_entry == new_sync_entries[0]); |
| 934 } | 942 } |
| 935 | 943 |
| 936 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfile) { | 944 TEST_F(ProfileSyncServiceAutofillTest, HasNativeHasSyncMergeProfile) { |
| 937 AutofillProfile sync_profile; | 945 AutofillProfile sync_profile; |
| 938 autofill::test::SetProfileInfoWithGuid(&sync_profile, | 946 autofill::test::SetProfileInfoWithGuid(&sync_profile, |
| 939 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", | 947 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", |
| 940 "Mitchell", "Morrison", | 948 "Mitchell", "Morrison", |
| 941 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 949 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 942 "91601", "US", "12345678910"); | 950 "91601", "US", "12345678910"); |
| 943 | 951 |
| 944 AutofillProfile* native_profile = new AutofillProfile; | 952 AutofillProfile* native_profile = new AutofillProfile; |
| 945 autofill::test::SetProfileInfoWithGuid(native_profile, | 953 autofill::test::SetProfileInfoWithGuid(native_profile, |
| 946 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", "Alicia", "Saenz", | 954 "23355099-1170-4B71-8ED4-144470CC9EBE", "Billing", "Alicia", "Saenz", |
| 947 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 955 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
| 948 "32801", "US", "19482937549"); | 956 "32801", "US", "19482937549"); |
| 949 | 957 |
| 950 std::vector<AutofillProfile*> native_profiles; | 958 std::vector<AutofillProfile*> native_profiles; |
| 951 native_profiles.push_back(native_profile); | 959 native_profiles.push_back(native_profile); |
| 952 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)). | 960 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| 953 WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 961 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
| 954 | 962 |
| 955 std::vector<AutofillProfile> sync_profiles; | 963 std::vector<AutofillProfile> sync_profiles; |
| 956 sync_profiles.push_back(sync_profile); | 964 sync_profiles.push_back(sync_profile); |
| 957 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 965 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| 958 | 966 |
| 959 EXPECT_CALL(autofill_table_, | 967 EXPECT_CALL(autofill_table(), |
| 960 UpdateAutofillProfile(MatchProfiles(sync_profile))). | 968 UpdateAutofillProfile(MatchProfiles(sync_profile))) |
| 961 WillOnce(Return(true)); | 969 .WillOnce(Return(true)); |
| 962 EXPECT_CALL(*personal_data_manager_, Refresh()); | 970 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 963 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); | 971 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
| 964 ASSERT_TRUE(add_autofill.success()); | 972 ASSERT_TRUE(add_autofill.success()); |
| 965 | 973 |
| 966 std::vector<AutofillProfile> new_sync_profiles; | 974 std::vector<AutofillProfile> new_sync_profiles; |
| 967 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( | 975 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( |
| 968 &new_sync_profiles)); | 976 &new_sync_profiles)); |
| 969 ASSERT_EQ(1U, new_sync_profiles.size()); | 977 ASSERT_EQ(1U, new_sync_profiles.size()); |
| 970 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); | 978 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); |
| 971 } | 979 } |
| 972 | 980 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 983 autofill::test::SetProfileInfoWithGuid(native_profile, | 991 autofill::test::SetProfileInfoWithGuid(native_profile, |
| 984 "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", "Alicia", "Saenz", | 992 "23355099-1170-4B71-8ED4-144470CC9EBF", "Billing", "Alicia", "Saenz", |
| 985 "joewayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 993 "joewayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 986 "91601", "US", "19482937549"); | 994 "91601", "US", "19482937549"); |
| 987 | 995 |
| 988 AutofillProfile expected_profile(sync_profile); | 996 AutofillProfile expected_profile(sync_profile); |
| 989 expected_profile.OverwriteWith(*native_profile, "en-US"); | 997 expected_profile.OverwriteWith(*native_profile, "en-US"); |
| 990 | 998 |
| 991 std::vector<AutofillProfile*> native_profiles; | 999 std::vector<AutofillProfile*> native_profiles; |
| 992 native_profiles.push_back(native_profile); | 1000 native_profiles.push_back(native_profile); |
| 993 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)). | 1001 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| 994 WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1002 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
| 995 EXPECT_CALL(autofill_table_, | 1003 EXPECT_CALL(autofill_table(), |
| 996 AddAutofillProfile(MatchProfiles(expected_profile))). | 1004 AddAutofillProfile(MatchProfiles(expected_profile))) |
| 997 WillOnce(Return(true)); | 1005 .WillOnce(Return(true)); |
| 998 EXPECT_CALL(autofill_table_, | 1006 EXPECT_CALL(autofill_table(), |
| 999 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")). | 1007 RemoveAutofillProfile("23355099-1170-4B71-8ED4-144470CC9EBF")) |
| 1000 WillOnce(Return(true)); | 1008 .WillOnce(Return(true)); |
| 1001 std::vector<AutofillProfile> sync_profiles; | 1009 std::vector<AutofillProfile> sync_profiles; |
| 1002 sync_profiles.push_back(sync_profile); | 1010 sync_profiles.push_back(sync_profile); |
| 1003 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 1011 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| 1004 | 1012 |
| 1005 EXPECT_CALL(*personal_data_manager_, Refresh()); | 1013 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 1006 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); | 1014 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
| 1007 ASSERT_TRUE(add_autofill.success()); | 1015 ASSERT_TRUE(add_autofill.success()); |
| 1008 | 1016 |
| 1009 std::vector<AutofillProfile> new_sync_profiles; | 1017 std::vector<AutofillProfile> new_sync_profiles; |
| 1010 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( | 1018 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( |
| 1011 &new_sync_profiles)); | 1019 &new_sync_profiles)); |
| 1012 ASSERT_EQ(1U, new_sync_profiles.size()); | 1020 ASSERT_EQ(1U, new_sync_profiles.size()); |
| 1013 // Check that key fields are the same. | 1021 // Check that key fields are the same. |
| 1014 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); | 1022 EXPECT_TRUE(new_sync_profiles[0].IsSubsetOf(sync_profile, "en-US")); |
| 1015 } | 1023 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1026 std::string native_guid = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; | 1034 std::string native_guid = "EDC609ED-7EEE-4F27-B00C-423242A9C44B"; |
| 1027 AutofillProfile* native_profile = new AutofillProfile; | 1035 AutofillProfile* native_profile = new AutofillProfile; |
| 1028 autofill::test::SetProfileInfoWithGuid(native_profile, | 1036 autofill::test::SetProfileInfoWithGuid(native_profile, |
| 1029 native_guid.c_str(), "Billing", | 1037 native_guid.c_str(), "Billing", |
| 1030 "Mitchell", "Morrison", | 1038 "Mitchell", "Morrison", |
| 1031 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", | 1039 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
| 1032 "91601", "US", "12345678910"); | 1040 "91601", "US", "12345678910"); |
| 1033 | 1041 |
| 1034 std::vector<AutofillProfile*> native_profiles; | 1042 std::vector<AutofillProfile*> native_profiles; |
| 1035 native_profiles.push_back(native_profile); | 1043 native_profiles.push_back(native_profile); |
| 1036 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)). | 1044 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| 1037 WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1045 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
| 1038 | 1046 |
| 1039 std::vector<AutofillProfile> sync_profiles; | 1047 std::vector<AutofillProfile> sync_profiles; |
| 1040 sync_profiles.push_back(sync_profile); | 1048 sync_profiles.push_back(sync_profile); |
| 1041 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 1049 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| 1042 | 1050 |
| 1043 EXPECT_CALL(autofill_table_, AddAutofillProfile(_)). | 1051 EXPECT_CALL(autofill_table(), AddAutofillProfile(_)).WillOnce(Return(true)); |
| 1044 WillOnce(Return(true)); | 1052 EXPECT_CALL(autofill_table(), RemoveAutofillProfile(native_guid)) |
| 1045 EXPECT_CALL(autofill_table_, RemoveAutofillProfile(native_guid)). | 1053 .WillOnce(Return(true)); |
| 1046 WillOnce(Return(true)); | 1054 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 1047 EXPECT_CALL(*personal_data_manager_, Refresh()); | |
| 1048 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); | 1055 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
| 1049 ASSERT_TRUE(add_autofill.success()); | 1056 ASSERT_TRUE(add_autofill.success()); |
| 1050 | 1057 |
| 1051 std::vector<AutofillProfile> new_sync_profiles; | 1058 std::vector<AutofillProfile> new_sync_profiles; |
| 1052 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( | 1059 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( |
| 1053 &new_sync_profiles)); | 1060 &new_sync_profiles)); |
| 1054 ASSERT_EQ(1U, new_sync_profiles.size()); | 1061 ASSERT_EQ(1U, new_sync_profiles.size()); |
| 1055 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); | 1062 EXPECT_EQ(0, sync_profile.Compare(new_sync_profiles[0])); |
| 1056 EXPECT_EQ(sync_profile.guid(), new_sync_profiles[0].guid()); | 1063 EXPECT_EQ(sync_profile.guid(), new_sync_profiles[0].guid()); |
| 1057 } | 1064 } |
| 1058 | 1065 |
| 1059 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddEntry) { | 1066 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddEntry) { |
| 1060 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)).WillOnce(Return(true)); | 1067 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
| 1061 EXPECT_CALL(*personal_data_manager_, Refresh()); | 1068 .WillOnce(Return(true)); |
| 1069 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 1062 SetIdleChangeProcessorExpectations(); | 1070 SetIdleChangeProcessorExpectations(); |
| 1063 CreateRootHelper create_root(this, AUTOFILL); | 1071 CreateRootHelper create_root(this, AUTOFILL); |
| 1064 StartSyncService(create_root.callback(), false, AUTOFILL); | 1072 StartSyncService(create_root.callback(), false, AUTOFILL); |
| 1065 ASSERT_TRUE(create_root.success()); | 1073 ASSERT_TRUE(create_root.success()); |
| 1066 | 1074 |
| 1067 AutofillEntry added_entry(MakeAutofillEntry("added", "entry", 1)); | 1075 AutofillEntry added_entry(MakeAutofillEntry("added", "entry", 1)); |
| 1068 | 1076 |
| 1069 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _, _)). | 1077 EXPECT_CALL(autofill_table(), GetAutofillTimestamps(_, _, _, _)) |
| 1070 WillOnce(DoAll(SetArgumentPointee<2>(added_entry.date_created()), | 1078 .WillOnce(DoAll(SetArgumentPointee<2>(added_entry.date_created()), |
| 1071 SetArgumentPointee<3>(added_entry.date_last_used()), | 1079 SetArgumentPointee<3>(added_entry.date_last_used()), |
| 1072 Return(true))); | 1080 Return(true))); |
| 1073 | 1081 |
| 1074 AutofillChangeList changes; | 1082 AutofillChangeList changes; |
| 1075 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key())); | 1083 changes.push_back(AutofillChange(AutofillChange::ADD, added_entry.key())); |
| 1076 | 1084 |
| 1077 web_data_service_->OnAutofillEntriesChanged(changes); | 1085 web_data_service()->OnAutofillEntriesChanged(changes); |
| 1078 | 1086 |
| 1079 std::vector<AutofillEntry> new_sync_entries; | 1087 std::vector<AutofillEntry> new_sync_entries; |
| 1080 std::vector<AutofillProfile> new_sync_profiles; | 1088 std::vector<AutofillProfile> new_sync_profiles; |
| 1081 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, | 1089 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, |
| 1082 &new_sync_profiles)); | 1090 &new_sync_profiles)); |
| 1083 ASSERT_EQ(1U, new_sync_entries.size()); | 1091 ASSERT_EQ(1U, new_sync_entries.size()); |
| 1084 EXPECT_TRUE(added_entry == new_sync_entries[0]); | 1092 EXPECT_TRUE(added_entry == new_sync_entries[0]); |
| 1085 } | 1093 } |
| 1086 | 1094 |
| 1087 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) { | 1095 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeAddProfile) { |
| 1088 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).WillOnce(Return(true)); | 1096 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)).WillOnce(Return(true)); |
| 1089 EXPECT_CALL(*personal_data_manager_, Refresh()); | 1097 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 1090 SetIdleChangeProcessorExpectations(); | 1098 SetIdleChangeProcessorExpectations(); |
| 1091 CreateRootHelper create_root(this, AUTOFILL_PROFILE); | 1099 CreateRootHelper create_root(this, AUTOFILL_PROFILE); |
| 1092 StartSyncService(create_root.callback(), false, AUTOFILL_PROFILE); | 1100 StartSyncService(create_root.callback(), false, AUTOFILL_PROFILE); |
| 1093 ASSERT_TRUE(create_root.success()); | 1101 ASSERT_TRUE(create_root.success()); |
| 1094 | 1102 |
| 1095 AutofillProfile added_profile; | 1103 AutofillProfile added_profile; |
| 1096 autofill::test::SetProfileInfoWithGuid(&added_profile, | 1104 autofill::test::SetProfileInfoWithGuid(&added_profile, |
| 1097 "D6ADA912-D374-4C0A-917D-F5C8EBE43011", "Josephine", "Alicia", "Saenz", | 1105 "D6ADA912-D374-4C0A-917D-F5C8EBE43011", "Josephine", "Alicia", "Saenz", |
| 1098 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 1106 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
| 1099 "32801", "US", "19482937549"); | 1107 "32801", "US", "19482937549"); |
| 1100 | 1108 |
| 1101 AutofillProfileChange change( | 1109 AutofillProfileChange change( |
| 1102 AutofillProfileChange::ADD, added_profile.guid(), &added_profile); | 1110 AutofillProfileChange::ADD, added_profile.guid(), &added_profile); |
| 1103 web_data_service_->OnAutofillProfileChanged(change); | 1111 web_data_service()->OnAutofillProfileChanged(change); |
| 1104 | 1112 |
| 1105 std::vector<AutofillProfile> new_sync_profiles; | 1113 std::vector<AutofillProfile> new_sync_profiles; |
| 1106 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( | 1114 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( |
| 1107 &new_sync_profiles)); | 1115 &new_sync_profiles)); |
| 1108 ASSERT_EQ(1U, new_sync_profiles.size()); | 1116 ASSERT_EQ(1U, new_sync_profiles.size()); |
| 1109 EXPECT_EQ(0, added_profile.Compare(new_sync_profiles[0])); | 1117 EXPECT_EQ(0, added_profile.Compare(new_sync_profiles[0])); |
| 1110 } | 1118 } |
| 1111 | 1119 |
| 1112 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) { | 1120 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeUpdateEntry) { |
| 1113 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); | 1121 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); |
| 1114 std::vector<AutofillEntry> original_entries; | 1122 std::vector<AutofillEntry> original_entries; |
| 1115 original_entries.push_back(original_entry); | 1123 original_entries.push_back(original_entry); |
| 1116 | 1124 |
| 1117 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). | 1125 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
| 1118 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 1126 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
| 1119 EXPECT_CALL(*personal_data_manager_, Refresh()); | 1127 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 1120 CreateRootHelper create_root(this, AUTOFILL); | 1128 CreateRootHelper create_root(this, AUTOFILL); |
| 1121 StartSyncService(create_root.callback(), false, AUTOFILL); | 1129 StartSyncService(create_root.callback(), false, AUTOFILL); |
| 1122 ASSERT_TRUE(create_root.success()); | 1130 ASSERT_TRUE(create_root.success()); |
| 1123 | 1131 |
| 1124 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2)); | 1132 AutofillEntry updated_entry(MakeAutofillEntry("my", "entry", 1, 2)); |
| 1125 | 1133 |
| 1126 EXPECT_CALL(autofill_table_, GetAutofillTimestamps(_, _, _, _)). | 1134 EXPECT_CALL(autofill_table(), GetAutofillTimestamps(_, _, _, _)) |
| 1127 WillOnce(DoAll(SetArgumentPointee<2>(updated_entry.date_created()), | 1135 .WillOnce(DoAll(SetArgumentPointee<2>(updated_entry.date_created()), |
| 1128 SetArgumentPointee<3>(updated_entry.date_last_used()), | 1136 SetArgumentPointee<3>(updated_entry.date_last_used()), |
| 1129 Return(true))); | 1137 Return(true))); |
| 1130 | 1138 |
| 1131 AutofillChangeList changes; | 1139 AutofillChangeList changes; |
| 1132 changes.push_back(AutofillChange(AutofillChange::UPDATE, | 1140 changes.push_back(AutofillChange(AutofillChange::UPDATE, |
| 1133 updated_entry.key())); | 1141 updated_entry.key())); |
| 1134 web_data_service_->OnAutofillEntriesChanged(changes); | 1142 web_data_service()->OnAutofillEntriesChanged(changes); |
| 1135 | 1143 |
| 1136 std::vector<AutofillEntry> new_sync_entries; | 1144 std::vector<AutofillEntry> new_sync_entries; |
| 1137 std::vector<AutofillProfile> new_sync_profiles; | 1145 std::vector<AutofillProfile> new_sync_profiles; |
| 1138 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, | 1146 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, |
| 1139 &new_sync_profiles)); | 1147 &new_sync_profiles)); |
| 1140 ASSERT_EQ(1U, new_sync_entries.size()); | 1148 ASSERT_EQ(1U, new_sync_entries.size()); |
| 1141 EXPECT_TRUE(updated_entry == new_sync_entries[0]); | 1149 EXPECT_TRUE(updated_entry == new_sync_entries[0]); |
| 1142 } | 1150 } |
| 1143 | 1151 |
| 1144 | 1152 |
| 1145 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) { | 1153 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveEntry) { |
| 1146 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); | 1154 AutofillEntry original_entry(MakeAutofillEntry("my", "entry", 1)); |
| 1147 std::vector<AutofillEntry> original_entries; | 1155 std::vector<AutofillEntry> original_entries; |
| 1148 original_entries.push_back(original_entry); | 1156 original_entries.push_back(original_entry); |
| 1149 | 1157 |
| 1150 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). | 1158 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
| 1151 WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); | 1159 .WillOnce(DoAll(SetArgumentPointee<0>(original_entries), Return(true))); |
| 1152 EXPECT_CALL(*personal_data_manager_, Refresh()); | 1160 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 1153 CreateRootHelper create_root(this, AUTOFILL); | 1161 CreateRootHelper create_root(this, AUTOFILL); |
| 1154 StartSyncService(create_root.callback(), false, AUTOFILL); | 1162 StartSyncService(create_root.callback(), false, AUTOFILL); |
| 1155 ASSERT_TRUE(create_root.success()); | 1163 ASSERT_TRUE(create_root.success()); |
| 1156 | 1164 |
| 1157 AutofillChangeList changes; | 1165 AutofillChangeList changes; |
| 1158 changes.push_back(AutofillChange(AutofillChange::REMOVE, | 1166 changes.push_back(AutofillChange(AutofillChange::REMOVE, |
| 1159 original_entry.key())); | 1167 original_entry.key())); |
| 1160 web_data_service_->OnAutofillEntriesChanged(changes); | 1168 web_data_service()->OnAutofillEntriesChanged(changes); |
| 1161 | 1169 |
| 1162 std::vector<AutofillEntry> new_sync_entries; | 1170 std::vector<AutofillEntry> new_sync_entries; |
| 1163 std::vector<AutofillProfile> new_sync_profiles; | 1171 std::vector<AutofillProfile> new_sync_profiles; |
| 1164 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, | 1172 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&new_sync_entries, |
| 1165 &new_sync_profiles)); | 1173 &new_sync_profiles)); |
| 1166 ASSERT_EQ(0U, new_sync_entries.size()); | 1174 ASSERT_EQ(0U, new_sync_entries.size()); |
| 1167 } | 1175 } |
| 1168 | 1176 |
| 1169 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) { | 1177 TEST_F(ProfileSyncServiceAutofillTest, ProcessUserChangeRemoveProfile) { |
| 1170 AutofillProfile sync_profile; | 1178 AutofillProfile sync_profile; |
| 1171 autofill::test::SetProfileInfoWithGuid(&sync_profile, | 1179 autofill::test::SetProfileInfoWithGuid(&sync_profile, |
| 1172 "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", "Alicia", "Saenz", | 1180 "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", "Alicia", "Saenz", |
| 1173 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 1181 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
| 1174 "32801", "US", "19482937549"); | 1182 "32801", "US", "19482937549"); |
| 1175 AutofillProfile* native_profile = new AutofillProfile; | 1183 AutofillProfile* native_profile = new AutofillProfile; |
| 1176 autofill::test::SetProfileInfoWithGuid(native_profile, | 1184 autofill::test::SetProfileInfoWithGuid(native_profile, |
| 1177 "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", "Alicia", "Saenz", | 1185 "3BA5FA1B-1EC4-4BB3-9B57-EC92BE3C1A09", "Josephine", "Alicia", "Saenz", |
| 1178 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 1186 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
| 1179 "32801", "US", "19482937549"); | 1187 "32801", "US", "19482937549"); |
| 1180 | 1188 |
| 1181 std::vector<AutofillProfile*> native_profiles; | 1189 std::vector<AutofillProfile*> native_profiles; |
| 1182 native_profiles.push_back(native_profile); | 1190 native_profiles.push_back(native_profile); |
| 1183 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)). | 1191 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)) |
| 1184 WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); | 1192 .WillOnce(DoAll(SetArgumentPointee<0>(native_profiles), Return(true))); |
| 1185 | 1193 |
| 1186 std::vector<AutofillProfile> sync_profiles; | 1194 std::vector<AutofillProfile> sync_profiles; |
| 1187 sync_profiles.push_back(sync_profile); | 1195 sync_profiles.push_back(sync_profile); |
| 1188 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); | 1196 AddAutofillHelper<AutofillProfile> add_autofill(this, sync_profiles); |
| 1189 EXPECT_CALL(*personal_data_manager_, Refresh()); | 1197 EXPECT_CALL(personal_data_manager(), Refresh()); |
| 1190 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); | 1198 StartSyncService(add_autofill.callback(), false, AUTOFILL_PROFILE); |
| 1191 ASSERT_TRUE(add_autofill.success()); | 1199 ASSERT_TRUE(add_autofill.success()); |
| 1192 | 1200 |
| 1193 AutofillProfileChange change( | 1201 AutofillProfileChange change( |
| 1194 AutofillProfileChange::REMOVE, sync_profile.guid(), NULL); | 1202 AutofillProfileChange::REMOVE, sync_profile.guid(), NULL); |
| 1195 web_data_service_->OnAutofillProfileChanged(change); | 1203 web_data_service()->OnAutofillProfileChanged(change); |
| 1196 | 1204 |
| 1197 std::vector<AutofillProfile> new_sync_profiles; | 1205 std::vector<AutofillProfile> new_sync_profiles; |
| 1198 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( | 1206 ASSERT_TRUE(GetAutofillProfilesFromSyncDBUnderProfileNode( |
| 1199 &new_sync_profiles)); | 1207 &new_sync_profiles)); |
| 1200 ASSERT_EQ(0U, new_sync_profiles.size()); | 1208 ASSERT_EQ(0U, new_sync_profiles.size()); |
| 1201 } | 1209 } |
| 1202 | 1210 |
| 1203 TEST_F(ProfileSyncServiceAutofillTest, ServerChangeRace) { | 1211 TEST_F(ProfileSyncServiceAutofillTest, ServerChangeRace) { |
| 1204 // Once for MergeDataAndStartSyncing() and twice for ProcessSyncChanges(), via | 1212 // Once for MergeDataAndStartSyncing() and twice for ProcessSyncChanges(), via |
| 1205 // LoadAutofillData(). | 1213 // LoadAutofillData(). |
| 1206 EXPECT_CALL(autofill_table_, GetAllAutofillEntries(_)). | 1214 EXPECT_CALL(autofill_table(), GetAllAutofillEntries(_)) |
| 1207 Times(3).WillRepeatedly(Return(true)); | 1215 .Times(3) |
| 1216 .WillRepeatedly(Return(true)); |
| 1208 // On the other hand Autofill and Autocomplete are separated now, so | 1217 // On the other hand Autofill and Autocomplete are separated now, so |
| 1209 // GetAutofillProfiles() should not be called. | 1218 // GetAutofillProfiles() should not be called. |
| 1210 EXPECT_CALL(autofill_table_, GetAutofillProfiles(_)).Times(0); | 1219 EXPECT_CALL(autofill_table(), GetAutofillProfiles(_)).Times(0); |
| 1211 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(_)). | 1220 EXPECT_CALL(autofill_table(), UpdateAutofillEntries(_)) |
| 1212 WillRepeatedly(Return(true)); | 1221 .WillRepeatedly(Return(true)); |
| 1213 EXPECT_CALL(*personal_data_manager_, Refresh()).Times(3); | 1222 EXPECT_CALL(personal_data_manager(), Refresh()).Times(3); |
| 1214 CreateRootHelper create_root(this, AUTOFILL); | 1223 CreateRootHelper create_root(this, AUTOFILL); |
| 1215 StartSyncService(create_root.callback(), false, AUTOFILL); | 1224 StartSyncService(create_root.callback(), false, AUTOFILL); |
| 1216 ASSERT_TRUE(create_root.success()); | 1225 ASSERT_TRUE(create_root.success()); |
| 1217 | 1226 |
| 1218 // (true, false) means we have to reset after |Signal|, init to unsignaled. | 1227 // (true, false) means we have to reset after |Signal|, init to unsignaled. |
| 1219 scoped_ptr<WaitableEvent> wait_for_start(new WaitableEvent(true, false)); | 1228 scoped_ptr<WaitableEvent> wait_for_start(new WaitableEvent(true, false)); |
| 1220 scoped_ptr<WaitableEvent> wait_for_syncapi(new WaitableEvent(true, false)); | 1229 scoped_ptr<WaitableEvent> wait_for_syncapi(new WaitableEvent(true, false)); |
| 1221 scoped_refptr<FakeServerUpdater> updater(new FakeServerUpdater( | 1230 scoped_refptr<FakeServerUpdater> updater(new FakeServerUpdater( |
| 1222 sync_service_.get(), wait_for_start.get(), wait_for_syncapi.get(), | 1231 sync_service(), wait_for_start.get(), wait_for_syncapi.get(), |
| 1223 data_type_thread_.task_runner())); | 1232 data_type_thread()->task_runner())); |
| 1224 | 1233 |
| 1225 // This server side update will stall waiting for CommitWaiter. | 1234 // This server side update will stall waiting for CommitWaiter. |
| 1226 updater->CreateNewEntry(MakeAutofillEntry("server", "entry", 1)); | 1235 updater->CreateNewEntry(MakeAutofillEntry("server", "entry", 1)); |
| 1227 wait_for_start->Wait(); | 1236 wait_for_start->Wait(); |
| 1228 | 1237 |
| 1229 AutofillEntry syncapi_entry(MakeAutofillEntry("syncapi", "entry", 2)); | 1238 AutofillEntry syncapi_entry(MakeAutofillEntry("syncapi", "entry", 2)); |
| 1230 ASSERT_TRUE(AddAutofillSyncNode(syncapi_entry)); | 1239 ASSERT_TRUE(AddAutofillSyncNode(syncapi_entry)); |
| 1231 DVLOG(1) << "Syncapi update finished."; | 1240 DVLOG(1) << "Syncapi update finished."; |
| 1232 | 1241 |
| 1233 // If we reach here, it means syncapi succeeded and we didn't deadlock. Yay! | 1242 // If we reach here, it means syncapi succeeded and we didn't deadlock. Yay! |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1246 std::vector<AutofillEntry> sync_entries; | 1255 std::vector<AutofillEntry> sync_entries; |
| 1247 std::vector<AutofillProfile> sync_profiles; | 1256 std::vector<AutofillProfile> sync_profiles; |
| 1248 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1257 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1249 EXPECT_EQ(3U, sync_entries.size()); | 1258 EXPECT_EQ(3U, sync_entries.size()); |
| 1250 EXPECT_EQ(0U, sync_profiles.size()); | 1259 EXPECT_EQ(0U, sync_profiles.size()); |
| 1251 for (size_t i = 0; i < sync_entries.size(); i++) { | 1260 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1252 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() | 1261 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() |
| 1253 << ", " << sync_entries[i].key().value(); | 1262 << ", " << sync_entries[i].key().value(); |
| 1254 } | 1263 } |
| 1255 } | 1264 } |
| OLD | NEW |