| 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" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 notification_service_->Init(); | 115 notification_service_->Init(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 virtual void TearDown() { | 118 virtual void TearDown() { |
| 119 service_.reset(); | 119 service_.reset(); |
| 120 notification_service_->TearDown(); | 120 notification_service_->TearDown(); |
| 121 db_thread_.Stop(); | 121 db_thread_.Stop(); |
| 122 MessageLoop::current()->RunAllPending(); | 122 MessageLoop::current()->RunAllPending(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void StartSyncService(Task* task) { | 125 void StartSyncService(Task* root_task, Task* node_task) { |
| 126 if (!service_.get()) { | 126 if (!service_.get()) { |
| 127 service_.reset(new TestProfileSyncService(&factory_, &profile_, | 127 service_.reset(new TestProfileSyncService(&factory_, &profile_, |
| 128 false, false)); | 128 false, false)); |
| 129 service_->AddObserver(&observer_); | 129 service_->AddObserver(&observer_); |
| 130 PasswordDataTypeController* data_type_controller = | 130 PasswordDataTypeController* data_type_controller = |
| 131 new PasswordDataTypeController(&factory_, | 131 new PasswordDataTypeController(&factory_, |
| 132 &profile_, | 132 &profile_, |
| 133 service_.get()); | 133 service_.get()); |
| 134 | 134 |
| 135 EXPECT_CALL(factory_, CreatePasswordSyncComponents(_, _, _)). | 135 EXPECT_CALL(factory_, CreatePasswordSyncComponents(_, _, _)). |
| 136 WillOnce(MakePasswordSyncComponents(service_.get(), | 136 WillOnce(MakePasswordSyncComponents(service_.get(), |
| 137 password_store_.get(), | 137 password_store_.get(), |
| 138 data_type_controller)); | 138 data_type_controller)); |
| 139 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). | 139 EXPECT_CALL(factory_, CreateDataTypeManager(_, _)). |
| 140 WillOnce(MakeDataTypeManager(&backend_)); | 140 WillOnce(MakeDataTypeManager(&backend_)); |
| 141 | 141 |
| 142 EXPECT_CALL(profile_, GetPasswordStore(_)). | 142 EXPECT_CALL(profile_, GetPasswordStore(_)). |
| 143 WillOnce(Return(password_store_.get())); | 143 WillOnce(Return(password_store_.get())); |
| 144 | 144 |
| 145 // State changes once for the backend init and once for startup done. | 145 // State changes once for the backend init and once for startup done. |
| 146 EXPECT_CALL(observer_, OnStateChanged()). | 146 EXPECT_CALL(observer_, OnStateChanged()). |
| 147 WillOnce(Return()). | 147 WillOnce(InvokeTask(root_task)). |
| 148 WillOnce(Return()). | 148 WillOnce(Return()). |
| 149 WillOnce(QuitUIMessageLoop()); | 149 WillOnce(QuitUIMessageLoop()); |
| 150 | 150 |
| 151 service_->RegisterDataTypeController(data_type_controller); | 151 service_->RegisterDataTypeController(data_type_controller); |
| 152 service_->Initialize(); | 152 service_->Initialize(); |
| 153 MessageLoop::current()->Run(); | 153 MessageLoop::current()->Run(); |
| 154 | 154 |
| 155 EXPECT_CALL(observer_, OnStateChanged()). | 155 // Only set the passphrase if we actually created the password and nigori |
| 156 WillOnce(InvokeTask(task)). | 156 // root nodes. |
| 157 WillOnce(Return()). | 157 if (root_task) { |
| 158 WillOnce(QuitUIMessageLoop()); | 158 EXPECT_CALL(observer_, OnStateChanged()). |
| 159 WillOnce(InvokeTask(node_task)). |
| 160 WillOnce(Return()). |
| 161 WillOnce(QuitUIMessageLoop()); |
| 159 | 162 |
| 160 service_->SetPassphrase("foo"); | 163 service_->SetPassphrase("foo"); |
| 161 MessageLoop::current()->Run(); | 164 MessageLoop::current()->Run(); |
| 165 } |
| 162 } | 166 } |
| 163 } | 167 } |
| 164 | 168 |
| 165 void CreatePasswordRoot() { | 169 void CreatePasswordRoot() { |
| 166 UserShare* user_share = service_->backend()->GetUserShareHandle(); | 170 UserShare* user_share = service_->backend()->GetUserShareHandle(); |
| 167 DirectoryManager* dir_manager = user_share->dir_manager.get(); | 171 DirectoryManager* dir_manager = user_share->dir_manager.get(); |
| 168 | 172 |
| 169 ScopedDirLookup dir(dir_manager, user_share->authenticated_name); | 173 ScopedDirLookup dir(dir_manager, user_share->authenticated_name); |
| 170 ASSERT_TRUE(dir.good()); | 174 ASSERT_TRUE(dir.good()); |
| 171 | 175 |
| 172 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); | 176 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 173 MutableEntry node(&wtrans, | 177 |
| 174 CREATE, | 178 MutableEntry password_node(&wtrans, |
| 175 wtrans.root_id(), | 179 CREATE, |
| 176 browser_sync::kPasswordTag); | 180 wtrans.root_id(), |
| 177 node.Put(UNIQUE_SERVER_TAG, browser_sync::kPasswordTag); | 181 browser_sync::kPasswordTag); |
| 178 node.Put(IS_DIR, true); | 182 password_node.Put(UNIQUE_SERVER_TAG, browser_sync::kPasswordTag); |
| 179 node.Put(SERVER_IS_DIR, false); | 183 password_node.Put(IS_DIR, true); |
| 180 node.Put(IS_UNSYNCED, false); | 184 password_node.Put(SERVER_IS_DIR, false); |
| 181 node.Put(IS_UNAPPLIED_UPDATE, false); | 185 password_node.Put(IS_UNSYNCED, false); |
| 182 node.Put(SERVER_VERSION, 20); | 186 password_node.Put(IS_UNAPPLIED_UPDATE, false); |
| 183 node.Put(BASE_VERSION, 20); | 187 password_node.Put(SERVER_VERSION, 20); |
| 184 node.Put(IS_DEL, false); | 188 password_node.Put(BASE_VERSION, 20); |
| 185 node.Put(ID, ids_.MakeServer(browser_sync::kPasswordTag)); | 189 password_node.Put(IS_DEL, false); |
| 186 sync_pb::EntitySpecifics specifics; | 190 password_node.Put(ID, ids_.MakeServer(browser_sync::kPasswordTag)); |
| 187 specifics.MutableExtension(sync_pb::password); | 191 sync_pb::EntitySpecifics password_specifics; |
| 188 node.Put(SPECIFICS, specifics); | 192 password_specifics.MutableExtension(sync_pb::password); |
| 193 password_node.Put(SPECIFICS, password_specifics); |
| 194 } |
| 195 |
| 196 void CreateNigoriRoot() { |
| 197 UserShare* user_share = service_->backend()->GetUserShareHandle(); |
| 198 DirectoryManager* dir_manager = user_share->dir_manager.get(); |
| 199 |
| 200 ScopedDirLookup dir(dir_manager, user_share->authenticated_name); |
| 201 ASSERT_TRUE(dir.good()); |
| 202 |
| 203 WriteTransaction wtrans(dir, UNITTEST, __FILE__, __LINE__); |
| 204 |
| 205 MutableEntry nigori_node(&wtrans, |
| 206 CREATE, |
| 207 wtrans.root_id(), |
| 208 browser_sync::kNigoriTag); |
| 209 nigori_node.Put(UNIQUE_SERVER_TAG, browser_sync::kNigoriTag); |
| 210 nigori_node.Put(IS_DIR, false); |
| 211 nigori_node.Put(SERVER_IS_DIR, false); |
| 212 nigori_node.Put(IS_UNSYNCED, false); |
| 213 nigori_node.Put(IS_UNAPPLIED_UPDATE, false); |
| 214 nigori_node.Put(SERVER_VERSION, 20); |
| 215 nigori_node.Put(BASE_VERSION, 20); |
| 216 nigori_node.Put(IS_DEL, false); |
| 217 nigori_node.Put(ID, ids_.MakeServer(browser_sync::kNigoriTag)); |
| 218 sync_pb::EntitySpecifics nigori_specifics; |
| 219 nigori_specifics.MutableExtension(sync_pb::nigori); |
| 220 nigori_node.Put(SPECIFICS, nigori_specifics); |
| 189 } | 221 } |
| 190 | 222 |
| 191 void AddPasswordSyncNode(const PasswordForm& entry) { | 223 void AddPasswordSyncNode(const PasswordForm& entry) { |
| 192 sync_api::WriteTransaction trans( | 224 sync_api::WriteTransaction trans( |
| 193 service_->backend()->GetUserShareHandle()); | 225 service_->backend()->GetUserShareHandle()); |
| 194 sync_api::ReadNode password_root(&trans); | 226 sync_api::ReadNode password_root(&trans); |
| 195 ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag)); | 227 ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag)); |
| 196 | 228 |
| 197 sync_api::WriteNode node(&trans); | 229 sync_api::WriteNode node(&trans); |
| 198 std::string tag = PasswordModelAssociator::MakeTag(entry); | 230 std::string tag = PasswordModelAssociator::MakeTag(entry); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 lhs.username_value == rhs.username_value && | 265 lhs.username_value == rhs.username_value && |
| 234 lhs.password_element == rhs.password_element && | 266 lhs.password_element == rhs.password_element && |
| 235 lhs.password_value == rhs.password_value && | 267 lhs.password_value == rhs.password_value && |
| 236 lhs.ssl_valid == rhs.ssl_valid && | 268 lhs.ssl_valid == rhs.ssl_valid && |
| 237 lhs.preferred == rhs.preferred && | 269 lhs.preferred == rhs.preferred && |
| 238 lhs.date_created == rhs.date_created && | 270 lhs.date_created == rhs.date_created && |
| 239 lhs.blacklisted_by_user == rhs.blacklisted_by_user; | 271 lhs.blacklisted_by_user == rhs.blacklisted_by_user; |
| 240 } | 272 } |
| 241 | 273 |
| 242 void SetIdleChangeProcessorExpectations() { | 274 void SetIdleChangeProcessorExpectations() { |
| 243 EXPECT_CALL(*(password_store_.get()), AddLoginImpl(_)).Times(0); | 275 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(0); |
| 244 EXPECT_CALL(*(password_store_.get()), UpdateLoginImpl(_)).Times(0); | 276 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(0); |
| 245 EXPECT_CALL(*(password_store_.get()), RemoveLoginImpl(_)).Times(0); | 277 EXPECT_CALL(*password_store_, RemoveLoginImpl(_)).Times(0); |
| 246 } | 278 } |
| 247 | 279 |
| 248 friend class CreatePasswordRootTask; | 280 friend class CreatePasswordRootTask; |
| 281 friend class CreateNigoriRootTask; |
| 249 friend class AddPasswordEntriesTask; | 282 friend class AddPasswordEntriesTask; |
| 250 | 283 |
| 251 MessageLoopForUI message_loop_; | 284 MessageLoopForUI message_loop_; |
| 252 ChromeThread ui_thread_; | 285 ChromeThread ui_thread_; |
| 253 ChromeThread db_thread_; | 286 ChromeThread db_thread_; |
| 254 scoped_refptr<ThreadNotificationService> notification_service_; | 287 scoped_refptr<ThreadNotificationService> notification_service_; |
| 255 | 288 |
| 256 scoped_ptr<TestProfileSyncService> service_; | 289 scoped_ptr<TestProfileSyncService> service_; |
| 257 ProfileMock profile_; | 290 ProfileMock profile_; |
| 258 ProfileSyncFactoryMock factory_; | 291 ProfileSyncFactoryMock factory_; |
| 259 ProfileSyncServiceObserverMock observer_; | 292 ProfileSyncServiceObserverMock observer_; |
| 260 SyncBackendHostMock backend_; | 293 SyncBackendHostMock backend_; |
| 261 scoped_refptr<MockPasswordStore> password_store_; | 294 scoped_refptr<MockPasswordStore> password_store_; |
| 262 | 295 |
| 263 TestIdFactory ids_; | 296 TestIdFactory ids_; |
| 264 }; | 297 }; |
| 265 | 298 |
| 266 class CreatePasswordRootTask : public Task { | 299 class CreatePasswordRootTask : public Task { |
| 267 public: | 300 public: |
| 268 explicit CreatePasswordRootTask(ProfileSyncServicePasswordTest* test) | 301 explicit CreatePasswordRootTask(ProfileSyncServicePasswordTest* test) |
| 269 : test_(test) { | 302 : test_(test) { |
| 270 } | 303 } |
| 271 | 304 |
| 272 virtual void Run() { | 305 virtual void Run() { |
| 306 test_->CreateNigoriRoot(); |
| 273 test_->CreatePasswordRoot(); | 307 test_->CreatePasswordRoot(); |
| 274 } | 308 } |
| 275 | 309 |
| 276 private: | 310 private: |
| 277 ProfileSyncServicePasswordTest* test_; | 311 ProfileSyncServicePasswordTest* test_; |
| 278 }; | 312 }; |
| 279 | 313 |
| 314 class CreateNigoriRootTask : public Task { |
| 315 public: |
| 316 explicit CreateNigoriRootTask(ProfileSyncServicePasswordTest* test) |
| 317 : test_(test) { |
| 318 } |
| 319 |
| 320 virtual void Run() { |
| 321 test_->CreateNigoriRoot(); |
| 322 } |
| 323 |
| 324 private: |
| 325 ProfileSyncServicePasswordTest* test_; |
| 326 }; |
| 327 |
| 280 class AddPasswordEntriesTask : public Task { | 328 class AddPasswordEntriesTask : public Task { |
| 281 public: | 329 public: |
| 282 AddPasswordEntriesTask(ProfileSyncServicePasswordTest* test, | 330 AddPasswordEntriesTask(ProfileSyncServicePasswordTest* test, |
| 283 const std::vector<PasswordForm>& entries) | 331 const std::vector<PasswordForm>& entries) |
| 284 : test_(test), entries_(entries) { | 332 : test_(test), entries_(entries) { |
| 285 } | 333 } |
| 286 | 334 |
| 287 virtual void Run() { | 335 virtual void Run() { |
| 288 test_->CreatePasswordRoot(); | |
| 289 for (size_t i = 0; i < entries_.size(); ++i) { | 336 for (size_t i = 0; i < entries_.size(); ++i) { |
| 290 test_->AddPasswordSyncNode(entries_[i]); | 337 test_->AddPasswordSyncNode(entries_[i]); |
| 291 } | 338 } |
| 292 } | 339 } |
| 293 | 340 |
| 294 private: | 341 private: |
| 295 ProfileSyncServicePasswordTest* test_; | 342 ProfileSyncServicePasswordTest* test_; |
| 296 const std::vector<PasswordForm>& entries_; | 343 const std::vector<PasswordForm>& entries_; |
| 297 }; | 344 }; |
| 298 | 345 |
| 299 TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { | 346 TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { |
| 300 // Backend will be paused but not resumed. | 347 // Backend will be paused but not resumed. |
| 301 EXPECT_CALL(backend_, RequestPause()). | 348 EXPECT_CALL(backend_, RequestPause()). |
| 302 WillRepeatedly(testing::DoAll(Notify(NotificationType::SYNC_PAUSED), | 349 WillRepeatedly(testing::DoAll(Notify(NotificationType::SYNC_PAUSED), |
| 303 testing::Return(true))); | 350 testing::Return(true))); |
| 304 // Don't create the root password node so startup fails. | 351 // Create the nigori root node so that password model association is |
| 305 StartSyncService(NULL); | 352 // attempted, but not the password root node so that it fails. |
| 353 CreateNigoriRootTask task(this); |
| 354 StartSyncService(&task, NULL); |
| 306 EXPECT_TRUE(service_->unrecoverable_error_detected()); | 355 EXPECT_TRUE(service_->unrecoverable_error_detected()); |
| 307 } | 356 } |
| 308 | 357 |
| 309 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { | 358 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { |
| 310 EXPECT_CALL(*(password_store_.get()), FillAutofillableLogins(_)) | 359 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
| 311 .WillOnce(Return(true)); | 360 .WillOnce(Return(true)); |
| 312 EXPECT_CALL(*(password_store_.get()), FillBlacklistLogins(_)) | 361 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) |
| 313 .WillOnce(Return(true)); | 362 .WillOnce(Return(true)); |
| 314 SetIdleChangeProcessorExpectations(); | 363 SetIdleChangeProcessorExpectations(); |
| 315 CreatePasswordRootTask task(this); | 364 CreatePasswordRootTask task(this); |
| 316 StartSyncService(&task); | 365 StartSyncService(&task, NULL); |
| 317 std::vector<PasswordForm> sync_entries; | 366 std::vector<PasswordForm> sync_entries; |
| 318 GetPasswordEntriesFromSyncDB(&sync_entries); | 367 GetPasswordEntriesFromSyncDB(&sync_entries); |
| 319 EXPECT_EQ(0U, sync_entries.size()); | 368 EXPECT_EQ(0U, sync_entries.size()); |
| 320 } | 369 } |
| 321 | 370 |
| 322 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) { | 371 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) { |
| 323 std::vector<PasswordForm*> forms; | 372 std::vector<PasswordForm*> forms; |
| 324 std::vector<PasswordForm> expected_forms; | 373 std::vector<PasswordForm> expected_forms; |
| 325 PasswordForm* new_form = new PasswordForm; | 374 PasswordForm* new_form = new PasswordForm; |
| 326 new_form->scheme = PasswordForm::SCHEME_HTML; | 375 new_form->scheme = PasswordForm::SCHEME_HTML; |
| 327 new_form->signon_realm = "pie"; | 376 new_form->signon_realm = "pie"; |
| 328 new_form->origin = GURL("http://pie.com"); | 377 new_form->origin = GURL("http://pie.com"); |
| 329 new_form->action = GURL("http://pie.com/submit"); | 378 new_form->action = GURL("http://pie.com/submit"); |
| 330 new_form->username_element = UTF8ToUTF16("name"); | 379 new_form->username_element = UTF8ToUTF16("name"); |
| 331 new_form->username_value = UTF8ToUTF16("tom"); | 380 new_form->username_value = UTF8ToUTF16("tom"); |
| 332 new_form->password_element = UTF8ToUTF16("cork"); | 381 new_form->password_element = UTF8ToUTF16("cork"); |
| 333 new_form->password_value = UTF8ToUTF16("password1"); | 382 new_form->password_value = UTF8ToUTF16("password1"); |
| 334 new_form->ssl_valid = true; | 383 new_form->ssl_valid = true; |
| 335 new_form->preferred = false; | 384 new_form->preferred = false; |
| 336 new_form->date_created = base::Time::FromInternalValue(1234); | 385 new_form->date_created = base::Time::FromInternalValue(1234); |
| 337 new_form->blacklisted_by_user = false; | 386 new_form->blacklisted_by_user = false; |
| 338 forms.push_back(new_form); | 387 forms.push_back(new_form); |
| 339 expected_forms.push_back(*new_form); | 388 expected_forms.push_back(*new_form); |
| 340 EXPECT_CALL(*(password_store_.get()), FillAutofillableLogins(_)) | 389 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
| 341 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); | 390 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); |
| 342 EXPECT_CALL(*(password_store_.get()), FillBlacklistLogins(_)) | 391 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) |
| 343 .WillOnce(Return(true)); | 392 .WillOnce(Return(true)); |
| 344 SetIdleChangeProcessorExpectations(); | 393 SetIdleChangeProcessorExpectations(); |
| 345 CreatePasswordRootTask task(this); | 394 CreatePasswordRootTask task(this); |
| 346 StartSyncService(&task); | 395 StartSyncService(&task, NULL); |
| 347 std::vector<PasswordForm> sync_forms; | 396 std::vector<PasswordForm> sync_forms; |
| 348 GetPasswordEntriesFromSyncDB(&sync_forms); | 397 GetPasswordEntriesFromSyncDB(&sync_forms); |
| 349 ASSERT_EQ(1U, sync_forms.size()); | 398 ASSERT_EQ(1U, sync_forms.size()); |
| 350 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0])); | 399 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0])); |
| 351 } | 400 } |
| 352 | 401 |
| 353 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) { | 402 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) { |
| 354 std::vector<PasswordForm*> forms; | 403 std::vector<PasswordForm*> forms; |
| 355 std::vector<PasswordForm> expected_forms; | 404 std::vector<PasswordForm> expected_forms; |
| 356 | 405 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 382 new_form->password_element = UTF8ToUTF16("cork"); | 431 new_form->password_element = UTF8ToUTF16("cork"); |
| 383 new_form->password_value = UTF8ToUTF16("password2"); | 432 new_form->password_value = UTF8ToUTF16("password2"); |
| 384 new_form->ssl_valid = true; | 433 new_form->ssl_valid = true; |
| 385 new_form->preferred = false; | 434 new_form->preferred = false; |
| 386 new_form->date_created = base::Time::FromInternalValue(1234); | 435 new_form->date_created = base::Time::FromInternalValue(1234); |
| 387 new_form->blacklisted_by_user = false; | 436 new_form->blacklisted_by_user = false; |
| 388 forms.push_back(new_form); | 437 forms.push_back(new_form); |
| 389 expected_forms.push_back(*new_form); | 438 expected_forms.push_back(*new_form); |
| 390 } | 439 } |
| 391 | 440 |
| 392 EXPECT_CALL(*(password_store_.get()), FillAutofillableLogins(_)) | 441 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
| 393 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); | 442 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); |
| 394 EXPECT_CALL(*(password_store_.get()), FillBlacklistLogins(_)) | 443 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) |
| 395 .WillOnce(Return(true)); | 444 .WillOnce(Return(true)); |
| 396 SetIdleChangeProcessorExpectations(); | 445 SetIdleChangeProcessorExpectations(); |
| 397 CreatePasswordRootTask task(this); | 446 CreatePasswordRootTask task(this); |
| 398 StartSyncService(&task); | 447 StartSyncService(&task, NULL); |
| 399 std::vector<PasswordForm> sync_forms; | 448 std::vector<PasswordForm> sync_forms; |
| 400 GetPasswordEntriesFromSyncDB(&sync_forms); | 449 GetPasswordEntriesFromSyncDB(&sync_forms); |
| 401 ASSERT_EQ(2U, sync_forms.size()); | 450 ASSERT_EQ(2U, sync_forms.size()); |
| 402 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1])); | 451 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1])); |
| 403 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0])); | 452 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0])); |
| 404 } | 453 } |
| 405 | 454 |
| 406 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) { | 455 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) { |
| 407 std::vector<PasswordForm*> native_forms; | 456 std::vector<PasswordForm*> native_forms; |
| 408 std::vector<PasswordForm> sync_forms; | 457 std::vector<PasswordForm> sync_forms; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 437 new_form.password_element = UTF8ToUTF16("cork2"); | 486 new_form.password_element = UTF8ToUTF16("cork2"); |
| 438 new_form.password_value = UTF8ToUTF16("password12"); | 487 new_form.password_value = UTF8ToUTF16("password12"); |
| 439 new_form.ssl_valid = false; | 488 new_form.ssl_valid = false; |
| 440 new_form.preferred = true; | 489 new_form.preferred = true; |
| 441 new_form.date_created = base::Time::FromInternalValue(12345); | 490 new_form.date_created = base::Time::FromInternalValue(12345); |
| 442 new_form.blacklisted_by_user = false; | 491 new_form.blacklisted_by_user = false; |
| 443 sync_forms.push_back(new_form); | 492 sync_forms.push_back(new_form); |
| 444 expected_forms.push_back(new_form); | 493 expected_forms.push_back(new_form); |
| 445 } | 494 } |
| 446 | 495 |
| 447 EXPECT_CALL(*(password_store_.get()), FillAutofillableLogins(_)) | 496 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
| 448 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); | 497 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); |
| 449 EXPECT_CALL(*(password_store_.get()), FillBlacklistLogins(_)) | 498 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); |
| 450 .WillOnce(Return(true)); | 499 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1); |
| 451 | 500 |
| 452 AddPasswordEntriesTask task(this, sync_forms); | 501 CreatePasswordRootTask root_task(this); |
| 453 | 502 AddPasswordEntriesTask node_task(this, sync_forms); |
| 454 EXPECT_CALL(*(password_store_.get()), AddLoginImpl(_)).Times(1); | 503 StartSyncService(&root_task, &node_task); |
| 455 StartSyncService(&task); | |
| 456 | 504 |
| 457 std::vector<PasswordForm> new_sync_forms; | 505 std::vector<PasswordForm> new_sync_forms; |
| 458 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 506 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
| 459 | 507 |
| 460 EXPECT_EQ(2U, new_sync_forms.size()); | 508 EXPECT_EQ(2U, new_sync_forms.size()); |
| 461 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 509 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
| 462 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1])); | 510 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1])); |
| 463 } | 511 } |
| 464 | 512 |
| 465 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncMergeEntry) { | 513 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncMergeEntry) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 new_form.username_value = UTF8ToUTF16("tom"); | 559 new_form.username_value = UTF8ToUTF16("tom"); |
| 512 new_form.password_element = UTF8ToUTF16("cork"); | 560 new_form.password_element = UTF8ToUTF16("cork"); |
| 513 new_form.password_value = UTF8ToUTF16("password12"); | 561 new_form.password_value = UTF8ToUTF16("password12"); |
| 514 new_form.ssl_valid = false; | 562 new_form.ssl_valid = false; |
| 515 new_form.preferred = true; | 563 new_form.preferred = true; |
| 516 new_form.date_created = base::Time::FromInternalValue(12345); | 564 new_form.date_created = base::Time::FromInternalValue(12345); |
| 517 new_form.blacklisted_by_user = false; | 565 new_form.blacklisted_by_user = false; |
| 518 expected_forms.push_back(new_form); | 566 expected_forms.push_back(new_form); |
| 519 } | 567 } |
| 520 | 568 |
| 521 EXPECT_CALL(*(password_store_.get()), FillAutofillableLogins(_)) | 569 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
| 522 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); | 570 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); |
| 523 EXPECT_CALL(*(password_store_.get()), FillBlacklistLogins(_)) | 571 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); |
| 524 .WillOnce(Return(true)); | 572 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1); |
| 525 | 573 |
| 526 AddPasswordEntriesTask task(this, sync_forms); | 574 CreatePasswordRootTask root_task(this); |
| 575 AddPasswordEntriesTask node_task(this, sync_forms); |
| 527 | 576 |
| 528 EXPECT_CALL(*(password_store_.get()), UpdateLoginImpl(_)).Times(1); | 577 StartSyncService(&root_task, &node_task); |
| 529 StartSyncService(&task); | |
| 530 | 578 |
| 531 std::vector<PasswordForm> new_sync_forms; | 579 std::vector<PasswordForm> new_sync_forms; |
| 532 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 580 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
| 533 | 581 |
| 534 EXPECT_EQ(1U, new_sync_forms.size()); | 582 EXPECT_EQ(1U, new_sync_forms.size()); |
| 535 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 583 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
| 536 } | 584 } |
| OLD | NEW |