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

Unified Diff: components/precache/core/precache_url_table_unittest.cc

Issue 27047003: Precache tracking database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@precache
Patch Set: Addressed comments 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_url_table_unittest.cc
diff --git a/components/precache/core/precache_url_table_unittest.cc b/components/precache/core/precache_url_table_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fe7c9249648258343d98a48ab48b62e46ecb7f4f
--- /dev/null
+++ b/components/precache/core/precache_url_table_unittest.cc
@@ -0,0 +1,121 @@
+// 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_url_table.h"
+
+#include <map>
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/callback.h"
+#include "base/time/time.h"
+#include "sql/connection.h"
+#include "sql/statement.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace precache {
+
+namespace {
+
+class PrecacheURLTableTest : public testing::Test {
+ public:
+ PrecacheURLTableTest() {}
+ virtual ~PrecacheURLTableTest() {}
+
+ protected:
+ virtual void SetUp() {
+ precache_url_table_.reset(new PrecacheURLTable());
+ db_.reset(new sql::Connection());
+ ASSERT_TRUE(db_->OpenInMemory());
+ precache_url_table_->Init(db_.get());
+ }
+
+ scoped_ptr<PrecacheURLTable> precache_url_table_;
+ scoped_ptr<sql::Connection> db_;
+};
+
+TEST_F(PrecacheURLTableTest, AddURLWithNoExistingRow) {
+ precache_url_table_->AddURL(GURL("http://url.com"),
+ base::Time::FromInternalValue(100));
+
+ std::map<GURL, base::Time> expected_map;
+ expected_map[GURL("http://url.com")] = base::Time::FromInternalValue(100);
+
+ std::map<GURL, base::Time> actual_map;
+ precache_url_table_->GetAllDataForTesting(&actual_map);
+ EXPECT_EQ(expected_map, actual_map);
+}
+
+TEST_F(PrecacheURLTableTest, AddURLWithExistingRow) {
+ precache_url_table_->AddURL(GURL("http://url.com"),
+ base::Time::FromInternalValue(90));
+ precache_url_table_->AddURL(GURL("http://url.com"),
+ base::Time::FromInternalValue(100));
+
+ std::map<GURL, base::Time> expected_map;
+ expected_map[GURL("http://url.com")] = base::Time::FromInternalValue(100);
+
+ std::map<GURL, base::Time> actual_map;
+ precache_url_table_->GetAllDataForTesting(&actual_map);
+ EXPECT_EQ(expected_map, actual_map);
+}
+
+TEST_F(PrecacheURLTableTest, DeleteURL) {
+ precache_url_table_->AddURL(GURL("http://stays.com"),
+ base::Time::FromInternalValue(100));
+ precache_url_table_->AddURL(GURL("http://deleted.com"),
+ base::Time::FromInternalValue(200));
+
+ precache_url_table_->DeleteURL(GURL("http://deleted.com"));
+
+ std::map<GURL, base::Time> expected_map;
+ expected_map[GURL("http://stays.com")] = base::Time::FromInternalValue(100);
+
+ std::map<GURL, base::Time> actual_map;
+ precache_url_table_->GetAllDataForTesting(&actual_map);
+ EXPECT_EQ(expected_map, actual_map);
+}
+
+TEST_F(PrecacheURLTableTest, HasURL) {
+ EXPECT_FALSE(precache_url_table_->HasURL(GURL("http://url.com")));
+
+ precache_url_table_->AddURL(GURL("http://url.com"),
+ base::Time::FromInternalValue(100));
+
+ EXPECT_TRUE(precache_url_table_->HasURL(GURL("http://url.com")));
+
+ precache_url_table_->DeleteURL(GURL("http://url.com"));
+
+ EXPECT_FALSE(precache_url_table_->HasURL(GURL("http://url.com")));
+}
+
+TEST_F(PrecacheURLTableTest, DeleteAllPrecachedBetween) {
+ precache_url_table_->AddURL(GURL("http://before.com"),
+ base::Time::FromInternalValue(40));
+ precache_url_table_->AddURL(GURL("http://begin.com"),
+ base::Time::FromInternalValue(50));
+ precache_url_table_->AddURL(GURL("http://between.com"),
+ base::Time::FromInternalValue(100));
+ precache_url_table_->AddURL(GURL("http://end.com"),
+ base::Time::FromInternalValue(150));
+ precache_url_table_->AddURL(GURL("http://after.com"),
+ base::Time::FromInternalValue(160));
+
+ precache_url_table_->DeleteAllPrecachedBetween(
+ base::Time::FromInternalValue(50), base::Time::FromInternalValue(150));
+
+ std::map<GURL, base::Time> expected_map;
+ expected_map[GURL("http://before.com")] = base::Time::FromInternalValue(40);
+ expected_map[GURL("http://after.com")] = base::Time::FromInternalValue(160);
+
+ std::map<GURL, base::Time> actual_map;
+ precache_url_table_->GetAllDataForTesting(&actual_map);
+ EXPECT_EQ(expected_map, actual_map);
+}
+
+} // namespace
+
+} // namespace precache

Powered by Google App Engine
This is Rietveld 408576698