summaryrefslogtreecommitdiff
path: root/chromium/sql
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2013-12-11 21:33:03 +0100
committerAndras Becsi <andras.becsi@digia.com>2013-12-13 12:34:07 +0100
commitf2a33ff9cbc6d19943f1c7fbddd1f23d23975577 (patch)
tree0586a32aa390ade8557dfd6b4897f43a07449578 /chromium/sql
parent5362912cdb5eea702b68ebe23702468d17c3017a (diff)
downloadqtwebengine-chromium-f2a33ff9cbc6d19943f1c7fbddd1f23d23975577.tar.gz
Update Chromium to branch 1650 (31.0.1650.63)
Change-Id: I57d8c832eaec1eb2364e0a8e7352a6dd354db99f Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'chromium/sql')
-rw-r--r--chromium/sql/connection.cc23
-rw-r--r--chromium/sql/connection.h5
-rw-r--r--chromium/sql/connection_unittest.cc13
-rw-r--r--chromium/sql/meta_table_unittest.cc226
-rw-r--r--chromium/sql/run_all_unittests.cc9
-rw-r--r--chromium/sql/sql.gyp5
-rw-r--r--chromium/sql/transaction_unittest.cc2
7 files changed, 263 insertions, 20 deletions
diff --git a/chromium/sql/connection.cc b/chromium/sql/connection.cc
index 3bc25458546..097edd7a1ea 100644
--- a/chromium/sql/connection.cc
+++ b/chromium/sql/connection.cc
@@ -724,6 +724,29 @@ scoped_refptr<Connection::StatementRef> Connection::GetUntrackedStatement(
return new StatementRef(NULL, stmt, true);
}
+std::string Connection::GetSchema() const {
+ // The ORDER BY should not be necessary, but relying on organic
+ // order for something like this is questionable.
+ const char* kSql =
+ "SELECT type, name, tbl_name, sql "
+ "FROM sqlite_master ORDER BY 1, 2, 3, 4";
+ Statement statement(GetUntrackedStatement(kSql));
+
+ std::string schema;
+ while (statement.Step()) {
+ schema += statement.ColumnString(0);
+ schema += '|';
+ schema += statement.ColumnString(1);
+ schema += '|';
+ schema += statement.ColumnString(2);
+ schema += '|';
+ schema += statement.ColumnString(3);
+ schema += '\n';
+ }
+
+ return schema;
+}
+
bool Connection::IsSQLValid(const char* sql) {
AssertIOAllowed();
if (!db_) {
diff --git a/chromium/sql/connection.h b/chromium/sql/connection.h
index 24f06deaedc..79386064228 100644
--- a/chromium/sql/connection.h
+++ b/chromium/sql/connection.h
@@ -389,6 +389,11 @@ class SQL_EXPORT Connection {
// last sqlite operation.
const char* GetErrorMessage() const;
+ // Return a reproducible representation of the schema equivalent to
+ // running the following statement at a sqlite3 command-line:
+ // SELECT type, name, tbl_name, sql FROM sqlite_master ORDER BY 1, 2, 3, 4;
+ std::string GetSchema() const;
+
private:
// For recovery module.
friend class Recovery;
diff --git a/chromium/sql/connection_unittest.cc b/chromium/sql/connection_unittest.cc
index 09a47fb47fd..445db3459bd 100644
--- a/chromium/sql/connection_unittest.cc
+++ b/chromium/sql/connection_unittest.cc
@@ -88,11 +88,10 @@ class ScopedUmaskSetter {
class SQLConnectionTest : public testing::Test {
public:
- SQLConnectionTest() {}
-
virtual void SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
- ASSERT_TRUE(db_.Open(db_path()));
+ db_path_ = temp_dir_.path().AppendASCII("SQLConnectionTest.db");
+ ASSERT_TRUE(db_.Open(db_path_));
}
virtual void TearDown() {
@@ -100,10 +99,7 @@ class SQLConnectionTest : public testing::Test {
}
sql::Connection& db() { return db_; }
-
- base::FilePath db_path() {
- return temp_dir_.path().AppendASCII("SQLConnectionTest.db");
- }
+ const base::FilePath& db_path() { return db_path_; }
// Handle errors by blowing away the database.
void RazeErrorCallback(int expected_error, int error, sql::Statement* stmt) {
@@ -112,8 +108,9 @@ class SQLConnectionTest : public testing::Test {
}
private:
- base::ScopedTempDir temp_dir_;
sql::Connection db_;
+ base::FilePath db_path_;
+ base::ScopedTempDir temp_dir_;
};
TEST_F(SQLConnectionTest, Execute) {
diff --git a/chromium/sql/meta_table_unittest.cc b/chromium/sql/meta_table_unittest.cc
new file mode 100644
index 00000000000..3fbc499f417
--- /dev/null
+++ b/chromium/sql/meta_table_unittest.cc
@@ -0,0 +1,226 @@
+// 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 "sql/meta_table.h"
+
+#include "base/files/file_path.h"
+#include "base/files/scoped_temp_dir.h"
+#include "sql/connection.h"
+#include "sql/statement.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class SQLMetaTableTest : public testing::Test {
+ public:
+ virtual void SetUp() {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLMetaTableTest.db")));
+ }
+
+ virtual void TearDown() {
+ db_.Close();
+ }
+
+ sql::Connection& db() { return db_; }
+
+ private:
+ base::ScopedTempDir temp_dir_;
+ sql::Connection db_;
+};
+
+TEST_F(SQLMetaTableTest, DoesTableExist) {
+ EXPECT_FALSE(sql::MetaTable::DoesTableExist(&db()));
+
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
+ }
+
+ EXPECT_TRUE(sql::MetaTable::DoesTableExist(&db()));
+}
+
+TEST_F(SQLMetaTableTest, VersionNumber) {
+ // Compatibility versions one less than the main versions to make
+ // sure the values aren't being crossed with each other.
+ const int kVersionFirst = 2;
+ const int kCompatVersionFirst = kVersionFirst - 1;
+ const int kVersionSecond = 4;
+ const int kCompatVersionSecond = kVersionSecond - 1;
+ const int kVersionThird = 6;
+ const int kCompatVersionThird = kVersionThird - 1;
+
+ // First Init() sets the version info as expected.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), kVersionFirst, kCompatVersionFirst));
+ EXPECT_EQ(kVersionFirst, meta_table.GetVersionNumber());
+ EXPECT_EQ(kCompatVersionFirst, meta_table.GetCompatibleVersionNumber());
+ }
+
+ // Second Init() does not change the version info.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), kVersionSecond, kCompatVersionSecond));
+ EXPECT_EQ(kVersionFirst, meta_table.GetVersionNumber());
+ EXPECT_EQ(kCompatVersionFirst, meta_table.GetCompatibleVersionNumber());
+
+ meta_table.SetVersionNumber(kVersionSecond);
+ meta_table.SetCompatibleVersionNumber(kCompatVersionSecond);
+ }
+
+ // Version info from Set*() calls is seen.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), kVersionThird, kCompatVersionThird));
+ EXPECT_EQ(kVersionSecond, meta_table.GetVersionNumber());
+ EXPECT_EQ(kCompatVersionSecond, meta_table.GetCompatibleVersionNumber());
+ }
+}
+
+TEST_F(SQLMetaTableTest, StringValue) {
+ const char kKey[] = "String Key";
+ const std::string kFirstValue("First Value");
+ const std::string kSecondValue("Second Value");
+
+ // Initially, the value isn't there until set.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
+
+ std::string value;
+ EXPECT_FALSE(meta_table.GetValue(kKey, &value));
+
+ EXPECT_TRUE(meta_table.SetValue(kKey, kFirstValue));
+ EXPECT_TRUE(meta_table.GetValue(kKey, &value));
+ EXPECT_EQ(kFirstValue, value);
+ }
+
+ // Value is persistent across different instances.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
+
+ std::string value;
+ EXPECT_TRUE(meta_table.GetValue(kKey, &value));
+ EXPECT_EQ(kFirstValue, value);
+
+ EXPECT_TRUE(meta_table.SetValue(kKey, kSecondValue));
+ }
+
+ // Existing value was successfully changed.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
+
+ std::string value;
+ EXPECT_TRUE(meta_table.GetValue(kKey, &value));
+ EXPECT_EQ(kSecondValue, value);
+ }
+}
+
+TEST_F(SQLMetaTableTest, IntValue) {
+ const char kKey[] = "Int Key";
+ const int kFirstValue = 17;
+ const int kSecondValue = 23;
+
+ // Initially, the value isn't there until set.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
+
+ int value;
+ EXPECT_FALSE(meta_table.GetValue(kKey, &value));
+
+ EXPECT_TRUE(meta_table.SetValue(kKey, kFirstValue));
+ EXPECT_TRUE(meta_table.GetValue(kKey, &value));
+ EXPECT_EQ(kFirstValue, value);
+ }
+
+ // Value is persistent across different instances.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
+
+ int value;
+ EXPECT_TRUE(meta_table.GetValue(kKey, &value));
+ EXPECT_EQ(kFirstValue, value);
+
+ EXPECT_TRUE(meta_table.SetValue(kKey, kSecondValue));
+ }
+
+ // Existing value was successfully changed.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
+
+ int value;
+ EXPECT_TRUE(meta_table.GetValue(kKey, &value));
+ EXPECT_EQ(kSecondValue, value);
+ }
+}
+
+TEST_F(SQLMetaTableTest, Int64Value) {
+ const char kKey[] = "Int Key";
+ const int64 kFirstValue = GG_LONGLONG(5000000017);
+ const int64 kSecondValue = GG_LONGLONG(5000000023);
+
+ // Initially, the value isn't there until set.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
+
+ int64 value;
+ EXPECT_FALSE(meta_table.GetValue(kKey, &value));
+
+ EXPECT_TRUE(meta_table.SetValue(kKey, kFirstValue));
+ EXPECT_TRUE(meta_table.GetValue(kKey, &value));
+ EXPECT_EQ(kFirstValue, value);
+ }
+
+ // Value is persistent across different instances.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
+
+ int64 value;
+ EXPECT_TRUE(meta_table.GetValue(kKey, &value));
+ EXPECT_EQ(kFirstValue, value);
+
+ EXPECT_TRUE(meta_table.SetValue(kKey, kSecondValue));
+ }
+
+ // Existing value was successfully changed.
+ {
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
+
+ int64 value;
+ EXPECT_TRUE(meta_table.GetValue(kKey, &value));
+ EXPECT_EQ(kSecondValue, value);
+ }
+}
+
+TEST_F(SQLMetaTableTest, DeleteKey) {
+ const char kKey[] = "String Key";
+ const std::string kValue("String Value");
+
+ sql::MetaTable meta_table;
+ EXPECT_TRUE(meta_table.Init(&db(), 1, 1));
+
+ // Value isn't present.
+ std::string value;
+ EXPECT_FALSE(meta_table.GetValue(kKey, &value));
+
+ // Now value is present.
+ EXPECT_TRUE(meta_table.SetValue(kKey, kValue));
+ EXPECT_TRUE(meta_table.GetValue(kKey, &value));
+ EXPECT_EQ(kValue, value);
+
+ // After delete value isn't present.
+ EXPECT_TRUE(meta_table.DeleteKey(kKey));
+ EXPECT_FALSE(meta_table.GetValue(kKey, &value));
+}
+
+} // namespace
diff --git a/chromium/sql/run_all_unittests.cc b/chromium/sql/run_all_unittests.cc
deleted file mode 100644
index 2c8d29c6d00..00000000000
--- a/chromium/sql/run_all_unittests.cc
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright (c) 2012 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 "base/test/test_suite.h"
-
-int main(int argc, char** argv) {
- return base::TestSuite(argc, argv).Run();
-}
diff --git a/chromium/sql/sql.gyp b/chromium/sql/sql.gyp
index 49ace016eb3..7add51cf258 100644
--- a/chromium/sql/sql.gyp
+++ b/chromium/sql/sql.gyp
@@ -62,6 +62,8 @@
'test/error_callback_support.h',
'test/scoped_error_ignorer.cc',
'test/scoped_error_ignorer.h',
+ 'test/test_helpers.cc',
+ 'test/test_helpers.h',
],
'include_dirs': [
'..',
@@ -78,13 +80,14 @@
'dependencies': [
'sql',
'test_support_sql',
+ '../base/base.gyp:run_all_unittests',
'../base/base.gyp:test_support_base',
'../testing/gtest.gyp:gtest',
'../third_party/sqlite/sqlite.gyp:sqlite',
],
'sources': [
- 'run_all_unittests.cc',
'connection_unittest.cc',
+ 'meta_table_unittest.cc',
'recovery_unittest.cc',
'sqlite_features_unittest.cc',
'statement_unittest.cc',
diff --git a/chromium/sql/transaction_unittest.cc b/chromium/sql/transaction_unittest.cc
index ceaa4dbd7de..fe5eee232d6 100644
--- a/chromium/sql/transaction_unittest.cc
+++ b/chromium/sql/transaction_unittest.cc
@@ -12,8 +12,6 @@
class SQLTransactionTest : public testing::Test {
public:
- SQLTransactionTest() {}
-
virtual void SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
ASSERT_TRUE(db_.Open(