OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 1;2c// 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" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 WillRepeatedly(Return(password_store_.get())); | 171 WillRepeatedly(Return(password_store_.get())); |
172 | 172 |
173 EXPECT_CALL(observer_, | 173 EXPECT_CALL(observer_, |
174 Observe( | 174 Observe( |
175 NotificationType(NotificationType::SYNC_CONFIGURE_DONE),_,_)); | 175 NotificationType(NotificationType::SYNC_CONFIGURE_DONE),_,_)); |
176 | 176 |
177 service_->RegisterDataTypeController(data_type_controller); | 177 service_->RegisterDataTypeController(data_type_controller); |
178 service_->Initialize(); | 178 service_->Initialize(); |
179 MessageLoop::current()->Run(); | 179 MessageLoop::current()->Run(); |
180 | 180 |
181 // Only set the passphrase if we actually created the password and nigori | 181 EXPECT_CALL( |
182 // root nodes. | 182 observer_, |
183 if (root_task) { | 183 Observe( |
184 EXPECT_CALL(observer_, | 184 NotificationType(NotificationType::SYNC_PASSPHRASE_ACCEPTED), |
185 Observe( | 185 _,_)). |
186 NotificationType(NotificationType::SYNC_PASSPHRASE_ACCEPTED), | 186 WillOnce(InvokeTask(node_task)); |
187 _,_)). | 187 EXPECT_CALL( |
188 WillOnce(InvokeTask(node_task)); | 188 observer_, |
189 EXPECT_CALL(observer_, | 189 Observe( |
190 Observe( | 190 NotificationType(NotificationType::SYNC_CONFIGURE_DONE), |
191 NotificationType(NotificationType::SYNC_CONFIGURE_DONE), | 191 _,_)). |
192 _,_)). | 192 WillOnce(QuitUIMessageLoop()); |
193 WillOnce(QuitUIMessageLoop()); | 193 service_->SetPassphrase("foo", false, true); |
194 service_->SetPassphrase("foo", false, true); | 194 MessageLoop::current()->Run(); |
195 MessageLoop::current()->Run(); | |
196 } | |
197 } | 195 } |
198 } | 196 } |
199 | 197 |
200 void AddPasswordSyncNode(const PasswordForm& entry) { | 198 void AddPasswordSyncNode(const PasswordForm& entry) { |
201 sync_api::WriteTransaction trans( | 199 sync_api::WriteTransaction trans( |
202 service_->backend()->GetUserShareHandle()); | 200 service_->backend()->GetUserShareHandle()); |
203 sync_api::ReadNode password_root(&trans); | 201 sync_api::ReadNode password_root(&trans); |
204 ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag)); | 202 ASSERT_TRUE(password_root.InitByTagLookup(browser_sync::kPasswordTag)); |
205 | 203 |
206 sync_api::WriteNode node(&trans); | 204 sync_api::WriteNode node(&trans); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 254 |
257 friend class AddPasswordEntriesTask; | 255 friend class AddPasswordEntriesTask; |
258 | 256 |
259 BrowserThread db_thread_; | 257 BrowserThread db_thread_; |
260 scoped_refptr<ThreadNotificationService> notification_service_; | 258 scoped_refptr<ThreadNotificationService> notification_service_; |
261 NotificationObserverMock observer_; | 259 NotificationObserverMock observer_; |
262 ProfileMock profile_; | 260 ProfileMock profile_; |
263 scoped_refptr<MockPasswordStore> password_store_; | 261 scoped_refptr<MockPasswordStore> password_store_; |
264 NotificationRegistrar registrar_; | 262 NotificationRegistrar registrar_; |
265 | 263 |
266 TestIdFactory ids_; | |
267 }; | |
268 | |
269 class CreatePasswordRootTask : public Task { | |
270 public: | |
271 explicit CreatePasswordRootTask(AbstractProfileSyncServiceTest* test) | |
272 : test_(test) { | |
273 } | |
274 | |
275 virtual void Run() { | |
276 test_->CreateRoot(syncable::NIGORI); | |
277 test_->CreateRoot(syncable::PASSWORDS); | |
278 } | |
279 | |
280 private: | |
281 AbstractProfileSyncServiceTest* test_; | |
282 }; | 264 }; |
283 | 265 |
284 class AddPasswordEntriesTask : public Task { | 266 class AddPasswordEntriesTask : public Task { |
285 public: | 267 public: |
286 AddPasswordEntriesTask(ProfileSyncServicePasswordTest* test, | 268 AddPasswordEntriesTask(ProfileSyncServicePasswordTest* test, |
287 const std::vector<PasswordForm>& entries) | 269 const std::vector<PasswordForm>& entries) |
288 : test_(test), entries_(entries) { | 270 : test_(test), entries_(entries) { |
289 } | 271 } |
290 | 272 |
291 virtual void Run() { | 273 virtual void Run() { |
292 for (size_t i = 0; i < entries_.size(); ++i) { | 274 for (size_t i = 0; i < entries_.size(); ++i) { |
293 test_->AddPasswordSyncNode(entries_[i]); | 275 test_->AddPasswordSyncNode(entries_[i]); |
294 } | 276 } |
295 } | 277 } |
296 | 278 |
297 private: | 279 private: |
298 ProfileSyncServicePasswordTest* test_; | 280 ProfileSyncServicePasswordTest* test_; |
299 const std::vector<PasswordForm>& entries_; | 281 const std::vector<PasswordForm>& entries_; |
300 }; | 282 }; |
301 | 283 |
302 TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { | 284 TEST_F(ProfileSyncServicePasswordTest, FailModelAssociation) { |
303 // Create the nigori root node so that password model association is | 285 StartSyncService(NULL, NULL, 1, 2); |
304 // attempted, but not the password root node so that it fails. | |
305 CreateRootTask task(this, syncable::NIGORI); | |
306 StartSyncService(&task, NULL, 1, 2); | |
307 EXPECT_TRUE(service_->unrecoverable_error_detected()); | 286 EXPECT_TRUE(service_->unrecoverable_error_detected()); |
308 } | 287 } |
309 | 288 |
310 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { | 289 TEST_F(ProfileSyncServicePasswordTest, EmptyNativeEmptySync) { |
311 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 290 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
312 .WillOnce(Return(true)); | 291 .WillOnce(Return(true)); |
313 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) | 292 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) |
314 .WillOnce(Return(true)); | 293 .WillOnce(Return(true)); |
315 SetIdleChangeProcessorExpectations(); | 294 SetIdleChangeProcessorExpectations(); |
316 CreatePasswordRootTask task(this); | 295 CreateRootTask task(this, syncable::PASSWORDS); |
317 StartSyncService(&task, NULL); | 296 StartSyncService(&task, NULL); |
318 std::vector<PasswordForm> sync_entries; | 297 std::vector<PasswordForm> sync_entries; |
319 GetPasswordEntriesFromSyncDB(&sync_entries); | 298 GetPasswordEntriesFromSyncDB(&sync_entries); |
320 EXPECT_EQ(0U, sync_entries.size()); | 299 EXPECT_EQ(0U, sync_entries.size()); |
321 } | 300 } |
322 | 301 |
323 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) { | 302 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySync) { |
324 std::vector<PasswordForm*> forms; | 303 std::vector<PasswordForm*> forms; |
325 std::vector<PasswordForm> expected_forms; | 304 std::vector<PasswordForm> expected_forms; |
326 PasswordForm* new_form = new PasswordForm; | 305 PasswordForm* new_form = new PasswordForm; |
327 new_form->scheme = PasswordForm::SCHEME_HTML; | 306 new_form->scheme = PasswordForm::SCHEME_HTML; |
328 new_form->signon_realm = "pie"; | 307 new_form->signon_realm = "pie"; |
329 new_form->origin = GURL("http://pie.com"); | 308 new_form->origin = GURL("http://pie.com"); |
330 new_form->action = GURL("http://pie.com/submit"); | 309 new_form->action = GURL("http://pie.com/submit"); |
331 new_form->username_element = UTF8ToUTF16("name"); | 310 new_form->username_element = UTF8ToUTF16("name"); |
332 new_form->username_value = UTF8ToUTF16("tom"); | 311 new_form->username_value = UTF8ToUTF16("tom"); |
333 new_form->password_element = UTF8ToUTF16("cork"); | 312 new_form->password_element = UTF8ToUTF16("cork"); |
334 new_form->password_value = UTF8ToUTF16("password1"); | 313 new_form->password_value = UTF8ToUTF16("password1"); |
335 new_form->ssl_valid = true; | 314 new_form->ssl_valid = true; |
336 new_form->preferred = false; | 315 new_form->preferred = false; |
337 new_form->date_created = base::Time::FromInternalValue(1234); | 316 new_form->date_created = base::Time::FromInternalValue(1234); |
338 new_form->blacklisted_by_user = false; | 317 new_form->blacklisted_by_user = false; |
339 forms.push_back(new_form); | 318 forms.push_back(new_form); |
340 expected_forms.push_back(*new_form); | 319 expected_forms.push_back(*new_form); |
341 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 320 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
342 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); | 321 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); |
343 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) | 322 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) |
344 .WillOnce(Return(true)); | 323 .WillOnce(Return(true)); |
345 SetIdleChangeProcessorExpectations(); | 324 SetIdleChangeProcessorExpectations(); |
346 CreatePasswordRootTask task(this); | 325 CreateRootTask task(this, syncable::PASSWORDS); |
347 StartSyncService(&task, NULL); | 326 StartSyncService(&task, NULL); |
348 std::vector<PasswordForm> sync_forms; | 327 std::vector<PasswordForm> sync_forms; |
349 GetPasswordEntriesFromSyncDB(&sync_forms); | 328 GetPasswordEntriesFromSyncDB(&sync_forms); |
350 ASSERT_EQ(1U, sync_forms.size()); | 329 ASSERT_EQ(1U, sync_forms.size()); |
351 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0])); | 330 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[0])); |
352 } | 331 } |
353 | 332 |
354 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) { | 333 TEST_F(ProfileSyncServicePasswordTest, HasNativeEntriesEmptySyncSameUsername) { |
355 std::vector<PasswordForm*> forms; | 334 std::vector<PasswordForm*> forms; |
356 std::vector<PasswordForm> expected_forms; | 335 std::vector<PasswordForm> expected_forms; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 new_form->blacklisted_by_user = false; | 367 new_form->blacklisted_by_user = false; |
389 forms.push_back(new_form); | 368 forms.push_back(new_form); |
390 expected_forms.push_back(*new_form); | 369 expected_forms.push_back(*new_form); |
391 } | 370 } |
392 | 371 |
393 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 372 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
394 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); | 373 .WillOnce(DoAll(SetArgumentPointee<0>(forms), Return(true))); |
395 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) | 374 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)) |
396 .WillOnce(Return(true)); | 375 .WillOnce(Return(true)); |
397 SetIdleChangeProcessorExpectations(); | 376 SetIdleChangeProcessorExpectations(); |
398 CreatePasswordRootTask task(this); | 377 CreateRootTask task(this, syncable::PASSWORDS); |
399 StartSyncService(&task, NULL); | 378 StartSyncService(&task, NULL); |
400 std::vector<PasswordForm> sync_forms; | 379 std::vector<PasswordForm> sync_forms; |
401 GetPasswordEntriesFromSyncDB(&sync_forms); | 380 GetPasswordEntriesFromSyncDB(&sync_forms); |
402 ASSERT_EQ(2U, sync_forms.size()); | 381 ASSERT_EQ(2U, sync_forms.size()); |
403 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1])); | 382 EXPECT_TRUE(ComparePasswords(expected_forms[0], sync_forms[1])); |
404 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0])); | 383 EXPECT_TRUE(ComparePasswords(expected_forms[1], sync_forms[0])); |
405 } | 384 } |
406 | 385 |
407 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) { | 386 TEST_F(ProfileSyncServicePasswordTest, HasNativeHasSyncNoMerge) { |
408 std::vector<PasswordForm*> native_forms; | 387 std::vector<PasswordForm*> native_forms; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 new_form.blacklisted_by_user = false; | 422 new_form.blacklisted_by_user = false; |
444 sync_forms.push_back(new_form); | 423 sync_forms.push_back(new_form); |
445 expected_forms.push_back(new_form); | 424 expected_forms.push_back(new_form); |
446 } | 425 } |
447 | 426 |
448 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 427 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
449 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); | 428 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); |
450 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); | 429 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); |
451 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1); | 430 EXPECT_CALL(*password_store_, AddLoginImpl(_)).Times(1); |
452 | 431 |
453 CreatePasswordRootTask root_task(this); | 432 CreateRootTask root_task(this, syncable::PASSWORDS); |
454 AddPasswordEntriesTask node_task(this, sync_forms); | 433 AddPasswordEntriesTask node_task(this, sync_forms); |
455 StartSyncService(&root_task, &node_task); | 434 StartSyncService(&root_task, &node_task); |
456 | 435 |
457 std::vector<PasswordForm> new_sync_forms; | 436 std::vector<PasswordForm> new_sync_forms; |
458 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 437 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
459 | 438 |
460 EXPECT_EQ(2U, new_sync_forms.size()); | 439 EXPECT_EQ(2U, new_sync_forms.size()); |
461 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 440 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
462 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1])); | 441 EXPECT_TRUE(ComparePasswords(expected_forms[1], new_sync_forms[1])); |
463 } | 442 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 new_form.date_created = base::Time::FromInternalValue(12345); | 495 new_form.date_created = base::Time::FromInternalValue(12345); |
517 new_form.blacklisted_by_user = false; | 496 new_form.blacklisted_by_user = false; |
518 expected_forms.push_back(new_form); | 497 expected_forms.push_back(new_form); |
519 } | 498 } |
520 | 499 |
521 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) | 500 EXPECT_CALL(*password_store_, FillAutofillableLogins(_)) |
522 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); | 501 .WillOnce(DoAll(SetArgumentPointee<0>(native_forms), Return(true))); |
523 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); | 502 EXPECT_CALL(*password_store_, FillBlacklistLogins(_)).WillOnce(Return(true)); |
524 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1); | 503 EXPECT_CALL(*password_store_, UpdateLoginImpl(_)).Times(1); |
525 | 504 |
526 CreatePasswordRootTask root_task(this); | 505 CreateRootTask root_task(this, syncable::PASSWORDS); |
527 AddPasswordEntriesTask node_task(this, sync_forms); | 506 AddPasswordEntriesTask node_task(this, sync_forms); |
528 | 507 |
529 StartSyncService(&root_task, &node_task); | 508 StartSyncService(&root_task, &node_task); |
530 | 509 |
531 std::vector<PasswordForm> new_sync_forms; | 510 std::vector<PasswordForm> new_sync_forms; |
532 GetPasswordEntriesFromSyncDB(&new_sync_forms); | 511 GetPasswordEntriesFromSyncDB(&new_sync_forms); |
533 | 512 |
534 EXPECT_EQ(1U, new_sync_forms.size()); | 513 EXPECT_EQ(1U, new_sync_forms.size()); |
535 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); | 514 EXPECT_TRUE(ComparePasswords(expected_forms[0], new_sync_forms[0])); |
536 } | 515 } |
OLD | NEW |