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

Unified Diff: chrome/browser/webdata/autofill_entry_unittest.cc

Issue 9959086: Add probability of culling if sync is enabled to https://chromiumcodereview.appspot.com/9585020/ In… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comment Created 8 years, 9 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
« no previous file with comments | « chrome/browser/webdata/autofill_entry.cc ('k') | chrome/browser/webdata/autofill_table.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..66a6178e8fe4dc57906611ea889dc922c8521eef 100644
--- a/chrome/browser/webdata/autofill_entry_unittest.cc
+++ b/chrome/browser/webdata/autofill_entry_unittest.cc
@@ -5,19 +5,20 @@
#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;
+
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 +39,40 @@ 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::TimeDelta one_hour = base::TimeDelta::FromHours(1);
+
+ std::vector<base::Time> timestamps;
+ base::Time cutoff_time = AutofillEntry::ExpirationTime();
+
+ // 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.IsExpired());
+
+ // 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.IsExpired());
+
+ // 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.IsExpired());
+ EXPECT_TRUE(entry_outside_the_limits.timestamps_culled());
}
« no previous file with comments | « chrome/browser/webdata/autofill_entry.cc ('k') | chrome/browser/webdata/autofill_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698