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

Side by Side Diff: components/precache/core/precache_statistics_table_unittest.cc

Issue 27047003: Precache tracking database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@precache
Patch Set: Moved MostVisitedURLsProvider into chrome/browser/precache Created 7 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2013 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 "components/precache/core/precache_statistics_table.h"
6
7 #include <map>
8
9 #include "base/basictypes.h"
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h"
14 #include "sql/connection.h"
15 #include "sql/statement.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace precache {
19
20 namespace {
21
22 typedef PrecacheStatisticsTable::PrecacheStatistics PrecacheStatistics;
23
24 class PrecacheStatisticsTableTest : public testing::Test {
25 public:
26 PrecacheStatisticsTableTest() {}
27 virtual ~PrecacheStatisticsTableTest() {}
28
29 protected:
30 virtual void SetUp() {
31 precache_statistics_table_.reset(new PrecacheStatisticsTable());
32 db_.reset(new sql::Connection());
33 ASSERT_TRUE(db_->OpenInMemory());
34 precache_statistics_table_->Init(db_.get());
35 }
36
37 scoped_ptr<PrecacheStatisticsTable> precache_statistics_table_;
38 scoped_ptr<sql::Connection> db_;
39 };
40
41 TEST_F(PrecacheStatisticsTableTest, IncreaseStatsForFetch) {
42 const base::Time kFetchDay = base::Time::UnixEpoch().LocalMidnight();
43
44 precache_statistics_table_->IncreaseStatsForFetch(
45 kFetchDay + base::TimeDelta::FromHours(5),
46 PrecacheStatistics(5, 4, 3, 2, 1));
47 precache_statistics_table_->IncreaseStatsForFetch(
48 kFetchDay + base::TimeDelta::FromHours(10),
49 PrecacheStatistics(50, 40, 30, 20, 10));
50
51 std::map<base::Time, PrecacheStatistics> expected_stats_map;
52 expected_stats_map[kFetchDay] = PrecacheStatistics(55, 44, 33, 22, 11);
53
54 std::map<base::Time, PrecacheStatistics> actual_stats_map;
55 precache_statistics_table_->GetAllStatsBetween(
56 base::Time::FromInternalValue(0), base::Time::Max(), &actual_stats_map);
57
58 EXPECT_EQ(expected_stats_map, actual_stats_map);
59 }
60
61 TEST_F(PrecacheStatisticsTableTest, DeleteAllStatsBetween) {
62 const base::Time kBeforeTime = base::Time::UnixEpoch();
63 const base::Time kDeleteBegin = kBeforeTime + base::TimeDelta::FromDays(1);
64 const base::Time kBetweenTime = kDeleteBegin + base::TimeDelta::FromDays(1);
65 const base::Time kDeleteEnd = kBetweenTime + base::TimeDelta::FromDays(1);
66 const base::Time kAfterTime = kDeleteEnd + base::TimeDelta::FromDays(1);
67 const PrecacheStatistics kStats(5, 4, 3, 2, 1);
68
69 precache_statistics_table_->IncreaseStatsForFetch(kBeforeTime, kStats);
70 precache_statistics_table_->IncreaseStatsForFetch(kDeleteBegin, kStats);
71 precache_statistics_table_->IncreaseStatsForFetch(kBetweenTime, kStats);
72 precache_statistics_table_->IncreaseStatsForFetch(kDeleteEnd, kStats);
73 precache_statistics_table_->IncreaseStatsForFetch(kAfterTime, kStats);
74
75 precache_statistics_table_->DeleteAllStatsBetween(kDeleteBegin, kDeleteEnd);
76
77 std::map<base::Time, PrecacheStatistics> expected_stats_map;
78 expected_stats_map[kBeforeTime.LocalMidnight()] = kStats;
79 expected_stats_map[kAfterTime.LocalMidnight()] = kStats;
80
81 std::map<base::Time, PrecacheStatistics> actual_stats_map;
82 precache_statistics_table_->GetAllStatsBetween(
83 base::Time::FromInternalValue(0), base::Time::Max(), &actual_stats_map);
84
85 EXPECT_EQ(expected_stats_map, actual_stats_map);
86 }
87
88 } // namespace
89
90 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698