OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 "base/string_util.h" | |
6 #include "base/utf_string_conversions.h" | |
7 #include "sql/connection.h" | |
8 #include "sql/statement.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 #include "webkit/database/quota_table.h" | |
11 | |
12 namespace { | |
13 | |
14 class TestErrorDelegate : public sql::ErrorDelegate { | |
15 public: | |
16 TestErrorDelegate() {} | |
17 virtual ~TestErrorDelegate() {} | |
18 | |
19 virtual int OnError(int error, | |
20 sql::Connection* connection, | |
21 sql::Statement* stmt) OVERRIDE { | |
22 return error; | |
23 } | |
24 | |
25 private: | |
26 DISALLOW_COPY_AND_ASSIGN(TestErrorDelegate); | |
27 }; | |
28 | |
29 } // namespace | |
30 | |
31 namespace webkit_database { | |
32 | |
33 static bool QuotaTableIsEmpty(sql::Connection* db) { | |
34 sql::Statement statement(db->GetCachedStatement( | |
35 SQL_FROM_HERE, "SELECT COUNT(*) FROM Quota")); | |
36 return (statement.is_valid() && statement.Step() && !statement.ColumnInt(0)); | |
37 } | |
38 | |
39 TEST(QuotaTableTest, TestIt) { | |
40 // Initialize the 'Quota' table. | |
41 sql::Connection db; | |
42 | |
43 // Set an error delegate that will make all operations return false on error. | |
44 db.set_error_delegate(new TestErrorDelegate()); | |
45 | |
46 // Initialize the temp dir and the 'Databases' table. | |
47 EXPECT_TRUE(db.OpenInMemory()); | |
48 QuotaTable quota_table(&db); | |
49 EXPECT_TRUE(quota_table.Init()); | |
50 | |
51 // The 'Quota' table should be empty. | |
52 EXPECT_TRUE(QuotaTableIsEmpty(&db)); | |
53 | |
54 // Set and check the quota for a new origin. | |
55 string16 origin = ASCIIToUTF16("origin"); | |
56 EXPECT_TRUE(quota_table.SetOriginQuota(origin, 1000)); | |
57 EXPECT_EQ(1000, quota_table.GetOriginQuota(origin)); | |
58 | |
59 // Reset and check the quota for the same origin. | |
60 EXPECT_TRUE(quota_table.SetOriginQuota(origin, 2000)); | |
61 EXPECT_EQ(2000, quota_table.GetOriginQuota(origin)); | |
62 | |
63 // Clear the quota for an origin | |
64 EXPECT_TRUE(quota_table.ClearOriginQuota(origin)); | |
65 EXPECT_TRUE(quota_table.GetOriginQuota(origin) < 0); | |
66 | |
67 // Check that there's no quota set for unknown origins. | |
68 EXPECT_TRUE(quota_table.GetOriginQuota(ASCIIToUTF16("unknown_origin")) < 0); | |
69 } | |
70 | |
71 } // namespace webkit_database | |
OLD | NEW |