diff options
author | skrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 22:45:27 +0000 |
---|---|---|
committer | skrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-17 22:45:27 +0000 |
commit | e52bc1e0d760a3a4829ab1cf8adfcb5a634c3914 (patch) | |
tree | 2fd140974cb82a17b08ed2682796effaf9ceb0aa /chrome/browser/webdata/web_database_unittest.cc | |
parent | e18f89a80abfa1ca7b4736002a797e407b3fef9b (diff) | |
download | chromium_src-e52bc1e0d760a3a4829ab1cf8adfcb5a634c3914.zip chromium_src-e52bc1e0d760a3a4829ab1cf8adfcb5a634c3914.tar.gz chromium_src-e52bc1e0d760a3a4829ab1cf8adfcb5a634c3914.tar.bz2 |
Return a list of changed from WebDatabase::RemoveFormElementsAddedBetween()
This changes add a list of AutofillChange out parameter to the RemoveFormElementsAddedBetween() method in order to communicate exactly what happened to the caller. This method may only update some autofill entries (by removing use timestamps that fall in the specified time range) or completely remove the autofill entry (if all the use timestamps fall between the specified time range). For sync, we need to know the difference.
This change also required some new testing method on WebDatabase to make it possible to add new autofill entries with specific timestamps. This is needed to create a reliable test that requires entries to be added at different times. If there is a better way to do this, please let me know.
The next change will add the notifications to the WebDataService.
BUG=30169
Review URL: http://codereview.chromium.org/506047
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34889 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata/web_database_unittest.cc')
-rw-r--r-- | chrome/browser/webdata/web_database_unittest.cc | 104 |
1 files changed, 94 insertions, 10 deletions
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc index beb716d..eb94e4f 100644 --- a/chrome/browser/webdata/web_database_unittest.cc +++ b/chrome/browser/webdata/web_database_unittest.cc @@ -9,6 +9,8 @@ #include "base/time.h" #include "base/values.h" #include "chrome/browser/search_engines/template_url.h" +#include "chrome/browser/webdata/autofill_change.h" +#include "chrome/browser/webdata/autofill_entry.h" #include "chrome/browser/webdata/web_database.h" #include "chrome/common/chrome_paths.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -21,6 +23,30 @@ using base::TimeDelta; using webkit_glue::FormField; using webkit_glue::PasswordForm; +// So we can compare AutofillKeys with EXPECT_EQ(). +std::ostream& operator<<(std::ostream& os, const AutofillKey& key) { + return os << UTF16ToASCII(key.name()) << ", " << UTF16ToASCII(key.value()); +} + +// So we can compare AutofillChanges with EXPECT_EQ(). +std::ostream& operator<<(std::ostream& os, const AutofillChange& change) { + switch (change.type()) { + case AutofillChange::ADD: { + os << "ADD"; + break; + } + case AutofillChange::UPDATE: { + os << "UPDATE"; + break; + } + case AutofillChange::REMOVE: { + os << "REMOVE"; + break; + } + } + return os << " " << change.key(); +} + class WebDatabaseTest : public testing::Test { protected: @@ -87,7 +113,7 @@ class WebDatabaseTest : public testing::Test { TEST_F(WebDatabaseTest, Keywords) { WebDatabase db; - EXPECT_TRUE(db.Init(file_)); + ASSERT_TRUE(db.Init(file_)); TemplateURL template_url; template_url.set_short_name(L"short_name"); @@ -148,7 +174,7 @@ TEST_F(WebDatabaseTest, Keywords) { TEST_F(WebDatabaseTest, KeywordMisc) { WebDatabase db; - EXPECT_TRUE(db.Init(file_)); + ASSERT_TRUE(db.Init(file_)); ASSERT_EQ(0, db.GetDefaulSearchProviderID()); ASSERT_EQ(0, db.GetBuitinKeywordVersion()); @@ -163,7 +189,7 @@ TEST_F(WebDatabaseTest, KeywordMisc) { TEST_F(WebDatabaseTest, UpdateKeyword) { WebDatabase db; - EXPECT_TRUE(db.Init(file_)); + ASSERT_TRUE(db.Init(file_)); TemplateURL template_url; template_url.set_short_name(L"short_name"); @@ -225,7 +251,7 @@ TEST_F(WebDatabaseTest, UpdateKeyword) { TEST_F(WebDatabaseTest, KeywordWithNoFavicon) { WebDatabase db; - EXPECT_TRUE(db.Init(file_)); + ASSERT_TRUE(db.Init(file_)); TemplateURL template_url; template_url.set_short_name(L"short_name"); @@ -252,7 +278,7 @@ TEST_F(WebDatabaseTest, KeywordWithNoFavicon) { TEST_F(WebDatabaseTest, Logins) { WebDatabase db; - EXPECT_TRUE(db.Init(file_)); + ASSERT_TRUE(db.Init(file_)); std::vector<PasswordForm*> result; @@ -385,7 +411,7 @@ TEST_F(WebDatabaseTest, Logins) { TEST_F(WebDatabaseTest, Autofill) { WebDatabase db; - EXPECT_TRUE(db.Init(file_)); + ASSERT_TRUE(db.Init(file_)); Time t1 = Time::Now(); @@ -485,7 +511,27 @@ TEST_F(WebDatabaseTest, Autofill) { // Removing all elements since the beginning of this function should remove // everything from the database. - EXPECT_TRUE(db.RemoveFormElementsAddedBetween(t1, Time())); + std::vector<AutofillChange> changes; + EXPECT_TRUE(db.RemoveFormElementsAddedBetween(t1, Time(), &changes)); + + const AutofillChange expected_changes[] = { + AutofillChange(AutofillChange::REMOVE, + AutofillKey(ASCIIToUTF16("Name"), + ASCIIToUTF16("Superman"))), + AutofillChange(AutofillChange::REMOVE, + AutofillKey(ASCIIToUTF16("Name"), + ASCIIToUTF16("Clark Kent"))), + AutofillChange(AutofillChange::REMOVE, + AutofillKey(ASCIIToUTF16("Name"), + ASCIIToUTF16("Clark Sutter"))), + AutofillChange(AutofillChange::REMOVE, + AutofillKey(ASCIIToUTF16("Favorite Color"), + ASCIIToUTF16("Green"))), + }; + EXPECT_EQ(arraysize(expected_changes), changes.size()); + for (size_t i = 0; i < arraysize(expected_changes); i++) { + EXPECT_EQ(expected_changes[i], changes[i]); + } EXPECT_TRUE(db.GetIDAndCountOfFormElement( FormField(string16(), @@ -536,6 +582,44 @@ TEST_F(WebDatabaseTest, Autofill) { EXPECT_EQ(kValue, v[0]); } +TEST_F(WebDatabaseTest, Autofill_RemoveBetweenChanges) { + WebDatabase db; + ASSERT_TRUE(db.Init(file_)); + + TimeDelta one_day(TimeDelta::FromDays(1)); + Time t1 = Time::Now(); + Time t2 = t1 + one_day; + + EXPECT_TRUE(db.AddFormFieldValueTime( + FormField(string16(), + ASCIIToUTF16("Name"), + string16(), + ASCIIToUTF16("Superman")), + t1)); + EXPECT_TRUE(db.AddFormFieldValueTime( + FormField(string16(), + ASCIIToUTF16("Name"), + string16(), + ASCIIToUTF16("Superman")), + t2)); + + std::vector<AutofillChange> changes; + EXPECT_TRUE(db.RemoveFormElementsAddedBetween(t1, t2, &changes)); + ASSERT_EQ(1U, changes.size()); + EXPECT_EQ(AutofillChange(AutofillChange::UPDATE, + AutofillKey(ASCIIToUTF16("Name"), + ASCIIToUTF16("Superman"))), + changes[0]); + changes.clear(); + + EXPECT_TRUE(db.RemoveFormElementsAddedBetween(t2, t2 + one_day, &changes)); + ASSERT_EQ(1U, changes.size()); + EXPECT_EQ(AutofillChange(AutofillChange::REMOVE, + AutofillKey(ASCIIToUTF16("Name"), + ASCIIToUTF16("Superman"))), + changes[0]); +} + static bool AddTimestampedLogin(WebDatabase* db, std::string url, const std::string& unique_string, const Time& time) { @@ -561,7 +645,7 @@ static void ClearResults(std::vector<PasswordForm*>* results) { TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) { WebDatabase db; - EXPECT_TRUE(db.Init(file_)); + ASSERT_TRUE(db.Init(file_)); std::vector<PasswordForm*> result; @@ -603,7 +687,7 @@ TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) { TEST_F(WebDatabaseTest, BlacklistedLogins) { WebDatabase db; - EXPECT_TRUE(db.Init(file_)); + ASSERT_TRUE(db.Init(file_)); std::vector<PasswordForm*> result; // Verify the database is empty. @@ -642,7 +726,7 @@ TEST_F(WebDatabaseTest, BlacklistedLogins) { TEST_F(WebDatabaseTest, WebAppHasAllImages) { WebDatabase db; - EXPECT_TRUE(db.Init(file_)); + ASSERT_TRUE(db.Init(file_)); GURL url("http://google.com/"); // Initial value for unknown web app should be false. |