Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "base/utf_string_conversions.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "chrome/browser/webdata/autofill_entry.h" | 10 #include "chrome/browser/webdata/autofill_entry.h" |
| 10 | 11 |
| 11 extern const unsigned int kMaxAutofillTimeStamps; | 12 extern const unsigned int kMaxAutofillTimeStamps; |
| 12 TEST(AutofillEntryTest, NoCulling) { | 13 TEST(AutofillEntryTest, NoCulling) { |
| 13 std::vector<base::Time> source, result; | 14 std::vector<base::Time> source, result; |
| 14 base::Time current = base::Time::Now(); | 15 base::Time current = base::Time::Now(); |
| 15 for (size_t i = 0; i < kMaxAutofillTimeStamps -1 ; ++i) { | 16 for (size_t i = 0; i < kMaxAutofillTimeStamps -1 ; ++i) { |
| 16 source.push_back(current); | 17 source.push_back(current); |
| 17 } | 18 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 39 | 40 |
| 40 EXPECT_EQ(result.size(), kMaxAutofillTimeStamps); | 41 EXPECT_EQ(result.size(), kMaxAutofillTimeStamps); |
| 41 int count = kMaxAutofillTimeStamps * 2 - 1; | 42 int count = kMaxAutofillTimeStamps * 2 - 1; |
| 42 for (std::vector<base::Time>::const_iterator it = result.begin(); | 43 for (std::vector<base::Time>::const_iterator it = result.begin(); |
| 43 it != result.end(); ++it) { | 44 it != result.end(); ++it) { |
| 44 EXPECT_EQ(*it, base::Time::FromInternalValue( | 45 EXPECT_EQ(*it, base::Time::FromInternalValue( |
| 45 count*offset + internal_value)); | 46 count*offset + internal_value)); |
| 46 --count; | 47 --count; |
| 47 } | 48 } |
| 48 } | 49 } |
| 50 | |
| 51 TEST(AutofillEntryTest, CullByTime) { | |
| 52 base::Time current = base::Time::Now(); | |
| 53 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | |
| 54 base::TimeDelta one_hour = base::TimeDelta::FromHours(1); | |
| 55 | |
| 56 std::vector<base::Time> timestamps; | |
| 57 base::Time cutoff_time = current - one_day; | |
| 58 | |
| 59 // Within the time limit. | |
| 60 timestamps.push_back(cutoff_time + one_hour); | |
| 61 | |
| 62 AutofillKey key(UTF8ToUTF16("test_key"), UTF8ToUTF16("test_value")); | |
| 63 | |
| 64 AutofillEntry entry_within_the_limits(key, timestamps); | |
| 65 EXPECT_FALSE(entry_within_the_limits.HasTimestampsOlder(cutoff_time)); | |
| 66 EXPECT_FALSE(entry_within_the_limits.CullExpiredTimeStamps(cutoff_time)); | |
| 67 EXPECT_FALSE(entry_within_the_limits.timestamps_culled()); | |
| 68 EXPECT_EQ(1U, entry_within_the_limits.timestamps().size()); | |
| 69 | |
| 70 // One within the time limit, one outside. | |
| 71 timestamps.push_back(cutoff_time - one_hour); | |
| 72 | |
| 73 AutofillEntry entry_partially_within_the_limits(key, timestamps); | |
| 74 EXPECT_TRUE( | |
| 75 entry_partially_within_the_limits.HasTimestampsOlder(cutoff_time)); | |
| 76 EXPECT_TRUE( | |
| 77 entry_partially_within_the_limits.CullExpiredTimeStamps(cutoff_time)); | |
| 78 EXPECT_TRUE(entry_partially_within_the_limits.timestamps_culled()); | |
| 79 EXPECT_EQ(1U, entry_partially_within_the_limits.timestamps().size()); | |
| 80 | |
| 81 // All outside the time limit. | |
| 82 timestamps.clear(); | |
| 83 timestamps.push_back(cutoff_time - one_hour); | |
| 84 timestamps.push_back(cutoff_time - one_hour * 2); | |
| 85 timestamps.push_back(cutoff_time - one_hour * 3); | |
| 86 | |
| 87 AutofillEntry entry_outside_the_limits(key, timestamps); | |
| 88 EXPECT_TRUE(entry_outside_the_limits.HasTimestampsOlder(cutoff_time)); | |
| 89 EXPECT_TRUE(entry_outside_the_limits.CullExpiredTimeStamps(cutoff_time)); | |
| 90 EXPECT_TRUE(entry_outside_the_limits.timestamps_culled()); | |
| 91 EXPECT_TRUE(entry_outside_the_limits.timestamps().empty()); | |
| 92 } | |
|
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.
| |
| OLD | NEW |