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

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

Issue 842163002: LoginDatabase::AddLogin should handle correctly incorrect input. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DoesMatchConstraints 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 fda25fb27e65d839bed1d54ec4c879b2ce7e46c9..f8bca7f4d92c8d1a501f134c106a5422f4ff7074 100644
--- a/components/password_manager/core/browser/login_database_unittest.cc
+++ b/components/password_manager/core/browser/login_database_unittest.cc
@@ -671,11 +671,15 @@ TEST_F(LoginDatabaseTest, ClearPrivateData_SavedPasswords) {
base::TimeDelta one_day = base::TimeDelta::FromDays(1);
// Create one with a 0 time.
- EXPECT_TRUE(AddTimestampedLogin(&db_, "1", "foo1", base::Time(), true));
+ EXPECT_TRUE(AddTimestampedLogin(&db_, "http://1.com", "foo1",
+ base::Time(), true));
// Create one for now and +/- 1 day.
- EXPECT_TRUE(AddTimestampedLogin(&db_, "2", "foo2", now - one_day, true));
- EXPECT_TRUE(AddTimestampedLogin(&db_, "3", "foo3", now, true));
- EXPECT_TRUE(AddTimestampedLogin(&db_, "4", "foo4", now + one_day, true));
+ EXPECT_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));
// Verify inserts worked.
EXPECT_TRUE(db_.GetAutofillableLogins(&result));
@@ -710,11 +714,15 @@ TEST_F(LoginDatabaseTest, RemoveLoginsSyncedBetween) {
base::TimeDelta one_day = base::TimeDelta::FromDays(1);
// Create one with a 0 time.
- EXPECT_TRUE(AddTimestampedLogin(&db_, "1", "foo1", base::Time(), false));
+ EXPECT_TRUE(AddTimestampedLogin(&db_, "http://1.com", "foo1",
+ base::Time(), false));
// Create one for now and +/- 1 day.
- EXPECT_TRUE(AddTimestampedLogin(&db_, "2", "foo2", now - one_day, false));
- EXPECT_TRUE(AddTimestampedLogin(&db_, "3", "foo3", now, false));
- EXPECT_TRUE(AddTimestampedLogin(&db_, "4", "foo4", now + one_day, false));
+ EXPECT_TRUE(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));
// Verify inserts worked.
EXPECT_TRUE(db_.GetAutofillableLogins(&result.get()));
@@ -724,8 +732,8 @@ TEST_F(LoginDatabaseTest, RemoveLoginsSyncedBetween) {
// Get everything from today's date and on.
EXPECT_TRUE(db_.GetLoginsSyncedBetween(now, base::Time(), &result.get()));
ASSERT_EQ(2U, result.size());
- EXPECT_EQ("3", result[0]->signon_realm);
- EXPECT_EQ("4", result[1]->signon_realm);
+ 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.
@@ -734,8 +742,8 @@ TEST_F(LoginDatabaseTest, RemoveLoginsSyncedBetween) {
// Should have deleted half of what we inserted.
EXPECT_TRUE(db_.GetAutofillableLogins(&result.get()));
ASSERT_EQ(2U, result.size());
- EXPECT_EQ("1", result[0]->signon_realm);
- EXPECT_EQ("2", result[1]->signon_realm);
+ 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).
@@ -961,6 +969,25 @@ TEST_F(LoginDatabaseTest, DoubleAdd) {
EXPECT_EQ(list, db_.AddLogin(form));
}
+TEST_F(LoginDatabaseTest, AddWrongForm) {
+ PasswordForm form;
+ // |origin| shouldn't be empty.
+ form.origin = GURL();
+ form.signon_realm = "http://accounts.google.com/";
+ form.username_value = ASCIIToUTF16("my_username");
+ form.password_value = ASCIIToUTF16("my_password");
+ form.ssl_valid = false;
+ form.preferred = true;
+ form.blacklisted_by_user = false;
+ form.scheme = PasswordForm::SCHEME_HTML;
+ 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));
+}
+
TEST_F(LoginDatabaseTest, UpdateLogin) {
PasswordForm form;
form.origin = GURL("http://accounts.google.com/LoginAuth");

Powered by Google App Engine
This is Rietveld 408576698