| Index: chrome/browser/password_manager/password_store_default_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/password_manager/password_store_default_unittest.cc (revision 133948)
|
| +++ chrome/browser/password_manager/password_store_default_unittest.cc (working copy)
|
| @@ -16,7 +16,6 @@
|
| #include "chrome/browser/password_manager/password_store_consumer.h"
|
| #include "chrome/browser/password_manager/password_store_default.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| -#include "chrome/browser/webdata/web_data_service.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| #include "chrome/common/pref_names.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| @@ -47,12 +46,6 @@
|
| const std::vector<webkit::forms::PasswordForm*>&));
|
| };
|
|
|
| -class MockWebDataServiceConsumer : public WebDataServiceConsumer {
|
| - public:
|
| - MOCK_METHOD2(OnWebDataServiceRequestDone, void(WebDataService::Handle,
|
| - const WDTypedResult*));
|
| -};
|
| -
|
| // This class will add and remove a mock notification observer from
|
| // the DB thread.
|
| class DBThreadObserverHelper :
|
| @@ -117,13 +110,9 @@
|
| login_db_.reset(new LoginDatabase());
|
| ASSERT_TRUE(login_db_->Init(temp_dir_.path().Append(
|
| FILE_PATH_LITERAL("login_test"))));
|
| -
|
| - wds_ = new WebDataService();
|
| - ASSERT_TRUE(wds_->Init(temp_dir_.path()));
|
| }
|
|
|
| virtual void TearDown() {
|
| - wds_->Shutdown();
|
| MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
|
| MessageLoop::current()->Run();
|
| db_thread_.Stop();
|
| @@ -136,7 +125,6 @@
|
|
|
| scoped_ptr<LoginDatabase> login_db_;
|
| scoped_ptr<TestingProfile> profile_;
|
| - scoped_refptr<WebDataService> wds_;
|
| ScopedTempDir temp_dir_;
|
| };
|
|
|
| @@ -149,21 +137,9 @@
|
| MessageLoop::current()->Quit();
|
| }
|
|
|
| -MATCHER(EmptyWDResult, "") {
|
| - return static_cast<const WDResult<std::vector<PasswordForm*> >*>(
|
| - arg)->GetValue().empty();
|
| -}
|
| -
|
| TEST_F(PasswordStoreDefaultTest, NonASCIIData) {
|
| - // Pretend that the migration has already taken place.
|
| - profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated,
|
| - true,
|
| - PrefService::UNSYNCABLE_PREF);
|
| -
|
| - // Initializing the PasswordStore shouldn't trigger a migration.
|
| scoped_refptr<PasswordStoreDefault> store(
|
| - new PasswordStoreDefault(login_db_.release(), profile_.get(),
|
| - wds_.get()));
|
| + new PasswordStoreDefault(login_db_.release(), profile_.get()));
|
| store->Init();
|
|
|
| // Some non-ASCII password form data.
|
| @@ -213,237 +189,9 @@
|
| STLDeleteElements(&expected_forms);
|
| }
|
|
|
| -TEST_F(PasswordStoreDefaultTest, 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 },
|
| - };
|
| -
|
| - // Build the expected forms vectors and populate the WDS with logins.
|
| - VectorOfForms expected_autofillable;
|
| - for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(autofillable_data); ++i) {
|
| - PasswordForm* form = CreatePasswordFormFromData(autofillable_data[i]);
|
| - expected_autofillable.push_back(form);
|
| - wds_->AddLogin(*form);
|
| - }
|
| - VectorOfForms expected_blacklisted;
|
| - for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(blacklisted_data); ++i) {
|
| - PasswordForm* form = CreatePasswordFormFromData(blacklisted_data[i]);
|
| - expected_blacklisted.push_back(form);
|
| - wds_->AddLogin(*form);
|
| - }
|
| -
|
| - // 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);
|
| - BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
|
| - base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
|
| - done.Wait();
|
| -
|
| - // Initializing the PasswordStore should trigger a migration.
|
| - scoped_refptr<PasswordStore> store(
|
| - new PasswordStoreDefault(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.
|
| - BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
|
| - base::Bind(&WaitableEvent::Signal, base::Unretained(&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.
|
| - BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
|
| - base::Bind(&WaitableEvent::Signal, base::Unretained(&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.
|
| - BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
|
| - base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
|
| - done.Wait();
|
| -
|
| - // Handle the callback from the WDS.
|
| - MessageLoop::current()->RunAllPending();
|
| -
|
| - STLDeleteElements(&expected_autofillable);
|
| - STLDeleteElements(&expected_blacklisted);
|
| -
|
| - store->ShutdownOnUIThread();
|
| -}
|
| -
|
| -TEST_F(PasswordStoreDefaultTest, MigrationAlreadyDone) {
|
| - PasswordFormData wds_data[] = {
|
| - { 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, 1 },
|
| - };
|
| -
|
| - // Build the expected forms vector and populate the WDS with logins.
|
| - VectorOfForms unexpected_autofillable;
|
| - for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(wds_data); ++i) {
|
| - PasswordForm* form = CreatePasswordFormFromData(wds_data[i]);
|
| - unexpected_autofillable.push_back(form);
|
| - wds_->AddLogin(*form);
|
| - }
|
| -
|
| - // 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);
|
| - BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
|
| - base::Bind(&WaitableEvent::Signal, base::Unretained(&done)));
|
| - done.Wait();
|
| -
|
| - // Pretend that the migration has already taken place.
|
| - profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated,
|
| - true,
|
| - PrefService::UNSYNCABLE_PREF);
|
| -
|
| - // Initializing the PasswordStore shouldn't trigger a migration.
|
| - scoped_refptr<PasswordStore> store(
|
| - new PasswordStoreDefault(login_db_.release(), profile_.get(),
|
| - wds_.get()));
|
| - store->Init();
|
| -
|
| - MockPasswordStoreConsumer consumer;
|
| - // Make sure we quit the MessageLoop even if the test fails.
|
| - ON_CALL(consumer, OnPasswordStoreRequestDone(_, _))
|
| - .WillByDefault(QuitUIMessageLoop());
|
| -
|
| - // No forms should be migrated.
|
| - VectorOfForms empty;
|
| - EXPECT_CALL(consumer,
|
| - OnPasswordStoreRequestDone(_,
|
| - ContainsAllPasswordForms(empty)))
|
| - .WillOnce(QuitUIMessageLoop());
|
| -
|
| - store->GetAutofillableLogins(&consumer);
|
| - MessageLoop::current()->Run();
|
| -
|
| - STLDeleteElements(&unexpected_autofillable);
|
| -
|
| - store->ShutdownOnUIThread();
|
| -}
|
| -
|
| TEST_F(PasswordStoreDefaultTest, Notifications) {
|
| - // Pretend that the migration has already taken place.
|
| - profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated,
|
| - true,
|
| - PrefService::UNSYNCABLE_PREF);
|
| -
|
| - // Initializing the PasswordStore shouldn't trigger a migration.
|
| scoped_refptr<PasswordStore> store(
|
| - new PasswordStoreDefault(login_db_.release(), profile_.get(),
|
| - wds_.get()));
|
| + new PasswordStoreDefault(login_db_.release(), profile_.get()));
|
| store->Init();
|
|
|
| PasswordFormData form_data =
|
|
|