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

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

Issue 335893002: Support to remove passwords by date_synced timestamp. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync integration tests Created 6 years, 6 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 8cef06ea54c2cc25dc8fc1df28d16d2a7a9d781a..fc4ab3b051ef25cb8d4bd1d710fce1b631bc7da1 100644
--- a/components/password_manager/core/browser/login_database_unittest.cc
+++ b/components/password_manager/core/browser/login_database_unittest.cc
@@ -579,7 +579,7 @@ TEST_F(LoginDatabaseTest, TestPublicSuffixDomainMatchingRegexp) {
static bool AddTimestampedLogin(LoginDatabase* db, std::string url,
const std::string& unique_string,
- const base::Time& time) {
+ const base::Time& time, bool date_is_creation) {
// Example password form.
PasswordForm form;
form.origin = GURL(url + std::string("/LoginAuth"));
@@ -588,7 +588,10 @@ static bool AddTimestampedLogin(LoginDatabase* db, std::string url,
form.password_element = ASCIIToUTF16(unique_string);
form.submit_element = ASCIIToUTF16("signIn");
form.signon_realm = url;
- form.date_created = time;
+ if (date_is_creation)
+ form.date_created = time;
+ else
+ form.date_synced = time;
return db->AddLogin(form) == AddChangeForForm(form);
}
@@ -610,11 +613,11 @@ 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()));
+ EXPECT_TRUE(AddTimestampedLogin(&db_, "1", "foo1", base::Time(), true));
// Create one for now and +/- 1 day.
- EXPECT_TRUE(AddTimestampedLogin(&db_, "2", "foo2", now - one_day));
- EXPECT_TRUE(AddTimestampedLogin(&db_, "3", "foo3", now));
- EXPECT_TRUE(AddTimestampedLogin(&db_, "4", "foo4", now + one_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));
// Verify inserts worked.
EXPECT_TRUE(db_.GetAutofillableLogins(&result));
@@ -642,6 +645,49 @@ TEST_F(LoginDatabaseTest, ClearPrivateData_SavedPasswords) {
EXPECT_EQ(0U, result.size());
}
+TEST_F(LoginDatabaseTest, RemoveLoginsSyncedBetween) {
+ ScopedVector<autofill::PasswordForm> result;
+
+ base::Time now = base::Time::Now();
+ base::TimeDelta one_day = base::TimeDelta::FromDays(1);
+
+ // Create one with a 0 time.
+ EXPECT_TRUE(AddTimestampedLogin(&db_, "1", "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));
+
+ // Verify inserts worked.
+ 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()));
+ ASSERT_EQ(2U, result.size());
+ EXPECT_EQ("3", result[0]->signon_realm);
+ EXPECT_EQ("4", result[1]->signon_realm);
+ result.clear();
+
+ // Delete everything from today's date and on.
+ db_.RemoveLoginsSyncedBetween(now, base::Time());
+
+ // 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);
+ result.clear();
+
+ // Delete with 0 date (should delete all).
+ db_.RemoveLoginsSyncedBetween(base::Time(), now);
+
+ // Verify nothing is left.
+ EXPECT_TRUE(db_.GetAutofillableLogins(&result.get()));
+ EXPECT_EQ(0U, result.size());
+}
+
TEST_F(LoginDatabaseTest, BlacklistedLogins) {
std::vector<PasswordForm*> result;
@@ -814,6 +860,7 @@ TEST_F(LoginDatabaseTest, UpdateOverlappingCredentials) {
// 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));
// Both still exist now.

Powered by Google App Engine
This is Rietveld 408576698