summaryrefslogtreecommitdiff
path: root/chromium/sql
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-08-01 12:59:39 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-08-04 12:40:43 +0000
commit28b1110370900897ab652cb420c371fab8857ad4 (patch)
tree41b32127d23b0df4f2add2a27e12dc87bddb260e /chromium/sql
parent399c965b6064c440ddcf4015f5f8e9d131c7a0a6 (diff)
downloadqtwebengine-chromium-28b1110370900897ab652cb420c371fab8857ad4.tar.gz
BASELINE: Update Chromium to 53.0.2785.41
Also adds a few extra files for extensions. Change-Id: Iccdd55d98660903331cf8b7b29188da781830af4 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/sql')
-rw-r--r--chromium/sql/BUILD.gn4
-rw-r--r--chromium/sql/connection.cc102
-rw-r--r--chromium/sql/connection.h52
-rw-r--r--chromium/sql/connection_memory_dump_provider.cc7
-rw-r--r--chromium/sql/connection_unittest.cc121
-rw-r--r--chromium/sql/recovery_unittest.cc8
-rw-r--r--chromium/sql/sql.gyp4
-rw-r--r--chromium/sql/sql_memory_dump_provider_unittest.cc2
-rw-r--r--chromium/sql/sqlite_features_unittest.cc22
-rw-r--r--chromium/sql/statement_unittest.cc16
10 files changed, 180 insertions, 158 deletions
diff --git a/chromium/sql/BUILD.gn b/chromium/sql/BUILD.gn
index fb1bd2f4709..47678559e62 100644
--- a/chromium/sql/BUILD.gn
+++ b/chromium/sql/BUILD.gn
@@ -42,8 +42,8 @@ source_set("test_support") {
sources = [
"test/error_callback_support.cc",
"test/error_callback_support.h",
- "test/scoped_error_ignorer.cc",
- "test/scoped_error_ignorer.h",
+ "test/scoped_error_expecter.cc",
+ "test/scoped_error_expecter.h",
"test/test_helpers.cc",
"test/test_helpers.h",
]
diff --git a/chromium/sql/connection.cc b/chromium/sql/connection.cc
index f4da99ef76b..25072904630 100644
--- a/chromium/sql/connection.cc
+++ b/chromium/sql/connection.cc
@@ -18,15 +18,17 @@
#include "base/format_macros.h"
#include "base/json/json_file_value_serializer.h"
#include "base/lazy_instance.h"
+#include "base/location.h"
#include "base/logging.h"
-#include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/metrics/sparse_histogram.h"
+#include "base/single_thread_task_runner.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/memory_dump_manager.h"
#include "sql/connection_memory_dump_provider.h"
#include "sql/meta_table.h"
@@ -34,6 +36,7 @@
#include "third_party/sqlite/sqlite3.h"
#if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE)
+#include "base/ios/ios_util.h"
#include "third_party/sqlite/src/ext/icu/sqliteicu.h"
#endif
@@ -159,18 +162,18 @@ void InitializeSqlite() {
sqlite3_initialize();
// Schedule callback to record memory footprint histograms at 10m, 1h, and
- // 1d. There may not be a message loop in tests.
- if (base::MessageLoop::current()) {
- base::MessageLoop::current()->PostDelayedTask(
+ // 1d. There may not be a registered thread task runner in tests.
+ if (base::ThreadTaskRunnerHandle::IsSet()) {
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&RecordSqliteMemory10Min),
base::TimeDelta::FromMinutes(10));
- base::MessageLoop::current()->PostDelayedTask(
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&RecordSqliteMemoryHour),
base::TimeDelta::FromHours(1));
- base::MessageLoop::current()->PostDelayedTask(
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&RecordSqliteMemoryDay),
base::TimeDelta::FromDays(1));
- base::MessageLoop::current()->PostDelayedTask(
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&RecordSqliteMemoryWeek),
base::TimeDelta::FromDays(7));
}
@@ -228,30 +231,13 @@ std::string AsUTF8ForSQL(const base::FilePath& path) {
namespace sql {
// static
-Connection::ErrorIgnorerCallback* Connection::current_ignorer_cb_ = NULL;
+Connection::ErrorExpecterCallback* Connection::current_expecter_cb_ = NULL;
// static
-bool Connection::ShouldIgnoreSqliteError(int error) {
- if (!current_ignorer_cb_)
+bool Connection::IsExpectedSqliteError(int error) {
+ if (!current_expecter_cb_)
return false;
- return current_ignorer_cb_->Run(error);
-}
-
-// static
-bool Connection::ShouldIgnoreSqliteCompileError(int error) {
- // Put this first in case tests need to see that the check happened.
- if (ShouldIgnoreSqliteError(error))
- return true;
-
- // Trim extended error codes.
- int basic_error = error & 0xff;
-
- // These errors relate more to the runtime context of the system than to
- // errors with a SQL statement or with the schema, so they aren't generally
- // interesting to flag. This list is not comprehensive.
- return basic_error == SQLITE_BUSY ||
- basic_error == SQLITE_NOTADB ||
- basic_error == SQLITE_CORRUPT;
+ return current_expecter_cb_->Run(error);
}
void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) {
@@ -283,15 +269,15 @@ void Connection::ReportDiagnosticInfo(int extended_error, Statement* stmt) {
}
// static
-void Connection::SetErrorIgnorer(Connection::ErrorIgnorerCallback* cb) {
- CHECK(current_ignorer_cb_ == NULL);
- current_ignorer_cb_ = cb;
+void Connection::SetErrorExpecter(Connection::ErrorExpecterCallback* cb) {
+ CHECK(current_expecter_cb_ == NULL);
+ current_expecter_cb_ = cb;
}
// static
-void Connection::ResetErrorIgnorer() {
- CHECK(current_ignorer_cb_);
- current_ignorer_cb_ = NULL;
+void Connection::ResetErrorExpecter() {
+ CHECK(current_expecter_cb_);
+ current_expecter_cb_ = NULL;
}
bool StatementID::operator<(const StatementID& other) const {
@@ -872,9 +858,11 @@ std::string Connection::CollectCorruptionInfo() {
size_t Connection::GetAppropriateMmapSize() {
AssertIOAllowed();
-#if defined(OS_IOS)
- // iOS SQLite does not support memory mapping.
- return 0;
+#if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE)
+ if (!base::ios::IsRunningOnIOS10OrLater()) {
+ // iOS SQLite does not support memory mapping.
+ return 0;
+ }
#endif
// How much to map if no errors are found. 50MB encompasses the 99th
@@ -1460,7 +1448,14 @@ scoped_refptr<Connection::StatementRef> Connection::GetCachedStatement(
scoped_refptr<Connection::StatementRef> Connection::GetUniqueStatement(
const char* sql) {
+ return GetStatementImpl(this, sql);
+}
+
+scoped_refptr<Connection::StatementRef> Connection::GetStatementImpl(
+ sql::Connection* tracking_db, const char* sql) const {
AssertIOAllowed();
+ DCHECK(sql);
+ DCHECK(!tracking_db || const_cast<Connection*>(tracking_db)==this);
// Return inactive statement.
if (!db_)
@@ -1470,33 +1465,19 @@ scoped_refptr<Connection::StatementRef> Connection::GetUniqueStatement(
int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, NULL);
if (rc != SQLITE_OK) {
// This is evidence of a syntax error in the incoming SQL.
- if (!ShouldIgnoreSqliteCompileError(rc))
+ if (rc == SQLITE_ERROR)
DLOG(FATAL) << "SQL compile error " << GetErrorMessage();
// It could also be database corruption.
OnSqliteError(rc, NULL, sql);
return new StatementRef(NULL, NULL, false);
}
- return new StatementRef(this, stmt, true);
+ return new StatementRef(tracking_db, stmt, true);
}
-// TODO(shess): Unify this with GetUniqueStatement(). The only difference that
-// seems legitimate is not passing |this| to StatementRef.
scoped_refptr<Connection::StatementRef> Connection::GetUntrackedStatement(
const char* sql) const {
- // Return inactive statement.
- if (!db_)
- return new StatementRef(NULL, NULL, poisoned_);
-
- sqlite3_stmt* stmt = NULL;
- int rc = sqlite3_prepare_v2(db_, sql, -1, &stmt, NULL);
- if (rc != SQLITE_OK) {
- // This is evidence of a syntax error in the incoming SQL.
- if (!ShouldIgnoreSqliteCompileError(rc))
- DLOG(FATAL) << "SQL compile error " << GetErrorMessage();
- return new StatementRef(NULL, NULL, false);
- }
- return new StatementRef(NULL, stmt, true);
+ return GetStatementImpl(NULL, sql);
}
std::string Connection::GetSchema() const {
@@ -1551,8 +1532,8 @@ bool Connection::DoesTableOrIndexExist(
"SELECT name FROM sqlite_master WHERE type=? AND name=? COLLATE NOCASE";
Statement statement(GetUntrackedStatement(kSql));
- // This can happen if the database is corrupt and the error is being ignored
- // for testing purposes.
+ // This can happen if the database is corrupt and the error is a test
+ // expectation.
if (!statement.is_valid())
return false;
@@ -1570,8 +1551,8 @@ bool Connection::DoesColumnExist(const char* table_name,
Statement statement(GetUntrackedStatement(sql.c_str()));
- // This can happen if the database is corrupt and the error is being ignored
- // for testing purposes.
+ // This can happen if the database is corrupt and the error is a test
+ // expectation.
if (!statement.is_valid())
return false;
@@ -1896,7 +1877,8 @@ void Connection::AddTaggedHistogram(const std::string& name,
histogram->Add(sample);
}
-int Connection::OnSqliteError(int err, sql::Statement *stmt, const char* sql) {
+int Connection::OnSqliteError(
+ int err, sql::Statement *stmt, const char* sql) const {
UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.Error", err);
AddTaggedHistogram("Sqlite.Error", err);
@@ -1923,7 +1905,7 @@ int Connection::OnSqliteError(int err, sql::Statement *stmt, const char* sql) {
}
// The default handling is to assert on debug and to ignore on release.
- if (!ShouldIgnoreSqliteError(err))
+ if (!IsExpectedSqliteError(err))
DLOG(FATAL) << GetErrorMessage();
return err;
}
diff --git a/chromium/sql/connection.h b/chromium/sql/connection.h
index 8e8931f2e67..12e7041c9fd 100644
--- a/chromium/sql/connection.h
+++ b/chromium/sql/connection.h
@@ -39,6 +39,7 @@ class Statement;
// To allow some test classes to be friended.
namespace test {
class ScopedCommitHook;
+class ScopedErrorExpecter;
class ScopedScalarFunction;
class ScopedMockTimeSource;
}
@@ -474,15 +475,12 @@ class SQL_EXPORT Connection {
// SELECT type, name, tbl_name, sql FROM sqlite_master ORDER BY 1, 2, 3, 4;
std::string GetSchema() const;
- // Clients which provide an error_callback don't see the
- // error-handling at the end of OnSqliteError(). Expose to allow
- // those clients to work appropriately with ScopedErrorIgnorer in
- // tests.
- static bool ShouldIgnoreSqliteError(int error);
-
- // Additionally ignores errors which are unlikely to be caused by problems
- // with the syntax of a SQL statement, or problems with the database schema.
- static bool ShouldIgnoreSqliteCompileError(int error);
+ // Returns |true| if there is an error expecter (see SetErrorExpecter), and
+ // that expecter returns |true| when passed |error|. Clients which provide an
+ // |error_callback| should use IsExpectedSqliteError() to check for unexpected
+ // errors; if one is detected, DLOG(FATAL) is generally appropriate (see
+ // OnSqliteError implementation).
+ static bool IsExpectedSqliteError(int error);
// Collect various diagnostic information and post a crash dump to aid
// debugging. Dump rate per database is limited to prevent overwhelming the
@@ -493,8 +491,8 @@ class SQL_EXPORT Connection {
// For recovery module.
friend class Recovery;
- // Allow test-support code to set/reset error ignorer.
- friend class ScopedErrorIgnorer;
+ // Allow test-support code to set/reset error expecter.
+ friend class test::ScopedErrorExpecter;
// Statement accesses StatementRef which we don't want to expose to everybody
// (they should go through Statement).
@@ -536,12 +534,12 @@ class SQL_EXPORT Connection {
// Internal helper for DoesTableExist and DoesIndexExist.
bool DoesTableOrIndexExist(const char* name, const char* type) const;
- // Accessors for global error-ignorer, for injecting behavior during tests.
- // See test/scoped_error_ignorer.h.
- typedef base::Callback<bool(int)> ErrorIgnorerCallback;
- static ErrorIgnorerCallback* current_ignorer_cb_;
- static void SetErrorIgnorer(ErrorIgnorerCallback* ignorer);
- static void ResetErrorIgnorer();
+ // Accessors for global error-expecter, for injecting behavior during tests.
+ // See test/scoped_error_expecter.h.
+ typedef base::Callback<bool(int)> ErrorExpecterCallback;
+ static ErrorExpecterCallback* current_expecter_cb_;
+ static void SetErrorExpecter(ErrorExpecterCallback* expecter);
+ static void ResetErrorExpecter();
// A StatementRef is a refcounted wrapper around a sqlite statement pointer.
// Refcounting allows us to give these statements out to sql::Statement
@@ -624,18 +622,24 @@ class SQL_EXPORT Connection {
// error handlers to transparently convert errors into success.
// Unfortunately, transactions are not generally restartable, so
// this did not work out.
- int OnSqliteError(int err, Statement* stmt, const char* sql);
+ int OnSqliteError(int err, Statement* stmt, const char* sql) const;
// Like |Execute()|, but retries if the database is locked.
bool ExecuteWithTimeout(const char* sql, base::TimeDelta ms_timeout)
WARN_UNUSED_RESULT;
- // Internal helper for const functions. Like GetUniqueStatement(),
- // except the statement is not entered into open_statements_,
- // allowing this function to be const. Open statements can block
- // closing the database, so only use in cases where the last ref is
- // released before close could be called (which should always be the
- // case for const functions).
+ // Implementation helper for GetUniqueStatement() and GetUntrackedStatement().
+ // |tracking_db| is the db the resulting ref should register with for
+ // outstanding statement tracking, which should be |this| to track or NULL to
+ // not track.
+ scoped_refptr<StatementRef> GetStatementImpl(
+ sql::Connection* tracking_db, const char* sql) const;
+
+ // Helper for implementing const member functions. Like GetUniqueStatement(),
+ // except the StatementRef is not entered into |open_statements_|, so an
+ // outstanding StatementRef from this function can block closing the database.
+ // The StatementRef will not call OnSqliteError(), because that can call
+ // |error_callback_| which can close the database.
scoped_refptr<StatementRef> GetUntrackedStatement(const char* sql) const;
bool IntegrityCheckHelper(
diff --git a/chromium/sql/connection_memory_dump_provider.cc b/chromium/sql/connection_memory_dump_provider.cc
index 0284bd04515..eaee9b43e3b 100644
--- a/chromium/sql/connection_memory_dump_provider.cc
+++ b/chromium/sql/connection_memory_dump_provider.cc
@@ -4,6 +4,8 @@
#include "sql/connection_memory_dump_provider.h"
+#include <inttypes.h>
+
#include "base/strings/stringprintf.h"
#include "base/trace_event/process_memory_dump.h"
#include "third_party/sqlite/sqlite3.h"
@@ -53,8 +55,9 @@ bool ConnectionMemoryDumpProvider::OnMemoryDump(
}
std::string name = base::StringPrintf(
- "sqlite/%s_connection/%p",
- connection_name_.empty() ? "Unknown" : connection_name_.c_str(), this);
+ "sqlite/%s_connection/0x%" PRIXPTR,
+ connection_name_.empty() ? "Unknown" : connection_name_.c_str(),
+ reinterpret_cast<uintptr_t>(this));
base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name);
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes,
diff --git a/chromium/sql/connection_unittest.cc b/chromium/sql/connection_unittest.cc
index 1c08881227d..6b2d4e75864 100644
--- a/chromium/sql/connection_unittest.cc
+++ b/chromium/sql/connection_unittest.cc
@@ -20,11 +20,15 @@
#include "sql/meta_table.h"
#include "sql/statement.h"
#include "sql/test/error_callback_support.h"
-#include "sql/test/scoped_error_ignorer.h"
+#include "sql/test/scoped_error_expecter.h"
#include "sql/test/test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/sqlite/sqlite3.h"
+#if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE)
+#include "base/ios/ios_util.h"
+#endif
+
namespace sql {
namespace test {
@@ -358,23 +362,23 @@ TEST_F(SQLConnectionTest, Rollback) {
EXPECT_TRUE(db().BeginTransaction());
}
-// Test the scoped error ignorer by attempting to insert a duplicate
+// Test the scoped error expecter by attempting to insert a duplicate
// value into an index.
-TEST_F(SQLConnectionTest, ScopedIgnoreError) {
+TEST_F(SQLConnectionTest, ScopedErrorExpecter) {
const char* kCreateSql = "CREATE TABLE foo (id INTEGER UNIQUE)";
ASSERT_TRUE(db().Execute(kCreateSql));
ASSERT_TRUE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
{
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_CONSTRAINT);
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_CONSTRAINT);
ASSERT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
}
}
// Test that clients of GetUntrackedStatement() can test corruption-handling
-// with ScopedErrorIgnorer.
+// with ScopedErrorExpecter.
TEST_F(SQLConnectionTest, ScopedIgnoreUntracked) {
const char* kCreateSql = "CREATE TABLE foo (id INTEGER UNIQUE)";
ASSERT_TRUE(db().Execute(kCreateSql));
@@ -387,13 +391,13 @@ TEST_F(SQLConnectionTest, ScopedIgnoreUntracked) {
ASSERT_TRUE(CorruptSizeInHeaderOfDB());
{
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_CORRUPT);
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_CORRUPT);
ASSERT_TRUE(db().Open(db_path()));
ASSERT_FALSE(db().DoesTableExist("bar"));
ASSERT_FALSE(db().DoesTableExist("foo"));
ASSERT_FALSE(db().DoesColumnExist("foo", "id"));
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
}
}
@@ -416,10 +420,10 @@ TEST_F(SQLConnectionTest, ErrorCallback) {
// Callback is no longer in force due to reset.
{
error = SQLITE_OK;
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_CONSTRAINT);
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_CONSTRAINT);
ASSERT_FALSE(db().Execute("INSERT INTO foo (id) VALUES (12)"));
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
EXPECT_EQ(SQLITE_OK, error);
}
@@ -616,19 +620,19 @@ TEST_F(SQLConnectionTest, RazeNOTADB) {
// SQLite will successfully open the handle, but fail when running PRAGMA
// statements that access the database.
{
- sql::ScopedErrorIgnorer ignore_errors;
+ sql::test::ScopedErrorExpecter expecter;
// Earlier versions of Chromium compiled against SQLite 3.6.7.3, which
// returned SQLITE_IOERR_SHORT_READ in this case. Some platforms may still
// compile against an earlier SQLite via USE_SYSTEM_SQLITE.
- if (ignore_errors.SQLiteLibVersionNumber() < 3008005) {
- ignore_errors.IgnoreError(SQLITE_IOERR_SHORT_READ);
+ if (expecter.SQLiteLibVersionNumber() < 3008005) {
+ expecter.ExpectError(SQLITE_IOERR_SHORT_READ);
} else {
- ignore_errors.IgnoreError(SQLITE_NOTADB);
+ expecter.ExpectError(SQLITE_NOTADB);
}
EXPECT_TRUE(db().Open(db_path()));
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
}
EXPECT_TRUE(db().Raze());
db().Close();
@@ -651,10 +655,10 @@ TEST_F(SQLConnectionTest, RazeNOTADB2) {
// SQLITE_NOTADB on pragma statemenets which attempt to read the
// corrupted header.
{
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_NOTADB);
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_NOTADB);
EXPECT_TRUE(db().Open(db_path()));
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
}
EXPECT_TRUE(db().Raze());
db().Close();
@@ -680,12 +684,12 @@ TEST_F(SQLConnectionTest, RazeCallbackReopen) {
// Open() will succeed, even though the PRAGMA calls within will
// fail with SQLITE_CORRUPT, as will this PRAGMA.
{
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_CORRUPT);
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_CORRUPT);
ASSERT_TRUE(db().Open(db_path()));
ASSERT_FALSE(db().Execute("PRAGMA auto_vacuum"));
db().Close();
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
}
db().set_error_callback(base::Bind(&SQLConnectionTest::RazeErrorCallback,
@@ -966,10 +970,10 @@ TEST_F(SQLConnectionTest, Attach) {
// Attach fails in a transaction.
EXPECT_TRUE(db().BeginTransaction());
{
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_ERROR);
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_ERROR);
EXPECT_FALSE(db().AttachDatabase(attach_path, kAttachmentPoint));
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
}
// Attach succeeds when the transaction is closed.
@@ -988,11 +992,11 @@ TEST_F(SQLConnectionTest, Attach) {
// Detach also fails in a transaction.
EXPECT_TRUE(db().BeginTransaction());
{
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_ERROR);
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_ERROR);
EXPECT_FALSE(db().DetachDatabase(kAttachmentPoint));
EXPECT_TRUE(db().IsSQLValid("SELECT count(*) from other.bar"));
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
}
// Detach succeeds outside of a transaction.
@@ -1011,11 +1015,11 @@ TEST_F(SQLConnectionTest, Basic_QuickIntegrityCheck) {
ASSERT_TRUE(CorruptSizeInHeaderOfDB());
{
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_CORRUPT);
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_CORRUPT);
ASSERT_TRUE(db().Open(db_path()));
EXPECT_FALSE(db().QuickIntegrityCheck());
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
}
}
@@ -1033,13 +1037,13 @@ TEST_F(SQLConnectionTest, Basic_FullIntegrityCheck) {
ASSERT_TRUE(CorruptSizeInHeaderOfDB());
{
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_CORRUPT);
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_CORRUPT);
ASSERT_TRUE(db().Open(db_path()));
EXPECT_TRUE(db().FullIntegrityCheck(&messages));
EXPECT_LT(1u, messages.size());
EXPECT_NE(kOk, messages[0]);
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
}
// TODO(shess): CorruptTableOrIndex could be used to produce a
@@ -1321,9 +1325,9 @@ TEST_F(SQLConnectionTest, TimeUpdateTransaction) {
}
TEST_F(SQLConnectionTest, OnMemoryDump) {
- base::trace_event::ProcessMemoryDump pmd(nullptr);
base::trace_event::MemoryDumpArgs args = {
base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
+ base::trace_event::ProcessMemoryDump pmd(nullptr, args);
ASSERT_TRUE(db().memory_dump_provider_->OnMemoryDump(args, &pmd));
EXPECT_GE(pmd.allocator_dumps().size(), 1u);
}
@@ -1435,30 +1439,23 @@ TEST_F(SQLConnectionTest, MmapInitiallyEnabled) {
}
}
-// Test specific operation of the GetAppropriateMmapSize() helper.
-#if defined(OS_IOS)
-TEST_F(SQLConnectionTest, GetAppropriateMmapSize) {
- ASSERT_EQ(0UL, db().GetAppropriateMmapSize());
-}
-#else
TEST_F(SQLConnectionTest, GetAppropriateMmapSize) {
+#if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE)
+ // Mmap is not supported on iOS9.
+ if (!base::ios::IsRunningOnIOS10OrLater()) {
+ ASSERT_EQ(0UL, db().GetAppropriateMmapSize());
+ return;
+ }
+#endif
+
const size_t kMmapAlot = 25 * 1024 * 1024;
+ int64_t mmap_status = MetaTable::kMmapFailure;
// If there is no meta table (as for a fresh database), assume that everything
- // should be mapped.
+ // should be mapped, and the status of the meta table is not affected.
ASSERT_TRUE(!db().DoesTableExist("meta"));
ASSERT_GT(db().GetAppropriateMmapSize(), kMmapAlot);
-
- // Getting the status fails if there is an error. GetAppropriateMmapSize()
- // should not call GetMmapStatus() if the table does not exist, but this is an
- // easy error to setup for testing.
- int64_t mmap_status;
- {
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_ERROR);
- ASSERT_FALSE(MetaTable::GetMmapStatus(&db(), &mmap_status));
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
- }
+ ASSERT_TRUE(!db().DoesTableExist("meta"));
// When the meta table is first created, it sets up to map everything.
MetaTable().Init(&db(), 1, 1);
@@ -1486,6 +1483,20 @@ TEST_F(SQLConnectionTest, GetAppropriateMmapSize) {
ASSERT_TRUE(MetaTable::GetMmapStatus(&db(), &mmap_status));
ASSERT_EQ(MetaTable::kMmapSuccess, mmap_status);
}
+
+// To prevent invalid SQL from accidentally shipping to production, prepared
+// statements which fail to compile with SQLITE_ERROR call DLOG(FATAL). This
+// case cannot be suppressed with an error callback.
+TEST_F(SQLConnectionTest, CompileError) {
+ // DEATH tests not supported on Android or iOS.
+#if !defined(OS_ANDROID) && !defined(OS_IOS)
+ if (DLOG_IS_ON(FATAL)) {
+ db().set_error_callback(base::Bind(&IgnoreErrorCallback));
+ ASSERT_DEATH({
+ db().GetUniqueStatement("SELECT x");
+ }, "SQL compile error no such column: x");
+ }
#endif
+}
} // namespace sql
diff --git a/chromium/sql/recovery_unittest.cc b/chromium/sql/recovery_unittest.cc
index b215777560d..a117690634b 100644
--- a/chromium/sql/recovery_unittest.cc
+++ b/chromium/sql/recovery_unittest.cc
@@ -20,7 +20,7 @@
#include "sql/meta_table.h"
#include "sql/statement.h"
#include "sql/test/paths.h"
-#include "sql/test/scoped_error_ignorer.h"
+#include "sql/test/scoped_error_expecter.h"
#include "sql/test/sql_test_base.h"
#include "sql/test/test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -422,12 +422,12 @@ TEST_F(SQLRecoveryTest, Meta) {
// Test meta table missing.
EXPECT_TRUE(db().Execute("DROP TABLE meta"));
{
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_CORRUPT); // From virtual table.
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_CORRUPT); // From virtual table.
std::unique_ptr<sql::Recovery> recovery =
sql::Recovery::Begin(&db(), db_path());
EXPECT_FALSE(recovery->SetupMeta());
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
}
}
diff --git a/chromium/sql/sql.gyp b/chromium/sql/sql.gyp
index cde30576cb9..66e3e7f203d 100644
--- a/chromium/sql/sql.gyp
+++ b/chromium/sql/sql.gyp
@@ -65,8 +65,8 @@
'sources': [
'test/error_callback_support.cc',
'test/error_callback_support.h',
- 'test/scoped_error_ignorer.cc',
- 'test/scoped_error_ignorer.h',
+ 'test/scoped_error_expecter.cc',
+ 'test/scoped_error_expecter.h',
'test/test_helpers.cc',
'test/test_helpers.h',
],
diff --git a/chromium/sql/sql_memory_dump_provider_unittest.cc b/chromium/sql/sql_memory_dump_provider_unittest.cc
index 1f1dcf9a689..95fa408a6b9 100644
--- a/chromium/sql/sql_memory_dump_provider_unittest.cc
+++ b/chromium/sql/sql_memory_dump_provider_unittest.cc
@@ -13,9 +13,9 @@ using SQLMemoryDumpProviderTest = sql::SQLTestBase;
}
TEST_F(SQLMemoryDumpProviderTest, OnMemoryDump) {
- base::trace_event::ProcessMemoryDump pmd(nullptr);
base::trace_event::MemoryDumpArgs args = {
base::trace_event::MemoryDumpLevelOfDetail::DETAILED};
+ base::trace_event::ProcessMemoryDump pmd(nullptr, args);
ASSERT_TRUE(
sql::SqlMemoryDumpProvider::GetInstance()->OnMemoryDump(args, &pmd));
ASSERT_TRUE(pmd.GetAllocatorDump("sqlite"));
diff --git a/chromium/sql/sqlite_features_unittest.cc b/chromium/sql/sqlite_features_unittest.cc
index 9b8c9716645..b84a80d69c0 100644
--- a/chromium/sql/sqlite_features_unittest.cc
+++ b/chromium/sql/sqlite_features_unittest.cc
@@ -18,6 +18,10 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/sqlite/sqlite3.h"
+#if defined(OS_IOS)
+#include "base/ios/ios_util.h"
+#endif
+
// Test that certain features are/are-not enabled in our SQLite.
namespace {
@@ -151,6 +155,13 @@ TEST_F(SQLiteFeaturesTest, ForeignKeySupport) {
// If the platform cannot support SQLite mmap'ed I/O, make sure SQLite isn't
// offering to support it.
TEST_F(SQLiteFeaturesTest, NoMmap) {
+#if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE)
+ if (base::ios::IsRunningOnIOS10OrLater()) {
+ // iOS 10 added mmap support for sqlite.
+ return;
+ }
+#endif
+
// For recent versions of SQLite, SQLITE_MAX_MMAP_SIZE=0 can be used to
// disable mmap support. Alternately, sqlite3_config() could be used. In
// that case, the pragma will run successfully, but the size will always be 0.
@@ -166,7 +177,9 @@ TEST_F(SQLiteFeaturesTest, NoMmap) {
sql::Statement s(db().GetUniqueStatement("PRAGMA mmap_size"));
ASSERT_TRUE(!s.Step() || !s.ColumnInt64(0));
}
-#else
+#endif
+
+#if !defined(MOJO_APPTEST_IMPL)
// Verify that OS file writes are reflected in the memory mapping of a
// memory-mapped file. Normally SQLite writes to memory-mapped files using
// memcpy(), which should stay consistent. Our SQLite is slightly patched to
@@ -174,6 +187,13 @@ TEST_F(SQLiteFeaturesTest, NoMmap) {
// version doesn't reflect the OS file writes, SQLite's memory-mapped I/O should
// be disabled on this platform using SQLITE_MAX_MMAP_SIZE=0.
TEST_F(SQLiteFeaturesTest, Mmap) {
+#if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE)
+ if (!base::ios::IsRunningOnIOS10OrLater()) {
+ // iOS9's sqlite does not support mmap, so this test must be skipped.
+ return;
+ }
+#endif
+
// Try to turn on mmap'ed I/O.
ignore_result(db().Execute("PRAGMA mmap_size = 1048576"));
{
diff --git a/chromium/sql/statement_unittest.cc b/chromium/sql/statement_unittest.cc
index 1565b3e48a9..75adf63c52c 100644
--- a/chromium/sql/statement_unittest.cc
+++ b/chromium/sql/statement_unittest.cc
@@ -11,7 +11,7 @@
#include "sql/correct_sql_test_base.h"
#include "sql/statement.h"
#include "sql/test/error_callback_support.h"
-#include "sql/test/scoped_error_ignorer.h"
+#include "sql/test/scoped_error_expecter.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/sqlite/sqlite3.h"
@@ -78,18 +78,20 @@ TEST_F(SQLStatementTest, ErrorCallback) {
EXPECT_EQ(SQLITE_MISMATCH, error);
}
-// Error ignorer works for error running a statement.
+// Error expecter works for error running a statement.
TEST_F(SQLStatementTest, ScopedIgnoreError) {
ASSERT_TRUE(db().Execute("CREATE TABLE foo (a INTEGER PRIMARY KEY, b)"));
sql::Statement s(db().GetUniqueStatement("INSERT INTO foo (a) VALUES (?)"));
EXPECT_TRUE(s.is_valid());
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_MISMATCH);
- s.BindCString(0, "bad bad");
- ASSERT_FALSE(s.Run());
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
+ {
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_MISMATCH);
+ s.BindCString(0, "bad bad");
+ ASSERT_FALSE(s.Run());
+ ASSERT_TRUE(expecter.SawExpectedErrors());
+ }
}
TEST_F(SQLStatementTest, Reset) {