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 36c158a1946b48a393f928d3bd7051a8cf60f311..58bb911bed208552eaa4b54f6f578d480b322864 100644 |
| --- a/chrome/browser/webdata/autofill_entry_unittest.cc |
| +++ b/chrome/browser/webdata/autofill_entry_unittest.cc |
| @@ -5,19 +5,19 @@ |
| #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" |
| -extern const unsigned int kMaxAutofillTimeStamps; |
| +const unsigned int kMaxAutofillTimeStamps = 2; |
|
Ilya Sherman
2012/03/15 21:00:41
nit: Please add a linebreak between this constant
GeorgeY
2012/03/17 00:36:16
Done.
|
| TEST(AutofillEntryTest, NoCulling) { |
| std::vector<base::Time> source, result; |
| base::Time current = base::Time::Now(); |
| - for (size_t i = 0; i < kMaxAutofillTimeStamps -1 ; ++i) { |
| + for (size_t i = 0; i < kMaxAutofillTimeStamps; ++i) |
| source.push_back(current); |
| - } |
| EXPECT_FALSE(AutofillEntry::CullTimeStamps(source, &result)); |
| - EXPECT_EQ(result.size(), kMaxAutofillTimeStamps -1); |
| + EXPECT_EQ(result.size(), kMaxAutofillTimeStamps); |
| for (std::vector<base::Time>::const_iterator it = result.begin(); |
| it != result.end(); ++it) { |
| EXPECT_EQ(*it, current); |
| @@ -38,11 +38,50 @@ TEST(AutofillEntryTest, Culling) { |
| EXPECT_TRUE(AutofillEntry::CullTimeStamps(source, &result)); |
| EXPECT_EQ(result.size(), kMaxAutofillTimeStamps); |
| - int count = kMaxAutofillTimeStamps * 2 - 1; |
| - for (std::vector<base::Time>::const_iterator it = result.begin(); |
| - it != result.end(); ++it) { |
| - EXPECT_EQ(*it, base::Time::FromInternalValue( |
| - count*offset + internal_value)); |
| - --count; |
| - } |
| + EXPECT_EQ(result.front(), base::Time::FromInternalValue(internal_value)); |
| + int last_offset = (kMaxAutofillTimeStamps * 2 - 1) * offset; |
| + EXPECT_EQ(result.back(), |
| + base::Time::FromInternalValue(last_offset + internal_value)); |
| +} |
| + |
| +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.LastAccessOlder(cutoff_time)); |
| + |
| + // 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.LastAccessOlder(cutoff_time)); |
| + |
| + // 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.LastAccessOlder(cutoff_time)); |
| + EXPECT_TRUE(entry_outside_the_limits.timestamps_culled()); |
| + |
| + // Timestamp is on the edge. |
|
GeorgeY
2012/03/17 00:36:16
This is removed, as it is going to be flaky with t
|
| + timestamps.clear(); |
| + timestamps.push_back(cutoff_time); |
| + AutofillEntry entry_on_the_edge(key, timestamps); |
| + EXPECT_FALSE(entry_on_the_edge.LastAccessOlder(cutoff_time)); |
| + EXPECT_FALSE(entry_on_the_edge.timestamps_culled()); |
| + EXPECT_EQ(1U, entry_on_the_edge.timestamps().size()); |
| } |