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

Side by Side Diff: chrome/browser/sync/profile_sync_service_autofill_unittest.cc

Issue 964563002: Replace SetAuthenticatedUsername with SetAuthenticatedAccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@priv
Patch Set: rebased Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
20 #include "base/strings/string16.h" 20 #include "base/strings/string16.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "base/synchronization/waitable_event.h" 22 #include "base/synchronization/waitable_event.h"
23 #include "base/time/time.h" 23 #include "base/time/time.h"
24 #include "chrome/browser/autofill/personal_data_manager_factory.h" 24 #include "chrome/browser/autofill/personal_data_manager_factory.h"
25 #include "chrome/browser/prefs/pref_service_syncable.h" 25 #include "chrome/browser/prefs/pref_service_syncable.h"
26 #include "chrome/browser/signin/account_tracker_service_factory.h"
26 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 27 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
27 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 28 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 29 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
29 #include "chrome/browser/signin/signin_manager_factory.h" 30 #include "chrome/browser/signin/signin_manager_factory.h"
30 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" 31 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
31 #include "chrome/browser/sync/glue/autofill_data_type_controller.h" 32 #include "chrome/browser/sync/glue/autofill_data_type_controller.h"
32 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h" 33 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h"
33 #include "chrome/browser/sync/profile_sync_components_factory.h" 34 #include "chrome/browser/sync/profile_sync_components_factory.h"
34 #include "chrome/browser/sync/profile_sync_service.h" 35 #include "chrome/browser/sync/profile_sync_service.h"
35 #include "chrome/browser/sync/profile_sync_service_factory.h" 36 #include "chrome/browser/sync/profile_sync_service_factory.h"
36 #include "chrome/browser/sync/profile_sync_test_util.h" 37 #include "chrome/browser/sync/profile_sync_test_util.h"
37 #include "chrome/browser/sync/test_profile_sync_service.h" 38 #include "chrome/browser/sync/test_profile_sync_service.h"
38 #include "chrome/browser/webdata/web_data_service_factory.h" 39 #include "chrome/browser/webdata/web_data_service_factory.h"
39 #include "chrome/test/base/testing_browser_process.h" 40 #include "chrome/test/base/testing_browser_process.h"
40 #include "chrome/test/base/testing_profile.h" 41 #include "chrome/test/base/testing_profile.h"
41 #include "chrome/test/base/testing_profile_manager.h" 42 #include "chrome/test/base/testing_profile_manager.h"
42 #include "components/autofill/core/browser/autofill_test_utils.h" 43 #include "components/autofill/core/browser/autofill_test_utils.h"
43 #include "components/autofill/core/browser/personal_data_manager.h" 44 #include "components/autofill/core/browser/personal_data_manager.h"
44 #include "components/autofill/core/browser/webdata/autocomplete_syncable_service .h" 45 #include "components/autofill/core/browser/webdata/autocomplete_syncable_service .h"
45 #include "components/autofill/core/browser/webdata/autofill_change.h" 46 #include "components/autofill/core/browser/webdata/autofill_change.h"
46 #include "components/autofill/core/browser/webdata/autofill_entry.h" 47 #include "components/autofill/core/browser/webdata/autofill_entry.h"
47 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser vice.h" 48 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser vice.h"
48 #include "components/autofill/core/browser/webdata/autofill_table.h" 49 #include "components/autofill/core/browser/webdata/autofill_table.h"
49 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 50 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
51 #include "components/signin/core/browser/account_tracker_service.h"
50 #include "components/signin/core/browser/signin_manager.h" 52 #include "components/signin/core/browser/signin_manager.h"
51 #include "components/sync_driver/data_type_controller.h" 53 #include "components/sync_driver/data_type_controller.h"
52 #include "components/webdata/common/web_database.h" 54 #include "components/webdata/common/web_database.h"
53 #include "components/webdata_services/web_data_service_test_util.h" 55 #include "components/webdata_services/web_data_service_test_util.h"
54 #include "content/public/test/test_browser_thread.h" 56 #include "content/public/test/test_browser_thread.h"
55 #include "google_apis/gaia/gaia_constants.h" 57 #include "google_apis/gaia/gaia_constants.h"
56 #include "sync/internal_api/public/base/model_type.h" 58 #include "sync/internal_api/public/base/model_type.h"
57 #include "sync/internal_api/public/data_type_debug_info_listener.h" 59 #include "sync/internal_api/public/data_type_debug_info_listener.h"
58 #include "sync/internal_api/public/read_node.h" 60 #include "sync/internal_api/public/read_node.h"
59 #include "sync/internal_api/public/read_transaction.h" 61 #include "sync/internal_api/public/read_transaction.h"
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 ->SetTestingFactoryAndUse(profile_, 492 ->SetTestingFactoryAndUse(profile_,
491 MockPersonalDataManager::Build)); 493 MockPersonalDataManager::Build));
492 494
493 EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1); 495 EXPECT_CALL(*personal_data_manager_, LoadProfiles()).Times(1);
494 EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1); 496 EXPECT_CALL(*personal_data_manager_, LoadCreditCards()).Times(1);
495 497
496 personal_data_manager_->Init( 498 personal_data_manager_->Init(
497 WebDataServiceFactory::GetAutofillWebDataForProfile( 499 WebDataServiceFactory::GetAutofillWebDataForProfile(
498 profile_, ServiceAccessType::EXPLICIT_ACCESS), 500 profile_, ServiceAccessType::EXPLICIT_ACCESS),
499 profile_->GetPrefs(), 501 profile_->GetPrefs(),
502 AccountTrackerServiceFactory::GetForProfile(profile_),
500 profile_->IsOffTheRecord()); 503 profile_->IsOffTheRecord());
501 504
502 web_data_service_->StartSyncableService(); 505 web_data_service_->StartSyncableService();
503 506
504 // When UpdateAutofillEntries() is called with an empty list, the return 507 // When UpdateAutofillEntries() is called with an empty list, the return
505 // value should be |true|, rather than the default of |false|. 508 // value should be |true|, rather than the default of |false|.
506 std::vector<AutofillEntry> empty; 509 std::vector<AutofillEntry> empty;
507 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(empty)) 510 EXPECT_CALL(autofill_table_, UpdateAutofillEntries(empty))
508 .WillRepeatedly(Return(true)); 511 .WillRepeatedly(Return(true));
509 } 512 }
(...skipping 17 matching lines...) Expand all
527 if (node.InitTypeRoot(type) != syncer::BaseNode::INIT_OK) 530 if (node.InitTypeRoot(type) != syncer::BaseNode::INIT_OK)
528 return 0; 531 return 0;
529 return node.GetTotalNodeCount() - 1; 532 return node.GetTotalNodeCount() - 1;
530 } 533 }
531 534
532 void StartSyncService(const base::Closure& callback, 535 void StartSyncService(const base::Closure& callback,
533 bool will_fail_association, 536 bool will_fail_association,
534 syncer::ModelType type) { 537 syncer::ModelType type) {
535 AbstractAutofillFactory* factory = GetFactory(type); 538 AbstractAutofillFactory* factory = GetFactory(type);
536 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_); 539 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile_);
537 signin->SetAuthenticatedUsername("test_user@gmail.com"); 540 signin->SetAuthenticatedAccountInfo("12345", "test_user@gmail.com");
538 sync_service_ = TestProfileSyncService::BuildAutoStartAsyncInit(profile_, 541 sync_service_ = TestProfileSyncService::BuildAutoStartAsyncInit(profile_,
539 callback); 542 callback);
540 543
541 ProfileSyncComponentsFactoryMock* components = 544 ProfileSyncComponentsFactoryMock* components =
542 sync_service_->components_factory_mock(); 545 sync_service_->components_factory_mock();
543 DataTypeController* data_type_controller = 546 DataTypeController* data_type_controller =
544 factory->CreateDataTypeController(components, profile_, sync_service_); 547 factory->CreateDataTypeController(components, profile_, sync_service_);
545 factory->SetExpectation(components, 548 factory->SetExpectation(components,
546 sync_service_, 549 sync_service_,
547 web_data_service_.get(), 550 web_data_service_.get(),
548 data_type_controller); 551 data_type_controller);
549 552
550 EXPECT_CALL(*components, CreateDataTypeManager(_, _, _, _, _)). 553 EXPECT_CALL(*components, CreateDataTypeManager(_, _, _, _, _)).
551 WillOnce(ReturnNewDataTypeManagerWithDebugListener( 554 WillOnce(ReturnNewDataTypeManagerWithDebugListener(
552 syncer::MakeWeakHandle(debug_ptr_factory_.GetWeakPtr()))); 555 syncer::MakeWeakHandle(debug_ptr_factory_.GetWeakPtr())));
553 556
554 EXPECT_CALL(*personal_data_manager_, IsDataLoaded()). 557 EXPECT_CALL(*personal_data_manager_, IsDataLoaded()).
555 WillRepeatedly(Return(true)); 558 WillRepeatedly(Return(true));
556 559
557 // We need tokens to get the tests going 560 // We need tokens to get the tests going
558 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) 561 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)
559 ->UpdateCredentials("test_user@gmail.com", "oauth2_login_token"); 562 ->UpdateCredentials(signin->GetAuthenticatedAccountId(),
563 "oauth2_login_token");
560 564
561 sync_service_->RegisterDataTypeController(data_type_controller); 565 sync_service_->RegisterDataTypeController(data_type_controller);
562 sync_service_->Initialize(); 566 sync_service_->Initialize();
563 base::MessageLoop::current()->Run(); 567 base::MessageLoop::current()->Run();
564 568
565 // It's possible this test triggered an unrecoverable error, in which case 569 // It's possible this test triggered an unrecoverable error, in which case
566 // we can't get the sync count. 570 // we can't get the sync count.
567 if (sync_service_->SyncActive()) { 571 if (sync_service_->SyncActive()) {
568 EXPECT_EQ(GetSyncCount(type), 572 EXPECT_EQ(GetSyncCount(type),
569 association_stats_.num_sync_items_after_association); 573 association_stats_.num_sync_items_after_association);
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 std::vector<AutofillEntry> sync_entries; 1374 std::vector<AutofillEntry> sync_entries;
1371 std::vector<AutofillProfile> sync_profiles; 1375 std::vector<AutofillProfile> sync_profiles;
1372 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); 1376 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles));
1373 EXPECT_EQ(3U, sync_entries.size()); 1377 EXPECT_EQ(3U, sync_entries.size());
1374 EXPECT_EQ(0U, sync_profiles.size()); 1378 EXPECT_EQ(0U, sync_profiles.size());
1375 for (size_t i = 0; i < sync_entries.size(); i++) { 1379 for (size_t i = 0; i < sync_entries.size(); i++) {
1376 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() 1380 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name()
1377 << ", " << sync_entries[i].key().value(); 1381 << ", " << sync_entries[i].key().value();
1378 } 1382 }
1379 } 1383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698