Chromium Code Reviews| Index: chrome/browser/webdata/autofill_entry_unittest.cc |
| diff --git a/chrome/browser/webdata/autofill_entry_unittest.cc b/chrome/browser/webdata/autofill_entry_unittest.cc |
| index 906674a6fa14feb76bb8f85738ac830fa9b03d90..339105b79ce0d55a3c1d24eb67e636616527239f 100644 |
| --- a/chrome/browser/webdata/autofill_entry_unittest.cc |
| +++ b/chrome/browser/webdata/autofill_entry_unittest.cc |
| @@ -5,6 +5,7 @@ |
| #include <algorithm> |
| #include "base/time.h" |
| +#include "base/utf_string_conversions.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "chrome/browser/webdata/autofill_entry.h" |
| @@ -46,3 +47,46 @@ TEST(AutofillEntryTest, Culling) { |
| --count; |
| } |
| } |
| + |
| +TEST(AutofillEntryTest, CullByTime) { |
| + base::Time current = base::Time::Now(); |
| + base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
| + base::TimeDelta one_hour = base::TimeDelta::FromHours(1); |
| + |
| + std::vector<base::Time> timestamps; |
| + base::Time cutoff_time = current - one_day; |
| + |
| + // Within the time limit. |
| + timestamps.push_back(cutoff_time + one_hour); |
| + |
| + AutofillKey key(UTF8ToUTF16("test_key"), UTF8ToUTF16("test_value")); |
| + |
| + AutofillEntry entry_within_the_limits(key, timestamps); |
| + EXPECT_FALSE(entry_within_the_limits.HasTimestampsOlder(cutoff_time)); |
| + EXPECT_FALSE(entry_within_the_limits.CullExpiredTimeStamps(cutoff_time)); |
| + EXPECT_FALSE(entry_within_the_limits.timestamps_culled()); |
| + EXPECT_EQ(1U, entry_within_the_limits.timestamps().size()); |
| + |
| + // One within the time limit, one outside. |
| + timestamps.push_back(cutoff_time - one_hour); |
| + |
| + AutofillEntry entry_partially_within_the_limits(key, timestamps); |
| + EXPECT_TRUE( |
| + entry_partially_within_the_limits.HasTimestampsOlder(cutoff_time)); |
| + EXPECT_TRUE( |
| + entry_partially_within_the_limits.CullExpiredTimeStamps(cutoff_time)); |
| + EXPECT_TRUE(entry_partially_within_the_limits.timestamps_culled()); |
| + EXPECT_EQ(1U, entry_partially_within_the_limits.timestamps().size()); |
| + |
| + // All outside the time limit. |
| + timestamps.clear(); |
| + timestamps.push_back(cutoff_time - one_hour); |
| + timestamps.push_back(cutoff_time - one_hour * 2); |
| + timestamps.push_back(cutoff_time - one_hour * 3); |
| + |
| + AutofillEntry entry_outside_the_limits(key, timestamps); |
| + EXPECT_TRUE(entry_outside_the_limits.HasTimestampsOlder(cutoff_time)); |
| + EXPECT_TRUE(entry_outside_the_limits.CullExpiredTimeStamps(cutoff_time)); |
| + EXPECT_TRUE(entry_outside_the_limits.timestamps_culled()); |
| + EXPECT_TRUE(entry_outside_the_limits.timestamps().empty()); |
| +} |
|
Ilya Sherman
2012/03/06 08:48:35
Might be good to also test a timestamp exactly at
GeorgeY
2012/03/09 20:14:24
Done.
|