Chromium Code Reviews| 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" |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 AssignOriginInfoTable(db.db_.get(), begin, end); | 438 AssignOriginInfoTable(db.db_.get(), begin, end); |
| 439 db.Commit(); | 439 db.Commit(); |
| 440 | 440 |
| 441 typedef EntryVerifier<Entry> Verifier; | 441 typedef EntryVerifier<Entry> Verifier; |
| 442 Verifier verifier(begin, end); | 442 Verifier verifier(begin, end); |
| 443 EXPECT_TRUE(db.DumpOriginInfoTable( | 443 EXPECT_TRUE(db.DumpOriginInfoTable( |
| 444 base::Bind(&Verifier::Run, base::Unretained(&verifier)))); | 444 base::Bind(&Verifier::Run, base::Unretained(&verifier)))); |
| 445 EXPECT_TRUE(verifier.table.empty()); | 445 EXPECT_TRUE(verifier.table.empty()); |
| 446 } | 446 } |
| 447 | 447 |
| 448 void GetOriginInfo(const base::FilePath& kDbFile) { | |
| 449 const GURL kOrigin = GURL("http://go/"); | |
| 450 typedef QuotaDatabase::OriginInfoTableEntry Entry; | |
| 451 Entry kTableEntries[] = { | |
| 452 Entry(kOrigin, kStorageTypeTemporary, 100, base::Time(), base::Time()) | |
| 453 }; | |
| 454 Entry* begin = kTableEntries; | |
| 455 Entry* end = kTableEntries + arraysize(kTableEntries); | |
| 456 | |
| 457 QuotaDatabase db(kDbFile); | |
| 458 EXPECT_TRUE(db.LazyOpen(true)); | |
| 459 AssignOriginInfoTable(db.db_.get(), begin, end); | |
| 460 db.Commit(); | |
| 461 | |
| 462 Entry entry; | |
| 463 EXPECT_TRUE(db.GetOriginInfo(kOrigin, kStorageTypeTemporary, &entry)); | |
| 464 EXPECT_EQ(kTableEntries[0].type, entry.type); | |
| 465 EXPECT_EQ(kTableEntries[0].origin, entry.origin); | |
| 466 EXPECT_EQ(kTableEntries[0].used_count, entry.used_count); | |
| 467 EXPECT_EQ(kTableEntries[0].last_access_time, entry.last_access_time); | |
| 468 EXPECT_EQ(kTableEntries[0].last_modified_time, entry.last_modified_time); | |
|
michaeln
2015/10/30 00:49:02
can you add a test negative, try to get info for a
calamity
2015/11/02 06:27:44
Done.
| |
| 469 } | |
| 470 | |
| 448 private: | 471 private: |
| 449 template <typename Iterator> | 472 template <typename Iterator> |
| 450 void AssignQuotaTable(sql::Connection* db, Iterator itr, Iterator end) { | 473 void AssignQuotaTable(sql::Connection* db, Iterator itr, Iterator end) { |
| 451 ASSERT_NE(db, (sql::Connection*)NULL); | 474 ASSERT_NE(db, (sql::Connection*)NULL); |
| 452 for (; itr != end; ++itr) { | 475 for (; itr != end; ++itr) { |
| 453 const char* kSql = | 476 const char* kSql = |
| 454 "INSERT INTO HostQuotaTable" | 477 "INSERT INTO HostQuotaTable" |
| 455 " (host, type, quota)" | 478 " (host, type, quota)" |
| 456 " VALUES (?, ?, ?)"; | 479 " VALUES (?, ?, ?)"; |
| 457 sql::Statement statement; | 480 sql::Statement statement; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 } | 661 } |
| 639 | 662 |
| 640 TEST_F(QuotaDatabaseTest, DumpOriginInfoTable) { | 663 TEST_F(QuotaDatabaseTest, DumpOriginInfoTable) { |
| 641 base::ScopedTempDir data_dir; | 664 base::ScopedTempDir data_dir; |
| 642 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); | 665 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); |
| 643 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName); | 666 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName); |
| 644 DumpOriginInfoTable(kDbFile); | 667 DumpOriginInfoTable(kDbFile); |
| 645 DumpOriginInfoTable(base::FilePath()); | 668 DumpOriginInfoTable(base::FilePath()); |
| 646 } | 669 } |
| 647 | 670 |
| 671 TEST_F(QuotaDatabaseTest, GetOriginInfo) { | |
| 672 base::ScopedTempDir data_dir; | |
| 673 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); | |
| 674 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName); | |
| 675 GetOriginInfo(kDbFile); | |
|
michaeln
2015/10/30 00:49:02
Any test that touches the disk is incredibly slow.
calamity
2015/11/02 06:27:44
Done.
| |
| 676 GetOriginInfo(base::FilePath()); | |
| 677 } | |
| 678 | |
| 648 TEST_F(QuotaDatabaseTest, OpenCorruptedDatabase) { | 679 TEST_F(QuotaDatabaseTest, OpenCorruptedDatabase) { |
| 649 base::ScopedTempDir data_dir; | 680 base::ScopedTempDir data_dir; |
| 650 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); | 681 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); |
| 651 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName); | 682 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName); |
| 652 LazyOpen(kDbFile); | 683 LazyOpen(kDbFile); |
| 653 ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile)); | 684 ASSERT_TRUE(sql::test::CorruptSizeInHeader(kDbFile)); |
| 654 sql::ScopedErrorIgnorer ignore_errors; | 685 sql::ScopedErrorIgnorer ignore_errors; |
| 655 ignore_errors.IgnoreError(SQLITE_CORRUPT); | 686 ignore_errors.IgnoreError(SQLITE_CORRUPT); |
| 656 Reopen(kDbFile); | 687 Reopen(kDbFile); |
| 657 EXPECT_TRUE(ignore_errors.CheckIgnoredErrors()); | 688 EXPECT_TRUE(ignore_errors.CheckIgnoredErrors()); |
| 658 } | 689 } |
| 659 | 690 |
| 660 } // namespace content | 691 } // namespace content |
| OLD | NEW |