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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/files/memory_mapped_file.h" | 12 #include "base/files/memory_mapped_file.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "sql/connection.h" | 14 #include "sql/connection.h" |
15 #include "sql/statement.h" | 15 #include "sql/statement.h" |
16 #include "sql/test/sql_test_base.h" | 16 #include "sql/test/sql_test_base.h" |
17 #include "sql/test/test_helpers.h" | 17 #include "sql/test/test_helpers.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/sqlite/sqlite3.h" | 19 #include "third_party/sqlite/sqlite3.h" |
20 | 20 |
21 #if defined(OS_IOS) | 21 #if defined(OS_IOS) |
22 #include "base/ios/ios_util.h" | 22 #include "base/ios/ios_util.h" |
23 #endif | 23 #endif |
24 | 24 |
| 25 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 26 #include <CoreFoundation/CoreFoundation.h> |
| 27 #include <CoreServices/CoreServices.h> |
| 28 |
| 29 #include "base/mac/mac_util.h" |
| 30 #include "base/mac/scoped_cftyperef.h" |
| 31 #endif |
| 32 |
25 // Test that certain features are/are-not enabled in our SQLite. | 33 // Test that certain features are/are-not enabled in our SQLite. |
26 | 34 |
27 namespace { | 35 namespace { |
28 | 36 |
29 void CaptureErrorCallback(int* error_pointer, std::string* sql_text, | 37 void CaptureErrorCallback(int* error_pointer, std::string* sql_text, |
30 int error, sql::Statement* stmt) { | 38 int error, sql::Statement* stmt) { |
31 *error_pointer = error; | 39 *error_pointer = error; |
32 const char* text = stmt ? stmt->GetSQLStatement() : NULL; | 40 const char* text = stmt ? stmt->GetSQLStatement() : NULL; |
33 *sql_text = text ? text : "no statement available"; | 41 *sql_text = text ? text : "no statement available"; |
34 } | 42 } |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 s.BindString(0, ".*test"); | 304 s.BindString(0, ".*test"); |
297 ASSERT_TRUE(s.Step()); | 305 ASSERT_TRUE(s.Step()); |
298 EXPECT_EQ(3, s.ColumnInt(0)); | 306 EXPECT_EQ(3, s.ColumnInt(0)); |
299 | 307 |
300 s.Reset(true); | 308 s.Reset(true); |
301 s.BindString(0, ".* s[a-z]+"); | 309 s.BindString(0, ".* s[a-z]+"); |
302 ASSERT_TRUE(s.Step()); | 310 ASSERT_TRUE(s.Step()); |
303 EXPECT_EQ(7, s.ColumnInt(0)); | 311 EXPECT_EQ(7, s.ColumnInt(0)); |
304 } | 312 } |
305 | 313 |
| 314 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 315 base::ScopedCFTypeRef<CFURLRef> CFURLRefForPath(const base::FilePath& path){ |
| 316 base::ScopedCFTypeRef<CFStringRef> urlString( |
| 317 CFStringCreateWithFileSystemRepresentation( |
| 318 kCFAllocatorDefault, path.value().c_str())); |
| 319 base::ScopedCFTypeRef<CFURLRef> url( |
| 320 CFURLCreateWithFileSystemPath(kCFAllocatorDefault, urlString, |
| 321 kCFURLPOSIXPathStyle, FALSE)); |
| 322 return url; |
| 323 } |
| 324 |
| 325 // If a database file is marked to be excluded from Time Machine, verify that |
| 326 // journal files are also excluded. |
| 327 // TODO(shess): Disabled because CSBackupSetItemExcluded() does not work on the |
| 328 // bots, though it's fine on dev machines. See <http://crbug.com/410350>. |
| 329 TEST_F(SQLiteFeaturesTest, DISABLED_TimeMachine) { |
| 330 ASSERT_TRUE(db().Execute("CREATE TABLE t (id INTEGER PRIMARY KEY)")); |
| 331 db().Close(); |
| 332 |
| 333 base::FilePath journal(db_path().value() + FILE_PATH_LITERAL("-journal")); |
| 334 ASSERT_TRUE(GetPathExists(db_path())); |
| 335 ASSERT_TRUE(GetPathExists(journal)); |
| 336 |
| 337 base::ScopedCFTypeRef<CFURLRef> dbURL(CFURLRefForPath(db_path())); |
| 338 base::ScopedCFTypeRef<CFURLRef> journalURL(CFURLRefForPath(journal)); |
| 339 |
| 340 // Not excluded to start. |
| 341 EXPECT_FALSE(CSBackupIsItemExcluded(dbURL, NULL)); |
| 342 EXPECT_FALSE(CSBackupIsItemExcluded(journalURL, NULL)); |
| 343 |
| 344 // Exclude the main database file. |
| 345 EXPECT_TRUE(base::mac::SetFileBackupExclusion(db_path())); |
| 346 |
| 347 Boolean excluded_by_path = FALSE; |
| 348 EXPECT_TRUE(CSBackupIsItemExcluded(dbURL, &excluded_by_path)); |
| 349 EXPECT_FALSE(excluded_by_path); |
| 350 EXPECT_FALSE(CSBackupIsItemExcluded(journalURL, NULL)); |
| 351 |
| 352 EXPECT_TRUE(db().Open(db_path())); |
| 353 ASSERT_TRUE(db().Execute("INSERT INTO t VALUES (1)")); |
| 354 EXPECT_TRUE(CSBackupIsItemExcluded(dbURL, &excluded_by_path)); |
| 355 EXPECT_FALSE(excluded_by_path); |
| 356 EXPECT_TRUE(CSBackupIsItemExcluded(journalURL, &excluded_by_path)); |
| 357 EXPECT_FALSE(excluded_by_path); |
| 358 |
| 359 // TODO(shess): In WAL mode this will touch -wal and -shm files. -shm files |
| 360 // could be always excluded. |
| 361 } |
| 362 #endif |
| 363 |
306 } // namespace | 364 } // namespace |
OLD | NEW |