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

Unified 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, 2 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
Index: components/precache/core/precache_statistics_table_unittest.cc
diff --git a/components/precache/core/precache_statistics_table_unittest.cc b/components/precache/core/precache_statistics_table_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..52abe62a421d30ec6b5d752b3b2cca87b3fcc168
--- /dev/null
+++ b/components/precache/core/precache_statistics_table_unittest.cc
@@ -0,0 +1,89 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/precache/core/precache_statistics_table.h"
+
+#include "base/basictypes.h"
+#include "base/bind.h"
+#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.
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "sql/connection.h"
+#include "sql/statement.h"
mmenke 2013/10/31 16:45:00 Do we need sql/statement?
sclittle 2013/11/06 01:51:42 Removed.
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace precache {
+
+namespace {
+
+typedef PrecacheStatisticsTable::PrecacheStatistics PrecacheStatistics;
+typedef PrecacheStatisticsTable::PrecacheStatisticsMap PrecacheStatisticsMap;
+
+class PrecacheStatisticsTableTest : public testing::Test {
+ public:
+ PrecacheStatisticsTableTest() {}
+ virtual ~PrecacheStatisticsTableTest() {}
+
+ protected:
+ 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.
+ precache_statistics_table_.reset(new PrecacheStatisticsTable());
+ db_.reset(new sql::Connection());
+ ASSERT_TRUE(db_->OpenInMemory());
+ precache_statistics_table_->Init(db_.get());
+ }
+
+ scoped_ptr<PrecacheStatisticsTable> precache_statistics_table_;
+ scoped_ptr<sql::Connection> db_;
+};
+
+TEST_F(PrecacheStatisticsTableTest, IncreaseDailyStats) {
+ const base::Time kFetchDay = base::Time::UnixEpoch().LocalMidnight();
+
+ precache_statistics_table_->IncreaseDailyStats(
+ kFetchDay + base::TimeDelta::FromHours(5),
+ PrecacheStatistics(5, 4, 3, 2, 1));
+ precache_statistics_table_->IncreaseDailyStats(
+ kFetchDay + base::TimeDelta::FromHours(10),
+ PrecacheStatistics(50, 40, 30, 20, 10));
+
+ PrecacheStatisticsMap expected_stats_map;
+ expected_stats_map[kFetchDay] = PrecacheStatistics(55, 44, 33, 22, 11);
+
+ PrecacheStatisticsMap actual_stats_map;
+ precache_statistics_table_->GetAllStatsBetween(
+ 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.
+
+ EXPECT_EQ(expected_stats_map, actual_stats_map);
+}
+
+TEST_F(PrecacheStatisticsTableTest, DeleteAllStatsBetween) {
+ 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.
+ const base::Time kDeleteBegin = kBeforeTime + base::TimeDelta::FromDays(1);
+ const base::Time kBetweenTime = kDeleteBegin + base::TimeDelta::FromDays(1);
+ const base::Time kDeleteEnd = kBetweenTime + base::TimeDelta::FromDays(1);
+ const base::Time kAfterTime = kDeleteEnd + base::TimeDelta::FromDays(1);
+ const PrecacheStatistics kStats(5, 4, 3, 2, 1);
+
+ precache_statistics_table_->IncreaseDailyStats(kBeforeTime, kStats);
+ precache_statistics_table_->IncreaseDailyStats(kDeleteBegin, kStats);
+ precache_statistics_table_->IncreaseDailyStats(kBetweenTime, kStats);
+ precache_statistics_table_->IncreaseDailyStats(kDeleteEnd, kStats);
+ precache_statistics_table_->IncreaseDailyStats(kAfterTime, kStats);
+
+ precache_statistics_table_->DeleteAllStatsBetween(kDeleteBegin, kDeleteEnd);
+
+ PrecacheStatisticsMap expected_stats_map;
+ expected_stats_map[kBeforeTime.LocalMidnight()] = kStats;
+ expected_stats_map[kAfterTime.LocalMidnight()] = kStats;
+
+ PrecacheStatisticsMap actual_stats_map;
+ precache_statistics_table_->GetAllStatsBetween(
+ base::Time(), base::Time::Max(), &actual_stats_map);
+
+ EXPECT_EQ(expected_stats_map, actual_stats_map);
+}
+
+} // namespace
+
+} // namespace precache

Powered by Google App Engine
This is Rietveld 408576698