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

Side by Side Diff: components/webdata/autofill/autofill_entry_unittest.cc

Issue 13839013: Webdata Component tryjobs NOT FOR REVIEW (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: After WD/AF merge Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <algorithm>
6
7 #include "base/time.h"
8 #include "base/utf_string_conversions.h"
9 #include "components/webdata/autofill/autofill_entry.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 const unsigned int kMaxAutofillTimeStamps = 2;
13
14 TEST(AutofillEntryTest, NoCulling) {
15 std::vector<base::Time> source, result;
16 base::Time current = base::Time::Now();
17 for (size_t i = 0; i < kMaxAutofillTimeStamps; ++i)
18 source.push_back(current);
19
20 EXPECT_FALSE(AutofillEntry::CullTimeStamps(source, &result));
21 EXPECT_EQ(result.size(), kMaxAutofillTimeStamps);
22 for (std::vector<base::Time>::const_iterator it = result.begin();
23 it != result.end(); ++it) {
24 EXPECT_EQ(*it, current);
25 }
26 }
27
28 TEST(AutofillEntryTest, Culling) {
29 std::vector<base::Time> source, result;
30 base::Time current = base::Time::Now();
31 const int offset = 10000;
32
33 int64 internal_value = current.ToInternalValue();
34 for (size_t i = 0; i < kMaxAutofillTimeStamps * 2 ; ++i) {
35 source.push_back(base::Time::FromInternalValue(
36 internal_value + i * offset));
37 }
38 std::sort(source.begin(), source.end());
39 EXPECT_TRUE(AutofillEntry::CullTimeStamps(source, &result));
40
41 EXPECT_EQ(result.size(), kMaxAutofillTimeStamps);
42 EXPECT_EQ(result.front(), base::Time::FromInternalValue(internal_value));
43 int last_offset = (kMaxAutofillTimeStamps * 2 - 1) * offset;
44 EXPECT_EQ(result.back(),
45 base::Time::FromInternalValue(last_offset + internal_value));
46 }
47
48 TEST(AutofillEntryTest, CullByTime) {
49 base::TimeDelta one_hour = base::TimeDelta::FromHours(1);
50
51 std::vector<base::Time> timestamps;
52 base::Time cutoff_time = AutofillEntry::ExpirationTime();
53
54 // Within the time limit.
55 timestamps.push_back(cutoff_time + one_hour);
56
57 AutofillKey key(UTF8ToUTF16("test_key"), UTF8ToUTF16("test_value"));
58
59 AutofillEntry entry_within_the_limits(key, timestamps);
60 EXPECT_FALSE(entry_within_the_limits.IsExpired());
61
62 // One within the time limit, one outside.
63 timestamps.push_back(cutoff_time - one_hour);
64
65 AutofillEntry entry_partially_within_the_limits(key, timestamps);
66 EXPECT_TRUE(
67 entry_partially_within_the_limits.IsExpired());
68
69 // All outside the time limit.
70 timestamps.clear();
71 timestamps.push_back(cutoff_time - one_hour);
72 timestamps.push_back(cutoff_time - one_hour * 2);
73 timestamps.push_back(cutoff_time - one_hour * 3);
74
75 AutofillEntry entry_outside_the_limits(key, timestamps);
76 EXPECT_TRUE(entry_outside_the_limits.IsExpired());
77 EXPECT_TRUE(entry_outside_the_limits.timestamps_culled());
78 }
OLDNEW
« no previous file with comments | « components/webdata/autofill/autofill_entry.cc ('k') | components/webdata/autofill/autofill_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698