| 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 67c04ab35d192811ef7e7e1bfdd2818badf34e1a..97c8f6d763f96b30c32747f234e7615e7d66f18e 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"
|
| @@ -80,9 +81,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;
|
|
|
| @@ -109,9 +113,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();
|
|
|
| @@ -120,16 +124,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
|
| @@ -149,25 +153,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.
|
| @@ -176,15 +180,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];
|
| @@ -196,7 +200,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();
|
| @@ -206,7 +210,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();
|
| @@ -217,32 +221,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
|
| @@ -251,7 +255,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();
|
| @@ -263,14 +267,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)
|
| @@ -285,8 +289,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());
|
| }
|
|
|
| @@ -294,7 +298,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.
|
| @@ -312,14 +316,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();
|
| @@ -331,17 +335,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();
|
| @@ -373,7 +377,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.
|
| @@ -391,14 +395,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();
|
| @@ -411,7 +415,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());
|
| }
|
|
|
| @@ -422,7 +426,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.
|
| @@ -440,14 +444,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();
|
| @@ -459,7 +463,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);
|
| @@ -480,8 +484,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];
|
| @@ -494,7 +498,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);
|
| @@ -515,7 +519,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.
|
| @@ -533,8 +537,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();
|
| @@ -544,91 +548,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());
|
| }
|
|
|
| @@ -668,46 +672,46 @@ 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();
|
| base::TimeDelta one_day = base::TimeDelta::FromDays(1);
|
|
|
| // Create one with a 0 time.
|
| - EXPECT_TRUE(AddTimestampedLogin(&db_, "http://1.com", "foo1",
|
| + EXPECT_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",
|
| + EXPECT_TRUE(AddTimestampedLogin(&db(), "http://2.com", "foo2",
|
| now - one_day, true));
|
| - EXPECT_TRUE(AddTimestampedLogin(&db_, "http://3.com", "foo3",
|
| + EXPECT_TRUE(AddTimestampedLogin(&db(), "http://3.com", "foo3",
|
| now, true));
|
| - EXPECT_TRUE(AddTimestampedLogin(&db_, "http://4.com", "foo4",
|
| + EXPECT_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());
|
| }
|
|
|
| @@ -718,43 +722,43 @@ TEST_F(LoginDatabaseTest, RemoveLoginsSyncedBetween) {
|
| base::TimeDelta one_day = base::TimeDelta::FromDays(1);
|
|
|
| // Create one with a 0 time.
|
| - EXPECT_TRUE(AddTimestampedLogin(&db_, "http://1.com", "foo1",
|
| + EXPECT_TRUE(AddTimestampedLogin(&db(), "http://1.com", "foo1",
|
| base::Time(), false));
|
| // Create one for now and +/- 1 day.
|
| - EXPECT_TRUE(AddTimestampedLogin(&db_, "http://2.com", "foo2",
|
| + EXPECT_TRUE(AddTimestampedLogin(&db(), "http://2.com", "foo2",
|
| now - one_day, false));
|
| - EXPECT_TRUE(AddTimestampedLogin(&db_, "http://3.com", "foo3",
|
| + EXPECT_TRUE(AddTimestampedLogin(&db(), "http://3.com", "foo3",
|
| now, false));
|
| - EXPECT_TRUE(AddTimestampedLogin(&db_, "http://4.com", "foo4",
|
| + EXPECT_TRUE(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());
|
| }
|
|
|
| @@ -762,7 +766,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.
|
| @@ -782,20 +786,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);
|
| @@ -821,7 +825,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
|
| @@ -837,7 +841,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;
|
| @@ -849,7 +853,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);
|
| @@ -881,11 +885,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.
|
| @@ -911,7 +915,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
|
| @@ -923,22 +927,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)
|
| @@ -963,14 +968,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) {
|
| @@ -984,12 +989,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) {
|
| @@ -1002,7 +1007,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");
|
| @@ -1020,10 +1025,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
|
| @@ -1040,29 +1045,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",
|
| @@ -1194,8 +1199,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;
|
|
|