| Index: chrome/browser/password_manager/password_store_win_unittest.cc
|
| diff --git a/chrome/browser/password_manager/password_store_win_unittest.cc b/chrome/browser/password_manager/password_store_win_unittest.cc
|
| index ed78289e812f4a0a634fb5f31806054a6c78c368..198084053547ad40c6b3ef5ffa93b5e8db17d6b2 100644
|
| --- a/chrome/browser/password_manager/password_store_win_unittest.cc
|
| +++ b/chrome/browser/password_manager/password_store_win_unittest.cc
|
| @@ -23,6 +23,8 @@
|
|
|
| using base::WaitableEvent;
|
| using testing::_;
|
| +using testing::DoAll;
|
| +using testing::WithArg;
|
| using webkit_glue::PasswordForm;
|
|
|
| namespace {
|
| @@ -52,6 +54,8 @@ class SignalingTask : public Task {
|
|
|
| } // anonymous namespace
|
|
|
| +typedef std::vector<PasswordForm*> VectorOfForms;
|
| +
|
| class PasswordStoreWinTest : public testing::Test {
|
| protected:
|
| PasswordStoreWinTest()
|
| @@ -134,11 +138,20 @@ class PasswordStoreWinTest : public testing::Test {
|
| ScopedTempDir temp_dir_;
|
| };
|
|
|
| +ACTION(STLDeleteElements0) {
|
| + STLDeleteContainerPointers(arg0.begin(), arg0.end());
|
| +}
|
| +
|
| ACTION(QuitUIMessageLoop) {
|
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
|
| MessageLoop::current()->Quit();
|
| }
|
|
|
| +MATCHER(EmptyWDResult, "") {
|
| + return static_cast<const WDResult<std::vector<PasswordForm*> >*>(
|
| + arg)->GetValue().empty();
|
| +}
|
| +
|
| TEST_F(PasswordStoreWinTest, ConvertIE7Login) {
|
| IE7PasswordInfo password_info;
|
| ASSERT_TRUE(CreateIE7PasswordInfo(L"http://example.com/origin",
|
| @@ -324,4 +337,166 @@ TEST_F(PasswordStoreWinTest, MultipleWDSQueriesOnDifferentThreads) {
|
| MessageLoop::current()->Run();
|
|
|
| STLDeleteElements(&forms);
|
| -}
|
| +}
|
| +
|
| +TEST_F(PasswordStoreWinTest, Migration) {
|
| + PasswordFormData autofillable_data[] = {
|
| + { PasswordForm::SCHEME_HTML,
|
| + "http://foo.example.com",
|
| + "http://foo.example.com/origin",
|
| + "http://foo.example.com/action",
|
| + L"submit_element",
|
| + L"username_element",
|
| + L"password_element",
|
| + L"username_value",
|
| + L"password_value",
|
| + true, false, 1 },
|
| + { PasswordForm::SCHEME_HTML,
|
| + "http://bar.example.com",
|
| + "http://bar.example.com/origin",
|
| + "http://bar.example.com/action",
|
| + L"submit_element",
|
| + L"username_element",
|
| + L"password_element",
|
| + L"username_value",
|
| + L"password_value",
|
| + true, false, 2 },
|
| + { PasswordForm::SCHEME_HTML,
|
| + "http://baz.example.com",
|
| + "http://baz.example.com/origin",
|
| + "http://baz.example.com/action",
|
| + L"submit_element",
|
| + L"username_element",
|
| + L"password_element",
|
| + L"username_value",
|
| + L"password_value",
|
| + true, false, 3 },
|
| + };
|
| + PasswordFormData blacklisted_data[] = {
|
| + { PasswordForm::SCHEME_HTML,
|
| + "http://blacklisted.example.com",
|
| + "http://blacklisted.example.com/origin",
|
| + "http://blacklisted.example.com/action",
|
| + L"submit_element",
|
| + L"username_element",
|
| + L"password_element",
|
| + NULL,
|
| + NULL,
|
| + false, false, 1 },
|
| + { PasswordForm::SCHEME_HTML,
|
| + "http://blacklisted2.example.com",
|
| + "http://blacklisted2.example.com/origin",
|
| + "http://blacklisted2.example.com/action",
|
| + L"submit_element",
|
| + L"username_element",
|
| + L"password_element",
|
| + NULL,
|
| + NULL,
|
| + false, false, 2 },
|
| + };
|
| +
|
| + VectorOfForms expected_autofillable;
|
| + for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(autofillable_data); ++i) {
|
| + expected_autofillable.push_back(
|
| + CreatePasswordFormFromData(autofillable_data[i]));
|
| + }
|
| +
|
| + VectorOfForms expected_blacklisted;
|
| + for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(blacklisted_data); ++i) {
|
| + expected_blacklisted.push_back(
|
| + CreatePasswordFormFromData(blacklisted_data[i]));
|
| + }
|
| +
|
| + // Populate the WDS with logins that should be migrated.
|
| + for (VectorOfForms::iterator it = expected_autofillable.begin();
|
| + it != expected_autofillable.end(); ++it) {
|
| + wds_->AddLogin(**it);
|
| + }
|
| + for (VectorOfForms::iterator it = expected_blacklisted.begin();
|
| + it != expected_blacklisted.end(); ++it) {
|
| + wds_->AddLogin(**it);
|
| + }
|
| +
|
| + // The WDS schedules tasks to run on the DB thread so we schedule yet another
|
| + // task to notify us that it's safe to carry on with the test.
|
| + WaitableEvent done(false, false);
|
| + ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, new SignalingTask(&done));
|
| + done.Wait();
|
| +
|
| + // Initializing the PasswordStore should trigger a migration.
|
| + scoped_refptr<PasswordStoreWin> store(
|
| + new PasswordStoreWin(login_db_.release(), profile_.get(), wds_.get()));
|
| + store->Init();
|
| +
|
| + // Check that the migration preference has not been initialized;
|
| + ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference(
|
| + prefs::kLoginDatabaseMigrated));
|
| +
|
| + // Again, the WDS schedules tasks to run on the DB thread, so schedule a task
|
| + // to signal us when it is safe to continue.
|
| + ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, new SignalingTask(&done));
|
| + done.Wait();
|
| +
|
| + // Let the WDS callbacks proceed so the logins can be migrated.
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + MockPasswordStoreConsumer consumer;
|
| +
|
| + // Make sure we quit the MessageLoop even if the test fails.
|
| + ON_CALL(consumer, OnPasswordStoreRequestDone(_, _))
|
| + .WillByDefault(QuitUIMessageLoop());
|
| +
|
| + // The autofillable forms should have been migrated from the WDS to the login
|
| + // database.
|
| + EXPECT_CALL(consumer,
|
| + OnPasswordStoreRequestDone(_,
|
| + ContainsAllPasswordForms(expected_autofillable)))
|
| + .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop()));
|
| +
|
| + store->GetAutofillableLogins(&consumer);
|
| + MessageLoop::current()->Run();
|
| +
|
| + // The blacklisted forms should have been migrated from the WDS to the login
|
| + // database.
|
| + EXPECT_CALL(consumer,
|
| + OnPasswordStoreRequestDone(_,
|
| + ContainsAllPasswordForms(expected_blacklisted)))
|
| + .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop()));
|
| +
|
| + store->GetBlacklistLogins(&consumer);
|
| + MessageLoop::current()->Run();
|
| +
|
| + // Check that the migration updated the migrated preference.
|
| + ASSERT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kLoginDatabaseMigrated));
|
| +
|
| + MockWebDataServiceConsumer wds_consumer;
|
| +
|
| + // No autofillable logins should be left in the WDS.
|
| + EXPECT_CALL(wds_consumer,
|
| + OnWebDataServiceRequestDone(_, EmptyWDResult()));
|
| +
|
| + wds_->GetAutofillableLogins(&wds_consumer);
|
| +
|
| + // Wait for the WDS methods to execute on the DB thread.
|
| + ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, new SignalingTask(&done));
|
| + done.Wait();
|
| +
|
| + // Handle the callback from the WDS.
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + // Likewise, no blacklisted logins should be left in the WDS.
|
| + EXPECT_CALL(wds_consumer,
|
| + OnWebDataServiceRequestDone(_, EmptyWDResult()));
|
| +
|
| + wds_->GetBlacklistLogins(&wds_consumer);
|
| +
|
| + // Wait for the WDS methods to execute on the DB thread.
|
| + ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, new SignalingTask(&done));
|
| + done.Wait();
|
| +
|
| + // Handle the callback from the WDS.
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + STLDeleteElements(&expected_autofillable);
|
| + STLDeleteElements(&expected_blacklisted);
|
| +}
|
|
|