| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/test/signaling_task.h" |
| 10 #include "base/time.h" | 11 #include "base/time.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/password_manager/password_form_data.h" | 13 #include "chrome/browser/password_manager/password_form_data.h" |
| 13 #include "chrome/browser/password_manager/password_store_change.h" | 14 #include "chrome/browser/password_manager/password_store_change.h" |
| 14 #include "chrome/browser/password_manager/password_store_consumer.h" | 15 #include "chrome/browser/password_manager/password_store_consumer.h" |
| 15 #include "chrome/browser/password_manager/password_store_default.h" | 16 #include "chrome/browser/password_manager/password_store_default.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/webdata/web_data_service.h" | 18 #include "chrome/browser/webdata/web_data_service.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/test/base/signaling_task.h" | |
| 21 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 22 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
| 23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 24 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
| 25 #include "content/test/notification_observer_mock.h" | 25 #include "content/test/notification_observer_mock.h" |
| 26 #include "content/test/test_browser_thread.h" | 26 #include "content/test/test_browser_thread.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 29 |
| 30 using base::WaitableEvent; | 30 using base::WaitableEvent; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(form_data); ++i) { | 183 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(form_data); ++i) { |
| 184 PasswordForm* form = CreatePasswordFormFromData(form_data[i]); | 184 PasswordForm* form = CreatePasswordFormFromData(form_data[i]); |
| 185 expected_forms.push_back(form); | 185 expected_forms.push_back(form); |
| 186 store->AddLogin(*form); | 186 store->AddLogin(*form); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // The PasswordStore schedules tasks to run on the DB thread so we schedule | 189 // The PasswordStore schedules tasks to run on the DB thread so we schedule |
| 190 // yet another task to notify us that it's safe to carry on with the test. | 190 // yet another task to notify us that it's safe to carry on with the test. |
| 191 WaitableEvent done(false, false); | 191 WaitableEvent done(false, false); |
| 192 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 192 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 193 new SignalingTask(&done)); | 193 new base::SignalingTask(&done)); |
| 194 done.Wait(); | 194 done.Wait(); |
| 195 | 195 |
| 196 MockPasswordStoreConsumer consumer; | 196 MockPasswordStoreConsumer consumer; |
| 197 | 197 |
| 198 // Make sure we quit the MessageLoop even if the test fails. | 198 // Make sure we quit the MessageLoop even if the test fails. |
| 199 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) | 199 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) |
| 200 .WillByDefault(QuitUIMessageLoop()); | 200 .WillByDefault(QuitUIMessageLoop()); |
| 201 | 201 |
| 202 // We expect to get the same data back, even though it's not all ASCII. | 202 // We expect to get the same data back, even though it's not all ASCII. |
| 203 EXPECT_CALL(consumer, | 203 EXPECT_CALL(consumer, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(blacklisted_data); ++i) { | 278 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(blacklisted_data); ++i) { |
| 279 PasswordForm* form = CreatePasswordFormFromData(blacklisted_data[i]); | 279 PasswordForm* form = CreatePasswordFormFromData(blacklisted_data[i]); |
| 280 expected_blacklisted.push_back(form); | 280 expected_blacklisted.push_back(form); |
| 281 wds_->AddLogin(*form); | 281 wds_->AddLogin(*form); |
| 282 } | 282 } |
| 283 | 283 |
| 284 // The WDS schedules tasks to run on the DB thread so we schedule yet another | 284 // The WDS schedules tasks to run on the DB thread so we schedule yet another |
| 285 // task to notify us that it's safe to carry on with the test. | 285 // task to notify us that it's safe to carry on with the test. |
| 286 WaitableEvent done(false, false); | 286 WaitableEvent done(false, false); |
| 287 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 287 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 288 new SignalingTask(&done)); | 288 new base::SignalingTask(&done)); |
| 289 done.Wait(); | 289 done.Wait(); |
| 290 | 290 |
| 291 // Initializing the PasswordStore should trigger a migration. | 291 // Initializing the PasswordStore should trigger a migration. |
| 292 scoped_refptr<PasswordStore> store( | 292 scoped_refptr<PasswordStore> store( |
| 293 new PasswordStoreDefault(login_db_.release(), | 293 new PasswordStoreDefault(login_db_.release(), |
| 294 profile_.get(), wds_.get())); | 294 profile_.get(), wds_.get())); |
| 295 store->Init(); | 295 store->Init(); |
| 296 | 296 |
| 297 // Check that the migration preference has not been initialized; | 297 // Check that the migration preference has not been initialized; |
| 298 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference( | 298 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference( |
| 299 prefs::kLoginDatabaseMigrated)); | 299 prefs::kLoginDatabaseMigrated)); |
| 300 | 300 |
| 301 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task | 301 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task |
| 302 // to signal us when it is safe to continue. | 302 // to signal us when it is safe to continue. |
| 303 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 303 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 304 new SignalingTask(&done)); | 304 new base::SignalingTask(&done)); |
| 305 done.Wait(); | 305 done.Wait(); |
| 306 | 306 |
| 307 // Let the WDS callbacks proceed so the logins can be migrated. | 307 // Let the WDS callbacks proceed so the logins can be migrated. |
| 308 MessageLoop::current()->RunAllPending(); | 308 MessageLoop::current()->RunAllPending(); |
| 309 | 309 |
| 310 MockPasswordStoreConsumer consumer; | 310 MockPasswordStoreConsumer consumer; |
| 311 | 311 |
| 312 // Make sure we quit the MessageLoop even if the test fails. | 312 // Make sure we quit the MessageLoop even if the test fails. |
| 313 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) | 313 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) |
| 314 .WillByDefault(QuitUIMessageLoop()); | 314 .WillByDefault(QuitUIMessageLoop()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 339 MockWebDataServiceConsumer wds_consumer; | 339 MockWebDataServiceConsumer wds_consumer; |
| 340 | 340 |
| 341 // No autofillable logins should be left in the WDS. | 341 // No autofillable logins should be left in the WDS. |
| 342 EXPECT_CALL(wds_consumer, | 342 EXPECT_CALL(wds_consumer, |
| 343 OnWebDataServiceRequestDone(_, EmptyWDResult())); | 343 OnWebDataServiceRequestDone(_, EmptyWDResult())); |
| 344 | 344 |
| 345 wds_->GetAutofillableLogins(&wds_consumer); | 345 wds_->GetAutofillableLogins(&wds_consumer); |
| 346 | 346 |
| 347 // Wait for the WDS methods to execute on the DB thread. | 347 // Wait for the WDS methods to execute on the DB thread. |
| 348 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 348 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 349 new SignalingTask(&done)); | 349 new base::SignalingTask(&done)); |
| 350 done.Wait(); | 350 done.Wait(); |
| 351 | 351 |
| 352 // Handle the callback from the WDS. | 352 // Handle the callback from the WDS. |
| 353 MessageLoop::current()->RunAllPending(); | 353 MessageLoop::current()->RunAllPending(); |
| 354 | 354 |
| 355 // Likewise, no blacklisted logins should be left in the WDS. | 355 // Likewise, no blacklisted logins should be left in the WDS. |
| 356 EXPECT_CALL(wds_consumer, | 356 EXPECT_CALL(wds_consumer, |
| 357 OnWebDataServiceRequestDone(_, EmptyWDResult())); | 357 OnWebDataServiceRequestDone(_, EmptyWDResult())); |
| 358 | 358 |
| 359 wds_->GetBlacklistLogins(&wds_consumer); | 359 wds_->GetBlacklistLogins(&wds_consumer); |
| 360 | 360 |
| 361 // Wait for the WDS methods to execute on the DB thread. | 361 // Wait for the WDS methods to execute on the DB thread. |
| 362 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 362 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 363 new SignalingTask(&done)); | 363 new base::SignalingTask(&done)); |
| 364 done.Wait(); | 364 done.Wait(); |
| 365 | 365 |
| 366 // Handle the callback from the WDS. | 366 // Handle the callback from the WDS. |
| 367 MessageLoop::current()->RunAllPending(); | 367 MessageLoop::current()->RunAllPending(); |
| 368 | 368 |
| 369 STLDeleteElements(&expected_autofillable); | 369 STLDeleteElements(&expected_autofillable); |
| 370 STLDeleteElements(&expected_blacklisted); | 370 STLDeleteElements(&expected_blacklisted); |
| 371 | 371 |
| 372 store->Shutdown(); | 372 store->Shutdown(); |
| 373 } | 373 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 391 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(wds_data); ++i) { | 391 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(wds_data); ++i) { |
| 392 PasswordForm* form = CreatePasswordFormFromData(wds_data[i]); | 392 PasswordForm* form = CreatePasswordFormFromData(wds_data[i]); |
| 393 unexpected_autofillable.push_back(form); | 393 unexpected_autofillable.push_back(form); |
| 394 wds_->AddLogin(*form); | 394 wds_->AddLogin(*form); |
| 395 } | 395 } |
| 396 | 396 |
| 397 // The WDS schedules tasks to run on the DB thread so we schedule yet another | 397 // The WDS schedules tasks to run on the DB thread so we schedule yet another |
| 398 // task to notify us that it's safe to carry on with the test. | 398 // task to notify us that it's safe to carry on with the test. |
| 399 WaitableEvent done(false, false); | 399 WaitableEvent done(false, false); |
| 400 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 400 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 401 new SignalingTask(&done)); | 401 new base::SignalingTask(&done)); |
| 402 done.Wait(); | 402 done.Wait(); |
| 403 | 403 |
| 404 // Pretend that the migration has already taken place. | 404 // Pretend that the migration has already taken place. |
| 405 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, | 405 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, |
| 406 true, | 406 true, |
| 407 PrefService::UNSYNCABLE_PREF); | 407 PrefService::UNSYNCABLE_PREF); |
| 408 | 408 |
| 409 // Initializing the PasswordStore shouldn't trigger a migration. | 409 // Initializing the PasswordStore shouldn't trigger a migration. |
| 410 scoped_refptr<PasswordStore> store( | 410 scoped_refptr<PasswordStore> store( |
| 411 new PasswordStoreDefault(login_db_.release(), profile_.get(), | 411 new PasswordStoreDefault(login_db_.release(), profile_.get(), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 Pointee(ElementsAreArray( | 471 Pointee(ElementsAreArray( |
| 472 expected_add_changes))))); | 472 expected_add_changes))))); |
| 473 | 473 |
| 474 // Adding a login should trigger a notification. | 474 // Adding a login should trigger a notification. |
| 475 store->AddLogin(*form); | 475 store->AddLogin(*form); |
| 476 | 476 |
| 477 // The PasswordStore schedules tasks to run on the DB thread so we schedule | 477 // The PasswordStore schedules tasks to run on the DB thread so we schedule |
| 478 // yet another task to notify us that it's safe to carry on with the test. | 478 // yet another task to notify us that it's safe to carry on with the test. |
| 479 WaitableEvent done(false, false); | 479 WaitableEvent done(false, false); |
| 480 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 480 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 481 new SignalingTask(&done)); | 481 new base::SignalingTask(&done)); |
| 482 done.Wait(); | 482 done.Wait(); |
| 483 | 483 |
| 484 // Change the password. | 484 // Change the password. |
| 485 form->password_value = WideToUTF16(L"a different password"); | 485 form->password_value = WideToUTF16(L"a different password"); |
| 486 | 486 |
| 487 const PasswordStoreChange expected_update_changes[] = { | 487 const PasswordStoreChange expected_update_changes[] = { |
| 488 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), | 488 PasswordStoreChange(PasswordStoreChange::UPDATE, *form), |
| 489 }; | 489 }; |
| 490 | 490 |
| 491 EXPECT_CALL(helper->observer(), | 491 EXPECT_CALL(helper->observer(), |
| 492 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), | 492 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), |
| 493 content::Source<PasswordStore>(store), | 493 content::Source<PasswordStore>(store), |
| 494 Property(&content::Details<const PasswordStoreChangeList>::ptr, | 494 Property(&content::Details<const PasswordStoreChangeList>::ptr, |
| 495 Pointee(ElementsAreArray( | 495 Pointee(ElementsAreArray( |
| 496 expected_update_changes))))); | 496 expected_update_changes))))); |
| 497 | 497 |
| 498 // Updating the login with the new password should trigger a notification. | 498 // Updating the login with the new password should trigger a notification. |
| 499 store->UpdateLogin(*form); | 499 store->UpdateLogin(*form); |
| 500 | 500 |
| 501 // Wait for PasswordStore to send the notification. | 501 // Wait for PasswordStore to send the notification. |
| 502 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 502 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 503 new SignalingTask(&done)); | 503 new base::SignalingTask(&done)); |
| 504 done.Wait(); | 504 done.Wait(); |
| 505 | 505 |
| 506 const PasswordStoreChange expected_delete_changes[] = { | 506 const PasswordStoreChange expected_delete_changes[] = { |
| 507 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), | 507 PasswordStoreChange(PasswordStoreChange::REMOVE, *form), |
| 508 }; | 508 }; |
| 509 | 509 |
| 510 EXPECT_CALL(helper->observer(), | 510 EXPECT_CALL(helper->observer(), |
| 511 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), | 511 Observe(int(chrome::NOTIFICATION_LOGINS_CHANGED), |
| 512 content::Source<PasswordStore>(store), | 512 content::Source<PasswordStore>(store), |
| 513 Property(&content::Details<const PasswordStoreChangeList>::ptr, | 513 Property(&content::Details<const PasswordStoreChangeList>::ptr, |
| 514 Pointee(ElementsAreArray( | 514 Pointee(ElementsAreArray( |
| 515 expected_delete_changes))))); | 515 expected_delete_changes))))); |
| 516 | 516 |
| 517 // Deleting the login should trigger a notification. | 517 // Deleting the login should trigger a notification. |
| 518 store->RemoveLogin(*form); | 518 store->RemoveLogin(*form); |
| 519 | 519 |
| 520 // Wait for PasswordStore to send the notification. | 520 // Wait for PasswordStore to send the notification. |
| 521 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 521 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 522 new SignalingTask(&done)); | 522 new base::SignalingTask(&done)); |
| 523 done.Wait(); | 523 done.Wait(); |
| 524 | 524 |
| 525 store->Shutdown(); | 525 store->Shutdown(); |
| 526 } | 526 } |
| OLD | NEW |