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

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: Added field trials 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 "base/basictypes.h"
8 #include "base/bind.h"
9 #include "base/callback.h"
mmenke 2013/10/31 16:45:00 Do we need bind or callback?
sclittle 2013/11/06 01:51:42 Removed.
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "sql/connection.h"
13 #include "sql/statement.h"
mmenke 2013/10/31 16:45:00 Do we need sql/statement?
sclittle 2013/11/06 01:51:42 Removed.
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace precache {
17
18 namespace {
19
20 typedef PrecacheStatisticsTable::PrecacheStatistics PrecacheStatistics;
21 typedef PrecacheStatisticsTable::PrecacheStatisticsMap PrecacheStatisticsMap;
22
23 class PrecacheStatisticsTableTest : public testing::Test {
24 public:
25 PrecacheStatisticsTableTest() {}
26 virtual ~PrecacheStatisticsTableTest() {}
27
28 protected:
29 virtual void SetUp() {
mmenke 2013/10/31 16:45:00 OVERRIDE (And include compiler_specific for it)
sclittle 2013/11/06 01:51:42 Done.
30 precache_statistics_table_.reset(new PrecacheStatisticsTable());
31 db_.reset(new sql::Connection());
32 ASSERT_TRUE(db_->OpenInMemory());
33 precache_statistics_table_->Init(db_.get());
34 }
35
36 scoped_ptr<PrecacheStatisticsTable> precache_statistics_table_;
37 scoped_ptr<sql::Connection> db_;
38 };
39
40 TEST_F(PrecacheStatisticsTableTest, IncreaseDailyStats) {
41 const base::Time kFetchDay = base::Time::UnixEpoch().LocalMidnight();
42
43 precache_statistics_table_->IncreaseDailyStats(
44 kFetchDay + base::TimeDelta::FromHours(5),
45 PrecacheStatistics(5, 4, 3, 2, 1));
46 precache_statistics_table_->IncreaseDailyStats(
47 kFetchDay + base::TimeDelta::FromHours(10),
48 PrecacheStatistics(50, 40, 30, 20, 10));
49
50 PrecacheStatisticsMap expected_stats_map;
51 expected_stats_map[kFetchDay] = PrecacheStatistics(55, 44, 33, 22, 11);
52
53 PrecacheStatisticsMap actual_stats_map;
54 precache_statistics_table_->GetAllStatsBetween(
55 base::Time(), base::Time::Max(), &actual_stats_map);
mmenke 2013/10/31 16:45:00 You never check that GetAllStatsBetween doesn't ju
sclittle 2013/11/06 01:51:42 Added test.
56
57 EXPECT_EQ(expected_stats_map, actual_stats_map);
58 }
59
60 TEST_F(PrecacheStatisticsTableTest, DeleteAllStatsBetween) {
61 const base::Time kBeforeTime = base::Time::UnixEpoch();
mmenke 2013/10/31 16:45:00 Using real times always makes me nervous. Suggest
sclittle 2013/11/06 01:51:42 Done.
62 const base::Time kDeleteBegin = kBeforeTime + base::TimeDelta::FromDays(1);
63 const base::Time kBetweenTime = kDeleteBegin + base::TimeDelta::FromDays(1);
64 const base::Time kDeleteEnd = kBetweenTime + base::TimeDelta::FromDays(1);
65 const base::Time kAfterTime = kDeleteEnd + base::TimeDelta::FromDays(1);
66 const PrecacheStatistics kStats(5, 4, 3, 2, 1);
67
68 precache_statistics_table_->IncreaseDailyStats(kBeforeTime, kStats);
69 precache_statistics_table_->IncreaseDailyStats(kDeleteBegin, kStats);
70 precache_statistics_table_->IncreaseDailyStats(kBetweenTime, kStats);
71 precache_statistics_table_->IncreaseDailyStats(kDeleteEnd, kStats);
72 precache_statistics_table_->IncreaseDailyStats(kAfterTime, kStats);
73
74 precache_statistics_table_->DeleteAllStatsBetween(kDeleteBegin, kDeleteEnd);
75
76 PrecacheStatisticsMap expected_stats_map;
77 expected_stats_map[kBeforeTime.LocalMidnight()] = kStats;
78 expected_stats_map[kAfterTime.LocalMidnight()] = kStats;
79
80 PrecacheStatisticsMap actual_stats_map;
81 precache_statistics_table_->GetAllStatsBetween(
82 base::Time(), base::Time::Max(), &actual_stats_map);
83
84 EXPECT_EQ(expected_stats_map, actual_stats_map);
85 }
86
87 } // namespace
88
89 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698