Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Unified Diff: components/password_manager/core/browser/login_database_unittest.cc

Issue 838453003: Open the LoginDatabase on the DB thread, not the UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits from vabr@. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/login_database_unittest.cc
diff --git a/components/password_manager/core/browser/login_database_unittest.cc b/components/password_manager/core/browser/login_database_unittest.cc
index 9c3b6b911a59d7061c4f10bc6e01578e2cba4d46..110355db3209e79fe7e32b9da1ad058dc6d5f8f8 100644
--- a/components/password_manager/core/browser/login_database_unittest.cc
+++ b/components/password_manager/core/browser/login_database_unittest.cc
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
+#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
@@ -79,9 +80,12 @@ class LoginDatabaseTest : public testing::Test {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
file_ = temp_dir_.path().AppendASCII("TestMetadataStoreMacDatabase");
- ASSERT_TRUE(db_.Init(file_));
+ db_.reset(new LoginDatabase(file_));
+ ASSERT_TRUE(db_->Init());
}
+ LoginDatabase& db() { return *db_; }
+
void TestNonHTMLFormPSLMatching(const PasswordForm::Scheme& scheme) {
ScopedVector<PasswordForm> result;
@@ -108,9 +112,9 @@ class LoginDatabaseTest : public testing::Test {
html_form.date_created = now;
// Add them and make sure they are there.
- EXPECT_EQ(AddChangeForForm(non_html_auth), db_.AddLogin(non_html_auth));
- EXPECT_EQ(AddChangeForForm(html_form), db_.AddLogin(html_form));
- EXPECT_TRUE(db_.GetAutofillableLogins(&result.get()));
+ EXPECT_EQ(AddChangeForForm(non_html_auth), db().AddLogin(non_html_auth));
+ EXPECT_EQ(AddChangeForForm(html_form), db().AddLogin(html_form));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result.get()));
EXPECT_EQ(2U, result.size());
result.clear();
@@ -119,16 +123,16 @@ class LoginDatabaseTest : public testing::Test {
second_non_html_auth.signon_realm = "http://second.example.com/Realm";
// This shouldn't match anything.
- EXPECT_TRUE(db_.GetLogins(second_non_html_auth, &result.get()));
+ EXPECT_TRUE(db().GetLogins(second_non_html_auth, &result.get()));
EXPECT_EQ(0U, result.size());
// non-html auth still matches against itself.
- EXPECT_TRUE(db_.GetLogins(non_html_auth, &result.get()));
+ EXPECT_TRUE(db().GetLogins(non_html_auth, &result.get()));
ASSERT_EQ(1U, result.size());
EXPECT_EQ(result[0]->signon_realm, "http://example.com/Realm");
// Clear state.
- db_.RemoveLoginsCreatedBetween(now, base::Time());
+ db().RemoveLoginsCreatedBetween(now, base::Time());
}
// Checks that a form of a given |scheme|, once stored, can be successfully
@@ -148,25 +152,25 @@ class LoginDatabaseTest : public testing::Test {
ip_form.scheme = scheme;
ip_form.date_created = now;
- EXPECT_EQ(AddChangeForForm(ip_form), db_.AddLogin(ip_form));
- EXPECT_TRUE(db_.GetLogins(ip_form, &result.get()));
+ EXPECT_EQ(AddChangeForForm(ip_form), db().AddLogin(ip_form));
+ EXPECT_TRUE(db().GetLogins(ip_form, &result.get()));
ASSERT_EQ(1U, result.size());
EXPECT_EQ(result[0]->signon_realm, origin);
// Clear state.
- db_.RemoveLoginsCreatedBetween(now, base::Time());
+ db().RemoveLoginsCreatedBetween(now, base::Time());
}
base::ScopedTempDir temp_dir_;
base::FilePath file_;
- LoginDatabase db_;
+ scoped_ptr<LoginDatabase> db_;
};
TEST_F(LoginDatabaseTest, Logins) {
std::vector<PasswordForm*> result;
// Verify the database is empty.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(0U, result.size());
// Example password form.
@@ -175,15 +179,15 @@ TEST_F(LoginDatabaseTest, Logins) {
// Add it and make sure it is there and that all the fields were retrieved
// correctly.
- EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form));
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
ASSERT_EQ(1U, result.size());
FormsAreEqual(form, *result[0]);
delete result[0];
result.clear();
// Match against an exact copy.
- EXPECT_TRUE(db_.GetLogins(form, &result));
+ EXPECT_TRUE(db().GetLogins(form, &result));
ASSERT_EQ(1U, result.size());
FormsAreEqual(form, *result[0]);
delete result[0];
@@ -195,7 +199,7 @@ TEST_F(LoginDatabaseTest, Logins) {
form2.submit_element = ASCIIToUTF16("reallySignIn");
// Match against an inexact copy
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
@@ -205,7 +209,7 @@ TEST_F(LoginDatabaseTest, Logins) {
form3.action = GURL("http://www.google.com/new/accounts/Login");
// signon_realm is the same, should match.
- EXPECT_TRUE(db_.GetLogins(form3, &result));
+ EXPECT_TRUE(db().GetLogins(form3, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
@@ -216,32 +220,32 @@ TEST_F(LoginDatabaseTest, Logins) {
form4.ssl_valid = true;
// We have only an http record, so no match for this.
- EXPECT_TRUE(db_.GetLogins(form4, &result));
+ EXPECT_TRUE(db().GetLogins(form4, &result));
EXPECT_EQ(0U, result.size());
// Let's imagine the user logs into the secure site.
- EXPECT_EQ(AddChangeForForm(form4), db_.AddLogin(form4));
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_EQ(AddChangeForForm(form4), db().AddLogin(form4));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(2U, result.size());
delete result[0];
delete result[1];
result.clear();
// Now the match works
- EXPECT_TRUE(db_.GetLogins(form4, &result));
+ EXPECT_TRUE(db().GetLogins(form4, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// The user chose to forget the original but not the new.
- EXPECT_TRUE(db_.RemoveLogin(form));
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().RemoveLogin(form));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// The old form wont match the new site (http vs https).
- EXPECT_TRUE(db_.GetLogins(form, &result));
+ EXPECT_TRUE(db().GetLogins(form, &result));
EXPECT_EQ(0U, result.size());
// The user's request for the HTTPS site is intercepted
@@ -250,7 +254,7 @@ TEST_F(LoginDatabaseTest, Logins) {
form5.ssl_valid = 0;
// It will match in this case.
- EXPECT_TRUE(db_.GetLogins(form5, &result));
+ EXPECT_TRUE(db().GetLogins(form5, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
@@ -262,14 +266,14 @@ TEST_F(LoginDatabaseTest, Logins) {
// We update, and check to make sure it matches the
// old form, and there is only one record.
- EXPECT_EQ(UpdateChangeForForm(form6), db_.UpdateLogin(form6));
+ EXPECT_EQ(UpdateChangeForForm(form6), db().UpdateLogin(form6));
// matches
- EXPECT_TRUE(db_.GetLogins(form5, &result));
+ EXPECT_TRUE(db().GetLogins(form5, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// Only one record.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(1U, result.size());
// Password element was updated.
#if defined(OS_MACOSX) && !defined(OS_IOS)
@@ -284,8 +288,8 @@ TEST_F(LoginDatabaseTest, Logins) {
result.clear();
// Make sure everything can disappear.
- EXPECT_TRUE(db_.RemoveLogin(form4));
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().RemoveLogin(form4));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(0U, result.size());
}
@@ -293,7 +297,7 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatching) {
std::vector<PasswordForm*> result;
// Verify the database is empty.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(0U, result.size());
// Example password form.
@@ -311,14 +315,14 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatching) {
form.scheme = PasswordForm::SCHEME_HTML;
// Add it and make sure it is there.
- EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form));
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// Match against an exact copy.
- EXPECT_TRUE(db_.GetLogins(form, &result));
+ EXPECT_TRUE(db().GetLogins(form, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
@@ -330,17 +334,17 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatching) {
form2.signon_realm = "https://mobile.foo.com/";
// Match against the mobile site.
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(1U, result.size());
EXPECT_EQ("https://mobile.foo.com/", result[0]->signon_realm);
EXPECT_EQ("https://foo.com/", result[0]->original_signon_realm);
// Try to remove PSL matched form
- EXPECT_FALSE(db_.RemoveLogin(*result[0]));
+ EXPECT_FALSE(db().RemoveLogin(*result[0]));
delete result[0];
result.clear();
// Ensure that the original form is still there
- EXPECT_TRUE(db_.GetLogins(form, &result));
+ EXPECT_TRUE(db().GetLogins(form, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
@@ -372,7 +376,7 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingShouldMatchingApply) {
std::vector<PasswordForm*> result;
// Verify the database is empty.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(0U, result.size());
// Example password form.
@@ -390,14 +394,14 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingShouldMatchingApply) {
form.scheme = PasswordForm::SCHEME_HTML;
// Add it and make sure it is there.
- EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form));
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// Match against an exact copy.
- EXPECT_TRUE(db_.GetLogins(form, &result));
+ EXPECT_TRUE(db().GetLogins(form, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
@@ -410,7 +414,7 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingShouldMatchingApply) {
// Match against the other site. Should not match since feature should not be
// enabled for this domain.
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(0U, result.size());
}
@@ -421,7 +425,7 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingDifferentSites) {
std::vector<PasswordForm*> result;
// Verify the database is empty.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(0U, result.size());
// Example password form.
@@ -439,14 +443,14 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingDifferentSites) {
form.scheme = PasswordForm::SCHEME_HTML;
// Add it and make sure it is there.
- EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form));
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// Match against an exact copy.
- EXPECT_TRUE(db_.GetLogins(form, &result));
+ EXPECT_TRUE(db().GetLogins(form, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
@@ -458,7 +462,7 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingDifferentSites) {
form2.signon_realm = "https://mobile.foo.com/";
// Match against the mobile site.
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(1U, result.size());
EXPECT_EQ("https://mobile.foo.com/", result[0]->signon_realm);
EXPECT_EQ("https://foo.com/", result[0]->original_signon_realm);
@@ -479,8 +483,8 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingDifferentSites) {
form.scheme = PasswordForm::SCHEME_HTML;
// Add it and make sure it is there.
- EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form));
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(2U, result.size());
delete result[0];
delete result[1];
@@ -493,7 +497,7 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingDifferentSites) {
form3.signon_realm = "https://m.baz.com/";
// Match against the mobile site of baz.com.
- EXPECT_TRUE(db_.GetLogins(form3, &result));
+ EXPECT_TRUE(db().GetLogins(form3, &result));
EXPECT_EQ(1U, result.size());
EXPECT_EQ("https://m.baz.com/", result[0]->signon_realm);
EXPECT_EQ("https://baz.com/", result[0]->original_signon_realm);
@@ -514,7 +518,7 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingRegexp) {
std::vector<PasswordForm*> result;
// Verify the database is empty.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(0U, result.size());
// Example password form.
@@ -532,8 +536,8 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingRegexp) {
form.scheme = PasswordForm::SCHEME_HTML;
// Add it and make sure it is there.
- EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form));
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
@@ -543,91 +547,91 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingRegexp) {
GetFormWithNewSignonRealm(form, "http://www.foo-bar.com/");
// Add it and make sure it is there.
- EXPECT_EQ(AddChangeForForm(form_dash), db_.AddLogin(form_dash));
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_EQ(AddChangeForForm(form_dash), db().AddLogin(form_dash));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(2U, result.size());
delete result[0];
delete result[1];
result.clear();
// Match against an exact copy.
- EXPECT_TRUE(db_.GetLogins(form, &result));
+ EXPECT_TRUE(db().GetLogins(form, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// www.foo.com should match.
PasswordForm form2 = GetFormWithNewSignonRealm(form, "http://www.foo.com/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// a.b.foo.com should match.
form2 = GetFormWithNewSignonRealm(form, "http://a.b.foo.com/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// a-b.foo.com should match.
form2 = GetFormWithNewSignonRealm(form, "http://a-b.foo.com/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// foo-bar.com should match.
form2 = GetFormWithNewSignonRealm(form, "http://foo-bar.com/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// www.foo-bar.com should match.
form2 = GetFormWithNewSignonRealm(form, "http://www.foo-bar.com/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// a.b.foo-bar.com should match.
form2 = GetFormWithNewSignonRealm(form, "http://a.b.foo-bar.com/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// a-b.foo-bar.com should match.
form2 = GetFormWithNewSignonRealm(form, "http://a-b.foo-bar.com/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(1U, result.size());
delete result[0];
result.clear();
// foo.com with port 1337 should not match.
form2 = GetFormWithNewSignonRealm(form, "http://foo.com:1337/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(0U, result.size());
// http://foo.com should not match since the scheme is wrong.
form2 = GetFormWithNewSignonRealm(form, "https://foo.com/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(0U, result.size());
// notfoo.com should not match.
form2 = GetFormWithNewSignonRealm(form, "http://notfoo.com/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(0U, result.size());
// baz.com should not match.
form2 = GetFormWithNewSignonRealm(form, "http://baz.com/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(0U, result.size());
// foo-baz.com should not match.
form2 = GetFormWithNewSignonRealm(form, "http://foo-baz.com/");
- EXPECT_TRUE(db_.GetLogins(form2, &result));
+ EXPECT_TRUE(db().GetLogins(form2, &result));
EXPECT_EQ(0U, result.size());
}
@@ -667,7 +671,7 @@ TEST_F(LoginDatabaseTest, ClearPrivateData_SavedPasswords) {
std::vector<PasswordForm*> result;
// Verify the database is empty.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(0U, result.size());
base::Time now = base::Time::Now();
@@ -675,37 +679,37 @@ TEST_F(LoginDatabaseTest, ClearPrivateData_SavedPasswords) {
// Create one with a 0 time.
EXPECT_TRUE(
- AddTimestampedLogin(&db_, "http://1.com", "foo1", base::Time(), true));
+ AddTimestampedLogin(&db(), "http://1.com", "foo1", base::Time(), true));
// Create one for now and +/- 1 day.
EXPECT_TRUE(
- AddTimestampedLogin(&db_, "http://2.com", "foo2", now - one_day, true));
- EXPECT_TRUE(AddTimestampedLogin(&db_, "http://3.com", "foo3", now, true));
+ AddTimestampedLogin(&db(), "http://2.com", "foo2", now - one_day, true));
+ EXPECT_TRUE(AddTimestampedLogin(&db(), "http://3.com", "foo3", now, true));
EXPECT_TRUE(
- AddTimestampedLogin(&db_, "http://4.com", "foo4", now + one_day, true));
+ AddTimestampedLogin(&db(), "http://4.com", "foo4", now + one_day, true));
// Verify inserts worked.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(4U, result.size());
ClearResults(&result);
// Get everything from today's date and on.
- EXPECT_TRUE(db_.GetLoginsCreatedBetween(now, base::Time(), &result));
+ EXPECT_TRUE(db().GetLoginsCreatedBetween(now, base::Time(), &result));
EXPECT_EQ(2U, result.size());
ClearResults(&result);
// Delete everything from today's date and on.
- db_.RemoveLoginsCreatedBetween(now, base::Time());
+ db().RemoveLoginsCreatedBetween(now, base::Time());
// Should have deleted half of what we inserted.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(2U, result.size());
ClearResults(&result);
// Delete with 0 date (should delete all).
- db_.RemoveLoginsCreatedBetween(base::Time(), base::Time());
+ db().RemoveLoginsCreatedBetween(base::Time(), base::Time());
// Verify nothing is left.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
EXPECT_EQ(0U, result.size());
}
@@ -717,41 +721,41 @@ TEST_F(LoginDatabaseTest, RemoveLoginsSyncedBetween) {
// Create one with a 0 time.
EXPECT_TRUE(
- AddTimestampedLogin(&db_, "http://1.com", "foo1", base::Time(), false));
+ AddTimestampedLogin(&db(), "http://1.com", "foo1", base::Time(), false));
// Create one for now and +/- 1 day.
EXPECT_TRUE(
- AddTimestampedLogin(&db_, "http://2.com", "foo2", now - one_day, false));
- EXPECT_TRUE(AddTimestampedLogin(&db_, "http://3.com", "foo3", now, false));
+ AddTimestampedLogin(&db(), "http://2.com", "foo2", now - one_day, false));
+ EXPECT_TRUE(AddTimestampedLogin(&db(), "http://3.com", "foo3", now, false));
EXPECT_TRUE(
- AddTimestampedLogin(&db_, "http://4.com", "foo4", now + one_day, false));
+ AddTimestampedLogin(&db(), "http://4.com", "foo4", now + one_day, false));
// Verify inserts worked.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result.get()));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result.get()));
EXPECT_EQ(4U, result.size());
result.clear();
// Get everything from today's date and on.
- EXPECT_TRUE(db_.GetLoginsSyncedBetween(now, base::Time(), &result.get()));
+ EXPECT_TRUE(db().GetLoginsSyncedBetween(now, base::Time(), &result.get()));
ASSERT_EQ(2U, result.size());
EXPECT_EQ("http://3.com", result[0]->signon_realm);
EXPECT_EQ("http://4.com", result[1]->signon_realm);
result.clear();
// Delete everything from today's date and on.
- db_.RemoveLoginsSyncedBetween(now, base::Time());
+ db().RemoveLoginsSyncedBetween(now, base::Time());
// Should have deleted half of what we inserted.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result.get()));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result.get()));
ASSERT_EQ(2U, result.size());
EXPECT_EQ("http://1.com", result[0]->signon_realm);
EXPECT_EQ("http://2.com", result[1]->signon_realm);
result.clear();
// Delete with 0 date (should delete all).
- db_.RemoveLoginsSyncedBetween(base::Time(), now);
+ db().RemoveLoginsSyncedBetween(base::Time(), now);
// Verify nothing is left.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result.get()));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result.get()));
EXPECT_EQ(0U, result.size());
}
@@ -759,7 +763,7 @@ TEST_F(LoginDatabaseTest, BlacklistedLogins) {
std::vector<PasswordForm*> result;
// Verify the database is empty.
- EXPECT_TRUE(db_.GetBlacklistLogins(&result));
+ EXPECT_TRUE(db().GetBlacklistLogins(&result));
ASSERT_EQ(0U, result.size());
// Save a form as blacklisted.
@@ -779,20 +783,20 @@ TEST_F(LoginDatabaseTest, BlacklistedLogins) {
form.avatar_url = GURL("https://accounts.google.com/Avatar");
form.federation_url = GURL("https://accounts.google.com/federation");
form.is_zero_click = true;
- EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form));
+ EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form));
// Get all non-blacklisted logins (should be none).
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
ASSERT_EQ(0U, result.size());
// GetLogins should give the blacklisted result.
- EXPECT_TRUE(db_.GetLogins(form, &result));
+ EXPECT_TRUE(db().GetLogins(form, &result));
ASSERT_EQ(1U, result.size());
FormsAreEqual(form, *result[0]);
ClearResults(&result);
// So should GetAllBlacklistedLogins.
- EXPECT_TRUE(db_.GetBlacklistLogins(&result));
+ EXPECT_TRUE(db().GetBlacklistLogins(&result));
ASSERT_EQ(1U, result.size());
FormsAreEqual(form, *result[0]);
ClearResults(&result);
@@ -818,7 +822,7 @@ TEST_F(LoginDatabaseTest, VectorSerialization) {
TEST_F(LoginDatabaseTest, UpdateIncompleteCredentials) {
std::vector<autofill::PasswordForm*> result;
// Verify the database is empty.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result));
ASSERT_EQ(0U, result.size());
// Save an incomplete form. Note that it only has a few fields set, ex. it's
@@ -834,7 +838,7 @@ TEST_F(LoginDatabaseTest, UpdateIncompleteCredentials) {
incomplete_form.preferred = true;
incomplete_form.blacklisted_by_user = false;
incomplete_form.scheme = PasswordForm::SCHEME_HTML;
- EXPECT_EQ(AddChangeForForm(incomplete_form), db_.AddLogin(incomplete_form));
+ EXPECT_EQ(AddChangeForForm(incomplete_form), db().AddLogin(incomplete_form));
// A form on some website. It should trigger a match with the stored one.
PasswordForm encountered_form;
@@ -846,7 +850,7 @@ TEST_F(LoginDatabaseTest, UpdateIncompleteCredentials) {
encountered_form.submit_element = ASCIIToUTF16("signIn");
// Get matches for encountered_form.
- EXPECT_TRUE(db_.GetLogins(encountered_form, &result));
+ EXPECT_TRUE(db().GetLogins(encountered_form, &result));
ASSERT_EQ(1U, result.size());
EXPECT_EQ(incomplete_form.origin, result[0]->origin);
EXPECT_EQ(incomplete_form.signon_realm, result[0]->signon_realm);
@@ -878,11 +882,11 @@ TEST_F(LoginDatabaseTest, UpdateIncompleteCredentials) {
completed_form.username_element = encountered_form.username_element;
completed_form.password_element = encountered_form.password_element;
completed_form.submit_element = encountered_form.submit_element;
- EXPECT_EQ(AddChangeForForm(completed_form), db_.AddLogin(completed_form));
- EXPECT_TRUE(db_.RemoveLogin(incomplete_form));
+ EXPECT_EQ(AddChangeForForm(completed_form), db().AddLogin(completed_form));
+ EXPECT_TRUE(db().RemoveLogin(incomplete_form));
// Get matches for encountered_form again.
- EXPECT_TRUE(db_.GetLogins(encountered_form, &result));
+ EXPECT_TRUE(db().GetLogins(encountered_form, &result));
ASSERT_EQ(1U, result.size());
// This time we should have all the info available.
@@ -908,7 +912,7 @@ TEST_F(LoginDatabaseTest, UpdateOverlappingCredentials) {
incomplete_form.preferred = true;
incomplete_form.blacklisted_by_user = false;
incomplete_form.scheme = PasswordForm::SCHEME_HTML;
- EXPECT_EQ(AddChangeForForm(incomplete_form), db_.AddLogin(incomplete_form));
+ EXPECT_EQ(AddChangeForForm(incomplete_form), db().AddLogin(incomplete_form));
// Save a complete version of the previous form. Both forms could exist if
// the user created the complete version before importing the incomplete
@@ -920,22 +924,23 @@ TEST_F(LoginDatabaseTest, UpdateOverlappingCredentials) {
complete_form.submit_element = ASCIIToUTF16("submit");
// An update fails because the primary key for |complete_form| is different.
- EXPECT_EQ(PasswordStoreChangeList(), db_.UpdateLogin(complete_form));
- EXPECT_EQ(AddChangeForForm(complete_form), db_.AddLogin(complete_form));
+ EXPECT_EQ(PasswordStoreChangeList(), db().UpdateLogin(complete_form));
+ EXPECT_EQ(AddChangeForForm(complete_form), db().AddLogin(complete_form));
// Make sure both passwords exist.
ScopedVector<autofill::PasswordForm> result;
- EXPECT_TRUE(db_.GetAutofillableLogins(&result.get()));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result.get()));
ASSERT_EQ(2U, result.size());
result.clear();
// Simulate the user changing their password.
complete_form.password_value = ASCIIToUTF16("new_password");
complete_form.date_synced = base::Time::Now();
- EXPECT_EQ(UpdateChangeForForm(complete_form), db_.UpdateLogin(complete_form));
+ EXPECT_EQ(UpdateChangeForForm(complete_form),
+ db().UpdateLogin(complete_form));
// Both still exist now.
- EXPECT_TRUE(db_.GetAutofillableLogins(&result.get()));
+ EXPECT_TRUE(db().GetAutofillableLogins(&result.get()));
ASSERT_EQ(2U, result.size());
#if defined(OS_MACOSX) && !defined(OS_IOS)
@@ -960,14 +965,14 @@ TEST_F(LoginDatabaseTest, DoubleAdd) {
form.preferred = true;
form.blacklisted_by_user = false;
form.scheme = PasswordForm::SCHEME_HTML;
- EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form));
+ EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form));
// Add almost the same form again.
form.times_used++;
PasswordStoreChangeList list;
list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form));
list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form));
- EXPECT_EQ(list, db_.AddLogin(form));
+ EXPECT_EQ(list, db().AddLogin(form));
}
TEST_F(LoginDatabaseTest, AddWrongForm) {
@@ -981,12 +986,12 @@ TEST_F(LoginDatabaseTest, AddWrongForm) {
form.preferred = true;
form.blacklisted_by_user = false;
form.scheme = PasswordForm::SCHEME_HTML;
- EXPECT_EQ(PasswordStoreChangeList(), db_.AddLogin(form));
+ EXPECT_EQ(PasswordStoreChangeList(), db().AddLogin(form));
// |signon_realm| shouldn't be empty.
form.origin = GURL("http://accounts.google.com/LoginAuth");
form.signon_realm.clear();
- EXPECT_EQ(PasswordStoreChangeList(), db_.AddLogin(form));
+ EXPECT_EQ(PasswordStoreChangeList(), db().AddLogin(form));
}
TEST_F(LoginDatabaseTest, UpdateLogin) {
@@ -999,7 +1004,7 @@ TEST_F(LoginDatabaseTest, UpdateLogin) {
form.preferred = true;
form.blacklisted_by_user = false;
form.scheme = PasswordForm::SCHEME_HTML;
- EXPECT_EQ(AddChangeForForm(form), db_.AddLogin(form));
+ EXPECT_EQ(AddChangeForForm(form), db().AddLogin(form));
form.action = GURL("http://accounts.google.com/login");
form.password_value = ASCIIToUTF16("my_new_password");
@@ -1017,10 +1022,10 @@ TEST_F(LoginDatabaseTest, UpdateLogin) {
form.avatar_url = GURL("https://accounts.google.com/Avatar");
form.federation_url = GURL("https://accounts.google.com/federation");
form.is_zero_click = true;
- EXPECT_EQ(UpdateChangeForForm(form), db_.UpdateLogin(form));
+ EXPECT_EQ(UpdateChangeForForm(form), db().UpdateLogin(form));
ScopedVector<autofill::PasswordForm> result;
- EXPECT_TRUE(db_.GetLogins(form, &result.get()));
+ EXPECT_TRUE(db().GetLogins(form, &result.get()));
ASSERT_EQ(1U, result.size());
#if defined(OS_MACOSX) && !defined(OS_IOS)
// On Mac, passwords are not stored in login database, instead they're in
@@ -1037,29 +1042,29 @@ TEST_F(LoginDatabaseTest, ReportMetricsTest) {
password_form.password_value = ASCIIToUTF16("test");
password_form.signon_realm = "http://example.com/";
password_form.times_used = 0;
- EXPECT_EQ(AddChangeForForm(password_form), db_.AddLogin(password_form));
+ EXPECT_EQ(AddChangeForForm(password_form), db().AddLogin(password_form));
password_form.username_value = ASCIIToUTF16("test2@gmail.com");
password_form.times_used = 1;
- EXPECT_EQ(AddChangeForForm(password_form), db_.AddLogin(password_form));
+ EXPECT_EQ(AddChangeForForm(password_form), db().AddLogin(password_form));
password_form.origin = GURL("http://second.example.com");
password_form.signon_realm = "http://second.example.com";
password_form.times_used = 3;
- EXPECT_EQ(AddChangeForForm(password_form), db_.AddLogin(password_form));
+ EXPECT_EQ(AddChangeForForm(password_form), db().AddLogin(password_form));
password_form.username_value = ASCIIToUTF16("test3@gmail.com");
password_form.type = PasswordForm::TYPE_GENERATED;
password_form.times_used = 2;
- EXPECT_EQ(AddChangeForForm(password_form), db_.AddLogin(password_form));
+ EXPECT_EQ(AddChangeForForm(password_form), db().AddLogin(password_form));
password_form.origin = GURL("http://third.example.com/");
password_form.signon_realm = "http://third.example.com/";
password_form.times_used = 4;
- EXPECT_EQ(AddChangeForForm(password_form), db_.AddLogin(password_form));
+ EXPECT_EQ(AddChangeForForm(password_form), db().AddLogin(password_form));
base::HistogramTester histogram_tester;
- db_.ReportMetrics("", false);
+ db().ReportMetrics("", false);
histogram_tester.ExpectUniqueSample(
"PasswordManager.TotalAccounts.UserCreated.WithoutCustomPassphrase",
@@ -1205,8 +1210,8 @@ TEST_F(LoginDatabaseMigrationTest, MigrationV1ToVCurrent) {
{
// Assert that the database was successfully opened and updated
// to current version.
- LoginDatabase db;
- ASSERT_TRUE(db.Init(database_path_));
+ LoginDatabase db(database_path_);
+ ASSERT_TRUE(db.Init());
// Verifies that the final version can save all the appropriate fields.
std::vector<PasswordForm*> result;
PasswordForm form;
« no previous file with comments | « components/password_manager/core/browser/login_database.cc ('k') | components/password_manager/core/browser/password_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698