| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/password_manager/password_store.h" | 12 #include "chrome/browser/password_manager/password_store.h" |
| 13 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" | 13 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" |
| 14 #include "chrome/browser/sync/engine/syncapi.h" | 14 #include "chrome/browser/sync/engine/syncapi.h" |
| 15 #include "chrome/browser/sync/glue/password_change_processor.h" | 15 #include "chrome/browser/sync/glue/password_change_processor.h" |
| 16 #include "chrome/browser/sync/glue/password_data_type_controller.h" | 16 #include "chrome/browser/sync/glue/password_data_type_controller.h" |
| 17 #include "chrome/browser/sync/glue/password_model_associator.h" | 17 #include "chrome/browser/sync/glue/password_model_associator.h" |
| 18 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" | |
| 19 #include "chrome/browser/sync/profile_sync_factory.h" | 18 #include "chrome/browser/sync/profile_sync_factory.h" |
| 20 #include "chrome/browser/sync/profile_sync_factory_mock.h" | 19 #include "chrome/browser/sync/profile_sync_factory_mock.h" |
| 21 #include "chrome/browser/sync/profile_sync_service.h" | 20 #include "chrome/browser/sync/profile_sync_service.h" |
| 22 #include "chrome/browser/sync/profile_sync_test_util.h" | 21 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 23 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 22 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 24 #include "chrome/browser/sync/syncable/directory_manager.h" | 23 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 25 #include "chrome/browser/sync/syncable/syncable.h" | 24 #include "chrome/browser/sync/syncable/syncable.h" |
| 26 #include "chrome/browser/sync/test_profile_sync_service.h" | 25 #include "chrome/browser/sync/test_profile_sync_service.h" |
| 27 #include "chrome/common/net/gaia/gaia_constants.h" | 26 #include "chrome/common/net/gaia/gaia_constants.h" |
| 28 #include "chrome/common/notification_observer_mock.h" | 27 #include "chrome/common/notification_observer_mock.h" |
| 29 #include "chrome/common/notification_source.h" | 28 #include "chrome/common/notification_source.h" |
| 30 #include "chrome/common/notification_type.h" | 29 #include "chrome/common/notification_type.h" |
| 31 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/test/sync/engine/test_id_factory.h" | 31 #include "chrome/test/sync/engine/test_id_factory.h" |
| 33 #include "chrome/test/profile_mock.h" | 32 #include "chrome/test/profile_mock.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "webkit/glue/password_form.h" | 34 #include "webkit/glue/password_form.h" |
| 36 | 35 |
| 37 using base::Time; | 36 using base::Time; |
| 38 using browser_sync::PasswordChangeProcessor; | 37 using browser_sync::PasswordChangeProcessor; |
| 39 using browser_sync::PasswordDataTypeController; | 38 using browser_sync::PasswordDataTypeController; |
| 40 using browser_sync::PasswordModelAssociator; | 39 using browser_sync::PasswordModelAssociator; |
| 41 using browser_sync::SyncBackendHostMock; | |
| 42 using browser_sync::TestIdFactory; | 40 using browser_sync::TestIdFactory; |
| 43 using browser_sync::UnrecoverableErrorHandler; | 41 using browser_sync::UnrecoverableErrorHandler; |
| 44 using sync_api::SyncManager; | 42 using sync_api::SyncManager; |
| 45 using sync_api::UserShare; | 43 using sync_api::UserShare; |
| 46 using syncable::BASE_VERSION; | 44 using syncable::BASE_VERSION; |
| 47 using syncable::CREATE; | 45 using syncable::CREATE; |
| 48 using syncable::DirectoryManager; | 46 using syncable::DirectoryManager; |
| 49 using syncable::IS_DEL; | 47 using syncable::IS_DEL; |
| 50 using syncable::IS_DIR; | 48 using syncable::IS_DIR; |
| 51 using syncable::IS_UNAPPLIED_UPDATE; | 49 using syncable::IS_UNAPPLIED_UPDATE; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 const base::Time&)); | 92 const base::Time&)); |
| 95 MOCK_METHOD2(GetLoginsImpl, void(GetLoginsRequest*, const PasswordForm&)); | 93 MOCK_METHOD2(GetLoginsImpl, void(GetLoginsRequest*, const PasswordForm&)); |
| 96 MOCK_METHOD1(GetAutofillableLoginsImpl, void(GetLoginsRequest*)); | 94 MOCK_METHOD1(GetAutofillableLoginsImpl, void(GetLoginsRequest*)); |
| 97 MOCK_METHOD1(GetBlacklistLoginsImpl, void(GetLoginsRequest*)); | 95 MOCK_METHOD1(GetBlacklistLoginsImpl, void(GetLoginsRequest*)); |
| 98 MOCK_METHOD1(FillAutofillableLogins, | 96 MOCK_METHOD1(FillAutofillableLogins, |
| 99 bool(std::vector<PasswordForm*>*)); | 97 bool(std::vector<PasswordForm*>*)); |
| 100 MOCK_METHOD1(FillBlacklistLogins, | 98 MOCK_METHOD1(FillBlacklistLogins, |
| 101 bool(std::vector<PasswordForm*>*)); | 99 bool(std::vector<PasswordForm*>*)); |
| 102 }; | 100 }; |
| 103 | 101 |
| 102 class PasswordTestProfileSyncService : public TestProfileSyncService { |
| 103 public: |
| 104 PasswordTestProfileSyncService(ProfileSyncFactory* factory, |
| 105 Profile* profile, |
| 106 const std::string& test_user, |
| 107 bool synchronous_backend_initialization, |
| 108 Task* initial_condition_setup_task, |
| 109 Task* passphrase_accept_task) |
| 110 : TestProfileSyncService(factory, profile, test_user, |
| 111 synchronous_backend_initialization, |
| 112 initial_condition_setup_task), |
| 113 passphrase_accept_task_(passphrase_accept_task) {} |
| 114 |
| 115 virtual ~PasswordTestProfileSyncService() {} |
| 116 |
| 117 virtual void OnPassphraseRequired(bool for_decryption) { |
| 118 TestProfileSyncService::OnPassphraseRequired(for_decryption); |
| 119 ADD_FAILURE(); |
| 120 } |
| 121 |
| 122 virtual void OnPassphraseAccepted() { |
| 123 TestProfileSyncService::OnPassphraseAccepted(); |
| 124 |
| 125 if (passphrase_accept_task_) { |
| 126 passphrase_accept_task_->Run(); |
| 127 } |
| 128 } |
| 129 |
| 130 private: |
| 131 Task* passphrase_accept_task_; |
| 132 }; |
| 133 |
| 104 class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { | 134 class ProfileSyncServicePasswordTest : public AbstractProfileSyncServiceTest { |
| 105 protected: | 135 protected: |
| 106 ProfileSyncServicePasswordTest() | 136 ProfileSyncServicePasswordTest() |
| 107 : db_thread_(BrowserThread::DB) { | 137 : db_thread_(BrowserThread::DB) { |
| 108 } | 138 } |
| 109 | 139 |
| 110 virtual void SetUp() { | 140 virtual void SetUp() { |
| 111 password_store_ = new MockPasswordStore(); | 141 password_store_ = new MockPasswordStore(); |
| 112 db_thread_.Start(); | 142 db_thread_.Start(); |
| 113 | 143 |
| 114 notification_service_ = new ThreadNotificationService(&db_thread_); | 144 notification_service_ = new ThreadNotificationService(&db_thread_); |
| 115 notification_service_->Init(); | 145 notification_service_->Init(); |
| 116 registrar_.Add(&observer_, | 146 registrar_.Add(&observer_, |
| 117 NotificationType::SYNC_PASSPHRASE_ACCEPTED, | |
| 118 NotificationService::AllSources()); | |
| 119 registrar_.Add(&observer_, | |
| 120 NotificationType::SYNC_CONFIGURE_DONE, | 147 NotificationType::SYNC_CONFIGURE_DONE, |
| 121 NotificationService::AllSources()); | 148 NotificationService::AllSources()); |
| 122 | |
| 123 // We shouldn't ever get this. Gmock will complain if we do. | |
| 124 registrar_.Add(&observer_, | |
| 125 NotificationType::SYNC_PASSPHRASE_REQUIRED, | |
| 126 NotificationService::AllSources()); | |
| 127 } | 149 } |
| 128 | 150 |
| 129 virtual void TearDown() { | 151 virtual void TearDown() { |
| 130 service_.reset(); | 152 service_.reset(); |
| 131 notification_service_->TearDown(); | 153 notification_service_->TearDown(); |
| 132 db_thread_.Stop(); | 154 db_thread_.Stop(); |
| 133 MessageLoop::current()->RunAllPending(); | 155 MessageLoop::current()->RunAllPending(); |
| 134 } | 156 } |
| 135 | 157 |
| 136 void StartSyncService(Task* root_task, Task* node_task) { | 158 void StartSyncService(Task* root_task, Task* node_task) { |
| 137 StartSyncService(root_task, node_task, 2, 2); | 159 StartSyncService(root_task, node_task, 2, 2); |
| 138 } | 160 } |
| 139 | 161 |
| 140 void StartSyncService(Task* root_task, Task* node_task, | 162 void StartSyncService(Task* root_task, Task* node_task, |
| 141 int num_resume_expectations, | 163 int num_resume_expectations, |
| 142 int num_pause_expectations) { | 164 int num_pause_expectations) { |
| 143 if (!service_.get()) { | 165 if (!service_.get()) { |
| 144 service_.reset(new TestProfileSyncService(&factory_, &profile_, | 166 service_.reset(new PasswordTestProfileSyncService( |
| 145 "test_user", false, root_task)); | 167 &factory_, &profile_, "test_user", false, root_task, node_task)); |
| 146 service_->RegisterPreferences(); | 168 service_->RegisterPreferences(); |
| 147 profile_.GetPrefs()->SetBoolean(prefs::kSyncPasswords, true); | 169 profile_.GetPrefs()->SetBoolean(prefs::kSyncPasswords, true); |
| 148 service_->set_num_expected_resumes(num_resume_expectations); | 170 service_->set_num_expected_resumes(num_resume_expectations); |
| 149 service_->set_num_expected_pauses(num_pause_expectations); | 171 service_->set_num_expected_pauses(num_pause_expectations); |
| 150 PasswordDataTypeController* data_type_controller = | 172 PasswordDataTypeController* data_type_controller = |
| 151 new PasswordDataTypeController(&factory_, | 173 new PasswordDataTypeController(&factory_, |
| 152 &profile_, | 174 &profile_, |
| 153 service_.get()); | 175 service_.get()); |
| 154 | 176 |
| 155 EXPECT_CALL(factory_, CreatePasswordSyncComponents(_, _, _)). | 177 EXPECT_CALL(factory_, CreatePasswordSyncComponents(_, _, _)). |
| (...skipping 15 matching lines...) Expand all Loading... |
| 171 WillRepeatedly(Return(password_store_.get())); | 193 WillRepeatedly(Return(password_store_.get())); |
| 172 | 194 |
| 173 EXPECT_CALL(observer_, | 195 EXPECT_CALL(observer_, |
| 174 Observe( | 196 Observe( |
| 175 NotificationType(NotificationType::SYNC_CONFIGURE_DONE),_,_)); | 197 NotificationType(NotificationType::SYNC_CONFIGURE_DONE),_,_)); |
| 176 | 198 |
| 177 service_->RegisterDataTypeController(data_type_controller); | 199 service_->RegisterDataTypeController(data_type_controller); |
| 178 service_->Initialize(); | 200 service_->Initialize(); |
| 179 MessageLoop::current()->Run(); | 201 MessageLoop::current()->Run(); |
| 180 | 202 |
| 181 | |
| 182 EXPECT_CALL( | 203 EXPECT_CALL( |
| 183 observer_, | 204 observer_, |
| 184 Observe( | 205 Observe( |
| 185 NotificationType(NotificationType::SYNC_PASSPHRASE_ACCEPTED), | |
| 186 _,_)). | |
| 187 WillOnce(InvokeTask(node_task)); | |
| 188 EXPECT_CALL( | |
| 189 observer_, | |
| 190 Observe( | |
| 191 NotificationType(NotificationType::SYNC_CONFIGURE_DONE), | 206 NotificationType(NotificationType::SYNC_CONFIGURE_DONE), |
| 192 _,_)). | 207 _,_)). |
| 193 WillOnce(QuitUIMessageLoop()); | 208 WillOnce(QuitUIMessageLoop()); |
| 194 service_->SetPassphrase("foo", false, true); | 209 service_->SetPassphrase("foo", false, true); |
| 195 MessageLoop::current()->Run(); | 210 MessageLoop::current()->Run(); |
| 196 } | 211 } |
| 197 } | 212 } |
| 198 | 213 |
| 199 void AddPasswordSyncNode(const PasswordForm& entry) { | 214 void AddPasswordSyncNode(const PasswordForm& entry) { |
| 200 sync_api::WriteTransaction trans( | 215 sync_api::WriteTransaction trans( |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 AddPasswordEntriesTask node_task(this, sync_forms); | 522 AddPasswordEntriesTask node_task(this, sync_forms); |
| 508 | 523 |
| 509 StartSyncService(&root_task, &node_task); | 524 StartSyncService(&root_task, &node_task); |
| 510 | 525 |
| 511 std::vector<PasswordForm> new_sync_forms; | 526 std::vector<PasswordForm> new_sync_forms; |
| 512 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 527 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
| 513 | 528 |
| 514 EXPECT_EQ(1U, new_sync_forms.size()); | 529 EXPECT_EQ(1U, new_sync_forms.size()); |
| 515 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 530 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
| 516 } | 531 } |
| OLD | NEW |