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

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: Moved MostVisitedURLsProvider into chrome/browser/precache 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..3a29b117d4d71834745c124fda8e50c50a4d086e
--- /dev/null
+++ b/components/precache/core/precache_statistics_table_unittest.cc
@@ -0,0 +1,90 @@
+// 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 <map>
+
+#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "sql/connection.h"
+#include "sql/statement.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace precache {
+
+namespace {
+
+typedef PrecacheStatisticsTable::PrecacheStatistics PrecacheStatistics;
+
+class PrecacheStatisticsTableTest : public testing::Test {
+ public:
+ PrecacheStatisticsTableTest() {}
+ virtual ~PrecacheStatisticsTableTest() {}
+
+ protected:
+ virtual void SetUp() {
+ 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, IncreaseStatsForFetch) {
+ const base::Time kFetchDay = base::Time::UnixEpoch().LocalMidnight();
+
+ precache_statistics_table_->IncreaseStatsForFetch(
+ kFetchDay + base::TimeDelta::FromHours(5),
+ PrecacheStatistics(5, 4, 3, 2, 1));
+ precache_statistics_table_->IncreaseStatsForFetch(
+ kFetchDay + base::TimeDelta::FromHours(10),
+ PrecacheStatistics(50, 40, 30, 20, 10));
+
+ std::map<base::Time, PrecacheStatistics> expected_stats_map;
+ expected_stats_map[kFetchDay] = PrecacheStatistics(55, 44, 33, 22, 11);
+
+ std::map<base::Time, PrecacheStatistics> actual_stats_map;
+ precache_statistics_table_->GetAllStatsBetween(
+ base::Time::FromInternalValue(0), base::Time::Max(), &actual_stats_map);
+
+ EXPECT_EQ(expected_stats_map, actual_stats_map);
+}
+
+TEST_F(PrecacheStatisticsTableTest, DeleteAllStatsBetween) {
+ const base::Time kBeforeTime = base::Time::UnixEpoch();
+ 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_->IncreaseStatsForFetch(kBeforeTime, kStats);
+ precache_statistics_table_->IncreaseStatsForFetch(kDeleteBegin, kStats);
+ precache_statistics_table_->IncreaseStatsForFetch(kBetweenTime, kStats);
+ precache_statistics_table_->IncreaseStatsForFetch(kDeleteEnd, kStats);
+ precache_statistics_table_->IncreaseStatsForFetch(kAfterTime, kStats);
+
+ precache_statistics_table_->DeleteAllStatsBetween(kDeleteBegin, kDeleteEnd);
+
+ std::map<base::Time, PrecacheStatistics> expected_stats_map;
+ expected_stats_map[kBeforeTime.LocalMidnight()] = kStats;
+ expected_stats_map[kAfterTime.LocalMidnight()] = kStats;
+
+ std::map<base::Time, PrecacheStatistics> actual_stats_map;
+ precache_statistics_table_->GetAllStatsBetween(
+ base::Time::FromInternalValue(0), 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