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

Side by Side Diff: webkit/database/quota_table_unittest.cc

Issue 11111021: Remove ref counting on sql::ErrorDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes as requested Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/database/databases_table_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/string_util.h" 5 #include "base/string_util.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "sql/connection.h" 7 #include "sql/connection.h"
8 #include "sql/statement.h" 8 #include "sql/statement.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "webkit/database/quota_table.h" 10 #include "webkit/database/quota_table.h"
11 11
12 namespace { 12 namespace {
13 13
14 class TestErrorDelegate : public sql::ErrorDelegate { 14 class TestErrorDelegate : public sql::ErrorDelegate {
15 public: 15 public:
16 TestErrorDelegate() {}
17 virtual ~TestErrorDelegate() {}
18
16 virtual int OnError(int error, 19 virtual int OnError(int error,
17 sql::Connection* connection, 20 sql::Connection* connection,
18 sql::Statement* stmt) OVERRIDE { 21 sql::Statement* stmt) OVERRIDE {
19 return error; 22 return error;
20 } 23 }
21 24
22 protected: 25 private:
23 virtual ~TestErrorDelegate() {} 26 DISALLOW_COPY_AND_ASSIGN(TestErrorDelegate);
24 }; 27 };
25 28
26 } // namespace 29 } // namespace
27 30
28 namespace webkit_database { 31 namespace webkit_database {
29 32
30 static bool QuotaTableIsEmpty(sql::Connection* db) { 33 static bool QuotaTableIsEmpty(sql::Connection* db) {
31 sql::Statement statement(db->GetCachedStatement( 34 sql::Statement statement(db->GetCachedStatement(
32 SQL_FROM_HERE, "SELECT COUNT(*) FROM Quota")); 35 SQL_FROM_HERE, "SELECT COUNT(*) FROM Quota"));
33 return (statement.is_valid() && statement.Step() && !statement.ColumnInt(0)); 36 return (statement.is_valid() && statement.Step() && !statement.ColumnInt(0));
34 } 37 }
35 38
36 TEST(QuotaTableTest, TestIt) { 39 TEST(QuotaTableTest, TestIt) {
37 // Initialize the 'Quota' table. 40 // Initialize the 'Quota' table.
38 sql::Connection db; 41 sql::Connection db;
39 42
40 // Set an error delegate that will make all operations return false on error. 43 // Set an error delegate that will make all operations return false on error.
41 scoped_refptr<TestErrorDelegate> error_delegate(new TestErrorDelegate()); 44 db.set_error_delegate(new TestErrorDelegate());
42 db.set_error_delegate(error_delegate);
43 45
44 // Initialize the temp dir and the 'Databases' table. 46 // Initialize the temp dir and the 'Databases' table.
45 EXPECT_TRUE(db.OpenInMemory()); 47 EXPECT_TRUE(db.OpenInMemory());
46 QuotaTable quota_table(&db); 48 QuotaTable quota_table(&db);
47 EXPECT_TRUE(quota_table.Init()); 49 EXPECT_TRUE(quota_table.Init());
48 50
49 // The 'Quota' table should be empty. 51 // The 'Quota' table should be empty.
50 EXPECT_TRUE(QuotaTableIsEmpty(&db)); 52 EXPECT_TRUE(QuotaTableIsEmpty(&db));
51 53
52 // Set and check the quota for a new origin. 54 // Set and check the quota for a new origin.
53 string16 origin = ASCIIToUTF16("origin"); 55 string16 origin = ASCIIToUTF16("origin");
54 EXPECT_TRUE(quota_table.SetOriginQuota(origin, 1000)); 56 EXPECT_TRUE(quota_table.SetOriginQuota(origin, 1000));
55 EXPECT_EQ(1000, quota_table.GetOriginQuota(origin)); 57 EXPECT_EQ(1000, quota_table.GetOriginQuota(origin));
56 58
57 // Reset and check the quota for the same origin. 59 // Reset and check the quota for the same origin.
58 EXPECT_TRUE(quota_table.SetOriginQuota(origin, 2000)); 60 EXPECT_TRUE(quota_table.SetOriginQuota(origin, 2000));
59 EXPECT_EQ(2000, quota_table.GetOriginQuota(origin)); 61 EXPECT_EQ(2000, quota_table.GetOriginQuota(origin));
60 62
61 // Clear the quota for an origin 63 // Clear the quota for an origin
62 EXPECT_TRUE(quota_table.ClearOriginQuota(origin)); 64 EXPECT_TRUE(quota_table.ClearOriginQuota(origin));
63 EXPECT_TRUE(quota_table.GetOriginQuota(origin) < 0); 65 EXPECT_TRUE(quota_table.GetOriginQuota(origin) < 0);
64 66
65 // Check that there's no quota set for unknown origins. 67 // Check that there's no quota set for unknown origins.
66 EXPECT_TRUE(quota_table.GetOriginQuota(ASCIIToUTF16("unknown_origin")) < 0); 68 EXPECT_TRUE(quota_table.GetOriginQuota(ASCIIToUTF16("unknown_origin")) < 0);
67 } 69 }
68 70
69 } // namespace webkit_database 71 } // namespace webkit_database
OLDNEW
« no previous file with comments | « webkit/database/databases_table_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698