diff options
author | mdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-14 16:47:15 +0000 |
---|---|---|
committer | mdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-14 16:47:15 +0000 |
commit | 4e3b71619a51f31fba9d5a5cc05b833312460102 (patch) | |
tree | d5ded42054bcd81e8303196cc1c02423761261e1 /chrome/browser/password_manager | |
parent | 89c75df34e80ca45f60b8b06f4102f8da7b132fb (diff) | |
download | chromium_src-4e3b71619a51f31fba9d5a5cc05b833312460102.zip chromium_src-4e3b71619a51f31fba9d5a5cc05b833312460102.tar.gz chromium_src-4e3b71619a51f31fba9d5a5cc05b833312460102.tar.bz2 |
Add tests to verify that non-ASCII passwords (and other password form data) can be stored correctly.
TEST=tests pass
BUG=54065
Review URL: http://codereview.chromium.org/3358031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59382 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/password_manager')
-rw-r--r-- | chrome/browser/password_manager/password_store_default_unittest.cc | 91 |
1 files changed, 68 insertions, 23 deletions
diff --git a/chrome/browser/password_manager/password_store_default_unittest.cc b/chrome/browser/password_manager/password_store_default_unittest.cc index f1c6c17..a416d37 100644 --- a/chrome/browser/password_manager/password_store_default_unittest.cc +++ b/chrome/browser/password_manager/password_store_default_unittest.cc @@ -149,6 +149,63 @@ MATCHER(EmptyWDResult, "") { arg)->GetValue().empty(); } +TEST_F(PasswordStoreDefaultTest, NonASCIIData) { + // Prentend that the migration has already taken place. + profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, + true); + + // Initializing the PasswordStore shouldn't trigger a migration. + scoped_refptr<PasswordStoreDefault> store( + new PasswordStoreDefault(login_db_.release(), profile_.get(), + wds_.get())); + store->Init(); + + // Some non-ASCII password form data. + PasswordFormData form_data[] = { + { PasswordForm::SCHEME_HTML, + "http://foo.example.com", + "http://foo.example.com/origin", + "http://foo.example.com/action", + L"มีสีสัน", + L"お元気ですか?", + L"盆栽", + L"أحب كرة", + L"£éä국수çà", + true, false, 1 }, + }; + + // Build the expected forms vector and add the forms to the store. + VectorOfForms expected_forms; + for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(form_data); ++i) { + PasswordForm* form = CreatePasswordFormFromData(form_data[i]); + expected_forms.push_back(form); + store->AddLogin(*form); + } + + // The PasswordStore 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(); + + MockPasswordStoreConsumer consumer; + + // Make sure we quit the MessageLoop even if the test fails. + ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) + .WillByDefault(QuitUIMessageLoop()); + + // We expect to get the same data back, even though it's not all ASCII. + EXPECT_CALL(consumer, + OnPasswordStoreRequestDone(_, + ContainsAllPasswordForms(expected_forms))) + .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); + + store->GetAutofillableLogins(&consumer); + MessageLoop::current()->Run(); + + STLDeleteElements(&expected_forms); +} + TEST_F(PasswordStoreDefaultTest, Migration) { PasswordFormData autofillable_data[] = { { PasswordForm::SCHEME_HTML, @@ -205,26 +262,18 @@ TEST_F(PasswordStoreDefaultTest, Migration) { 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) { - expected_autofillable.push_back( - CreatePasswordFormFromData(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) { - 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); + 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 @@ -326,16 +375,12 @@ TEST_F(PasswordStoreDefaultTest, MigrationAlreadyDone) { 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) { - unexpected_autofillable.push_back( - CreatePasswordFormFromData(wds_data[i])); - } - - // Populate the WDS with logins that should be migrated. - for (VectorOfForms::iterator it = unexpected_autofillable.begin(); - it != unexpected_autofillable.end(); ++it) { - wds_->AddLogin(**it); + 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 |