summaryrefslogtreecommitdiffstats
path: root/webkit/database/quota_table_unittest.cc
diff options
context:
space:
mode:
authordumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-06 21:15:55 +0000
committerdumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-06 21:15:55 +0000
commit3ccfe535658c8852c1cc1df01372ecc602f376cd (patch)
tree47582af5ba2a4f0658126d564d618c18a93173cf /webkit/database/quota_table_unittest.cc
parent6d8e2a64b6961331816689850192a8ee864f9a97 (diff)
downloadchromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.zip
chromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.tar.gz
chromium_src-3ccfe535658c8852c1cc1df01372ecc602f376cd.tar.bz2
Adding methods that will be used by the quota management UI.
TEST=none BUG=none Review URL: http://codereview.chromium.org/507014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35651 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/database/quota_table_unittest.cc')
-rw-r--r--webkit/database/quota_table_unittest.cc65
1 files changed, 65 insertions, 0 deletions
diff --git a/webkit/database/quota_table_unittest.cc b/webkit/database/quota_table_unittest.cc
new file mode 100644
index 0000000..fbb59bf
--- /dev/null
+++ b/webkit/database/quota_table_unittest.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2009 The Chromium Authos. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "app/sql/connection.h"
+#include "app/sql/statement.h"
+#include "base/string_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/database/quota_table.h"
+
+namespace {
+
+class TestErrorDelegate : public sql::ErrorDelegate {
+ public:
+ virtual ~TestErrorDelegate() { }
+ virtual int OnError(
+ int error, sql::Connection* connection, sql::Statement* stmt) {
+ return error;
+ }
+};
+
+} // namespace
+
+namespace webkit_database {
+
+static bool QuotaTableIsEmpty(sql::Connection* db) {
+ sql::Statement statement(db->GetCachedStatement(
+ SQL_FROM_HERE, "SELECT COUNT(*) FROM Quota"));
+ return (statement.is_valid() && statement.Step() && !statement.ColumnInt(0));
+}
+
+TEST(QuotaTableTest, TestIt) {
+ // Initialize the 'Quota' table.
+ sql::Connection db;
+
+ // Set an error delegate that will make all operations return false on error.
+ scoped_refptr<TestErrorDelegate> error_delegate(new TestErrorDelegate());
+ db.set_error_delegate(error_delegate);
+
+ // Initialize the temp dir and the 'Databases' table.
+ EXPECT_TRUE(db.OpenInMemory());
+ QuotaTable quota_table(&db);
+ EXPECT_TRUE(quota_table.Init());
+
+ // The 'Quota' table should be empty.
+ EXPECT_TRUE(QuotaTableIsEmpty(&db));
+
+ // Set and check the quota for a new origin.
+ string16 origin = ASCIIToUTF16("origin");
+ EXPECT_TRUE(quota_table.SetOriginQuota(origin, 1000));
+ EXPECT_EQ(1000, quota_table.GetOriginQuota(origin));
+
+ // Reset and check the quota for the same origin.
+ EXPECT_TRUE(quota_table.SetOriginQuota(origin, 2000));
+ EXPECT_EQ(2000, quota_table.GetOriginQuota(origin));
+
+ // Clear the quota for an origin
+ EXPECT_TRUE(quota_table.ClearOriginQuota(origin));
+ EXPECT_TRUE(quota_table.GetOriginQuota(origin) < 0);
+
+ // Check that there's no quota set for unknown origins.
+ EXPECT_TRUE(quota_table.GetOriginQuota(ASCIIToUTF16("unknown_origin")) < 0);
+}
+
+} // namespace webkit_database