| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <iterator> | 6 #include <iterator> |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "content/public/test/mock_special_storage_policy.h" | 14 #include "content/public/test/mock_special_storage_policy.h" |
| 15 #include "sql/connection.h" | 15 #include "sql/connection.h" |
| 16 #include "sql/meta_table.h" | 16 #include "sql/meta_table.h" |
| 17 #include "sql/statement.h" | 17 #include "sql/statement.h" |
| 18 #include "sql/test/test_helpers.h" | |
| 19 #include "storage/browser/quota/quota_database.h" | 18 #include "storage/browser/quota/quota_database.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 22 | 21 |
| 23 using storage::kStorageTypePersistent; | 22 using storage::kStorageTypePersistent; |
| 24 using storage::kStorageTypeTemporary; | 23 using storage::kStorageTypeTemporary; |
| 25 using storage::QuotaDatabase; | 24 using storage::QuotaDatabase; |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 namespace { | 27 namespace { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 40 typedef QuotaDatabase::OriginInfoTableCallback | 39 typedef QuotaDatabase::OriginInfoTableCallback |
| 41 OriginInfoTableCallback; | 40 OriginInfoTableCallback; |
| 42 | 41 |
| 43 void LazyOpen(const base::FilePath& kDbFile) { | 42 void LazyOpen(const base::FilePath& kDbFile) { |
| 44 QuotaDatabase db(kDbFile); | 43 QuotaDatabase db(kDbFile); |
| 45 EXPECT_FALSE(db.LazyOpen(false)); | 44 EXPECT_FALSE(db.LazyOpen(false)); |
| 46 ASSERT_TRUE(db.LazyOpen(true)); | 45 ASSERT_TRUE(db.LazyOpen(true)); |
| 47 EXPECT_TRUE(db.db_.get()); | 46 EXPECT_TRUE(db.db_.get()); |
| 48 EXPECT_TRUE(kDbFile.empty() || base::PathExists(kDbFile)); | 47 EXPECT_TRUE(kDbFile.empty() || base::PathExists(kDbFile)); |
| 49 } | 48 } |
| 50 | |
| 51 void Reopen(const base::FilePath& kDbFile) { | |
| 52 QuotaDatabase db(kDbFile); | |
| 53 ASSERT_TRUE(db.LazyOpen(false)); | |
| 54 EXPECT_TRUE(db.db_.get()); | |
| 55 EXPECT_TRUE(kDbFile.empty() || base::PathExists(kDbFile)); | |
| 56 } | |
| 57 | 49 |
| 58 void UpgradeSchemaV2toV3(const base::FilePath& kDbFile) { | 50 void UpgradeSchemaV2toV3(const base::FilePath& kDbFile) { |
| 59 const QuotaTableEntry entries[] = { | 51 const QuotaTableEntry entries[] = { |
| 60 QuotaTableEntry("a", kStorageTypeTemporary, 1), | 52 QuotaTableEntry("a", kStorageTypeTemporary, 1), |
| 61 QuotaTableEntry("b", kStorageTypeTemporary, 2), | 53 QuotaTableEntry("b", kStorageTypeTemporary, 2), |
| 62 QuotaTableEntry("c", kStorageTypePersistent, 3), | 54 QuotaTableEntry("c", kStorageTypePersistent, 3), |
| 63 }; | 55 }; |
| 64 | 56 |
| 65 CreateV2Database(kDbFile, entries, arraysize(entries)); | 57 CreateV2Database(kDbFile, entries, arraysize(entries)); |
| 66 | 58 |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 DumpQuotaTable(base::FilePath()); | 556 DumpQuotaTable(base::FilePath()); |
| 565 } | 557 } |
| 566 | 558 |
| 567 TEST_F(QuotaDatabaseTest, DumpOriginInfoTable) { | 559 TEST_F(QuotaDatabaseTest, DumpOriginInfoTable) { |
| 568 base::ScopedTempDir data_dir; | 560 base::ScopedTempDir data_dir; |
| 569 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); | 561 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); |
| 570 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName); | 562 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName); |
| 571 DumpOriginInfoTable(kDbFile); | 563 DumpOriginInfoTable(kDbFile); |
| 572 DumpOriginInfoTable(base::FilePath()); | 564 DumpOriginInfoTable(base::FilePath()); |
| 573 } | 565 } |
| 574 | |
| 575 TEST_F(QuotaDatabaseTest, OpenCorruptedDatabase) { | |
| 576 base::ScopedTempDir data_dir; | |
| 577 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); | |
| 578 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName); | |
| 579 LazyOpen(kDbFile); | |
| 580 ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile)); | |
| 581 Reopen(kDbFile); | |
| 582 } | |
| 583 | |
| 584 } // namespace content | 566 } // namespace content |
| OLD | NEW |