OLD | NEW |
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/databases_table.h" | 10 #include "webkit/database/databases_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 void CheckDetailsAreEqual(const DatabaseDetails& d1, | 33 static void CheckDetailsAreEqual(const DatabaseDetails& d1, |
31 const DatabaseDetails& d2) { | 34 const DatabaseDetails& d2) { |
32 EXPECT_EQ(d1.origin_identifier, d2.origin_identifier); | 35 EXPECT_EQ(d1.origin_identifier, d2.origin_identifier); |
33 EXPECT_EQ(d1.database_name, d2.database_name); | 36 EXPECT_EQ(d1.database_name, d2.database_name); |
34 EXPECT_EQ(d1.description, d2.description); | 37 EXPECT_EQ(d1.description, d2.description); |
35 EXPECT_EQ(d1.estimated_size, d2.estimated_size); | 38 EXPECT_EQ(d1.estimated_size, d2.estimated_size); |
36 } | 39 } |
37 | 40 |
38 static bool DatabasesTableIsEmpty(sql::Connection* db) { | 41 static bool DatabasesTableIsEmpty(sql::Connection* db) { |
39 sql::Statement statement(db->GetCachedStatement( | 42 sql::Statement statement(db->GetCachedStatement( |
40 SQL_FROM_HERE, "SELECT COUNT(*) FROM Databases")); | 43 SQL_FROM_HERE, "SELECT COUNT(*) FROM Databases")); |
41 return (statement.is_valid() && statement.Step() && !statement.ColumnInt(0)); | 44 return (statement.is_valid() && statement.Step() && !statement.ColumnInt(0)); |
42 } | 45 } |
43 | 46 |
44 TEST(DatabasesTableTest, TestIt) { | 47 TEST(DatabasesTableTest, TestIt) { |
45 // Initialize the 'Databases' table. | 48 // Initialize the 'Databases' table. |
46 sql::Connection db; | 49 sql::Connection db; |
47 | 50 |
48 // Set an error delegate that will make all operations return false on error. | 51 // Set an error delegate that will make all operations return false on error. |
49 scoped_refptr<TestErrorDelegate> error_delegate(new TestErrorDelegate()); | 52 db.set_error_delegate(new TestErrorDelegate()); |
50 db.set_error_delegate(error_delegate); | |
51 | 53 |
52 // Initialize the temp dir and the 'Databases' table. | 54 // Initialize the temp dir and the 'Databases' table. |
53 EXPECT_TRUE(db.OpenInMemory()); | 55 EXPECT_TRUE(db.OpenInMemory()); |
54 DatabasesTable databases_table(&db); | 56 DatabasesTable databases_table(&db); |
55 EXPECT_TRUE(databases_table.Init()); | 57 EXPECT_TRUE(databases_table.Init()); |
56 | 58 |
57 // The 'Databases' table should be empty. | 59 // The 'Databases' table should be empty. |
58 EXPECT_TRUE(DatabasesTableIsEmpty(&db)); | 60 EXPECT_TRUE(DatabasesTableIsEmpty(&db)); |
59 | 61 |
60 // Create the details for a databases. | 62 // Create the details for a databases. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 details_in1.origin_identifier, | 147 details_in1.origin_identifier, |
146 details_in1.database_name, | 148 details_in1.database_name, |
147 &details_out1)); | 149 &details_out1)); |
148 | 150 |
149 // Check that trying to delete a record that doesn't exist fails. | 151 // Check that trying to delete a record that doesn't exist fails. |
150 EXPECT_FALSE(databases_table.DeleteDatabaseDetails( | 152 EXPECT_FALSE(databases_table.DeleteDatabaseDetails( |
151 ASCIIToUTF16("unknown_origin"), ASCIIToUTF16("unknown_database"))); | 153 ASCIIToUTF16("unknown_origin"), ASCIIToUTF16("unknown_database"))); |
152 } | 154 } |
153 | 155 |
154 } // namespace webkit_database | 156 } // namespace webkit_database |
OLD | NEW |